結果
問題 | No.832 麻雀修行中 |
ユーザー |
|
提出日時 | 2019-05-24 22:06:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,274 bytes |
コンパイル時間 | 1,748 ms |
コンパイル使用メモリ | 176,036 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-17 10:43:04 |
合計ジャッジ時間 | 2,678 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 25 |
ソースコード
#include<bits/stdc++.h>#define REP(x,y,z) for(int x=y;x<=z;x++)#define MSET(x,y) memset(x,y,sizeof(x))#define Musing namespace std;bool vis[20];bool check(vector<int> ar,int d,int toizu) {if (d==0) {REP(i,0,13) {int j=i;while (j+1<=13 && ar[j+1]==ar[j]) j++;if (j-i+1>4) return false;i = j;}bool flg = true;for (int i=1; i<14; i+=2)if (ar[i]!=ar[i-1])flg = false;for (int i=3; i<14; i+=2)if (ar[i-1]==ar[i-2])flg = false;if (flg) return true; //chitoizu}if (d==14) {return true;}int pos=-1, pos2, pos3;REP(i,0,13) if (!vis[i]) {pos = i;break;}if (pos==-1) return false;//123 456pos2=-1, pos3=-1;REP(i,pos+1, 13) if (!vis[i]) {if (ar[i]==ar[pos]+1) pos2=i;if (ar[i]==ar[pos]+2) pos3=i;}if (pos3!=-1 && pos2!=-1) {vis[pos] = vis[pos2] = vis[pos3] = true;if (check(ar, d+3, toizu)) return true;vis[pos] = vis[pos2] = vis[pos3] = false;}//111 222pos2=-1, pos3=-1;REP(i,pos+1, 13) if (!vis[i]) {if (ar[i]==ar[pos] && pos2==-1) pos2=i;else if (ar[i]==ar[pos] && pos3==-1) pos3=i;}if (pos3!=-1 && pos2!=-1) {vis[pos] = vis[pos2] = vis[pos3] = true;if (check(ar, d+3, toizu)) return true;vis[pos] = vis[pos2] = vis[pos3] = false;}//11pos2 = -1;REP(i,pos+1, 13) if (!vis[i]) {if (ar[i]==ar[pos] && pos2==-1) pos2=i;}if (pos2!=-1 && toizu==0) {vis[pos] = vis[pos2] = true;if (check(ar, d+2, toizu+1)) return true;vis[pos] = vis[pos2] = false;}return false;}int main(){vector<int> in, tmp, ans;char buf[20];while (~scanf("%s", buf+1)) {in.clear();ans.clear();REP(i,1,13) in.push_back( buf[i]-48 );REP(i,1,9) {tmp = in;tmp.push_back(i);sort(tmp.begin(), tmp.end());MSET(vis, false);if (check(tmp, 0, 0)) ans.push_back(i);}for (int i:ans) printf("%d\n", i);}return 0;}