답안 #433497

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
433497 2021-06-19T22:45:42 Z rqi 무지개나라 (APIO17_rainbow) C++14
35 / 100
3000 ms 32004 KB
#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

#define mp make_pair
#define f first
#define s second
#define ins insert
#define pb push_back

void ckmin(int& a, int b){
	a = min(a, b);
}

void ckmax(int& a, int b){
	a = max(a, b);
}

vector<char> dchar = vector<char>{'S', 'E', 'N', 'W'};
vi dx = vi{1, 0, -1, 0};
vi dy = vi{0, 1, 0, -1};

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

struct hashFunc{
	size_t operator()(pi a) const {
		ll res = ll(a.f)*200005+ll(a.s);
		ll BIG_RAND = 102923014203249LL;
		return __builtin_bswap64((unsigned long long)(res)*BIG_RAND);
	}
};

struct Off2DBIT{
	vpi all_updates;
	void update(int X, int Y){
		all_updates.pb(mp(X, Y));
	}
	ll query(int xl, int yl, int xr, int yr){
		ll res = 0;
		for(auto& u: all_updates){
			if(xl <= u.f && u.f <= xr && yl <= u.s && u.s <= yr){
				res++;
			}
		}
		return res;
	}
};

Off2DBIT bits[2][2];
gp_hash_table<pi, null_type, hashFunc> rects[4];

int min_sr, max_sr, min_sc, max_sc;

void init(int R, int C, int sr, int sc, int M, char *S) {
	min_sr = sr;
	min_sc = sc;
	max_sr = sr;
	max_sc = sc;
	for(int i = 0; i <= M; i++){
		for(int i = 0; i <= 1; i++){
			for(int j = 0; j <= 1; j++){
				for(int xl = sr-i; xl <= sr; xl++){
					for(int yl = sc-j; yl <= sc; yl++){
						if(1 <= xl && 1 <= yl){
							rects[2*i+j][mp(xl, yl)];
						}
					}
				}
			}
		}
		if(i < M){
			for(int d = 0; d < 4; d++){
				if(S[i] == dchar[d]){
					sr+=dx[d];
					sc+=dy[d];
					break;
				}
			}
		}

		ckmin(min_sr, sr);
		ckmin(min_sc, sc);
		ckmax(max_sr, sr);
		ckmax(max_sc, sc);
	}

	for(int i = 0; i <= 1; i++){
		for(int j = 0; j <= 1; j++){
			// cout << "i, j = " << i << ", " << j << "\n";
			for(auto u: rects[2*i+j]){
				// cout << "RECT " << i << " " << j << " " << u.f << " " << u.s << "\n";
				bits[i][j].update(u.f, u.s);
			}
		}
	}
}

int colour(int ar, int ac, int br, int bc) {
	ll ans = 0;
	if(ar+1 <= min_sr && max_sr+1 <= br && ac+1 <= min_sc && max_sc+1 <= bc){
		ans++;
	}
	
	for(int i = 0; i <= 1; i++){
		for(int j = 0; j <= 1; j++){
			ll val = ll(br-i-ar+1)*ll(bc-j-ac+1);
			// cout << "val: " << val << "\n";
			val-=bits[i][j].query(ar, ac, br-i, bc-j);
			if((i+j) % 2 == 0){
				ans+=val;
			}
			else{
				ans-=val;
			}

			// cout << i << " " << j << " " << val << "\n";
		}
	}
    return (int)(ans);
}

# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 23 ms 460 KB Output is correct
3 Correct 6 ms 364 KB Output is correct
4 Correct 7 ms 376 KB Output is correct
5 Correct 26 ms 612 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 7 ms 332 KB Output is correct
12 Correct 18 ms 460 KB Output is correct
13 Correct 37 ms 644 KB Output is correct
14 Correct 36 ms 800 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Execution timed out 3060 ms 13396 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 176 ms 29264 KB Output is correct
3 Correct 87 ms 29164 KB Output is correct
4 Correct 102 ms 31728 KB Output is correct
5 Correct 140 ms 24916 KB Output is correct
6 Correct 30 ms 5008 KB Output is correct
7 Correct 49 ms 9512 KB Output is correct
8 Correct 127 ms 24484 KB Output is correct
9 Correct 136 ms 18644 KB Output is correct
10 Correct 29 ms 7220 KB Output is correct
11 Correct 93 ms 16124 KB Output is correct
12 Correct 192 ms 29280 KB Output is correct
13 Correct 88 ms 29308 KB Output is correct
14 Correct 102 ms 31824 KB Output is correct
15 Correct 153 ms 25116 KB Output is correct
16 Correct 34 ms 4856 KB Output is correct
17 Correct 50 ms 9628 KB Output is correct
18 Correct 105 ms 31784 KB Output is correct
19 Correct 159 ms 27936 KB Output is correct
20 Correct 160 ms 27952 KB Output is correct
21 Correct 137 ms 24604 KB Output is correct
22 Correct 137 ms 18712 KB Output is correct
23 Correct 29 ms 7256 KB Output is correct
24 Correct 97 ms 16132 KB Output is correct
25 Correct 170 ms 29276 KB Output is correct
26 Correct 89 ms 29340 KB Output is correct
27 Correct 111 ms 32004 KB Output is correct
28 Correct 141 ms 25040 KB Output is correct
29 Correct 30 ms 4864 KB Output is correct
30 Correct 50 ms 9628 KB Output is correct
31 Correct 107 ms 31808 KB Output is correct
32 Correct 161 ms 28108 KB Output is correct
33 Correct 156 ms 27956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 23 ms 460 KB Output is correct
3 Correct 6 ms 364 KB Output is correct
4 Correct 7 ms 376 KB Output is correct
5 Correct 26 ms 612 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 7 ms 332 KB Output is correct
12 Correct 18 ms 460 KB Output is correct
13 Correct 37 ms 644 KB Output is correct
14 Correct 36 ms 800 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Execution timed out 3071 ms 13260 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 23 ms 460 KB Output is correct
3 Correct 6 ms 364 KB Output is correct
4 Correct 7 ms 376 KB Output is correct
5 Correct 26 ms 612 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 7 ms 332 KB Output is correct
12 Correct 18 ms 460 KB Output is correct
13 Correct 37 ms 644 KB Output is correct
14 Correct 36 ms 800 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Execution timed out 3071 ms 13260 KB Time limit exceeded
19 Halted 0 ms 0 KB -