#include<iostream> #include<map> #include<cstring> #include<vector> #include<deque> usingnamespace std; #define int long long deque<char> v; int a[15]; map<string, int> m = { {"QQ",1},{"QW",2},{"QE",3},{"WQ",4},{"WW",5},{"WE",6},{"EQ",7},{"EW",8},{"EE",9},{"R",10} }; string s; int ans = 0; signedmain() { for (int i = 1; i <= 10; i++) cin >> a[i]; cin >> s; for (int i = 0; i < s.size(); i++) { if (v.empty()) { if (s[i] == 'R') ans += a[m["R"]]; else v.push_back(s[i]); } else { char t = v.front(); v.pop_front(); if (s[i] == 'R') continue; else { string que = ""; que += t; que += s[i]; ans += a[m[que]]; } } } cout << ans; return0; }
#include<iostream> #include<queue> #include<algorithm> #include<cstring> usingnamespace std; constint N = 510; int g[N][N]; int n, m; int l[N][N], r[N][N]; int st[N][N]; int dx[4] = { -1, 1, 0, 0 }, dy[4] = { 0, 0, 1, -1 }; voiddfs(int i, int j) { st[i][j] = 1; for (int t = 0; t < 4; t++) { int x = i + dx[t], y = j + dy[t]; if (x >= 1 && y >= 1 && x << n && y <= m) { if (g[x][y] < g[i][j]) { if (!st[x][y]) dfs(x, y); l[i][j] = min(l[i][j], l[x][y]); r[i][j] = max(r[i][j], r[x][y]); } } } } signedmain() { memset(l, 0x3f3f3f3f, sizeof l); cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { cin >> g[i][j]; if (i == n) l[i][j] = r[i][j] = j; } for (int i = 1; i <= m; i++) if (!st[1][i]) dfs(1, i); int cnt0 = 0, cnt1 = 0; for (int i = 1; i <= m; i++) if (!st[n][i]) cnt0++; if (cnt0) cout << 0 << '\n' << cnt0; else { int tl = 1, tr = r[1][1]; while (tl <= m) { for (int i = 1; i <= m; i++) { if (l[1][i] <= tl) tr = max(tr, r[1][i]); } tl = tr + 1; cnt1++; } cout << 1 << '\n' << cnt1; } return0; }