20240909

libohan0518發表於2024-10-17

Dihedral Group

猜結論,我們觀察樣例就可以猜到,只要 \(t\) 可以被 \(d\) 在一個圓上正著或泛著表示即可

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 5e4 + 5;

int n, m, a[N], b[N], pos[N];

signed main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
  }
  for (int i = 2; i <= m; i++) {
    int tmp = (pos[b[i]] + n - pos[b[i - 1]]) % n;
    int tmp1 = (pos[b[i - 1]] + n - pos[b[i]]) % n;
    if (min(tmp, tmp1) != 1) {
      cout << 0;
      return 0;
    }
  }
  cout << 1;
  return 0;
}//

Passport Stamps

也是結論題,非常好想,沒什麼好說的

#include <bits/stdc++.h>

using namespace std;

#define int long long

int n, p, c;

signed main() {
  cin >> n >> p;
  __int128 sum = 0;
  for (__int128 i = 1; i <= n; i++) {
    cin >> c;
    if ((i - 1) * (c - 1) + c + sum > p) {
      int tmp = i - 1;
      cout << tmp;
      return 0;
    }
    sum += c;
  }
  cout << n;
  return 0;
}//