Submission #888467

# Submission time Handle Problem Language Result Execution time Memory
888467 2023-12-17T13:39:53 Z hafo Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
15 / 100
1 ms 456 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pa pair<int, int>
#define pall pair<ll, int>
#define fi first
#define se second
#define TASK "test"
#define Size(x) (int) x.size()
#define all(x) x.begin(), x.end()
using namespace std;

template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;}

const int MOD = 1e9 + 7;
const int LOG = 20;
const int maxn = 4e2 + 7;
const ll oo = 1e9 + 69;

int n;
char a[maxn];

struct sub3 {
    char b[maxn];

    int calc(char ch) {
        for(int i = 1; i <= n; i++) b[i] = a[i];
        int ans = 0;
        for(int i = 1; i <= n; i++) {
            if(i % 2 == 1 && b[i] != ch) {
                bool ok = 0;
                for(int j = i + 1; j <= n; j++) {
                    if(b[j] == ch) {
                        ok = 1;
                        for(int k = j; k > i; k--) {
                            ans++;
                            swap(b[k], b[k - 1]);
                        }
                        break;
                    }
                }

                if(!ok) return oo;
            }

            if(i % 2 == 0 && b[i] == ch) {
                bool ok = 0;
                for(int j = i + 1; j <= n; j++) {
                    if(b[j] != ch) {
                        ok = 1;
                        for(int k = j; k > i; k--) {
                            ans++;
                            swap(b[k], b[k - 1]);
                        }
                        break;
                    }
                }
                if(!ok) return oo;
            }
        }
        return ans;
    }

    void solve() {
        int ans = oo;
        mini(ans, calc('R'));
        mini(ans, calc('G'));
        if(ans == oo) cout<<-1;
        else cout<<ans;
    }   

} sub3;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //freopen(TASK".inp", "r", stdin);
    //freopen(TASK".out", "w", stdout);

    cin>>n;
    for(int i = 1; i <= n; i++) cin>>a[i];

    sub3.solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 456 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -