Submission #110438

#TimeUsernameProblemLanguageResultExecution timeMemory
110438luciocfGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
0 / 100
2 ms384 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 410; char a[maxn], b[maxn]; int main(void) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf(" %c", &a[i]); b[i] = a[i]; } int ans = 0, Ans = 1e9+10; bool ok = 1; for (int i = 0; i < n; i++) { if ( (i%2 == 0 && b[i] == 'G') || (i%2 == 1 && b[i] == 'R')) { ok = 0; break; } bool found = 0; for (int j = i+1; j < n; j++) { if (i%2 == 0 && j%2 == 1 && b[j] == 'G') { found = 1; ans += (j-i); swap(b[i], b[j]); } else if (i%2 == 1 && j%2 == 0 && b[j] == 'R') { found = 1; ans += j-i; swap(b[i], b[j]); } } if (!found) { ok = 0; break; } } if (ok) Ans = max(Ans, ans); ok = 1, ans = 0; for (int i = 0; i < n; i++) b[i] = a[i]; for (int i = 0; i < n; i++) { if ( (i%2 == 0 && b[i] == 'R') || (i%2 == 1 && b[i] == 'G')) { ok = 0; break; } bool found = 0; for (int j = i+1; j < n; j++) { if (i%2 == 0 && j%2 == 1 && b[j] == 'R') { found = 1; ans += j-i; swap(b[i], b[j]); } else if (i%2 == 1 && j%2 == 0 && b[j] == 'G') { found = 1; ans += j-i; swap(b[i], b[j]); } } if (!found) { ok = 0; break; } } if (ok) Ans = max(ans, Ans); if (Ans == 1e9+10) printf("-1\n"); else printf("%d\n", Ans); }

Compilation message (stderr)

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
joi2019_ho_t3.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c", &a[i]);
   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...