제출 #241532

#제출 시각아이디문제언어결과실행 시간메모리
241532arnold518Chessboard (IZhO18_chessboard)C++14
100 / 100
959 ms2044 KiB
#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=(ll)N*N-b;
		a+=b-c;
		//printf("%lld\n", a);
		ans=min(ans, min(a, (ll)N*N-a));
	}
	printf("%lld\n", ans);
}

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...