[SWEA] 1491 원재의 벽 꾸미기

Time Lapse :34min 0sec

1491.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;
int main(int argc, char** argv){
int T, test_case;
unsigned long long A,B,N,R,C;
unsigned long long answer;
cin>>T;
for(test_case=1;test_case<=T;test_case++){
cin>>N>>A>>B;
answer = -1;
for(R=N;R>=1;R--)
for(C=1;R*C<=N&&C<=R;C++)
answer = (answer > A*(R-C)+ B*(N-R*C))&&A*(R-C)+ B*(N-R*C)>=0 ? A*(R-C)+ B*(N-R*C) : answer;

cout<<"#"<<test_case<<" "<<answer<<endl;
}
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/04/PS/SWEA/1491/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.