답안 #927867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927867 2024-02-15T12:28:52 Z Unforgettablepl Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
5 / 100
500 ms 600 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int INF = 1e15;
int n;

int calc(vector<int> arr,int start,int mask){
    vector<int> target = {start};
    for(int bit=0;bit<n;bit++){
        target.emplace_back(target.back()+1);
        if(mask&(1<<bit))target.back()++;
        target.back()%=3;
    }
    int ans = 0;
    for(int i=0;i<arr.size();i++){
        int idx = find(arr.begin()+i, arr.end(),target[i])-arr.begin();
        if(idx==arr.size())return INF;
        ans+=idx-i;
        arr.erase(arr.begin()+idx);
        arr.insert(arr.begin()+i,target[i]);
    }
    return ans;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    vector<int> arr;
    for(int i=1;i<=n;i++){
        char a;
        cin>>a;
        if(a=='R') arr.emplace_back(0);
        else if(a=='G') arr.emplace_back(1);
        else arr.emplace_back(2);
    }
    int ans = INF;
    n--;
    for(int start=0;start<3;start++){
        for(int mask=0;mask<(1<<n);mask++){
            ans = min(ans,calc(arr,start,mask));
        }
    }
    cout << (ans>=INF ? -1 : ans) << '\n';
}

Compilation message

joi2019_ho_t3.cpp: In function 'long long int calc(std::vector<long long int>, long long int, long long int)':
joi2019_ho_t3.cpp:17:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i=0;i<arr.size();i++){
      |                 ~^~~~~~~~~~~
joi2019_ho_t3.cpp:19:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |         if(idx==arr.size())return INF;
      |            ~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 19 ms 348 KB Output is correct
6 Correct 20 ms 348 KB Output is correct
7 Correct 20 ms 348 KB Output is correct
8 Correct 21 ms 452 KB Output is correct
9 Correct 14 ms 456 KB Output is correct
10 Correct 11 ms 460 KB Output is correct
11 Correct 19 ms 348 KB Output is correct
12 Correct 21 ms 456 KB Output is correct
13 Correct 18 ms 348 KB Output is correct
14 Correct 11 ms 600 KB Output is correct
15 Correct 24 ms 456 KB Output is correct
16 Correct 14 ms 512 KB Output is correct
17 Correct 6 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 19 ms 348 KB Output is correct
6 Correct 20 ms 348 KB Output is correct
7 Correct 20 ms 348 KB Output is correct
8 Correct 21 ms 452 KB Output is correct
9 Correct 14 ms 456 KB Output is correct
10 Correct 11 ms 460 KB Output is correct
11 Correct 19 ms 348 KB Output is correct
12 Correct 21 ms 456 KB Output is correct
13 Correct 18 ms 348 KB Output is correct
14 Correct 11 ms 600 KB Output is correct
15 Correct 24 ms 456 KB Output is correct
16 Correct 14 ms 512 KB Output is correct
17 Correct 6 ms 456 KB Output is correct
18 Execution timed out 1048 ms 348 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 560 KB Output is correct
2 Incorrect 277 ms 448 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 19 ms 348 KB Output is correct
6 Correct 20 ms 348 KB Output is correct
7 Correct 20 ms 348 KB Output is correct
8 Correct 21 ms 452 KB Output is correct
9 Correct 14 ms 456 KB Output is correct
10 Correct 11 ms 460 KB Output is correct
11 Correct 19 ms 348 KB Output is correct
12 Correct 21 ms 456 KB Output is correct
13 Correct 18 ms 348 KB Output is correct
14 Correct 11 ms 600 KB Output is correct
15 Correct 24 ms 456 KB Output is correct
16 Correct 14 ms 512 KB Output is correct
17 Correct 6 ms 456 KB Output is correct
18 Execution timed out 1048 ms 348 KB Time limit exceeded
19 Halted 0 ms 0 KB -