solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
struct hash_pair {
template <class T1, class T2>
size_t operator()(const pair<T1, T2> &p) const {
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};
long long int n, m;
vector<long long int> adj[1];
bool visited... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 510;
const long long INF = 10000000000000000LL;
const long long inf = 5000000000000LL;
int n;
int nx, ny;
int times;
long long v[MAXN][MAXN];
long long ex[MAXN], ey[MAXN];
long long slack[MAXN];
int ux[MAXN], uy[MAXN], mx[MAXN], my[MAXN], pre[MAXN];
templat... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("tree-vectorize")
#pragma GCC target("sse4")
using namespace std;
using lint = long long;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
template <typename T>
using vc = vector<T>;
template <typename T>
using vvc = vector<vector<T>>;
te... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> used;
vector<long long> order;
vector<vector<long long>> g, gr;
void dfs(long long v) {
used[v] = 1;
for (int i = 0; i < g[v].size(); ++i) {
long long to = g[v][i];
if (!used[to]) dfs(to);
}
order.push_back(v);
}
vector<long lo... | 5 |
#include <bits/stdc++.h>
using namespace std;
int idx[100010], F[100010];
long long int mod = 1e9 + 7;
void build_failure_function(string &pattern) {
int m = pattern.length();
F[0] = F[1] = 0;
for (int i = 2; i <= m; i++) {
int j = F[i - 1];
while (1) {
if (pattern[j] == pattern[i - 1]) {
F[... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int b[n];
for (int i = 0; i < n; i++) {
cin >> b[i];
}
long long int ans = -1;
map<long long int, long long int> m;
for (int i = 0; i < n; i++) {
int j = i + 1;
m[j - b[i]] += b[i];
ans = max(ans, m[j - b[i]]);
... | 2 |
#include<iostream>
#include<cmath>
using namespace std;
#define EPS 1e-8
int dfs(double remain, int n, double a, int denominator) {
if(fabs(remain) < EPS) return 1;
if(remain < EPS) return 0;
if(n <= 0) return 0;
if(remain - ((double) n) / ((double) denominator) > EPS) return 0;
int result = 0;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int ab(int x) { return x > 0 ? x : -x; }
int par[1010], ex[1010];
int find(int x) { return par[x] == x ? x : (par[x] = find(par[x])); }
int n;
int x[1010], y[1010], xi[1010], yi[1010];
vector<int> xs, ys;
vector<pair<int, int> > gx[1010], gy[1010];
int w[1010][1010][... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
long long mod(long long a, long long m) {
if (a == 0)
return 0;
else
return (a % m + m) % m;
}
int mod(string num, int a) {
int res = 0;
for (int i = 0; i < num.length(); i++)
res = (res * 10 + (int)num[i] - '0') % a;
return res;... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
long long n;
cin >> n >> s;
long long c8 = 0, x;
for (long long i = 0; i < n; ++i) {
if (s[i] == '8') c8++;
}
x = (n - 11) / 2;
if (c8 <= x) {
cout << "NO\n";
return 0;
}
string s2;
long long idx = -1;
for (long lon... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
;
long long cnt = 0;
long long ans = 0;
long long n, m = 0;
string s[1005];
long long posC = 0;
cin >> n;
if (n % 2 == 0) {
ans = n * (n / 2);
} else {
ans = (n * n) / 2 + 1;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int t, n, m, ans;
vector<vector<int>> gh, used;
int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1};
int dy[8] = {1, 0, -1, 1, -1, 1, 0, -1};
bool onseg(double x1, double y1, double x2, double y2, double x, double y) {
double d1 = sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
do... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
char board[n][m];
char tog = 'B';
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < m; j++) {
board[i][j] = ... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> bubbleSteps(vector<int> planks, int steps, int np) {
for (int k = 0; k < steps; k++) {
for (int kk = 0; kk < (np - k - 1); kk++) {
if (planks[kk] > planks[kk + 1]) {
int tmp = planks[kk];
planks[kk] = planks[kk + 1];
planks[kk... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> nums(2 * n + 1, 0), even, odd;
for (int i = 1; i <= 2 * n; i++) {
cin >> nums[i];
if (nums[i] % 2)
odd.push_back(i);
else
even.push_back(i);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-10;
int D[1000000];
double sum[1000000];
double maxi[1000000];
double maxiL[1000000];
double maxiR[1000000];
int W;
void init() {
for (int i = 0; i < (W); ++i)
maxiL[i + W] = maxiR[i + W] = maxi[i + W] = max(sum[i + W], 0.0);
for (int i = (W)-1; i >=... | 3 |
#include<iostream>
using namespace std;
int main(){
int H,W,h,w;
cin>>H>>W>>h>>w;
cout<<H*W-(h*W+H*w-h*w)<<endl;
}
| 0 |
#include<cstdio>
#include<vector>
#include<string.h>
#include<cassert>
using namespace std;
int dx[4] = { 1, -1, 0, 0 };
int dy[4] = { 0, 0, 1, -1 };
int map[22][22];
int ans = 100;
int tx,ty;
void dfs(int map[22][22],int depth) {
if(depth >= 10 || depth >= ans) return;
int sx=-1,sy=-1,px,py;
for(int i=0; i<2... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
int arr[100010];
long long cnt = 0;
bool check(long long g) {
long long tres = 0;
for (int i = 0; i < n; ++i) {
tres += g < arr[i] ? g : arr[i];
}
if (tres <= k) cnt = k - tres;
return tres <= k;
};
int main() {
cin >> n >> k;
long long sum... | 4 |
#include <bits/stdc++.h>
using namespace std;
int dp, pre[810], p[810], tt[810], g[810], vis[810], dis[810], z[100010],
now[810], s, t, a[100010], sum[100010];
int n, m, i, L[100010], R[100010], flag, j, ans;
void link(int x, int y, int z) {
dp++;
pre[dp] = p[x];
p[x] = dp;
tt[dp] = y;
g[dp] = z;
dp++;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int x, l;
int cnt = 0;
for (int i = 0; i < n; i++) {
cnt = 0;
cin >> x;
if (x % 7 != 0) {
cnt++;
}
x /= 7;
cout << x + cnt << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
struct seg_tree_lazy {
int S, H;
T zero;
vector<T> value;
U noop;
vector<bool> dirty;
vector<U> prop;
seg_tree_lazy<T, U>(int _S, T _zero = T(), U _noop = U()) {
zero = _zero, noop = _noop;
for (S = 1, H = 1; S < _S;) ... | 5 |
/* User : efficientSloth
Date : 04/01/2021
Time : 20:05:45
*/
#define STANDALONE
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define forn(i,n) for(int i = 0; i < (int)n; i++) // single incremental for loop starting at 0
#define forsn(i,s,n) for(int i = (int)s; i < (int)n; i++) //single increm... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[4000], b[4000];
int s[4000], t[4000];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < n; ++i) b[i] = a[i];
sort(b, b + n);
int cnt = 0;
for (int i = 0; i < n; ++i) {
if (a[i] == b[i]) continue;
for (int ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int lim = 3e5 + 5;
const int blk = 550;
struct qst {
int ql, qr, qk, qi;
};
qst qur[lim];
int arr[lim], ans[lim], cnt[lim];
bool comp(const qst& a, const qst& b) {
int ba = a.ql / blk, bb = b.ql / blk;
if (ba < bb)
return 1;
else if (ba > bb)
return 0;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, s[1111111], gr[1111111];
int calc() {
int r = 0;
gr[0] = -1;
for (int i = 0; i < n; ++i) {
int j = i - 1;
while (j != -1 && s[j] < s[i]) j = gr[j];
gr[i] = j;
if (j != -1) r = max(r, s[j] ^ s[i]);
}
return r;
}
int main() {
scanf("%d", &n)... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
long double x1, y1, r1, x2, y2, r2;
cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2;
long double d = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
long double r = min(r1, r2);
long double R = max(r1,... | 4 |
#include <bits/stdc++.h>
using namespace std;
int mex(const vector<int> &nimbers) {
unordered_set<int> set;
for (auto &nimber : nimbers) set.insert(nimber);
for (int i = 0; i < INT_MAX; i++) {
bool exclude = set.find(i) == set.end();
if (!exclude) continue;
return i;
}
assert(false);
}
int x, y, z... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long qpow(long long a, long long n) {
long long r = 1 % P;
for (a %= P; n; a = a * a % P, n >>= 1)
if (n & 1) r = r * a % P;
return r;
}
void exgcd(long long a, l... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
unordered_map<int, int> maps;
for (int i = 0; i < n; i++) {
int a, x;
cin >> a >> x;
maps[a] = x;
}
int m;
cin >> m;
for (int i = 0; i < m; i++) {
int b, y;
cin >> b >> y;
if (maps.count(b) == 0) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool check[1000005];
int prime[1000005];
int main() {
memset(check, false, sizeof(check));
int pos = 0;
for (int i = 2; i <= 1000005; i++) {
if (!check[i]) prime[++pos] = i;
for (int j = 1; j <= pos && i * prime[j] < 1000005; j++) {
check[i * prime[j]] =... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long b[104][104], c[104][104];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, i, j, k, ss = 0;
cin >> n;
string a[4][n];
for (i = 0; i < 4; i++)
for (j = 0; j < n; j++) cin >> a[i][j];
for (i = 0; i < n; i++) {
... | 3 |
#include <bits/stdc++.h>
char s[520][520];
char q[520][520];
int main() {
int n, m;
scanf("%d", &n);
memset(s, '\0', sizeof(s));
memset(q, '\0', sizeof(q));
q[1][1] = '+', q[1][2] = '+', q[2][1] = '+', q[2][2] = '*';
s[1][1] = '+', s[1][2] = '+', s[2][1] = '+', s[2][2] = '*';
m = 2;
if (n == 0)
prin... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int G = 1000 * 1000 + 10;
vector<int> e[G], cycle;
bool visited[G];
vector<vector<int> > sz[G];
int ans[G], odd[G];
void even_cycle(int x, int y) {
for (int i = 0; i < x; i++) {
ans[sz[x][y][i]] = sz[x][y + 1][i];
ans[sz[x][y + 1][i]] = sz[x][y][(i + 1) % x]... | 5 |
#include <iostream>
#include <vector>
#include <unordered_set>
#include <set>
#include <algorithm>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
int s = n;
int log = 1;
while (s > 0) {
s = s / k;
++... | 4 |
#include <bits/stdc++.h>
using namespace std;
long sum[200010];
long ans, n, m;
string s;
void deal(char c1, char c2, char c3) {
long i;
for (i = 0; i < n; i += 3) {
sum[i + 1] = (s[i] != c1) ? 1 : 0;
sum[i + 2] = (s[i + 1] != c2) ? 1 : 0;
sum[i + 3] = (s[i + 2] != c3) ? 1 : 0;
sum[i + 1] += sum[i];... | 4 |
#include <bits/stdc++.h>
int Kx[1000];
int Ky[1000];
int n, m, k;
struct wall {
int R, x, y;
};
wall C[10000];
double hypot(double x, double y) { return sqrt(x * x + y * y); }
int G[2000][2000];
int P[2000];
int aa[1000];
int bb[1000];
void build_graph() {
for (int i = 0; i < m; i++) {
bool flag = true;
int... | 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;
int main() {
long long n;
cin >> n;
long long s = 0;
for (long long i = 0; i <= n - 1; ++i) {
long long temp;
cin >> temp;
if (temp - s > 15) continue;
s = temp;
}
if (s + 15 < 90)
cout << s + 15 << endl;
else
cout << "90" << endl;
}
| 1 |
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct Data{
string L;
int P,A,B,C,D,E,F,S,M;
int t;
int income;
double eff;
bool operator<(const Data& data)const{
if(eff != data.eff)return eff > data.eff;
return L < data.L;
}
};
int main(){
int N;
Data... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const double PI = 3.141592653589793;
int a, b, n, m, k, i, j;
char t[20];
string s, tab[50][50];
int main() {
ifstream ifile("input.txt");
if (ifile) freopen("input.txt", "rt", stdin);
if (ifile) freopen("output.txt", "wt", stdout);
scanf... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, s;
int v[200010];
int f[200010];
int nxt[200010];
int getNxt(int cpoz, int spec) {
int ans = nxt[cpoz];
if (spec <= cpoz && spec > ans) ans = spec;
return ans;
}
int solve(int val) {
int csum = s;
int prv = s + 1;
while (csum > 0) {
int cr = getNxt(mi... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
long long x, y;
long long n, w;
long long a[N];
long long p[N];
long long a1, a2;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.precision(17);
cin >> n >> w;
for (int i = 0; i < n; i++) cin >> a[i];
p[0] = a[0];
for (int i = 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s = 0, r = 0;
cin >> n;
int arr[n][2];
for (int i = 0; i < n; i++) {
cin >> arr[i][1] >> arr[i][2];
if (arr[i][1] != arr[i][2]) s++;
}
if (s > 0) {
cout << "rated";
} else {
for (int i = 0; i < n - 1; i++) {
if (arr[i]... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int N = 400005;
const int MOD = 1000000007;
int n, p, q, sz;
pair<int, int> a[N];
inline double get(double x, int i, int j) {
double P, Q;
P = p - a[i].first * x;
Q = q - a[i].second * x;
return max(0.0, max(P / a[j].first, Q / a[j]... | 3 |
#include <bits/stdc++.h>
const int N = 1e5 + 7;
char s[N], t[N];
int n, m, sa[N], sb[N], ta[N], tb[N];
inline int read() {
int x = 0;
char c = getchar();
while (!isdigit(c)) c = getchar();
while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return x;
}
int main() {
std::cin >> (s + 1) >> (... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
struct edge {
int u, v;
long long d;
bool o;
};
struct node {
int u;
long long d;
bool operator<(const node& zjz) const { return d > zjz.d; }
};
int n, m, s, t, Next[20000 + 100];
long long dis[maxn], L;
bool done[maxn];
vector<edge> ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
vector<pair<int, int> > G[N], G1[N];
const long long INF = 1e15;
long long preday[N], lastday[N];
int n, m, k;
bool cmp1(pair<int, int> a, pair<int, int> b) {
return a.first == b.first ? (a.second < b.second) : (a.first < b.first);
}
bool cmp2(pair<... | 2 |
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
#define ALL(a) begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
double n, r;
cin >> n >> r;
double num = r * (sin(3.141592653589793 / n));
double den = 1 - sin(3.141592653589793 / n);
cout << setprecision(15);
cout << num / den;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double n, h;
int i;
cin >> n >> h;
double temp1 = sqrt(2.0 / 3.0);
double temp2 = sqrt(1.0 / 2.0);
if (n == 2) {
double temp = h * temp2;
printf("%.12lf\n", temp);
return 0;
}
vector<double> ans;
ans.push_back(h * sqrt((double)(n -... | 2 |
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
int n,m,s,g1,g2;
while(cin>>n>>m>>s>>g1>>g2,n){
s--,g1--,g2--;
int a,b,c,d[n][n];
rep(i,n)rep(j,n)d[i][j]=1<<20;
rep(i,m){
cin>>a>>b>>c;a--,b--;
d[a][b]=c;
}
rep(i,n)d[i][i]=0;
rep(k,n)rep(i,n)rep(j,n)if(d[i]... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
string ans = "WA";
int A = 0;
if (S.at(0) == 'A') {
for (int i = 1; i < S.size(); i++) {
if (S.at(i) < 'a') A++;
}
}
if (A == 1) {
for (int i = 2; i < S.size() - 1; i++) {
if (S.at(i) == 'C') {
... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:108777216")
using namespace std;
int const MAX_N = 4 * 1024;
int const INT_INF = 1100000000;
long long const LL_INF = 1500000000000000000LL;
int n, s[MAX_N], p_sum[MAX_N];
int dp[MAX_N / 2 + 500][100][100];
void do_max(int& a, int b) { a = max(a, b); }
int get_p_... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;
using ll = int64_t;
using ld = long double;
const int N = 30228;
int a[N], b[N];
int ac, bc;
int l[N];
int r[N];
int main() {
#ifdef BZ
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nu... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N=805;
int n,m,k;
char s[N][N];
int d[N][N],qx[N*N],qy[N*N];
int dx[4]={ 0, 0,-1, 1};
int dy[4]={-1, 1, 0, 0};
bool check(int x,int y){
return 1<=x&&x<=n&&1<=y&&y<=m&&s[x][y]!='#';
}
int main(){
cin >> n >> m >> k;
for (int i=1;i<=n;i++)
scanf("%s",s[i]+1);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double PI = atan(1.0) * 4;
int n, m, a, b;
unsigned long long int g, x, y, z;
unsigned long long int sum = 0;
unsigned long long int arr[3002][3002];
unsigned long long int data[3002][3002];
deque<pair<int, int>> dq;
void insert(int i, unsigned long long int no) {
w... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 100000 + 7;
int main() {
long long n, Len, L[N], R[N], tsum = 0, cnt = -1;
long long ans = 0;
scanf("%lld", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &Len);
long long tmax = -1, tmin = 10000000, x, Flag = 0;
for (int j = 1; j ... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int K;
cin>>K;
string S;
cin>>S;
if(S.size()<=K) cout<<S<<endl;
else cout<<S.erase(K)+"..."<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
bool test(string& s, int r) {
int x = 0, y = s.size() - 1;
bool ok = false;
while (x <= y) {
if (s[(x + r) % s.size()] != s[x]) ok = 1;
if (s[(x + r) % s.size()] != s[(y + r) % s.size()]) return false;
++x;
--y;
}
return ok;
}
int main() {
ios_ba... | 2 |
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n, ans=0, len, c;
string s, name[110], t;
cin>>n>>s;
for (int i=0; i<n; i++) cin>>name[i];
for (int i=0; i<n; i++)
{
len=name[i].size();
for (int j=1; j<51; j++)
{
for (int k=0; k<le... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k;
int n, m;
string s, ans;
cin >> n;
cin >> s;
set<int> room;
for (i = 0; i < 10; i++) ans.push_back('0'), room.insert(i);
for (i = 0; i < n; i++) {
if (s[i] == 'L')
k = *room.begin(), room.erase(k), ans[k] = '1';
else i... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000003;
const int V = 501000;
int n, m;
vector<string> str;
string tmp;
int row[V], col[V];
int main() {
scanf("%d%d", &n, &m);
str.resize(n);
for (int i = 0; i < n; i++) cin >> str[i];
memset(row, -1, sizeof(row));
memset(col, -1, sizeof(col));
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int N, K, ans;
int p[205];
int main() {
int i;
scanf("%d", &N);
for (i = 1; i <= 2 * N - 1; i++) {
scanf("%d", &p[i]);
if (p[i] >= 0)
K++;
else
p[i] = -p[i];
ans += p[i];
}
sort(p + 1, p + 2 * N);
if ((2 * N - 1 - K) % 2 == 1)
if ... | 1 |
#include <iostream>
using namespace std;
int main()
{
int a[100],n,i,j,t,c;
for(;;){
cin >> n;
if(n==0)break;
for(i=0;i<n;i++){
cin >> a[i];
}
c = 0;
for(i=n-1;i>0;i--){
for(j=0;j<i;j++){
if(a[j] > a[j+1]){
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
c++;
}
}
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
const long long MOD = 1e9 + 7;
const double eps = 1e-7;
int N, M, K, Q, T;
long long gcd(long long a, long long b) {
if (b == 0LL) return a;
return gcd(b, a % b);
}
int tree[MAXN];
int nmx;
void update(int i, int x) {
while (i <= nmx) {
t... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long dx[] = {1, 0, -1, 0};
long long dy[] = {0, 1, 0, -1};
void solve() {
long long n, m;
string s, t;
cin >> s >> t;
n = stoi(s);
m = stoi(t);
if (s.size() != t.size()) {
cout << "WRONG_ANSWER"
<< "\n";
return;
}
if (n == 0 && m == 0) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 100000 + 10;
int n;
vector<int> G[N];
int son_size[N];
double ans[N];
void init() {
for (int i = 1; i <= n; ++i) G[i].clear();
for (int i = 2; i <= n; ++i) {
int x;
scanf("%d", &x);
G[x].push_back(i);
}
memset(an... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 550;
int n, root, bo[N], ans[N], a[N * 3];
char ss[N][N];
struct node {
vector<int> ch;
int tag, col, leaf;
} d[N * 3];
int dn = 0;
bool chk(node &it) {
int o = 0;
for (int j = 0; j < it.ch.size(); ++j) {
a[j] = d[it.ch[j]].col;
if (a[j] > a[o]... | 5 |
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#define LL long long
using namespace std;
inline int read( )
{
int sum=0;char c=getchar( );bool f=0;
while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar( );}
while(c>='0'&&c<='9') {sum... | 0 |
#include <bits/stdc++.h>
using namespace ::std;
const int INF = int(1e9);
const long long INF64 = (long long)(1e18);
vector<vector<pair<long long, long long> > > g;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
long long n, m;
cin >> n >> m;
g = vector<vector<pair<long long, lo... | 3 |
#include <bits/stdc++.h>
using namespace std;
const pair<long long, long long> M = make_pair(1e9 + 7, 1e9 + 9);
const long long base = 347;
const int N = 1e6 + 7;
ostream& operator<<(ostream& os, pair<long long, long long> hash) {
return os << "(" << hash.first << ", " << hash.second << ")";
}
pair<long long, long lo... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool good(int a) {
while (a > 0) {
if (a % 10 != 4 && a % 10 != 7) {
return false;
}
a /= 10;
}
return true;
}
int main() {
int n;
scanf("%d", &n);
int i = 0;
int l = 0;
multiset<pair<int, int>> m;
vector<int> v(n);
for (int j = 0; j < ... | 4 |
#include <iostream>
using namespace std;
int main() {
int N, p[50], count=0;
cin >> N;
for(int i=0; i<N; ++i) cin >> p[i];
for(int i=0; i<N; ++i)
if(p[i]!=i+1) ++count;
cout << ((count<=2)?"YES":"NO") << endl;
return 0;
} | 0 |
#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
double dp[200][555];
int n;
int main()
{
cin>>n;
for(int i=0;i<555;i++)dp[0][i]=1e150;
dp[0][1]=0;
for(int i=0;i<n;i++)
{
int h;
cin>>h;
for(int j=0;j<555;j++)dp[i+1][j]=1e150;
for(int j=1;j<500;j++)
{
for(int k=1;k<500;k++)... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
long long p, h[100005], a[100005], now[100005];
struct node {
long long d;
int id;
friend bool operator<(node x, node y) { return x.d > y.d; }
};
priority_queue<node> q;
bool check(long long x) {
while (!q.empty()) q.pop();
for (int i = 1; i <= n; i++... | 3 |
#include<iostream>
#include<string>
using namespace std;
int main(){
string s;
cin>>s;
string strs[]={
"dream",
"dreamer",
"erase",
"eraser"
};
bool dp[100001]={true};
for(int i=0;i<s.size();i++){
for(auto e:strs){
int n=i+e.size();
if(n<=s.size()&&!s.compare(i,e.size(),e))... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
;
}
template <class T>
void chmin(T& a, const T& b) {
if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, cons... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long int a, b, mini = 0;
while (n--) {
cin >> a >> b;
mini = max(mini, a + b);
}
cout << mini << "\n";
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100, M = 52 + 10, LG = 30, base = 2;
const int MOD = 1e9 + 7, mod = 1e9 + 9;
const long long INF = 1e9, inf = 1e18;
long long a[3], m;
long double x;
bool b[N];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
;
cin >> a[0] >... | 3 |
#include <bits/stdc++.h>
using namespace std;
int dp[35][15][5];
int month[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char s[100005];
int main() {
int d, m, y;
int ad, am, ay, mx = 0;
scanf("%s", s);
int len = strlen(s);
for (int i = 0; i + 9 < len; i++) {
if (s[i + 2] != '-' || s[i + 5] != ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, sum = 0, ans = 0;
int day1[7] = {1, 1, 0, 0, 0, 0, 0}, day2[7] = {0, 0, 0, 0, 0, 1, 1};
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
sum += day1[i % 7];
ans += day2[i % 7];
}
cout << ans << " " << sum << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long int x, y, n, m, k, ind, mx = 0, t = 1, sum = 0, flag = 0;
string str, strin;
char ch;
const int MAX_N = 1e5 + 10;
void solve() {
cin >> n >> m;
for (long long int i = 0; i < n; i++) {
for (long long int j = 0; j < m; j++) {
if (i == n - 1 && j == m -... | 1 |
#include <bits/stdc++.h>
int main(void) {
long long int n, k;
scanf("%lld %lld", &n, &k);
long long ans = -1, res;
long long lo = 2, hi = k;
while (lo <= hi) {
long long mid = (lo + hi) / 2;
long long left = mid * (mid + 1) / 2 - 1, right = k * (k + 1) / 2 - 1;
long long ret = (right - left) - (k ... | 2 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int>, vector<pair<int, int> >,
greater<pair<int, int> > >
pq;
int a[600005], ans;
int n, k, pre[600005], nxt[600005];
int main() {
scanf("%d%d", &k, &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
sort(a + 1, a + n + 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1010;
const long long mod = 998244353;
inline long long sum(long long a, long long b) { return (a + b) % mod; }
long long n, k;
long long a[maxn];
long long dp[maxn][maxn], pref[maxn][maxn];
long long le[maxn];
long long solve(long long val) {
for (... | 6 |
#include<cstdio>
#include<deque>
#include<iostream>
using namespace std;
deque<int>_deq;
int main(){
int Q,q,d,x;
scanf("%d",&Q);
while(Q--){
scanf("%d",&q);
if(q==0){
scanf("%d%d",&d,&x);
if(d==0) _deq.push_front(x);
else _deq.push_back(x);
}
else if(q==1){
scanf("%d",&d);
printf("%d\n",_deq... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5000005;
pair<int, int> pa[N];
int vis[N];
int main() {
int n, x, y;
scanf("%d", &n), scanf("%d", &x), scanf("%d", &y);
for (int i = 0; i < n; i++) {
scanf("%d", &pa[i].first), scanf("%d", &pa[i].second);
}
int ans = 0;
for (int i = 0; i < n; i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[100];
int a[4], result;
for (int j = 0; j <= 3; j++) a[j] = 0;
gets(str);
for (int j = 0; str[j] != '\0'; j++) {
if (str[j] == 'n') a[0]++;
if (str[j] == 'i') a[1]++;
if (str[j] == 'e') a[2]++;
if (str[j] == 't') a[3]++;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[505], ans = -1;
void check(int k) {
long long temp = 0;
for (int i = 1; i <= n; i++) {
int x = a[i] / k, y = a[i] % k;
if (x < y) return;
x -= y;
temp += (x + y - x / (k + 1));
}
if (ans == -1 || ans > temp) ans = temp;
}
int main(... | 5 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int N, D[1000];
cin >> N;
bool sss[1000] = {};
for(int i = 0; i < N; i++) {
cin >> D[i];
sss[D[i]] = true;
if(i > 0) sss[D[i - 1] * 10 + D[i]] = true;
if(i > 1) sss[D[i - 2] * 100 + D[i - 1] * 10 + D[i]] = true;
}
for(int i = 0; true;... | 0 |
#include <iostream>
using namespace std;
int gcd(int a, int b) {
if (b == 0) return a;
else return gcd(b, a % b);
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
const int MAX_N = 1010;
const int INF = (1 << 28);
int a[MAX_N];
int main() {
int n, m;
cin >> n >> m;
int group = lcm(n, ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000000 + 7;
const long long int MOD1 = 998244353;
const long long int Val9 = 1000000000;
const long long int Val6 = 1000000;
vector<long long int> vd;
void no_of_divisors(long long int n) {
for (long long int i = 1; i <= sqrt(n); i++) {
i... | 1 |
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loo... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 101010;
int n, ans;
int pa[N << 1], ns[N], nt[N], ma[N], pos[N];
vector<pair<int, int> > res;
char s[N], sr[N];
void Manacher(char *s, int n, int *pa) {
pa[0] = 1;
for (int i = 1, j = 0; i < (n << 1) - 1; ++i) {
int p = i >> 1, q = i - p, r = ((j + 1) ... | 5 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,cnt,ans;
string s,t;
int main(void){
cin>>n>>s;
for(int i=0;i<=9;i++){
for(int j=0;j<=9;j++){
for(int k=0;k<=9;k++){
cnt=0;
ll L[]={i,j,k};
for(int i=0;i<n;i++){
if(L[cnt]==s[i]-'0'){
cnt++;
}
if(cnt==3){
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
for (int i = 1, x; cin >> x && x; ++i) {
cout << "Case " << i << ": " << x << '\n';
}
}
| 0 |
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<climits>
#include<bitset>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define int long long
#define mod 1000000007
using namesp... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long n, k;
scanf("%ld %ld", &n, &k);
for (long i = k + 2 - 1; i >= 1; --i) printf("%ld ", i);
;
for (long i = k + 2; i < n + 1; ++i) printf("%ld ", i);
;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, n, d, x, mx, a, b;
vector<int> v;
while (cin >> n) {
for (i = 0; i < n; i++) {
cin >> k;
v.push_back(k);
}
mx = 99999;
for (i = 0; i < v.size(); i++) {
if (i != v.size() - 1) {
x = v[i] - v[i + 1];
... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.