QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#478517#8485. Magic Squarerania__#WA 0ms3800kbC++232.9kb2024-07-15 04:02:562024-07-15 04:02:56

Judging History

This is the latest submission verdict.

  • [2024-07-15 04:02:56]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3800kb
  • [2024-07-15 04:02:56]
  • Submitted

answer

#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef int in;
#define int long long
#define double long double
#define f first
#define s second
#define pb push_back
#define pp push
#define ceill(x,y) ((x/y)+(x%y!=0)*(x/abs(x)*y/abs(y)<0?0:1))
#define floorr(x,y) ((x/y)+(x%y!=0)*(x/abs(x)*y/abs(y)<0?-1:0))
#define YN(x) cout<<(x?"YES\n":"NO\n");
#define Yn(x) cout<<(x?"Yes\n":"No\n");
#define yn(x) cout<<(x?"yes\n":"no\n");
const int MAAX=1e18;
const int MOD=1e9+7;
const int MAX=1e9;

int n,arr[1010][1010];
map<int,int> mp,mp2;
bool check(){
	int mx=0,mn=MAAX;
	for(int i=0;i<n&&(i==0||mx==mn);i++){
		int sum=0;
		for(int j=0;j<n;j++){
			sum+=arr[i][j];
		}
		mx=max(mx,sum);
		mn=min(mn,sum);
	}
	for(int i=0;i<n&&mx==mn;i++){
		int sum=0;
		for(int j=0;j<n;j++){
			sum+=arr[j][i];
		}
		mx=max(mx,sum);
		mn=min(mn,sum);
	}
	return mx==mn;
}

in main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int tc=1;
    // cin>>tc;
    while(tc--){
		cin>>n;
		mp.clear();
		mp2.clear();
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++)
				cin>>arr[i][j];
		}
		vector<int> r,c;
		for(int i=0;i<n;i++){
			int sum=0;
			for(int j=0;j<n;j++){
				sum+=arr[i][j];
			}
			if(mp[sum]<3)
				r.pb(i);
			mp[sum]++;
		}
		for(int i=0;i<n;i++){
			int sum=0;
			for(int j=0;j<n;j++){
				sum+=arr[j][i];
			}
			if(mp2[sum]<3)
				c.pb(i);
			mp2[sum]++;
		}
		for(int i=0;i<r.size();i++){
			for(int j=0;j<c.size();j++){
				for(int k=i+1;k<r.size();k++){
					for(int l=j+1;l<c.size();l++){
						swap(arr[r[i]][c[j]],arr[r[k]][c[l]]);
						if(check()){
							cout<<r[i]+1<<" "<<c[j]+1<<"\n"<<r[k]+1<<" "<<c[l]+1<<"\n";
							goto a;
						}
						swap(arr[r[i]][c[j]],arr[r[k]][c[l]]);
					}
				}
			}
		}
		if(c.size()==3){
			for(int i=0;i<r.size();i++){
				for(int j=i+1;j<r.size();j++){
					int sum1=0;
					for(int k=0;k<n;k++)
						sum1+=arr[r[i]][k];
					int sum2=0;
					for(int k=0;k<n;k++)
						sum2+=arr[r[j]][k];
					for(int k=0;k<n;k++){
						if(sum2+arr[r[i]][k]-arr[r[j]][k]==sum1+arr[r[j]][k]-arr[r[i]][k]){
							swap(arr[r[i]][k],arr[r[j]][k]);
							if(check()){
								cout<<r[i]+1<<" "<<k+1<<"\n"<<r[j]+1<<" "<<k+1<<"\n";
								goto a;
							}
							swap(arr[r[i]][k],arr[r[j]][k]);
						}
					}
				}
			}
		}
		for(int i=0;i<c.size();i++){
			for(int j=i+1;j<c.size();j++){
				int sum1=0;
				for(int k=0;k<n;k++)
					sum1+=arr[k][c[i]];
				int sum2=0;
				for(int k=0;k<n;k++)
					sum2+=arr[k][c[j]];
				for(int k=0;k<n;k++){
					if(sum2+arr[k][c[i]]-arr[k][c[j]]==sum1+arr[k][c[j]]-arr[k][c[i]]){
						swap(arr[k][c[i]],arr[k][c[j]]);
						if(check()){
							cout<<k+1<<" "<<c[i]+1<<"\n"<<k+1<<" "<<c[j]+1<<"\n";
							goto a;
						}
						swap(arr[k][c[i]],arr[k][c[j]]);
					}
				}
			}
		}
		a:;
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3800kb

input:

3
6 9 2
3 5 7
8 1 4

output:

1 1
3 3

result:

ok OK

Test #2:

score: 0
Accepted
time: 0ms
memory: 3504kb

input:

4
16 3 2 13
5 10 11 8
9 6 7 12
1 15 14 4

output:

2 1
2 4

result:

ok OK

Test #3:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

3
8 1 6
3 5 7
4 2 9

output:

3 2
3 3

result:

ok OK

Test #4:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

4
9 12 7 6
4 2 14 15
16 13 1 3
5 8 11 10

output:

2 2
3 3

result:

ok OK

Test #5:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

5
15 17 1 8 24
3 10 19 21 12
16 23 7 14 6
22 4 13 20 5
9 11 25 2 18

output:

3 5
4 5

result:

ok OK

Test #6:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

6
14 34 12 5 16 30
27 2 22 9 20 31
18 28 13 36 11 4
19 6 26 1 24 35
10 33 17 29 15 8
23 7 21 32 25 3

output:

3 2
5 4

result:

ok OK

Test #7:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

7
39 28 30 1 19 10 48
47 29 38 8 27 18 7
6 37 46 17 35 26 9
23 12 21 41 3 43 32
31 20 22 49 11 2 40
14 45 5 25 36 34 16
15 4 13 33 44 42 24

output:

2 4
3 7

result:

ok OK

Test #8:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

8
42 22 20 47 19 21 48 41
55 11 13 50 14 12 49 56
57 3 5 58 6 4 63 64
7 59 61 2 62 60 1 8
34 30 28 39 27 29 40 33
15 51 53 10 54 52 9 16
18 46 44 23 43 45 24 17
26 38 36 31 35 37 32 25

output:

1 1
1 7

result:

ok OK

Test #9:

score: -100
Wrong Answer
time: 0ms
memory: 3636kb

input:

9
23 69 1 45 47 34 12 58 80
64 29 51 5 16 75 62 27 40
53 18 31 66 77 55 42 7 49
63 19 41 76 6 65 52 17 30
13 59 81 35 37 24 2 48 70
3 20 71 25 36 14 73 38 60
74 39 61 15 26 4 72 28 50
43 8 21 56 67 54 32 78 10
33 79 11 46 57 44 22 68 9

output:


result:

wrong output format Unexpected end of file - int32 expected