AtCoder Beginner Contest 296

发布时间 2023-04-02 16:21:40作者: 哲远甄骏

AtCoder Beginner Contest 296

赛时代码

A - Alternately

// Problem: A - Alternately
// Contest: AtCoder - AtCoder Beginner Contest 296
// URL: https://atcoder.jp/contests/abc296/tasks/abc296_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n;
	cin >> n;
	string s;
	cin >> s;
	if(n==1)
	{
		cout << "Yes\n";
		return 0;
	}
	int flag = 0;
	for(int i = 1; i < n; i++)
	{
		if(s[i] == s[i - 1]) flag = 1;
	}
	
	if(flag) cout << "No\n";
	else cout << "Yes\n";
	
	
	return 0;
}

B - Chessboard

// Problem: B - Chessboard
// Contest: AtCoder - AtCoder Beginner Contest 296
// URL: https://atcoder.jp/contests/abc296/tasks/abc296_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	string s;
	int cnt = 8;
	for(int i = 0; i < 8; i++)
	{
		cin >> s;
		for(int i = 0; i < 8; i++)
		{
			if(s[i] == '*')
			{
				char k =i  + 'a';
				cout << k << cnt << "\n"; 
				return 0;
			}
		}
		cnt--;
	}
	return 0;
}

C - Gap Existence

// Problem: C - Gap Existence
// Contest: AtCoder - AtCoder Beginner Contest 296
// URL: https://atcoder.jp/contests/abc296/tasks/abc296_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
map<int, bool> st;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, x;
	cin >> n >> x;
	// set<int> a;
	// if(!x)
	// {
		// cout << "Yes\n";
		// return 0;
	// }
	// for(int i = 0; i < n; i++) 
	// {
		// int b;
		// cin >> b;
		// a.insert(b);
	// }
	// for(auto x1 : a)
	// {
		// for(auto x2 : a)
		// {
			// if(x1 != x2)
			// {
				// if(x1 - x2 == x)
				// {
					// cout << "Yes\n";
					// return 0;
				// }
			// }
		// }
	// }
// 	
	// cout << "No\n";
	
	
	vector<int> a(n + 1);
	for(int i = 0; i < n; i++) 
	{
		cin >> a[i];
		st[a[i]] = 1;
	}
	if(x == 0) 
	{
		cout << "Yes\n";
		return 0;
	}
	
	for(int i = 0; i < n; i++)
	{
		if(st[a[i] - x] || st[x + a[i]]) 
		{
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
	// sort(a.begin(), a.begin() + n);
	// int i = 0, j = n - 1;
	// for(i; i < n; i++)
	// {
		// while(a[j] - a[i] > x )
		// {
			// i++;
		// }
		// if(a[j] - a[i] == x) 
		// {
			// cout << "Yes\n";
			// return 0;
		// }
	// }
// 	
	// i = n - 1, j = 0;
	// for(i; ~i; i--)
	// {
		// while(a[j] - a[i] < x && j < n)
		// {
			// j++;
		// }
		// if(a[j] - a[i] == x) 
		// {
			// cout << "Yes\n";
			// return 0;
		// }
	// }
	// cout << "No\n";
	return 0;
}

补题代码

D - M<=ab

补充向上取整知识点

// Problem: D - M<=ab
// Contest: AtCoder - AtCoder Beginner Contest 296
// URL: https://atcoder.jp/contests/abc296/tasks/abc296_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

// #include<bits/stdc++.h>
// #define int long long
// using namespace std;
// const int N = 2e5 + 10, M = 1e6;
// int n, m;
// int primes[N];
// map<int, int> st;
// 
// void get_primes()
// {
	// for(int i = 2; i <= M; i++)
	// {
		// if(!st[i]) primes[++primes[0]] = i;
		// for(int j = 1; primes[j] <= M / i; j++)
		// {
			// st[primes[j] * i] = 1;
			// if(i % primes[j] == 0) break;
		// }
	// }
// }
// bool check(int x)
// {
	// if(!st[x] && x < 1e6) return false;
	// for(int i = n; i; i--)
	// {
		// if(x % i == 0 && x / i <= n)
		// {
			// return true;
		// }
	// }
	// return false;
// }
// 
// signed main()
// {
	// ios::sync_with_stdio(false);
	// cin.tie(nullptr);
	// get_primes();
	// cin >> n >> m;
	// if(n * n < m)
	// {
		// cout << "-1\n";
		// return 0;
	// }
	// for(int i = m; i <= 1e12; i++)
	// {
		// if(i > n * n) 
		// {
			// cout << "-1";
			// return 0;
		// }
		// if(check(i))
		// {
			// cout << i << "\n";
			// return 0;
		// }
	// }
	// cout << "-1\n";
	// return 0;
// }

#include<bits/stdc++.h>
#define INF 1e18
using namespace std;
typedef long long ll;
ll n, m;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	cin >> n >> m;
	
	ll res = INF;
	for(ll i = 1; i <= n; i++)
	{
		ll x = (m + i - 1) / i;
		if(x <= n) res = min(res, i * x);
		if(i > x) break;
	}
	
	if(res == INF) cout << "-1\n";
	else cout << res << "\n";
	
	return 0;
}

E - Transition Game(待补)

F - Simultaneous Swap (待补)

G - Polygon and Points (待补)

Ex不考虑