Submission #241531

# Submission time Handle Problem Language Result Execution time Memory
241531 2020-06-24T11:39:30 Z arnold518 Chessboard (IZhO18_chessboard) C++14
39 / 100
218 ms 1912 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

struct Rect { int y1, x1, y2, x2; };
Rect A[MAXN+10];

int N, K;

ll f(int y, int x)
{
	if(y<0 || x<0) return 0;
	ll t=(ll)(y+1)*(x+1);
	return (t+1)/2;
}

ll g(int y, int x, int it)
{
	if(y<0 || x<0) return 0;
	int yy=(y+1)/it-1, xx=(x+1)/it-1;
	ll ret=0;
	ret+=f(yy, xx)*it*it;
	ret+=(ll)(x-(xx*it+it-1))*(f(yy, xx+1)-f(yy, xx))*it;
	ret+=(ll)(y-(yy*it+it-1))*(f(yy+1, xx)-f(yy, xx))*it;
	if((yy+xx)%2==0) ret+=(ll)(x-(xx*it+it-1))*(y-(yy*it+it-1));
	//printf("%d %d %d => %d %d %lld\n", y, x, it, yy, xx, ret);
	return ret;
}

int main()
{
	int i, j;

	scanf("%d%d", &N, &K);
	for(i=1; i<=K; i++) scanf("%d%d%d%d", &A[i].y1, &A[i].x1, &A[i].y2, &A[i].x2), A[i].y1--, A[i].x1--, A[i].y2--, A[i].x2--;

	vector<int> V;
	for(i=1; i<N; i++) if(N%i==0) V.push_back(i);

	ll ans=1e18;
	for(auto it : V)
	{
		ll a=0, b=0, c=0;
		for(i=1; i<=K; i++)
		{
			ll t=g(A[i].y2, A[i].x2, it)-g(A[i].y1-1, A[i].x2, it)-g(A[i].y2, A[i].x1-1, it)+g(A[i].y1-1, A[i].x1-1, it);
			a+=t;
			b+=(ll)(A[i].y2-A[i].y1+1)*(A[i].x2-A[i].x1+1);
		}
		c=((ll)(N/it)*(N/it)+1)/2*it*it-a;
		b=N*N-b;
		a+=b-c;
		//printf("%lld\n", a);
		ans=min(ans, min(a, N*N-a));
	}
	printf("%lld\n", ans);
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:37:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
chessboard.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &K);
  ~~~~~^~~~~~~~~~~~~~~~
chessboard.cpp:40:112: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1; i<=K; i++) scanf("%d%d%d%d", &A[i].y1, &A[i].x1, &A[i].y2, &A[i].x2), A[i].y1--, A[i].x1--, A[i].y2--, A[i].x2--;
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 1272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 20 ms 768 KB Output is correct
17 Correct 41 ms 1660 KB Output is correct
18 Correct 60 ms 1912 KB Output is correct
19 Correct 200 ms 1740 KB Output is correct
20 Correct 218 ms 1912 KB Output is correct
21 Correct 40 ms 1656 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 40 ms 1024 KB Output is correct
24 Correct 59 ms 1656 KB Output is correct
25 Correct 12 ms 384 KB Output is correct
26 Correct 38 ms 1152 KB Output is correct
27 Correct 56 ms 1408 KB Output is correct
28 Correct 58 ms 1784 KB Output is correct
29 Correct 19 ms 896 KB Output is correct
30 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 1272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Incorrect 37 ms 1272 KB Output isn't correct
10 Halted 0 ms 0 KB -