답안 #776704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
776704 2023-07-08T07:31:15 Z vjudge1 Sajam (COCI18_sajam) C++17
90 / 90
18 ms 1732 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+37;

		
void f(){
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
 
	//f();
 	
 	int n, k; cin >> n >> k;

 	vector<string> s(n);
 	vector<int> val(n);


 	for(auto &i: s) cin >> i;

 	for(int i=0; i<n; i++){
 		for(int l=0; l<n; l++){
 			val[i]+=((s[i][l]=='x')?1:0);

 		}

 	}

 	int flag=0;


	for(int i=0; i<1; i++){
		vector<int> tf=val;

		for(int l=0; l<n; l++){
			if(s[i][l]=='x'){
				for(int j=0; j<n; j++){
					if(s[j][l]=='x'){
						val[j]--;
					}
					else val[j]++;
				}
			}
		}

		int ans=0;
		for(int l=0; l<n; l++){
			ans+=min(val[l], n-val[l]);
		}
		if(ans<=k) flag=1;
		val=tf;
	}
	
	k--;

	int x=0, y=0, z=0;
	for(int i=0; i<n-1&&!z; i++){
		for(int l=0; l<n-1&&!z; l++){
			int p=0;
			for(int j=0; j<2; j++){
				for(int f=0; f<2; f++){
					if(s[i+j][l+f]=='x') p++;
				}
			}

			if(p%2==1){
				x=i, y=l;
				z=1;
			} 
		}
	}

	for(int j=0; j<2; j++){

		for(int F=0; F<2; F++){
			if(x>=n||y>=n) continue; 
			vector<int> tf=val;
			if(s[x][y]=='x') val[x]--;
			else val[x]++;
			s[x][y]=(s[x][y]=='x'?'o':'x');


			for(int l=0; l<n; l++){
				if(s[x][l]=='x'){
					for(int p=0; p<n; p++){
						if(s[p][l]=='x'){
							val[p]--;
						}
						else val[p]++;
					}
				}
			}
			int ans=0;
			for(int l=0; l<n; l++){
				ans+=min(val[l], n-val[l]);
			}
			if(ans<=k) flag=1;
			val=tf;
			s[x][y]=(s[x][y]=='x'?'o':'x');
						y++;


		}
		x++;
		y-=2;
	}
	if(flag) cout<<"DA";
	else cout<<"NE";

}

Compilation message

sajam.cpp: In function 'void f()':
sajam.cpp:7:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |  freopen("in.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
sajam.cpp:8:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |  freopen("out.txt", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 628 KB Output is correct
3 Correct 3 ms 852 KB Output is correct
4 Correct 8 ms 1508 KB Output is correct
5 Correct 3 ms 852 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 5 ms 724 KB Output is correct
8 Correct 15 ms 1620 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 15 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1324 KB Output is correct
2 Correct 5 ms 1264 KB Output is correct
3 Correct 3 ms 964 KB Output is correct
4 Correct 3 ms 980 KB Output is correct
5 Correct 6 ms 1364 KB Output is correct
6 Correct 2 ms 852 KB Output is correct
7 Correct 4 ms 1136 KB Output is correct
8 Correct 4 ms 1224 KB Output is correct
9 Correct 3 ms 592 KB Output is correct
10 Correct 18 ms 1624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1460 KB Output is correct
2 Correct 5 ms 1300 KB Output is correct
3 Correct 3 ms 980 KB Output is correct
4 Correct 4 ms 1060 KB Output is correct
5 Correct 4 ms 1116 KB Output is correct
6 Correct 7 ms 1492 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Correct 4 ms 1088 KB Output is correct
9 Correct 10 ms 1124 KB Output is correct
10 Correct 18 ms 1600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1108 KB Output is correct
2 Correct 5 ms 1016 KB Output is correct
3 Correct 7 ms 1496 KB Output is correct
4 Correct 2 ms 844 KB Output is correct
5 Correct 4 ms 1012 KB Output is correct
6 Correct 7 ms 1596 KB Output is correct
7 Correct 2 ms 844 KB Output is correct
8 Correct 3 ms 848 KB Output is correct
9 Correct 6 ms 852 KB Output is correct
10 Correct 5 ms 844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1732 KB Output is correct
2 Correct 7 ms 1548 KB Output is correct
3 Correct 7 ms 1492 KB Output is correct
4 Correct 4 ms 1116 KB Output is correct
5 Correct 4 ms 1108 KB Output is correct
6 Correct 4 ms 1108 KB Output is correct
7 Correct 3 ms 844 KB Output is correct
8 Correct 6 ms 1364 KB Output is correct
9 Correct 7 ms 980 KB Output is correct
10 Correct 15 ms 1652 KB Output is correct