solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int get() {
int t;
cin >> t;
string s;
for (int i = 0; i < t; i++) {
cin >> s;
}
return t;
}
int main() {
while (1) {
cout << "next 0 1" << endl;
get();
cout << "next 0" << endl;
if (get() != 3) break;
}
while (1) {
cout << "next 0 ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 2;
const int max_sqr = 600;
const int inf = 1e9;
int a[maxn];
int b[maxn];
int c[maxn];
int q[max_sqr][max_sqr];
int uk[max_sqr];
int n, block_sz, cnt_block;
int MOD;
void re_build_block_1(int i) {
int st = i * block_sz;
for (int j = 0; j < block_... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
int i, j;
for (i = 0; i < str.size() - 1; ++i) {
if (str[i] == '0') {
for (int j = i + 1; j < str.size(); ++j) {
cout << str[j];
}
return 0;
} else {
cout << str[i];
}
}
return 0;
}... | 3 |
#include<iostream>
#include<vector>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<cassert>
using namespace std;
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
struct Point;
typedef Point Vector;
typedef vector<Point> Polygon;
struct Circle;
struct Segment;
typedef Segment Line;
doub... | 0 |
#include<iostream>
int main(){std::string s;std::cin>>s;s[3]=56;std::cout<<s;} | 0 |
//hinagata.cpp
/*includes*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <numeric>
#include <iomanip>
#include <limits>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(int i=0;i<... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y, h, m, counter = 1;
vector<int> v;
cin >> n;
if (n == 1) {
cin >> h >> m;
cout << counter << endl;
} else {
for (int i = 0; i < n; i++) {
cin >> h >> m;
if (i == 0) {
x = h;
y = m;
} else if (i... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m;
vector<int> lalal[N];
vector<int> a[N], b[N];
int fx[4] = {-1, 0, 0, 1};
int fy[4] = {0, -1, 1, 0};
bool ok[N];
bool check(int o, int x, int y) {
if (x <= 0 || y <= 0) return false;
int size = lalal[o].size();
for (int u = 0; u < size; ... | 4 |
/*
Problem : https://atcoder.jp/contests/yahoo-procon2019-qual/tasks/yahoo_procon2019_qual_f
Algorithm : dp
Status : AC
*/
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
con... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,M;
cin>>N>>M;
int ans=pow(2,M)*(100*N+1800*M);
cout<<ans<<endl;
} | 0 |
#include <bits/stdc++.h>
int n, m, a[1000006], b[1000006], pin, sd;
bool u[1000006], flag;
inline int read() {
int n = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
n = n * 10 + c - '0';
c = getchar();
}
ret... | 2 |
#include <bits/stdc++.h>
int main() {
int t;
int i, j, k;
int flag;
long long x1, x2, x3, x4, x, y;
int ans[55][55];
scanf("%d", &t);
while (t--) {
scanf("%lld%lld%lld%lld", &x1, &x2, &x3, &x4);
x = x3 - x1;
y = x4 - x2;
printf("%lld\n", x * y + 1);
}
return 0;
}
| 3 |
#include <iostream>
#include <queue>
#include <vector>
#include <utility>
using namespace std;
long long f(vector<pair<int,int>> a){
priority_queue<int> que;
int size=a.size();
vector<vector<int>> in(size+1);
for(auto p: a){
if(p.first>=size){
que.push(p.second);
}else{
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int k, n;
while (cin >> k >> n) {
set<long long> num;
for (int i = 1; i <= sqrt(k); i++) {
if (k % i == 0) {
num.insert(i);
num.insert(k / i);
}
}
if (n > num.size())
cout << -1 << endl;
else {... | 1 |
#include <iostream>
using namespace std;
const int INF = 1000000000;
int main()
{
while(true){
int n, m;
cin >> n >> m;
if(n==0 && m==0)
break;
int C[100][100];
int T[100][100];
for(int i=0; i<m; i++){
for(int j=0; j<m; j++){
if(i==j){
C[i][j] = T[i][j] = 0;
}
else{
C[i][j] ... | 0 |
#include <bits/stdc++.h>
using namespace std;
char A[4][102];
int n;
void Solve() {
scanf("%d", &n);
for (int i = 0; i < 2; ++i) {
A[i][0] = 'x';
}
char ch = 'a';
for (int c = 1; c < n; c += 2) {
if (c + 1 < n) {
A[0][c] = A[0][c + 1] = ch;
A[1][c] = A[1][c + 1] = 'a' + 'b' - ch;
ch ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int sum[100010];
int main() {
int n;
long long int d, a, b;
scanf("%d %lld", &n, &d);
vector<pair<long long int, long long int>> p;
for (int i = 0; i < n; i++) {
scanf("%lld %lld", &a, &b);
p.push_back(make_pair(a, b));
}
sort(p.begin(), p.en... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAX = 1e5 + 5;
double x[MAX], y[MAX];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
double ret = 1e18;
for (int i = 0; i < n; i++) {
double den = sqrt(((x[i] - x[(i + 2) % n]) * (x[i] - x[(i +... | 2 |
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,in... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool isprime(int n) {
for (int i = 2; i * i <= n; i++)
if (n % i == 0) return false;
return true;
}
int main() {
int n, m = 0;
cin >> n;
for (int i = 0, x; i < n; i++) {
cin >> x;
m = max(x, m);
}
m > 25 ? cout << m - 25 : cout << 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
return x > 0 ? x : -x;
}
int n;
int m;
vector<pair<int, int> > v[100000];
int main() {
scanf("%d", &n);
printf("%d\n", n - 1);
for (int i = 0; i < n - 1; i++) {
int a, b;
scanf("%d%d", &a, &b);
a--;
b--;
v[a].push_... | 4 |
#include <bits/stdc++.h>
using namespace std;
string s, ans;
vector<pair<int, int> > seg;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> s;
reverse(s.begin(), s.end());
int n = s.size(), cntz = 0, cnto = 0, ze = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0')
cntz++, ze++, a... | 4 |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int MAX = 600600;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i-1] * i % MOD;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, m, n, a1[10], a2[10], pos[10];
cin >> n >> m;
for (i = 0; i < n; i++) cin >> a1[i];
for (j = 0; j < m; j++) cin >> a2[j];
int count;
for (i = 0; i < m; i++) {
count = 0;
for (j = 0; j < n; j++) {
if (a1[j] == a2[i]) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long arr[200009];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
long long x = 0;
for (int i = 0; i < n; i++) {
cout << arr[i] + x << " ";
x = max(x, arr[i] + x);
}
cout << endl;
}
| 2 |
#include <bits/stdc++.h>
int main() {
int a, b, c, d;
scanf("%d%d%d%d ", &a, &b, &c, &d);
int s1 = 3 * a / 10;
int s2 = 3 * b / 10;
int n1 = a - a / 250 * c;
int n2 = b - b / 250 * d;
int p1 = s1;
if (s1 < n1)
p1 = n1;
else
p1 = s1;
int p2 = s2;
if (s2 < n2)
p2 = n2;
else
p2 = s2... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433832795;
const long double eps = 0.000000001;
const int INF = 1E9;
const int MAXN = 210000;
int n, k, s, m;
bool fail;
set<pair<int, int> > cur;
pair<int, int> cnt, c2;
vector<pair<int, int> > ans, nxt;
int main() {
cin >> ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int arr[1000005];
int main() {
int n, q, i, j, d, diagnolSum, arr[1005];
scanf("%d", &n);
diagnolSum = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &d);
if (i == j) {
arr[i] = d;
diagnolSum += d;
}
}
... | 3 |
#include <bits/stdc++.h>
const long long int N = 300001;
using namespace std;
long long int f(long long int n) {
if (n == 1) {
return 1;
}
long long int ans = n;
for (long long int i = 2; i * i <= n; i++) {
if (n % i == 0) {
ans /= i;
ans *= (i - 1);
while (n % i == 0) {
n /= i... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> arr;
int n, k;
long long sum[5500];
double mx = -1e9;
int main() {
cin >> n >> k;
for (int x, i = 1; i <= n; i++) {
cin >> x;
arr.push_back(x);
sum[i] = sum[i - 1] + x;
}
for (int i = 1; i <= n; i++) {
for (int j = i + k - 1; j <= n; j++)... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1000005;
const long long maxv = 750000000000LL;
long long n, q;
long long val[maxn];
long long test(long long limit) {
priority_queue<long long> pq;
long long start = 0LL;
long long use = 0;
for (long long i = 0; i < n; i++) {
pq.push(-val... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chkmin(T &x, T y) {
return x > y ? x = y, 1 : 0;
}
template <typename T>
bool chkmax(T &x, T y) {
return x < y ? x = y, 1 : 0;
}
int readint() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f =... | 6 |
#include<bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}init;
typedef long long LL;
struct edge{
int flow,to,rev;
};
typedef vector<edge> E;
typedef vector<E> FlowGraph;
void addedge(FlowGraph &g,int from,int to,int f){
int a=g[from].size();
int b=g[to].siz... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m[N];
int main() {
scanf("%d", &n);
long long sum = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", m + i);
sum += m[i];
}
long long cap = sum % n;
long long res = sum / n + (cap != 0);
long long sec = 0;
for (int i = 0; i <... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 10;
int n;
int a[N];
int mex[N];
map<int, int> sg;
void solve(long long x) {
if (sg.count(x)) return;
vector<int> mex(30, 0);
for (int i = 0; x >> i; ++i) {
long long nx = ((x >> (i + 1)) | (x & ((1 << i) - 1)));
solve(nx);
mex[sg[nx]] ... | 3 |
#include <bits/stdc++.h>
using namespace std;
void ff1(int arr[], int n, int mx) {
int i;
for (i = 0; i < n; i++) arr[i] = mx - arr[i];
}
void ff2(int arr[], int n, int mx) {
int i, mx1 = 0;
for (i = 0; i < n; i++) arr[i] = mx - arr[i], mx1 = max(mx1, arr[i]);
for (i = 0; i < n; i++) arr[i] = mx1 - arr[i];
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
#define for_(i,a,b) for(int i=a;i<b;++i)
typedef long long lint;
int H, W, dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
lint L;
string grid[110], dir = "NESW";
int visit[110][110][4], seq[41000];
bool able(int x, int y) {
if (x < 0 || x >= W || y < 0 || y >= H) r... | 0 |
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define DEB 0
#define all(x) x.begin(), x.end()
//max:2192
unsigned short int dp[5][32770];
int main(){
unsigned short int i,j,k;
int n;
for(i=1; i*i<(... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,n;
cin >> a >> b >> n;
cout << n / 1000 * min(a, 2 * b) + (n % 1000 > 500 ? min(a, 2 * b) : n % 1000 == 0 ? 0 : min(a, b)) << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int s, c, b;
s = floor(sqrt(n));
c = floor(cbrt(n));
b = floor(cbrt(sqrt(n)));
cout << (s + c - b) << endl;
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
double EPS=1e-10;
int p,q,a,n;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, a[N], m, ans[N];
vector<int> pref[N], suf[N];
inline void Add(vector<int> &bas, int val) {
for (auto it : bas) {
val = min(val, (val ^ it));
}
if (!val) {
return;
}
for (auto &it : bas) {
it = min(it, (it ^ val));
}
ba... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 8;
const int MAXR = 1;
const int MAXC = 1;
const int INF = (int)1e9;
priority_queue<int, vector<int>, greater<int>> q1;
priority_queue<int, vector<int>, less<int>> q2;
int arr[MAXN];
map<int, int> m1;
map<string, int> m2;
vector<pair<string, pair<int, int>>... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 555555;
int mn[MAX_N << 2];
int a[MAX_N], fa[MAX_N][18], p[MAX_N], n, N, L[MAX_N];
int query(int x, int l, int r, int f, int t) {
if (f <= l && r <= t) {
return mn[x];
}
int mid = (l + r) >> 1;
int ret = 0;
if (f <= mid) ret = query((x << 1),... | 2 |
#include <bits/stdc++.h>
using namespace std;
int MAXCOL;
int MAXROW;
vector<pair<int, int>> getnei(int row, int col) {
vector<pair<int, int>> ans;
if (row > 0) {
ans.push_back({row - 1, col});
}
if (row <= MAXROW - 1) {
ans.push_back({row + 1, col});
}
if (col > 0) {
ans.push_back({row, col - 1... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n;
cin >> n;
vector<int> arr(n);
vector<int> aux(n, 0);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int id = 0;
sort(arr.begin(), arr.end());
for (int i = 0; i < s.length() / 2; i++) {
while (id < n && ar... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string t = "";
char c = s[s.length() - 1];
t += c;
for (int i = s.length() - 2; i >= 0; i--) {
if (t[0] <= s[i]) t = s[i] + t;
}
cout << t;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a1, a2, a3, a4, a5, a6, d;
cin >> a1 >> a2 >> a3 >> a4 >> a5 >> a6;
d = pow(a1 + a2 + a3, 2) - pow(a1, 2) - pow(a3, 2) - pow(a5, 2);
cout << d;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int c1, c2, c3, c4, c5, sum = 0;
cin >> c1 >> c2 >> c3 >> c4 >> c5;
sum = c1 + c2 + c3 + c4 + c5;
if (sum % 5 == 0 && sum != 0)
cout << sum / 5 << endl;
else
cout << -1 << endl;
ret... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct R {
long long n, d;
R(long long l_n, long long l_d) {
n = l_n;
d = l_d;
}
};
bool smaller(R r1, R r2) { return r1.n * r2.d < r1.d * r2.n; }
int main() {
int n;
cin >> n;
R s1(100000000, 1), s2(0, 1);
for (int i = 1; i <= n; i++) {
int x;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m, x, y, ans, i, j;
cin >> n >> m;
long long int dp[100005];
vector<vector<long long int> > adj(n + 1);
for (i = 0; i < m; i++) {
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
dp[1] = 1;
for (i = 2; i <=... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int inf = (1 << 30) - 1;
const ll INF = (1LL << 60) - 1;
template <typename T>
bool chmax(T &x, const T &y) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T min(T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
T max(T a, T b, T c) {
return max(a, max(b, c));
}
int n, a[55], p[55];
int main() {
scanf("%d", &n);
for (int i = (1); i <= (n); ++i) {
for (int j = (1); j <= (n); ++j) sca... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long M = 1000000000 + 7;
long long power(long long x, long long n) {
long long result = 1;
while (n > 0) {
if (n % 2 == 1) result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
int main() {
long long n, x;
cin >> x >> n;
ve... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
namespace ywy {
int ch[2111][2], fa[2111], gpt = 1, size[2111];
unsigned char bv[2111];
int tot = 0, zx;
void afs(int pt) {
if (bv[pt] || !pt) return;
if (!ch[pt][0] && !ch[pt][1]) {
tot++... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
const ll inf = (1e18);
const ll mod = 1000000007;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }
struct __... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200500;
int d, n, m;
pair<int, int> x[N];
struct Cmp {
bool operator()(int a, int b) const {
if (x[a].second != x[b].second) return x[a].second < x[b].second;
return a < b;
}
};
set<int, Cmp> tanks;
void solve() {
scanf("%d%d%d", &d, &n, &m);
f... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int X = 0, w = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') w = -1;
c = getchar();
}
while (c >= '0' && c <= '9') X = X * 10 + c - '0', c = getchar();
return X * w;
}
const int N = 100 + 10;
inline int id(int x, i... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void _R(T &x) {
cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <clas... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("-ffloat-store")
using namespace std;
clock_t time_p = clock();
void aryanc403() {}
const long long int INF = 0xFFFFFFFFFFFFFFFL;
long long int seed;
mt19937 rng(seed... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
int main() {
double a, b, c, d, tmp, ans, tt;
while (~scanf("%lf%lf%lf%lf", &a, &b, &c, &d)) {
tmp = (1.0 - a / b) * (1.0 - c / d);
tt = tmp * a / b;
ans = a / b;
while (tt > EPS) {
ans += tt;
tt *= tmp;
}
pri... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long int i, ct = 0;
string s, g, p, prev;
cin >> s;
set<string> s1, s2;
s1.insert("0");
s1.insert("4");
s1.insert("8");
s2.insert("00");
s2.insert("04");
s2.insert("08");
for (i = 12; i <= 100;... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
int xx[100100];
while (scanf("%d", &n) != EOF) {
int temp;
int max = 0;
int min = 20000;
memset(xx, 0, sizeof(xx));
map<int, int> he;
he.clear();
for (i = 0; i < n; i++) {
scanf("%d", &xx[i]);
if (xx[i] >=... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const int MOD = 1e9 + 7;
const double PI = 3.141592653589793238460;
long long power(long long a, long long b) {
long long res = 1;
if (a == 0) return 0;
if (a == 1) return 1;
for (; b > 0; b >>= 1) {
if (b & 1) res = (res * a);
if (res... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
int n = 2 * (a - 1), m = 2;
int d[2] = {1, 2};
if (a == 1) n = m = 1;
cout << n << " " << m << endl;
for (int i = 0; i < m; i++) cout << d[i] << (i == m - 1 ? "\n" : " ");
}
| 1 |
#include <cstdio>
#include <math.h>
using namespace std;
typedef struct vec2 {
double x, y;
vec2(){}
vec2(int a, int b) {
x = a;
y = b;
}
vec2(double a, double b) {
x = a;
y = b;
}
vec2 operator*(double l) {
return{ x*l,y*l };
}
vec2 operator-(const vec2 &r) {
return{ x - r.x,y - r.y };
}
vec2 o... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long tests;
long long n, a[1000256], b[1000256], cnt, ans;
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
if (a[i] - a[i - 1] < cnt) {
cnt += b[i];
cnt -= a[i] - a[i - 1];
} else
cnt = b[i];
if (ans < ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k = 0;
string s, t;
cin >> n;
cin >> s >> t;
vector<int> vect;
for (int i = 0; i < n; i++) {
if (s[i] == t[i])
continue;
else {
int flag = -1;
for (int j = i + 1; j < n; j++) {
if (s[j] == t[i]) {
f... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
string s;
cin >> s;
for (char ch = 'z'; ch >= 'a'; ch--) {
for (long long int i = 1; i < s.length(); i++) {
if (s[i] == ch && s[i - 1] + 1 == ch) s.erase(i, 1), i--;
}
for (long long int i = s.length() - 1;... | 3 |
#include <bits/stdc++.h>
using namespace std;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int32_t main() {
c_p_c();
long long x;
cin >> x;
while (x--) {
long long a, b;
cin >> a >> b;
if (a == b)
cout << 0 << '\n';
else if (b > a) {
if (a % 2 == 0 &&... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int visit[1000] = {
0,
};
int n;
int k = 0;
int i;
cin >> n;
int cnt = 0;
for (i = 0; i < n; i++) {
k = (k + i) % n;
if (visit[k] == 0) {
cnt++;
visit[k] = 1;
}
}
cout << (cnt == n ? "YES" : "NO") << endl;
ret... | 1 |
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int n,m;
cin>>n;
m=sqrt(n);
cout<<m*m;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int ask(int i, int j) {
printf("? %d %d\n", i, j);
fflush(stdout);
char c;
cin >> c;
if (c == '<')
return 1;
else if (c == '=')
return 2;
else
return 3;
}
void solve() {
scanf("%d", &n);
if (n == 1) {
printf("! 1 1\n");
fflush(st... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, k, s, t;
long long g[N];
struct Node {
int vol, p;
Node() {}
bool operator<(const Node &rhs) const {
return (vol == rhs.vol) ? p < rhs.p : vol < rhs.vol;
}
} seq[N];
bool judge(int cap) {
long long tot = 0;
for (int i = 1; i <= k... | 3 |
#include<iostream>
#include<string>
using namespace std;
int main()
{
int n, h, m, d, guest[3], ok[3];
char c;
string s[3] = { "lunch", "dinner", "midnight" };
while( cin >> n )
{
if( !n )
break;
guest[0] = guest[1] = guest[2] = 0;
ok[0] = ok[1] = ok[2] = 0;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int M = 100000 + 10;
const long long inf = 1e16;
int n, Q, s;
int mp[M];
vector<vector<long long> > T[M << 2];
long long d[M << 2];
bool vis[M << 2];
bool flag[M << 2];
bool leaf[M << 2];
bool flag2[M << 2];
priority_queue<vector<long long>, vector<vector<long long> >... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 250005;
const long long inf = 1e12;
struct Treap {
Treap *left, *right;
int val, key, size;
long long sum;
Treap(int val = 0)
: val(val), key(rand()), size(1), left(0), right(0), sum(val) {}
} * t[MX];
inline int nodeSize(Treap* T) { return T ? ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
srand(time(0));
auto print = [&](long long x, long long y) {
cout << x << " " << y;
exit(0);
};
long long n;
cin >> n;
if (n == 0) {
cout << "0 0";
r... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
vector<vector<int>> graph;
int child[N];
int level[N];
int dfs(int s) {
int ret = 0;
for (int i = 0; i < (int)graph[s].size(); i++) {
int v = graph[s][i];
level[v] = 1 + level[s];
ret += 1 + dfs(v);
}
return child[s] = ret;
}... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n;
cin >> n;
vector<long long> a(n);
for (long long &i : a) cin >> i;
cout << "1 1\n" << -a[0] << '\n';
a[0] = 0;
if (n == 1) {
cout << "1 1\n0\n1 1\n0\n";
return 0;
}
cout <<... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
double ma[100005], mb[100005], a[100005], b[100005], prep[100005], preq[100005];
double f(double x, double y) {
double tmp = (x - y + 1) * (x - y + 1) - 4 * x;
tmp = max(tmp, 0.0);
return sqrt(tmp);
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i+... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 412345;
const int MAXINT = 2047483098;
const long long int MOD = 1e9 + 7;
const int MAX = 1e4;
const long double pi = 2 * acosl(0);
const long double EPS = 1e-10;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
bool isPrime(long lo... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int pow_ar[26];
vector<long long int> primes;
long long int sieve[105];
long long int pascal_triangle[5005][5005];
long long int dx[] = {1, -1, 0, 0};
long long int dy[] = {0, 0, 1, -1};
long long int mod_pow(long long int n, long long int p, long long int mod) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 3e5 + 5;
long long sum[maxn], a[maxn];
long long qsm(long long x, long long b) {
long long base = x;
long long ans = 1;
while (b) {
if (b & 1) {
ans = ans * base % mod;
}
base = base * base % mod;
b... | 1 |
#include <bits/stdc++.h>
using namespace std;
int p[1000 + 5][1000 + 5];
char c[1000 + 5][1000 + 5];
vector<char> ans;
vector<pair<int, int> > pos;
vector<pair<char, int> > go;
int get_sum(int l1, int r1, int l2, int r2) {
if (l1 > l2) swap(l1, l2);
if (r1 > r2) swap(r1, r2);
return p[l2][r2] - p[l1 - 1][r2] - p[... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000007;
long long int inf = 1e15;
void scan(int &x);
long long int powermod(long long int _a, long long int _b, long long int _m) {
long long int _r = 1;
while (_b) {
if (_b % 2 == 1) _r = (_r * _a) % _m;
_b /= 2;
_a = (_a * _a) % _m;... | 3 |
#include<bits/stdc++.h>
using namespace std;
int main()
{long long i,j;
cin>>i;
cout<<1-i;}
| 0 |
#include <bits/stdc++.h>
const int MAX = 1123;
int p[MAX];
int main(void) {
int n, m, x, y, first, i, ans;
scanf("%d %d", &n, &m);
while (n--) {
scanf("%d %d", &x, &y);
for (i = x; i <= y; i++) p[i] = 1;
}
for (ans = 0, i = 1; i <= m; i++) ans += !p[i];
printf("%d\n", ans);
if (ans) {
for (fir... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
const int b = 130000;
int f[2*b+5], s[2*b+5], g[2*b+5], ans[N];
int n, mod;
void solve(){
for (int i = b; i <= 2 * b + 4; ++i) s[i]=1;
for (int i = 1; i <= n; ++i) {
int tmp = i * (i - 1) / 2;
for (int k = - tmp + b; k <= tmp +... | 5 |
#include<bits/stdc++.h>
using namespace std;
template<typename TP>inline void read(TP &tar)
{
TP ret=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){ret=ret*10+ch-'0';ch=getchar();}
tar=ret*f;
}
namespace RKK
{
const int N=200011;
struct sumireko{int to,ne;}e[N]... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
long long gcd(long long a, long long b) { re... | 4 |
#include <bits/stdc++.h>
int cmp(const void* a, const void* b) { return (*(int*)a - *(int*)b); }
int main() {
int q;
scanf("%d", &q);
while (q--) {
int n;
int cnt = 1;
int flag = 0;
int a[105] = {0};
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
qsort(a... | 1 |
#include <bits/stdc++.h>
using namespace std;
int dp[110], tmp[110], mod = 1e6 + 3, dir[200];
int n, w, h;
int main() {
long long sum = 1, x;
scanf("%d%d%d", &n, &w, &h);
dir[0] = 1;
for (int i = 1; i <= 150; i++) dir[i] = dir[i - 1] * h % mod;
queue<long long> q;
for (int i = 0; i < w; i++) q.push(0);
q.... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
long long int power(long long int x, long long int n) {
long long int result = 1;
while (n) {
if (n % 2 == 1) result = result * x;
n = n / 2;
x = x * x;
}
return result;... | 1 |
#include<stdio.h>
#include<algorithm>
using namespace std;
int s(int x,int y){
if(x<=y) return y-x;
else return x-y+2;
}
int main(){
int x,y;
scanf("%d %d",&x,&y);
printf("%d\n",min(s(x,y),min(s(-x,y)+1,min(s(x,-y)+1,s(-x,-y)+2))));
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream &operator<<(ostream &s, vector<T> &P) {
for (long long i = 0; i < P.size(); ++i) {
if (i > 0) {
s << " ";
}
s << P[i];
}
return s;
}
template <class T>
bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string t;
cin >> t;
int n = t.length();
string s = "", s1 = "", s2 = "";
int k = 0;
for (int i = 0; i < n; i++) {
if (t[i] != 'a') {
s2 = s2 + t[i];
}
}
if (s2.length() % 2 == 0) {
if (s2.substr(0, s2.length() / 2) ==
s... | 2 |
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;
bool prime(int n) {
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0)return false;
}
return n != 1... | 0 |
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#incl... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, x, y;
string f[100005], g[100005], t[100005];
map<string, int> m1, m2;
int u[100005];
vector<int> v1, v2, r1, r2;
vector<string> p1, p2;
void cty(int k) {
if (k <= x) {
if (v1.size()) {
int o = v1[v1.size() - 1];
int nex = m2[f[o]];
v1.pop_bac... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.