过了四题,第一次排名进前1000,打比赛确实可以带来进步,继续加油!
比赛传送门
官方题解
C 智乃买瓜(another version)
原题传送门 官方题解:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const int N = 1e3 + 10, mod = 1e9 + 7;
ll dp[N];
int n, m;
vector<int> ans;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
dp[0] = 1;
cin>>m;
for(int i = 1; i <= m; i ++ ){
cin>>dp[i];
}
for(int i = 1; i <= m; ++ i){
while(dp[i]){
ans.push_back(i * 2);
for(int j = 0; j <= m; ++ j){
if(i + j <= m) dp[i + j] -= dp[j];
while(i + j <= m && dp[i + j] < 0) dp[i + j] += mod;
if(i + i + j <= m) dp[i + i + j] -= dp[j];
while(i + i + j <= m && dp[i + i + j] < 0) dp[i + i + j] += mod;
}
}
}
cout<<ans.size()<<endl;
for(int i = 0; i < ans.size(); ++ i){
cout<<ans[i]<<" ";
}
return 0;
}
I 智乃的密码
原题传送门 官方题解:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int l, r, n;
int limit[4];
int a[4][N];
char s[N];
ll ans;
int type(char c){
if(c >= 'A' && c <= 'Z') return 1;
else if(c >= 'a' && c <= 'z') return 2;
else if(c >= '0' && c <= '9') return 3;
else return 0;
}
void presum(int a[]){
for(int i = 1; i <= n; ++ i){
a[i] += a[i - 1];
}
}
int has(int a[], int l, int r){
return a[r] - a[l - 1] > 0;
}
int get_d(){
int temp[4];
memcpy(temp, limit, sizeof temp);
sort(temp , temp + 4);
return temp[1];
}
int cal(int i){
int L = 1, R = n;
L = max(L, i - r + 1);
R = min(R, i - l + 1);
R = min(get_d(), R);
return R - L >= 0 ? R - L + 1 : 0;
}
int main()
{
cin>>n>>l>>r;
scanf("%s", s + 1);
for(int i = 1; i <= n; ++ i){
a[type(s[i])][i] ++ ;
}
for(int i = 0; i < 4; ++ i){
presum(a[i]);
}
for(int i = 1; i <= n; ++ i){
for(int j = 0; j < 4; ++ j){
while(has(a[j], limit[j] + 1, i)) limit[j] ++ ;
}
ans += cal(i);
}
cout<<ans<<endl;
return 0;
}
|