QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#461007#8485. Magic SquareLynkcat#WA 0ms3904kbC++143.3kb2024-07-02 15:03:322024-07-02 15:03:33

Judging History

This is the latest submission verdict.

  • [2024-07-02 15:03:33]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3904kb
  • [2024-07-02 15:03:32]
  • Submitted

answer

#include<bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < int,int >
#define fi first
#define se second
#define inf 1e18
#define mod 998244353
#define sz(x) ((int)((x).size()))
#define int ll
// #define N 
using namespace std;
const int N=1005;
int n,a[N][N],f[N],g[N];
void BellaKira()
{
    cin>>n;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=n;j++)
            cin>>a[i][j],f[i]+=a[i][j],g[j]+=a[i][j];
    if (n<=4)
    {
        for (int i=1;i<=n;i++)
            for (int j=1;j<=n;j++)
                for (int x=1;x<=n;x++)
                    for (int y=1;y<=n;y++)
                        if (i!=x||j!=y)
                        {
                            f[i]-=a[i][j],g[j]-=a[i][j];
                            f[x]-=a[x][y],g[y]-=a[x][y];
                            swap(a[i][j],a[x][y]);
                            f[i]+=a[i][j],g[j]+=a[i][j];
                            f[x]+=a[x][y],g[y]+=a[x][y];
                            bool bl=1;
                            for (int k=1;k<=n;k++) bl&=(f[k]==f[1]&&g[k]==f[1]);
                            if (!bl) 
                            {
                                f[i]-=a[i][j],g[j]-=a[i][j];
                                f[x]-=a[x][y],g[y]-=a[x][y];
                                swap(a[i][j],a[x][y]);
                                f[i]+=a[i][j],g[j]+=a[i][j];
                                f[x]+=a[x][y],g[y]+=a[x][y];
                                continue;
                            }
                            cout<<i<<" "<<j<<" "<<x<<" "<<y<<'\n';
                            return;
                        }
        return;
    }
    map<int,int>Mp;
    for (int i=1;i<=n;i++) Mp[f[i]]++,Mp[g[i]]++;
    int p=0;
    for (auto [u,v]:Mp)
        if (v>Mp[p])
        {
            p=u;
        }
    poly gx,gy;
    for (int i=1;i<=n;i++)
        if (f[i]!=p) gx.push_back(i);
    for (int i=1;i<=n;i++)
        if (g[i]!=p) gy.push_back(i);
    for (int i:gx)
        for (int j:gy)
            for (int x:gx)
                for (int y:gy)
                    if (i!=x||j!=y)
                    {
                        f[i]-=a[i][j],g[j]-=a[i][j];
                        f[x]-=a[x][y],g[y]-=a[x][y];
                        swap(a[i][j],a[x][y]);
                        f[i]+=a[i][j],g[j]+=a[i][j];
                        f[x]+=a[x][y],g[y]+=a[x][y];
                        bool bl=1;
                        for (int k=1;k<=n;k++) bl&=(f[k]==f[1]&&g[k]==f[1]);
                        if (!bl) 
                        {
                            f[i]-=a[i][j],g[j]-=a[i][j];
                            f[x]-=a[x][y],g[y]-=a[x][y];
                            swap(a[i][j],a[x][y]);
                            f[i]+=a[i][j],g[j]+=a[i][j];
                            f[x]+=a[x][y],g[y]+=a[x][y];
                            continue;
                        }
                        cout<<i<<" "<<j<<" "<<x<<" "<<y<<'\n';
                        return;
                    }

    
                                
                            
}
signed main()
{
	IOS;
	cin.tie(0);
	int T=1;
	while (T--)
	{
		BellaKira();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3576kb

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: 3904kb

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: 3664kb

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: -100
Wrong Answer
time: 0ms
memory: 3660kb

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:


result:

wrong output format Unexpected end of file - int32 expected