답안 #934344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
934344 2024-02-27T07:52:15 Z irmuun 벽 칠하기 (APIO20_paint) C++17
12 / 100
49 ms 13904 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 minimumInstructions(int n,int m,int k,vector<int>C,vector<int>A,vector<vector<int>>B){
    vector<int>cnt(k,0);
    vector<int>pos[k];
    int mx=0;
    for(int i=0;i<m;i++){
        for(auto x:B[i]){
            cnt[x]++;
            mx=max(mx,cnt[x]);
            pos[x].pb(i);
        }
    }
    if(mx<=1){
        vector<int>can(k,-1);
        for(int i=0;i<m;i++){
            for(int j=0;j<A[i];j++){
                can[B[i][j]]=i;
            }
        }
        for(int i=0;i<n;i++){
            if(can[C[i]]==-1) return -1;
        }
        vector<int>count(n,0);
        int cur=1;
        count[n-1]=1;
        for(int i=n-2;i>=0;i--){
            if(can[C[i]]==can[C[i+1]]-1||(can[C[i+1]]==0&&can[C[i]]==m-1)){
                cur++;
            }
            else{
                cur=1;
            }
            count[i]=cur;
        }
        int ans=0;
        bool ok=true;
        if(count[0]<m) return -1;
        ans++;
        int r=m-1,nxt=0;
        for(int i=1;i<n;i++){
            if(count[i]>=m){
                nxt=i;
            }
            if(i>r){
                r=nxt+m-1;
                if(i>r) return -1;
                ans++;
            }
        }
        return ans;
    }
    vector<int>q(m),q1(m,-1e9);
    vector<int>L(n,-1e9);
    vector<int>change,back;
    for(int j=0;j<m;j++){
        for(auto j:pos[C[j]]){
            q[j]=1;
            L[n-1]=1;
            change.pb(j);
        }
    }
    for(int i=n-2;i>=0;i--){
        back=change;
        for(auto j:change){
            q1[j]=q[j];
        }
        change.clear();
        for(auto j:pos[C[i]]){
            if(i==n-1||q1[(j+1)%m]==-1e9){
                q[j]=1;
                change.pb(j);
            }
            else{
                q[j]=q1[(j+1)%m]+1;
                change.pb(j);
            }
            L[i]=max(L[i],q[j]);
        }
        for(auto j:back){
            q1[j]=-1e9;
        }
    }
    vector<int>mn(n+1,1e9);
    mn[n]=0;
    multiset<int>st;
    for(int i=n-m+1;i<=n;i++){
        st.insert(mn[i]);
    }
    for(int i=n-m;i>=0;i--){
        bool ok=(L[i]>=m);
        if(ok){
            mn[i]=*st.begin()+1;
        }
        st.erase(st.find(mn[i+m]));
        st.insert(mn[i]);
    }
    if(mn[0]>=1e9) return -1;
    return mn[0];
}

