比赛链接:https://atcoder.jp/contests/abc176
A - Takoyaki
#include <bits/stdc++.h> using namespace std; int main() { int n, x, t; cin >> n >> x >> t; cout << (n + x - 1) / x * t << " "; }
B - Multiple of 9
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int mod = 0; for (char c : s) { mod += c - '0'; mod %= 9; } cout << (mod == 0 ? "Yes" : "No") << " "; }
C - Step
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long ans = 0; int mx = 0; for (int i = 0; i < n; i++) { int x; cin >> x; mx = max(mx, x); ans += mx - x; } cout << ans << " "; }
D - Wizard in Maze
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 100; const int dir[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}}; int h, w; int c_h, d_h, c_w, d_w; int ans = -1; string MP[N]; bool vis[N][N]; struct P{ int x, y; int cnt; }; bool inside(int x, int y) { return x >= 0 and x < h and y >= 0 and y < w; } void bfs() { deque<P> dque; dque.push_front({c_h, c_w, 0}); while (!dque.empty()) { auto [x, y, cnt] = dque.front(); dque.pop_front(); if (x == d_h and y == d_w) { ans = cnt; break; } if (vis[x][y]) continue; vis[x][y] = true; for (int i = 0; i < 4; i++) { int nx = x + dir[i][0]; int ny = y + dir[i][1]; if (inside(nx, ny) and MP[nx][ny] == '.') dque.push_front({nx, ny, cnt}); } for (int nx = x - 2; nx <= x + 2; nx++) { for (int ny = y - 2; ny <= y + 2; ny++) { if (inside(nx, ny) and MP[nx][ny] == '.') dque.push_back({nx, ny, cnt + 1}); } } } } int main() { cin >> h >> w; cin >> c_h >> c_w >> d_h >> d_w; --c_h, --c_w, --d_h, --d_w; for (int i = 0; i < h; i++) cin >> MP[i]; bfs(); cout << ans << " "; }
E - Bomber
#include <bits/stdc++.h> using namespace std; int main() { int h, w; cin >> h >> w; int m; cin >> m; int mxr = 0, mxc = 0; vector<int> row(h), col(w); vector<pair<int, int>> v; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; --x, --y; mxr = max(mxr, ++row[x]); mxc = max(mxc, ++col[y]); v.emplace_back(x, y); } int inter = 0; for (auto [x, y] : v) { if (row[x] == mxr and col[y] == mxc) ++inter; } int cnt_mxr = count(row.begin(), row.end(), mxr); int cnt_mxc = count(col.begin(), col.end(), mxc); cout << (mxr + mxc - (inter == 1ll * cnt_mxr * cnt_mxc)) << " "; }