Codeforces Round 917 (Div. 2)

发布时间 2024-01-06 00:51:02作者: zfxyyy

Codeforces Round 917 (Div. 2)

康复训练

A. Least Product

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int n;

void solve(){
	cin >> n;
	int cnt = 0;
	bool ok = false;
	// cout << endl;
	// cout << n <<endl;
	for(int i = 1;i <=n ; i++)
	{
		int x;
		cin >> x;
		//cout << i << endl;
		//cout << x << " " <<endl;
		if(x < 0) cnt++;
		if(x ==0) ok=true;
	}
	//cout << endl;
	//cout << ok <<"  " << cnt <<endl;
	if(ok || (cnt&1)){
		cout << 0 << endl;
	}else{
		cout << 1 << endl;
		cout << "1 0" << endl;
	}
}

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T = 1;
	cin >> T;
	while(T--) solve();
    return 0;
} 

B. Erase First or Second Letter

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int n;
bool a[26];

void solve(){
	string s;
	memset(a,false,sizeof a);
	cin >> n >> s;

	int ans = 0 ;
	for(int i=0;i<s.size();i++){
		if(!a[s[i]-'a']){
			a[s[i]-'a'] = true;
			ans += n - i;
		}
	}
	cout << ans << endl;

}

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T = 1;
	cin >> T;
	while(T--) solve();
    return 0;
} 

C. Watering an Array

注意注意注意ans不能初始化为d/2。

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

const int N = 1e5 + 10;
int n,k,d;
int a[N],b[N];

void solve(){
	cin>>n>>k>>d;

	long long cnt = 0;	
	for(int i = 1;i<=n;i++){
		cin >> a[i];
		if(a[i]==i) cnt++;
	}
	for(int i = 1;i<=k;i++) cin>>b[i];
	
	long long ans = 0;	
	for(int i = 1;i<=d && i<=n*2+1;i++){
		ans = max(ans,cnt + (d-i)/2);
		int len = i%k;
		if(len==0) len = k;
		len = b[len];
		for(int j=1;j<=len;j++){
			if(a[j]==j) cnt--;
			a[j]++;
			if(a[j]==j) cnt++;
		}
	}
	cout << ans <<endl;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T = 1;
	cin >> T;
	while(T--) solve();
    return 0;
}