結果
問題 | No.1818 6 Operations |
ユーザー | rabimea |
提出日時 | 2023-03-01 18:35:41 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 90 ms / 2,500 ms |
コード長 | 1,147 bytes |
コンパイル時間 | 2,114 ms |
コンパイル使用メモリ | 201,528 KB |
実行使用メモリ | 66,536 KB |
最終ジャッジ日時 | 2023-10-14 22:31:24 |
合計ジャッジ時間 | 5,979 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 19 ms
66,200 KB |
testcase_01 | AC | 19 ms
66,452 KB |
testcase_02 | AC | 19 ms
66,192 KB |
testcase_03 | AC | 18 ms
66,192 KB |
testcase_04 | AC | 18 ms
66,280 KB |
testcase_05 | AC | 19 ms
66,196 KB |
testcase_06 | AC | 19 ms
66,184 KB |
testcase_07 | AC | 18 ms
66,316 KB |
testcase_08 | AC | 32 ms
66,228 KB |
testcase_09 | AC | 64 ms
66,308 KB |
testcase_10 | AC | 31 ms
66,224 KB |
testcase_11 | AC | 34 ms
66,308 KB |
testcase_12 | AC | 53 ms
66,408 KB |
testcase_13 | AC | 34 ms
66,284 KB |
testcase_14 | AC | 46 ms
66,284 KB |
testcase_15 | AC | 51 ms
66,248 KB |
testcase_16 | AC | 37 ms
66,444 KB |
testcase_17 | AC | 54 ms
66,300 KB |
testcase_18 | AC | 83 ms
66,304 KB |
testcase_19 | AC | 56 ms
66,232 KB |
testcase_20 | AC | 73 ms
66,240 KB |
testcase_21 | AC | 87 ms
66,240 KB |
testcase_22 | AC | 52 ms
66,296 KB |
testcase_23 | AC | 80 ms
66,536 KB |
testcase_24 | AC | 75 ms
66,436 KB |
testcase_25 | AC | 63 ms
66,240 KB |
testcase_26 | AC | 71 ms
66,232 KB |
testcase_27 | AC | 80 ms
66,328 KB |
testcase_28 | AC | 33 ms
66,200 KB |
testcase_29 | AC | 32 ms
66,360 KB |
testcase_30 | AC | 90 ms
66,340 KB |
testcase_31 | AC | 58 ms
66,292 KB |
testcase_32 | AC | 82 ms
66,304 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back using vi = vector <int>; using ll = long long; using vl = vector <ll>; using pii = pair <int, int>; const ll mod = 998244353; //~ const ll mod = 1e9 + 7; ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a; for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; } const int N = 4e3 + 11; int f[N][N]; void chmin(int &a, int b) { if(a > b) a = b; } int main() { ios::sync_with_stdio(0); int n, m; cin >> n >> m; vi a, b; for(int i = 0; i < n; i ++) { int x; cin >> x; a.pb(0); for(int j = 0; j < x; j ++) a.pb(1); } for(int i = 0; i < m; i ++) { int x; cin >> x; b.pb(0); for(int j = 0; j < x; j ++) b.pb(1); } n = a.size(); m = b.size(); a.pb(2); b.pb(2); memset(f, 0x3f, sizeof f); f[0][0] = 0; for(int i = 0; i < n; i ++) for(int j = 0; j < m; j ++) { chmin(f[i + 1][j], f[i][j] + 1); chmin(f[i][j + 1], f[i][j] + 1); if(a[i + 1] == b[j + 1]) chmin(f[i + 1][j + 1], f[i][j]); else chmin(f[i + 1][j + 1], f[i][j] + 1); } cout << f[n - 1][m - 1] << '\n'; }