版本比较
2024.2.23周赛订正
正文
增加 16 行删除 16 行
16 行未改动1718192021212223242526262728293030 行未改动6162636465656667686917 行未改动8788899091919293939495969726 行未改动1241251261271281281291301311327 行未改动1401411421431441451441451461471481491501511521531541551551561571581591601611621631641621631641651661671681691701701711721731747 行未改动1821831841851861861871881891901911921931931941951951961971981995 行未改动16 行未改动 { puts("1"); cout << max(b - a, c - b) - 1 << '\n'; } else else { cout << 2 << '\n'; cout << max(b - a, c - b) - 1 << '\n'; }
return 0;}```-----------------------------30 行未改动 ct[stk[i][cnt - 1]] ++ ; s[stk[i][cnt - 1]].insert(i); if (ct[stk[i][cnt - 1]] == 2) q.push(stk[i][cnt - 1]); }
int res = 0; while (q.size()) { int t = q.front(); q.pop();17 行未改动 ct[stk[b][cnt - 1]] ++ ; s[stk[b][cnt - 1]].insert(b); if (ct[stk[b][cnt - 1]] == 2) q.push(stk[b][cnt - 1]); } res ++ ; res ++ ; }
if (res == n) cout << "Yes\n"; else cout << "No\n";
return 0;26 行未改动 while (j && p[i] != p[j + 1]) j = ne[j]; if (p[i] == p[j + 1]) j ++ ; ne[i] = j; }
// cout << ne[m] << '\n'; if (n == 1 && m == 1) { cout << "-1\n";7 行未改动 if (n == 1) cout << ne[m] << '\n'; else if(!(m % (m - ne[m]))) cout << (n - 1) * m + ne[m] << '\n'; else cout << (n - 1) * m << '\n'; }
return 0;}```---------------------## D 排列与交换```#include <bits/stdc++.h>#define int long long
using namespace std; using namespace std;
const int N = 10010, MOD = 1e9 + 7;
int n, K;int sum[N];int f[N][N], g[N][N];//设f[i][j]表示对长度为i的A进行恰好j次相邻交换(无重复交换),能得到多少个不同的序列 //设g[i][j]表示对长度为i的A进行j次交换,能得到多少个不同的序列 //f[i][j] += f[i - 1][k](max(0, j - (i - 1)) <= k <= j)(经过i - 1次交换后应该是所有可能序列都出现了,所以要大于等于j - (i - 1)) //设f[i][j]表示对长度为i的A进行恰好j次相邻交换(无重复交换),能得到多少个不同的序列//设g[i][j]表示对长度为i的A进行j次交换,能得到多少个不同的序列//f[i][j] += f[i - 1][k](max(0, j - (i - 1)) <= k <= j)(经过i - 1次交换后应该是所有可能序列都出现了,所以要大于等于j - (i - 1))//g[i][j] = g[i - 1][j] + g[i - 1][j - 1] * (i - 1)
signed main(){ cin >> n >> K;
f[1][0] = 1; for (int i = 2; i <= n; i ++ ) { for (int j = 0; j <= K; j ++ )7 行未改动 g[1][0] = 1; for (int i = 2; i <= n; i ++ ) for (int j = 0; j <= K; j ++ ) (g[i][j] = g[i - 1][j] + g[i - 1][j - 1] * (i - 1)) %= MOD;
int res1 = 0, res2 = 0; for (int i = 0; i <= K; i ++ ) { if (i % 2 == K % 2) (res1 += f[n][i]) %= MOD; (res2 += g[n][i]) %= MOD; }
cout << res1 << ' ' << res2 << '\n';
return 0;}```-----------------------------5 行未改动