# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
574921 | 2022-06-09T13:00:10 Z | MateGiorbelidze | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 1 ms | 1236 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define ff first #define sc second #define pb push_back #define in insert int main () { ios::sync_with_stdio(false); cin.tie(nullptr); ll n; cin>>n; string s; cin>>s; ll a[n + 1] , r = 0 , g = 0, y = 0; ll rp[401], rg[401], ry[401]; for (int i = 0; i < s.size(); i++) { if (s[i] == 'R') { r++; rp[r] = i + 1; } if (s[i] == 'G') { g++; rg[g] = i + 1; } if (s[i] == 'Y') { y++; ry[y] = i + 1; } } ll d[r + 1][g + 1][y + 1][3]; //cout<<r<<" "<<g<<" "<<y; for (int i = 0; i <= r; i++) for (int j = 0; j <= g; j++) for (int k = 0; k <= y; k++) d[i][j][k][0] = d[i][j][k][1] = d[i][j][k][2] = INT_MAX; d[0][0][0][0] = d[0][0][0][1] = d[0][0][0][2] = 0; for (int i = 0; i <= r; i++) for (int j = 0; j <= g; j++) for (int k = 0; k <= y; k++) { if (k != 0) { d[i][j][k][2] = min(d[i][j][k - 1][1] , d[i][j][k - 1][0]); d[i][j][k][2] += abs(ry[k] - i - j - k); } if (j != 0) { d[i][j][k][1] = min(d[i][j - 1][k][2] , d[i][j - 1][k][0]); d[i][j][k][1] += abs(rg[j] - i - j - k); } if (i != 0) { d[i][j][k][0] = min(d[i - 1][j][k][1] , d[i - 1][j][k][2]); d[i][j][k][0] += abs(rp[i] - i - j - k); } //cout<<i<<" "<<j<<" "<<k<<'\n'; //cout<<d[i][j][k][0]<<" "<<d[i][j][k][1]<<" "<<d[i][j][k][2]<<'\n'; //cout<<'\n'; } ll mn = min( {d[r][g][y][1], d[r][g][y][0], d[r][g][y][2]}); if (mn != INT_MAX)cout<<mn / 2; else cout<<-1; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 328 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 320 KB | Output is correct |
11 | Incorrect | 0 ms | 212 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 328 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 320 KB | Output is correct |
11 | Incorrect | 0 ms | 212 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 1224 KB | Output is correct |
3 | Correct | 1 ms | 1212 KB | Output is correct |
4 | Correct | 1 ms | 1236 KB | Output is correct |
5 | Correct | 1 ms | 1236 KB | Output is correct |
6 | Correct | 1 ms | 1236 KB | Output is correct |
7 | Correct | 1 ms | 1236 KB | Output is correct |
8 | Correct | 1 ms | 1224 KB | Output is correct |
9 | Correct | 1 ms | 1236 KB | Output is correct |
10 | Correct | 1 ms | 1236 KB | Output is correct |
11 | Correct | 1 ms | 1220 KB | Output is correct |
12 | Correct | 1 ms | 468 KB | Output is correct |
13 | Correct | 1 ms | 724 KB | Output is correct |
14 | Correct | 1 ms | 852 KB | Output is correct |
15 | Correct | 1 ms | 1220 KB | Output is correct |
16 | Correct | 1 ms | 1224 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 328 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 320 KB | Output is correct |
11 | Incorrect | 0 ms | 212 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |