Submission #876392

#TimeUsernameProblemLanguageResultExecution timeMemory
876392vjudge1Growing Vegetable is Fun 3 (JOI19_ho_t3)C++17
0 / 100
0 ms456 KiB
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back //emplace_back #define pp pop_back #define pii pair<ll, ll> //pair<int, int> #define all(x) (x).begin(),(x).end() #define mp(a,b) make_pair(a , b) #define lb lower_bound #define ub upper_bound #define sz(x) (ll)(x).size() #define F first #define S second #define bg(x) (x).begin() #define For(x, n) for(int (x) = 0 ; (x) < (n) ; (x)++) #define debug(x) cout << #x << " : " << x << endl #define endl (char)(10) #define arr(x) array<int , (x)> #define yes cout << "YES" << endl #define no cout << "NO" << endl #define FAST ios_base::sync_with_stdio(0);cin.tie(0); ll Sum(ll a , ll b , ll MOD) { a %= MOD; b %= MOD; a += b; return a % MOD; } ll Mul(ll a , ll b , ll MOD) { a %= MOD; b %= MOD; a *= b; return a % MOD; } ll Pow(ll a , ll b , ll MOD) { ll res = 1; while(b) { if((b & 1))res = Mul(res , a , MOD); a = Mul(a , a , MOD); b >>= 1; } return res; } ll Min(ll a , ll b) { if(a > b)return b; return a; } ll Max(ll a , ll b) { if(a > b)return a; return b; } ll Ceil(ll a , ll b) { if(a % b)return (a/b)+1; return a/b; } ///////////////////// //VALS ///////////////////// //FUNCTIONS ll Abs(ll a, ll b) { ll c = a -b; if(c < 0)return -c; return c; } ///////////////////// //SOLVE void solve() { ll n; cin >> n; string s; cin >> s; ll cntr = 0,cntg = 0; For(i,n)if(s[i] == 'R')cntr++; else if(s[i] == 'G')cntg++; if(n % 2 == 0) if(cntr != n/2)cout << -1 << endl; if(n % 2 == 1) if(cntr != n/2 and cntr != n/2+1){cout << -1 << endl;return;} if(n % 2 == 1) { if(cntr > cntg) { ll ans = 0; ll x = 0; For(i,n) { if(s[i] == 'R') { ans += Abs(i,x); x += 2; } } x = 1; For(i,n) { if(s[i] == 'G') { ans += Abs(i, x); x += 2; } } cout << ans << endl; } else { ll ans = 0; ll x = 0; For(i,n) { if(s[i] == 'G') { ans += Abs(i,x); x += 2; } } x = 1; For(i,n) { if(s[i] == 'R') { ans += Abs(i, x); x += 2; } } cout << ans << endl; } } else { ll ans = 0; ll x = 0; For(i,n) { if(s[i] == 'R') { ans += Abs(i,x); x += 2; } } x = 1; For(i,n) { if(s[i] == 'G') { ans += Abs(i, x); x += 2; } } ll ans2 = 0; x = 0; For(i,n) { if(s[i] == 'G') { ans2 += Abs(i,x); x += 2; } } x = 1; For(i,n) { if(s[i] == 'R') { ans2 += Abs(i, x); x += 2; } } cout << Min(ans,ans2) << endl; } } ///////////////////// //MAIN int main() { FAST; ll t = 1; // cin >> t; while(t--) { solve(); } } ///////////////////// /* ZZZZZZZ A M M IIIIIII N N Z A A M M M M I NN N Z A A M M M M I N N N Z AAAAAAA M M M I N N N Z A A M M I N N N Z A A M M I N NN ZZZZZZZ A A M M IIIIIII N N TREE */

Compilation message (stderr)

joi2019_ho_t3.cpp: In function 'void solve()':
joi2019_ho_t3.cpp:19:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   19 | #define For(x, n) for(int (x) = 0 ; (x) < (n) ; (x)++)
      |                           ^
joi2019_ho_t3.cpp:95:2: note: in expansion of macro 'For'
   95 |  For(i,n)if(s[i] == 'R')cntr++;
      |  ^~~
joi2019_ho_t3.cpp:19:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   19 | #define For(x, n) for(int (x) = 0 ; (x) < (n) ; (x)++)
      |                           ^
joi2019_ho_t3.cpp:110:4: note: in expansion of macro 'For'
  110 |    For(i,n)
      |    ^~~
joi2019_ho_t3.cpp:19:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   19 | #define For(x, n) for(int (x) = 0 ; (x) < (n) ; (x)++)
      |                           ^
joi2019_ho_t3.cpp:119:4: note: in expansion of macro 'For'
  119 |    For(i,n)
      |    ^~~
joi2019_ho_t3.cpp:19:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   19 | #define For(x, n) for(int (x) = 0 ; (x) < (n) ; (x)++)
      |                           ^
joi2019_ho_t3.cpp:134:4: note: in expansion of macro 'For'
  134 |    For(i,n)
      |    ^~~
joi2019_ho_t3.cpp:19:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   19 | #define For(x, n) for(int (x) = 0 ; (x) < (n) ; (x)++)
      |                           ^
joi2019_ho_t3.cpp:143:4: note: in expansion of macro 'For'
  143 |    For(i,n)
      |    ^~~
joi2019_ho_t3.cpp:19:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   19 | #define For(x, n) for(int (x) = 0 ; (x) < (n) ; (x)++)
      |                           ^
joi2019_ho_t3.cpp:158:4: note: in expansion of macro 'For'
  158 |    For(i,n)
      |    ^~~
joi2019_ho_t3.cpp:19:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   19 | #define For(x, n) for(int (x) = 0 ; (x) < (n) ; (x)++)
      |                           ^
joi2019_ho_t3.cpp:167:4: note: in expansion of macro 'For'
  167 |    For(i,n)
      |    ^~~
joi2019_ho_t3.cpp:19:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   19 | #define For(x, n) for(int (x) = 0 ; (x) < (n) ; (x)++)
      |                           ^
joi2019_ho_t3.cpp:178:4: note: in expansion of macro 'For'
  178 |    For(i,n)
      |    ^~~
joi2019_ho_t3.cpp:19:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   19 | #define For(x, n) for(int (x) = 0 ; (x) < (n) ; (x)++)
      |                           ^
joi2019_ho_t3.cpp:187:4: note: in expansion of macro 'For'
  187 |    For(i,n)
      |    ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...