답안 #136311

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
136311 2019-07-25T06:24:54 Z Utaha Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
100 / 100
127 ms 163076 KB
/*input
6
RRRRRG
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
    out<<'('<<P.F<<','<<P.S<<')';
    return out;
}
#define version 20190713
//}}}
const ll maxn=405;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        
        b>>=1;
    }
    return res;
}

int dp[maxn][maxn][maxn][3];
int cnt[3][3][maxn];

int idx[256];
int main(){
    IOS;
    int n;
    string s;
    cin>>n>>s;

    idx['R']=0;
    idx['G']=1;
    idx['Y']=2;

    int c[3]={0};
    REP(i,n){
        c[idx[s[i]]]++;
    }
    REP(i,3) REP(j,3) if(i!=j){
        int tmp=0;
        int pt=1;
        REP(k,n){
            if(idx[s[k]]==j) tmp++;
            if(idx[s[k]]==i){
                cnt[i][j][pt++]=tmp;
            }
        }
    }

    REP(i,c[0]+1) REP(j,c[1]+1) REP(k,c[2]+1){
        if(!i&&!j&&!k){
            REP(l,3) dp[i][j][k][l]=0;
            continue;
        }
        {
            if(i==0) dp[i][j][k][0]=INF;
            else{
                dp[i][j][k][0]=min(dp[i-1][j][k][1],dp[i-1][j][k][2]);
                if(j>=cnt[0][1][i]) dp[i][j][k][0]+=j-cnt[0][1][i];
                if(k>=cnt[0][2][i]) dp[i][j][k][0]+=k-cnt[0][2][i];
            }
        }
        {
            if(j==0) dp[i][j][k][1]=INF;
            else{
                dp[i][j][k][1]=min(dp[i][j-1][k][0],dp[i][j-1][k][2]);
                if(i>=cnt[1][0][j]) dp[i][j][k][1]+=i-cnt[1][0][j];
                if(k>=cnt[1][2][j]) dp[i][j][k][1]+=k-cnt[1][2][j];
            }
        }
        {
            if(k==0) dp[i][j][k][2]=INF;
            else{
                dp[i][j][k][2]=min(dp[i][j][k-1][0],dp[i][j][k-1][1]);
                if(i>=cnt[2][0][k]) dp[i][j][k][2]+=i-cnt[2][0][k];
                if(j>=cnt[2][1][k]) dp[i][j][k][2]+=j-cnt[2][1][k];
            }
        }
    }
    int tmp=*min_element(dp[c[0]][c[1]][c[2]],dp[c[0]][c[1]][c[2]]+3);
    if(tmp>=INF) cout<<"-1\n";
    else cout<<tmp<<'\n';
    return 0;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:67:19: warning: array subscript has type 'char' [-Wchar-subscripts]
         c[idx[s[i]]]++;
                   ^
joi2019_ho_t3.cpp:73:24: warning: array subscript has type 'char' [-Wchar-subscripts]
             if(idx[s[k]]==j) tmp++;
                        ^
joi2019_ho_t3.cpp:74:24: warning: array subscript has type 'char' [-Wchar-subscripts]
             if(idx[s[k]]==i){
                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 4 ms 2424 KB Output is correct
19 Correct 3 ms 1912 KB Output is correct
20 Correct 3 ms 2296 KB Output is correct
21 Correct 4 ms 2424 KB Output is correct
22 Correct 3 ms 1656 KB Output is correct
23 Correct 3 ms 2168 KB Output is correct
24 Correct 3 ms 1656 KB Output is correct
25 Correct 6 ms 3960 KB Output is correct
26 Correct 5 ms 4216 KB Output is correct
27 Correct 4 ms 3064 KB Output is correct
28 Correct 3 ms 2424 KB Output is correct
29 Correct 3 ms 2296 KB Output is correct
30 Correct 4 ms 2296 KB Output is correct
31 Correct 3 ms 2040 KB Output is correct
32 Correct 4 ms 2424 KB Output is correct
33 Correct 6 ms 3932 KB Output is correct
34 Correct 5 ms 3576 KB Output is correct
35 Correct 4 ms 2808 KB Output is correct
36 Correct 3 ms 1912 KB Output is correct
37 Correct 3 ms 1784 KB Output is correct
38 Correct 4 ms 2168 KB Output is correct
39 Correct 3 ms 2296 KB Output is correct
40 Correct 2 ms 504 KB Output is correct
41 Correct 4 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 124 ms 163036 KB Output is correct
3 Correct 122 ms 162232 KB Output is correct
4 Correct 127 ms 163064 KB Output is correct
5 Correct 123 ms 163076 KB Output is correct
6 Correct 124 ms 163064 KB Output is correct
7 Correct 123 ms 162272 KB Output is correct
8 Correct 123 ms 162296 KB Output is correct
9 Correct 125 ms 161356 KB Output is correct
10 Correct 123 ms 163036 KB Output is correct
11 Correct 124 ms 163064 KB Output is correct
12 Correct 35 ms 44124 KB Output is correct
13 Correct 62 ms 77176 KB Output is correct
14 Correct 97 ms 111448 KB Output is correct
15 Correct 123 ms 163068 KB Output is correct
16 Correct 124 ms 162936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 632 KB Output is correct
10 Correct 2 ms 632 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 4 ms 2424 KB Output is correct
19 Correct 3 ms 1912 KB Output is correct
20 Correct 3 ms 2296 KB Output is correct
21 Correct 4 ms 2424 KB Output is correct
22 Correct 3 ms 1656 KB Output is correct
23 Correct 3 ms 2168 KB Output is correct
24 Correct 3 ms 1656 KB Output is correct
25 Correct 6 ms 3960 KB Output is correct
26 Correct 5 ms 4216 KB Output is correct
27 Correct 4 ms 3064 KB Output is correct
28 Correct 3 ms 2424 KB Output is correct
29 Correct 3 ms 2296 KB Output is correct
30 Correct 4 ms 2296 KB Output is correct
31 Correct 3 ms 2040 KB Output is correct
32 Correct 4 ms 2424 KB Output is correct
33 Correct 6 ms 3932 KB Output is correct
34 Correct 5 ms 3576 KB Output is correct
35 Correct 4 ms 2808 KB Output is correct
36 Correct 3 ms 1912 KB Output is correct
37 Correct 3 ms 1784 KB Output is correct
38 Correct 4 ms 2168 KB Output is correct
39 Correct 3 ms 2296 KB Output is correct
40 Correct 2 ms 504 KB Output is correct
41 Correct 4 ms 2296 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 124 ms 163036 KB Output is correct
44 Correct 122 ms 162232 KB Output is correct
45 Correct 127 ms 163064 KB Output is correct
46 Correct 123 ms 163076 KB Output is correct
47 Correct 124 ms 163064 KB Output is correct
48 Correct 123 ms 162272 KB Output is correct
49 Correct 123 ms 162296 KB Output is correct
50 Correct 125 ms 161356 KB Output is correct
51 Correct 123 ms 163036 KB Output is correct
52 Correct 124 ms 163064 KB Output is correct
53 Correct 35 ms 44124 KB Output is correct
54 Correct 62 ms 77176 KB Output is correct
55 Correct 97 ms 111448 KB Output is correct
56 Correct 123 ms 163068 KB Output is correct
57 Correct 124 ms 162936 KB Output is correct
58 Correct 77 ms 76280 KB Output is correct
59 Correct 92 ms 96772 KB Output is correct
60 Correct 87 ms 87824 KB Output is correct
61 Correct 83 ms 84984 KB Output is correct
62 Correct 124 ms 160632 KB Output is correct
63 Correct 124 ms 160248 KB Output is correct
64 Correct 122 ms 150108 KB Output is correct
65 Correct 119 ms 138684 KB Output is correct
66 Correct 82 ms 86136 KB Output is correct
67 Correct 80 ms 82936 KB Output is correct
68 Correct 84 ms 88696 KB Output is correct
69 Correct 83 ms 85496 KB Output is correct
70 Correct 90 ms 92536 KB Output is correct
71 Correct 82 ms 83960 KB Output is correct
72 Correct 38 ms 41720 KB Output is correct
73 Correct 5 ms 2936 KB Output is correct