이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 65
#define INF 0x3f3f3f3f
int n;
string s;
vector <int> pos[3];
int to_rch[3][MAX_N][MAX_N][MAX_N];
int dp[3][MAX_N][MAX_N][MAX_N] ,root = -1;
int solve(int t ,int p0 ,int p1 ,int p2){
int i = p0+p1+p2;
if(i == n)
return 0;
int&ret = (~t ? dp[t][p0][p1][p2] : root);
if(~ret)
return ret;
ret = INF;
int st[] = {p0 ,p1 ,p2};
for(int nt=0; nt<3; nt++)
if(t != nt && st[nt] < pos[nt].size()){
int cost = to_rch[nt][st[0]][st[1]][st[2]];
st[nt]++;
ret = min(ret ,cost+solve(nt ,st[0] ,st[1] ,st[2]));
st[nt]--;
}
return ret;
}
int main()
{
//freopen("input.in" ,"r" ,stdin);
while(cin >> n){
pos[0].clear();
pos[1].clear();
pos[2].clear();
cin >> s; n = s.size();
for(int i=0; i<n; i++){
if(s[i] == 'R') pos[0].push_back(i);
if(s[i] == 'G') pos[1].push_back(i);
if(s[i] == 'Y') pos[2].push_back(i);
}
memset(to_rch ,0 ,sizeof to_rch);
for(int p0=0; p0<=pos[0].size(); p0++)
for(int p1=0; p1<=pos[1].size(); p1++)
for(int p2=0; p2<=pos[2].size(); p2++)
{
int i = p0+p1+p2 ,st[] = {p0 ,p1 ,p2};
for(int t=0; t<3; t++) if(st[t] < pos[t].size())
for(int h=0; h<3; h++) if(h != t)
for(int j=st[h]; j<pos[h].size(); j++)
to_rch[t][p0][p1][p2] += pos[h][j] < pos[t][st[t]];
/*to_rch[t][p0][p1][p2] +=
upper_bound(pos[h].begin()+st[h] ,pos[h].end() ,pos[t][st[t]])-(pos[h].begin()+st[h]);*/
}
memset(dp ,-1 ,sizeof dp);
root = -1 ,solve(-1 ,0 ,0 ,0);
cout << (root == INF ? -1 : root) << endl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
joi2019_ho_t3.cpp: In function 'int solve(int, int, int, int)':
joi2019_ho_t3.cpp:24:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(t != nt && st[nt] < pos[nt].size()){
~~~~~~~^~~~~~~~~~~~~~~~
joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:51:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int p0=0; p0<=pos[0].size(); p0++)
~~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:52:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int p1=0; p1<=pos[1].size(); p1++)
~~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:53:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int p2=0; p2<=pos[2].size(); p2++)
~~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:56:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int t=0; t<3; t++) if(st[t] < pos[t].size())
~~~~~~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:58:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=st[h]; j<pos[h].size(); j++)
~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:55:8: warning: unused variable 'i' [-Wunused-variable]
int i = p0+p1+p2 ,st[] = {p0 ,p1 ,p2};
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |