QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#478474#8485. Magic Squarerania__#WA 0ms3608kbC++231.8kb2024-07-15 00:27:032024-07-15 00:27:03

Judging History

你现在查看的是最新测评结果

  • [2024-07-15 00:27:03]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3608kb
  • [2024-07-15 00:27:03]
  • 提交

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(){
	vector<int> v;
	for(int i=0;i<n;i++){
		int sum=0;
		for(int j=0;j<n;j++){
			sum+=arr[i][j];
		}
		v.pb(sum);
	}
	for(int i=0;i<n;i++){
		int sum=0;
		for(int j=0;j<n;j++){
			sum+=arr[j][i];
		}
		v.pb(sum);
	}
	sort(v.begin(),v.end());
	return v[0]==v.back();
}

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]==0)
				r.pb(i);
			mp[sum]=1;
		}
		for(int i=0;i<n;i++){
			int sum=0;
			for(int j=0;j<n;j++){
				sum+=arr[j][i];
			}
			if(mp2[sum]==0)
				c.pb(i);
			mp2[sum]=1;
		}
		for(int i=0;i<r.size();i++){
			for(int j=0;j<c.size();j++){
				for(int k=0;k<r.size();k++){
					for(int l=0;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]]);
					}
				}
			}
		}
		a:;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
6 9 2
3 5 7
8 1 4

output:

1 1
3 3

result:

ok OK

Test #2:

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

input:

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

output:


result:

wrong output format Unexpected end of file - int32 expected