QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#101787#6380. LaLa and Divination MagicZeardoeRE 0ms0kbC++203.0kb2023-05-01 08:28:072023-05-01 08:28:12

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-01 08:28:12]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-05-01 08:28:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
//use ll instead of int.
#define f(i, a, b) for(int i = (a); i <= (b); i++)
#define cl(i, n) i.clear(),i.resize(n);
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e9;
//#define cerr if(false)cerr
//#define freopen if(false)freopen
#define watch(x) cerr  << (#x) << ' '<<'i'<<'s'<<' ' << x << endl
void pofe(int number, int bitnum) {
    string s; f(i, 0, bitnum) {s += char(number & 1) + '0'; number >>= 1; } 
    reverse(s.begin(), s.end()); cerr << s << endl; 
    return;
}
template <typename TYP> void cmax(TYP &x, TYP y) {if(x < y) x = y;}
template <typename TYP> void cmin(TYP &x, TYP y) {if(x > y) x = y;}
//调不出来给我对拍!
//use std::array.
time_t alltime = 0;
vector<bitset<2000>> s;int ord[2020];
int n,m; struct syz {int x,y,z;};
bool vt[2020][2020][4];int trie[2020*2020][2];int cnt=1;int memo[2020];
bool dfs(int step, int cur) {
  //  cerr<<step<<" "<<cur<<endl;
  //  f(i,0,step-1)cerr<<memo[i];
  //  cerr<<endl;
    if(step==m){return cur;}
    f(i,0,1){
        bool ok=1;
        f(j,0,step-1)if(vt[j][step][(memo[j]<<1) + i]==0){ok=0;break;}
        if(vt[step][step][(i<<1)+i]==0){ok=0;}
        if(ok){
            memo[step]=i;
            if(cur==0){
                if(!dfs(step+1,0)) return 0;
            }
            else {
                if(!dfs(step+1,trie[cur][i])) return 0;
            }
        }
    }
    return 1;
}
void build(){
    f(i,0,n-1){
        int cur=1;
        f(j,0,m-1){
            if(!trie[cur][s[i][j]]) trie[cur][s[i][j]] = ++cnt;
            cur = trie[cur][s[i][j]];
        }
    }
    return;
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    freopen("G.in","r",stdin);
    freopen("G.out","w",stdout);
    //freopen();
    
    //think twice,code once.
    //think once,debug forever.
    cin>>n>>m;s.resize(n);
    f(i,0,n-1){f(j,0,m-1){char ct;cin>>ct;s[i][j]=ct-'0';}}build();
    mt19937 rng(time(0));
    shuffle(ord+1,ord+n+1,rng);vector<syz> v;
    
    f(i,0,m-1)f(j,i,m-1){
        bitset<4> ok;//time_t start = clock();
        f(k,0,n-1){
            ok[(s[k][i]<<1) + s[k][j]] = 1;
        }//time_t finish = clock(); alltime += finish - start;
        f(t,0,3){
            if(!ok[t]){if(i!=j || t==0 || t==3)v.push_back({i,j,(t==0?4:(t==3?1:t+1))});}
            else vt[i][j][t]=1;
        }
    }
    
    if(!dfs(0,1)) {
        cout << -1 << endl;
        
    //    cerr << "time used:" << alltime * 1.0 / CLOCKS_PER_SEC <<"s"<< endl;
        return 0;
    }
    // time_t finish = clock(); alltime += finish - start << endl;
    cout<<v.size()<<endl;
    for(syz it : v)cout<<it.x<<" "<<it.y<<" "<<it.z<<endl;
    //
  //  cerr << "time used:" << alltime * 1.0 / CLOCKS_PER_SEC <<"s"<< endl;
    return 0;
}
/*
2023/4/29
start thinking at 11:24


start coding at h:mm
finish debugging at h:mm
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

2 1
1
0

output:


result: