LOADING

加载过慢请开启缓存,浏览器默认开启

Waiting for the dawn

daily 2

2023/9/11

CF 940E

void solve() {
  int n, c;
  cin >> n >> c;
  vector<int> a(n + 1);
  ll sum = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    sum += a[i];
  } 
  deque<int> q;
  vector<ll> dp(n + 1);
  for (int i = 1; i <= n; ++i) {
    // we maintain a queue to store the increasing queue
    while(q.size() && a[q.back()] >= a[i]) q.pop_back();
    q.push_back(i);
    while(q.size() && i - q.front() >= c) q.pop_front();
    if(i >= c) dp[i] = max(dp[i - 1], dp[i - c] + a[q.front()]);
  }
  cout << sum - dp[n] << '\n';
  return ;
}

CF 580D

void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  vector<vector<ll>> dp(n,
                        vector<ll>(1 << n));  // the status is sta and ends in i
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    dp[i][1 << i] = a[i];
  }
  int u, v, c;
  vector<vector<int>> mp(n, vector<int>(n));
  for (int i = 0; i < k; ++i) {
    cin >> u >> v >> c;
    --u, --v;
    mp[u][v] = c;
  }
  for (int sta = 0; sta < (1 << n); ++sta) {
    for (int i = 0; i < n; ++i) {
      if (!(sta & (1 << i))) continue;
      for (int j = 0; j < n; ++j) {
        if (i == j || !(sta & (1 << j))) continue;
        dp[i][sta] = max(dp[i][sta], dp[j][sta ^ (1 << i)] + mp[j][i] + a[i]);
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < (1 << n); ++i) {
    if (__builtin_popcount(i) != m) {
      continue;
    }
    for (int j = 0; j < n; ++j) {
      ans = max(ans, dp[j][i]);
    }
  }
  cout << ans << '\n';
  return;
}
阅读全文

daily 2

2023/9/10

CF 295C

#define total(x, y) ((x * 50 + y * 100))
ll A[N][N][N][N];
ll C[N][N];
ll dp[N << 2][N][N];
void solve() {
  ll n, lim;
  cin >> n >> lim;
  vector<int> a(n + 1);
  int cnta = 0, cntb = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (a[i] == 50) {
      cnta++;
    } else {
      cntb++;
    }
  }
  for (int i = 0; i < N; ++i) {
    for (int j = C[i][0] = 1; j <= i; ++j) {
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
    }
  }
  for (int a = 0; a < N; ++a) {
    for (int b = 0; b < N; ++b) {
      for (int c = 0; c <= a; ++c) {
        for (int d = 0; d <= b; ++d) {
          A[a][b][c][d] = (C[a][c] * C[b][d]) % MOD;
        }
      }
    }
  }
  dp[0][cnta][cntb] = 1;
  for (int i = 1; i <= 4 * n + 1; i += 2) {
    ll res = 0;
    // positive direction
    for (int x = 0; x <= cnta; ++x) {
      for (int y = 0; y <= cntb; ++y) {
        if (dp[i - 1][x][y]) {
          for (int a = 0; a <= x; ++a) {
            for (int b = 0; b <= y; ++b) {
              if ((a | b) && (total(a, b) <= lim)) {
                dp[i][x - a][y - b] +=
                    (A[x][y][a][b] * dp[i - 1][x][y]);
                dp[i][x - a][y - b] %= MOD;
              }
            }
          }
        }
      }
    }
    if (dp[i][0][0]) {
      cout << i << '\n' << dp[i][0][0] << '\n';
      return;
    }
    // negative direction
    for (int x = 0; x <= cnta; ++x) {
      for (int y = 0; y <= cntb; ++y) {
        if (dp[i][x][y]) {
          for (int a = 0; a <= cnta - x; ++a) {
            for (int b = 0; b <= cntb - y; ++b) {
              if ((a | b) && (total(a, b) <= lim)) {
                dp[i + 1][x + a][y + b] +=
                    (A[cnta - x][cntb - y][a][b] * dp[i][x][y]);
                dp[i + 1][x + a][y + b] %= MOD;
              }
            }
          }
        }
      }
    }
  }
  cout << -1 << '\n' <<0 <<'\n';
  return;
}
阅读全文

daily 1

2023/9/9

CF 59A

