이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,k,x,y,z;
int val['z'];
char ar[405], tar[405];
int cal() {
int pos[405];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (ar[i] == tar[j]) {
pos[i] = j;
tar[j] = '#';
goto nxt;
}
}
return 1e9;
nxt:;
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
ans += (pos[i] < pos[j]);
}
}
return ans;
}
int main() {
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> ar[i];
for (int i = 1; i <= n; i++) tar[i] = (i & 1 ? 'R' : 'G');
int ans = cal();
for (int i = 1; i <= n; i++) tar[i] = (i & 1 ? 'G' : 'R');
ans = min(ans,cal());
if (ans > 1e8) cout << "-1\n";
else cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |