# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
978928 | 2024-05-10T03:39:47 Z | irmuun | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 500 ms | 348 KB |
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(s) s.begin(),s.end() #define rall(s) s.rbegin(),s.rend() int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin>>n; string s; cin>>s; string t=s; sort(all(t)); vector<char>ch={'R','G','Y'}; int ans=1e9; do{ bool ok=true; for(int i=1;i<n;i++){ if(t[i-1]==t[i]){ ok=false; } } if(!ok) continue; int cur=0; for(char c:ch){ vector<int>v,u; for(int i=0;i<n;i++){ if(s[i]==c) v.pb(i); if(t[i]==c) u.pb(i); } for(int i=0;i<v.size();i++){ cur+=abs(v[i]-u[i]); } } ans=min(ans,cur/2); }while(next_permutation(all(t))); if(ans==1e9) ans=-1; cout<<ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 5 ms | 348 KB | Output is correct |
6 | Correct | 11 ms | 348 KB | Output is correct |
7 | Correct | 7 ms | 348 KB | Output is correct |
8 | Correct | 11 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 344 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Incorrect | 6 ms | 348 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 5 ms | 348 KB | Output is correct |
6 | Correct | 11 ms | 348 KB | Output is correct |
7 | Correct | 7 ms | 348 KB | Output is correct |
8 | Correct | 11 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 344 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Incorrect | 6 ms | 348 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Execution timed out | 1078 ms | 348 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 5 ms | 348 KB | Output is correct |
6 | Correct | 11 ms | 348 KB | Output is correct |
7 | Correct | 7 ms | 348 KB | Output is correct |
8 | Correct | 11 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 344 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Incorrect | 6 ms | 348 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |