답안 #597722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
597722 2022-07-16T17:08:06 Z cfalas 벽 칠하기 (APIO20_paint) C++17
28 / 100
1500 ms 524288 KB
#include<bits/stdc++.h>
using namespace std;
#include "paint.h"
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;

#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)

int M, N;
vi c;
map<int, vector<int>> f;

bool check(int j){
	unordered_set<int> poss;
	FOA(v, f[c[j]]) poss.insert(v);
	FORi(i,1,M){
		unordered_set<int> npos;
		FOA(v, f[c[j+i]]){
			int pp = (v-i + M)%M;
			if(poss.count(pp)) npos.insert(pp);
		}
		poss = npos;
	}
	return !poss.empty();
}

struct seg{
	unordered_set<int> val;
	seg *L, *R;
 
	unordered_set<int> merge(unordered_set<int> &a, int as, unordered_set<int> &b){
		unordered_set<int> ans;
		FOA(v,a){
			if(b.count((v + as)%M)) ans.insert(v);
		}
		return ans;
	}
 
	void build(int l=0, int r=N-1){
		if(l==r){
			FOA(v, f[c[l]]){
				val.insert(v);
			}
		}
		else{
			L = new seg;
			R = new seg;
 
			L->build(l,MID);
			R->build(MID+1,r);
 
			val = merge(L->val, MID-l+1, R->val);
		}
	}
 
	unordered_set<int> query(int rl, int rr, int l=0, int r=N-1){
		if(rl<=l && r<=rr) return val;
		else if(rr<l || r<rl) return unordered_set<int>();
		else{
			unordered_set<int> sl = L->query(rl,rr,l,MID);
			unordered_set<int> sr = R->query(rl,rr,MID+1,r);
			if(rr<=MID){
				/*
				cout<<"Return left "<<l<<" "<<r<<": ";
				FOA(v,sl) cout<<v<<" ";
				cout<<endl;*/
				return sl;
			}
			if(rl>MID){
				/*
				cout<<"Return right "<<l<<" "<<r<<": ";
				FOA(v,sr) cout<<v<<" ";
				cout<<endl;*/
				return sr;
			}
			//cout<<"merge "<<l<<" "<<r<<": ";
			unordered_set<int> qq;
			if(l<=rl) qq = merge(sl, MID-rl+1, sr);
			else qq = merge(sl, MID-l+1, sr);
			/*
			FOA(v, sl) cout<<v<<" ";
			cout<<" | ";
			FOA(v, sr) cout<<v<<" ";
			cout<<" | ";
			FOA(v, qq) cout<<v<<" ";
			cout<<endl;*/
			return qq;
		}
	}
 
	void print(int l=0, int r=N-1){
		cout<<l<<" "<<r<<": ";
		FOA(v, val) cout<<v<<" ";
		cout<<endl;
		if(l!=r){
			L->print(l, MID);
			R->print(MID+1,r);
		}
	}
};

