solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int a[6];
int main() {
int m, x, y, i;
scanf("%d", &m);
for (i = 0; i < m; ++i) {
scanf("%d%d", &x, &y);
++a[x], ++a[y];
}
if (m != 5)
printf("WIN");
else {
for (i = 1; i <= 5; ++i) {
if (a[i] != 2) {
printf("WIN");
return 0... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main() {
int n,k,s;
cin>>n>>k>>s;
for(int i=1;i<=k;i++) printf("%d ",s);
if(s==1) s++;
else s--;
for(int i=k+1;i<=n;i++) printf("%d ",s);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const int MAXN = 1e5 + 5;
const int T = 1e3 + 10;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
long long binpow(long long val, long long deg) {
if (!deg) return 1;
if (deg & 1) return binpow(val, deg - 1) * val... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
vector<int> par;
vector<int> sz;
UnionFind(int n = 0) {
if (n > 0) initialize(n);
}
void initialize(int n) {
par.resize(n);
sz.resize(n);
for (int i = 0; i < n; i++) {
par[i] = i;
sz[i] = 1;
}
}
int find(int x... | 6 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-8;
const long double PI = 3.1415926535897932384626433832795;
char buf[100];
long long phi(long long x) {
sprintf(buf, "%I64d", x);
fo... | 1 |
#include<iostream>
#include<queue>
#include<string>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
int main(){
int m, n, s, i;
char no[100];
while(cin >> m >> n, m != 0 || n != 0) {
queue<int> q;
for(int j = 0; j < m; j++) q.push(j+1);
i = 1;
while(n--) {
if(q.s... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, k;
set<int> edge[3001];
map<pair<int, int>, set<int>> forb;
int d[3001][2], pre[3001][2], cnt[3001];
void bfs() {
queue<pair<int, int>> q;
q.push({1, 0});
while (q.size()) {
int cur = q.front().first, from = q.front().second;
q... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
int m;
long long a[400005], b[400005];
long long L0, R0;
void init() {
L0 = R0 = -1;
long long l = 1, r = n;
while (l <= r) {
long long mid = l + r >> 1, s = 0;
for (int i = 0; i <= m; ++i) s += (((b[i]) + (mid)-1) / (mid)) - 1;
if (s <= k)... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[1000 * 100 + 10];
int dis[1000 * 100 + 10][200], mark[1000 * 100 + 100], col[1000 * 100 + 100], n,
m, k, s;
void BFS(int c) {
vector<int> Q;
for (int i = 0; i < n; i++) {
if (col[i] == c) {
Q.push_back(i);
mark[i] = 1;
} else
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, q;
cin >> n >> q;
vector<pair<long long, long long>> v;
for (long long i = 0; i < n; i++) {
v.push_back({i + 1, 0});
}
while (q--) {
long long t, k, d;
cin >> t >> k >> d;
long long av = 0;
for (long long i = 0; i < ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(void){
int n, m; cin >> n >> m;
if(n % 2 == 1){
for(int i = 0; i < n/2 + 1; i++){
if(i == 0)
cout << 0;
else
cout << " " << 0;
}
for(int i = 0; i < n/2; i++){
cout << " " << m;
}
cout << endl;
}else{
... | 0 |
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
using namespace std;
int main(){
int n;
while(1){
cin>>n;
if(n==0) break;
vector<int> a(n);
rep(i,0,n) cin>>a[i];
int MAX=a[0];
rep(i,0,n){
int sum=0;
rep(j,i,n){
sum+=a[... | 0 |
#include <bits/stdc++.h>
const int N = 505;
const int mod = 1e9 + 7;
using namespace std;
int n;
int k;
long long d[N][N];
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> k;
for (int i = 1; i < k; i++) {
d[0][i] = -1e18;
}
for (int i = 1; i <= n; i++) {
long long a, b;
cin >> a >> b;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, x, y;
cin >> n >> m;
for (i = 1; i <= m; i++) cin >> x >> y;
for (i = 1; i <= n; i++) cout << i % 2;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int N = 1, n, m, x, y, k, t, a[400005], b[400005], cay_vai_lon[400005],
sieu_cay_khong_lo[800005];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
while (N <= n) N <<= 1;
for (int i = 1; i <= m; i... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
clock_t clk = clock();
long long int i, j;
void solve(void);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int t = 1;
while (t--) solve();
return 0;
}
void solve() {
string s;
int k;
cin >> s >> k;
set<pair... | 2 |
#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > s;
set<pair<int, int> >::iterator st, it, pre, suc;
int h[120000], l[120000], r[120000], i, j, k, o, n, p, q, P[120000], f[120000];
bool cmp(const int& a, const int& b) { return h[a] > h[b]; }
int main() {
scanf("%d%*d", &n);
for (i = 1; i <= n; ++i... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500500;
int n, k;
long long dp[N][2];
vector<pair<int, int> > adj[N];
long long get(int v, int p, int par) {
long long& ans = dp[v][p];
if (ans != -1) {
return ans;
}
ans = 0;
long long sum = 0;
vector<long long> ot;
for (pair<int, int> e : a... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005, M = 6;
int a[N][M];
struct RMQ {
int n, lg;
int d[M][N][20];
void init(int N, int M) {
n = N;
for (lg = 0; (1 << lg) <= n; lg++)
;
lg--;
for (int j = 1; j <= M; j++) {
for (int i = 1; i <= n; i++) d[j][i][0] = i;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define MAX 100000
int main()
{
vector<int> p;
bool prime[MAX];
fill(prime, prime + MAX, 1);
prime[0] = prime[1] = 0;
for (int i = 2; i < MAX; i++) {
if (prime[i]) {
p.push_back(i);
for (int j = 2*i; j < MAX; j += i)... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1500;
const int N = 1e3 + 7, M = N * 2;
const int inf = 0x3f3f3f3f;
const long long INF = 0xFFFFFFFFFF;
const long long mod = 1e9 + 7;
inline long long read();
int p[N];
int b[N];
int find1(int x) {
if (p[x] != x) p[x] = find1(p[x]);
return p[x];
}
int ... | 4 |
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
const int MOD=1000000007;
int INF=100100100100100;
int a[2010];
signed main(){
i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
int main() {
scanf("%d%d%d", &n, &a, &b);
a = (a + b) % n;
printf("%d\n", (a == 0 ? n : (n + a) % n));
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const double PI = 3.141592653589793;
int licz, maxx, i, j, akt, n, m, L[5005], R[5005], U[5005], D[5005], sum, w;
char dir[5005];
char t[5005];
vector<int> wek;
void hide(int a) {
L[R[a]] = L[a];
R[L[a]] = R[a];
U[D[a]] = U[a];
D[U[a]] = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
cin >> x >> y;
if (x < y)
cout << x << " " << (y - x) / 2;
else
cout << y << " " << (x - y) / 2;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
int a[maxn];
bool ans[maxn];
priority_queue<int, vector<int>, greater<int> > dw;
priority_queue<int> up;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
if (n == 1) {
cout << "YE... | 3 |
#include <bits/stdc++.h>
using namespace std;
int dp[204][104];
bool vis[204][104];
int n, k, l;
vector<int> delta;
vector<int> d;
int dfs(int t, int pos) {
int &ans = dp[t][pos];
vis[t][pos] = 1;
if (pos == n + 1) return ans = 1;
if (ans != -1) return ans;
if (pos > 0) {
if (d[pos - 1] + delta[t] > l) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
int vis[N + 100], cnt[N + 100];
int main() {
int n, ans = 0;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int a;
scanf("%d", &a);
vis[a] = 1;
}
for (int i = N; i > 0; i--) {
if (!vis[i]) {
continue;
}
cnt[i] = 1;... | 6 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n;
cin>>n;
vector<string> g(n);
for(auto &s:g)
cin>>s;
int res=-1;
for(int u=0;u<n;++u){
queue<int> q;
q.push(u);
vector<int> cost(n,-1);
vector<int> clr(n,-1);
clr[u]=0;
cost[u]=0;
while(!q.empty()){
int x=q.f... | 0 |
#include <bits/stdc++.h>
using namespace std;
int arr1[100010], arr2[100010], ans[200020];
int ansit;
int main() {
int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y,
z, cnt, st, ed, fl;
char tmp;
scanf("%d", &t);
for (i = 0; i < t; i++) {
scanf("%d", &n);
scanf("%c", &t... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
string a;
cin >> n >> a;
k = n;
for (int i = 0; i < n - 1; i++) {
if (a[i] != a[i + 1]) {
k--;
i++;
}
}
cout << k;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
struct fast_ios {
fast_ios() {
cin.tie(nullptr), ios::sync_with_stdio(false),
cout << fixed << setprecision(20);
};
} fast_ios_;
template <class T>
auto add = [](T a, T b) -> T { return a + b; };
template <class T>
auto f_max = [](T a, T b) -> T { return max... | 4 |
#include<bits/stdc++.h>
using namespace std;
const int N=1000007;
int a[N],b[N];
int main()
{
int n,m,t;cin>>n>>m;t=(m+1)/2;
for(int i=1;i<=t;++i) a[i]=i,b[i]=t+t+1-i;
for(int i=t+1;i<=m;++i) a[i]=t+i,b[i]=a[i]+2*(m-i+1);
for(int i=1;i<=m;++i) printf("%d %d\n",a[i],b[i]);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int IN() {
int c, f, x;
while (!isdigit(c = getchar()) && c != '-')
;
c == '-' ? (f = 1, x = 0) : (f = 0, x = c - '0');
while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + c - '0';
return !f ? x : -x;
}
const int N = 200000 + 19;
struct QType {
int i, l... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int N, A[MAXN], B[MAXN];
int st[4 * MAXN];
int query_st(int L, int R) {
int ans = 0;
for (L += N, R += N; L < R; L >>= 1, R >>= 1) {
if (L & 1) ans += st[L++];
if (R & 1) ans += st[--R];
}
return ans;
}
void update_st(int p, int v) ... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <class T>
T Gcd(T x, T y) {
return y ? Gcd(y, x % y) : x;
}
template <class T>
T Lcm(T x, T y) {
return x / Gcd(x, y) * y;
}
template <class T>
void Adj(T &x, T y) {
if (x >= y) x %= y;
while (x < 0) x += y;
}
const long long M... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long INF = 1e18;
const double eps = 1e-6;
const int maxn = 4e5 + 5;
map<long long, long long> mp;
long long n, I, K, idx, a, b[maxn], sum[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> I;
for (int i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) cout << 1;
cout << endl;
for (int i = 1; i < n; i++) cout << 8;
cout << 9;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int Szukaj(vector<int>& a, int x) {
if (a.size() == 0) return -1;
int l = 0, p = a.size() - 1, s, r = -1;
while (l <= p) {
s = (l + p) / 2;
if (a[s] >= x) {
r = s;
p = s - 1;
} else
l = s + 1;
}
return r;
}... | 3 |
#include <bits/stdc++.h>
long long INF = (1ll << 61);
using namespace std;
long double EPS = 1e-15;
struct pt {
long double x, y;
pt() {}
pt(long double x, long double y) : x(x), y(y) {}
pt(const pt &p) : x(p.x), y(p.y) {}
pt operator+(const pt &p) const { return pt(x + p.x, y + p.y); }
pt operator-(const p... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y, z = 0, v = 0, c = 0, b;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x >> y;
if (x % 2 != 0) z++;
if (y % 2 != 0) v++;
if ((y % 2 == 0 && x % 2 != 0) || (y % 2 != 0 && x % 2 == 0)) c++;
}
if (v % 2 == 0 && z % 2 == 0)
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e3 + 7;
const int INF = 1e9;
int n, m, k, p, q, a, b, c, d, cnt = 0, ans = 0;
map<int, int> mp;
int ar[MAX];
vector<int> used;
set<pair<int, int> > did;
int solve(int a, int b) {
if (did.find({a, b}) != did.end()) return 0;
int ret = 2;
used.push_back... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int a, b, c, ans = 0;
cin >> a >> b >> c;
for (int i = 0; i <= a; i++) {
if (b >= 2 * i && c >= 4 * i) {
ans = 7 * i;
}
}
cout << ans;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
return (b ? __gcd(a, b) : a);
}
template <typename T>
T lcm(T a, T b) {
return (a * (b / gcd(a, b)));
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
os << "[ ";
for (auto v : V) os << v << " ";
return o... | 4 |
#include <bits/stdc++.h>
using namespace std;
int stone[100005];
int main() {
int l, w;
cin >> l >> w;
long long sum = 0;
for (int i = 1; i <= l - 1; i++) {
scanf("%d", &stone[i]);
if (i <= w) sum += stone[i];
}
int cnt = 0;
for (int i = w + 1; i <= l - 1; i++) {
if (stone[i] <= stone[i - w] -... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e1) {
cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
cout << e1 << " " << e2 << " " << e3 << endl;
... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c *r) -> decltype(cerr << *r);
template <class c>
char dud(...);
struct muu {
template <class c>
muu ... | 3 |
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,p;
cin >> n >> p;
long long a[n];
for(int i=0;i<n;i++){
cin >> a[i];
if(a[i]%2==1){
cout << (long long)pow(2,n-1);
return 0;
}
}
if(p==0)cout << (long long)pow(2,n);
else cout << 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
int n;
int tp[MAXN];
int son[MAXN][2];
int f[MAXN], g[MAXN], h[MAXN];
void dfs(int o) {
if (tp[o] == 0) return;
if (tp[o] == 4) {
dfs(son[o][0]);
f[o] = !f[son[o][0]];
} else {
dfs(son[o][0]), dfs(son[o][1]);
int a = f[son[o][... | 6 |
#include <bits/stdc++.h>
#define debug(x) cout << #x" = " << x;
#define st first
#define nd second
using namespace std;
using namespace placeholders;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MAXN = 5E5 + 10, SIGMA = 26, D = 18;
char s[MA... | 0 |
#include <bits/stdc++.h>
using namespace std;
;
int MOD = 1e9 + 7;
struct mod_int {
int val;
mod_int(long long v = 0) {
if (v < 0) v = v % MOD + MOD;
if (v >= MOD) v %= MOD;
val = v;
}
static int mod_inv(int a, int m = MOD) {
int g = m, r = a, x = 0, y = 1;
while (r != 0) {
int q = g /... | 6 |
#include <bits/stdc++.h>
int main() {
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
if (n > m || n > k) {
printf("NO");
} else {
printf("YES");
}
}
| 1 |
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define MAXN 100000
using namespace std;
typedef long long LL;
vector<int> G[MAXN+5];
int N,ans;
int cnt[MAXN+5][21];
void DFS(int u,int fa)
{
for(int i=0;i<(int)G[u].size();i++)
{
int v=G[u][i];
if(v==fa)
continue;
DFS(v,u);
for(int j... | 0 |
#include <cassert>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
vector<bool> f(string &a, string &b) {
int la = a.size(), lb = b.size();
vector<bool> ret(la+1, true);
for (int i = 0; i < la; i++) {
for (int j = i, k = 0; j < la && k < lb; j++, k++) {
i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000;
int n, K, D, a[maxn + 5], b[maxn + 5], tem[maxn + 5], r[maxn + 5], ans, AL, AR;
bool vis[maxn + 5];
int top[2], stk[2][maxn + 5], R[2][maxn + 5];
long long MIN[(maxn << 2) + 5], tag[(maxn << 2) + 5];
inline int Find(int x, int L = 1, int R = tem[0])... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, a, k;
const int N = 1e6 + 5;
int t[2 * N];
void modify(int p) {
for (t[p += n]++; p > 1; p >>= 1) t[p >> 1] = t[p] + t[p ^ 1];
}
int query(int l, int r) {
int res = 0;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1) res += t[l++];
if (r & 1) ... | 4 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MAX_N = 15;
int dist[MAX_N][MAX_N]; // dist[i][j] i から j への距離
// dp[i][j]: 状態iでjにいるときの最短経路
// 状態iはビットで管理: 00011->点0と点1は通貨済
int dp[1 << MAX_N][MAX_N];
int n, m;
const... | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;
int n, m;
int a[777][777];
int col[777];
bool bad;
int W, B;
vector <pii> v;
int mem[777][777];
void dfs(int p) {
if(col[p] == 0) ++W;
else ++B;
for(int i = 1; i <= n; i++) {
if(i == p) continue;
if(a[p][i] == 0) {
if(col[i] == -1) {
... | 0 |
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <iostream>
#include <cstdio>
#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>
#i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, cur, a[100005];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
cur = 1;
for (int i = 0; i < n; i++) {
if (a[i] >= cur) {
cur++;
}
}
printf("%d\n", cur);
return 0;
}
| 2 |
#include<bits/stdc++.h>
using namespace std;
int a[200000];
int main()
{
int n,ans=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=n;i>=1;i--)
{
for(int j=i+i;j<=n;j+=i)
{
a[i]^=a[j];
}if(a[i])
{
ans++;
}
}
cout<<ans<<endl;
for(int i=1;i<=n;i++)
{
if(a[i])
{
cout<... | 0 |
#include <iostream>
#include <queue>
using namespace std;
void loadData(int *data,int *cData){
for(int i=0;i<=9;i++){
cData[i] = data[i];
}
}
int main(){
//dataが固定用。aData,bDataを変化させて行う。aDataは頭を固定しbDataにてへんか
int data[9+1];
int aData[9+1];
int bData[9+1];
int cData[9+1];
int ansData[9+1];
int ansState=0;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> a, used;
long long mem[100000 + 10];
long long solve(int ind) {
if (ind < 0) return 0;
if (mem[ind] != -1) return mem[ind];
if (ind - 1 >= 0 && a[ind - 1] == a[ind] - 1)
return mem[ind] =
max(a[ind] * used[a[ind]] + solve(ind - 2),... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, q;
cin >> n >> k;
vector<long long> a(n + 1);
vector<long long> b(n + 1);
map<long long, int> mp;
for (long long i = 1; i <= n; i++) cin >> a[i];
long long count = 0;
for (auto i = n; i >= 1; i--) {
if (mp[a[i]] != 1) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[1000001];
int main() {
int n, ans = 1;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
if (++a[x] > a[ans]) ans = x;
}
printf("%d\n", ans);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int T, n, m, i, j, x, s, c = 0, flag, ans = 0;
cin >> n;
m = s = 0;
for (i = 1; i <= n; i++) {
m = m + i;
s = s + m;
if (s > n) {
s = s - m;
ans = i - 1;
break;
}
}
if (s == n) ans = i - 1;
cout << ans <... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int n;
int main() {
vector<pair<int, int> > v;
v.clear();
cin >> n;
int sn = sqrt(n);
for (int i = 2; i < sn + 1; i++) {
int c = 0;
bool flag = true;
while (flag) {
if (n % i == 0) {
c++;
n /= i;
} else {
f... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
string toStr(T x) {
stringstream ss;
ss << x;
return ss.str();
}
template <class T1, class T2>
string toStr(pair<T1, T2> x) {
return toStr(x.first) + ": " + toStr(x.second);
}
template <class T>
string containerToStr(T v) {
string r = "[";
for... | 2 |
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <s... | 0 |
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n, l, t, a[100001], cnt;
int main(int argc, char const *argv[])
{
scanf("%d%d%d", &n, &l, &t);
for (int i = 1; i <= n; i++)
{
int op;
scanf("%d%d", &a[i], &op);
a[i] += op == 1 ? t ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int flag[N], s[5][5], n;
vector<int> a[6][N];
void init() {
for (int i = 2; i < N; i++) {
if (flag[i]) continue;
for (int j = i + i; j < N; j += i) flag[j] = 1;
int t = i;
for (int j = 1; j < 5; j++) {
t /= 10;
a[j][t].pus... | 5 |
#include <bits/stdc++.h>
using namespace std;
int Max(int &a,int b){return a = max(a,b);}
int dp[2][1001][1001];
int check(const string &a,const string &b){
int n = a.size();
int m = b.size();
assert(n==m);
int res = 0;
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
Max(res,dp[0][i][j]);
Max(... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, t, b, c, sum = 0;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> a >> b;
if (a > b) {
sum = a + b;
if (sum % 2 == 0) {
cout << "1" << endl;
} else
cout << "2" << endl;
}
if (a < b) {
sum = a +... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, tab[100001], occ[100001];
set<int> ss;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> tab[i];
ss.insert(tab[n]);
occ[n] = 1;
for (int i = n - 1; i >= 1; i--) {
if (ss.count(tab[i]) != 0)
occ[i] = occ[i + 1];
else {
ss... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
register int c = getchar();
x = 0;
int neg = 0;
for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
;
if (c == '-') {
neg = 1;
c = getchar();
}
for (; c > 47 && c < 58; c = getchar()) {
x = (x << 1) + (x << 3) + c... | 5 |
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#in... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline void fast() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
long long int solve(long long int a, long long int b, long long int mn,
long long int e, long long int h) {
if (mn > 0) {
long long int s = 0;
if (mn >= e * a) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<vector<int>> x(4, vector<int>(n));
if (k > (n - 2) * 2)
cout << "NO";
else {
cout << "YES" << endl;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < n; j++) {
if (i == 0 || j == 0 || i == 3 ||... | 2 |
#include <bits/stdc++.h>
const int N = 2e3 + 5;
int TEST_NUM = 1;
using namespace std;
void calc(string *res, long double *d, long double x, long double y,
long double z) {
res[1] = "x^y^z";
d[1] = log(x) * pow(y, z);
res[2] = "x^z^y";
d[2] = log(x) * pow(z, y);
res[3] = "(x^y)^z";
d[3] = log(x) *... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500000;
int n;
bool seq[MAXN], goal[MAXN];
vector<int> node[MAXN], ans;
void DFS(int curr, int parent, bool cpar, bool opar) {
if (seq[curr] ^ goal[curr] != cpar) {
cpar = !cpar;
ans.push_back(curr);
}
for (int a = 0; a < node[curr].size(); a+... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[200005];
long long k,l,r,mid,ans;
long long work(long long a,long long b) {
return a / b + (((a ^ b) >= 0) and a % b);
}
long long _work(long long a, long long b) {
return a / b - (((a ^ b) < 0) and a % b);
}
long long check(long long w){
long long cnt... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000 + 5;
const int MAXn = 3005;
const int MAXi = 3;
vector<char> a;
bool res = true;
int main() {
string b, c;
cin >> b >> c;
for (int i = 0; i < b.size(); i++) {
a.push_back(b[i]);
}
sort(a.begin(), a.end());
for (int i = 0; i < a.size();... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, indexsize;
vector<int> fac;
cin >> n;
for (int i = 1; i <= n; ++i) {
int x = n / i;
if (i > x) {
break;
}
if (n % i == 0) {
fac.push_back(i);
fac.push_back(x);
}
}
indexsize = fac.size() - 1;
cout << fa... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a1234;
inline void xxx() {
for (;;)
;
}
inline int rd(int l, int r) { return rand() % (r - l + 1) + l; }
const int mxn = 2e5 + 3, mod = 1e9 + 7, mxm = 1e6 + 3;
inline long long por(long long x, int y) {
long long res = 1;
for (; y; y >>= 1) {
if (y & 1) re... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXFFTBIT = 21;
const int MAXFFTN = 1 << MAXFFTBIT;
struct Complex {
double real, image;
Complex(double real = 0, double image = 0) : real(real), image(image) {}
Complex operator+(const Complex &rhs) const {
return Complex(real + rhs.real, image + rhs.im... | 5 |
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
ll n,k;
cin >> n >> k;
vector<ll> a(n);
for (ll i=0;i<n;i++) cin >> a[i];
sort(a.begin(),a.end());
ll right=ll(1e18)+1;
ll left=-right;
while (right-left>1) {
ll mid=(left+right)/2;
ll cn... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int n;
string s;
struct st {
long long int size;
long long int Op;
long long int Cl;
st() {
size = 0;
Op = 0;
Cl = 0;
}
};
struct st t[2000001];
struct st combine(struct st x, struct st y) {
struct st z;
z.size = x.size + y.size;
long l... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 7, INF = 0x3f3f3f3f, mod = 1e9 + 7;
int a[maxn], dp[maxn], res[maxn];
vector<int> e[maxn], ok[maxn];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
void dfs(int u, int f) {
for (int i = 0; i < (int)e[u].size(); ++i) {
int v = e[... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005, LN = 20;
int L, p[LN][N], d[N], n;
long long S, w[N], pre[N];
vector<int> v[N];
int kth(int x, int k) {
for (int i = LN - 1; i >= 0; i--) {
if (k & (1 << i)) x = p[i][x];
}
return x;
}
void dfs(int u) {
for (int v1 : v[u]) {
pre[v1] = p... | 5 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long int Pow(unsigned long long number, int Power) {
if (Power == 0) return 1;
if (Power == 1) return number % 1000000007;
unsigned long long temp;
temp = Pow(number, Power / 2);
temp *= temp;
if (Power % 2 == 1) temp *= number;
return temp % 100... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1e5 + 10;
int a[N];
const int MOD = 1e9 + 7;
long long fastMul(long long n, int k) {
long long ret = 1;
while (k) {
if (k & 1) {
ret = ret * n % MOD;
}
n = n * n % MOD;
k >>= 1;
}
return ret;
}
int main() {
int n;
scanf("%... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long int t;
cin >> t;
while (t--) {
long int n, k;
cin >> n >> k;
string s;
cin >> s;
long int i = 0, ans = 1;
i = 0;
while (i != k) {
long int j = i;
char current = s[j];
if (s[j] == '?') {
set<char> ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, d, h;
cin >> n >> d >> h;
if (d == h && d == 1 && n > 2) {
printf("-1\n");
return 0;
}
if (d + 1 <= n && 2 * h >= d) {
for (int i = 1; i <= h; i++) {
printf("%d %d\n", i, i + 1);
}
if (d != h) {
printf("1 %d\n", ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
double x[100], y[100], z[100];
int main() {
scanf("%d", &n);
for (int i = 0; i < (n); i++) scanf("%lf%lf%lf", x + i, y + i, z + i);
double x0 = 0, y0 = 0, z0 = 0, lambda = 1;
for (int _ = 0; _ < (100000); _++) {
int i_opt;
double d_opt = -1;
for (... | 5 |
#include <bits/stdc++.h>
const long long MAX_N = 1e6 + 10;
const long long MOD = 1e9 + 7;
using namespace std;
int a[MAX_N];
int dp[MAX_N];
int main() {
int n;
string s;
cin >> n >> s;
if (n & 1) return cout << 0, 0;
for (int i = 1; i <= n; ++i) {
a[i] = a[i - 1];
a[i] += (s[i - 1] == '(');
a[i] -... | 5 |
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define INF (1<<29)
#define EPS (1e-10)
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<in... | 0 |
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
template <typename T>
istream &operator>>(istr... | 1 |
#include <bits/stdc++.h>
const int N = 5005, djq = 998244353;
int n, f[N][N], fac[N];
int main() {
std::cin >> n;
f[1][0] = fac[0] = 1;
for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * (n - i + 1) % djq;
for (int i = 1; i < n; i++)
for (int j = 0; j < i; j++) {
f[i + 1][j] = (1ll * (j + 1) * f... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 20, OFF = 4e5 + 10, OFF2 = 9e5;
const long long inf = 1e18;
int n, s;
vector<pair<int, int> > g[N];
long long dist[N];
void build(int v, int i, int j) {
if (i == j) {
g[v].push_back({OFF2 + i, 0});
g[OFF2 + i].push_back({OFF + v, 0});
retur... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
int a[maxn];
map<int, int> mp1, mp2;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
int ans = INT_MAX;
for (int i = 0; i <= n; i++) {
if (i != 0) {
mp1[a[i]]++;
if (mp1[a[i]] >= 2) break;
}
mp... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.