結果
問題 | No.437 cwwゲーム |
ユーザー |
![]() |
提出日時 | 2019-04-04 18:18:56 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 1,661 bytes |
コンパイル時間 | 989 ms |
コンパイル使用メモリ | 102,500 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-12 08:51:04 |
合計ジャッジ時間 | 2,097 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include<algorithm> #include<complex> #include<ctype.h> #include<iomanip> #include<iostream> #include<fstream> #include<map> #include<math.h> #include<numeric> #include<queue> #include<set> #include<stack> #include<stdio.h> #include<string> #include<string> #include<vector> using namespace std; typedef long long ll; #define FOR(i,a,b) for(ll i=(a);i<(b);++i) #define ALL(v) (v).begin(), (v).end() #define p(s) cout<<(s)<<endl #define p2(s, t) cout << (s) << " " << (t) << endl #define br() p("") #define pn(s) cout << (#s) << " " << (s) << endl #define p_yes() p("Yes") #define p_no() p("No") const ll mod = 1e9 + 7; const ll inf = 1e18; string s; ll L; bool is_chihuahua(ll i, ll j, ll k){ if(s[i]!='0' && s[i]!=s[j] && s[j]==s[k]) return true; return false; } ll calc_score(ll i, ll j, ll k){ stringstream ss; ss << s[i] << s[j] << s[k]; return stoi(ss.str()); } ll dfs(ll f){ ll max_score = 0; FOR(i, 0, L){ FOR(j, i+1, L){ FOR(k, j+1, L){ // もう使用済み if(f>>i & 1 || f>>j & 1 || f>>k & 1) continue; // チワワじゃない if(!is_chihuahua(i, j, k)) continue; // 今回のフラグ ll flag = (1<<i) + (1<<j) + (1<<k); // 今回のスコア ll score = calc_score(i, j, k); max_score = max(max_score, dfs(f+flag) + score); } } } return max_score; } int main(){ cin.tie(0); ios::sync_with_stdio(false); // input cin >> s; L = s.size(); ll ans = dfs(0); p(ans); return 0; }