LoginSignup
0
0

More than 1 year has passed since last update.

Codeforces Round #799 (Div. 4)

Last updated at Posted at 2022-07-16

A

void solve(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int cnt=0;
	if(b>a) cnt++;
	if(c>a) cnt++;
	if(d>a) cnt++;
	cout << cnt << "\n";
}

B

void solve(){
	int n; cin >> n;
	set<int> s;
	for(int i=0; i<n; i++){
		int k; cin >> k;
		s.insert(k);
	}
	int sp = s.size();
	if((n-sp)%2 != 0) sp--;
	cout << sp << "\n";
}

C

void solve(){
	vector<string> s(8);
	for(int i=0; i<8; i++) cin >> s[i];
	for(int i=1; i<=6; i++){
		for(int j=1; j<=6; j++){
			if(s[i][j]=='.') continue;
			if(s[i-1][j-1]=='#' && s[i-1][j+1]=='#' && s[i+1][j-1]=='#' && s[i+1][j+1]=='#'){
				cout << i+1 << " " << j+1 << "\n";
				return;
			}
		}
	}
}

D

void solve(){
	string s;
	int x;
	cin >> s >> x;
	string sh = s.substr(0, 2);
	string sm = s.substr(3, 2);
	if(sh[0]=='0') sh = sh[1];
	if(sm[0]=='0') sm = sm[1];
	int h = stoi(sh);
	int m = stoi(sm);
	set<string> st;
	set<string> ss;
	while(true){
		m+=x;
		h+=m/60;
		h%=24;
		m%=60;
		string sh = to_string(h);
		if(sh.size()==1) sh = '0'+sh;
		string sm = to_string(m);
		if(sm.size()==1) sm = '0'+sm;
		string t = sh+":"+sm;
		string rt = t;
		reverse(rt.begin(), rt.end());
		if(ss.count(t)>0) break;
		ss.insert(t);
		if(t == rt){
			if(st.count(t)>0) break;
			st.insert(t);
		}
	}
	//for(auto e : st) cout << e << "\n";
	cout << st.size() << "\n";
}
 

E

void solve(){
	ll n, s; cin >> n >> s;
	vector<ll> a(n), r(n+1, 0);
	for(ll i=0; i<n; i++) cin >> a[i];
	for(ll i=1; i<=n; i++){
		r[i]+=r[i-1];
		r[i]+=a[i-1];
	}
	//for(auto e : r) cout << e << endl;
	if(r[n]==s){
		cout << 0 << "\n";
		return;
	}
	ll ans=2*n;
	for(ll i=0; i<n; i++){
		ll ac=n+1, wa=-1;
		while(abs(wa-ac)>1){
			ll mid = (ac+wa)/2;
			if(r[mid]-r[i] > s) ac=mid;
			else wa=mid;
		}
		//cout << ac << endl;
		if(ac<0) continue;
		if(ac>=n+1){
			if(r[n]-r[i]==s){
				int del = i;
				if(ans>del) ans = del;
			}
		}
		else if(r[ac-1]-r[i]==s){
			ll ex = ac-1-i;
			ll del = n-ex;
			if(ans>del) ans=del;
		}
	}
	if(ans==2*n) cout << -1 << "\n";
	else cout << ans << "\n";
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0