답안 #126734

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
126734 2019-07-08T10:09:32 Z eriksuenderhauf 보물 찾기 (CEOI13_treasure2) C++11
100 / 100
11 ms 1204 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "treasure.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e2 + 5;
const double eps = 1e-9;
int a[MAXN][MAXN], n, t[MAXN][MAXN], sm[MAXN][MAXN], sm2[MAXN][MAXN];
map<pair<pii,pii>,int> dp;
 
int qry(int x1, int y1, int x2, int y2) {
	if (dp.count(mp(mp(x1,y1),mp(x2,y2)))) return dp[mp(mp(x1,y1),mp(x2,y2))];
	int ret = countTreasure(x1, y1, x2, y2);
	dp[mp(mp(x1,y1),mp(x2,y2))] = ret;
	return ret;
}
 
void g(int i, int j) {
	if ((n & 1) && (i == (n+1) / 2 || j == (n+1) / 2))
		return;
	if (!(n & 1) && (i - 1 == n / 2 || j - 1 == n / 2))
		return;
	int tl = i * j + (i-1) * j + i * (j-1) + (i-1)*(j-1);
	int bl = (n-i+1)*j+(n-i)*j+(n-i+1)*(j-1)+(n-i)*(j-1);
	int tr = i*(n-j+1)+(i-1)*(n-j+1)+i*(n-j)+(i-1)*(n-j);
	int br = (n-i+1)*(n-j+1)+(n-i)*(n-j+1)+(n-i+1)*(n-j)+(n-i)*(n-j);
	int mx = max(max(tl,bl), max(tr, br));
	if (mx == tl)
		t[i][j] = 1;
	else if (mx == bl)
		t[i][j] = 2;
	else if (mx == tr)
		t[i][j] = 3;
	else if (mx == br)
		t[i][j] = 4;
}
 
int f(int i, int j) {
	if (t[i][j] == 1)
		return qry(1,1,i,j)-qry(1,1,i-1,j)-qry(1,1,i,j-1)+qry(1,1,i-1,j-1);
	if (t[i][j] == 2)
		return qry(i,1,n,j)-qry(i+1,1,n,j)-qry(i,1,n,j-1)+qry(i+1,1,n,j-1);
	if (t[i][j] == 3)
		return qry(1,j,i,n)-qry(1,j,i-1,n)-qry(1,j+1,i,n)+qry(1,j+1,i-1,n);
	if (t[i][j] == 4)
		return qry(i,j,n,n)-qry(i+1,j,n,n)-qry(i,j+1,n,n)+qry(i+1,j+1,n,n);
	return 0;
}
 
void findTreasure(int N) {
	n = N;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			g(i, j);
	for (int i = n; i > 0; i--)
		for (int j = n; j > 0; j--)
			if (t[i][j] == 4)
				a[i][j] = f(i, j);
	for (int i = 1; i <= n; i++)
		for (int j = n; j > 0; j--)
			if (t[i][j] == 3)
				a[i][j] = f(i, j);
	for (int i = n; i > 0; i--)
		for (int j = 1; j <= n; j++)
			if (t[i][j] == 2) 
				a[i][j] = f(i, j);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (t[i][j] == 1)
				a[i][j] = f(i, j);
	for (int i = n; i > 0; i--)
		for (int j = 1; j <= n; j++)
			sm[i][j] = sm[i+1][j] + a[i][j];
	for (int i = n; i > 0; i--)
		for (int j = n; j > 0; j--)
			sm2[i][j] = sm2[i][j+1] + a[i][j];
	int idx = n / 2 + 1;
	if (n & 1)
		idx = (n+1) / 2;
	for (int i = 1; i <= n; i++) {
		if (i == idx) continue;
		if (i < idx) {
			a[idx][i] = qry(idx, i, n, n) - qry(idx, i+1, n, n) - sm[idx][i];
			a[i][idx] = qry(i, idx, n, n) - qry(i+1, idx, n, n) - sm2[i][idx];
		} else {
			a[idx][i] = qry(idx, 1, n, i) - qry(idx, 1, n, i-1) - sm[idx][i];
			a[i][idx] = qry(1, idx, i, n) - qry(1, idx, i-1, n) - sm2[i][idx];
		}
	}
	a[idx][idx] = qry(1,1,idx,idx);
	for (int i = 1; i <= idx; i++)
		for (int j = 1; j <= idx; j++)
			if (!(i == idx && j == idx))
				a[idx][idx] -= a[i][j];
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (a[i][j])
				Report(i, j);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct - N = 5, K = 289, score = 10
2 Correct 2 ms 376 KB Output is correct - N = 10, K = 4475, score = 10
3 Correct 2 ms 376 KB Output is correct - N = 15, K = 22289, score = 10
4 Correct 2 ms 376 KB Output is correct - N = 16, K = 28928, score = 10
5 Correct 4 ms 632 KB Output is correct - N = 55, K = 4005289, score = 10
6 Correct 6 ms 760 KB Output is correct - N = 66, K = 8305803, score = 10
7 Correct 7 ms 888 KB Output is correct - N = 77, K = 15383161, score = 10
8 Correct 8 ms 1012 KB Output is correct - N = 88, K = 26244416, score = 10
9 Correct 11 ms 1204 KB Output is correct - N = 99, K = 42032201, score = 10
10 Correct 11 ms 1144 KB Output is correct - N = 100, K = 43760000, score = 10