20251011总结
前言
666今天又坠机了,A题挂了60分,C题还没写出来。
分数:
题目
A - password
666少打一个!死了60分,火大。
简单题,不说了,直接上代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 10;
int n, k, mp[25][25];
string s, t;
vector<int> v[N];
signed main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> k >> s; s = ' ' + s;
int fl = 0, ans = 1;
for(int i = 1, l; i <= n; i++){
char c;
cin >> l; ans *= l;
for(int j = 1; j <= l; j++) {
cin >> c;
mp[i][c - '0'] = 1;
}
fl |= !(mp[i][s[i] - '0']);
}
for(int i = 1; i <= k; i++){
cin >> t; t = ' ' + t;
int f = 0;
for(int j = 1; j <= n; j++) {
f |= !(mp[j][t[j] - '0']);
}
ans -= !f;
}
if(fl){
cout << -1;
return 0;
}
cout << ans;
return 0;
}
B - matrix
666神秘推式子题我竟然做出来了,听说能用矩阵优化,我不会写,于是推了1h终于推出来了。
题意就是一堆一次函数套在一起, 于是我们来快乐的推式子:
先对于单一行算贡献,直接拆括号得:
可以发现
再套上第二层的括号,得:
再来推当有三层时的答案:
到这之后公式其实已经出来了,即当有
我们又可以发现
那么我们就做完了。
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 10, MOD = 1e9 + 7;
int POW(int x, int y){
int res = 1;
while(y){
if(y & 1){
(res *= x) %= MOD;
}
(x *= x) %= MOD, y >>= 1;
}
return res;
}
int Pow(int x, string y){
int res = 1;
for(int i = 0; i < y.size(); i++){
res = POW(res, 10) * POW(x, y[i] - '0') % MOD;
}
return res;
}
string n, m;
int a, b, c, d;
int calc(int x, string s){
if(x == 1){
int op = 0;
for(int i = 0; i < s.size(); i++){
op = (op * 10 + s[i] - '0') % MOD;
}
return op;
}
return (Pow(x, s) - 1 + MOD) % MOD * POW(x - 1, MOD - 2) % MOD;
}
string f(string s){
for(int i = s.size() - 1; i >= 0; i--){
if(s[i] >= '1'){
s[i]--;
break;
}
s[i] = '9';
}
return s;
}
signed main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> m >> a >> b >> c >> d;
string nx = f(n), mx = f(m);
int x = Pow(a, mx), e = calc(a, mx);
int ans1 = Pow(c, nx) * Pow(x, n) % MOD;
int ans2 = d * x % MOD * calc(c * x % MOD, nx) % MOD;
int ans3 = b * e % MOD * calc(c * x % MOD, n) % MOD;
cout << (ans1 + ans2 + ans3) % MOD;
return 0;
}
C - perm
666神秘结论题我竟然没做出来,赛后发现自己是啥子。
无解的情况很好判,判完后我们又可以分类讨论,当
#include<bits/stdc++.h>
#define lp p<<1
#define rp p<<1|1
#define int long long
using namespace std;
const int N = 2e6 + 10, MOD = 1e9 + 7;
int T, n, a[N];
void solve(){
cin >> n;
int fl = 0;
for(int i = 1; i <= n; i++){
cin >> a[i];
fl |= a[i] < a[i - 1] || a[i] >= n;
}
if(fl || a[n] != n - 1 || a[1] != 0){
cout << "0\n";
return ;
}
int op = 1;
for(int i = 2; i <= n; i++){
if(a[i] == a[i - 1]){
(op *= max(0ll, a[i] - i + 2)) %= MOD;
}else{
(op *= 2) %= MOD;
}
}
cout << op << '\n';
}
signed main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> T;
while(T--){
solve();
}
return 0;
}