답안 #508836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
508836 2022-01-13T21:27:41 Z inksamurai Sajam (COCI18_sajam) C++17
90 / 90
517 ms 20040 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _34raRxL ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;

void print(){
	cout<<"\n";
}
template<class te,class ...ti>
void print(const te&v, const ti&...nv) { 
	cout<<v;
	if(sizeof...(nv)){
		cout<<" ";
		print(nv...);
	}
}

#define yare {cout<<"DA\n"; exit(0);}
#define nare {cout<<"NE\n"; exit(0);}

using pii=pair<int,int>;
using vi=vector<int>;
using vll=vector<long long>;

signed main(){
_34raRxL;
	int n,k;
	cin>>n>>k;
	int h=n,w=n;
	vec(vi) a(h,vi(w));
	rep(i,h){
		string s;
		cin>>s;
		rep(j,w){
			a[i][j]=s[j]=='o';
		}
	}
	vec(vi) tbl(2*n,vi(2*n));
	rep(i,h){
		rep(j,w){
			int x=a[i][j];
			// co = j + n ..
			int ro=i,co=j+n;
			tbl[ro][co]=tbl[co][ro]=x;
		}
	}
	vi c(n);
	{
		rep(i,n){
			rep(j,n){
				c[i]+=(tbl[i][j+n]!=tbl[0][j+n]);
			}
		}
	}
	{
		vec(vi) rbe(n,vi(2));
		rep(i,n){
			rep(j,n){
				bool e=(2*c[i]<n);
				if(tbl[i][j+n]!=tbl[0][j+n]){
					rbe[j][e]++;
				}else{
					rbe[j][e^1]++;
				}
			}
		}
		int now=0;
		rep(i,n){
			now+=min(rbe[i][0],rbe[i][1]);
		}
		if(now<=k){
			yare;
		}
	}
	auto affine=[&](int i0,int i1,int add)->void{
		rep(i,n){
			if(i==i0 or i==i1) continue;
			add+=min(c[i],n-c[i]);
		}
		if(add<=k){
			yare;
		}
	};
	rep(i,n){
		crep(j,i+1,n){
			if(i==j) continue;
			affine(i,j,max(c[i],n-c[i])+max(c[j],n-c[j]));
		}
	}

	nare;
//	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 5 ms 3916 KB Output is correct
3 Correct 7 ms 5452 KB Output is correct
4 Correct 17 ms 16564 KB Output is correct
5 Correct 6 ms 5708 KB Output is correct
6 Correct 3 ms 2380 KB Output is correct
7 Correct 69 ms 5216 KB Output is correct
8 Correct 444 ms 17356 KB Output is correct
9 Correct 7 ms 1332 KB Output is correct
10 Correct 437 ms 17656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 312 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 11468 KB Output is correct
2 Correct 14 ms 13952 KB Output is correct
3 Correct 11 ms 9420 KB Output is correct
4 Correct 9 ms 8328 KB Output is correct
5 Correct 18 ms 16320 KB Output is correct
6 Correct 85 ms 5964 KB Output is correct
7 Correct 216 ms 11180 KB Output is correct
8 Correct 253 ms 12172 KB Output is correct
9 Correct 37 ms 3404 KB Output is correct
10 Correct 514 ms 19620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 15192 KB Output is correct
2 Correct 16 ms 14828 KB Output is correct
3 Correct 9 ms 8524 KB Output is correct
4 Correct 12 ms 10956 KB Output is correct
5 Correct 12 ms 11712 KB Output is correct
6 Correct 486 ms 18736 KB Output is correct
7 Correct 72 ms 4780 KB Output is correct
8 Correct 203 ms 10588 KB Output is correct
9 Correct 231 ms 11740 KB Output is correct
10 Correct 517 ms 19624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8652 KB Output is correct
2 Correct 8 ms 8780 KB Output is correct
3 Correct 20 ms 19448 KB Output is correct
4 Correct 7 ms 6212 KB Output is correct
5 Correct 10 ms 8908 KB Output is correct
6 Correct 471 ms 18808 KB Output is correct
7 Correct 82 ms 6140 KB Output is correct
8 Correct 100 ms 6920 KB Output is correct
9 Correct 107 ms 7212 KB Output is correct
10 Correct 105 ms 6840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 20040 KB Output is correct
2 Correct 19 ms 19012 KB Output is correct
3 Correct 18 ms 17412 KB Output is correct
4 Correct 11 ms 10896 KB Output is correct
5 Correct 11 ms 10956 KB Output is correct
6 Correct 243 ms 11656 KB Output is correct
7 Correct 96 ms 6440 KB Output is correct
8 Correct 358 ms 16208 KB Output is correct
9 Correct 148 ms 8908 KB Output is correct
10 Correct 477 ms 19272 KB Output is correct