Submission #776693

# Submission time Handle Problem Language Result Execution time Memory
776693 2023-07-08T07:23:54 Z vjudge1 Sajam (COCI18_sajam) C++17
45 / 90
17 ms 1396 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), t;
 	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==0){
				x=i, y=l;
				z=1;
			} 
		}
	}


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

		for(int k=0; k<2; k++){
			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;
			y++;

			s[x][y]=(s[x][y]=='x'?'o':'x');

		}
		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);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 5 ms 1108 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 4 ms 536 KB Output is correct
8 Correct 15 ms 1264 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 15 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 852 KB Output is correct
2 Correct 4 ms 980 KB Output is correct
3 Correct 3 ms 724 KB Output is correct
4 Correct 3 ms 724 KB Output is correct
5 Correct 6 ms 1108 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Correct 4 ms 980 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 17 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1108 KB Output is correct
2 Correct 5 ms 1108 KB Output is correct
3 Correct 3 ms 724 KB Output is correct
4 Correct 7 ms 852 KB Output is correct
5 Correct 4 ms 852 KB Output is correct
6 Correct 6 ms 1328 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 4 ms 852 KB Output is correct
9 Correct 10 ms 852 KB Output is correct
10 Correct 16 ms 1396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 724 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Incorrect 7 ms 1372 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1364 KB Output is correct
2 Correct 7 ms 1364 KB Output is correct
3 Incorrect 6 ms 1236 KB Output isn't correct
4 Halted 0 ms 0 KB -