AtCoder abc333 参加メモ

Toyota Programming Contest 2023#8(AtCoder Beginner Contest 333) - AtCoder

B - Pentagon

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define endl '\n'

int main() {
  string s,t; cin >> s >> t;
  auto f = [&](string s) {
    int x = s[0]-'A', y = s[1]-'A';
    int d = abs(x-y);
    return d > 2 ? 5 - d : d;
  };

  cout << (f(s) == f(t) ? "Yes" : "No") << endl;
  return 0;
}

C - Repunit Trio

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define endl '\n'
using ll = long long;

int main() {
  int n; cin >> n;
  vector<ll> x = { 1 };
  REP(i,11) x.push_back(x.back()*10+1);

  set<ll> st;
  auto dfs = [&](auto self, ll tot, int cnt) -> void {
    if (cnt == 3) { st.insert(tot); return; }
    for(auto v: x) { self(self,tot+v,cnt+1); }
  };

  dfs(dfs,0,0);
  auto it = st.begin();
  REP(i,n-1) it++;
  cout << *it << endl;
  return 0;
}

D - Erase Leaves

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define endl '\n'

int main() {
  int n; cin >> n;
  vector g(n,vector<int>());
  REP(i,n-1) {
    int u,v; cin >> u >> v;
    u--; v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  auto dfs = [&](auto self, int i, int p) -> int {
    int res = 1;
    for(auto v: g[i]) {
      if (v == p) continue;
      res += self(self,v,i);
    }
    return res;
  };

  vector<int> s;
  for(auto v: g[0]) s.push_back(dfs(dfs,v,0));
  sort(s.begin(),s.end());

  s.pop_back();
  int ans = 1;
  for(auto v: s) ans += v;
  cout << ans << endl;

  return 0;
}

E - Takahashi Quest

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define endl '\n'
using ll = long long;

int main() {
  int n; cin >> n;
  vector<int> t(n),x(n);
  REP(i,n) {
    cin >> t[i] >> x[i];
    x[i]--;
  }

  vector g(n, vector<int>());
  vector<int> potion(n); // potion[i] := ポーションを i に拾ったら 1
  REP(i,n) {
    if (t[i] == 1) g[x[i]].push_back(i);
    if (t[i] == 2) {
      if (g[x[i]].size() == 0) { cout << -1 << endl; return 0; }
      potion[g[x[i]].back()] = 1;
      g[x[i]].pop_back();
    }
  }

  vector<int> ans;
  int mx = 0, sum = 0;
  REP(i,n) {
    if (t[i] == 1) {
      ans.push_back((potion[i] ? 1 : 0));
      if (potion[i]) { sum++; mx = max(mx,sum); }
    }
    if (t[i] == 2) sum--;
  }

  cout << mx << endl;
  for(auto v: ans) cout << v << " ";
  return 0;
}
tic40さんのトヨタ自動車プログラミングコンテスト2023#8(AtCoder Beginner Contest 333)での成績:2207位
パフォーマンス:1144相当
レーティング:1048→1058 (+10) :)
#AtCoder #トヨタ自動車プログラミングコンテスト2023#8(ABC333) https://atcoder.jp/users/tic40/history/share/abc333?lang=ja