제출 #136801

#제출 시각아이디문제언어결과실행 시간메모리
136801SirCenessGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
0 / 100
2 ms376 KiB
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define mp make_pair #define pb push_back #define bas(x) #x << ": " << x << " " #define prarr(x, n) cout << #x << ": "; for (int qsd = 0; qsd < n; qsd++) cout << x[qsd] << " "; cout << endl; #define prarrv(x) cout << #x << ": "; for (int qsd = 0; qsd < (int)x.size(); qsd++) cout << x[qsd] << " "; cout << endl; #define ppair(x) "(" << x.first << ", " << x.second << ")" #define inside sl<=l&&r<=sr #define outside sr<l||r<sl typedef long long ll; int main(){ //freopen("in", "r", stdin); //freopen("out", "w", stdout); int n; cin >> n; string s; cin >> s; int fazla = 0; char son = s[0]; ll ans = 0; string yeni; yeni += son; for (int i = 1; i < n; i++){ //cout << bas(i) << endl; //cout << bas(fazla) << endl; if (fazla == 0){ if (son == s[i]) fazla++; else { son = s[i]; yeni += s[i]; } } else { if (son == s[i]) fazla++; else { ans += fazla; fazla--; yeni += s[i]; yeni += son; } } //cout << bas(fazla) << endl; } while (fazla--) yeni += son; reverse(yeni.begin(), yeni.end()); //cout << yeni << endl; //cout << ans << endl; fazla = 0; son = yeni[0]; for (int i = 1; i < n; i++){ //cout << bas(i) << endl; //cout << bas(fazla) << endl; if (fazla == 0){ if (son == yeni[i]) fazla++; else { son = yeni[i]; } } else { if (son == yeni[i]) fazla++; else { ans += fazla; fazla--; } } //cout << bas(fazla) << endl; } if (fazla != 0) cout << -1; else cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...