結果
問題 | No.1029 JJOOII 3 |
ユーザー | otera |
提出日時 | 2020-05-12 16:23:11 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 293 ms / 2,000 ms |
コード長 | 2,474 bytes |
コンパイル時間 | 1,269 ms |
コンパイル使用メモリ | 120,816 KB |
実行使用メモリ | 6,312 KB |
最終ジャッジ日時 | 2023-10-11 15:43:45 |
合計ジャッジ時間 | 9,154 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,004 KB |
testcase_01 | AC | 3 ms
5,720 KB |
testcase_02 | AC | 3 ms
5,712 KB |
testcase_03 | AC | 17 ms
5,988 KB |
testcase_04 | AC | 54 ms
6,100 KB |
testcase_05 | AC | 249 ms
6,232 KB |
testcase_06 | AC | 179 ms
6,052 KB |
testcase_07 | AC | 222 ms
6,076 KB |
testcase_08 | AC | 238 ms
6,156 KB |
testcase_09 | AC | 205 ms
6,072 KB |
testcase_10 | AC | 215 ms
6,308 KB |
testcase_11 | AC | 267 ms
6,216 KB |
testcase_12 | AC | 146 ms
5,980 KB |
testcase_13 | AC | 271 ms
6,216 KB |
testcase_14 | AC | 275 ms
6,276 KB |
testcase_15 | AC | 183 ms
6,048 KB |
testcase_16 | AC | 212 ms
6,160 KB |
testcase_17 | AC | 252 ms
6,220 KB |
testcase_18 | AC | 257 ms
6,232 KB |
testcase_19 | AC | 3 ms
5,708 KB |
testcase_20 | AC | 4 ms
5,880 KB |
testcase_21 | AC | 4 ms
5,788 KB |
testcase_22 | AC | 4 ms
5,716 KB |
testcase_23 | AC | 4 ms
5,732 KB |
testcase_24 | AC | 4 ms
5,728 KB |
testcase_25 | AC | 4 ms
5,724 KB |
testcase_26 | AC | 4 ms
5,816 KB |
testcase_27 | AC | 5 ms
5,792 KB |
testcase_28 | AC | 4 ms
5,812 KB |
testcase_29 | AC | 4 ms
5,716 KB |
testcase_30 | AC | 5 ms
5,796 KB |
testcase_31 | AC | 4 ms
5,744 KB |
testcase_32 | AC | 287 ms
6,248 KB |
testcase_33 | AC | 293 ms
6,312 KB |
testcase_34 | AC | 292 ms
6,252 KB |
testcase_35 | AC | 291 ms
6,228 KB |
testcase_36 | AC | 290 ms
6,224 KB |
testcase_37 | AC | 3 ms
5,772 KB |
testcase_38 | AC | 3 ms
5,808 KB |
testcase_39 | AC | 3 ms
5,740 KB |
testcase_40 | AC | 3 ms
5,944 KB |
ソースコード
/** * author: otera **/ #include<iostream> #include<string> #include<cstdio> #include<cstring> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<deque> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<cassert> using namespace std; #define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef long double ld; const int inf=1e9+7; const ll INF=1LL<<60 ; const ll mod=1e9+7 ; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<int, int> P; typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(),c.end() #define pb push_back #define debug(x) cerr << #x << " = " << (x) << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } void solve() { int n, k; cin >> n >> k; vector<string> s(n); vector<int> c(n); rep(i, n) { cin >> s[i] >> c[i]; } vector<vector<int>> cnt(n, vector<int>(3, 0)); string JOI = "JOI"; rep(i, n) { rep(j, 3) { cnt[i][j] = count(all(s[i]), JOI[j]); } } static int dp[300300]; rep(i, 300300) { dp[i] = INF; } dp[0] = 0; string t = string(k, 'J') + string(k, 'O') + string(k, 'I') + string(k, '?'); rep(i, 3 * k) { rep(j, n) { int pos = i; int sz = (int)s[j].size(); if(t[i] == t[i + sz]) { pos += cnt[j][i / k]; } else { for(char c: s[j]) { if(t[pos] == c) ++ pos; } } chmin(dp[pos], dp[i] + c[j]); } } if(dp[3 * k] == INF) { cout << -1 << endl; } else { cout << dp[3 * k] << endl; } } signed main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(10); //int t; cin >> t; rep(i, t)solve(); solve(); return 0; }