solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int n, m, arr[500005], l[500005], r[500005], ord[500005], ans[500005],
bit[500005];
map<int, int> mm;
bool cmp(int x, int y) { return r[x] < r[y]; }
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
for (int i = 0; i < 500005;... | 4 |
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#in... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, arr[110][110], brr[110];
set<int> ans;
bool found = 0;
void solve() {
vector<pair<int, int>> temp;
vector<int> tempans;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < m; j++) {
int k = arr[j][n - 1] - arr[j][i];
temp.push_back({k... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 1e5 + 4;
const long long MOD = 998244353;
stack<int> St;
bool visited[N];
vector<int> conc[N];
vector<long long> edge[N];
vector<long long> depth(N);
vector<long long> sub(N, 0);
pair<long long, pair<long long, long long>> wt[N];... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
long long int n;
cin >> n;
vector<long long int> array(n);
for (long long int i = 0; i < n; i++) cin >> array[i];
long long int count = 0, last_index = 0, last_num = array[0];
for (long long int i = 0; i < n; i++) {
if (last_num != array[i])... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n) {
int num[n];
for (int i = 0; i < n; ++i) scanf("%d", &num[i]);
int vis[n];
int cnt = 0;
bool ans = false;
for (int i = 0; i < n; ++i) {
cnt = 0;
memset(vis, 0, sizeof(vis));
for (int j = 0; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, data[1000], orig[1000];
vector<pair<int, int> > ans[1000], stat;
bool up(int ind);
bool isUsed[1000];
void print(int ind);
bool increase(int &curVal, int i);
int lastlen;
int main(void) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> orig[i];
data[i] = o... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d%d", &n, &m);
int mn = min(n, m);
printf("%d\n", mn + 1);
for (int i = 0; i <= mn; i++) {
printf("%d %d\n", i, mn - i);
}
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
bool f1(pair<long long, long long> x, pair<long long, long long> y) {
return x.first > y.first;
}
bool f2(pair<long long, long long> x, pair<long long, long long> y) {
return x.second > y.second;
}
bool f3(long long x, long long y) { return x > y; }
long long gcd(long l... | 1 |
#include <bits/stdc++.h>
int main() {
int i, j, n, g[25][25], k, find;
bool mark[1001];
int a[25];
a[0] = a[1] = 0;
k = 1;
memset(mark, 0, sizeof(mark));
mark[0] = 1;
for (i = 2; i <= 20; ++i) {
find = 0;
while (!find) {
for (j = 1; j < i; ++j) {
if (mark[a[j] + k]) break;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, x, y;
cin >> n >> x >> y;
string s;
cin >> s;
long long ans = 0, a = 0, b = 0;
reverse(s.begin(), s.end());
cerr << s << endl;
for (long long i = 0; i < y; i++) {
if (s[i] == '1') {
ans++;
}
}
cerr << ans;
if (... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char ch;
set < char > s;
for(int i=0;i<4;i++)
{
cin >> ch;
s.insert(ch);
}
if(s.size()==2) cout << "Yes";
else cout << "No";
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 64;
const int inf = 1e9 + 5;
const long double eps = 1e-8;
const int Q = 1e9 + 7;
long long countInv = 0;
void mergeSort(vector<int> &a, long long l, long long r) {
if (l == r) return;
long long m = (l + r) / 2;
mergeSort(a, l, m);
mergeSort(a, m + ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int cx[] = {-1, 0, 0, 1, -1, -1, 1, 1, 0},
cy[] = {0, -1, 1, 0, -1, 1, 1, -1, 0};
int ingrid(int ii, int jj, int R, int C) {
if (ii < 0 || jj < 0 || ii >= R || jj >= C) return 0;
return 1;
}
int in[10];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct __s {
__s() {
srand(time(NULL));
if (1) {
ios_base::Init i;
cin.sync_with_stdio(0);
cin.tie(0);
}
}
~__s() {
if (!1)
fprintf(stderr, "Execution time: %.3lf s.\n",
(double)clock() / CLOCKS_PER_SEC);
int n... | 5 |
#include <bits/stdc++.h>
int main() {
int n, d, flag = 0;
scanf("%d", &n);
int ara[n], i, j, k;
char str[n][101], stt[] = "aeiouy";
for (i = 0; i < n; i++) {
scanf("%d", &ara[i]);
}
getchar();
for (i = 0; i < n; i++) {
gets(str[i]);
}
for (i = 0; i < n; i++) {
d = 0;
for (j = 0; j < ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
vector<long long> dp(4, 0), a(4, 0);
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
dp[0] = 1;
for (int i = 1; i <= n; i++) {
a[0] = a[1] = a[2] = a[3] = 0;
a[0] = 1ll * (dp[1] + dp[2] + dp[3]) % M;
a[1]... | 5 |
//
// 円の接線 (円外の 1 点から円へ)
//
// verified:
// AOJ Course CGL_7_F Circles - Tangent to a Circle
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_F&lang=jp
//
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
//////////////////////... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int a[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = int(0); i < int(n); i++) cin >> a[i];
sort(a, a + n);
int h = 0, cnt = 0, mx = 0;
long long total = 0;
for (int i = int(0); i < int(n)... | 2 |
#include<cstdio>
int main()
{
int a, b;
scanf("%d%d", &a, &b);
if ((a * b) & 1)
puts("Odd");
else
puts("Even");
return 0;
} | 0 |
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>
#define int long long
#define lowbit(x) (x&(-x))
#define mp(x,y) make_pair(x,y)
#define lc (x<<1)
#define rc (x<<1|1)
#define fi first
#define se second... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long c1, c2, c3, c4;
cin >> c1 >> c2 >> c3 >> c4;
if (c3 == 0 && c1 == c4) {
cout << 1 << endl;
return 0;
}
c1 -= 1;
c4 -= 1;
if (c1 >= 0 && c1 == c4)
cout << 1 << endl;
else
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, r[100], l[100], n, x, cnt = 1, ans;
int main() {
cin >> n >> x;
for (i = 1; i <= n; i++) {
cin >> l[i] >> r[i];
ans += (l[i] - cnt) % x;
ans += (r[i] - l[i] + 1);
cnt = r[i] + 1;
}
cout << ans;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, d;
cin >> n >> m >> d;
int arr[n][m];
int arr1[n * m];
int flag = 1, median;
int last = -1;
int k = 0, ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> arr[i][j];
arr1[k] = arr[i][j];
k+... | 2 |
#include <bits/stdc++.h>
using namespace std;
string s;
long long N;
void change() {
for (int i = 0; i < s.size(); ++i) {
if (s[i] == 'L') {
s[i] = 'R';
} else {
s[i] = 'L';
}
}
}
bool good(int p) {
int curr = 0, step = 0, ma = 0, cnt = 1;
bool v = 0;
for (int i = 0; i < N; ++i) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int a[101010 * 3];
int b[101010 * 3];
int _rank[101010 * 3];
int n, m, k;
int main() {
memset(b, 0, sizeof(b));
scanf("%d", &n);
for (int i = 0; i < 3 * n; ++i) {
scanf("%d", &a[i]);
_rank[a[i]] = i;
}
int len = 0;
for (int i ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n;
string s[100005];
long long t[100005];
vector<pair<string, string> > ans;
set<string> S[2];
set<string> freeS[2];
set<string> wrong[2];
long long check(string &s) {
for (auto c : s) {
if (c < '0' || c > '9') return -1;
}
if (s.front() == '0') return -... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
string queue_[6] = {"", "Sheldon", "Leonard", "Penny", "Rajesh", "Howard"};
int main() {
cin >> n;
double count = 1;
bool used = false;
while (count * 5 < n) {
n -= count * 5;
count *= 2;
used = true;
}
int x = ceil(n / count);
cout << queue... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
vector<long long> adj[1000005];
long long a[1000005];
long long val[1000005];
bool chan[1000005];
void dfs(long long n) {
if (a[n] < 3) {
dfs(adj[n][0]);
dfs(adj[n][1]);
long long v1 = val[adj[n][0]];
long long v2 = val[adj[n][1... | 4 |
#include <iostream>
using namespace std;
int main(){
unsigned h,w,x,y,t;
cin>>h>>w;
for(y=0; y<h; ++y){
for(x=0; x<w; ++x){
cin>>t;
if((x^y)&1)
cout<<"720720 ";
else cout<<720720+t*t*t*t<<' ';
}
cout<<'\n';
}
return 0;
} | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[100005], it[100005][100], it2[100005][100], sum[100005],
it3[1000];
void buil() {
for (long long i = (1); i <= (n); ++i) it[i][0] = a[i];
for (long long k = 1; (1ll << k) <= n; k++)
for (long long i = 1; i + (1ll << k) - 1 <= n; i++)
it[i][k... | 4 |
#include "stdio.h"
#include "math.h"
#include <algorithm>
using namespace std;
#define SUQARE_SIZE 100000
int block[SUQARE_SIZE];
int blockSize;
int n;
void updateArr(int arr[],int left,int num){
for(int i = left;i < left + blockSize;++i){
if(i >= n){
break;
}
arr[i] = num;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
cout << (a ^ b) << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, m, t, c[1001], first[500], last[500];
long long dp[1000][1000];
long long f(int l, int r) {
if (l > r) return 1;
if (dp[l][r] != -1) return dp[l][r];
int col = n;
for (int i = l; i <= r; i++) col = min(col, c[i]);
if (first[col] <... | 6 |
#include <bits/stdc++.h>
int main() {
int t, n;
std::cin >> t;
for (int i = 0; i < t; ++i) {
std::cin >> n;
std::vector<int> v(n);
for (int j = 0; j < n; ++j) {
std::cin >> v[j];
}
std::sort(v.begin(), v.end(), std::greater<int>());
for (int k : v) {
std::cout << k << " ";
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, maximum;
int v[200005];
stack<int> st;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> v[i];
maximum = max(maximum, v[i]);
}
for (int i = 1; i <= n; ++i) {
if (v[i] == maximu... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
int connect[30][30];
int a, b;
memset(connect, 0, sizeof connect);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a >> b;
connect[a][b] = 1;
connect[b][a] = 1;
}
if (n <= 6)
printf("%d\n", m);
else {
int ans ... | 1 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s,s1,s2;
cin>>s;
s1=s.substr(0,2),s2=s.substr(2,4);
bool b1="01"<=s1&&s1<="12",b2="01"<=s2&&s2<="12";
cout<<(b1?b2?"AMBIGUOUS":"MMYY":b2?"YYMM":"NA")<<endl;
}
| 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:32000000")
#pragma GCC optimize("O3")
using namespace std;
int n, m;
int arr[4][128];
int dp[128][16];
int mx(int id, int mask) {
int MX = 0;
for (int i = 0; i < n; i++) {
int sum = 0;
for (int j = 0; j < n; j++) {
if (mask & (1 << j)) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, p, w, d;
cin >> n >> p >> w >> d;
if (p % w == 0 && n >= p / w) {
cout << p / w << " " << 0 << " " << n - p / w;
return 0;
}
if (p % d == 0 && n >= p / d) {
cout << 0 << " " << p / d << " " << n - p / d;
return 0;
}
if... | 3 |
#include <iostream>
#include <vector>
using namespace std;
int main(void){
while (1) {
int n; cin >> n;
if (!n) break;
vector<char> v1, v2;
for (int i = 0; i < n; i++) {
char c;
cin >> c; v1.push_back(c);
cin >> c; v2.push_back(c);
}
int m; cin >> m;
for (int i = 0; i < m; i++) {
char b; ... | 0 |
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <map>
#define all(x) (x).begin(), (x).end()
#define mkp make_pair
#define fr first
#define sc second
using namespace std;
int N;
void solve();
int main() {
while (cin >> N, N)
solve();
return 0;
}
void solve() {
istringst... | 0 |
#include <bits/stdc++.h>
using namespace std;
std::mt19937_64 rng(
std::chrono::steady_clock::now().time_since_epoch().count());
void solve() {
int t;
cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
int c = abs(a - b);
int d = c / 10;
if (c % 10 == 0) {
cout << d << "\n";
} else... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10000, G = 1000, INF = 0x3f3f3f3f;
int xx[N], qu[G + 1][N], cnt[G + 1];
bool used[G + 1][N];
int main() {
int x_, n;
cin >> x_ >> n;
for (int i = 0; i < n; i++) cin >> xx[i];
int g, r;
cin >> g >> r;
sort(xx, xx + n);
used[0][0] = true, qu[0][cnt... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4005;
const int MAXK = 4005;
const int MAXT = 86400;
int n, k;
int dp[2][MAXK];
inline int getEndTime(int right, int a, int b) { return max(right, a) + b; }
int main() {
int a, b;
while (~scanf("%d%d", &n, &k)) {
if (n == k) {
printf("%d\n", M... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2002;
int n, l[MAX], r[MAX];
string a, b;
int solve(int d) {
int last = n-1;
while(!(b[last] - '0')) --last;
for(int i = 0; i < n; i++) {
if(b[i]-'0') last = i;
l[i] = min(d, -((i+n-last) % n));
}
last = 0;
while(!(b[last] - '0')) ++last;
for(in... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e8;
int main(){
int Q; cin >> Q;
for(int query = 0; query<Q; query++){
string S, T; cin >> S >> T;
//dp[i][j]: S[i],T[j]まででの最長共通部分列
vector<vector<int>> dp(1010, vector<int>(1010, 0));
for(int i=0; i<S.length(); i++){
for(... | 0 |
#include <bits/stdc++.h>
using namespace std;
string s,ans;
int n,num,now;
int csize[10]={0,5,3,3,3,3,3,4,3,4};
char btn[10][5]={
{'-','-','-','-','-'},
{'.',',','!','?',' '},
{'a','b','c','-','-'},
{'d','e','f','-','-'},
{'g','h','i','-','-'},
{'j','k','l','-','-'},
{'m','n','o','-','-'},
{'p','q','r'... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool isprime(int n) {
if (n < 2) return false;
for (int i = 2; i * i <= n; i++)
if (n % i == 0) return false;
return true;
}
int main() {
int n;
cin >> n;
if (isprime(n))
cout << "1" << endl;
else if (n % 2 == 0)
cout << "2" << endl;
else if (isp... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long p[1000100], h[1000100], g[1000100], ans;
int main() {
int m, n, x, y;
cin >> n >> m;
for (int i = 0; i <= n; i++) p[i] = (i ? p[i - 1] * 7 : 1);
while (m--) {
scanf("%d%d", &x, &y);
h[x] += p[y];
h[y] += p[x];
}
for (int i = 1; i <= n; i++)... | 3 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
string s;
cin >> s;
long long n = s.size();
vector<vector<long long> > p(4, vector<long long>(4, 0));
for (long long i = 0; i < n; ++i) {
if (s[i] == '0') {
if (p[2][0] == 0) {
cout << "3 1\n";
p[2][0] = 1;
} else {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long T, n, ans, am, bm;
long long al[120], bl[120];
long long ad[120], bd[120];
int main() {
cin >> T;
while (T) {
T--;
cin >> n;
ans = 0;
am = 1e13 + 20, bm = 1e13 + 20;
for (int i = 1; i <= n; i++) {
cin >> al[i];
am = min(am, al[i... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long a1, a2, b1, b2, c1, c2;
long long flag = 0;
long long check(long long x, long long y) {
x -= b1, y -= b2;
long long dis = c1 * c1 + c2 * c2;
if (!dis) return !x && !y;
return !((c1 * x + c2 * y) % dis) && !((c1 * y - c2 * x) % dis);
}
signed main() {
cin... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int k, n = s.length();
cin >> k;
string a[k];
for (int i = 0; i < k; i++) {
cin >> a[i];
}
int ans = 0;
for (int i = 0; i < k; i++) {
int temp = 0, temp1 = 0;
for (int j = 0; j < n; j++) {
if (s[j] == a[i]... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<ld, ld>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<str>;
using vpi = ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
const int N = 1e6 + 10;
bool present[2010];
bool vis[2010];
queue<pair<int, int> > q;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, k;
cin >> n >> k;
memset(vis, 0, sizeof(vi... | 3 |
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
using namespace std;
#define NODE (128)
#define INF (1 << 30)
#define SHOP (6)
int cost[NODE][NODE];
int v[1 << (SHOP)][NODE];
int V;
int m, n, k, d;
int cake[SHOP];
typedef struct{
int pos, val, bit;
} State;
bool opera... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct range_t {
int rmin, rmax;
range_t() {}
range_t(int rmin, int rmax) : rmin(rmin), rmax(rmax) {}
inline int size() { return rmax - rmin + 1; }
};
struct edge_t {
int from, to;
range_t range;
edge_t() {}
edge_t(int from, int to, range_t range) : from(fro... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<int> min_factor(1010);
void seive() {
for (int i = 1; i <= 1005; i++) min_factor[i] = i;
for (int i = 2; i * i <= 1005; i++) {
if (min_factor[i] != i) continue;
for (int j = i * i; j < 1005; j += i) {
min_factor[j] = i;
}
}
}
int main() {
lo... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
;
long long h, w, i, j, p = 0;
cin >> h >> w;
char s[h][w];
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
cin >> s[i][j];
if (s[i][j] == '*') {
p++;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n, r = 0;
cin >> n;
for (int i = 0; i < n; i++) {
char c;
cin >> c;
if (c == '(') {
r++;
cout << r % 2;
} else {
cout << r % 2;
r--;
}
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int ans;
int main() {
int a[101010];
int b, c;
cin >> b >> c;
for (int i = 1; i <= b; ++i) {
cin >> a[i];
}
for (int i = 1; i <= b; ++i) {
if (a[i] > c)
ans += 2;
else if (a[i] <= c)
ans++;
}
cout << ans;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 200;
const int mod = 1e9 + 7;
int n, m, s, k, a[N];
int l[N], r[N];
int sum[N];
vector<int> g[1505];
int dp[1505][1505];
vector<pair<int, int> > f[1505];
inline int check(int x) {
for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + (a[i] <= x);
for (i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long arr[n];
for (long long i = 0; i < n; ++i) cin >> arr[i];
long long max_index = 0, digi_add = a... | 1 |
#include <bits/stdc++.h>
using namespace std;
int cnt = 0;
long long read() {
long long f = 1, x = 0;
char ss = getchar();
while (ss < '0' || ss > '9') {
if (ss == '-') f = -1;
ss = getchar();
}
while (ss >= '0' && ss <= '9') {
x = x * 10 + ss - '0';
ss = getchar();
}
return f * x;
}
long ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string a;
cin >> a;
bool flag;
string poke[8] = {"vaporeon", "jolteon", "flareon", "espeon",
"umbreon", "leafeon", "glaceon", "sylveon"};
for (int j = 0; j < 8; j++) {
if (poke[j].size() == n) {
flag... | 1 |
#include<stdio.h>
#include <map>
int main(){
int n,a,s,t,w,i;
for(;scanf("%d",&n),n;puts(!a?"Yes":"No")){
w=a=0;
std::multimap<int,int> m;
for(i=n;i--;m.insert(std::pair<int,int>(s,t)))
scanf("%d%d",&t,&s);
for(std::multimap<int,int>::iterator i=m.begin();i!=m.end();++i){
w+=i->second;
i->firs... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
for (int i = 0; i < q; i++) {
long long l, r, sum;
cin >> l >> r;
if (l == r)
sum = l * pow(-1, l);
else {
if (l == 1) {
sum = (r * pow(-1, r + 2) - (r + 1) * pow(-1, r + 1) + -1) / 4;
} else {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 20;
int H, W;
char board[MAXN][MAXN + 1];
void init() {
scanf("%d%d", &H, &W);
for (int i = 0; i < H; ++i) {
scanf(" %s ", board[i]);
}
}
int grundy[2 * MAXN + 1][2 * MAXN + 1][2 * MAXN + 1][2 * MAXN + 1][2];
bool visited[2 * MAXN + 1][2 * MAXN + ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n;
cin >> k;
int l, r;
int x = 0;
for (int i = 1; i <= n; i++) {
cin >> l >> r;
x = x + (r - l + 1);
}
int m;
m = x % k;
int moves;
if (m == 0)
moves = 0;
else
moves = k - m;
cout << moves << endl;
re... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int S = 1500;
struct bigint {
char d[S];
bigint() { memset(d, 0, sizeof(d)); }
void normalize() {
int r = 0;
for (int i = 0; i < S; ++i) {
d[i] += r;
r = d[i] / 10;
d[i] %= 10;
}
}
void output() {
int first = 0;
for (int... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
inline int read() {
int ret = 0, sgn = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') sgn = -1;
ch = getchar();
}... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, MOD = 1000000007, a[100001], q1[100001], q2[100001], fail[100001],
found[100001];
string s, t;
void kmp() {
int i, j, k;
j = fail[0] = -1;
for (i = 1; i <= m; i++) {
while (j >= 0 and t[j] != t[i - 1]) j = fail[j];
fail[i] = j + 1;
j++;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
string d;
cin >> d;
bool f = true;
for (int i = 0; i < d.size(); i++) {
if (d[i] == '0') {
d.erase(i, 1);
f = false;
break;
}
}
if (f) {
d.erase(0, 1);
}
cout << d << endl;
return EXIT_SUCCES... | 3 |
// 基本テンプレート
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#in... | 0 |
#include<iostream>
using namespace std;
int main()
{
int h, r;
cin >> h >> r;
if( h + r == 0 )
cout << 0 << endl;
else if( h + r > 0 )
cout << 1 << endl;
else
cout << -1 << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 150005;
string str;
int solve(int l, int r, char t) {
if (l >= r) return str[l] != t;
int mid = l + r >> 1;
int res = 0;
int res1 = solve(l, mid, (char)(t + 1));
int res2 = solve(mid + 1, r, (char)(t + 1));
int cnt = 0;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int N;
struct Node {
int a, len, l, r;
Node(int a = 0, int len = 0, int l = 0, int r = 0)
: a(a), len(len), l(l), r(r) {}
bool operator<(const Node& n1) const { return a < n1.a; }
} n[305];
int c[305];
int dp[305][305];
int main() {
cin >> N;
int top = 0;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
cin >> S;
for(int i = 0; i < S.size(); i++){
if((i % 2 == 0 && S[i] == 'L') || (i % 2 == 1 && S[i] == 'R')){
printf("No\n");
return 0;
}
}
printf("Yes\n");
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int parition(vector<pair<int, int>> &song_size, int low, int high) {
int pivot = song_size[high].first - song_size[high].second;
int i = low - 1;
for (int j = low; j <= high - 1; j++) {
if (song_size[j].first - song_size[j].second >
song_size[high].first -... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int N;
cin >> N;
int A, cnt = 0;
while (cin >> A) if (A % 2) cnt++;
cout << (!(cnt % 2) ? "YES" : "NO") << "\n";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t;
cin >> t;
while(t--){
int n;
cin >> n;
int a[n];
for(int i=0;i<n;i++){
cin >> a[i];
}
sort(a,a+n);
int ls=a[n-1];
int temp,count=0,max... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const vector<int> vec(3, -1);
vector<vector<int>> trie(1, vec);
vector<int> cnt(1, 0);
void add() {
string s;
cin >> s;
int v = 0, n = s.size();
for (int i = 0; i < n; i++) {
int c = s[i] - 'a';
if (trie[v][c] == -1) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, count_of_0 = 0, idx1 = 1, idx2 = 1;
cin >> n;
vector<int> bal(n + 1, 0);
vector<int> balance(n + 1);
vector<int> prefix_count_1(n + 1, 0);
vector<int> prefix_count_2(n + 1, 0);
vector<int> vector_of_1;
vector<int> vector_of_0 = {0};
int... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
const long long N = 3e3 + 7;
vector<long long> ad[N];
long long n, m;
long long a[N];
long long dp[N][N];
long long f[N][N];
long long g[N], t[N], sz[N];
void get(long long v, long long p) {
sz[v] = 1;
f[v][1] = a[v];
for (auto u : ad[v])
if... | 4 |
#include<bits/stdc++.h>
using namespace std;
bool parse_string(string cur){
int L = 0 ,R = cur.length()-1;
int ptr = cur.length()-1;
while(L<R){
char alphabet = ('a'+(ptr--));
//bacout<<alphabet<<endl;
if(alphabet==cur[R])R--;
else if(alphabet==cur[L])L++;
else
return false... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,x,t;
cin>>n>>x>>t;
n = ceil(n/double(x));
cout << n*t;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
template <class t>
inline t read(t &x) {
char c = getchar();
bool f = 0;
x = 0;
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
if (f) x = -x;
return x;
}
template <class t>
inline void wr... | 6 |
#include<bits/stdc++.h>
#define N 100
#define M 26
using namespace std;
string s;
int p,len;
string bnf(bool rev){
string res;
int cnt=0;
while(p!=len){
if(s[p]=='+')p++,cnt++;
if(s[p]=='-')p++,cnt--;
if('A'<=s[p]&&s[p]<='Z')
res+=((s[p++]+cnt+M*N)-'A')%M+'A',cnt=0;
if(s[p]=='?')res+=s[p++... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool isprime(long long n) {
if (n == 2) return true;
if (n < 2 || n % 2 == 0) return false;
for (int i = 3; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.... | 1 |
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
long long n;
int ans;
int main()
{
scanf("%lld",&n);
n++;
while(n>=10)
{
ans+=9;
n/=10;
}
ans+=n-1;
printf("%d",ans);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void smax(T &x, T y) {
x = max((x), (y));
}
template <class T>
inline void smin(T &x, T y) {
x = min((x), (y));
}
inline void sc(long long &x) { cin >> x; }
void sc(char &x) { scanf("%c", &x); }
void sc(long long &x, long long &y) {
sc(x);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
char a[N][N];
int T, n, m, id[N][N];
int head[N * N], ver[N * N << 1], Next[N * N << 1], tot;
int deg[N * N], dp[N * N];
pair<int, int> sta[N * N];
queue<int> q;
inline void add(int x, int y) {
deg[y]++;
ver[++tot] = y;
Next[tot] = head[x];
head[... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
long long mod(long long x) { return ((x % M + M) % M); }
long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }
long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }
long long modPow(long long a, long long b) {
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long mcm(long long a, long long b) { return (a * b) / gcd(a, b); }
bool comp(long long a, long long b) { return a > b; }
void solve() {
int n;
cin >> n;
vector<int> a(n);
vector<int>... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct Matrix {
int a[6][6];
int* operator[](int x) { return a[x]; }
} m[800005];
int n, q, a[200005];
Matrix init(int x) {
Matrix ans;
for (int i = 1; i <= 5; i++)
for (int j = 1; j <= 5; j++) ans[i][j] = 1000000000;
for (int i = 1; i <= 5; i++) ans[i][i] = 0... | 5 |
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
using namespace std;
int w,h;
char inpMap[51][51]={'0'},ctemp;
const int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
void dfs(int y,int x,char moji){
for(int i=0;i<4;i++){
int nx=x+dx[i];
int ny=y+d... | 0 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int n = 0;
bool b = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') b = 1;
c = getchar();
}
while (c >= '0' && c <= '9') {
n = (n << 1) + (n << 3) + (c ^ 48);
c = getchar();
}
return b ? -n : n;
}
const int N = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
using std::cin;
using std::cout;
long long MOD = 998244353;
int main() {
long long x;
cin >> x;
long long m = 1000000;
vector<pair<long long, long long> > sets;
for (long long i = 1; i < 2000005; i++) {
long long s = 6 * x + i * i * i - i;
m = (3 * i + 3) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
... | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.