#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    while(cin>>s){
        int low=0,up=0;
        for(int i=0;i<s.length();++i){
            if(s[i]>=65&&s[i]<=90)  ++up;
            else if(s[i]>=97&&s[i]<=122)    ++low;
        }
        if(low>=up){
            for(int i=0;i<s.length();++i){
                if(s[i]>=65&&s[i]<=90)
                    s[i]+=32;
            }
        }
        else{
            for(int i=0;i<s.length();++i){
                if(s[i]>=97&&s[i]<=122)
                    s[i]-=32;
            }
        }
        cout<<s<<'\n';
    }
    return 0;
}
阅读全文

daily 1

2023/9/8

daily codeforces

阅读全文

daily 2

2023/9/7

daily codeforces

阅读全文

daily 2

2023/9/6

CF 1696E

ll quick_pow(ll x,ll exp,int p)
{
      ll ans=1;
      while(exp)
      {
        if(exp&1)ans=ans*x%p;
        exp>>=1;
        x=x*x%p;
      }
      return ans;
}
ll inv[MAXN],fac[MAXN];
void init(int n,int p)
{
  memset(inv,0,sizeof(inv));
  memset(fac,0,sizeof(fac));
  inv[0]=fac[0]=1;
  for(int i=1;i<=n;++i)
  {
    fac[i]=fac[i-1]*i%p;
  }
  inv[n]=quick_pow(fac[n],p-2,p)%p;
  for(int i=n;i>=1;--i)inv[i-1]=inv[i]*i%p;
}
ll C(ll n,ll m,ll p)
{
  if(m>n||m<0)return 0;
  return fac[n]*inv[n-m]%p*inv[m]%p;
}
void solve() {
  int n;
  cin >> n;
  ++n;
  vector<ll> a(n + 1);
  for (int i = 1 ; i <= n; ++i) {
    cin >> a[i];
  } 
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = (ans + C(a[i] + i - 1, a[i] - 1, MOD)) %MOD;
  }
  cout << ans << '\n';
  return ;
}

CF 1699C

void solve() {
  int n;
  cin >> n;
  vector<int> a(n), pos(n);
  for (int i = 0; i <= n - 1; ++i) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  int l = pos[0], r = pos[0];
  ll ans = 1;
  for (int i = 1; i <= n - 1; ++i) {
    if (pos[i] < l) {
      l = pos[i];
    } else if (pos[i] > r) {
      r = pos[i];
    } else {
      ans = ans * (r - l + 1 - i) % MOD;
    }
  }
  cout << ans << '\n';
  return ;
}
阅读全文

daily 1

2023/9/5

CF 1717D

ll quick_pow(ll x, ll exp, int p) {
  ll ans = 1;
  while (exp) {
    if (exp & 1) ans = ans * x % p;
    exp >>= 1;
    x = x * x % p;
  }
  return ans;
}
ll inv[MAXN], fac[MAXN];
void init(int n, int p) {
  memset(inv, 0, sizeof(inv));
  memset(fac, 0, sizeof(fac));
  inv[0] = fac[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fac[i] = fac[i - 1] * i % p;
  }
  inv[n] = quick_pow(fac[n], p - 2, p) % p;
  for (int i = n; i >= 1; --i) inv[i - 1] = inv[i] * i % p;
}
ll C(ll n, ll m, ll p) {
  if (m > n || m < 0) return 0;
  return fac[n] * inv[n - m] % p * inv[m] % p;
}
void solve() {
  int n, k;
  cin >> n >> k;
  ll ans = 1;
  for (int i = 1; i <= min(n, k); ++i) {
    ans = (ans + C(n, i, MOD) % MOD) % MOD;
  }
  cout << ans << '\n';
}
阅读全文

daily 1

2023/9/2

CF 50A

#include<iostream>
using namespace std;
int main(){
    int m,n,t=0,Sn=0;
    cin>>m>>n;
    if(m%2==0){
        t=1;
    }
    if(n%2==0){
        t=2;
    }

    if(t==1){
        Sn=n*(m/2);
    }
    else if(t==2) {
        Sn=m*(n/2);
    }
    else {
        Sn=m*((n-1)/2)+(m-1)/2;
    }
    cout<<Sn;

}
阅读全文

daily 1

2023/9/1

daily codeforces

阅读全文

daily 2

2023/8/31

daily codeforces

阅读全文
1 ... 8 9 10 11 12 ... 30
avatar
Yanxin Xiang

愿有一天能和你最重要的人再次相逢