提出 #502774


ソースコード 拡げる

#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>

#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<functional>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF 1<<30
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define ll long long
#define ull unsigned long long
int n,k;
int rm[2010][2010];
int bm[2010][2010];
set<int> tx;
set<int> ty;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>n>>k;
	FOR(i,1,n+1) FOR(j,1,n+1){
		((i+j)%2 ? bm[i][j] : rm[i][j] ) = 1;
	}
	tx.insert(0); ty.insert(0);
	tx.insert(1); ty.insert(1);
	tx.insert(n); ty.insert(n);
	tx.insert(n-1); ty.insert(n-1);

	REP(i,k){
		int y,x;cin>>y>>x;
		((y+x)%2 ? rm[y][x] : bm[y][x] ) = 1;
		((y+x)%2 ? bm[y][x] : rm[y][x] ) = 0;
		tx.insert(x);ty.insert(y);
		tx.insert(x-1);ty.insert(y-1);
		tx.insert(x+1);ty.insert(y+1);
	}
// 	REP(i,n){ REP(j,n)cout<<rm[i][j]<<" "; cout<<endl;}
	FOR(i,1,n+1) FOR(j,1,n+1){
		rm[i][j] = rm[i][j] + rm[i-1][j] + rm[i][j-1] - rm[i-1][j-1];
		bm[i][j] = bm[i][j] + bm[i-1][j] + bm[i][j-1] - bm[i-1][j-1];
	}
// 	FOR(i,1,n+1){ FOR(j,1,n+1)cout<<rm[i][j]<<" "; cout<<endl;}
	int ans=0;
	for(auto ax:tx) for(auto ay:ty) for(auto bx:tx) for(auto by:ty){
		if(bx<=ax || by <= ay) continue;
		int red = rm[by][bx] - rm[ay][bx] - rm[by][ax] + rm[ay][ax];
		int blue = bm[by][bx] - bm[ay][bx] - bm[by][ax] + bm[ay][ax];
		ans = max(ans,abs(red-blue));
	}
	cout<<ans<<endl;
//  	REP(i,n){ REP(j,n)cout<<rm[i][j]<<" "; cout<<endl;}
// 	REP(i,n){ REP(j,n)cout<<rm[i][j]<<" "; cout<<endl;}
		
}

提出情報

提出日時
問題 E - マス目色ぬり
ユーザ ish_774
言語 C++11 (GCC 4.9.2)
得点 100
コード長 1850 Byte
結果 AC
実行時間 122 ms
メモリ 32176 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 100 / 100
結果
AC × 3
AC × 27
セット名 テストケース
Sample example_0.txt, example_1.txt, example_2.txt
All all_black_0.txt, all_black_1.txt, all_edge_0.txt, all_edge_1.txt, all_edge_2.txt, all_white_0.txt, all_white_1.txt, corner_0.txt, example_0.txt, example_1.txt, example_2.txt, maxrand_0.txt, maxrand_1.txt, maxrand_2.txt, maxrand_3.txt, maxrand_4.txt, random_0.txt, random_1.txt, random_2.txt, random_3.txt, random_4.txt, smallrand_0.txt, smallrand_1.txt, smallrand_2.txt, example_0.txt, example_1.txt, example_2.txt
ケース名 結果 実行時間 メモリ
all_black_0.txt AC 65 ms 17572 KiB
all_black_1.txt AC 83 ms 22688 KiB
all_edge_0.txt AC 39 ms 8096 KiB
all_edge_1.txt AC 78 ms 24472 KiB
all_edge_2.txt AC 31 ms 4596 KiB
all_white_0.txt AC 28 ms 1576 KiB
all_white_1.txt AC 96 ms 31132 KiB
corner_0.txt AC 26 ms 800 KiB
example_0.txt AC 25 ms 928 KiB
example_1.txt AC 24 ms 800 KiB
example_2.txt AC 27 ms 740 KiB
maxrand_0.txt AC 122 ms 32164 KiB
maxrand_1.txt AC 117 ms 32176 KiB
maxrand_2.txt AC 114 ms 32164 KiB
maxrand_3.txt AC 113 ms 32168 KiB
maxrand_4.txt AC 114 ms 32164 KiB
random_0.txt AC 76 ms 20772 KiB
random_1.txt AC 35 ms 3880 KiB
random_2.txt AC 92 ms 29220 KiB
random_3.txt AC 76 ms 23200 KiB
random_4.txt AC 36 ms 2088 KiB
smallrand_0.txt AC 25 ms 924 KiB
smallrand_1.txt AC 24 ms 972 KiB
smallrand_2.txt AC 24 ms 924 KiB