Compilation message

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:46:14: warning: unused variable 'ok' [-Wunused-variable]
   46 |         bool ok=true;
      |              ^~
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 3 ms 3420 KB Output is correct
14 Correct 2 ms 3416 KB Output is correct
15 Correct 2 ms 3416 KB Output is correct
16 Correct 2 ms 3520 KB Output is correct
17 Correct 2 ms 3420 KB Output is correct
18 Correct 2 ms 3420 KB Output is correct
19 Correct 3 ms 3416 KB Output is correct
20 Correct 2 ms 3420 KB Output is correct
21 Correct 2 ms 3420 KB Output is correct
22 Correct 18 ms 7416 KB Output is correct
23 Correct 19 ms 7260 KB Output is correct
24 Correct 17 ms 7668 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 508 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 600 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 7 ms 4700 KB Output is correct
32 Correct 7 ms 4700 KB Output is correct
33 Correct 7 ms 4720 KB Output is correct
34 Correct 7 ms 4700 KB Output is correct
35 Correct 7 ms 4716 KB Output is correct
36 Correct 7 ms 4604 KB Output is correct
37 Correct 18 ms 7832 KB Output is correct
38 Correct 17 ms 7792 KB Output is correct
39 Correct 17 ms 8060 KB Output is correct
40 Correct 8 ms 1372 KB Output is correct
41 Correct 5 ms 1116 KB Output is correct
42 Correct 9 ms 1372 KB Output is correct
43 Correct 6 ms 1116 KB Output is correct
44 Correct 5 ms 1116 KB Output is correct
45 Correct 9 ms 1368 KB Output is correct
46 Correct 40 ms 13004 KB Output is correct
47 Correct 20 ms 8280 KB Output is correct
48 Correct 23 ms 10588 KB Output is correct
49 Correct 29 ms 10836 KB Output is correct
50 Correct 36 ms 10740 KB Output is correct
51 Correct 22 ms 8024 KB Output is correct
52 Correct 8 ms 1372 KB Output is correct
53 Correct 8 ms 1372 KB Output is correct
54 Correct 9 ms 1368 KB Output is correct
55 Correct 8 ms 1624 KB Output is correct
56 Correct 8 ms 1624 KB Output is correct
57 Correct 8 ms 1372 KB Output is correct
58 Correct 40 ms 13648 KB Output is correct
59 Correct 37 ms 13904 KB Output is correct
60 Correct 35 ms 13652 KB Output is correct
61 Correct 35 ms 13500 KB Output is correct
62 Correct 36 ms 13656 KB Output is correct
63 Correct 42 ms 13652 KB Output is correct
64 Correct 35 ms 12884 KB Output is correct
65 Correct 36 ms 12892 KB Output is correct
66 Correct 49 ms 12924 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 3 ms 3420 KB Output is correct
14 Correct 2 ms 3416 KB Output is correct
15 Correct 2 ms 3416 KB Output is correct
16 Correct 2 ms 3520 KB Output is correct
17 Correct 2 ms 3420 KB Output is correct
18 Correct 2 ms 3420 KB Output is correct
19 Correct 3 ms 3416 KB Output is correct
20 Correct 2 ms 3420 KB Output is correct
21 Correct 2 ms 3420 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 600 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Incorrect 0 ms 348 KB Output isn't correct
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 3 ms 3420 KB Output is correct
16 Correct 2 ms 3416 KB Output is correct
17 Correct 2 ms 3416 KB Output is correct
18 Correct 2 ms 3520 KB Output is correct
19 Correct 2 ms 3420 KB Output is correct
20 Correct 2 ms 3420 KB Output is correct
21 Correct 3 ms 3416 KB Output is correct
22 Correct 2 ms 3420 KB Output is correct
23 Correct 2 ms 3420 KB Output is correct
24 Correct 18 ms 7416 KB Output is correct
25 Correct 19 ms 7260 KB Output is correct
26 Correct 17 ms 7668 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Incorrect 0 ms 348 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 3 ms 3420 KB Output is correct
16 Correct 2 ms 3416 KB Output is correct
17 Correct 2 ms 3416 KB Output is correct
18 Correct 2 ms 3520 KB Output is correct
19 Correct 2 ms 3420 KB Output is correct
20 Correct 2 ms 3420 KB Output is correct
21 Correct 3 ms 3416 KB Output is correct
22 Correct 2 ms 3420 KB Output is correct
23 Correct 2 ms 3420 KB Output is correct
24 Correct 18 ms 7416 KB Output is correct
25 Correct 19 ms 7260 KB Output is correct
26 Correct 17 ms 7668 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 508 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 600 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 7 ms 4700 KB Output is correct
34 Correct 7 ms 4700 KB Output is correct
35 Correct 7 ms 4720 KB Output is correct
36 Correct 7 ms 4700 KB Output is correct
37 Correct 7 ms 4716 KB Output is correct
38 Correct 7 ms 4604 KB Output is correct
39 Correct 18 ms 7832 KB Output is correct
40 Correct 17 ms 7792 KB Output is correct
41 Correct 17 ms 8060 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Incorrect 0 ms 348 KB Output isn't correct
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 3 ms 3420 KB Output is correct
16 Correct 2 ms 3416 KB Output is correct
17 Correct 2 ms 3416 KB Output is correct
18 Correct 2 ms 3520 KB Output is correct
19 Correct 2 ms 3420 KB Output is correct
20 Correct 2 ms 3420 KB Output is correct
21 Correct 3 ms 3416 KB Output is correct
22 Correct 2 ms 3420 KB Output is correct
23 Correct 2 ms 3420 KB Output is correct
24 Correct 18 ms 7416 KB Output is correct
25 Correct 19 ms 7260 KB Output is correct
26 Correct 17 ms 7668 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 508 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 600 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 7 ms 4700 KB Output is correct
34 Correct 7 ms 4700 KB Output is correct
35 Correct 7 ms 4720 KB Output is correct
36 Correct 7 ms 4700 KB Output is correct
37 Correct 7 ms 4716 KB Output is correct
38 Correct 7 ms 4604 KB Output is correct
39 Correct 18 ms 7832 KB Output is correct
40 Correct 17 ms 7792 KB Output is correct
41 Correct 17 ms 8060 KB Output is correct
42 Correct 8 ms 1372 KB Output is correct
43 Correct 5 ms 1116 KB Output is correct
44 Correct 9 ms 1372 KB Output is correct
45 Correct 6 ms 1116 KB Output is correct
46 Correct 5 ms 1116 KB Output is correct
47 Correct 9 ms 1368 KB Output is correct
48 Correct 40 ms 13004 KB Output is correct
49 Correct 20 ms 8280 KB Output is correct
50 Correct 23 ms 10588 KB Output is correct
51 Correct 29 ms 10836 KB Output is correct
52 Correct 36 ms 10740 KB Output is correct
53 Correct 22 ms 8024 KB Output is correct
54 Correct 8 ms 1372 KB Output is correct
55 Correct 8 ms 1372 KB Output is correct
56 Correct 9 ms 1368 KB Output is correct
57 Correct 8 ms 1624 KB Output is correct
58 Correct 8 ms 1624 KB Output is correct
59 Correct 8 ms 1372 KB Output is correct
60 Correct 40 ms 13648 KB Output is correct
61 Correct 37 ms 13904 KB Output is correct
62 Correct 35 ms 13652 KB Output is correct
63 Correct 35 ms 13500 KB Output is correct
64 Correct 36 ms 13656 KB Output is correct
65 Correct 42 ms 13652 KB Output is correct
66 Correct 35 ms 12884 KB Output is correct
67 Correct 36 ms 12892 KB Output is correct
68 Correct 49 ms 12924 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Incorrect 0 ms 348 KB Output isn't correct
71 Halted 0 ms 0 KB -