답안 #521624

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521624 2022-02-02T15:15:51 Z AdamGS Snake Escaping (JOI18_snake_escaping) C++17
75 / 100
1803 ms 65540 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
string S;
void solve(vector<ll>&V, vector<int>&ans, int l, int r, ll akt) {
	if(!V.size()) return;
	if(l==r) {
		ans[0]=S[l]-'0';
		return;
	}
	int ile1=0, ile2=0, ile3=0;
	rep(i, V.size()) {
		if(V[i]/akt==0) ++ile1;
		else if(V[i]/akt==1) ++ile2;
		else ++ile3;
		V[i]%=akt;
	}
	vector<ll>zero, jeden;
	int l1=0, l2=0;
	while(l1<ile1 && l2<ile2) {
		if(V[l1]<=V[ile1+l2]) {
			if(V[l1]==V[ile1+l2]) ++l2;
			zero.pb(V[l1]);
			++l1;
		} else {
			zero.pb(V[ile1+l2]);
			++l2;
		}
	}
	while(l1<ile1) {
		zero.pb(V[l1]); ++l1;
	}
	while(l2<ile2) {
		zero.pb(V[ile1+l2]); ++l2;
	}
	vector<int>zans(zero.size());
	solve(zero, zans, l, (l+r)/2, akt/3);
	l1=0;
	rep(i, ile1) {
		while(zero[l1]<V[i]) ++l1;
		ans[i]+=zans[l1];
	}
	l1=0;
	rep(i, ile2) {
		while(zero[l1]<V[ile1+i]) ++l1;
		ans[ile1+i]+=zans[l1];
	}
	l1=0; l2=0;
	while(l1<ile1 && l2<ile3) {
		if(V[l1]<=V[ile1+ile2+l2]) {
			if(V[l1]==V[ile1+ile2+l2]) ++l2;
			jeden.pb(V[l1]);
			++l1;
		} else {
			jeden.pb(V[ile1+ile2+l2]);
			++l2;
		}
	}
	while(l1<ile1) {
		jeden.pb(V[l1]); ++l1;
	}
	while(l2<ile3) {
		jeden.pb(V[ile1+ile2+l2]); ++l2;
	}
	vector<int>jans(jeden.size());
	solve(jeden, jans, (l+r)/2+1, r, akt/3);
	l1=0;
	rep(i, ile1) {
		while(jeden[l1]<V[i]) ++l1;
		ans[i]+=jans[l1];
	}
	l1=0;
	rep(i, ile3) {
		while(jeden[l1]<V[ile1+ile2+i]) ++l1;
		ans[ile1+ile2+i]+=jans[l1];
	}
	rep(i, ile2) V[ile1+i]+=akt;
	rep(i, ile3) V[ile1+ile2+i]+=2*akt;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int l, q, n=1;
	cin >> l >> q >> S;
	rep(i, l) n*=2;
	pair<ll,int>T[q];
	rep(i, q) {
		string x;
		cin >> x;
		ll p=0;
		for(auto j : x) {
			p*=3;
			if(j=='0') ++p;
			if(j=='1') p+=2;
		}
		T[i]={p, i};
	}
	sort(T, T+q);
	ll akt=1;
	rep(i, l-1) akt*=3;
	vector<ll>V;
	V.pb(T[0].st);
	for(int i=1; i<q; ++i) if(T[i].st!=T[i-1].st) V.pb(T[i].st);
	vector<int>ans(V.size());
	solve(V, ans, 0, n-1, akt);
	int l1=0;
	rep(i, q) {
		while(V[l1]<T[i].st) ++l1;
		T[i]={T[i].nd, ans[l1]};
	}
	sort(T, T+q);
	rep(i, q) cout << T[i].nd << '\n';
}

Compilation message

