#include "treasure.h"
#include <bits/stdc++.h>
using namespace std;
const int N=100+5;
int ask(int r1,int c1,int r2,int c2)
{
return countTreasure(r1,c1,r2,c2);
}
int s[N][N];
int askk(int r,int c)
{
return s[r][c]-s[r-1][c]-s[r][c-1]+s[r-1][c-1];
}
int nn;
int co(int r1,int c1,int r2,int c2)
{
int a=(r2-r1+1)*(c2-c1+1);
return nn*nn+1-a;
}
void hack(int i,int j)
{
if(i>nn-i)
{
if(j>nn-j)
{
s[i][j]=ask(1,1,i,j);
}
else
{
s[i][j]=s[i][nn]-ask(1,j+1,i,nn);
}
}
else
{
if(j>nn-j)
{
s[i][j]=s[nn][j]-ask(i+1,1,nn,j);
}
else
{
s[i][j]=s[i][nn]+s[nn][j]-s[nn][nn]+ask(i+1,j+1,nn,nn);
}
}
}
int findTreasure(int n)
{
nn=n;
s[n][n]=ask(1,1,n,n);
for(int i=1;i<n;i++)
{
if(co(1,1,i,n)<co(i+1,1,n,n))
{
s[i][n]=ask(1,1,i,n);
s[n][i]=ask(1,1,n,i);
}
else
{
s[i][n]=s[n][n]-ask(i+1,1,n,n);
s[n][i]=s[n][n]-ask(1,i+1,n,n);
}
}
for(int i=1;i<n;i++)
{
for(int j=1;j<n;j++)
{
hack(i,j);
}
}
///for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) {cout<<askk(i,j)<<" "; if(j==n) cout<<"\n";}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(askk(i,j))
{
Report(i,j);
}
}
}
}
Compilation message
treasure.cpp: In function 'int findTreasure(int)':
treasure.cpp:89:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct - N = 5, K = 289, score = 10 |
2 |
Correct |
2 ms |
380 KB |
Output is correct - N = 10, K = 4475, score = 10 |
3 |
Correct |
2 ms |
440 KB |
Output is correct - N = 15, K = 22289, score = 10 |
4 |
Correct |
2 ms |
516 KB |
Output is correct - N = 16, K = 28928, score = 10 |
5 |
Correct |
2 ms |
616 KB |
Output is correct - N = 55, K = 4005289, score = 10 |
6 |
Correct |
2 ms |
616 KB |
Output is correct - N = 66, K = 8305803, score = 10 |
7 |
Correct |
2 ms |
616 KB |
Output is correct - N = 77, K = 15383161, score = 10 |
8 |
Correct |
2 ms |
660 KB |
Output is correct - N = 88, K = 26244416, score = 10 |
9 |
Correct |
2 ms |
660 KB |
Output is correct - N = 99, K = 42032201, score = 10 |
10 |
Correct |
2 ms |
660 KB |
Output is correct - N = 100, K = 43760000, score = 10 |