QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#288199#5446. 琪露诺的符卡交换catagory#0 5ms6084kbC++232.8kb2023-12-22 10:11:032024-07-04 03:14:37

Judging History

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

  • [2024-07-04 03:14:37]
  • 评测
  • 测评结果:0
  • 用时:5ms
  • 内存:6084kb
  • [2023-12-22 10:11:03]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define SZ(x) ((LL)(x.size()))
using namespace std;
long long read(){
  long long q=0,w=1;
  char ch=getchar();
  while(ch>'9' || ch<'0'){if(ch=='-')w=-1;ch=getchar();}
  while(ch>='0'&&ch<='9'){q=q*10+(ch-'0');ch=getchar();}
  return q*w;
}
void write(LL x){
  if(x<0){putchar('-');x=(-x);}
  if(x>9)write(x/10);
  putchar('0'+x%10);
}
void writeln(LL x){write(x);puts("");}
void writecs(LL x){write(x);putchar(' ');}

namespace TP{
  const long long N = 200+95;
  LL lim;vector<LL>E[N];LL matchL[N],matchR[N];
  void clear(){
    for(LL i=1;i<=lim;i++){E[i].clear();matchL[i]=matchR[i]=0;}
    return ;
  }
  void add_e(LL x,LL y){E[x].push_back(y);return ;}
  bool vis[N];
  bool dfs(LL x){
    if(vis[x])return 0;
    vis[x]=1;
    for(auto y:E[x]){
      if(!matchR[y]){matchL[x]=y;matchR[y]=x;return 1;}
      if(dfs(matchR[y])){matchL[x]=y;matchR[y]=x;return 1;}
    }
    return 0;
  }
  void solve(LL CNT=-1){
    LL cnt=0;
    for(LL t=1;t<=lim;t++){
      for(LL x=1;x<=lim;x++)vis[x]=0;
      cnt+=dfs(t);
    }
    if(CNT!=-1)assert(CNT==cnt);
    return ;
  }
}

#define x1 x_tmp_1
#define y1 y_tmp_1

struct pt{LL x,y;};
const long long N = 200+95;
long long T,n;vector<pt>a[N][N];bool b[N][N];vector<vector<LL>>ans;
void make(LL x0,LL y0,LL x1,LL y1){
  assert(SZ(a[x0][y0])&&SZ(a[x1][y1])&&!b[x0][y1]&&!b[x1][y0]);
  ans.push_back({x0,y0,x1,y1});
  return ;
}
int main(){
  T=read();
  while(T--){
    ans.clear();n=read();TP::lim=n;
    for(LL i=1;i<=n;i++)
      for(LL j=1;j<=n;j++){a[i][j].clear();b[i][j]=0;}

    for(LL i=1;i<=n;i++)
      for(LL j=1;j<=n;j++){LL x=read();a[i][x].push_back((pt){i,j});}

    {
      vector<LL>ord(n+2);vector<LL>vis(n+2);for(LL i=1;i<=n;i++)vis[i]=0;
      for(LL v=1;v<=n;v++)
	for(LL i=1;i<=n;i++)
	  if(!vis[i]&&SZ(a[i][v])>=(n-1)){ord[v]=i;vis[i]=1;break;}
    
      vector<pt>tmp[n+2][n+2];
      for(LL i=1;i<=n;i++)
	for(LL j=1;j<=n;j++)tmp[i][j]=a[i][j];
      for(LL i=1;i<=n;i++)
	for(LL j=1;j<=n;j++)a[i][j]=tmp[ord[i]][j];
    }

    for(LL t=1;t<=n;t++){
      vector<LL>visL(n+2),visR(n+2);
      for(LL i=t+1;i<=n;i++)
	if(SZ(a[t][i])){make(t,i,t,i);visR[i]=1;}
      for(LL i=t+1;i<=n;i++)
	if(SZ(a[i][t])){make(i,t,i,t);visL[i]=1;}
      LL cnt=0;
      for(LL i=t+1;i<=n;i++)
	if(!b[t][i])cnt++;
      TP::clear();
      for(LL i=t+1;i<=n;i++)
	for(LL j=t+1;j<=n;j++)
	  if(!b[t][i]&&!b[j][t]&&SZ(a[j][i]))TP::add_e(i,j);
      TP::solve(cnt);
      for(LL i=t+1;i<=n;i++){
	if(b[t][i])continue;
	LL j=TP::matchL[i];
	make(t,t,j,i);
      }
    }

    writeln(SZ(ans));
    for(LL t=0;t<SZ(ans);t++){
      for(LL i=0;i<SZ(ans[t]);i++)writecs(ans[t][i]);
      puts("");
    }
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 5ms
memory: 6084kb

input:

7
132
96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 ...

output:

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

result:

wrong answer exist a card swapped twice.

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%