# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
126650 | eriksuenderhauf | Treasure (different grader from official contest) (CEOI13_treasure2) | C++11 | 8 ms | 1144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#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];
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;
}
int g(int i, int j) {
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
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);
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);
}
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) continue;
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) continue;
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) continue;
a[i][j] = f(i, j);
}
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
sm[i][j] = a[i][j] + sm[i-1][j] + sm[i][j-1] - sm[i-1][j-1];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (t[i][j] != 1 && t[i][j] != 3) continue;
sm[i][j] = qry(1,1,i,j);
a[i][j] = sm[i][j] - sm[i-1][j] - sm[i][j-1] + sm[i-1][j-1];
}
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (a[i][j])
Report(i, j);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |