제출 #708656

#제출 시각아이디문제언어결과실행 시간메모리
708656ngano_upat_naMiners (IOI07_miners)C++17
25 / 100
21 ms540 KiB
#include "bits/stdc++.h" using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; string s; cin >> n >> s; char cur1 = '?', prev1 = '?'; char cur2 = '?', prev2 = '?'; int ans = 0; string A, B; for (int i=0; i<n; i++) { set<char> a, b; a.insert(s[i]); if (cur1 != '?') a.insert(cur1); if (prev1 != '?') a.insert(prev1); b.insert(s[i]); if (cur2 != '?') b.insert(cur2); if (prev2 != '?') b.insert(prev2); ans = ans + max((int)a.size(),(int)b.size()); if ((int)a.size() > (int)b.size()) { prev1 = cur1; cur1 = s[i]; A.push_back(s[i]); } if ((int)a.size() < (int)b.size()) { prev2 = cur2; cur2 = s[i]; B.push_back(s[i]); } if ((int)a.size() == (int)b.size()) { if ((cur1 == s[i] && cur2 == s[i]) || (cur1 != s[i] && cur2 != s[i])) { if ((int)A.size() >= (int)B.size()) { prev2 = cur2; cur2 = s[i]; B.push_back(s[i]); } else { prev1 = cur1; cur1 = s[i]; A.push_back(s[i]); } } else { if (cur1 != s[i]) { prev1 = cur1; cur1 = s[i]; A.push_back(s[i]); } else { prev2 = cur2; cur2 = s[i]; B.push_back(s[i]); } } } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...