답안 #117760

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
117760 2019-06-17T07:34:02 Z JohnTitor Growing Vegetable is Fun 3 (JOI19_ho_t3) C++11
0 / 100
2 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
#define taskname "Vegetable3"
int n;
string s;
int cnt[256];
int x[3][401][3];
int f[401][201][134][3];
bool done[401][201][134][3];
int F(int c0, int c1, int c2, int l){
    if(done[c0][c1][c2][l]) return f[c0][c1][c2][l];
    done[c0][c1][c2][l]=1;
    if(c0+c1+c2==0) return f[c0][c1][c2][l]=0;
    int res=1e9;
    if((l!=0)&&c0) res=min(res, max(0, c1-x[0][c0][1])+max(0, c2-x[0][c0][2])+F(c0-1, c1, c2, 0));
    if((l!=1)&&c1) res=min(res, max(0, c0-x[1][c1][0])+max(0, c2-x[1][c1][2])+F(c0, c1-1, c2, 1));
    if((l!=2)&&c2) res=min(res, max(0, c0-x[2][c2][0])+max(0, c1-x[2][c2][1])+F(c0, c1, c2-1, 2));
//    cerr<<c0<<' '<<c1<<' '<<c2<<' '<<l<<'\n';
//    bug(res);
    return f[c0][c1][c2][l]=res;
}
int main(){
    #ifdef Aria
        if(fopen(taskname".in", "r"))
            freopen(taskname".in", "r", stdin);
    #endif // Aria
    cin>>n>>s;
    string all="RGY";
    for(char c: s) cnt[c]++;
    sort(all.begin(), all.end(), [](char A, char B){
        return cnt[A]>cnt[B];
    });
    bug(all);
    for(char &c: s) c=all.find(c);
    reverse(s.begin(), s.end());
    for(char c: s){
        cnt[c]++;
        FFOR(i, 0, 3) x[c][cnt[c]][i]=cnt[i];
    }
    int ans=1e9;
    FFOR(i, 0, 3) ans=min(ans, F(cnt[0], cnt[1], cnt[2], i));
    if(ans==1e9) ans=-1;
    writeln(ans);
}

Compilation message

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:45:25: warning: array subscript has type 'char' [-Wchar-subscripts]
     for(char c: s) cnt[c]++;
                         ^
joi2019_ho_t3.cpp: In lambda function:
joi2019_ho_t3.cpp:47:21: warning: array subscript has type 'char' [-Wchar-subscripts]
         return cnt[A]>cnt[B];
                     ^
joi2019_ho_t3.cpp:47:28: warning: array subscript has type 'char' [-Wchar-subscripts]
         return cnt[A]>cnt[B];
                            ^
joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:53:14: warning: array subscript has type 'char' [-Wchar-subscripts]
         cnt[c]++;
              ^
joi2019_ho_t3.cpp:54:26: warning: array subscript has type 'char' [-Wchar-subscripts]
         FFOR(i, 0, 3) x[c][cnt[c]][i]=cnt[i];
                          ^
joi2019_ho_t3.cpp:54:33: warning: array subscript has type 'char' [-Wchar-subscripts]
         FFOR(i, 0, 3) x[c][cnt[c]][i]=cnt[i];
                                 ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -