답안 #391311

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
391311 2021-04-18T13:37:39 Z hhhhaura Snake Escaping (JOI18_snake_escaping) C++14
58 / 100
2000 ms 30184 KB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b) for(int i = a; i <= b; i++)

#define INF 1000000000000000000
#define MAXN 1000005
#define MOD 1000000007
#define eps (1e-9)

#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

using namespace std;
#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a )
void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ",kout(e...);}
#else 
#define print(...) 0
#define vprint(...) 0
#endif
namespace solver {
	int L; string s;
	vector<int> sp, sb, cnt;
	void init_(int _L, string _s) {
		L = _L, s = _s;
		sp.assign(1 << L, 0);
		sb.assign(1 << L, 0);
		cnt.assign(1 << L, 0);
		
		rep(i, 0, (1 << L) - 1) {
			sp[i] = s[i] - '0';
			sb[i] = s[i] - '0';
			cnt[i] = __builtin_popcount(i);
		}
		rep(i, 0, L - 1) {
			rep(j, 0, (1 << L) - 1) 
				if(!((j >> i) & 1)) sp[j] += sp[j ^ (1 << i)];
			rrep(j, 0, (1 << L) - 1) 
				if((j >> i) & 1) sb[j] += sb[j ^ (1 << i)];
		}
	}
	int query(string a) {
		int A = 0, B = 0, C = 0;
		rep(i, 0, L - 1) {
			if(a[i] == '1') B |= (1 << (L - 1 - i));
			else if(a[i] == '0') A |= (1 << (L - 1 - i));
			else C |= (1 << (L - 1 - i));
		}
		int mn = min({cnt[A], cnt[B], cnt[C]});
		if(cnt[A] == mn) { 
			print("A");
			int ans = sp[B];
			for(int i = A; i > 0; i = (i - 1) & A) {
				ans += sp[i | B] * ((cnt[i] & 1) ? -1 : 1);
			}
			return ans;
		}
		else if(cnt[B] == mn) { 
			print("B");
			int ans = sb[C] * ((cnt[B] & 1) ? -1 : 1);
			for(int i = B; i > 0; i = (i - 1) & B) {
				ans += sb[C | i] * (((cnt[B] - cnt[i]) & 1) ? -1 : 1);
			}
			return ans;
		}
		else {
			int ans = s[B] - '0';
			print("C");
			for(int i = C; i > 0; i = (i - 1) & C) {
				ans += s[B | i] - '0';
			}
			return ans;
		}
	} 
};
using namespace solver;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int L, Q; cin >> L >> Q;
	string s; cin >> s;
	init_(L, s);
	rep(i, 1, Q) {
		string cur; cin >> cur;
		cout << query(cur) << "\n";
	}
	return 0;
}

Compilation message

snake_escaping.cpp:4: warning: ignoring #pragma loop  [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
snake_escaping.cpp:24:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts'
   24 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |             ^~~~
snake_escaping.cpp:24:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts'
   24 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |                     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 356 KB Output is correct
2 Correct 10 ms 332 KB Output is correct
3 Correct 10 ms 332 KB Output is correct
4 Correct 10 ms 332 KB Output is correct
5 Correct 10 ms 328 KB Output is correct
6 Correct 10 ms 332 KB Output is correct
7 Correct 10 ms 332 KB Output is correct
8 Correct 10 ms 372 KB Output is correct
9 Correct 10 ms 364 KB Output is correct
10 Correct 11 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 356 KB Output is correct
2 Correct 10 ms 332 KB Output is correct
3 Correct 10 ms 332 KB Output is correct
4 Correct 10 ms 332 KB Output is correct
5 Correct 10 ms 328 KB Output is correct
6 Correct 10 ms 332 KB Output is correct
7 Correct 10 ms 332 KB Output is correct
8 Correct 10 ms 372 KB Output is correct
9 Correct 10 ms 364 KB Output is correct
10 Correct 11 ms 332 KB Output is correct
11 Execution timed out 2079 ms 6424 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 356 KB Output is correct
2 Correct 10 ms 332 KB Output is correct
3 Correct 10 ms 332 KB Output is correct
4 Correct 10 ms 332 KB Output is correct
5 Correct 10 ms 328 KB Output is correct
6 Correct 10 ms 332 KB Output is correct
7 Correct 10 ms 332 KB Output is correct
8 Correct 10 ms 372 KB Output is correct
9 Correct 10 ms 364 KB Output is correct
10 Correct 11 ms 332 KB Output is correct
11 Execution timed out 2079 ms 6424 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 356 KB Output is correct
2 Correct 10 ms 332 KB Output is correct
3 Correct 10 ms 332 KB Output is correct
4 Correct 10 ms 332 KB Output is correct
5 Correct 10 ms 328 KB Output is correct
6 Correct 10 ms 332 KB Output is correct
7 Correct 10 ms 332 KB Output is correct
8 Correct 10 ms 372 KB Output is correct
9 Correct 10 ms 364 KB Output is correct
10 Correct 11 ms 332 KB Output is correct
11 Correct 588 ms 29912 KB Output is correct
12 Correct 578 ms 30032 KB Output is correct
13 Correct 584 ms 29984 KB Output is correct
14 Correct 632 ms 29956 KB Output is correct
15 Correct 577 ms 30012 KB Output is correct
16 Correct 610 ms 30048 KB Output is correct
17 Correct 601 ms 29944 KB Output is correct
18 Correct 560 ms 30184 KB Output is correct
19 Correct 566 ms 29852 KB Output is correct
20 Correct 579 ms 29924 KB Output is correct
21 Correct 589 ms 29916 KB Output is correct
22 Correct 613 ms 30064 KB Output is correct
23 Correct 576 ms 29940 KB Output is correct
24 Correct 615 ms 30060 KB Output is correct
25 Correct 602 ms 30004 KB Output is correct
26 Correct 569 ms 29828 KB Output is correct
27 Correct 572 ms 30044 KB Output is correct
28 Correct 574 ms 29788 KB Output is correct
29 Correct 593 ms 29940 KB Output is correct
30 Correct 588 ms 30080 KB Output is correct
31 Correct 591 ms 29916 KB Output is correct
32 Correct 617 ms 30008 KB Output is correct
33 Correct 616 ms 29992 KB Output is correct
34 Correct 561 ms 29852 KB Output is correct
35 Correct 595 ms 29916 KB Output is correct
36 Correct 599 ms 30032 KB Output is correct
37 Correct 599 ms 30072 KB Output is correct
38 Correct 605 ms 29940 KB Output is correct
39 Correct 596 ms 29948 KB Output is correct
40 Correct 594 ms 30140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 356 KB Output is correct
2 Correct 10 ms 332 KB Output is correct
3 Correct 10 ms 332 KB Output is correct
4 Correct 10 ms 332 KB Output is correct
5 Correct 10 ms 328 KB Output is correct
6 Correct 10 ms 332 KB Output is correct
7 Correct 10 ms 332 KB Output is correct
8 Correct 10 ms 372 KB Output is correct
9 Correct 10 ms 364 KB Output is correct
10 Correct 11 ms 332 KB Output is correct
11 Execution timed out 2079 ms 6424 KB Time limit exceeded
12 Halted 0 ms 0 KB -