답안 #978930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
978930 2024-05-10T03:43:33 Z irmuun Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
0 / 100
500 ms 452 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 dist(string s,string t){//t->s
    int res=0;
    for(int i=0;i<s.size();i++){
        for(int j=i;j<t.size();j++){
            if(t[j]==s[i]){
                for(int k=i;k<j;k++){
                    res++;
                    swap(t[k],t[k+1]);
                }
                break;
            }
        }
    }
    return res;
}

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;
        ans=min(ans,dist(s,t));
    }while(next_permutation(all(t)));
    if(ans==1e9) ans=-1;
    cout<<ans;
}

Compilation message

joi2019_ho_t3.cpp: In function 'int dist(std::string, std::string)':
joi2019_ho_t3.cpp:14:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~
joi2019_ho_t3.cpp:15:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |         for(int j=i;j<t.size();j++){
      |                     ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 6 ms 452 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 6 ms 452 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 1094 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 6 ms 452 KB Output isn't correct
6 Halted 0 ms 0 KB -