20251011总结

· · 个人记录

前言

666今天又坠机了,A题挂了60分,C题还没写出来。

分数:40 + 100 + 10 + 100

题目

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终于推出来了。

题意就是一堆一次函数套在一起, 于是我们来快乐的推式子:

ans = a(a(a(\dots c(a( \dots ) + b) + d \dots) + b) + b) + b\\

先对于单一行算贡献,直接拆括号得:

ans = a^{m - 1} + b \times (1 + a + \dots + a^{m - 2})

可以发现 (1 + a + \dots + a^{m - 2}) 为等比数列,我们令 e = (1 + a + \dots + a^{m - 2}) = \frac{a^{m - 1} - 1}{a - 1}, 则

ans = x_1 = a^{m - 1} + b \times e

再套上第二层的括号,得:

ans = x_2 = a(a(\dots c(x) + d \dots) + b) + b\\ = c \times a^{m-1} \times x_1 + b \times e + d \times a^{m - 1}\\ = c \times a^{2m-2} + c \times a^{m - 1} \times b \times e + b \times e + d \times a^{m - 1}\\ = c \times a^{2m-2} + b \times e \times (1 + c \times a^{m - 1}) + d \times a^{m - 1}

再来推当有三层时的答案:

ans = a(a(\dots c(y) + d \dots) + b) + b\\ = c \times a^{m-1} \times x_2 + b \times e\\ = c^2 \times a^{3m-3} + b \times e \times ( c \times a^{m-1} + c^2 \times a^{2m - 2}) + c \times a^{2m-2} \times d + b \times e + d \times a^{m - 1}\\ = c^2 \times a^{3m-3} + b \times e \times (1 + c \times a^{m - 1} + c^2 \times a^{2m-2}) + a^{m - 1} \times d \times (1 + c \times a^{m - 1})

到这之后公式其实已经出来了,即当有 n 行 m 列时答案为:

ans = c^{n - 1} \times a^{n(m - 1)} + b \times e \times (1 + c \times a^{m - 1} + \dots + c^{n - 1} \times a^{(n - 1)(m - 1)}) + a^{m - 1} \times d \times (1 + c \times a_{m - 1} + \dots + c^{n - 2} \times a^{(n - 2)(m - 1)})

我们又可以发现 (1 + c \times a^{m - 1} + \dots + c^{n - 1} \times a^{(n - 1)(m - 1)}) 与 (1 + c \times a_{m - 1} + \dots + c^{n - 2} \times a^{(n - 2)(m - 1)}) 都是公比为 c \times a^{m - 1} 的等比数列,设 f = c \times a^{m - 1},用公式转换后得到最终形式:

ans = c^{n - 1} \times a^{n(m - 1)} + b \times e \times \frac{f ^ n - 1}{f - 1} + a_{m - 1} \times d \times \frac{f^{n - 1} - 1}{f - 1}

那么我们就做完了。

#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神秘结论题我竟然没做出来,赛后发现自己是啥子。

无解的情况很好判,判完后我们又可以分类讨论,当 a_i = a_{i - 1} 时直接在区间内随便选,否则就选两边,然后就做完了。

#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;
}

D - gifts