QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#756399#3569. Foul Playgyydp123_LIM100 ✓26ms5172kbC++141.8kb2024-11-16 20:19:292024-11-16 20:19:30

Judging History

This is the latest submission verdict.

  • [2024-11-16 20:19:30]
  • Judged
  • Verdict: 100
  • Time: 26ms
  • Memory: 5172kb
  • [2024-11-16 20:19:29]
  • Submitted

answer

#include<bits/stdc++.h>
#define For(i,j,k) for(int i=(j);i<=(k);++i)
#define ForDown(i,j,k) for(int i=(j);i>=(k);--i)
#define Debug(fmt, args...) fprintf(stderr,"(func %s, line #%d): " fmt,__func__,__LINE__,##args),fflush(stderr)
#define debug(fmt, args...) fprintf(stderr,fmt,##args),fflush(stderr)
#define within :
#define LJY main
using namespace std;
typedef long long ll;
const int N=1035;
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
inline int read(){
  char ch=getchar();int x=0,f=1;
  while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
  while(ch>='0'&&ch<='9')
    x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
  return x*f;
}
int n;
vector<int>v1,v2;
char s[N][N];bool vis[N];
void ljy(){
  v1.clear();v2.clear();
  For(i,1,n) scanf("%s",s[i]+1);
  For(i,2,n) if(s[1][i]-'0') v1.emplace_back(i);else v2.emplace_back(i);
  int lg=__lg(n);
  vector<pair<int,int> >ans;
  For(i,1,lg){
    For(i,1,n) vis[i]=0;
    vector<int>v3,v4;
    for(int x within v1) for(int y within v2) if(!vis[y]&&s[x][y]=='1'){
      ans.emplace_back(x,y);v3.emplace_back(x);vis[x]=vis[y]=1;break;}
    int lst=1;
    for(int x within v1) if(!vis[x])
      if(lst){
        ans.emplace_back(lst,x);
        if(lst!=1) v3.emplace_back(s[lst][x]=='1'?lst:x);lst=0;
      }else lst=x;
    for(int x within v2) if(!vis[x])
      if(lst){
        ans.emplace_back(lst,x);
        int bst=(s[lst][x]=='1'?lst:x);
        if(s[1][bst]=='1') v3.emplace_back(bst);
        else v4.emplace_back(bst);lst=0;
      }else lst=x;
    v1.swap(v3);v2.swap(v4);
    // for(int x within v1) debug("%d ",x);debug("\n");
    // for(int x within v2) debug("%d ",x);debug("\n");
  }for(auto [x,y] within ans) printf("%d %d\n",x,y);
}
signed LJY(){while(scanf("%d",&n)==1) ljy();}

詳細信息


Pretests


Final Tests

Test #1:

score: 100
Accepted
time: 26ms
memory: 5172kb

input:

4
0110
0011
0000
1010
8
00111010
10101111
00010010
01000101
00110010
10101011
00010000
10101010
2
01
00
4
0101
0000
1100
0110
4
0011
1000
0100
0110
4
0111
0000
0100
0110
4
0101
0010
1000
0110
4
0011
1010
0000
0110
4
0111
0010
0000
0110
4
0110
0001
0100
1010
4
0101
0001
1100
0010
4
0011
1001
0100
001...

output:

2 4
1 3
1 2
4 2
1 3
5 7
6 8
4 6
1 5
1 4
1 2
4 3
1 2
1 4
3 2
1 4
1 3
1 2
3 4
1 4
2 3
1 4
1 2
4 2
1 3
1 4
1 2
3 4
1 4
2 4
1 3
1 2
4 3
1 2
1 4
3 2
1 4
1 3
1 2
3 4
1 4
2 4
1 3
1 2
2 3
1 4
1 2
1 2
3 4
1 4
3 4
1 2
1 3
3 2
1 4
1 3
1 2
3 4
1 3
3 4
1 2
1 3
2 3
1 4
1 2
4 2
1 3
1 4
1 2
3 4
1 3
2 4
1 3
1 2
3 2
...

result:

ok correct