diff --git a/aizu/4023.cpp b/aizu/4023.cpp new file mode 100644 index 00000000..bb6f80b8 --- /dev/null +++ b/aizu/4023.cpp @@ -0,0 +1,16 @@ +#include + +#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) + +using namespace std; + +int main(void){ + int n; + scanf("%d", &n); + REP(i, 0, 2 * n + 1) { + REP(j, 0, 2 * n + 1) { + printf("%c", i % 2 == 0 && j % 2 == 0 ? '.' : '#'); + } + puts(""); + } +} diff --git a/aizu/4024.cpp b/aizu/4024.cpp new file mode 100644 index 00000000..6952c3d2 --- /dev/null +++ b/aizu/4024.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) +#define DEBUGP(val) cerr << #val << "=" << val << "\n" + +using namespace std; +typedef long long int ll; +typedef vector VI; +typedef vector VL; +typedef pair PI; +const ll mod = 1e9 + 7; + + + +int main(void) { + ios::sync_with_stdio(false); + cin.tie(0); + string s; + cin >> s; + int ma = 0; + for (char c: s) { + ma = max(ma, c - '0'); + } + ma++; + if (ma == 10 || s.size() == 1) { + cout << "No" << endl; + } else { + cout << "Yes" << endl; + } +} diff --git a/aizu/4025.cpp b/aizu/4025.cpp new file mode 100644 index 00000000..806e3875 --- /dev/null +++ b/aizu/4025.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) +#define DEBUGP(val) cerr << #val << "=" << val << "\n" + +using namespace std; +typedef long long int ll; +typedef vector VI; +typedef vector VL; +typedef pair PI; +const ll mod = 1e9 + 7; + + + +int main(void) { + ios::sync_with_stdio(false); + cin.tie(0); + int n; + cin >> n; + VI a(n), b(n); + REP(i, 0, n) { + cin >> a[i]; + } + REP(i, 0, n) { + cin >> b[i]; + } + vector ba; + REP(i, 0, n) { + ba.push_back(PI(b[i], a[i])); + } + sort(ba.begin(), ba.end()); + int ans = 0; + REP(i, 0, n) { + if (ba[i].first == ba[i].second) { + continue; + } + bool found = false; + REP(j, i + 1, n) { + if (ba[i].second == ba[j].first) { + found = true; + } + } + if (!found || ba[i].first > ba[i].second) { + cout << -1 << endl; + return 0; + } + ans++; + } + cout << ans << endl; +} diff --git a/aizu/4026.cpp b/aizu/4026.cpp new file mode 100644 index 00000000..c5ef8a62 --- /dev/null +++ b/aizu/4026.cpp @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) +#define DEBUGP(val) cerr << #val << "=" << val << "\n" + +using namespace std; +typedef long long int ll; +typedef vector VI; +typedef vector VL; +typedef pair PI; +const ll mod = 1e9 + 7; + + + +int main(void) { + ios::sync_with_stdio(false); + cin.tie(0); + string s; + cin >> s; + // oo, ox/xo, xx だけ試せば良い。他のパターンでできるならこれでもできる。 + int ma = 0; + // oo, xx + REP(iter, 0, 2) { + char target = "ox"[iter]; + int bl = 0; + int cnt = 0; + for (auto c: s) { + if (c == target) { + cnt++; + } else { + cnt = 0; + } + if (cnt >= 2) { + bl++; + cnt = 0; + } + } + ma = max(ma, bl); + } + // ox/xo + { + int bl = 0; + int pos = 0; + while (pos < (int)s.size()) { + string cut = s.substr(pos, 2); + if (cut == "ox" || cut == "xo") { + bl++; + pos += 2; + } else { + pos++; + } + } + ma = max(ma, bl); + } + cout << ma << endl; +} diff --git a/aizu/4027.cpp b/aizu/4027.cpp new file mode 100644 index 00000000..1651635d --- /dev/null +++ b/aizu/4027.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) +#define DEBUGP(val) cerr << #val << "=" << val << "\n" + +using namespace std; +typedef long long int ll; +typedef vector VI; +typedef vector VL; +typedef pair PI; +const ll mod = 1e9 + 7; + +int dist(int x, int y) { + return abs(x / 3 - y / 3) + abs(x % 3 - y % 3); +} + +int main(void) { + ios::sync_with_stdio(false); + cin.tie(0); + string n; + cin >> n; + int ans = n.size() * 4; + VI p(9); + REP(i, 0, 9) p[i] = i; + vector freq(9, VI(9, 0)); + REP(i, 0, n.size() - 1) { + int x = n[i] - '1'; + int y = n[i + 1] - '1'; + freq[x][y] += 1; + } + do { + int sum = 0; + REP(i, 0, 9) { + REP(j, 0, 9) sum += dist(p[i], p[j]) * freq[i][j]; + } + sum += dist(p[n[0] - '1'], 0); + ans = min(ans, sum); + } while (next_permutation(p.begin(), p.end())); + cout << ans + n.size() << endl; +} diff --git a/aizu/4028.cpp b/aizu/4028.cpp new file mode 100644 index 00000000..8dbe64c6 --- /dev/null +++ b/aizu/4028.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) +#define DEBUGP(val) cerr << #val << "=" << val << "\n" + +using namespace std; +typedef long long int ll; +typedef vector VI; +typedef vector VL; +typedef pair PI; +const ll mod = 1e9 + 7; + + + +int main(void) { + ios::sync_with_stdio(false); + cin.tie(0); + +} diff --git a/aizu/4029.cpp b/aizu/4029.cpp new file mode 100644 index 00000000..2e286ed6 --- /dev/null +++ b/aizu/4029.cpp @@ -0,0 +1,97 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) +#define DEBUGP(val) cerr << #val << "=" << val << "\n" + +using namespace std; +typedef long long int ll; +typedef vector VI; +typedef vector VL; +typedef pair PI; + +int main(void) { + ios::sync_with_stdio(false); + cin.tie(0); + mt19937_64 mt(time(0)); + int n, m; + cin >> n >> m; + VL s(n); + vector p(n); + vector> solve_idx(m); + VL tot(m); + VL st(m); + VL rand(n); + REP(i, 0, n) { + rand[i] = mt(); + } + // 支配関係。dom[i][j] == true だったら i は j に勝ったことがある + vector> dom(m, vector(m)); + REP(i, 0, n) { + cin >> s[i]; + int k; + cin >> k; + p[i] = VI(k); + REP(j, 0, k) { + cin >> p[i][j]; + p[i][j]--; + solve_idx[p[i][j]].push_back(PI(i, j)); + tot[p[i][j]] += s[i]; + st[p[i][j]] ^= rand[i]; + } + // O(K^2)、合計 O(NM) + REP(j, 0, k) { + REP(l, 0, j) { + dom[p[i][l]][p[i][j]] = true; + } + } + } + REP(i, 0, m) assert(!dom[i][i]); + // 最小値は常に他のチームが時間ギリギリで解いたことにすれば良いので楽。 + // 最大値が難しい。相手チームごとに自分の解いた問題のどれが遅かったかを計算して都合よく合わせることができないため。 + // どの問題を最後に解いたか決め打ちして、その問題のそれ以前および他の問題は開始 0 秒で解かれたことにすると良い。 + REP(i, 0, m) { + int loss = 0; + set possible_loss; + REP(j, 0, m) { + if (tot[i] < tot[j] || (tot[i] == tot[j] && st[i] == st[j] && dom[j][i] && !dom[i][j])) { + loss++; + continue; + } + if (tot[i] == tot[j] && (st[i] != st[j] || (dom[j][i] && dom[i][j]))) { + possible_loss.insert(j); + } + } + int ma = 0; + for (PI idx: solve_idx[i]) { + int prob = idx.first; + int rank = idx.second; + int cnt = 0; + REP(j, rank + 1, p[prob].size()) { + if (possible_loss.count(p[prob][j])) { + cnt++; + } + } + ma = max(ma, (int) possible_loss.size() - cnt); + } + cout << loss + 1 << " " << loss + ma + 1 << "\n"; + } +} diff --git a/aizu/4030.cpp b/aizu/4030.cpp new file mode 100644 index 00000000..70566359 --- /dev/null +++ b/aizu/4030.cpp @@ -0,0 +1,157 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) +#define DEBUGP(val) cerr << #val << "=" << val << "\n" + +using namespace std; +typedef long long int ll; +typedef vector VI; +typedef vector VL; +typedef pair PI; + +// (0, [i, j]): i 行目と j 列目の和集合 +// (1, [i]): i 行目 +// (2, [i]): i 列目 +// (3, [i, j, ...]): 定数個の点 (i, j), ... +// (4, []): 全体集合 +pair intersection(const vector &pts) { + if (pts.size() == 0) { + return pair(4, VI()); + } + if (pts.size() == 1) { + return pair(0, VI({pts[0].first, pts[0].second})); + } + pair cur = pair(0, VI({pts[0].first, pts[0].second})); + REP(i, 1, pts.size()) { + pair nxt = pair(0, VI({pts[i].first, pts[i].second})); + int x = pts[i].first, y = pts[i].second; + if (cur.first == 0) { + if (cur.second[0] == x) { + nxt = pair(1, VI({x})); + } else if (cur.second[1] == y) { + nxt = pair(2, VI({y})); + } else { + nxt = pair(3, VI({x, cur.second[1], cur.second[0], y})); + } + } else if (cur.first == 1) { + if (x == cur.second[0]) { + nxt = cur; + } else { + nxt = pair(3, VI({cur.second[0], y})); + } + } else if (cur.first == 2) { + if (y == cur.second[1]) { + nxt = cur; + } else { + nxt = pair(3, VI({x, cur.second[1]})); + } + } else { + assert (cur.first == 3); + VI new_pts; + REP(k, 0, cur.second.size() / 2) { + int px = cur.second[2 * k], py = cur.second[2 * k + 1]; + if (px == x || py == y) { + new_pts.push_back(px); + new_pts.push_back(py); + } + } + nxt = pair(3, new_pts); + } + cur = nxt; + } + return cur; +} + +int main(void) { + ios::sync_with_stdio(false); + cin.tie(0); + int h, w; + cin >> h >> w; + vector p(h, VI(w)); + vector> occ(h * w); + REP(i, 0, h) { + REP(j, 0, w) { + cin >> p[i][j]; + occ[p[i][j]].push_back(PI(i, j)); + } + } + vector rows(h), cols(w); + vector ans(h, VI(w, h * w)); + REP(mex, 0, h * w) { + pair inter = intersection(occ[mex]); + if (false) { + cerr << mex << ": " << inter.first << endl; + for (int x: inter.second) cerr << x << " "; + cerr << endl; + } + if (inter.first == 4) { + REP(i, 0, h) { + if (rows[i]) { + continue; + } + REP(j, 0, w) { + if (ans[i][j] == h * w) ans[i][j] = mex; + cols[j] = true; + } + rows[i] = true; + } + break; + } + if (inter.first == 0) { + int x = inter.second[0], y = inter.second[1]; + if (!cols[y]) + REP(i, 0, h) if (ans[i][y] == h * w) ans[i][y] = mex; + if (!rows[x]) + REP(j, 0, w) if (ans[x][j] == h * w) ans[x][j] = mex; + rows[x] = true; + cols[y] = true; + } else if (inter.first == 1) { + int x = inter.second[0]; + if (rows[x]) { + continue; + } + REP(j, 0, w) if (ans[x][j] == h * w) ans[x][j] = mex; + rows[x] = true; + } else if (inter.first == 2) { + int y = inter.second[0]; + if (cols[y]) { + continue; + } + REP(i, 0, h) if (ans[i][y] == h * w) ans[i][y] = mex; + cols[y] = true; + } else { + assert (inter.first == 3); + REP(k, 0, inter.second.size() / 2) { + int x = inter.second[2 * k], y = inter.second[2 * k + 1]; + if (rows[x] || cols[y]) { + continue; + } + if (ans[x][y] == h * w) ans[x][y] = mex; + } + } + } + REP(i, 0, h) { + REP(j, 0, w) { + cout << ans[i][j] << (j == w - 1 ? "\n" : " "); + } + } +} diff --git a/aizu/4032.cpp b/aizu/4032.cpp new file mode 100644 index 00000000..f90ec97b --- /dev/null +++ b/aizu/4032.cpp @@ -0,0 +1,296 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++) +#define DEBUGP(val) cerr << #val << "=" << val << "\n" + +using namespace std; +typedef long long int ll; +typedef vector VI; +typedef vector VL; +typedef pair PI; + +// https://github.com/atcoder/ac-library/blob/v1.5.1/atcoder/internal_bit.hpp +namespace internal { + +#if __cplusplus >= 202002L + +using std::bit_ceil; + +#else + +// @return same with std::bit::bit_ceil +unsigned int bit_ceil(unsigned int n) { + unsigned int x = 1; + while (x < (unsigned int)(n)) x *= 2; + return x; +} + +#endif + +// @param n `1 <= n` +// @return same with std::bit::countr_zero +int countr_zero(unsigned int n) { +#ifdef _MSC_VER + unsigned long index; + _BitScanForward(&index, n); + return index; +#else + return __builtin_ctz(n); +#endif +} + +// @param n `1 <= n` +// @return same with std::bit::countr_zero +constexpr int countr_zero_constexpr(unsigned int n) { + int x = 0; + while (!(n & (1 << x))) x++; + return x; +} + +} // namespace internal + +// https://github.com/atcoder/ac-library/blob/v1.5.1/atcoder/lazysegtree.hpp +template +struct lazy_segtree { + + public: + lazy_segtree() : lazy_segtree(0) {} + explicit lazy_segtree(int n) : lazy_segtree(std::vector(n, e())) {} + explicit lazy_segtree(const std::vector& v) : _n(int(v.size())) { + size = (int)internal::bit_ceil((unsigned int)(_n)); + log = internal::countr_zero((unsigned int)size); + d = std::vector(2 * size, e()); + lz = std::vector(size, id()); + for (int i = 0; i < _n; i++) d[size + i] = v[i]; + for (int i = size - 1; i >= 1; i--) { + update(i); + } + } + + void set(int p, S x) { + assert(0 <= p && p < _n); + p += size; + for (int i = log; i >= 1; i--) push(p >> i); + d[p] = x; + for (int i = 1; i <= log; i++) update(p >> i); + } + + S get(int p) { + assert(0 <= p && p < _n); + p += size; + for (int i = log; i >= 1; i--) push(p >> i); + return d[p]; + } + + S prod(int l, int r) { + assert(0 <= l && l <= r && r <= _n); + if (l == r) return e(); + + l += size; + r += size; + + for (int i = log; i >= 1; i--) { + if (((l >> i) << i) != l) push(l >> i); + if (((r >> i) << i) != r) push((r - 1) >> i); + } + + S sml = e(), smr = e(); + while (l < r) { + if (l & 1) sml = op(sml, d[l++]); + if (r & 1) smr = op(d[--r], smr); + l >>= 1; + r >>= 1; + } + + return op(sml, smr); + } + + S all_prod() { return d[1]; } + + void apply(int p, F f) { + assert(0 <= p && p < _n); + p += size; + for (int i = log; i >= 1; i--) push(p >> i); + d[p] = mapping(f, d[p]); + for (int i = 1; i <= log; i++) update(p >> i); + } + void apply(int l, int r, F f) { + assert(0 <= l && l <= r && r <= _n); + if (l == r) return; + + l += size; + r += size; + + for (int i = log; i >= 1; i--) { + if (((l >> i) << i) != l) push(l >> i); + if (((r >> i) << i) != r) push((r - 1) >> i); + } + + { + int l2 = l, r2 = r; + while (l < r) { + if (l & 1) all_apply(l++, f); + if (r & 1) all_apply(--r, f); + l >>= 1; + r >>= 1; + } + l = l2; + r = r2; + } + + for (int i = 1; i <= log; i++) { + if (((l >> i) << i) != l) update(l >> i); + if (((r >> i) << i) != r) update((r - 1) >> i); + } + } + + template int max_right(int l) { + return max_right(l, [](S x) { return g(x); }); + } + template int max_right(int l, G g) { + assert(0 <= l && l <= _n); + assert(g(e())); + if (l == _n) return _n; + l += size; + for (int i = log; i >= 1; i--) push(l >> i); + S sm = e(); + do { + while (l % 2 == 0) l >>= 1; + if (!g(op(sm, d[l]))) { + while (l < size) { + push(l); + l = (2 * l); + if (g(op(sm, d[l]))) { + sm = op(sm, d[l]); + l++; + } + } + return l - size; + } + sm = op(sm, d[l]); + l++; + } while ((l & -l) != l); + return _n; + } + + template int min_left(int r) { + return min_left(r, [](S x) { return g(x); }); + } + template int min_left(int r, G g) { + assert(0 <= r && r <= _n); + assert(g(e())); + if (r == 0) return 0; + r += size; + for (int i = log; i >= 1; i--) push((r - 1) >> i); + S sm = e(); + do { + r--; + while (r > 1 && (r % 2)) r >>= 1; + if (!g(op(d[r], sm))) { + while (r < size) { + push(r); + r = (2 * r + 1); + if (g(op(d[r], sm))) { + sm = op(d[r], sm); + r--; + } + } + return r + 1 - size; + } + sm = op(d[r], sm); + } while ((r & -r) != r); + return 0; + } + + private: + int _n, size, log; + std::vector d; + std::vector lz; + + void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); } + void all_apply(int k, F f) { + d[k] = mapping(f, d[k]); + if (k < size) lz[k] = composition(f, lz[k]); + } + void push(int k) { + all_apply(2 * k, lz[k]); + all_apply(2 * k + 1, lz[k]); + lz[k] = id(); + } +}; + +const ll INF = 1e16; + +ll op(ll x, ll y) { return max(x, y); } +ll e() { return -INF; } +ll mapping(ll f, ll x) { return f + x; } +ll composition(ll f, ll g) { return f + g; } +ll id() { return 0; } + +const int W = 200100; + +int main(void) { + ios::sync_with_stdio(false); + cin.tie(0); + int n; + cin >> n; + VI x(n), y(n); + VL r(n); + REP(i, 0, n) { + cin >> x[i] >> y[i] >> r[i]; + } + lazy_segtree st(W); + st.apply(0, W, INF); + ll ans = -4; + vector>> rem(W); + REP(i, 1, W) { + st.apply(i, W, -4); + } + REP(i, 0, n) { + int mi = min(x[i], y[i]); + int ma = max(x[i], y[i]); + rem[mi].push_back(make_pair(ma, r[i])); + st.apply(ma, W, r[i]); + } + REP(i, 0, W) { + if (i < 0) { + cerr << "i: " << i; + REP(i, 0, 10) cerr << " " << st.get(i); + cerr << endl; + } + ans = max(ans, st.prod(i + 1, W)); + ans = max(ans, st.get(i) - 4); + if (i + 1 < W) { + for (auto p: rem[i]) { + st.apply(p.first, W, -p.second); + } + st.apply(i + 1, W, 4); + } + } + cout << ans << "\n"; +} diff --git a/aizu/submit.go b/aizu/submit.go index 89e51581..2b142bae 100644 --- a/aizu/submit.go +++ b/aizu/submit.go @@ -43,6 +43,9 @@ func readAOJConfig(baseDir string) (*aojConfig, string, error) { yamlContent, err := os.ReadFile(aojConfigPath) // If the file is not found, recurse into the parent directory. if _, ok := err.(*fs.PathError); ok { + if baseDir == "/" { + return nil, "", fmt.Errorf("aoj_config.yml not found") + } baseDir = path.Clean(path.Join(baseDir, "..")) continue } @@ -108,8 +111,45 @@ func login(aojConfig *aojConfig) (*session, error) { return &session{JSessionID: jSessionID}, nil } +func (s *session) submit(problemID, language, source string) error { + // https://judgeapi.u-aizu.ac.jp/submissions + url := Endpoint + "/submissions" + client := &http.Client{} + + // example: + // problemId: "4023" + // language: "C++17" + // sourceCode: "a" + jsonStream, err := json.Marshal(map[string]string{ + "problemId": problemID, + "language": language, + "sourceCode": source, + }) + if err != nil { + return err + } + req, err := http.NewRequest("POST", url, bytes.NewReader(jsonStream)) + if err != nil { + log.Println("NewRequest failed") + return err + } + req.AddCookie(&http.Cookie{ + Name: JSessionIDName, + Value: s.JSessionID, + }) + req.Header.Add("Content-Type", "application/json") // Without this, the judge server fails with Internal Error. + resp, err := client.Do(req) + if err != nil { + return err + } + if resp.StatusCode/100 != 2 { + return fmt.Errorf("StatusCode = %d != 2xx", resp.StatusCode) + } + return nil +} + // http://developers.u-aizu.ac.jp/api?key=judgeapi%2Farenas%2F%7BarenaId%7D%2Fsubmissions_POST -func (session *session) submitInArena(arenaID, ID, language, source string) error { +func (s *session) submitInArena(arenaID, ID, language, source string) error { url := fmt.Sprintf("%s/arenas/%s/submissions", Endpoint, arenaID) client := &http.Client{} @@ -135,7 +175,7 @@ func (session *session) submitInArena(arenaID, ID, language, source string) erro } req.AddCookie(&http.Cookie{ Name: JSessionIDName, - Value: session.JSessionID, + Value: s.JSessionID, }) req.Header.Add("Content-Type", "application/json") // Without this, the judge server fails with Internal Error. resp, err := client.Do(req) @@ -241,8 +281,14 @@ func main() { log.Fatalf("%w", err) } } else if len(segments) == 1 { - log.Panicf("TODO: not implemented") + problemId := segments[0] + err := session.submit(problemId, language, string(source)) + if err != nil { + log.Fatalf("%w", err) + } } else { log.Fatalf("Invalid relative path: %s", relfilename) } + submissionURL := fmt.Sprintf("https://onlinejudge.u-aizu.ac.jp/status/users/%s/submissions/1", aojConfig.UserID) + log.Printf(submissionURL) } diff --git a/languages.yml b/languages.yml index 61b7200d..e1c44f87 100644 --- a/languages.yml +++ b/languages.yml @@ -2,6 +2,7 @@ file: wiz.cpp extension: cpp yukicoder_name: cpp17 + aoj_name: C++17 - name: Erlang file: erl.erl extension: erl @@ -9,6 +10,7 @@ file: rust.rs extension: rs yukicoder_name: rust + aoj_name: Rust - name: Go file: go.go extension: go