Submission #529970

# Submission time Handle Problem Language Result Execution time Memory
529970 2022-02-24T08:00:58 Z scottchou Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
15 / 100
1 ms 292 KB
#include<iostream>
#include<cassert>
using namespace std;
int const N = 405;
char a[N];
int main(){
    int n;
    cin >> n;
    int R = 0, G = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] == 'R'){
            R++;
        }else if(a[i] == 'G') {
            G++;
        }
    }
    if(R != n / 2 && G != n / 2){
        cout << -1 << '\n';
        return 0;
    }
    if(n & 1){
        int cnt = 0;
        if(R > G){
            int last = 0;
            for(int i = 0; i < n; i++){
                if(a[i] == 'R'){
                    cnt += abs(i - last);
                    last += 2;
                }
            }
        }else{
            int last = 0;
            for(int i = 0; i < n; i++){
                if(a[i] == 'G'){
                    cnt += abs(i - last);
                    last += 2;
                }
            }
        }
        cout << cnt << '\n';
    }else{
        int cnt1 = 0, cnt2 = 0, last1 = 0, last2 = 0;
        for(int i = 0; i < n; i++){
            if(a[i] == 'R'){
                cnt1 += abs(i - last1);
                last1 += 2;
            }else{
                cnt2 += abs(i - last2);
                last2 += 2;
            }
        }
        cout << min(cnt1, cnt2) << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 272 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -