QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#694237#7900. Gifts from KnowledgeLi_XinyueCompile Error//C++206.1kb2024-10-31 17:31:492024-10-31 17:31:57

Judging History

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

  • [2024-10-31 17:31:57]
  • 评测
  • [2024-10-31 17:31:49]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
#define int long long
typedef unsigned long long ULL;
typedef pair<LL, LL>PII;
typedef pair<double, double>PDD;
typedef pair<char, char>PCC;
LL n, m, k;

const LL inf = 1e18;
const LL N = 1e6 + 10;
const LL mod = 1e9 + 7;
int fa[N];
int qmi(int a,int b){
    int res = 1;
    while(b){
        if(b&1)res = res*a%mod;
        a = a*a%mod;
        b>>=1;
    }
    return res;
}
int find(int i){
    return fa[i]==i?fa[i]:(fa[i] =find(fa[i]));
}
void solve(){
    cin>>n>>m;
    for(int i = 1;i<=n;i++){
        fa[i] = i;
    }
    vector<string>a(n+1);
    for(int i = 1;i<=n;i++){
        cin>>a[i];
        a[i] = " "+a[i];
    }
    map<pair<int,int>,int>mp;
    int i = 1,j = m;
    while(i<j){
            vector<int>pos1;
            vector<int>pos2;
            int cnt = 0;
        for(int k = 1;k<=n;k++){
            if(a[k][i]=='1'){
                pos1.push_back(k);
                ++cnt;
            }
            if(a[k][j]=='1'){
                    ++cnt;
                pos2.push_back(k);
            }
        }
        if(cnt>2){
            cout<<0<<"\n";
            return;
        }
        i++,j--;
        if(cnt<=1)continue;
        if(pos1.size()==2){
            int x = pos1[0];
            int y = pos1[1];
            int fx = find(x);
            int fy = find(y);
            if(mp.count({x,y})&&mp[{x,y}]==0){
                cout<<0<<"\n";
                return;
            }
            mp[{x,y}] = mp[{y,x}] = 1;
            fa[fx] = fy;
            find(fx);
        }
        else if(pos2.size()==2){
            int x = pos2[0];
            int y = pos2[1];
            int fx = find(x);
            int fy = find(y);
            if(fx==fy){
                cout<<0<<"\n";
                return;
            }
            mp[{x,y}] = mp[{y,x}] = 1;
            fa[fx] = fy;
            find(fx);
        }
        else{
            int x = pos1[0];
            int y = pos2[0];
            if(x==y)continue;
            if(mp.count({x,y})==1){
                cout<<0<<"\n";
                return;
            }
            mp[{x,y}] = mp[{y,x}] = 0;
            int fx = find(x);
            int fy = find(y);
            fa[fx] = fy;
            find(fx);
        }

    }
    if(i==j){
            int cnt = 0;
        for(int k = 1;k<=n;k++){
            if(a[k][i]=='1')++cnt;
        }
        if(cnt>=2){
            cout<<0<<"\n";
            return;
        }
    }
    int cnt = 0;
    for(int i = 1;i<=n;i++){
            find(i);
        if(fa[i]==i){
            ++cnt;
        }
    }
    int ans = qmi(2,cnt);
    cout<<ans<<"\n";
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}




#include<bits/stdc++.h>
using namespace std;

typedef long long LL;
#define int long long
typedef unsigned long long ULL;
typedef pair<LL, LL>PII;
typedef pair<double, double>PDD;
typedef pair<char, char>PCC;
LL n, m, k;

const LL inf = 1e18;
const LL N = 1e6 + 10;
const LL mod = 1e9 + 7;
int fa[N];
int qmi(int a,int b){
    int res = 1;
    while(b){
        if(b&1)res = res*a%mod;
        a = a*a%mod;
        b>>=1;
    }
    return res;
}
int find(int i){
    return fa[i]==i?fa[i]:(fa[i] =find(fa[i]));
}


void solve(){
    cin>>n>>m;
    for(int i = 1;i<=n;i++){
        fa[i] = i;
    }
    vector<string>a(n+1);
    for(int i = 1;i<=n;i++){
        cin>>a[i];
        a[i] = " "+a[i];
    }

    map<PII,int> mp;
    int i = 1,j = m;
    while(i<j){
            vector<int>pos1;
            vector<int>pos2;
            int cnt = 0;
        for(int k = 1;k<=n;k++){
            if(a[k][i]=='1'){
                pos1.push_back(k);
                ++cnt;
            }
            if(a[k][j]=='1'){
                ++cnt;
                pos2.push_back(k);
            }
        }
        if(cnt>2){
            cout<<0<<"\n";
            return;
        }
        i++,j--;
        if(cnt<=1)continue;
        if(pos1.size()==2){
            int x = pos1[0];
            int y = pos1[1];
            if(mp.find({x,y}) != mp.end())
            {
                if(mp[{x,y}] != 1)
                {
                    cout<<0<<"\n";
                    return;
                }
            }
            mp[{x,y}] = mp[{y,x}] =  1;
            int fx = find(x);
            int fy = find(y);

            fa[fx] = fy;
            find(fx);
        }
        else if(pos2.size()==2){
            int x = pos2[0];
            int y = pos2[1];
            if(mp.find({x,y}) != mp.end())
            {
                if(mp[{x,y}] != 1)
                {
                    cout<<0<<"\n";
                    return;
                }
            }
            mp[{x,y}] =mp[{y,x}]  = 1;
            int fx = find(x);
            int fy = find(y);

            fa[fx] = fy;
            find(fx);
        }
        else{
            int x = pos1[0];
            int y = pos2[0];
            if(x == y)continue;
            if(mp.find({x,y}) != mp.end())
            {
                if(mp[{x,y}] != 0)
                {
                    cout<<0<<"\n";
                    return;
                }
            }
            mp[{x,y}] =mp[{y,x}] =  0;
            int fx = find(x);
            int fy = find(y);
            fa[fx] = fy;
            find(fx);
        }

    }
    if(i==j){
        int cnt = 0;
        for(int k = 1;k<=n;k++){
            if(a[k][i]=='1')++cnt;
        }
        if(cnt>=2){
            cout<<0<<"\n";
            return;
        }
    }
    int cnt = 0;
    for(int i = 1;i<=n;i++){
            find(i);
        if(fa[i]==i){
            ++cnt;
        }
    }
    int ans = qmi(2,cnt);
    cout<<ans<<"\n";
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

Details

answer.code:148:4: error: redefinition of ‘LL n’
  148 | LL n, m, k;
      |    ^
answer.code:10:4: note: ‘LL n’ previously declared here
   10 | LL n, m, k;
      |    ^
answer.code:148:7: error: redefinition of ‘LL m’
  148 | LL n, m, k;
      |       ^
answer.code:10:7: note: ‘LL m’ previously declared here
   10 | LL n, m, k;
      |       ^
answer.code:148:10: error: redefinition of ‘LL k’
  148 | LL n, m, k;
      |          ^
answer.code:10:10: note: ‘LL k’ previously declared here
   10 | LL n, m, k;
      |          ^
answer.code:150:10: error: redefinition of ‘const LL inf’
  150 | const LL inf = 1e18;
      |          ^~~
answer.code:12:10: note: ‘const LL inf’ previously defined here
   12 | const LL inf = 1e18;
      |          ^~~
answer.code:151:10: error: redefinition of ‘const LL N’
  151 | const LL N = 1e6 + 10;
      |          ^
answer.code:13:10: note: ‘const LL N’ previously defined here
   13 | const LL N = 1e6 + 10;
      |          ^
answer.code:152:10: error: redefinition of ‘const LL mod’
  152 | const LL mod = 1e9 + 7;
      |          ^~~
answer.code:14:10: note: ‘const LL mod’ previously defined here
   14 | const LL mod = 1e9 + 7;
      |          ^~~
answer.code:153:5: error: redefinition of ‘long long int fa [1000010]’
  153 | int fa[N];
      |     ^~
answer.code:15:5: note: ‘long long int fa [1000010]’ previously declared here
   15 | int fa[N];
      |     ^~
answer.code:154:5: error: redefinition of ‘long long int qmi(long long int, long long int)’
  154 | int qmi(int a,int b){
      |     ^~~
answer.code:16:5: note: ‘long long int qmi(long long int, long long int)’ previously defined here
   16 | int qmi(int a,int b){
      |     ^~~
answer.code:163:5: error: redefinition of ‘long long int find(long long int)’
  163 | int find(int i){
      |     ^~~~
answer.code:25:5: note: ‘long long int find(long long int)’ previously defined here
   25 | int find(int i){
      |     ^~~~
answer.code:168:6: error: redefinition of ‘void solve()’
  168 | void solve(){
      |      ^~~~~
answer.code:28:6: note: ‘void solve()’ previously defined here
   28 | void solve(){
      |      ^~~~~
answer.code:278:8: error: redefinition of ‘int main()’
  278 | signed main() {
      |        ^~~~
answer.code:123:8: note: ‘int main()’ previously defined here
  123 | signed main() {
      |        ^~~~