snake_escaping.cpp: In function 'void solve(std::vector<long long int>&, std::vector<int>&, int, int, ll)':
snake_escaping.cpp:5:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
snake_escaping.cpp:18:2: note: in expansion of macro 'rep'
   18 |  rep(i, V.size()) {
      |  ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 323 ms 19908 KB Output is correct
12 Correct 369 ms 19652 KB Output is correct
13 Correct 374 ms 19152 KB Output is correct
14 Correct 354 ms 19144 KB Output is correct
15 Correct 357 ms 20164 KB Output is correct
16 Correct 359 ms 19528 KB Output is correct
17 Correct 379 ms 20044 KB Output is correct
18 Correct 201 ms 20936 KB Output is correct
19 Correct 342 ms 17864 KB Output is correct
20 Correct 325 ms 19656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 323 ms 19908 KB Output is correct
12 Correct 369 ms 19652 KB Output is correct
13 Correct 374 ms 19152 KB Output is correct
14 Correct 354 ms 19144 KB Output is correct
15 Correct 357 ms 20164 KB Output is correct
16 Correct 359 ms 19528 KB Output is correct
17 Correct 379 ms 20044 KB Output is correct
18 Correct 201 ms 20936 KB Output is correct
19 Correct 342 ms 17864 KB Output is correct
20 Correct 325 ms 19656 KB Output is correct
21 Correct 336 ms 20036 KB Output is correct
22 Correct 397 ms 20528 KB Output is correct
23 Correct 404 ms 24868 KB Output is correct
24 Correct 392 ms 22016 KB Output is correct
25 Correct 384 ms 22012 KB Output is correct
26 Correct 407 ms 30256 KB Output is correct
27 Correct 453 ms 39988 KB Output is correct
28 Correct 210 ms 21988 KB Output is correct
29 Correct 373 ms 18024 KB Output is correct
30 Correct 335 ms 20424 KB Output is correct
31 Correct 415 ms 26348 KB Output is correct
32 Correct 400 ms 21676 KB Output is correct
33 Correct 360 ms 20048 KB Output is correct
34 Correct 424 ms 29740 KB Output is correct
35 Correct 438 ms 39996 KB Output is correct
36 Correct 260 ms 17904 KB Output is correct
37 Correct 391 ms 20060 KB Output is correct
38 Correct 378 ms 18148 KB Output is correct
39 Correct 397 ms 24508 KB Output is correct
40 Correct 389 ms 20652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 213 ms 7212 KB Output is correct
12 Correct 348 ms 6600 KB Output is correct
13 Correct 313 ms 4776 KB Output is correct
14 Correct 604 ms 5376 KB Output is correct
15 Correct 1311 ms 8544 KB Output is correct
16 Correct 759 ms 7956 KB Output is correct
17 Correct 775 ms 8116 KB Output is correct
18 Correct 139 ms 4584 KB Output is correct
19 Correct 53 ms 6048 KB Output is correct
20 Correct 336 ms 9728 KB Output is correct
21 Correct 1100 ms 8848 KB Output is correct
22 Correct 605 ms 8016 KB Output is correct
23 Correct 104 ms 8888 KB Output is correct
24 Correct 522 ms 7484 KB Output is correct
25 Correct 749 ms 7980 KB Output is correct
26 Correct 15 ms 4324 KB Output is correct
27 Correct 219 ms 7856 KB Output is correct
28 Correct 60 ms 6072 KB Output is correct
29 Correct 310 ms 8304 KB Output is correct
30 Correct 482 ms 7276 KB Output is correct
31 Correct 121 ms 7620 KB Output is correct
32 Correct 751 ms 7740 KB Output is correct
33 Correct 753 ms 8076 KB Output is correct
34 Correct 15 ms 4296 KB Output is correct
35 Correct 786 ms 7876 KB Output is correct
36 Correct 750 ms 7812 KB Output is correct
37 Correct 776 ms 7848 KB Output is correct
38 Correct 750 ms 7996 KB Output is correct
39 Correct 770 ms 7780 KB Output is correct
40 Correct 747 ms 7780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 323 ms 19908 KB Output is correct
12 Correct 369 ms 19652 KB Output is correct
13 Correct 374 ms 19152 KB Output is correct
14 Correct 354 ms 19144 KB Output is correct
15 Correct 357 ms 20164 KB Output is correct
16 Correct 359 ms 19528 KB Output is correct
17 Correct 379 ms 20044 KB Output is correct
18 Correct 201 ms 20936 KB Output is correct
19 Correct 342 ms 17864 KB Output is correct
20 Correct 325 ms 19656 KB Output is correct
21 Correct 336 ms 20036 KB Output is correct
22 Correct 397 ms 20528 KB Output is correct
23 Correct 404 ms 24868 KB Output is correct
24 Correct 392 ms 22016 KB Output is correct
25 Correct 384 ms 22012 KB Output is correct
26 Correct 407 ms 30256 KB Output is correct
27 Correct 453 ms 39988 KB Output is correct
28 Correct 210 ms 21988 KB Output is correct
29 Correct 373 ms 18024 KB Output is correct
30 Correct 335 ms 20424 KB Output is correct
31 Correct 415 ms 26348 KB Output is correct
32 Correct 400 ms 21676 KB Output is correct
33 Correct 360 ms 20048 KB Output is correct
34 Correct 424 ms 29740 KB Output is correct
35 Correct 438 ms 39996 KB Output is correct
36 Correct 260 ms 17904 KB Output is correct
37 Correct 391 ms 20060 KB Output is correct
38 Correct 378 ms 18148 KB Output is correct
39 Correct 397 ms 24508 KB Output is correct
40 Correct 389 ms 20652 KB Output is correct
41 Correct 213 ms 7212 KB Output is correct
42 Correct 348 ms 6600 KB Output is correct
43 Correct 313 ms 4776 KB Output is correct
44 Correct 604 ms 5376 KB Output is correct
45 Correct 1311 ms 8544 KB Output is correct
46 Correct 759 ms 7956 KB Output is correct
47 Correct 775 ms 8116 KB Output is correct
48 Correct 139 ms 4584 KB Output is correct
49 Correct 53 ms 6048 KB Output is correct
50 Correct 336 ms 9728 KB Output is correct
51 Correct 1100 ms 8848 KB Output is correct
52 Correct 605 ms 8016 KB Output is correct
53 Correct 104 ms 8888 KB Output is correct
54 Correct 522 ms 7484 KB Output is correct
55 Correct 749 ms 7980 KB Output is correct
56 Correct 15 ms 4324 KB Output is correct
57 Correct 219 ms 7856 KB Output is correct
58 Correct 60 ms 6072 KB Output is correct
59 Correct 310 ms 8304 KB Output is correct
60 Correct 482 ms 7276 KB Output is correct
61 Correct 121 ms 7620 KB Output is correct
62 Correct 751 ms 7740 KB Output is correct
63 Correct 753 ms 8076 KB Output is correct
64 Correct 15 ms 4296 KB Output is correct
65 Correct 786 ms 7876 KB Output is correct
66 Correct 750 ms 7812 KB Output is correct
67 Correct 776 ms 7848 KB Output is correct
68 Correct 750 ms 7996 KB Output is correct
69 Correct 770 ms 7780 KB Output is correct
70 Correct 747 ms 7780 KB Output is correct
71 Correct 632 ms 51556 KB Output is correct
72 Correct 852 ms 65536 KB Output is correct
73 Correct 1803 ms 65536 KB Output is correct
74 Runtime error 1279 ms 65540 KB Execution killed with signal 9
75 Halted 0 ms 0 KB -