QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#116045#4777. Tichumomoyuu#WA 159ms3540kbC++172.5kb2023-06-28 02:05:492023-06-28 02:05:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-28 02:05:52]
  • 评测
  • 测评结果:WA
  • 用时:159ms
  • 内存:3540kb
  • [2023-06-28 02:05:49]
  • 提交

answer

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


bool ch(vector<pair<int,int>>&now){
    sort(now.begin(),now.end());
    if(now.size()<=1) return 1;
    if(now.size()==2){
        if(now[0].first==now[1].first)return 1;
    }
    if(now[0].first==now.back().first) return 1;
    if(now.size()==5){
        int k = now[0].first;
        int kk = now.back().first;
        int c = 0;
        int cc = 0;
        for(int i = 0;i<5;i++){
            if(now[i].first==k) c++;
            if(now[i].first==kk) cc++;
        }
        if(c==3&&cc==2) return 1;
        if(c==2&&cc==3) return 1;
    }
    int cnt = now.size();
    if(now.size()<5) return 0;
    for(int i = 0;i<now.size()-1;i++){
        if(now[i].first==now[i+1].first-1) continue;
        return false;
    }
    return 1;


}

void solve(){
    int n = 13;
    vector<string> now(n);
    vector<pair<int,int>> use(n);
    for(int i = 0;i<n;i++){
        cin>>now[i];
        char c = now[i][0];
        if('0'<=c&&c<='9') use[i].first = c - '0';
        else if(c=='A') use[i].first = 14;
        else if(c=='T') use[i].first = 10;
        else if(c=='J') use[i].first = 11;
        else if(c=='Q') use[i].first = 12;
        else use[i].first = 13;
        c = now[i][1];
        if(c=='h') use[i].second = 1;
        else if(c=='d') use[i].second = 2;
        else if(c=='s') use[i].second = 3;
        else use[i].second = 4;
    }
    vector<int> dp(1<<n,1e9);
    dp[0] = 0;
    vector<int> can(1<<n,0);
    for(int i = 0;i<1<<n;i++){
        vector<pair<int,int>> a;
        for(int j = 0;j<n;j++) if(i>>j&1) a.push_back(use[j]);
        bool ok = ch(a);
        can[i] = ok;
    }
    int mask = (1<<n) - 1;
    for(int i = 0;i<1<<n;i++){
        int k = mask ^ i;
        for(int j = (1<<n)-1;j>=0;j--){
            j &= k;
            if(can[j]) dp[i|j] = min(dp[i|j],dp[i]+1);
        }
    }
    cout<<dp[(1<<n)-1]<<endl;
    int nn = (1<<n) - 1;
    while(nn!=0){
        for(int i = (1<<n)-1;i>=0;i--){
            i &= nn;
            if(dp[i]+1==dp[nn]){
                int k = nn ^ i;
                nn = i;
                int cnt = 0;
                for(int j = 0;j<n;j++) if(k>>j&1){
                    if(cnt++) cout<<" ";
                    cout<<now[j];
                }
                cout<<endl;
            }
        }
    }
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 3540kb

input:

2
2h 3c 4d 5d 6s Th Qc Qs Ad Tc Ts 9c 9d
2h 3h 4h 5h 6d 7s 8h 8d 8c 8s 9c Td Js

output:

4
2h 3c 4d 5d 6s
Qc Qs
Ad
Th Tc Ts 9c 9d
2
8h 8d 8c
2h 3h 4h 5h 6d 7s 8s 9c Td Js

result:

ok correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 159ms
memory: 3508kb

input:

63
2h 3c 4d 5d 6s Th Qc Qs Ad Tc Ts 9c 9d
2h 3h 4h 5h 6d 7s 8h 8d 8c 8s 9c Td Js
2h 2d 2c 2s 4s 4d 4c Qh Qs Qc Ts Js Ac
5d 5c 7d 5s 3s 3c Qh 3d Qc Ts 5h Js Qs
2s 3h 4d 5d 6d 7s 8s 9s Tc Jd Qc Kc As
2s 3h 4d 5d 6d 7s 8s 9s Tc Jd Qc Kc 8c
2s 3h 4d 5d 6d 7s 8s 9s Tc Jd Qc 8c 7h
3h 4d 5d 6d 7s 8s 9s Tc ...

output:

4
2h 3c 4d 5d 6s
Qc Qs
Ad
Th Tc Ts 9c 9d
2
8h 8d 8c
2h 3h 4h 5h 6d 7s 8s 9c Td Js
5
2h 2d 2c 2s 4s
4d 4c Qh Qs Qc
Ts
Js
Ac
5
7d
5d 5c 3s 3c 3d
Ts
Js
5s Qh Qc 5h Qs
1
2s 3h 4d 5d 6d 7s 8s 9s Tc Jd Qc Kc As
2
8s
2s 3h 4d 5d 6d 7s 9s Tc Jd Qc Kc 8c
2
7s 8s
2s 3h 4d 5d 6d 9s Tc Jd Qc 8c 7h
2
7s 8s 9s
3h...

result:

wrong answer invalid combination: 2h 2d 2c 2s 4s (test case 3)