結果
| 問題 |
No.437 cwwゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-28 23:15:26 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,395 bytes |
| コンパイル時間 | 1,257 ms |
| コンパイル使用メモリ | 161,684 KB |
| 実行使用メモリ | 6,816 KB |
| 最終ジャッジ日時 | 2024-11-24 06:52:03 |
| 合計ジャッジ時間 | 2,488 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 WA * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:29:21: warning: ‘((__gnu_cxx::__alloc_traits<std::allocator<char>, char>::value_type*)((char*)&t + offsetof(std::__cxx11::string, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::<unnamed>)))[1]’ may be used uninitialized [-Wmaybe-uninitialized]
29 | if(t[0] != t[1] && t[1] == t[2]) {
main.cpp:25:20: note: ‘t’ declared here
25 | string t = "";
| ^
ソースコード
class in{struct myIterator{int it;const bool rev;explicit constexpr myIterator(int it_, bool rev=false):it(it_),rev(rev){}int operator*(){return it;}bool operator!=(myIterator& r){return it!=r.it;}void operator++(){rev?--it:++it;}};const myIterator i,n;public:explicit constexpr in(int n):i(0),n(n){}explicit constexpr in(int i,int n):i(i,n<i),n(n){}const myIterator& begin(){return i;}const myIterator& end(){return n;}};
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
string cww;
cin >> cww;
int n = cww.size();
vector<int> dp(1 << n, -1);
int s = (1 << n) - 1;
dp[s] = 0;
for(int i : in(s, -1)) if(dp[i] >= 0) {
if(__builtin_popcount(i) < 3) continue;
int comb = i;
do {
int erased = comb ^ i;
if(__builtin_popcount(erased) != 3) {
comb = (comb - 1) & i;
continue;
}
string t = "";
for(int j : in(n))
if((1 << j) & erased)
t += cww[j];
if(t[0] != t[1] && t[1] == t[2]) {
int score = (t[0] - '0') * 100 + (t[1] - '0') * 11;
dp[comb] = max(dp[comb], dp[i] + score);
}
comb = (comb - 1) & i;
} while(comb != i);
}
cout << *max_element(dp.begin(), dp.end()) << endl;
}