T1:To Be Saikyo

\(x \geqslant \max({p_i}), i > 1\)

代码实现
n = int(input())
a = list(map(int, input().split()))
if n == 1:
    exit(print(0))
mx = max(a[1:])
ans = max(0, mx+1-a[0])
print(ans)

T2:Who is Saikyo?

\((A_i, B_i)\) 连一条有向边,使得 \(A_i \to B_i\),同时统计每个点的入度

当入度为 \(0\) 的点超过 \(1\) 个则无解
否则答案为入度为 \(0\) 的那个点

代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    
    set<int> st;
    for (int i = 1; i <= n; ++i) st.insert(i);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        st.erase(b);
    }
    
    if (st.size() >= 2) puts("-1");
    else cout << *st.begin() << '\n';
    
    return 0;
}

T3:Approximate Equalization 2

注意到不管怎么操作总和始终不变

最终的形态经排序后为 \((X, X, \cdots, X+1, \cdots, X+1)\)

总和 \(S = NX+r\),其中 \(r\) 表示序列中 +1 的个数
那么 \(X = \lfloor\frac{S}{N}\rfloor\)\(r = S\%N\)

然后将最终形态的序列和原序列作差,对差值为正数的那些数进行累加便能得到答案

代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    
    ll s = reduce(a.begin(), a.end());
    ll x = s/n, r = s%n;
    vector<ll> b(n, x);
    rep(i, r) b[i]++;
    
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    
    ll ans = 0;
    rep(i, n) ans += abs(a[i]-b[i]);
    ans /= 2;
    cout << ans << '\n';
    
    return 0;
}

T4:Odd or Even

可以通过查询前 \(K+1\) 个数中任意 \(K\) 个数的和的奇偶性来确定这前 \(K+1\) 个数,然后固定前 \(K-1\) 个数,通过向其中分别加入 \(A_{K+2}, A_{K+3}, \cdots, A_N\) 从而得到 \(A_{K+2}, A_{K+3}, \cdots, A_N\)

代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	
	auto f = [&](vector<int> x) {
	    rep(i, k) x[i]++;
	    cout << '?';
	    rep(i, k) cout << ' ' << x[i];
	    cout << '\n';
	    int res;
	    cin >> res;
	    return res;
	};
	
	vector<int> a(n), b(k+1);
	int t = 0;
	rep(i, k+1) {
	    vector<int> x;
	    rep(j, k+1) if (j != i) x.push_back(j);
	    b[i] = f(x);
	   // t += b[i]; t %= 2;
	    t ^= b[i];
	}
	rep(i, k+1) a[i] = b[i]^t;
	
	t = 0;
	rep(i, k-1) t ^= a[i];
	for (int i = k+1; i < n; ++i) {
	    vector<int> x;
	    rep(j, k-1) x.push_back(j);
	    x.push_back(i);
	    a[i] = t^f(x);
	}
	
	cout << '!';
	rep(i, n) cout << ' ' << a[i];
	
	return 0;
}

T5:Duplicate

如果 \(S\) 中存在大于 \(1\) 的两个数相邻一定无解,因为从那里一定会产生大于 \(1\) 的两个数相邻的地方
除此以外,通过找规律发现从后往前删除每个字符会得到一个一次函数

代码实现
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using mint = modint998244353;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    rep(i, n-1) {
        if (s[i] > '1' and s[i+1] > '1') {
            puts("-1");
            return 0;
        }
    }
    
    mint ans;
    while (s.size() > 1) {
        int c = s.back()-'0';
        ans += 1;
        ans += ans*(c-1);
        s.pop_back();
    }
    
    cout << ans.val() << '\n';
    
    return 0;
}