Submission #98786

#TimeUsernameProblemLanguageResultExecution timeMemory
98786bogdan10bosGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
0 / 100
2 ms384 KiB
#include <bits/stdc++.h> using namespace std; //#define FILE_IO typedef pair<int, int> pii; int N; string s; vector<pii> v; int main() { #ifdef FILE_IO freopen("1.in", "r", stdin); //freopen("1.out", "w", stdout); #endif cin >> N; cin >> s; for(int i = 0; i < N; i++) v.push_back({s[i], i}); for(int i = 1; i < N; i++) { if(v[i].first != v[i - 1].first) continue; for(int j = i + 1; j < N; j++) if(v[j].first != v[i].first) { while(j > i) { swap(v[j], v[j - 1]); j--; } break; } } for(int i = N - 1; i > 0; i--) { if(v[i].first != v[i - 1].first) continue; for(int j = i - 2; j >= 0; j--) if(v[j].first != v[i].first) { while(j < i - 1) { swap(v[j], v[j + 1]); j++; } break; } } int ans = 0; for(int i = 0; i < v.size(); i++) if(v[i].second > i) ans += v[i].second - i; cout << ans << '\n'; return 0; }

Compilation message (stderr)

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:56:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < v.size(); 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...