solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include<iostream>
#include<string>
using namespace std;
int main(void)
{
int dayNum[13]={
0,31,29,31,30,31,30,31,31,30,31,30,31
};
string youbi[7]={
"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"
};
int manth,day;
while(cin>>manth>>day)
{
if(manth==0)
{
break;
}
int sum=... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int inf = 1e9 + 7;
int n, m, k;
pair<int, int> p[N];
map<int, vector<int> > r, c;
map<int, bool> mp[N];
set<int> R, C;
int main() {
cin >> n >> m >> k;
for (int i = 1; i <= k; i++) {
scanf("%d%d", &p[i].first, &p[i].second);
mp[p[i]... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, r, vt, a[1005];
int main() {
cin >> n >> r;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int d = 0;
int cuoi = 0;
while (cuoi < n) {
vt = 0;
for (int j = min(n, cuoi + r); j > max(0, cuoi - r + 1); j--)
if (a[j] == 1 && cuoi >= j - r... | 2 |
#include <bits/stdc++.h>
template <class T>
inline void read(T &res) {
res = 0;
bool bo = 0;
char c;
while (((c = getchar()) < '0' || c > '9') && c != '-')
;
if (c == '-')
bo = 1;
else
res = c - 48;
while ((c = getchar()) >= '0' && c <= '9')
res = (res << 3) + (res << 1) + (c - 48);
if (... | 4 |
#include <bits/stdc++.h>
using namespace std;
string s;
int k;
void changeNumbers(int i) {
s[i] = '9';
if (i > 1 && s[i - 1] != '0') {
s[i - 1] -= 1;
} else {
if (i > 1 && s[i - 1] == '0') {
s[i - 1] = '9';
changeNumbers(i - 1);
}
}
if (i == 1 && s[i - 1] != '0') {
s[i - 1] -= 1;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline long long getnum() {
char c = getchar();
long long num, sign = 1;
for (; c < '0' || c > '9'; c = getchar())
if (c == '-') sign = -1;
for (num = 0; c >= '0' && c <= '9';) {
c -= '0';
num = num * 10 + c;
c = getchar();
}
return num * sign;
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long dp[2][2000], a[2000][2000], o[2000][2000];
int main() {
ios::sync_with_stdio(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < m; j++) cin >> a[i][j];
for (int j = 1; j <= m; j++) o[i][j] = o[i][j - 1] + a[i][j - 1];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> s, t;
vector<int> G[100000];
int used[100000];
void dfs1(int v) {
s.push_back(v);
used[v] = 1;
for (auto to : G[v]) {
if (!used[to]) {
dfs1(to);
break;
}
}
}
void dfs2(int v) {
t.push_back(v);
used[v] = 1;
for (auto to : G[v]) {
i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int sum, t, p, pos, a[100005], b[100005], n, f, c, f1;
cin >> t;
while (t--) {
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
cin >> n;
f = 1;
sum = 0;
p = 0;
f1 = 1, c = 0;
for (int i = 0; i < n; i++) cin >> a[i];
f... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
char s[N];
int main() {
int aOdd = 0, aEven = 0, bOdd = 0, bEven = 0;
scanf("%s", s);
int n = strlen(s);
for (int i = 0; i < (n); ++i) {
if (s[i] == 'a') {
if (i & 1)
++aOdd;
else
++aEven;
} else {
if (... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t = 1;
cin >> t;
while (t--) {
long long n, a, b;
cin >> n >> a >> b;
long long a1 = a * n;
long long a2 = (n / 2) * b;
if (n % 2 != 0) a2 += a;
if (a1 < a2) {
cout << a1 << endl;
} else
cout << a2 << endl... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int h, n, m, cnt, out[MAXN], ans, a[MAXN];
bool vis[MAXN];
struct Edge {
int nxt, from, ver;
} e[MAXN * 2];
int head[MAXN], tot;
void add(int u, int v) {
e[++tot].from = u;
e[tot].ver = v;
e[tot].nxt = head[u];
head[u] = tot;
}
stack<int>... | 3 |
#include <bits/stdc++.h>
using namespace std;
int A[5000 + 2], n;
vector<pair<int, int> > v;
int binary(int num, int x, int y) {
int lo = x, hi = y, mi;
if (num <= v[lo].first) return lo;
if (!(num <= v[hi].first)) return n;
while (hi - lo > 1) {
mi = (lo + hi) / 2;
if (num <= v[mi].first)
hi = mi... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
;
long long int t, i, n = 7;
cin >> t;
long long int arr[7];
while (t--) {
for (i = 0; i < n; i++) {
cin >> arr[i];
}
cout << arr[0] << " " << arr[1] << " " << arr[6] - (arr[0] ... | 1 |
/*Bismillahir Rahmanir Rahim*/
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define ff first
#define ss second
#define ll long long int
#define dd double
#define pb push_back
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char cad[100];
int tam, signo = 1;
long long res = 0, acarreo = 0;
scanf("%s", cad);
tam = strlen(cad);
for (int i = 0; i < tam; i++) {
if (cad[i] == '-' || cad[i] == '+') {
res += signo * acarreo;
acarreo = 0;
}
if (cad[i] =... | 6 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> it[1 << 21];
void it_add(pair<int, int> val, int pos) {
int p = pos + (1 << 20) - 1;
while (p) {
it[p] = max(it[p], val);
p /= 2;
}
}
pair<int, int> it_get(int nd, int nl, int nr, int l, int r) {
if (l <= nl && nr <= r) return it[nd];
if (l ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
int n, m, t;
long long dp[61][31][31];
int arr[61];
long long solve(int ind, int x, int y) {
if (x > 3 && y > 0 && x + y == t) return 1;
if (ind == n + m + 1) return 0;
long long &ret = dp[ind][x][y];
if (ret != -1) return ret;
ret = solv... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double error = 1e-15;
const double pi = 2 * acos(0);
const int maxn = (int)1e5 + 10;
const int mod = (int)1e9;
int dx[] = {0, -1, 0, +1, -1, -1, +1, +1};
int dy[] = {-1, 0, +1, 0, -1, +1, +1, -1};
long int A[900], B[900], C[900];
vector<pair<long, pair<int, int> > > v... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int fin() {
long long int x;
scanf("%lld", &x);
return x;
}
void func() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
pair<long long int, long long int> p;
map<pair<long long int, long long int>, long long int> mp;
int main() ... | 3 |
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#de... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 4e18;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long a, b;
cin >> a >> b;
long long d = abs(a - b);
if (b == a)
cout << 0 << '\n';
e... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool isnum(string s) {
if (s[0] == '0') return false;
for (char c : s)
if (c > '9' || c < '0') return false;
return true;
}
int n;
vector<pair<string, string> > V;
void dod(string a, string b) { V.push_back(pair<string, string>(a, b)); }
char A[10];
string tost(in... | 3 |
#include <bits/stdc++.h>
int main() {
int a, b, m, s = 0;
scanf("%d %d", &a, &b);
s = a;
while (1) {
m = a / b;
a = m + (a % b);
s += m;
if (a < b) break;
}
printf("%d", s);
return 0;
}
| 1 |
#include <iostream>
#include <vector>
#include <climits>
#include <functional>
template<typename T>
struct segment_tree {
long long N; // 木の頂点数
long long M; // 葉の数
std::vector<T> V; // セグメント木 1-indexed
std::vector<T> W; // 遅延配列 1-indexed
std::vector<bool> flag; // true : W[i] の子孫に更新していない遅延配列が存在
std::... | 0 |
#include<bits/stdc++.h>
#define mxn 1000010
#define LL long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair<int,int>
#define mp make_pair
#define fr first
#define sc second
#define pb push_back
#define node(a,b,c) (node){a,b,c}
using namespace std;
const int inf=1e9,mod=1e9+7;
int... | 0 |
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string str;
int last[256];
int cost[216000];
int nxt[216000];
char chr[216000];
int main(){
cin >> str;
fill(last, last + 256, str.size() + 1);
cost[str.size() + 1] = 0;
for(int i = str.size();i >= 0;i--){
cost[i] = 216000;
fo... | 0 |
#include<cstdio>
#include<cstring>
const int N=2005;
int n,m,he[N],to[N*2],nx[N*2],f[N][N],g[N],h[N],fa[N],sz[N],a=1e9;
inline void wk(int w,int x,int y){to[w]=y,nx[w]=he[x],he[x]=w;}
inline int mn(int x,int y){return x<y?x:y;}
void dfs(int x)
{
memset(f[x],0x3f,sizeof(f[x])),f[x][0]=0,sz[x]=1;
for(int i=he[x],y;i;i=... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7;
int n;
bool del[MAXN];
int a[MAXN], to[MAXN];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < n; ++i) to[i] = i + 1;
vector<int> v;
for (int i = n - 1; i... | 2 |
//g++ -Wall -Werror -O2 -std=c++11 main.cpp -o main && main.exe < in.txt
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long
int main() {
ios::sync_with_stdio(false);
int N, Q;
string S;
cin >> N >> S >> Q;
for (int i = 0; i < Q; i++) {
int k;
cin >> k;
ll a = 0;
l... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int q;
cin >> q;
while (q--) {
int b, w;
cin >> b >> w;
if (b > 3 * w + 1 || w > 3 * b + 1) {
cout << "NO\n";
continue;
}
cout << "YES\n";
int sx = 2, sy = 3;
if (b > w)... | 5 |
#include<bits/stdc++.h>
const int N = 200010;
int a[N], left[N], right[N];
int main(){
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++ i){
scanf("%d", &a[i]);
}
std::stack <int> s;
for (int i = 0; i <= n + 1; ++ i){
while (!s.empty() && a[s.top()] > a[i]){
right[s.top()] = i;
s.pop();
}
if (!s... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a, b;
string s, t;
bool chk(string s) {
int ss = 0;
for (auto c : s) ss += c == 0;
for (auto c : t) ss -= c == 0;
if (ss) return 0;
if (t.find(s) != t.npos) return 1;
return 0;
}
int main() {
cin >> a >> b;
if (a == b) {
cout << "YES\n";
re... | 6 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
int const N = 5e5 + 20, mod = 998244353;
int n, dp[N][2], ans, sz[N], pw[N];
vector<int> g[N];
inline void add(int &a, int b) {
a += b;
if (a >= mod) a -= mod;
}
void dfs(int v, int par = -1) {
... | 5 |
#include <bits/stdc++.h>
int a[1001];
int main() {
int n, m = -1, M = 1e7, c = 0, x;
scanf("%d", &n);
while (n--) scanf("%d", &x), x > m ? m = x, c++ : 0, x < M ? M = x, c++ : 0;
printf("%d", c - 2);
}
| 1 |
#include<iostream>
using namespace std;
int main()
{
string s,t;
cin>>s>>t;
int s1=s.size(),t1=t.size();
string dp[2][t1+1];
for(int i=0;i<=t1;++i)
dp[0][i]="";
for(int i=1;i<=s1;++i)
{
dp[1][0]="";
dp[0][0]="";
for(int j=1;j<=t1;++j)
{
if(s[i-1]==t[j-1])
{
dp[1][j]=dp[0][j-1];
dp[1][j]+=... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,mi=100001,m,sum=0,x;
cin>>n>>x;
for(int i=0;i<n;i++){
cin>>m;
mi=min(mi,m);
sum+=m;
}
cout<<n+(x-sum)/mi<<endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
bool prime[1000000 + 1];
void SieveOfEratosthenes() {
memset(prime, true, sizeof(prime));
prime[1] = false;
for (int p = 2; p * p <= 1000000; p++) {
if (prime[p] == true) {
for (int i = p * 2; i <= 1000000; i += p) prime[i] = false;
}
}
}
long long int... | 2 |
#include <bits/stdc++.h>
using namespace std;
char s[101];
char vowels[] = {'A', 'E', 'I', 'O', 'U', 'Y', '\0'};
int main() {
scanf("%s", s);
int ans = 0;
int cur = -1;
for (int i = 0; i < strlen(s); ++i) {
for (int j = 0; j < strlen(vowels); ++j) {
if (s[i] == vowels[j]) {
if (ans < i - cur) ... | 1 |
#include <bits/stdc++.h>
#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
#ifdef __WIN32
#define LLFORMAT "I64"
#define Rand() ((rand() << 15) + rand())
#else
#define LLFORMAT "ll"
#define Rand() (rand())
#endif
using namespace std;
const int maxn = 1e5 + 10;
int n, rt, ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int h[1010];
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) scanf("%d", &h[i]);
int ans = 1, de = 1, num = 1, su = 5000;
for (int i = 1; i <= 1000; i++) {
int w = i - k;
de = num = 0;
int j;
for (j = 1; j <= n; j++) {
w +=... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(){long long x,y;cin>>x>>y;cout<<floor(log2((long double)(y/x)))+1<<endl;} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, s;
cin >> a >> b >> s;
int sum = abs(a) + abs(b);
int temp = (sum - s) % 2;
if (!temp && s >= sum)
cout << "Yes\n";
else
cout << "No\n";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long f(long long x, long long y, long long n, long long c) {
if (c == -1) return 0LL;
long long ret = (c + 1) * (c + 1) + c * c;
if (c > x - 1) ret -= (c - x + 1) * (c - x + 1);
if (c > n - x) ret -= (c + x - n) * (c + x - n);
if (c > y - 1) ret -= (c - y + 1... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
struct node {
int l, r;
};
node a[N];
int vis[N];
int v1[N], v2[N];
int solve(int x, int y) {
if (a[x].l > a[y].l) {
swap(x, y);
}
if (a[x].r < a[y].l) return 0;
if (a[x].r > a[y].r) {
return v2[a[y].r] - v2[a[y].l - 1];
}
return... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int size = 110000, mod = 1000000009;
long long cal(long long a, int n, int m) {
long long s = 1;
while (n) {
if (n & 1) s = (s * a) % m;
a = (a * a) % m;
n /= 2;
}
return s;
}
int main() {
int n, m;
cin >> n >> m;
long long ans = 1, tmp = cal... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[101];
int edge[101][2];
int len_graph[101];
int graph[103][100];
bool prime[32001];
int cnt[101];
int cap[103][103];
int rsd[103][103];
int path[103];
bool flag[103];
bool has_aug_path(int from, int to, int path[], int &len_path) {
path[len_path++] = from;... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool check(long long int mid, vector<pair<long long int, long long int>> v,
long long int k) {
long long int c = 0;
for (long long int i = v.size() - 1; i >= 0; i--) {
c += (v[i].first) / mid;
}
if (c >= k) return true;
return false;
}
int main() {
... | 4 |
#include<iostream>
int a[99]={11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381};
int main(){int n;std::cin>>n;for(int i=0;i<n;i++){std::cou... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long oo = 1LL << 60;
int value[100100], n, k, taken[100100];
long long dist[10010], H;
vector<pair<long long, int> > treasure[10010];
vector<long long> method;
priority_queue<pair<int, int> > reach;
void dijkstra() {
priority_queue<pair<long long, int> > q;
f... | 3 |
#include <iostream>
#include <vector>
using namespace std;
vector<int> g[100005];
int N, u, v;
vector<int> ret(100005);
void dfs(int now, int d, int par){
ret[now] = d;
for(auto next : g[now]){
if(next == par) continue;
dfs(next, d+1, now);
}
}
vector<int> dist(int s){
dfs(s, 0, -1)... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1E9;
int D, V, N;
pair<int, int> gas[200005];
int d[200005], a[200005], dp[19][200005], lenj[200005];
void rmq() {
for (int i = (0); i < (19); i++) {
for (int len = (1 << i); len < (1 << (i + 1)); len++) {
if (len >= N) break;
lenj[len... | 4 |
#include <bits/stdc++.h>
using namespace std;
char s[55][55], ss[55][55];
vector<pair<int, int> > path1, path2;
int r, c;
bool check(char s[][55]) {
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j += 2) {
if (s[i][j] != 'L') return false;
}
}
return true;
}
bool check2(char s[][55]) {
for (... | 4 |
#include<bits/stdc++.h>
#define inf 1000000000
#define N 2009
using namespace std;
int n,cnt,f[N],g[N]; char a[N],b[N];
struct node{ int x,y; }c[N];
bool cmp(node u,node v){ return u.x<v.x; }
int calc(int x,int y,int u,int v){
return x+y+min(y+abs(x-u),x+abs(y-v));
}
int main(){
scanf("%s%s",a,b); n=strlen(a);
int ... | 0 |
#include <bits/stdc++.h>
template <class T>
inline void read(T &res)
{
char ch; bool flag = false; res = 0;
while (ch = getchar(), !isdigit(ch) && ch != '-');
ch == '-' ? flag = true : res = ch ^ 48;
while (ch = getchar(), isdigit(ch))
res = res * 10 + ch - 48;
flag ? res = -res : 0;
}
const int N = 1e7 + 5;
c... | 0 |
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#includ... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct pq {
int st, ed;
long long tot_ac;
int f;
pq() {}
pq(int i, int j, long long k) { st = i, ed = j, tot_ac = k, f = 0; }
};
pq fib[100];
pq find_sol(pq a, pq b) {
if (a.ed != -1 && b.ed != -1) {
if (a.ed == 1 && b.st == 2)
return pq(a.st, b.ed, a.... | 4 |
#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,b,a) for(int i=b;i>=a;i--)
#define efo(i,u,v) for(int i=BB[u],v=B[BB[u]][1];i;v=B[i=B[i][0]][1])
#define mset(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
char ch;
int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, m, i, j, c1 = 0, c2, c = 0, s;
cin >> n >> m;
if (n == 1)
cout << "YES" << endl;
else if (m == 1)
cout << "YES" << endl;
else if (n == 2 && m == 2)
cout << "YE... | 1 |
#include <bits/stdc++.h>
using namespace std;
const pair<int, int> bound(0, 0);
int main() {
int k, n, maxb, t;
scanf("%d%d%d%d", &k, &n, &maxb, &t);
while (k--) {
vector<int> seq(n);
vector<vector<pair<int, int>>> dp(
n + 1, vector<pair<int, int>>(maxb + 1, make_pair(0, 0)));
vector<pair<int,... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long getgcd(long long a, long long b) {
long long t, sum;
sum = a * b;
while (b > 0) {
t = b;
b = a % b;
a = t;
}
return sum / a;
}
int main() {
long long n, a, b, p, q, sum1, sum2, sum3, x, y, ans;
while (scanf("%lld%lld%lld%lld%lld", &n, &a,... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int count = 0, n, max, a, min;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
if (i == 0) {
max = a;
min = a;
} else if (a > max) {
max = a;
count++;
} else if (a < min) {
min = a;
count++;
}
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-12;
const int inf = 2000000000;
const long long int infLL = (long long int)2e18;
long long int MOD = 1000000007;
int MOD1 = 1000000007;
int MOD2 = 1000000009;
inline bool checkBit(long long int n, long long int i) {
return... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6;
vector<int> e[SIZE];
vector<int> gg[SIZE];
int jump[20][SIZE], lv[SIZE];
void __init(int x, int lt) {
gg[lv[x]].push_back(x);
jump[0][x] = lt;
for (int i = 0; i < (((int)(e[x]).size())); ++i) {
int y = e[x][i];
if... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1000000007;
const int Maxn = 1010101;
long long p, k, Ans;
bool visited[Maxn];
void dfs(long long v) {
visited[v] = true;
if (!visited[v * k % p]) dfs(v * k % p);
}
int main() {
cin >> p >> k;
Ans = 1;
if (k == 1) Ans = p;
for (int i = 1; i < p; ... | 4 |
#include<iostream>
using namespace std;
int main()
{
int A,B;
cin>>A>>B;
if(A<=9 && B<=9)
cout<<A*B;
else
cout<<-1;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(nam... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q;
struct query {
int type, idx, i, j;
query() {}
query(int type, int idx, int i, int j) {
this->type = type;
this->idx = idx;
this->i = i;
this->j = j;
}
};
bool shelf[2000][2000];
bool invert[2000];
int row[200000];
vector<vector<query> >... | 4 |
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int INF=1001001001;
int map[10][10000];//0????????????
int main(){
while(1){
int R,C;
scanf("%d %d",&R,&C);
if(R==0&&C==0)break;
rep(i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int cnst = -(1e9 + 7);
bool IsQuery = true, found;
long long int q = 1, cnt;
void solve() {
long long int b, c, r, g, o, e, p, d, x, y, z, n,
minm = cnst, maxm = cnst, k = 200, sum = 0, ans = 1, l = 0, flag = 0,
sum1;
string s, t, s1;
set<string> set... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a[32000];
for (int i = 0; i < 32000; i++) a[i] = i * i;
if (n == 1) {
cout << 2;
return 0;
}
for (int i = 1; i < 32000; i++) {
if (n <= a[i + 1] && n >= a[i]) {
if (n <= a[i] + i) {
cout <... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, t;
int main() {
scanf("%d", &t);
for (k = 0; k < t; k++) {
scanf("%d %d", &n, &m);
int res = 0;
char a[252][252];
bool b[252][252];
short sum_row[252][252];
short sum_col[252][252];
short sum_d1[252][252];
short sum_d2[... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int x = 0, y = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
char c;
cin >> c;
if (c == '*') {
x = x ^ i;
y = y ^ j;
}
}
}
cout << x << " " << y;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
struct message {
string from;
string to;
int time;
};
bool mark[int(1e4)];
message msg[int(1e4)];
int n, d, result;
vector<pair<string, string> > friends;
int main() {
cin >> n >> d;
for (int i = 0; i < n; i++) {
string from, to;
int time;
cin >> from ... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > V;
int main() {
int n, k, i, j;
scanf("%d %d", &n, &k);
int arr[n];
long long int suffix_total = 0;
for (i = 0; i < n; i++) {
scanf("%d", &arr[i]);
suffix_total = suffix_total + arr[i];
}
sort(arr, arr + n);
pair<int, int> p;
... | 6 |
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;
int main()
{
int n,q,c,t,x;
vector<priority_queue<int, vector<int>>> a;
scanf("%d", &n);
scanf("%d", &q);
for (int i = 0; i < n; i++) {
a.emplace_back();
}
for (int i = 0; i < q; i++) {
scanf("%d", &c);
scanf("%... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int i = 1; i <= t; i++) {
int n, k;
cin >> n >> k;
if (k % 3 != 0) {
if (n % 3 == 0) {
cout << "Bob" << endl;
} else {
cout << "Alice" << endl;
}
} else {
n %= (k + 1);
if... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool isrange(int second, int first, int n, int m) {
if (0 <= second && second < n && 0 <= first && first < m) return true;
return false;
}
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1},
ddy[8] = {1, 0, -1, 0, 1, 1, -1, -1}, ddx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
c... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int flag = 0, n;
cin >> n;
for (int i = 0; i < 150; i++) {
int x = 7 * i;
for (int j = 0; j <= 200; j++) {
int y = 5 * j;
int z = n - x - y;
if (z < 0) continue;
if (!z... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m[5];
int w[5];
int s, u;
for (int i = 0; i < 5; i++) {
cin >> m[i];
}
for (int i = 0; i < 5; i++) {
cin >> w[i];
}
cin >> s >> u;
double out[5];
int x[5];
x[0] = 500;
x[1] = 1000;
x[2] = 1500;
x[3] = 2000;
x[4] = 2500;... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6;
const int INF = 1e9 + 9;
struct FenTree {
int n;
unordered_map<int, int> t;
void init(int _n) { n = _n; }
void upd(int x, int val) {
for (; x <= n; x = (x | (x + 1))) t[x] = max(t[x], val);
}
int get(int x) {
int ans = 0;
for (; x ... | 2 |
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define LL long long
#define Maxn 800005
using namespace std;
const LL P = 200003; const double PI = acos(-1.0);
inline LL read() {
LL x = 0, f = 1;
char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int tree[5 * 300006];
long long int lazy[5 * 300006];
long long int n;
long long int arr[300006];
bool vis[300006];
map<long long int, long long int> m;
vector<long long int> v, vv;
long long int p = 1000000007;
long long int power(long long int x, long long int y... | 3 |
#include<bits/stdc++.h>
using namespace std;
int main () {
long long n, t, i, x, m, r, ans, y, p ;
string s;
cin >> n >> m >> s;
map < long long, long long > a;
a[0] = 0;
for ( i = 0; i < n; i ++) {
a[i +1] = a[i] + s[i] - 'a';
}
for ( i =1 ; i <= m; i ++) {
scanf("%lld",& x );
scanf(... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int mod = (int)1e+9 + 7;
const double pi = acos(-1.);
const int maxn = 5 * 100100;
priority_queue<long long> q;
long long t = 0;
int main() {
srand(time(0));
const string file = "";
if (!file.empty()) {
freopen((file + ".in").c_str()... | 4 |
#include <bits/stdc++.h>
char a[128], c[128];
int b, d, t[128];
int main() {
scanf("%d%d", &b, &d);
scanf("%s%s", a, c);
int s = 0, n = strlen(c);
for (int i = 0; c[i]; ++i) {
int& k = t[i];
for (int j = 0; a[j]; ++j)
if (a[j] == c[(i + k) % n]) ++k;
}
for (int i = 0; i < b; ++i) s += t[s % n]... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 1000111, max_lev = 20, mod = 1000000007;
int n, k, a[max_n], mx[max_lev][max_n], dp[max_n];
multiset<int> q;
void add(int &x, int y) {
x += y;
if (x >= mod) {
x -= mod;
}
}
int main() {
scanf("%d%d", &n, &k);
--k;
for (int i = 0; i < n; ++i... | 6 |
#include <bits/stdc++.h>
using namespace std;
string a[123];
bool b[1234];
int pos[1234];
int main() {
int m, n;
cin >> m >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
for (int j = 0; j < m; j++) {
if (a[i][j] == '0') {
b[i] = 1;
break;
}
}
}
for (int i = 0; i < n; i... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, n;
set<int> s;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a);
s.insert(a);
}
if (s.size() <= 2) {
puts("YES");
} else if (s.size() == 3) {
vector<int> v(s.begin(), s.end());
if (v[2] - v[1] == v[1] - v[0... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a... | 0 |
#include <iostream>
using namespace std;
int main() {
int a,b,c,d;
cin >> a >> b >> c >> d;
cout << max(0, min(b,d) - max(a,c)) << endl;
} | 0 |
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[60][60];
int dp[52][52][52][52];
int v[52][52][52][52];
int r[600];
int w[600];
int sz;
int H,W;
int solve(int a,int b,int c,int d){
if(a>c||b>d)return 0;
if(a<0||b<0||c>=H||d>=W)return 0;
if(str[a][b]=='#'||str[c][d]=='#')return 0;
if(~dp[a][b][c]... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, p = 0;
cin >> n;
int ara[n];
for (i = 0; i < n; i++) {
cin >> ara[i];
}
sort(ara + 0, ara + n);
for (i = 0; i < n - 1; i++) {
if (ara[i] + 1 != ara[i + 1]) p = p - 1 + ara[i + 1] - ara[i];
}
cout << p;
}
| 1 |
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
while(1){
int N;
cin>> N;
if(!N) break;
vector<pair<double, string>> V;
for(int i=0; i<N; i++){
string L;
int P, A, B, C, D, E, F, S, M;
cin>> L>> ... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int f(long long int x, long long int b, long long int n) {
return x * x + b * x - n;
}
long long int find(int lo, int hi, long long int b, long long int n) {
if (lo > hi) return -1;
long long int m = (lo + hi) / 2;
if (f(m, b, n) == 0)
return m;
else... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, n;
cin >> a >> b >> c >> n;
int d = n - (a + b - c);
if ((a - c) >= 0 && (b - c) >= 0 && c >= 0 && d > 0) {
cout << d << endl;
} else
cout << -1 << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
int aib_repaired[MAX], aib_broken[MAX], n, k, updated, current, q;
int lsb(int x) { return x & (-x); }
int sum_query(int aib[], int pos) {
if (!pos || pos > n) return 0;
int sum = 0;
for (int i = pos; i > 0; i -= lsb(i)) sum += aib[i];
retur... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1e9 + 7, MOD1 = 998244353;
void _print(long long int t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[110000];
int b[100021];
int c[111002];
int main() {
int n;
while (scanf("%d", &n) == 1) {
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < n; i++) scanf("%d", &b[i]);
for (int i = 0; i < n; i++) c[a[i] - 1] = b[i];
for (int i = 0... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> g[2501];
long long visited[2501];
long long low[2501];
long long disc[2501];
long long parent[2501];
long long apa[2501] = {0};
void ap(long long u) {
static long long time = 0;
long long child = 0;
visited[u] = 1;
disc[u] = low[u] = ++time;
for ... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.