int minimumInstructions(int n, int m, int K, std::vector<int> C, 
						vector<int> A, vector<std::vector<int>> B) {
	M = m;
	N = n;
	c = C;
	FOR(i,M){
		FOA(v, B[i]){
			f[v].push_back(i);
		}
	}
	seg s;
	s.build();
	if(s.query(0, M-1).empty()) return -1;
	int p=0;
	int cp=M;
	int ans = 1;
	while(cp<N){
		//cout<<p<<" "<<cp<<endl;
		while(!check(cp)) cp--;
		if(cp<=p) return -1;
		p = cp;
		cp+=M;
		ans++;
	}
  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 6 ms 608 KB Output is correct
14 Correct 6 ms 612 KB Output is correct
15 Correct 5 ms 556 KB Output is correct
16 Correct 6 ms 608 KB Output is correct
17 Correct 6 ms 608 KB Output is correct
18 Correct 8 ms 596 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 65 ms 12732 KB Output is correct
23 Correct 60 ms 12604 KB Output is correct
24 Correct 49 ms 12644 KB Output is correct
25 Correct 19 ms 9300 KB Output is correct
26 Correct 18 ms 9308 KB Output is correct
27 Correct 11 ms 7252 KB Output is correct
28 Correct 10 ms 6868 KB Output is correct
29 Correct 10 ms 6740 KB Output is correct
30 Correct 12 ms 6740 KB Output is correct
31 Correct 38 ms 11988 KB Output is correct
32 Correct 44 ms 11896 KB Output is correct
33 Correct 35 ms 11888 KB Output is correct
34 Correct 34 ms 11988 KB Output is correct
35 Correct 34 ms 11952 KB Output is correct
36 Correct 34 ms 11956 KB Output is correct
37 Correct 91 ms 18820 KB Output is correct
38 Correct 107 ms 18984 KB Output is correct
39 Correct 97 ms 18824 KB Output is correct
40 Correct 81 ms 41316 KB Output is correct
41 Correct 52 ms 25944 KB Output is correct
42 Correct 52 ms 34444 KB Output is correct
43 Correct 35 ms 22216 KB Output is correct
44 Correct 29 ms 19796 KB Output is correct
45 Correct 47 ms 32440 KB Output is correct
46 Execution timed out 1591 ms 54784 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 6 ms 608 KB Output is correct
14 Correct 6 ms 612 KB Output is correct
15 Correct 5 ms 556 KB Output is correct
16 Correct 6 ms 608 KB Output is correct
17 Correct 6 ms 608 KB Output is correct
18 Correct 8 ms 596 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 244 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 296 KB Output is correct
27 Correct 1 ms 428 KB Output is correct
28 Correct 3 ms 980 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 1 ms 684 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 4 ms 468 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 4 ms 472 KB Output is correct
36 Correct 5 ms 468 KB Output is correct
37 Correct 2 ms 436 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 1 ms 468 KB Output is correct
45 Correct 7 ms 1832 KB Output is correct
46 Correct 2 ms 980 KB Output is correct
47 Correct 1 ms 852 KB Output is correct
48 Correct 2 ms 724 KB Output is correct
49 Correct 1 ms 724 KB Output is correct
50 Correct 6 ms 556 KB Output is correct
51 Correct 6 ms 612 KB Output is correct
52 Correct 6 ms 596 KB Output is correct
53 Correct 6 ms 596 KB Output is correct
54 Correct 6 ms 596 KB Output is correct
55 Correct 6 ms 596 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 6 ms 596 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 7 ms 564 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 6 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 244 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 300 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 6 ms 608 KB Output is correct
16 Correct 6 ms 612 KB Output is correct
17 Correct 5 ms 556 KB Output is correct
18 Correct 6 ms 608 KB Output is correct
19 Correct 6 ms 608 KB Output is correct
20 Correct 8 ms 596 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 65 ms 12732 KB Output is correct
25 Correct 60 ms 12604 KB Output is correct
26 Correct 49 ms 12644 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 296 KB Output is correct
30 Correct 1 ms 428 KB Output is correct
31 Correct 3 ms 980 KB Output is correct
32 Correct 1 ms 596 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 1 ms 684 KB Output is correct
35 Correct 1 ms 596 KB Output is correct
36 Correct 4 ms 468 KB Output is correct
37 Correct 3 ms 468 KB Output is correct
38 Correct 4 ms 472 KB Output is correct
39 Correct 5 ms 468 KB Output is correct
40 Correct 2 ms 436 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 7 ms 1832 KB Output is correct
49 Correct 2 ms 980 KB Output is correct
50 Correct 1 ms 852 KB Output is correct
51 Correct 2 ms 724 KB Output is correct
52 Correct 1 ms 724 KB Output is correct
53 Correct 6 ms 556 KB Output is correct
54 Correct 6 ms 612 KB Output is correct
55 Correct 6 ms 596 KB Output is correct
56 Correct 6 ms 596 KB Output is correct
57 Correct 6 ms 596 KB Output is correct
58 Correct 6 ms 596 KB Output is correct
59 Correct 1 ms 468 KB Output is correct
60 Correct 6 ms 596 KB Output is correct
61 Correct 1 ms 468 KB Output is correct
62 Correct 7 ms 564 KB Output is correct
63 Correct 1 ms 468 KB Output is correct
64 Correct 6 ms 596 KB Output is correct
65 Correct 214 ms 4308 KB Output is correct
66 Correct 6 ms 1956 KB Output is correct
67 Correct 16 ms 5192 KB Output is correct
68 Correct 8 ms 3520 KB Output is correct
69 Correct 26 ms 4564 KB Output is correct
70 Correct 24 ms 1364 KB Output is correct
71 Correct 9 ms 1448 KB Output is correct
72 Correct 11 ms 1364 KB Output is correct
73 Correct 3 ms 980 KB Output is correct
74 Correct 18 ms 1492 KB Output is correct
75 Correct 8 ms 1236 KB Output is correct
76 Correct 53 ms 7880 KB Output is correct
77 Correct 35 ms 9232 KB Output is correct
78 Correct 44 ms 10152 KB Output is correct
79 Correct 253 ms 8660 KB Output is correct
80 Correct 226 ms 8696 KB Output is correct
81 Correct 239 ms 8716 KB Output is correct
82 Correct 228 ms 8660 KB Output is correct
83 Correct 233 ms 8712 KB Output is correct
84 Correct 26 ms 1812 KB Output is correct
85 Correct 24 ms 1620 KB Output is correct
86 Correct 24 ms 1720 KB Output is correct
87 Correct 24 ms 1712 KB Output is correct
88 Correct 24 ms 1620 KB Output is correct
89 Correct 24 ms 1620 KB Output is correct
90 Correct 59 ms 10316 KB Output is correct
91 Correct 73 ms 10352 KB Output is correct
92 Correct 77 ms 10320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 244 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 300 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 6 ms 608 KB Output is correct
16 Correct 6 ms 612 KB Output is correct
17 Correct 5 ms 556 KB Output is correct
18 Correct 6 ms 608 KB Output is correct
19 Correct 6 ms 608 KB Output is correct
20 Correct 8 ms 596 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 65 ms 12732 KB Output is correct
25 Correct 60 ms 12604 KB Output is correct
26 Correct 49 ms 12644 KB Output is correct
27 Correct 19 ms 9300 KB Output is correct
28 Correct 18 ms 9308 KB Output is correct
29 Correct 11 ms 7252 KB Output is correct
30 Correct 10 ms 6868 KB Output is correct
31 Correct 10 ms 6740 KB Output is correct
32 Correct 12 ms 6740 KB Output is correct
33 Correct 38 ms 11988 KB Output is correct
34 Correct 44 ms 11896 KB Output is correct
35 Correct 35 ms 11888 KB Output is correct
36 Correct 34 ms 11988 KB Output is correct
37 Correct 34 ms 11952 KB Output is correct
38 Correct 34 ms 11956 KB Output is correct
39 Correct 91 ms 18820 KB Output is correct
40 Correct 107 ms 18984 KB Output is correct
41 Correct 97 ms 18824 KB Output is correct
42 Correct 1 ms 300 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 1 ms 296 KB Output is correct
45 Correct 1 ms 428 KB Output is correct
46 Correct 3 ms 980 KB Output is correct
47 Correct 1 ms 596 KB Output is correct
48 Correct 1 ms 596 KB Output is correct
49 Correct 1 ms 684 KB Output is correct
50 Correct 1 ms 596 KB Output is correct
51 Correct 4 ms 468 KB Output is correct
52 Correct 3 ms 468 KB Output is correct
53 Correct 4 ms 472 KB Output is correct
54 Correct 5 ms 468 KB Output is correct
55 Correct 2 ms 436 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 1 ms 468 KB Output is correct
59 Correct 2 ms 468 KB Output is correct
60 Correct 1 ms 468 KB Output is correct
61 Correct 2 ms 468 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 7 ms 1832 KB Output is correct
64 Correct 2 ms 980 KB Output is correct
65 Correct 1 ms 852 KB Output is correct
66 Correct 2 ms 724 KB Output is correct
67 Correct 1 ms 724 KB Output is correct
68 Correct 6 ms 556 KB Output is correct
69 Correct 6 ms 612 KB Output is correct
70 Correct 6 ms 596 KB Output is correct
71 Correct 6 ms 596 KB Output is correct
72 Correct 6 ms 596 KB Output is correct
73 Correct 6 ms 596 KB Output is correct
74 Correct 1 ms 468 KB Output is correct
75 Correct 6 ms 596 KB Output is correct
76 Correct 1 ms 468 KB Output is correct
77 Correct 7 ms 564 KB Output is correct
78 Correct 1 ms 468 KB Output is correct
79 Correct 6 ms 596 KB Output is correct
80 Correct 214 ms 4308 KB Output is correct
81 Correct 6 ms 1956 KB Output is correct
82 Correct 16 ms 5192 KB Output is correct
83 Correct 8 ms 3520 KB Output is correct
84 Correct 26 ms 4564 KB Output is correct
85 Correct 24 ms 1364 KB Output is correct
86 Correct 9 ms 1448 KB Output is correct
87 Correct 11 ms 1364 KB Output is correct
88 Correct 3 ms 980 KB Output is correct
89 Correct 18 ms 1492 KB Output is correct
90 Correct 8 ms 1236 KB Output is correct
91 Correct 53 ms 7880 KB Output is correct
92 Correct 35 ms 9232 KB Output is correct
93 Correct 44 ms 10152 KB Output is correct
94 Correct 253 ms 8660 KB Output is correct
95 Correct 226 ms 8696 KB Output is correct
96 Correct 239 ms 8716 KB Output is correct
97 Correct 228 ms 8660 KB Output is correct
98 Correct 233 ms 8712 KB Output is correct
99 Correct 26 ms 1812 KB Output is correct
100 Correct 24 ms 1620 KB Output is correct
101 Correct 24 ms 1720 KB Output is correct
102 Correct 24 ms 1712 KB Output is correct
103 Correct 24 ms 1620 KB Output is correct
104 Correct 24 ms 1620 KB Output is correct
105 Correct 59 ms 10316 KB Output is correct
106 Correct 73 ms 10352 KB Output is correct
107 Correct 77 ms 10320 KB Output is correct
108 Correct 21 ms 10452 KB Output is correct
109 Runtime error 765 ms 524288 KB Execution killed with signal 9
110 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 244 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 300 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 6 ms 608 KB Output is correct
16 Correct 6 ms 612 KB Output is correct
17 Correct 5 ms 556 KB Output is correct
18 Correct 6 ms 608 KB Output is correct
19 Correct 6 ms 608 KB Output is correct
20 Correct 8 ms 596 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 65 ms 12732 KB Output is correct
25 Correct 60 ms 12604 KB Output is correct
26 Correct 49 ms 12644 KB Output is correct
27 Correct 19 ms 9300 KB Output is correct
28 Correct 18 ms 9308 KB Output is correct
29 Correct 11 ms 7252 KB Output is correct
30 Correct 10 ms 6868 KB Output is correct
31 Correct 10 ms 6740 KB Output is correct
32 Correct 12 ms 6740 KB Output is correct
33 Correct 38 ms 11988 KB Output is correct
34 Correct 44 ms 11896 KB Output is correct
35 Correct 35 ms 11888 KB Output is correct
36 Correct 34 ms 11988 KB Output is correct
37 Correct 34 ms 11952 KB Output is correct
38 Correct 34 ms 11956 KB Output is correct
39 Correct 91 ms 18820 KB Output is correct
40 Correct 107 ms 18984 KB Output is correct
41 Correct 97 ms 18824 KB Output is correct
42 Correct 81 ms 41316 KB Output is correct
43 Correct 52 ms 25944 KB Output is correct
44 Correct 52 ms 34444 KB Output is correct
45 Correct 35 ms 22216 KB Output is correct
46 Correct 29 ms 19796 KB Output is correct
47 Correct 47 ms 32440 KB Output is correct
48 Execution timed out 1591 ms 54784 KB Time limit exceeded
49 Halted 0 ms 0 KB -