solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long INF = 1e7;
double EPS = 1e-12;
double tick() {
static clock_t oldt;
clock_t newt = clock();
double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;
oldt = newt;
return diff;
}
long long int powP(long long int a, long long int b) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
char s[10000011], T[10000011], S[5][10000011], t[10000011];
int P[10000011], Len, L[10000011], len, nxt[10000011], cnt, K;
void Lyndon() {
for (int i = 1; i <= len;) {
int j = i, k = i + 1;
while (k <= len && s[k] >= s[j]) {
if (s[k] > s[j])
j = i;
... | 5 |
#include<iostream>
#include<cstdio>
#define MAX_N 10000
using namespace std;
const int INF = 1 << 30;
int dp[2][MAX_N / 2 + 1][2];
int main() {
int n, ans = INF, t[MAX_N + 1] = {};
scanf("%d", &n);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n / 2 + 1; j++) {
fill(dp[i][j], dp[i][j] + 2, INF);
}
}
for... | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int n; ll c[60][60];
ll f[60][120];
int main()
{
c[0][0] = 1;
for(int i = 0; i < 60; ++i)
{
c[i][0] = 1;
for(int j = 1; j <= i; ++j)
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD;
}
scanf("%d", &n);
f[1][n] =... | 0 |
#include<bits/stdc++.h>
using namespace std;
long long t,a[1000020],k,l;
int main(){
cin>>t;
for(long long i=1;i<10;i++){
a[k++]=i;
}
while(1){
long long x=a[l],o=x%10;
l++;
if(o!=0)a[k++]=x*10+o-1;
a[k++]=x*10+o;
if(o!=9)a[k++]=x*10+o+1;
if(k>=t){
cout<<a[t-1]<<endl;break;
}
}
return 0;
}
/* S... | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long int Int;
Int ans[10];
int main(void)
{
map<pair<int,int>,int> m;
Int h,w,n;
cin>>h>>w>>n;
for(int i = 0;i < n;i++)
{
int a,b;
cin>>a>>b;
a--;
b--;
int dx[9] = {-2,-1,0,-2,-1,0,-2,-1,0};
int dy[9] = {-2,-2,-2,-1,-1,-1,0,0,... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long ara[300000], m, n, x, y, z;
int main() {
cin >> n;
for (long long i = 1; i <= n; i++) cin >> ara[i];
long long prvoff = -1;
for (long long i = 1; i <= n; i++) {
if (prvoff == -1) {
long long tmp = ara[i];
tmp = tmp % 2;
if (tmp == 0) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int mod = 998244353;
const int inf = 1 << 30;
const int maxn = 200000 + 5;
int n, k, a[maxn];
ll pre[maxn], suf[maxn];
int main() {
scanf("%d%d", &n, &k);
map<int, int> cnt;
for (int i = 1; i <= n; i++) {
sca... | 6 |
#include <bits/stdc++.h>
using namespace std;
int fin(string s, int i1) {
int mi = 999999999;
for (int d = 1; d <= 9; d++) {
for (int i = i1; i < i1 + 10; i++) {
if (i + 2 * d < s.length()) {
if (s[i] == s[i + d] && s[i] == s[i + 2 * d]) {
mi = min(mi, i + 2 * d);
}
}
}... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool dbg = 0;
void bad(string mes = "Impossible") {
cout << mes;
exit(0);
}
void bad(int mes) {
cout << mes;
exit(0);
}
template <typename T>
string bin(T x, int st = 2) {
string ans = "";
while (x > 0) {
ans += char('0' + x % st);
x /= st;
}
reverse... | 2 |
#include <bits/stdc++.h>
const long long MAX = 10000000000;
using namespace std;
long long pw(long a, int n) {
long long res = 1;
for (int i = 0; i < n; i++) {
res *= a;
if (res > MAX) return res;
}
return res;
}
int main() {
long p, n, d, t, k, count, q;
long long res = 0;
cin >> n >> k;
vector... | 4 |
#include <iostream>
int main(){
int a,p;
std::cin>>a>>p;
std::cout << (a*3+p)/2 << '\n';
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
string a;
cin>>a;
if(int(a.find('C'))!=-1 and int(a.rfind('F'))!=-1&&a.find('C')<a.rfind('F'))//个人码风问题,习惯用and而不是&&
cout<<"Yes";
else
cout<<"No";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
char ch = getchar();
long long x = 0, f = 1;
while (ch < '0' || ch > '9') f = ch == '-' ? -1 : 1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * f;
}
const int MAXN = 100010, MAXM = 200010... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 17;
int f(int m, int n, int d) { return m + ceil(double(d) / double(m + 1)); }
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
string s;
cin >> s;
int l = 0, r = 0;
for (auto cur : s) (cur == 'L') ? ... | 1 |
#include <bits/stdc++.h>
int main() {
int a, b, c = 0, d = 0, e, f;
scanf("%d", &a);
char s[a + 1];
scanf("%s", &s);
for (b = 0; b < a - 1; b++) {
if (s[b] == 'F' && s[b + 1] == 'S') {
c++;
}
if (s[b] == 'S' && s[b + 1] == 'F') {
d++;
}
}
if (d > c) {
printf("YES\n");
} e... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void NO () {
cout << "No";
exit (0);
}
void YES (string ans) {
cout << "Yes\n" << ans;
exit (0);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, sum = 0, askiiA = 'A';
cin >> n;
vector <string> a(n);
int c[3+a... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
sort(S.begin(), S.end());
if (S.at(0)==S.at(1) && S.at(2)==S.at(3) && S.at(0)!=S.at(2)) cout << "Yes\n";
else cout << "No\n";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
const long long L = 1e9;
map<long long, pair<long long, long long> > mp;
int a[MAXN], b[MAXN], c[MAXN];
int n, nn;
long long ans, ans1, ans2;
void dfs1(int cur, long long t, long long x, long long y, long long z) {
if (cur == nn + 1) {
long long ... | 4 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
template <typename T, typename Add = std::plus<T>,
typename Mul = std::multiplies<T>>
struct Matrix {
std::vector<std::vector<T>> D;
Matrix(size_t m, size_t n) {
D.resize(m);
for (size_t i = 0; i < m; +... | 3 |
#include<iostream>
using namespace std;
int main(){
string s,t;
cin>>s>>t;
int a,b;
cin>>a>>b;
string u;
cin>>u;
if( s == u){
a--;
}else {
b--;
}
cout<<a<<" "<<b;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000;
vector<tuple<int, int, int>> adjList[MAXN + 1];
tuple<int, int, int> edges[MAXN];
int ans[MAXN];
bool dfs(int v, int p, int target, int bt, int &minW) {
if (v == target) return true;
for (int i = 0; i < (int)adjList[v].size(); i++) {
tuple<int... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > v;
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
long long x = min(a.first * 2, a.second) - a.first;
long long y = min(b.first * 2, b.second) - b.first;
return x > y;
}
int main() {
int n, f;
cin >> n >... | 2 |
#include <bits/stdc++.h>
const int N = 5e5 + 5;
int s[N], num[N];
int find(int x) {
if (x != s[x]) s[x] = find(s[x]);
return s[x];
}
void built(int x, int y) {
x = find(s[x]), y = find(s[y]);
if (x != y) {
if (num[x] >= num[y]) {
s[y] = x;
num[x] += num[y];
} else {
s[x] = y;
num... | 3 |
#include <stdio.h>
#include <stdlib.h>
const int map[7][2]={
{0,0}, /* 0:砂漠 */
{2,3}, /* 1:A XorY*/
{0,4}, /* 2:X 砂漠orZ*/
{2,0}, /* 3:Y Aor砂漠*/
{5,6}, /* 4:Z WorB*/
{6,3}, /* 5:W BorY*/
{3,2}, /* 6:B YorX*/
};
int main(void) {
char route[200];
int i,P;
while(0==0) {
sc... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 5;
long long n, sum, sum2, w, k, a[maxn], ti[maxn], ans;
set<pair<long long, long long>> s;
set<pair<long long, long long>, greater<pair<long long, long long>>> s1;
bool mrk[maxn];
void f16_62() {
while (s1.size()) {
long long sz = s.size(... | 6 |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long N = 1e2 + 5;
unsigned long long a, z[101], vis[101], ok = 0;
vector<unsigned long long> ans;
void dfs(unsigned long long u, unsigned long long le) {
if (u % 3 == 0) {
for (unsigned long long i = 1; i <= a; i++) {
if (z[i] == u / 3 && vis... | 4 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> string_to_id;
map<int, string> id_to_string;
vector<vector<int>> adj;
vector<int> in_degree;
vector<int> out_degree;
int get_id(const string& code) {
if (string_to_id.count(code) == 0) {
int size = string_to_id.size();
string_to_id[code] = size;
... | 4 |
#include <bits/stdc++.h>
template <typename T>
inline T max(T a, T b) {
return a > b ? a : b;
}
template <typename T>
inline T min(T a, T b) {
return a < b ? a : b;
}
template <typename T>
inline T abs(T a) {
return a > 0 ? a : -a;
}
template <typename T>
inline bool repr(T &a, T b) {
return a < b ? a = b, 1 : ... | 1 |
#include <bits/stdc++.h>
using namespace std;
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(bool b) { return (b ? "true" : "false"); }
template <size_t N>
string to_string(bitset<N> v) {
string s = "";
for (size_t i = 0; i < N; i++) {
s += static_cast<char>('0' + v[i]);
}
retu... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
map<string, int> dp;
void add(int &a, int b){
a += b;
if(a >= mod)
a -= mod;
}
void merge(string &a, string b){
int n = b.length();
for(int i = 0;i < n;i++){
if(b[i] == '0')
a[i] = '0';
}
}
int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
int a[maxn];
int main() {
int n;
scanf("%i", &n);
for (int i = 0; i < n; i++) scanf("%i", &a[i]);
int cnt = 0;
int l = 0, r = 0;
for (int i = 1; i < n; i++)
if (a[i - 1] > a[i]) {
if (cnt == 2) {
printf("NO\n");
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
vector<string> a;
vector<int> pA, pB;
vector<vector<int> > dp;
int n, m, x, y;
int getPA(int l, int r) { return pA[r] - (l ? pA[l - 1] : 0); }
int getPB(int l, int r) { return pB[r] - (l ? pB[l - 1] : 0); }
int main() {
cin >> n >> m >> x >> y;... | 3 |
#include<stdio.h>
int main(){float n,m,d;scanf("%f%f%f",&n,&m,&d);printf("%lf",(d?2:1)*(n-d)*(m-1)/n/n);} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, x1, x2, p, d, t1, t2, ans = 0;
cin >> s >> x1 >> x2 >> t1 >> t2 >> p >> d;
if (t1 >= t2) {
ans = (abs(x2 - x1)) * t2;
} else if (x2 < x1) {
if (p >= x1 and d == -1)
ans = min(t1 * (p - x2), t2 * (x1 - x2));
else if (d == -1 and ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n + 1], b[n + 1], x;
for (int i = 1; i <= n; i++) {
cin >> x;
a[x] = i;
}
for (int i = 1; i <= n; i++) {
cin >> x;
b[i] = a[x];
}
for (int i = 1; i <= n; i++) {
cout << b[i] << " ";
}
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p);
template <class T>
ostream& operator<<(ostream& ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int inf = 1000000ll * 1000000 + 200;
long long int mod = 998244353;
const int maxn = 2e5 + 2000;
long long int fen[maxn], h[maxn];
void inc(int i) {
for (; i < maxn; i += i & -i) {
fen[i]++;
}
}
void dec(int i) {
for (; i < maxn; i += i & -i) {
fen[i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int times(int a, int b) {
int s = 0;
while (a) {
a /= b;
s++;
}
return s;
}
int main() {
int t, a[100001] = {}, b, s = 0, c = 0, n, i, j, x;
int d;
char s1[101], s2[101];
cin >> n;
s = n;
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < n -... | 1 |
#include <iostream>
#include <cmath>
using namespace std;
int main() {
long n, k;
cin >> n >> k;
cout << (n - 1 + (k - 1) - 1) / (k - 1) << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
double low = 0, high = INFINITY;
void restrict(int init, int dir, int min, int max) {
if (dir > 0) {
low = std::max(low, double(min - init) / dir);
high = std::min(high, double(max - init) / dir);
} else if (dir < 0) {
low = std::max(low, double(max - init) / dir);
high = st... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[5], a1, a2, a3, a4, sum = 0, k;
cin >> a1 >> a2 >> a3 >> a4;
a[1] = a1;
a[2] = a2;
a[3] = a3;
a[4] = a4;
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
k = s[i] - 48;
sum = sum + a[k];
}
cout << sum << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
bool isprime(long long int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (long long int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
int main() {
int ... | 2 |
#include<iostream>
#include<algorithm>
using namespace std;
int a[12];
int main(){
for(int i=0;i<12;i++)cin>>a[i];
sort(a,a+12);
bool ok=true;
for(int i=0;i<12;i++){
if(i%4!=3)if(a[i]!=a[i+1])ok=false;
}
if(ok)cout<<"yes"<<endl;
else cout<<"no"<<endl;
return 0;
} | 0 |
/*
* じょえチャンネル
* 高評価・チャンネル登録よろしくお願いします!
* https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
*/
#include<bits/stdc++.h>
int main(){
using namespace std;
unsigned long k, q;
cin >> k >> q;
vector<unsigned long> d(k);
for(auto& i : d)cin >> i;
const auto& query = [&](unsigned long n, un... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX_N = 1e5+2;
int n;
int a[MAX_N];
void solve()
{
sort(a,a+n);
int x=a[n-1], y=-x/2;
for(int i=0;i<n-1;++i){
if(abs(1.0*x/2-a[i]) < abs(1.0*x/2-y)) y=a[i];
}
cout << x << ' ' << y << '\n';
}
int main()
{
cin >> n;
for(int i=0;i<n... | 0 |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
printf("%d\n", n / 2 + 1);
return 0;
}
| 1 |
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorit... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q, n;
long long x, s = 0;
cin >> q;
while (q--) {
cin >> n;
s = 0;
for (int i = 0; i < n; i++) {
cin >> x;
if (x <= 2048) {
if (s < 2048) s = s + x;
}
... | 1 |
#include<bits/stdc++.h>
using namespace std;
int main(){
long long X;
cin >> X;
for(long long i=-200;i<201;i++){
for(long long j=-200;j<201;j++){
if(i*i*i*i*i-j*j*j*j*j==X){
cout << i << " " << j << endl;
return 0;
}
}
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 9223372034707292160;
const int maxn = 2e5 + 5;
long long geshu(long long a) {
int sum = 0;
for (int i = 1; i <= sqrt(a); i++) {
if (a % i == 0) {
sum++;
if (a / i != i) sum++;
}
}
return sum - 2;
}
int main() {
int t;
sc... | 4 |
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int dp[201][201];
int t[201],u[201],v[201],w[201];
int N,D,ans=0;
int main(){
cin>>N>>D;
for(int i=1;i<=N;i++)cin>>t[i];
for(int i=1;i<=D;i++){
cin>>u[i]>>v[i]>>w[i];
if(t[1]<u[i]||v[i]<t[1])dp[1][i]=-1;
else dp[1][i]=0;
}
... | 0 |
#include <bits/stdc++.h>
#define Int int64_t
using namespace std;
int main() {
constexpr Int INF = 1e18;
int N;
cin >> N;
vector<Int> a(N);
for (int i = 0; i < N; ++i) { cin >> a[i]; }
int skip = 1 + N % 2;
vector<vector<Int>> dp(N + 2, vector<Int>(skip + 1, -INF));
dp[0][0] = 0;
for (int i = 0; i <= N; ++i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int q, x;
cin >> q >> x;
vector<int> rem(x);
vector<bool> a(q);
int mes = 0;
for (int i = 0; i < q; i++) {
int y;
cin >> y;
int r = y % x;
rem[r]++;
long long ind = (long long)... | 4 |
#include<cstdio>
#include<algorithm>
int h[100000];
int main(){
int n,k;
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++)scanf("%d",&h[i]);
std::sort(h,h+n);
for(int i=0;i+k-1<n;i++)h[i]=h[i+k-1]-h[i];
std::sort(h,h+(n+1-k));
printf("%d",h[0]);
return 0;
} | 0 |
#include <bits/stdc++.h>
#define ll long long
#define ii pair<int, int>
#define fi first
#define se second
#define multitest \
int t; \
cin >> t; \
while (t--)
using namespace std;
const int N = 32;
int main()
{
ios::sync_with_stdio(false);
multitest
{
int n, w;
cin >... | 2 |
#include <iostream>
#include <cstdio>
using namespace std;
char c;
int n,m;
int f[110][110][110][110];
int linex[110][110],liney[110][110];
int X,Y;
struct LIMIT{
int u,d,l,r;
}L;
int main(){
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++){
scanf("%c",&c);
while (c!='.'&&c!='o'&&c!='E') sc... | 0 |
#include <bits/stdc++.h>
long long maxx, maxy;
void judge(long long x, long long y) {
if (x * y > maxx * maxy) {
maxx = x;
maxy = y;
return;
}
if ((x * y == maxx * maxy) && (x > maxx)) {
maxx = x;
maxy = y;
return;
}
}
int main() {
long long s;
long long i;
long long x, y;
long l... | 2 |
#include <iostream>
using namespace std;
int main(){
string s;
int n=0;
cin >> s;
for (auto &c:s) {
if (c=='+') n++;
else n--;
}
cout << n << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
string s;
long long ans, all1, all1full, bonus, All1[1000006];
vector<pair<long long, long long> > v;
stack<pair<int, long long> > zeroes;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> s;
long long sz = s.size(), l = 0;
while (l < sz && s[l] == '0')... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long i, min_, j, k, n, z, cnt, arr[30][30], ans[100005];
for (i = 0; i < 30; i++) {
for (j = 0; j < 30; j++) {
arr[i][j] = 1123456789LL;
}
}
string str1, str2, sx, sy, str, ch;
cin >> str1 >> str2 >> n;
for (i = 1; i <= n; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
long long int x, n;
cin >> x >> n;
if (n == 0)
cout << x << endl;
else if (n > 0) {
long long int nums = (n / 4) * 4;
n... | 2 |
#include <bits/stdc++.h>
using namespace std;
void array_print(vector<char> a, long long int n) {
for (long long int i = 0; i < n; i++) {
cout << a[i];
}
cout << "\n";
}
void pair_print(vector<pair<long long int, long long int> > p,
long long int n) {
for (long long int i = 0; i < n; i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, a;
cin >> n >> m >> a;
long long x = n / a;
if (n % a != 0) x++;
long long y = m / a;
if (m % a != 0) y++;
cout << x * y << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10000000;
int pi[maxn + 10], pa[maxn + 10];
bool zhi[maxn + 10];
bool hui[maxn + 10];
void mk_zhi() {
memset(zhi, 1, sizeof(zhi));
for (int i = 4; i <= maxn; i += 2) zhi[i] = false;
for (int i = 3; i <= maxn; i += 2) {
if (zhi[i]) {
for (int... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main (){
string s;
cin >> s;
if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3] ) {
cout << "Bad"; }
else {
cout << "Good"; } } | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
bool g[MAXN][MAXN];
void a(int x, int y) { g[x][y] = g[y][x] = true; }
int n;
void out() {
vector<int> p(n);
for (int i = 0; i < (int)(n); i++) p[i] = i;
p[1] = n - 1;
p[n - 1] = 1;
cout << n << endl;
for (int i = 0; i < (int)(n); i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
bool debug = 1;
int main() {
int n, m;
scanf("%d %d", &n, &m);
int amn[n];
fill(amn, amn + n, 0);
for (int i = 0; i < m; i++) {
int x, y;
scanf("%d %d", &x, &y);
x--, y--;
amn[x]++, amn[y]++;
}
bool ok = 1;
int k = 0;
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vc<vc<T>>;
template <class T>
void mkuni(vector<T>& v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
}
long long rand_int(long long l, long long r) {
static mt19937_64 ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int arr[100010];
int main() {
long long int num, i, flag, div;
cin >> num;
for (i = 0; i < num; i++) cin >> arr[i];
sort(arr, arr + num);
div = arr[0];
flag = 1;
for (i = 0; i < num; i++) {
while (arr[i] % 2 == 0 || arr[i] % 3 == 0) {
if (a... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct treap;
typedef treap *ptreap;
const unsigned long long mod = 1000000007ll;
unsigned long long k, dp[100000][11], n, m, a, ans;
ptreap tree = NULL;
struct treap {
ptreap l, r;
unsigned long long x, sum[11], key, index;
treap(unsigned long long x, unsigned long l... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
const int mod = 1e9 + 7;
const int inf = 1e9;
int n;
char s[N], ans[N];
map<string, int> mp;
string pre[N];
int main() {
scanf("%d", &n);
if (n == 1) {
printf("? %d %d\n", 1, n);
fflush(stdout);
scanf("%s", s);
printf("! %s\n", s);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a < b) swap(a, b);
if (b == 0) return a;
while ((a = a % b) != 0) {
swap(a, b);
}
return b;
}
long long mpow(long long x, long long y, long long m) {
long long res = 1;
while (y > 0) {
if (y & 1) res = res ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100001;
const int inf = 0x7f7f7f7f;
const int mod = (int)(1e9 + 7);
const long long INF = 1LL << 50;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int mask = 65535;
vector<int> W[maxn];
bool ok(int x, int y) {
if (x >= maxn || y >= maxn) re... | 4 |
#include <bits/stdc++.h>
using namespace std;
class dsu {
vector<int> p;
public:
dsu(int n) {
p.resize(n);
iota(p.begin(), p.end(), 0);
}
int get(int v) { return (v == p[v] ? v : p[v] = get(p[v])); }
void unite(int u, int v) { p[get(u)] = get(v); }
};
int main() {
ios::sync_with_stdio(0);
cin.ti... | 4 |
#include <bits/stdc++.h>
template <typename T>
std::istream& operator>>(std::istream& input, std::vector<T>& v) {
for (T& a : v) input >> a;
return input;
}
void no_answer() { std::cout << -1 << '\n'; }
void answer(const std::vector<unsigned>& v) {
const char* separator = "";
for (const unsigned x : v) {
st... | 3 |
#include <bits/stdc++.h>
using namespace std;
const bool TEST = false;
using ll = long long;
const ll MAXX = ll(1e18);
int n;
ll l;
ll D;
int nq = 0;
map<pair<int, ll>, ll> cache;
ll f(int i, ll x) {
if (cache.count({i, x})) return cache[{i, x}];
nq += 1;
assert(nq <= 199999);
if (TEST) return min(x / (i + 1), ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXn = 21, MAXx = (1 << 20), anti = MAXx - 1;
long double sum[MAXx], dp[MAXx], prob[MAXn];
int n, k, kk;
vector<int> vec[MAXn + 2];
bool flag[MAXx];
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> prob[i];
if (prob[i] > 0) kk++;
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
unsigned int get_mask(int m) {
unsigned int res = (1 << m) - 1;
res <<= (32 - m);
return res;
}
int count(vector<unsigned int> &ips, unsigned int mask) {
unsigned int pr = 1;
unsigned int temp;
int count = 0;
for (vector<unsigned int>::iterator it = ips.begin(... | 3 |
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int dp[100100];
int n,l;
int a[100100];
int rec(int p){
if(0<=dp[p])return dp[p];
if(a[p-1] < a[p] && a[p] < a[p])return dp[p] = l-a[p];
int tmp = 0;
if(a[p]<a[p-1])tmp = max(tmp,rec(p-1));
if(a[p]<a[p+1])tmp = max(tmp,rec(p... | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALL(a) (a).begin(),(a).end()
ll n,m;
ll p[100000],y[100000];
vector<ll> yd[100001];
int main(){
cin>>n>>m;
rep(i,m){
cin>>p[i]>>y[i];
yd[p[i]].push_back(y[i]);
}
rep(i,n){
sort(ALL(yd... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = (int)1e9 + 7;
struct edge {
int u, v, c, f;
edge() {}
edge(int u, int v, int c) : u(u), v(v), c(c), f(0) {}
int nxt(int x) { return x ^ u ^ v; }
};
struct FLOW {
int N, s, t, d[maxn], cur[maxn];
vector<edge> E;
vector<... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100007;
const int ooi = 1e9 + 7;
const long long mod = 1e9 + 7;
const long long ool = 1e18 + 7;
long long cost[maxn];
long long used[maxn];
long long has[maxn];
long long yu1;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >... | 2 |
#include <bits/stdc++.h>
char s[500005];
int x[300005], y[300005];
inline bool check(int n, int val) {
int xL = 0, xR = INT_MAX, yL = 0, yR = INT_MAX, zL = INT_MIN, zR = INT_MAX;
for (register int i = 1; i <= n; ++i) {
xL = ((xL) > (x[i] - val) ? (xL) : (x[i] - val));
xR = ((xR) < (x[i] + val) ? (xR) : (x[i... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 6e5 + 10;
pair<long long, long long> a[N], b[N];
long long limit[N][50];
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long n, m;
cin >> n >> m;
long long maxi = 0;
for (long long i = 1; i <= n; i++) {
cin >> a[i].first >> a[... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s, p;
cin >> s >> p;
int n = s.size();
vector<int> pos(n);
for (int c1 = 0; c1 < n; c1++) {
cin >> pos[c1];
pos[c1]--;
}
reverse(pos.begin(), pos.end());
int l... | 1 |
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typede... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, mod = 20090717, inf = 2e9 + 10;
int dp[110][55][310][2], m, n;
char a[N];
int main() {
scanf("%s%d", a + 1, &m);
n = strlen(a + 1);
dp[0][0][100][1] = 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= m; ++j) {
for (int k = 0; k... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, arr[1000001], k[1000001];
int main() {
scanf("%d %d", &n, &m);
if (n / m < 3)
printf("-1\n");
else {
memset(k, 0, sizeof(k));
int coun = 1;
for (int i = 1; i <= n; i++) {
if (i <= m) {
arr[i] = i;
k[i]++;
} else {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 110, M = 4, inF = N * N * N;
int n, ans = inF;
string s[M][N];
vector<int> vec = {0, 1, 2, 3};
int check(int dex, int b) {
int res = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
res += (s[dex][i][j] - '0' != ((i + j + b) & 1));
re... | 3 |
#include <bits/stdc++.h>
using namespace std;
int i, j, cnt = 0;
long long p = 1000000007;
long long pre[100] = {0, 1};
long long a[100] = {1, 2};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long l, r, ans = 0;
cin >> l >> r;
for (int i = 2; i <= 60; i++) {
a[i] = ... | 3 |
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,a[100010],b[100010];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(a[i]<=n) b[a[i]]++;
}
int all=0;
for(int i=1;i<=n;i++)
if(b[i]!=0)
{
if(b[i]<i) continue;
else all+=i;
}
printf("%d",n-... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n;
string Name, in;
vector<vector<int> > v(n, vector<int>(3, 0));
vector<string> names(n);
for (int i = 0; i < n; ++i) {
cin >> m;
cin >> names[i];
for (int j = 0; j < m; ++j) {
cin >> in;
char x = in[0];
... | 2 |
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n;
int x[5000], y[5000], maxn;
bool p[7000][7000];
int Ax, Ay, Bx, By, Cx, Cy, Dx, Dy;
int main() {
while (true) {
memset(p, false, sizeof(p));
cin >> n;
maxn = 0;
if (n == 0) { break; }
for (int i = 0; i < n; i++) {
cin >... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a[100][100];
int main() {
long long i, j, n, m, t, ans = 0;
a[0][0] = 1;
for (i = 1; i < 40; i++)
for (j = 0; j <= i; j++) {
a[i][j] = a[i - 1][j];
if (j) a[i][j] += a[i - 1][j - 1];
}
cin >> n >> m >> t;
t -= 5;
for (i = 0; i <= t;... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<
!is_same<T_container, s... | 3 |
#include <bits/stdc++.h>
using namespace std;
string s, t, ans;
int alphabets[128];
int i = 0;
void find_matching() {
for (i = 0; i < s.length(); ++i) ++alphabets[s[i]];
for (i = 0; i < t.length(); ++i) {
if (alphabets[t[i]] > 0) {
ans[i] = t[i];
--alphabets[t[i]];
continue;
}
break;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long t, a, b;
cin >> t;
while (t--) {
cin >> a >> b;
if (a == b)
cout << "0\n";
else {
if (a > b)
(a - b) % 2 ? cout << "2\n" : cout << "1\n";
else
(b - a) % 2 ? cout << "1\n" : cout << "2\n";
}
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int a[102];
int main() {
int n, d, m, c = 0;
cin >> n >> d;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
cin >> m;
for (int i = 0; i < m; i++) {
c += a[i];
}
if (n < m) {
c += (n - m) * d;
}
cout << c;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int a[200200];
int main() {
int n, l, r, m, p;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
sort(a, a + n);
l = 0;
r = a[n - 1];
while (l < r) {
m = (l + r) / 2;
p = 0;
for (int i = 0; i < 3; ++i) {
p = upper_bou... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.