solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int n, m, h;
vector<int> aux, aux2;
int vec[102][102];
int vis[102];
int vis2[102];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m >> h;
for (int i = 0; i < m; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[8];
int main() {
int n, s = 0;
cin >> n;
for (int i = 1; i <= 7; i++) {
cin >> a[i];
}
for (int i = 1; i <= 7; i++) {
s += a[i];
if (s >= n) {
cout << i;
return 0;
}
if (i == 7) {
i = 0;
}
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, -1, 1, 0};
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
if (a.first == b.first) return a.second < b.second;
return (a.first < b.first);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
... | 1 |
#include<iostream>
using namespace std;
int main(){
while(true){
double a[100000], data, total=0;
cin >> data;
if(data == 0) break;
for(int i=0; i<data; i++){
cin >> a[i];
total += a[i];
}
double ave = total/data;
int n=0;
for(int i=0; i<data; i++){
if(a[i]<=ave) n++... | 0 |
#include <bits/stdc++.h>
using namespace std;
int Y[] = {-1, 1, 0, 0, -1, -1, 1, 1};
int X[] = {0, 0, -1, 1, -1, 1, -1, 1};
int directions = 4;
long long power(long long a, long long n) {
if (a == 0) return 0;
if (a == 1 || n == 0) return 1;
if (n == 1) return a % 1000000007;
long long t = power(a, n / 2);
t ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int N;
bool firstMass[3000000];
bool secondMass[3000000];
void input() {
cin >> N;
char c;
for (int i = 0; i < 2 * N; i++) {
cin >> c;
if (c == '1')
firstMass[i] = true;
else
firstMass[i] = false;
}
for (int i = 0; i < 2 * N; i++) {
cin... | 1 |
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
int n,m,i,j,mx,x,a[1000];
while(1) {
scanf("%d %d",&n,&m);
if(n==0 && m==0) break;
for(i=0;i<n;i++) scanf("%d",&a[i]);
mx=0;
for(i=0;i<n-1;i++) {
for(j=i+1;j<n;j++) {
if(a[i]+a[j]<=m) {
mx=max(mx,a[i]... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
Node *ch[2];
int r, s, v;
Node(int _v = 0) : v(_v) {
ch[0] = ch[1] = NULL;
r = rand();
s = 1;
}
void up() {
s = 1;
if (ch[0] != NULL) s += ch[0]->s;
if (ch[1] != NULL) s += ch[1]->s;
}
};
struct Treap {
Node *root;
Treap... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin>>n;
double x,s=0;
string u;
for(int i=0; i<n; i++){
cin>>x>>u;
if(u=="JPY") s+=x;
else s+=380000*x;
}
printf("%-10.5lf\n",s);
} | 0 |
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int mod=1e9+7;
typedef long long ll;
struct mat{
ll a[3][3];
friend mat operator *(mat a,mat b){
mat c;memset(c.a,0,sizeof(c.a));
for(int i=0;i<3;i++){
for(int p=0;p<3;p++){
for(int j=0;j<3;j++) c.a[i][p]=(c.a[i][p]+a.a[i][... | 0 |
#include <bits/stdc++.h>
using namespace std;
int64_t a[200005];
signed main() {
int64_t t;
cin >> t;
while (t--) {
int64_t n, i;
cin >> n;
for (i = 1; i <= n; i++) cin >> a[i];
int64_t c = 0, f = 0, fl = 0;
a[0] = 1000000000;
int64_t cou = 0;
for (i = 1; i <= n; i++) {
if (a[i] ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, s, pcount = 0, vis[500][500];
char arr[500][500];
int dfs(int i, int j) {
vis[i][j] = 1;
int count = 1;
if (i > 0 && vis[i - 1][j] == 0) count += dfs(i - 1, j);
if (i < n - 1 && vis[i + 1][j] == 0) count += dfs(i + 1, j);
if (j > 0 && vis[i][j - 1] ==... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 10;
const long long INF = 1e9;
long long n, ans[maxn], fen[maxn], dp[maxn], a[maxn];
vector<pair<pair<long long, long long>, long long> > poi;
long long ask(long long l, long long r) {
if (r < l) return 0;
if (l > n - 1 || l < 0 || r < 0 || ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int minn(long long int a, long long int b) {
if (a > b) return b;
return a;
}
long long int maxx2(long long int a, long long int b) {
if (a > b) return a;
return b;
}
long long int maxx(long long int a, long long int b, long long int c) {
return maxx2(a,... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int num = 1;
struct node {
int to;
int next;
} road[400010];
int head[200010];
int low[100010], dfn[100010], cut[200010], tot = 0;
int cnt = 0, vis[100010], belong[100010];
int pre[200010][20], deep[200010];
void build(int from, int to) {
road[++num].next... | 2 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0;
bool flg = false;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') flg = true;
for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);
return flg ? -x : x;
}
int ans[310][310];
int a[310][310];... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
const int s = 30;
int n, d, x;
int a[maxn], b[maxn], q[maxn], to[maxn];
int getNextX() {
x = (x * 37LL + 10007) % 1000000007;
return x;
}
void initAB() {
int i;
for (i = 0; i < n; i = i + 1) {
a[i] = i + 1;
}
for (i = 0; i < n; i = i... | 2 |
#include<iostream>
#include<algorithm>
using namespace std;
int N,A[100];
int ans=1e9;
int main()
{
cin>>N;
for(int i=0;i<N;i++)cin>>A[i];
for(int X=-100;X<=100;X++)
{
int now=0;
for(int i=0;i<N;i++)now+=(X-A[i])*(X-A[i]);
ans=min(ans,now);
}
cout<<ans<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
int n, x[N], y[N], sx, sy, cnt1, cnt2, cnt3, cnt4, mx;
int main() {
scanf("%d%d%d", &n, &sx, &sy);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &x[i], &y[i]);
x[i] -= sx;
y[i] -= sy;
}
for (int i = 1; i <= n; i++) {
if (y[i] >= ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, b, c, mn;
struct node {
int x, d;
};
int mem1[200001];
int mem2[200001];
vector<node> v[200001];
stack<node> q;
queue<int> ans;
void f(int x, int p) {
for (int i = 0; i < v[x].size(); i++) {
int nx = v[x][i].x;
int nd = v[x][i].d;
if (nx != p) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, l, r, s, c[1000];
double d, ans, f[110][100010], sum[100010];
inline long long read() {
long long x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[1005];
int main() {
int cc;
int n, m;
while (cin >> n >> m) {
for (int i = 1; i <= n; i++) cin >> a[i];
int ans = -0x3f3f3f3f;
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++) {
vector<int> ss, pp;
int sum = 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool isCoprime(int64_t a, int64_t b) {
if (a > b) {
swap(a, b);
}
if (a == 1) {
return true;
}
if (b % a == 0) {
return false;
}
for (int64_t d = 2; d <= b - a; ++d) {
if (a % d == 0 and (b % d == 0 or b % (b / d) == 0)) {
return false;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
char ch = 0;
int x = 0, flag = 1;
while (!isdigit(ch)) {
ch = getchar();
if (ch == '-') flag = -1;
}
while (isdigit(ch)) {
x = (x << 3) + (x << 1) + ch - '0';
ch = getchar();
}
return x * flag;
}
struct edge {
int to, nxt;... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long int infinity = 9e18;
string getString(string s) {
if (s.size() == 0) return "-1";
int i = 0;
while (i < s.size() && s[i] == '0') i++;
if (i == s.size())
return "0";
else
return s.substr(i, s.size() - i);
}
string get(string s, int x, int y)... | 3 |
#include <bits/stdc++.h>
int getbit(long long x, int y) { return (x >> y) & 1; }
long long getoff(long long x, int y) { return x ^ ((1ll) << y); }
using namespace std;
int n, k, pos, p[410], c[410][410];
vector<int> vt[410];
vector<int> f[410][410];
void dfs(int u, int cha) {
for (int i = 0; i <= n; ++i) f[u][i].resi... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
bool f;
int n, i, j;
int card[9];
bool judge (int a, int b, int c){
if (a == b && b == c) return true;
else if (a + 1 == b && a + 2 == c) return true;
return false;
}
int win(){
sort(card, card + 9);
do{
... | 0 |
#include <iostream>
#include <algorithm>
using namespace std;
const long long INF = 1000000000000000;
int main() {
int a, b, q; cin >> a >> b >> q;
long long s[100010], t[100010];
s[0] = t[0] = -INF;
for (int i = 1; i <= a; i++) {
cin >> s[i];
}
for (int i = 1; i <= b; i++) {
cin >> t[i];
}
s[a + 1] = INF... | 0 |
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;
int main()
{... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int N;
cin >> N;
set<int> s;
map<int, int> m, mm;
for (int i = 0; i < N; ++i) {
int x;
cin >> x;
s.insert(x);
m[x]++;
}
if (s.size() != 2) {
cout << "... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long md = 1e9 + 7;
const long long MD = md * 100;
const int xn = 2e3 + 10;
const int xm = 4e6 + 10;
const int SQ = 320;
const int sq = 1e3 + 10;
const long long inf = 1e18 + 10;
long long power(long long a, long long b) {
return (!b ? 1
: (b & 1 ? ... | 5 |
#include <bits/stdc++.h>
struct I_Node {
int x = 0;
int k = 0;
long long int subtract = 0;
};
struct T_Node {
int start;
int end;
int height;
int root;
};
I_Node segtree[4 * 300010];
T_Node tree[300010];
int roots[300010];
int name[300010];
int name_inv[300010];
int curr_name = 0;
std::vector<std::vector<... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int N, M;
vector<vector<int>> occur;
string S;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> M >> S;
occur.assign(M, vector<int>(M, 0));
for (int i = 0; i + 1 < N; i++) {
int x = S[i] - 'a';
int y = S[i + ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300007;
const int IT = 500000;
struct xorshift {
unsigned x, y, z, w;
xorshift() : x(123456789), y(328932), z(7777777), w(898329832) {}
unsigned dsljhfdskjfdshkjfds() {
unsigned t = x ^ (x << 11);
x = y;
y = z;
z = w;
return w = w ^ (... | 6 |
#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long ll;
//using ll=long long;
using vll=vector<ll>;
ll nCr(int n, int r)
{
ll ret=1;
if(r*2>n) r=n-r;
for(int i=0;i<r;i++)
{
ret*=(n-i);
ret/=(i+1);
}
return ret;
}
int main(void)
{
int n, a,... | 0 |
#include<bits/stdc++.h>
#define lowbit(x) x&(-x)
#define ll long long
#define mod 998244353
using namespace std;
int x[200001];int y[200001];int lsh[200001];int cnt;ll ans=0; int n;
struct point {
int x,y;
bool operator<(const point &gv)const{
return gv.x<x;}
}p[200001];ll tree[200001];ll tree2[200001];
int query(in... | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pb push_back
#define PII pair <int,int>
#define PLL pair <ll,ll>
#define mp make_pair
#define xx first
#define yy ... | 0 |
#include <iostream>
#include <cstdio>
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
int N;
int64 S,X[MAXN],P[MAXN],ans;
void Solve() {
scanf("%d%lld",&N,&S);
for(int i = 1 ; i <= N ; ++i) {
scanf("%lld%lld",&X[i],&P[i]);
}
int L = 1,R = N;... | 0 |
#include <bits/stdc++.h>
using namespace std;
char str[5050];
short lcp[5050][5050], f[5050][5050];
int ans[5050];
int main() {
scanf("%s", str + 1);
int len = strlen(str + 1);
for (int i = len; i >= 1; --i) {
for (int j = 1; j <= len; ++j) {
if (str[i] == str[j]) {
lcp[i][j] = lcp[i + 1][j - 1]... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long n, i, j;
string s1, s2;
cin >> s1 >> s2;
scanf("%lld", &n);
string s3[n], s4[n];
for (i = 0; i < n; i++) {
cin >> s3[i] >> s4[i];
}
string tm1, tm2;
tm1 = s1;
tm2 = s2;
for (i = 0; i < n; i++) {
cout << tm1 << " ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 255;
const int RIGHT = 1;
const int DOWN = 2;
int nowarn;
int n, m, a[MAXN][MAXN];
int ALLST, EMPTYST, GRIDST, UDST, LRST;
map<int, int> f[2];
void add_to(int cur, int S, int S2) {
f[cur ^ 1][S2] = (f[cur ^ 1][S2] + f[cur][S]) % M... | 6 |
#include<iostream>
using namespace std;
int main()
{
int n, r, k;
cin>>n>>r;
if(n>=10)
cout<<r;
else
cout<<r+100*(10-n)<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
map<pair<int, pair<int, int> >, bool> v;
int n = s.size();
int i;
int x = 0, y = 0;
long long ans = 0;
for ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
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;
}
int main() {
int i, j, k;
string s1, s2, s3, s4, s5;
s1 = "Danil";... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5000 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1);
template <class T, class S>
inline void add(T& a, S b) {
a += b;
if (a >= mod) a -= mod;
}
templat... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
map<string, int> record;
struct player {
string ratings;
string name;
int scr;
void getratings(int bnum) {
if (bnum * 2 > n) {
ratings = "noob";
return;
}
if (bnum * 5 > n) {
ratings = "random";
return;
}
if (bnum *... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
long long n, a, b, x, y, t, m, c, p;
string s;
bool bole, bolo;
int main() {
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'C') {
if (p) {
m++;
p = 0;
}
c++;
if (c == 5) {
m++;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, m, x, i, flag = 0;
cin >> a >> m;
x = a;
for (i = 1; i <= (2 * m); i++) {
x += x % m;
if (x % m == 0) {
flag = 1;
break;
}
}
if (flag == 0)
cout << "No";
else
cout << "Yes";
}
| 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int N = 1 << 20;
long long lazy[N << 1], val[N << 1], sum[N << 1], mul[N << 1], mn[N << 1],
mnpos[N << 1];
void pd(int i, int l, int r) {
if (lazy[i] != -1e18) {
val[i] = lazy[i];
sum[i] = lazy[i] * mul[i];
if (0 <= sum[... | 3 |
#include <bits/stdc++.h>
#define vc vector<ll>
#define um unordered_map<ll,ll>
#define ll long long
#define rep(i,a,b) for(__typeof(a) i=a; i<b; i++)
#define si(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define ss(a) a.second
#define ff(a) a.first
#define pb push_back
#define repit(i,a) for(auto i=a.begin(); ... | 5 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int x = 0, y = 0;
cin >> x >> y;
cout << min({x, y, (x + y) / 3}) << "\n";
}
int main() {
int t = 0;
cin >> t;
while (t--) {
solve();
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long* input(long long n) {
long long* arr = new long long[n];
for (long long i = 0; i < n; i++) cin >> arr[i];
return arr;
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
signed main() {
long long n;
cin >> n;
l... | 2 |
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<unordered_map>
#include<functional>
#include<map>
#include<iomanip>
#include<limits>
#include<unordered_set>
#include<cmath>
#include <numeric>
#include <array>
#include<utili... | 0 |
#include <bits/stdc++.h>
const int N = 600100;
using namespace std;
int a[N];
long long sum1[N];
long long sum2[N];
long long pre_sum1[N];
long long pre_sum2[N];
long long inc_sum1[N];
long long inc_sum2[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i = 1; i <= n; i++)... | 3 |
#include<cstdio>
using namespace std;
int n;
int a[100]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
scanf("%d",&n);
printf("%d",a[n-1]);
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
vector<int> di[N];
int s[8];
int main() {
for (int i = (int)(1); i <= (int)(N - 1); i++)
for (int j = (int)(1); j <= (int)((N - 1) / i); j++) di[i * j].push_back(i);
int T;
scanf("%d", &T);
while (T--) {
int x, y, z, ans = 0;
scanf(... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
unsigned long long Total;
unsigned long long Array[200001];
unsigned long long Brray[200001];
unsigned long long Crray[200001];
unsigned long long Count[101];
int main(void) {
register unsigned long long i, j;
cin >> Total;
for (i = 1; i <= Tot... | 6 |
#include <bits/stdc++.h>
using namespace std;
int arr[100][100];
int vis[100][100];
int n;
int in(int r, int c) { return r >= 0 && r < n && c >= 0 && c < n; }
int edge(int r, int c) { return !in(r, c) || (arr[r][c] == 1); }
int main() {
cin >> n;
pair<int, int> topLeft4(-1, -1), bottomRight4(-1, -1);
int nums[5] ... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using ld = long double;
using pii = pair<int, int>;
template <class F>
void bleh(int i, int n, F f) {
f(i);
poop(i + 1, n, f);
}
template <class F>
void poop(int i, int n, F f) {
return (i == n) ? void() : bleh(i, n, f);
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;
int main(){
ll N; cin >> N;
vector<ll> T(N), A(N), V(N);
for(int i = 0; i < N; i++) cin >> T[i];
for(int i = 0; i < N; i++) cin >> A[i];
V[0] = 1;
if(T[N-1] != A[0]){co... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, k;
cin >> n >> k;
long long int i, arr[n];
for (i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n, greater<int>());
long long int max = arr[0], min = 0, ans = 0;
for (... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
string ans = "0000000000";
for (int i = 0; i < n; ++i) {
if (s[i] == 'L') {
for (int j = 0; j < 10; ++j) {
if (ans[j] == '0') {
ans[j]... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char n[5] = "";
for (int i = 0; i < 4; i++)
cin >> n[i];
sort(n, n + 4);
cout << (string(n) == "1479" ? "YES" : "NO") << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int h, m, nQ;
const int MAX_N = int(2e5) + 10;
set<int> emptySet[MAX_N];
vector<int> seqs[MAX_N];
int id[MAX_N], idx[MAX_N], cnt[MAX_N];
int nId;
int findNext(set<int>& s, int me) {
set<int>::iterator it = s.lower_bound(me);
if (it == s.end())
return *s.begin();
e... | 3 |
#include <bits/stdc++.h>
using namespace std;
int U, a[10], C[100][100];
int cur[100], nxt[100];
int solve2() {
int i, j, k, ret = 0;
int L = 0;
for (i = 0; i < 10; i++) L += a[i];
memset(cur, 0x00, sizeof(cur));
cur[0] = 1;
for (i = 0; i < 10; i++) {
memset(nxt, 0x00, sizeof(nxt));
for (j = 0; j <=... | 2 |
#include <bits/stdc++.h>
using namespace std;
int long long n, i, a, b[100005], ans, ans1;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> a;
for (i = 1; i <= n; i++) {
cin >> b[i];
}
if (n == 1) {
cout << 0;
return 0;
}
sort(b + 1, b + n + 1);
ans =... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
int n, m, t, q;
vector<int> G[N];
map<int, int> M;
set<int> S;
struct p {
int x, y;
};
int a[N], ans[N];
int main() {
scanf("%d%d%d", &n, &m, &t);
int sum = 0;
for (int i = (1); i <= (m); i++) scanf("%d", &a[i]), sum +... | 3 |
#include <bits/stdc++.h>
using namespace std;
int arr[1005][1005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, tmp = 0;
cin >> n;
for (int i = 1; i <= n / 4; i++) {
for (int j = 1; j <= n / 4; j++) {
for (int x = 1; x <= 4; x++) {
for (int y = 1; y ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n], x[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int cnt = 1, temp = 0;
int prim[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
for (int j = 0; j < 11; j++)... | 2 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
const int M=300005;
const int N=998244353;
int n;
ll m,x,y,a,b,k,fact[M],inv[M];
int modpow(int x,int p,int m){
if(p==0)return 1;
int k=modpow(x,p/2,m)%m;
k=(1LL*k*k)%m;
if(p%2==1)k=(1LL*k*x)%m... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, p[100100], cnt, flag[100100], inv[100100];
void shai() {
for (long long i = 2; i <= n; i++) {
if (flag[i] == 0) p[++cnt] = i;
for (long long j = 1; j <= cnt && i * p[j] <= n; j++) {
flag[i * p[j]] = 1;
if (i % p[j] == 0) break;
}
}
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int num[maxn];
vector<pair<int, int> > edges[maxn];
int dfs(int v, int dad, long long dis) {
if (dis > num[v]) return 0;
int res = 1;
for (int i = 0; i < edges[v].size(); i++) {
int vv = edges[v][i].first;
int ww = edges[v][i].second... | 3 |
#include<cstdio>
const int N = 1000000;
int prime[N] = {0},num_prime = 0;
int isNotPrime[N] = {1, 1};
int main()
{
int n;
for(long i=2; i<(2<<17); i++)
{
if(!isNotPrime[i])
prime[num_prime++]=i;
for(long j = 0 ; j < num_prime && i * prime[j] < N ; j ++)
{
i... | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll N;
vector<P> A; //(活性度、番号)
vector<vector<ll>> dp(2010, vector<ll>(2010, 0));
ll res = 0;
int main(){
cin >> N;
ll a;
for(ll i = 1; i <= N; i++){ cin >> a; A.push_back({a, i}); }
sort(A.begin(), A.end());
reverse... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const long double pi = acos(-1);
const int MOD = 1e9 + 7;
int get(int n) {
int r = 0;
while (n) {
r += n % 10;
n /= 10;
}
return r;
}
int main() {
int n;
cin >> n;
set<int> r;
f... | 1 |
#include <bits/stdc++.h>
const int N = 100010;
long long t[N];
long long Ans[N];
long long sum[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%I64d", &t[i]);
std::sort(t + 1, t + n + 1);
std::reverse(t + 1, t + n + 1);
for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + t[i];
... | 2 |
#include<iostream>
#include<string>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
for (int i = 0; i < 111; i++) {
s = s.substr(1) + s[0];
if (s == t) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
char arr[62];
void def() {
int k = 0, l = 0;
for (int i = 0; i < 62; i++) {
if (i < 26)
arr[i] = 'A' + i;
else if (i < 52)
arr[i] = 'a' + k++;
else
arr[i] = '0' + l++;
}
}
int main() {
def();
int t;
cin >> t;
while (t--) {
int... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
bool vis[maxn];
vector<pair<int, int> > g;
bool dfs(int node, int t) {
if (vis[node]) return false;
if (node == t) return true;
vis[node] = true;
bool ans = false;
for (int i = 0; i < (int)g.size(); i++) {
int l_atual = g[node].first;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
pair<long long, long long> par[MAXN];
vector<pair<long long, long long>> edge;
;
long long n, ans;
void input();
bool is_lucky(long long a);
long long get_par(long long u);
void merge(long long u, long long v);
void merge1(long long u, long long v)... | 5 |
#include <bits/stdc++.h>
using namespace std;
int gi() {
int res = 0, w = 1;
char ch = getchar();
while (ch != '-' && !isdigit(ch)) ch = getchar();
if (ch == '-') w = -1, ch = getchar();
while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar();
return res * w;
}
const int MAX_N = 1e6 + 5;
int N, flag, ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, p;
int main() {
long long l, r, i, j, b, ans;
cin >> n >> l >> r >> k;
p = (r - l + n) % n + 1;
if (k - p < 0) {
cout << -1 << endl;
return 0;
}
if (k - p == 0) {
cout << n - p + 1 << endl;
return 0;
}
if (k - p <= p) {
co... | 4 |
#include <bits/stdc++.h>
using ll = long long;
const ll N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ll SZ = 101;
const double eps = 1e-9;
using namespace std;
void solve() {
ll n, k;
cin >> n;
vector<pair<ll, ll> > a(n);
vector<ll> pfx(n, 0);
for (ll(i) = 0; i < (n); i++) cin >> a[i].f... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c;
cin >> n >> a >> b >> c;
cout << max(min(min(a, b) * (n - 1), min(a, b) + (n - 2) * c), 0);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
const int inf = 1e9;
int n, m, high[N], nxt[N];
int visit[N * 2];
vector<pair<int, int> > E;
vector<int> G[N];
struct Dinic {
int source, sink, n;
struct edge {
int to, c, f;
edge(int to, int c, int f) : to(to), c(c), f(f) {}
};
vector<e... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n;
char x;
cin >> n >> t;
if (t == 10 && n == 1) {
cout << "-1";
return 0;
}
if (t == 10 && n > 1) {
for (int i = 1; i <= n - 1; i++) {
if (i >= 10) {
cout << i % 10;
} else {
cout << i;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int suma[100005], sumb[100005];
int a[100005], n;
struct Node {
int s, t;
} ans[100005];
int num;
bool cmp(Node x, Node y) { return x.s < y.s; }
int main() {
while (scanf("%d", &n) != EOF) {
memset(suma, 0, sizeof(suma));
memset(sumb, 0, sizeof(sumb));
for (... | 2 |
#include <bits/stdc++.h>
using std::swap;
const int maxn = 610, maxm = 200010;
int N, n, m, P;
int fs[maxn], oth[maxm], next[maxm];
int id[maxn], od[maxn];
bool v[maxn];
int d[maxn][maxn], a[maxn][maxn];
void sol(int x) {
if (v[x]) return;
v[x] = 1;
int i, j, t;
for (i = fs[x]; i; i = next[i]) {
sol(t = oth... | 5 |
#include <bits/stdc++.h>
using namespace std;
ifstream fin(
""
".in");
ofstream fout(
""
".out");
const int MAX_N = int(2e5) + 20;
int main() {
ios_base::sync_with_stdio(false);
vector<pair<long long, long long>> seg(MAX_N);
map<long long, long long> cnt;
int n;
cin >> n;
for (int i = 0; i <... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, t1, ans[1005], cnt;
bool used[1005];
char ch;
int main() {
scanf("%d%c", &t1, &ch);
while (ch == ',') {
used[t1] = true;
scanf("%d%c", &t1, &ch);
}
used[t1] = true;
for (int i = 1; i <= 1000; ++i) {
if (used[i]) {
for (int j = i; used[j]; ... | 3 |
#include "bits/stdc++.h"
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;
void Main() {
ll n;
cin >> n;
vector<ll> C(n);
rep(... | 0 |
#include <bits/stdc++.h>
using namespace std;
int t, x, y, n, k;
int main() {
cin >> t;
while (t--) {
cin >> x >> y >> n;
k = (n / x * x + y > n) ? n / x - 1 : n / x;
cout << k * x + y << "\n";
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200 * 1000 + 10;
vector<int> g[N];
vector<long long> w[N];
vector<long long> p[N];
long long sum[N];
long long minw[N];
long long maxw[N];
bool ok = true;
map<pair<int, int>, long long> delta;
void dfs2(int v, int par) {
for (int i = 0; i < g[v].size(); i++)... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 3e3 + 5, MXX = 23;
const long long mod = 1e9 + 7, inf = 1e18 + 6;
vector<int> G[MX];
long long dp[MX][MX], sz[MX], par[MXX][MX], hig[MX], mxa, n;
void dfs(int u) {
for (auto v : G[u])
if (v != par[0][u]) {
par[0][v] = u;
hig[v] = hig[u] + 1;... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = 3.14159265359;
vector<long long> primes;
void GeneratingPrimes(int top) {
vector<bool> p(top + 1, 1);
p[0] = p[1] = 0;
for (int i = 2; i <= sqrt(top); i++) {
if (p[i]) {
for (int j = i * i; j <= top; j += i) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int solve() {
int n, i, j, k, m;
cin >> n;
vector<int> v(n);
for (i = 0; i < n; ++i) cin >> v[i];
set<int> st(v.begin(), v.end());
v.clear();
for (int x : st) v.push_back(x);
sort(v.begin(), v.end());
int flg = 1;
for (i = 0; i < v.size() - 1; ++i) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 20;
int tree[2 * MAXN];
int tree_min[2 * MAXN];
int tree_max[2 * MAXN];
void update(int v, int vl, int vr, int tl, int tr, int val) {
if (vl > tr || tl > vr) {
return;
}
if (tl <= vl && tr >= vr) {
tree[v] += val;
return;
}
int vm... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int __ = 505;
int b[__][10005];
int fi[__];
int xorxy(int n, int m) {
int i = 1;
for (int j = 1; i <= n && j <= m; j++) {
int x = 0;
for (int k = i; k <= n; k++)
if (b[k][j]) {
x = k;
break;
}
if (!x) continue;
for (int ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const long long LINF = INF * (long long)INF;
const int MAX = 4 * 1000 * 1000 + 47;
const int MIN = 2 * 1000 * 100 + 47;
string A[MIN];
string s;
int U[MIN];
int U1[MIN];
struct node {
int next[2];
int... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, m, j;
cin >> n >> m;
int a1[n];
int a2[m];
for (i = 0; i < n; i++) {
cin >> a1[i];
}
for (i = 0; i < m; i++) {
cin >> a2[i];
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (a1[i] == a2[j]) {
cout <... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.