solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int d[200000], i;
long int n, a;
cin >> n;
a = n / 2;
if (1 == n % 2)
d[0] = 7;
else
d[0] = 1;
cout << d[0];
for (i = 1; i < a; i++) {
d[i] = 1;
cout << d[1];
}
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
long long max(long long a, long long b) { return (a > b) ? a : b; }
long long min(long long a, long long b) { return (a < b) ? a : b; }
void solve() {
vector<long long> v(5);
long long sum = 0;
for (long long ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int A, B;
inline int read() {
int ret = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -f;
ch = getchar();
}
while (ch <= '9' && ch >= '0') ret = ret * 10 + ch - '0', ch = getchar();
return ret * f;
}
int main() {
int ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long double pai = acos(-1.0L);
const long double eps = 1e-10;
const long long mod = 1e9 + 7;
const int MXN = 1e6 + 5;
vector<int> g[MXN], v;
int co[MXN];
int go[MXN];
void dfs(int now, int pr, int cg0, int cg1, int dis) {
if (dis % 2 == 0) {
if ((co[now] + cg1) ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e4 + 7;
long long expo(long long x, long long n, long long mod) {
long long res = 1LL;
while (n) {
if (n & 1) res = (res * x) % mod;
x = (x * x) % mod;
n = n / 2;
}
return res;
}
int main(int argc, char const *argv[]) {
ios_bas... | 5 |
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
int t[100][6];
int ans = 0;
bool remove(){
bool ret = 0;
rep(i,20)rep(j,4){
if(t[i][j] != 0 && t[i][j] == t[i][j+1] && t[i][j+1] == t[i][j+2]){
//cout << t[i][j] << " " << t[i][j+1] << endl;
for(int jj = j +... | 0 |
#include <bits/stdc++.h>
using namespace std;
char s1[105][101], s2[105][105], s3[105], s4[105];
int mm[105];
void change(char s[]) {
int l = strlen(s);
for (int i = 0; i < l; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') s[i] += 32;
}
}
int main() {
int i, j, t, k, n, z, flag;
char letter;
while (scanf("%d", ... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << '{';
string sep;
for (const auto &x : v) os << sep << x, sep = ", ";
return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
re... | 4 |
#include <bits/stdc++.h>
using namespace std;
ifstream file("input.txt");
int main() {
int n, m = 0;
string str;
cin >> n >> str;
for (int i = 0; i < n; i++) {
if (str[i] == '<')
m++;
else
break;
}
for (int i = n - 1; i >= 0; i--) {
if (str[i] == '>')
m++;
else
break;... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, j, l, p;
cin >> n >> m;
p = n;
int arr[m];
string s[n];
int k = 0;
for (i = 0; i < m; i++) {
arr[i] = 0;
}
while (p-- > 0) {
cin >> s[k];
for (i = 0; i < m; i++) {
arr[i] = arr[i] + (s[k][i] % 48);
}
k++;... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000005;
const long long INFLL = 1000000000000000002ll;
const long long MOD = 1000000007;
inline long long min(long long a, long long b, long long c) {
return min(min(a, b), c);
}
inline long long min(long long a, long long b, long long c, long long d) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0;
char ch = getchar();
bool positive = 1;
for (; ch < '0' || ch > '9'; ch = getchar())
if (ch == '-') positive = 0;
for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
return positive ? x : -x;
}
int N, M, a[405... | 4 |
#include <bits/stdc++.h>
const int MAXN = 150005;
const int INF = 1500000;
using namespace std;
int n, a[MAXN];
vector<int> v;
bool yes[MAXN];
int scan() {
int t = 0, m = 1;
char c;
c = getchar();
while ((c < '0' || c > '9') and c != '-') c = getchar();
if (c == '-') c = getchar(), m = -1;
while (c >= '0' &... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
using namespace std;
long long int t, n, u, x, y;
const long long int N = 100001;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
t = 1;
cin >> t;
while (t--) {
cin >> n;
long long int ans = -1;
if (n % 2... | 2 |
// #pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long int ll;
typedef unsigned long long ull;
#define int ll
typedef std::v... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void amin(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
if (x < y) x = y;
}
long long powmod(long long a, long long b) {
long long res = 1;
a %= 1000000007;
assert(b >= 0);... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
inline long long read() {
long long t = 0, f = 1;
char c = getchar();
while (... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &a) {
static char c;
int f = 0;
while (((c = getchar()) < '0' || c > '9') && (c != '-'))
;
if (c == '-') {
a = 0;
f = 1;
} else {
a = c - '0';
}
while ((c = getchar()) <= '9' && c >= '0') a = (a << 3) + (a ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long int t;
cin >> t;
while (t--) {
long long int n, m;
cin >> n >> m;
char arr[n][m];
for (long long int i = 0; i < n; i++) {
for (long long int j = 0; j < m; j++) {
cin >> arr[i][j];
}
}
long long int... | 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); }
int main() {
long long a, b, gc;
long long ga, gb, gcc;
cin >> a >> b;
gc = gcd(a, b);
gcc = a / gc * b;
ga = gcc / a;
gb = gcc / b;
if (a < b)
ga--;
else if (a > b)
gb-... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int A,B;
cin >> A >> B;
cout<<(A+B-1)/B<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
string a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < m - 1; j++) {
int f1 = 0, a1 = 0, c1 = 0, e1 = 0;
if (a[i][j] == 'f') f1++;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
int arr[3];
while (t--) {
cin >> arr[0] >> arr[1] >> arr[2];
sort(arr, arr + 3);
if (arr[0] + arr[1] >= arr[2] - 1)
cout << "Yes\n";
else
cout << "No\n";
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 998244353;
long long int fpow(long long int a, long long int k) {
long long int r = 1;
long long int t = a;
while (k) {
if (k & 1) {
r = r * t % MOD;
}
t = t * t % MOD;
k >>= 1;
}
return r;
}
int main() {
ios_base:... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char keyboard[100] = "qwertyuiopasdfghjkl;zxcvbnm,./";
char x[101];
char d;
cin >> d >> x;
if (d == 'L') {
for (int i = 0; i < strlen(x); i++) {
for (int j = 0; j < strlen(keyboard); j++) {
if (x[i] == keyboard[j]) {
cout <... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const int dx[6] = {1, -1, 0, 0, 0, 0};
const int dy[6] = {0, 0, 1, -1, 0, 0};
const int dz[6] = {0, 0, 0, 0, 1, -1};
template <typename T>
void chkmax(T &x, T y) {
x = max(x, y);
}
template <typename T>
void chkmin(T &x, T y) {
x = min(x, y);
}... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000000 + 1, mod = 1000000007;
int n;
long long dp[maxn] = {};
int main() {
int T;
scanf("%d", &T);
for (int i = 3; i < maxn; ++i)
dp[i] = (dp[i - 1] + dp[i - 2] * 2 + (!(i % 3) ? 4 : 0)) % mod;
while (T--) {
scanf("%d", &n);
printf("%d\... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct OP {
double flag;
int st, ed, lft;
OP() {}
OP(int a, int b, double c, int d) {
st = a;
ed = b;
flag = c;
lft = d;
}
};
struct node {
double P;
int lft, rht, flag;
void fun(double tmp) {
P *= tmp;
flag = 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
int add(int a, int b) { return a + b >= Mod ? a + b - Mod : a + b; }
int dec(int a, int b) { return a - b < 0 ? a - b + Mod : a - b; }
int mul(int a, int b) { return 1ll * a * b % Mod; }
void Add(int &a, int b) { a = add(a, b); }
void Dec(int &a, in... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
std::cerr... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct s {
int data;
int sum;
int xu;
} a[101];
bool cmp1(s a, s b) { return a.data < b.data; }
bool cmp2(s a, s b) { return a.xu < b.xu; }
int main() {
int n, w;
int sum_1 = 0, sum_2 = 0;
scanf("%d%d", &n, &w);
for (int i = 0; i < n; i++) {
scanf("%d", &a... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
int arr[n];
for (i = 0; i < n; i++) {
cin >> arr[i];
}
int o = sizeof(arr) / sizeof(arr[0]);
sort(arr, arr + o);
for (i = 0; i < n; i++) {
cout << arr[i] << endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << '\n';
err(++it, args...);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<long long, long long>, pair<long long, long long> > > vc;
long long n, dp[109][2009], path[109][2009];
long long maximum(long long ind, long long time) {
if (ind > n) return 0;
if (~dp[ind][time]) return dp[ind][time];
long long ret1 = maximum(ind + 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool zero(double x) { return fabs(x) <= 1e-8; }
int sign(double x) {
if (zero(x)) return 0;
if (x > 0) return 1;
return -1;
}
struct point {
double x, y;
double tht;
point(double xx = 0.0, double yy = 0.0) {
x = xx;
y = yy;
}
void input() { scanf("%l... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N=120;
int a[N];
int n,u,v;
int solve() {
bool allsame = true;
for (int i = 1; i < n; i++) {
if (abs(a[i]-a[i-1]) > 1) return 0;
if (a[i] != a[i-1]) allsame = false;
}
if (allsame) return min(2*v,u+v);
return min(u,v);
}
int... | 2 |
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <tuple>
#include <utility>
#include <queue>
using namespace std;
using AnsType = long long int;
const AnsType INF = 1LL << 60;
int pow3[10];
int get_digit(int val, int k) {
val /= pow3[k];
return val % 3;
}
str... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
return a < b ? (a = b, true) : false;
}
const int maxn = 2 * (int)1e5 + 1000;
int n, m, tot = 1, fa[maxn], vis[maxn], in[maxn], out[maxn], pa[maxn],... | 5 |
#include <bits/stdc++.h>
#define inf 100000000
using namespace std;
int main(){
int simen[200]={};
for(int i=0;i<200;i++)simen[i] = (i+1) * (i+2) * (i+3) / 6;
int dp[1000005], kisudp[1000005];
for(int i=0;i<1000005;i++){dp[i] = inf; kisudp[i] = inf;}
dp[0]=0;kisudp[0]=0;
for(int k=0;k<200;k++)for(int i=1;i... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool fs(T &x) {
int c = getchar();
int sgn = 1;
while (~c && c < '0' || c > '9') {
if (c == '-') sgn = -1;
c = getchar();
}
for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
x *= sgn;
return ~c;
}
in... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, a, b, i;
cin >> n >> m;
vector<pair<long long, long long> > v;
for (i = 0; i < n; i++) {
cin >> a >> b;
v.push_back({a, b});
}
if (v[0].first != 0) {
cout << "NO";
return 0;
}
long long start = 0, end = 0;
for (... | 1 |
#include <bits/stdc++.h>
using namespace std;
int N, D, A, B, Q, op, p, v;
int tree[2][200100], lo[200100], hi[200100];
void update(int *Tree, int p, int v) {
assert(p > 0);
while (p < 200100) {
Tree[p] += v;
p += p & -p;
}
}
int query(int *Tree, int p) {
int ret = 0;
while (p > 0) {
ret += Tree[p... | 3 |
#include<bits/stdc++.h>
using namespace std;
int a[2000][2000]={};
int main(){
int n,f;
//int a[2000][2000]={};
map<string,int> M;
map<int,string> MD;
set<string> S;
int c=0;
int count=0;
cin>>n>>f;
for(int i=0;i<n;i++){
int m;
cin>>m;
vector<string> st;
for(int t=0;t<m;t++){
str... | 0 |
#include<iostream>
#include<vector>
using namespace std;
const int N = 100000 ;
int size,
c,
l[N],
r[N],
b[2*N+1];
vector<int> vec[N];
void dfs(int v){
l[v] = ++c;
for(int i=0;i<vec[v].size();i++){
dfs(vec[v][i]);
}
r[v] = ++c;
}
void add(int i,int x){
while(i<=size){
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N;
cin >> N;
string s;
cin >> s;
if (N & 1)
cout << ":(";
else {
int flag = 0, g = 0, l = 0, r = 0;
for (int i = 0; i < N; i++) {
if (s[i] == '(')
l++;
e... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
string tostr(const T& t) {
ostringstream os;
os << t;
return os.str();
}
vector<string> G;
bool vis[15][15][15][15];
int dr[] = {2, -2, 2, -2};
int dc[] = {2, 2, -2, -2};
bool calc() {
memset(vis, false, sizeof vis);
int r1, c1, r2, c2;
r1 ... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct line {
long long m, y0;
line(long long y0 = 0, long long m = 0) : y0(y0), m(m) {}
};
struct ConvexHullTrick {
int pos = 0;
bool check(line a, line b, line c) {
return (a.y0 - b.y0) * (c.m - a.m) < (a.y0 - c.y0) * (b.m - a.m);
}
vector<line> H;
void ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int ans = pow(2, n / 2 + 1);
cout << ans - 2 << endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXS = 2e4;
int sizeL = MAXS, sizeR = MAXS;
bool vis[MAXS];
int par[MAXS];
vector<int> adj[MAXS];
bool match(int u) {
for (int v : adj[u]) {
if (vis[v]) continue;
vis[v] = true;
if (par[v] == -1 || match(par[v])) {
par[v] = u;
return true... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const long long int Inf = 1LL << 62;
unordered_map<int, int> cntup, cntlw, duplicate;
unordered_set<int> up, lw;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int x, y, n, need;
cin >> n;
need = n / 2... | 4 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <cstring>
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second
using namespace std;
typedef vecto... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int q;
cin >> q;
string prev;
cin >> prev;
q--;
set<string> s;
s.insert(prev);
bool ok = true;
while(q--)
{
string next;
cin >> next;
ok &= next.front() == prev.back();
ok &= (not s.count(next));
s.insert(next);
prev = next;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
char ans[11000][11000];
char a[10] = {"aeiou"};
int main() {
int k;
int flag = 0;
cin >> k;
for (int i = 5; i <= k; i++) {
if (k % i == 0 && k / i >= 5) {
flag = i;
break;
}
}
if (!flag) {
cout << "-1" << endl;
return 0;
}
int n =... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int h[N][N];
int f[N * N];
double dp[N * N];
pair<int, int> coord(int i) {
int r = i / N;
int c = i % N;
if (r & 1) c = N - c - 1;
return {r, c};
}
int getidx(int r, int c) {
if (r & 1) c = N - c - 1;
return N * r + c;
}
int main() {
ios::syn... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int maxm = 50;
int edge[maxm + 1][maxm + 1];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i) {
int u, v;
scanf("%d%d", &u, &v);
if (u <= maxm && v <= maxm) edge[u][v] = edge[v][u] = 1;
}
for (in... | 6 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int tx[]={0,0,1,-1};
const int ty[]={1,-1,0,0};
int getd(int a,int b,int x,int y){
return abs(a-x)+abs(b-y);
}
char getc(int &a,int &b,int d,int x,int y){
int Mn=2e9,op=-1;
for (int i=0;i<4;i++){
int xx=a+tx[i]*d,yy=b+ty[i]*d;
int dis=getd... | 0 |
#include <bits/stdc++.h>
using namespace std;
double dp[305][305][305];
double dish(int a,int b,int c,int n){
if(a<0 or b<0 or c<0)
return 0;
if(a==0 and b==0 and c==0)
dp[a][b][c]=0;
if(dp[a][b][c]==-1){
dp[a][b][c]=(a*dish(a-1,b+1,c,n)+b*dish(a,b-1,c+1,n)+c*dish(a,b,c-1,n)+n)/(a+b+c);
}
return dp[a][b][c];... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
for (int i = 0; i < s.size() / 2; i++)
if (s[i] != s[s.size() - i - 1]) {
cout << "NO";
return 0;
}
for (int i = 0; i < s.size(); i++)
if ((s[i] != 'A') && (s[i] != 'W') && (s[i] != 'T') && (s[i] != 'Y') &&
... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool divc[100001][318];
int sum[100001][318];
int n;
int x[100001], y[100001];
set<pair<int, int> > comp;
int main() {
memset(divc, 0, sizeof(divc));
memset(sum, 0, sizeof(sum));
comp.clear();
cin >> n;
for (int i = 0; i < (int)(n); i++) cin >> x[i + 1] >> y[i + 1... | 2 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:512000000")
template <class T>
T sqr(T a) {
return a * a;
}
int n;
vector<vector<int> > g;
int val[1 << 17];
bool was[1 << 17] = {0};
pair<long long, long long> dfs(int v) {
was[v] = 1;
long long d1 = 0, d2 = 0;
for (int i = 0; i < (i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 312345;
int n, mx, fa[maxn][20], dep[maxn];
vector<int> v1, v2;
inline int lca(int u, int v) {
if (dep[u] < dep[v]) swap(u, v);
int det = dep[u] - dep[v];
for (int i = 0; i < 20; ++i)
if (det >> i & 1) u = fa[u][i];
if (u == v) return u;
for (... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long sumofdigit(long long n) {
long long ans = 0;
while (n) {
ans += (n % 10);
n = n / 10;
}
return ans;
}
long long power(long long n, long long p) {
long long res = n;
for (long long i = 1; i < p; i++) {
res *= n;
}
return res;
}
int32_t m... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, s = 0, d = 0;
cin >> n;
vector<int> v;
for (int i = 0; i < n; i++) {
cin >> x;
v.push_back(x);
}
while (!v.empty()) {
if (v[0] >= v[v.size() - 1]) {
s += v[0];
v.erase(v.begin());
} else {
s += v[v.size() ... | 1 |
#include<bits/stdc++.h>
using namespace std;
struct block{
double xr;
double xl;
double g;
set<int> chil;
};
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int w,h;
int inde=1;
bool isrange(int i,int j){
return 0<=i && i<h && 0<=j && j<w;
}
void draw(int i,int j,char x,vector<string> &f,vector<vect... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct _ {
ios_base::Init i;
_() {
cin.sync_with_stdio(0);
cin.tie(0);
}
} _;
double a[500];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) cin >> a[i];
double ans = 0;
for (int i = 0; i < m; ++i) {
int from, to;
double x;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MN = 100005, note = 100;
int C[MN], W[MN], czy[MN], ile[MN];
priority_queue<pair<long long, int> > Q;
long long wynik;
int main() {
int n;
long long hajs;
scanf("%d%I64d", &n, &hajs);
for (int i = 1; i <= n; ++i) {
scanf("%d", &C[i]);
ile[i] = C[i]... | 5 |
#include <bits/stdc++.h>
using namespace std;
char grid[2010][2010];
bool vis[2010][2010];
int dx[] = {0, 0, 1, -1};
int dy[] = {-1, 1, 0, 0};
bool valid(int x, int y, int n, int m) {
if (x == n || y == m || x == -1 || y == -1 || vis[x][y] ||
grid[x][y] == '*') {
return 0;
}
return 1;
}
int main() {
i... | 4 |
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define IOS cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
using namespace std;
const int mod = 1e9+7;
int MSB(unsigned x){ //most significant bit-read IEEE 754
union { double a; int64_t b; };
a = x;
return (b >> 20) - 1023;
}
struct custom_hash {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<string, string> mp1, mp2;
map<string, string>::iterator it;
while (n--) {
string s1, s2;
cin >> s1 >> s2;
if (mp2.find(s1) == mp2.end()) {
mp1[s1] = s2;
mp2[s2] = s1;
} else {
string s3 = mp2[s1];... | 2 |
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<cstring>
#include<cstdio>
//#include<bits/stdc++.h>
using namespace std;
void work(){
int n,k;
cin>>n>>k;
int x=0;
for(int i=0;i<n;i++){
if(i==0)x=0;
else x=(i^(i-1));
printf("%d\n",x);
fflush(stdo... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
long long n;
cin >> n;
long long a[2][2] = {{3, 1}, {1, 3}};
long long r[2][2];
long long t[2][2];
r[0][0] = r[1][1] = 1;
r[1][0] = r[0][1] = 0;
while (n) {
if (n & 1) {
memset(t, 0, sizeof(t));
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int numeros[n + 1];
for (int i = 0; i < n; i++) {
int a;
cin >> a;
numeros[i] = a;
}
sort(numeros, numeros + n);
set<int> largo;
for (int i = 0; i < n; ++i) {
int l, m;
l = (abs(numeros[i] % k));
... | 1 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long tt;
cin >> tt;
while (tt--) {
long long n, k;
cin >> n;
vector<long long> a(n + 1);
map<long long, vector<long long>> mp;
map<long long, set<long long>> ans;
for (long long i = 1; i <= n; ++i) {
cin >> a[i];
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000 + 86;
long long x[MAXN], c[MAXN];
int main() {
int n, q;
int L, R;
long long tot = 0;
cin >> n >> q;
for (int i = 1; i <= n; ++i) cin >> x[i];
for (int i = 0; i < q; ++i) cin >> L >> R, --c[L - 1], ++c[R];
for (int i = n - 1; i > 0; --i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int const inf = 1000 * 1000 * 1000;
long long const inf64 = 1ll * inf * inf;
int const K = 300005;
int const N = 1005;
int n, m, k;
int mat[N][N];
struct picture {
int color;
int li, lj, ri, rj;
void read() {
char type;
scanf("%d %d %d %d %c", &li, &lj, &ri, &... | 6 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B,C,D;cin>>A>>B>>C>>D;
for(int i=0;i<D-B;i++)cout<<'U';
for(int i=0;i<C-A;i++)cout<<'R';
for(int i=0;i<D-B;i++)cout<<'D';
for(int i=0;i<C-A;i++)cout<<'L';
cout<<'L';
for(int i=0;i<D-B+1;i++)cout<<'U';
for(int i=0;i<C-A+1;i++)cout<<'R';
cou... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
(ios_base::sync_with_stdio(false), cin.tie(NULL));
;
int t, n, x;
cin >> t;
while (t--) {
cin >> n >> x;
int c = 2, ans = 1;
while (c < n) {
c += x;
ans++;
}
cout << ans << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
string dtob(long long int n) {
string r = "";
long long int t = n;
while (n > 0) {
r = to_string(n % 2) + r;
n /= 2;
}
return r;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long int n, q;
cin >> n >> q... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> v, v2, v3, v4;
int main() {
long long ar[102] = {0}, arb[102] = {0};
long long int i = 0, j, temp = 0, c, d, n, m, k, flag = 0, mi2 = 0, sum = 0,
a, b, cur, ma = 0, ans = 0;
float re;
vector<pair<long long, long long> > vp, vp2;... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int count = 0, count2 = 0;
int i, j, k = -1;
cin >> n;
int a[n];
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < n; i++) {
if (a[i] == 1) {
k = i;
break;
}
}
if (k == -1) {
cout << "0";
return 0;
}
f... | 1 |
#include <bits/stdc++.h>
int a[100009];
int S[100009];
struct sLine {
int K, B;
int L, R;
} lines[2000009];
int linesCnt;
struct sTree {
int l, r;
sLine* arr;
int pl, pr;
int cnt;
} tree[200009];
int treeSize;
int BuildTree(int l, int r) {
int cur = treeSize++;
tree[cur].l = l;
tree[cur].r = r;
if (... | 5 |
#include <iostream>
using namespace std;
int main(){
int S, W;
cin >> S >> W;
cout << (S > W ? "safe" : "unsafe");
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 600010;
int mem[MAXN], lan[MAXN], accept[MAXN], like[MAXN], b[MAXN];
int cnt[MAXN];
int n, m, tmp, t;
void discrete() {
for (int i = 1; i <= tmp; i++) b[i] = lan[i];
sort(b + 1, b + tmp + 1);
t = unique(b + 1, b + tmp + 1) - b - 1;
}
int query(int x) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int ans[2000][2000];
int main() {
long long n, k, d, f = 0;
cin >> n >> k >> d;
long long x = 1;
for (int i = 1; i <= d; i++) {
x *= k;
if (x >= n) {
f = 1;
break;
}
}
if (!f) {
cout << -1 << endl;
return 0;
}
for (int i = 0; ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long B[4001], c[4001][4001], n, ans = 0;
int main() {
while (scanf("%d", &n) != EOF) {
for (int i = 0; i <= n; i++) c[i][0] = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % 1000000007;
... | 4 |
#include<bits/stdc++.h>
using namespace std;
int n;
char s[1000100];
char t[1000100];
queue<int>q;
int main()
{
scanf("%d",&n);
scanf("%s",s+1);
scanf("%s",t+1);
int ans=0;
for(int i=1;i<=n;++i)
if(s[i]!=t[i]){ans=1;break;}
if(!ans)
{
puts("0");
return 0;
}
for(int up=n,dn=n;dn;--dn)
{
while(t[dn-1]==... | 0 |
#include <bits/stdc++.h>
int main() {
long long int n, a, b, i, t;
scanf("%lld %lld %lld", &n, &a, &b);
t = n / a + 1;
for (i = 0; i < t; i++) {
if ((n - (a * i)) % b == 0 && n - (a * i) >= 0) {
printf("YES\n%lld %lld", i, (n - (a * i)) / b);
return 0;
}
}
printf("NO");
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int n, msize = 0, head = 1, tail = 0;
long long t[300010] = {0}, w[300010] = {0}, mheap[300010];
int mqueue[300010];
void insert_heap(long long key) {
mheap[++msize] = key;
long long tmp = mheap[msize];
int cur = msize, fc = msize / 2;
while (cur > 1) {
if (mhea... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[100010];
bool vis[100010];
double len[100010];
bool chk[100010];
void dfs(int s) {
bool f = 0;
for (int i = 0; i < g[s].size(); i++) {
int j = g[s][i];
if (!vis[j]) f = 1;
}
if (!f) {
chk[s] = 1;
return;
}
for (int i = 0; i < g[s].s... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string s;
cin>>n>>s;
if(s.substr(0,n/2)==s.substr(n/2,n)&&n%2==0) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e6 + 3;
long long inf = 1e18;
double eps = 1e-2;
ifstream in("input.txt");
ofstream out("output.txt");
int main() {
int n, q;
cin >> n >> q;
string s;
cin >> s;
vector<vector<int>> links(n + 3, vector<int>(26, n + 1));
for (int i = n - 1; i >= 0... | 2 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0, sgn = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') sgn = -1;
for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
return x * sgn;
}
const int N = 3e5 + 10;
int h[N], cnt, deg[N], m, n, ... | 6 |
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,a) for(int i=lst[a];i;i=nxt[i])
#define mp(a,b) make_pair(a,b)
using namespace std;
typedef pair<int,int> pii;
#define fi first
#define se second
int read() {
char... | 0 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct BIT {
int n;
vector<int> v;
BIT(int n) : v(n+1) {
this->n = n;
}
void add(int a, int x) {
for (int i = a; i <= n; i += i & -i)
v[i] += x;
}
int sum(int a) {
int res ... | 0 |
#include <bits/stdc++.h>
using namespace std;
char in[10];
int res = 10;
void dfs(int sum1, int sum2, int nm, int cur) {
if (cur == 6) {
if (sum1 == sum2) res = min(res, nm);
return;
}
for (int i = 0; i < 10; i++)
if (cur < 3)
dfs(sum1 + i, sum2, nm + (i != in[cur] - '0'), cur + 1);
else
... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;cin>>a>>b>>c;
int x=7*a+b,cnt=0;
cnt+=c/x*7;int y=c%x;if(y>0)cnt+=min((y-1+a)/a,7);
cout<<cnt<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> m;
long long a[10004];
long long f(long long a, long long b) {
m[a]--;
m[b]--;
vector<long long> v;
v.push_back(a);
v.push_back(b);
long long x = b;
long long y = a + b;
while (m[y] != 0) {
m[y]--;
v.push_back(y);
y = x ... | 4 |
#include <bits/stdc++.h>
int main() {
int q;
scanf("%d", &q);
while (q--) {
long long a, b, c;
scanf("%lld%lld%lld", &a, &b, &c);
printf("%lld\n", (a + b + c) / 2);
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod = 1e9 + 7;
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T> v) {
os << "(" << v.first << ", " << v.second << ")";
return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T> v) {
for (int i... | 3 |
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
using namespace std;
struct Node {
double x, y, r;
Node(double x, double y, double r) : x(x), y(y), r(r) {}
};
int n, k;
vector<int> x, y, c;
double distance(double px, double py) {
vector<double> dis(n);
for (int... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.