solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int val;
map<int, int, greater<int> > mp;
for (int i = 1; i <= n; i++) {
cin >> val;
mp[val]++;
}
int lim = n / 2;
if (mp.size() <= 2) {
cout << 0 << " " << ... | 1 |
#include <iostream>
int main()
{
std::ios_base::sync_with_stdio(false);
int N, ans = 0;
std::cin >> N;
while (N > 0) {
ans += N % 10;
N /= 10;
}
std::cout << (ans != 1 ? ans : 10) << std::endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
string s[105];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> s[i];
string h = "12345RGBYW";
int ans = 12;
for (int i = 0; i < 1024; i++) {
bool f[256] = {};
int cnt = 0;
for (int j = 0; j < 10; j++) {
if (i & (1 << j)) f[h[j]... | 3 |
#include <bits/stdc++.h>
using namespace std;
void solve();
long long int power(long long int n, long long int k) {
if (k == 0) return 1;
if (k % 2) return (n * power(n, k - 1)) % 1000000007;
return power((n * n) % 1000000007, k / 2);
}
long long int gcd(long long int a, long long int b) {
return b ? gcd(b, a %... | 5 |
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c = 1;
;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (int i = 1; i < n; i++) {
while (a[i] == a[i - 1]) i++;
a[c++] = a[i];
}
for (int i = 2; i < c; i++) {
if ((a[i] == a[i - 1]... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 2147483647;
const long long LINF = 1e18;
const long double PI = 4 * atan((long double)1);
template <class T, class S>
ostream& operator<<(ostream& os, const pair<T, S>& p) {
os << p.first << " " << p.second;
return os;
}
templ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
long int x;
cin >> x;
cout << x/500 * 1000 + (x%500)/5 * 5;
}
| 0 |
#include <bits/stdc++.h>
int n, m, s, t, ppl, maxppl, idd;
int a[20000], id[20000];
bool inq[20000];
int toInt(int hh, int mm, int ss) { return hh * 3600 + mm * 60 + ss; }
int main() {
int hh, mm, ss, oldestId, newestId;
scanf("%d%d%d", &n, &m, &t);
for (int i = 0; i < n; i++) {
scanf("%d:%d:%d", &hh, &mm, &s... | 4 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int n0 = 1003;
int n, sz[n0], root, d, mx, h[n0], ep, has[n0], sub;
bool flag;
vector<int> g[n0], q, can;
array<int, 2> cur;
void get() {
if (q.empty()) return;
cout << "? " << (int)(q).size() <<... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
long long dp[N][1 << N];
bool vis[1 << N];
bool Adj[N][N];
int n, m;
long long sub;
long long solve(int idx, int mask, int p, int st) {
if (dp[idx][mask] != -1) return dp[idx][mask];
long long res = 0;
for (int u = int(st); u <= int(n); u++) {
if... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> sq, nsq, cc;
int main() {
int n, x;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &x);
long long num = (long long)sqrt(x);
if (num * num == x)
sq.push_back(x);
else
nsq.push_back(x);
}
int l1 = sq.size();
... | 5 |
#include "bits/stdc++.h"
using namespace std;
int main(){
int a,b;cin>>a>>b;
cout<<--a*--b;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
return b < a ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
const int MAXN = 65;
map<int, bitset<MAXN << 1> > mp;
int n... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pi2 = pair<int, int>;
using pl2 = pair<ll, ll>;
using cpl = complex<ld>;
const ld pi = 3.14159265358979323846264338327950288;
const ld tau = 2 * pi;
const int dx[4] = {0, 1, 0, -1}, dy[4] = ... | 5 |
#include <bits/stdc++.h>
int main() {
int n, p = 0, q = 0, a = 0, b = 0;
int t, x, y;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d %d %d", &t, &x, &y);
if (t == 1) {
a = a + x;
p++;
} else if (t == 2) {
b = b + x;
q++;
}
}
if (a >= (p * 5)) {
printf("L... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long S = 0, f[26][26];
char a[111510], b[111510], c[111510];
int main() {
scanf("%s%s%d", a, b, &m);
for (int i = 0; i < 26; ++i) {
for (int j = 0; j < 26; ++j) f[i][j] = 1ll << 30;
f[i][i] = 0;
}
for (char x[3], y[3]; m--;) {
scanf("%s%s%... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, p;
long long d, w;
cin >> n >> p >> w >> d;
for (long long i = 0; i < w; i++) {
if ((p - i * d) % w == 0) {
if (p - i * d >= 0 && n - i - (p - i * d) / w >= 0) {
cout << (p - i * d) / w << " " << i << " " << n - i - (p - i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int tt;
cin >> tt;
while (tt--) {
string k, s;
cin >> k >> s;
int pos[26];
for (int i = 0; i < 26; i++) {
pos[k[i] - 'a'] = i;
}
int ans = 0;
for (int i = 1; i < s.size(); i++) {
ans += abs(pos[s[i] - 'a'] - pos[s[i... | 1 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,h,maxh=0,r=0;
cin>>n;
for(int i=0;i<n;++i){
cin>>h;
if(maxh<=h){
r++;
maxh=h;
}
}
cout<<r<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
void solveA() {
int ar[6], n;
cin >> n;
for (int i = 0; i < n; i++) cin >> ar[i];
sort(ar, ar + n);
cout << ar[n / 2];
}
void solveB() {
int n;
cin >> n;
vector<pair<int, int>> rez;
pair<int, int> ar[102];
for (int i = 1; i <= n; i++) {
cin >> ar[i].... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
struct point {
long long x, y;
point() {}
point(long long _x, long long _y) {
x = _x;
y = _y;
}
long long operator^(const point &b) const { return x * b.y - y * b.x; }
point operator-(const point &b) const { return point(x - b... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 100000000000000001;
const long long mod = 1073741824;
long long pow(long long x, unsigned long long y, long long p) {
long long res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x ... | 2 |
#include <bits/stdc++.h>
#pragma optimizitaion_level 3
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
using namespace std;
int n, h;
vector<int> b;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> h;
b.resize(n);
for (auto &i : b) cin >> i;
for (in... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 7;
const long double pi = 3.14159;
const long long INF = 1e9 + 7;
double ans, realans, a, b, c, d;
int main() {
ios_base::sync_with_stdio();
cin.tie(0);
cout.tie(0);
;
srand(time(0));
;
cin >> a >> b >> c >> d;
ans = a / b;
realan... | 2 |
#include <bits/stdc++.h>
using namespace std;
int k, c[1005][1005], mod = 1000000007, a[1005], dp[1005];
int add(int a, int b) {
long long c = a + b;
if (c >= mod) c -= mod;
return (int)c;
}
int main() {
c[0][0] = 1;
for (int i = 1; i <= 1003; ++i) {
c[i][0] = 1;
for (int j = 1; j <= i; ++j) {
c... | 3 |
#include <iostream>
#include <vector>
int main() {
std::vector <int> v;
int N, q, val;
std::cin >> N;
for (int i = 0; i < N; i++) {
std::cin >> q;
if (q == 0) {
std::cin >> val;
v.push_back(val);
}
else if (q == 1) {
std::cin >> v... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
list<char> L;
for (int i = 0; i < s.length(); i++) L.push_back(s[i]);
list<char>::iterator it1 = L.begin();
list<char>::iterator it2 = L.begin();
++it2;
for (; it2 != L.end();)
if (*it1 == *it2) {
list<char>::iterat... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10010, mo[] = {1224469897, 1503325967, 1336143462, 937397015};
const long long MAX = 5000000;
const int prime[][7] = {{7, 17, 37, 47, 61, 97},
{11, 13, 41, 43, 67, 89},
{2, 3, 23, 31, 53, 71, 83},
... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct Tree {
Tree *ls, *rs;
int l, r;
long long sum;
bool same;
int x;
long long add;
Tree() {}
~Tree() {
if (ls) delete ls;
if (rs) delete rs;
}
void up() {
if (ls->same && rs->same && ls->x == rs->x) {
same = 1;
x = ls->x;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct fastio {
char s[100000];
int it, len;
fastio() { it = len = 0; }
inline char get() {
if (it < len) return s[it++];
it = 0;
len = fread(s, 1, 100000, stdin);
if (len == 0)
return EOF;
else
return s[it++];
}
bool notend() {
... | 5 |
#include <iostream>
int main() {
int H, W; std::cin >> H >> W;
while (H--) {
std::string S; std::cin >> S;
std::cout << S << "\n" << S << "\n";
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, c[55][55];
int solve(int a, int b) {
int k, t, i, j, sum, min = 100000000;
for (k = 1; k <= n - a + 1; k++)
for (t = 1; t <= m - b + 1; t++) {
sum = 0;
for (i = k; i <= a + k - 1; i++)
for (j = t; j <= b + t - 1; j++) sum += c[i][j];
... | 2 |
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+5;
int sum[N];
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i){
int l,r;
scanf("%d%d",&l,&r);
sum[l]++; sum[r+1]--; l--;
for(int j=1,nxt;j<=l;j=nxt+1){
nxt=min(l/(l/j),r/(r/j));
if(l/j<r/j) sum[j]++,sum[nxt+1]--;
}
}
for(i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int N = 4e2 + 99;
const int A = 5;
const int B = 4;
int pref[N][N], t[N][N];
int n, m;
deque<pair<int, int>> q;
int ans = INF;
void dodaj(int i, int j, int z) {
int suma = (pref[j - 1][z - 1] - pref[i][z - 1]);
suma += (j - i - 1 -
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
vector<bool> prime(1e6 + 5, true);
void SieveOfEratosthenes(long long int n) {
prime[0] = false;
prime[1] = false;
for (long long unsigned int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (long long unsigned int i = p * p; i... | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
const int MAX_N = 100005;
int N, Q;
lint A[MAX_N], X[MAX_N], S[MAX_N], odd[MAX_N], even[MAX_N];
bool check(int q, int i){
int j = distance(A, lower_bound(A, A+N, 2*X[q]-A[i]));
int cnt = i - j;
if(A[i]+A[j]>=2*X[q]) cnt++;
if(cnt>N-... | 0 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
int t;
cin >> t;
while (t--) {
int n, x, sum = 0;
cin >> n;
for (int i = 0; i < n; i++) cin >> x, sum += x;
cout << (sum + n - 1) / n << endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[200005];
int main()
{
ll n, k, x;
cin>>n>>k>>x;
for(int i=0;i<n;i++){
cin>>arr[i];
}
sort(arr, arr+n);
std::vector<ll> v;
ll cnt=0,xtra=0;
for(int i=1;i<n;i++){
ll d=arr[i]-arr[i-1];
if(d>x){
xtra=((d+x-1)/x)-1;
v.push_back(x... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int ans, tot, n, q, col[N], f[N], size[N], head[N], to[N << 1], ne[N << 1];
map<int, int> e[N];
struct SGT {
int L[N << 2], R[N << 2];
vector<int> v[N << 2][2];
void build(int k, int l, int r) {
L[k] = l, R[k] = r;
if (l == r) return;
... | 6 |
#include<bits/stdc++.h>
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
using namespace std;
struct Point {
double x,y;
Point(){}
Point(double x, double y): x(x),y(y){}
Point operator+(Point p) {return Point(x+p.x, y+p.y);}
Poi... | 0 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int n;
cin >> n;
vector<vector<long int> > a(n, vector<long int>(n));
vector<vector<long int> > p(n, vector<long int>(n, 1));
for(int i=0; i<n; ++i){
for(int j=0; j<n; ++j){
cin >> a[i][j];
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> v(n);
for (string& s : v) cin >> s;
for (char ch = 'a'; ch <= 'z'; ch++) {
char bs[100];
const int i = 49;
int mn = i, mx = i;
string* ps = 0;
for (string& s : v) {
if (s.empty()) continue;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long md = 998244353;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int test = 1;
while (test--) {
string s;
cin >> s;
string t;
cin >> t;
int i = 0;
long long ans[1 + t.length()];
int l = t.length();
while... | 3 |
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define llong long long
int T;
int n;
llong a[220];
llong B[110];
int op[220];
void ins(llong x)
{
for(int i=61;i>=0;--i)
if((x>>i)&1)
{
if(!B[i])
{
B[i]=x;
break;
}
x^=B[i];
}
}
bool find(llong x)
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long Lef[512345], Rig[512345];
char s[512345];
int main() {
int n, a, b, T;
cin >> n >> a >> b >> T;
scanf("%s", s);
for (int i = 0; i < n; i++) {
if (i == 0) {
Rig[i] = s[i] == 'w' ? 1 + b : 1;
} else {
Rig[i] = Rig[i - 1] + a + 1;
if... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, m, L[N][N], R[N][N], f[N][N];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1, k, l, r; i <= n; i++) {
for (scanf("%d", &k); k; k--) {
scanf("%d%d", &l, &r);
for (int j = l; j <= r; j++) {
L[i][j] = l, R[i][j] = r;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, q;
char str[105];
int num[15];
char st[105];
int cp, dp;
int l, r;
int next(int ty, int x) {
int tmp = x;
if (ty == 1) {
x++;
while (x <= r && st[x] == char('0' - 1)) x++;
}
if (ty == -1) {
x--;
while (x >= l && st[x] == char('0' - 1)) x--;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000003;
const int N = 1000006;
long long power(int a, int b, int md) {
int res = 1;
while (b > 0) {
if (b & 1) res = (res * 1LL * a) % md;
a = (a * 1LL * a) % md;
b /= 2;
}
return res;
}
int pr[N];
int main() {
long long n, k;
scanf(... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int mat[100][100];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> mat[i][j];
}
}
int row[100] = {0}, col[100] = {0}, ans = 0;
if (m < n) {
for (int i = 0; i < m; i++) {
int cmin ... | 1 |
#include <bits/stdc++.h>
const int MAX = 2e5 + 11;
using namespace std;
int N, A[MAX], L[MAX], R[MAX], B[MAX];
int main() {
scanf("%d", &N);
for (int i = 0; i < N; ++i) {
scanf("%d", &A[i + 1]);
}
stack<int> S;
for (int i = 1; i <= N; ++i) {
while (!S.empty() && A[S.top()] >= A[i]) {
S.pop();
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 5;
int a[N], n, d, dep[N], y, mx;
vector<int> vec[N];
void dfs(int x, int pa) {
if (pa == -1)
dep[x] = 0;
else {
if (a[x] == a[pa])
dep[x] = dep[pa];
else
dep[x] = dep[pa] + 1;
}
if (dep[x] > mx) {
mx = dep[x];
... | 5 |
#include<iostream>
#include<math.h>
#include<algorithm>
#include <stdlib.h>
using namespace std;
long long a[300002];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
int n;
long long m, ans;
cin >> T;
while (T--)
{
cin >> n;
ans = 0;
m = 0;
for (int i = 0; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using
namespace std;
template <typename T, class F = function<T(const T&, const T&)>>
class SparseTable {
public:
int n;
vector<vector<T>> sp;
F func;
SparseTable(const vector<T> &a , const F& f) : func(f) {
n = static_c... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t, c = 0, ans;
bool b = 0;
cin >> n >> t;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (!b && c + 86400 - x >= t) {
b = 1;
ans = i + 1;
} else
c += (86400 - x);
}
cout << ans;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int f[409][409];
char s[409], t[409];
int main() {
int T, i, j, k, n, m;
scanf("%d", &T);
while (T--) {
scanf("%s%s", s + 1, t + 1), n = strlen(s + 1), m = strlen(t + 1);
for (i = 1; i <= m; ++i) {
for (j = 1, k = 1; j <= n; ++j) {
while (j <= n ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MM = 320000;
const int LE = 1100000;
long long da[110000];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int q;
cin >> q;
while (q-- != 0) {
int n, m;
cin >> n >> m;
vector<string> vs(n);
for (int i = 0; i < n; i++) cin ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
struct matrix {
long long a[128][128];
};
void mul(const matrix &a, const matrix &b, matrix &c, int ogr) {
for (int i = 0; i <= (ogr); ++i)
for (int j = 0; j <= (ogr); ++j) {
c.a[i][j] = 0;
for (int l = 0; l <= (ogr); ++l) {
... | 5 |
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n; cin >> n;
vector<ll> la(n);
for (ll &a: la) cin >> a;
ll x = la[0];
for (int i = 1; i < n; ++i) {
if (i % 2) x -= la[i];
else x += la[i];
}
cout << x;
for (int i = 0; i < n-1; ++i) {
x = 2... | 0 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> arr;
typedef vector<arr> mat;
inline mat mul(mat a,mat b,int mod){
if((int)a.size()==1&&(int)a[0].size()==1){
mat res(b);
for(int i=0;i<(int)b.size();i++)
for(int j=0;j<(int)b[i].size();j++)
(res[i][j]*=a[0][0])%=mod... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int p = 131;
int n;
bool ok[N][20];
int sum[N][26];
long long del[N], add[N][26];
unsigned long long h[N], pw[N];
char s[N];
inline unsigned long long calc(int l, int r) {
return h[r] - h[l - 1] * pw[r - l + 1];
}
inline int find(int a, int b)... | 5 |
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long mod=1e9+7;
long long power(long long a,long long b)
{
return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;
}
long long M;
string C;
long long P[1<<17];
long long c[1<<17];
long long X[10];
int main()
{
cin>>M>>C;
if(C.size()==1)
{
if(M... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
for (int i = 0; i < n; i++) cout << (i & 1);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
long long tree[400009];
int mv[400009];
void build(int s, int t, int start) {
if (s == t) {
cin >> tree[start];
mv[start] = tree[start];
return;
}
int mid = (s + t) / 2;
build(s, mid, start * 2);
build(mid + 1, t, start * 2 + 1);
tree[start] = tree[s... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
const int K = 666;
static int cnt[N], ans, _ans[N];
int main() {
int n, q;
cin >> n >> q;
int a[n];
for (int i = 0; i < n; ++i) cin >> a[i];
int l[q], r[q], mo_l = 0, mo_r = 0;
for (int i = 0; i < q; ++i) cin >> l[i] >> r[i], --l[i];
int... | 2 |
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
vector<string> vs;
vs.push_back("1111110");
vs.push_back("0110000");
vs.push_back("1101101");
vs.push_back("1111001");
vs.push_back("0110011");
vs.push_back("1011011");
vs.push_back("1011111");... | 0 |
// B.
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
int main(int argc, char *argv[]) {
int n, k;
cin >> n >> k;
int sz = (n * (n + 1)) / 2;
vector<LL> a(n), v(sz);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int si = 0;
for (int i = 0; i < n; ++i) {... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long k, n, res;
int main() {
scanf("%I64d %I64d", &n, &k);
while (n % 5 == 0 && res < k) {
n /= 5;
res++;
}
res = 0;
while (n % 2 == 0 && res < k) {
n /= 2;
res++;
}
cout << n;
while (k--) printf("0");
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n, k;
cin >> n >> k;
int a[n + 1], b[10] = {0}, ans = 0;
for (int i = 1; i < n + 1; i++) {
cin >> a[i];
ans = ans + a[i] / 10;
b[10 - (a[i] % 10)]++;
}
for (int i = 1; i < 10; i++) {
while (k >... | 3 |
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <cmath>
#include <cfloat>
#define FOR(i,b,n) for(int i=b;i<n;i++)
#define REP(i,b,n) for(i=b;i<n;i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
using namespa... | 0 |
#include <bits/stdc++.h>
const int N = 2e5 + 10;
int n, u, v, cnt, d[N], parent[N];
std::set<std::pair<int, int> > far;
std::vector<int> graph[N];
void dfs(int v) {
if (d[v] > 2) far.insert({d[v], v});
for (int u : graph[v]) {
if (d[u] < 0) {
d[u] = d[v] + 1;
parent[u] = v;
dfs(u);
}
}
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXB = 1e7;
char buf[MAXB], *cp = buf;
inline void rd(int &x) {
x = 0;
int f = 1;
while (*cp < '0' || '9' < *cp) {
if (*cp == '-') f = -1;
cp++;
}
while ('0' <= *cp && *cp <= '9') x = (x << 3) + (x << 1) + *cp - 48, cp++;
x *= f;
}
const int MA... | 6 |
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e17;
long long MOD = 1e9 + 7;
long double eps = 1e-15;
long long m[100008];
pair<long long, long long> dp[41][100005];
bool vis[100005];
long long a, b;
long long n;
pair<long long, long long> DP(long long x, long long sum) {
if (sum >= a) return {0... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
const int U = 700;
const int S = 305;
const int L = 1e6 + 5;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int ch[4] = {'U', 'R', 'D', 'L'};
int block[N][N], last[N][N];
pair<int, int> q[N * N];
void go(int x, int y, int S, int ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long b[n + 1], a[n + 1];
for (long long i = 1; i <= n; i++) {
cin >> b[i];
}
a[1] = b[1];
long long maxn = a[1];
for (long long i = 2; i <= n; i++) {
maxn = max(maxn, a[i - 1]);
a[i] = b[i] + maxn;
}
f... | 2 |
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
if(n<1200)cout<<"ABC";
else if(n<2800)cout<<"ARC";
else cout<<"AGC";
return(0);
} | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int maxN = 110000;
int n, m, a[maxN];
int killers[maxN], nonkillers[maxN];
int candidates[maxN];
int main() {
scanf("%d%d", &n, &m);
int s = 0;
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
if (a[i] > 0) {... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>a>>b;
cout<<((a*10+b)%4==0?"YES":"NO")<<endl;
return 0;
}
| 0 |
#include <stdio.h>
constexpr int N = 1e5;
char vS[N+3], vT[N+3];
constexpr short K = 'A' - 1;
int main(void){
int i, q;char c1, c2;
scanf("%s%s", vS+1, vT+1);
vS[0] = 0; i = 1; while(vS[i] != '\0') {(vS[i] += vS[i-1] - K) %= 3; i++;}
vT[0] = 0; i = 1; while(vT[i] != '\0') {(vT[i] += vT[i-1] - K) %= 3;... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y, step;
} que[100005 * 2];
int n, k;
int vis[2][100005], dir[3][2] = {{1, 0}, {-1, 0}};
char wall[2][100005];
bool bfs() {
int f, r;
node p, q;
memset(vis, 0, sizeof(vis));
dir[2][0] = k;
dir[2][1] = 1;
f = 0, r = 1;
while (f < r) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long n;
cin >> n;
long long a = 0, b = 0;
long long ans = 0;
vector<pair<long long, long long> > v(n);
for (long long i = 0; i ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int mx = 1e6 + 5;
int par[mx], rnk[mx];
void init(int n) {
for (int i = 0; i < n; i++) par[i] = i, rnk[i] = 0;
}
int find(int x) {
if (par[x] == x)
return x;
else
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int nm = 100010;
const long long inf = 1000000000;
int n;
map<int, int> vt;
vector<pair<int, int> > xxx;
vector<int> total;
set<int> val;
map<int, int> newval;
int tree[2 * nm];
int demBeHon(int x) {
int l = 0, r = (int)total.size() - 1, kq = total.size();
while (... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
template <class T>
void chmax(T& a, T b) {
a = max(a, b);
}
template <class T>
void chmin(T& a, T b) {
a = min(a, b);
}
int dpl[4320][4320];
int dpr[4320][4320];
int ls, rs;
int n, p, c, h, t, qq, a,... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = (long long int)1e9 + 7;
const long long int inf = 1e18;
int solve() {
long long int n;
cin >> n;
vector<long long int> v(n + 11);
for (long long int i = 2; i <= n; i++) {
cin >> v[i];
}
vector<long long int> ans;
while (n > 0) {
... | 1 |
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;
ll dp[200][2][5];
int main(){
string s;int K;cin>>s>>K;
dp[0][0][0]=1;
rep(i,s.size())rep(j,2)rep(... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int N = 1 << 6 | 1;
const int inf = 0x3f3f3f3f;
const long long oo = 0x3f3f3f3f3f3f3f3fll;
int n, m;
int dp[41][N][N], w[N];
int dfs(int a, int nw, int sp) {
if (a == n + 1) return (sp == 0) ? 0 : inf;
int &r... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, width[201010], height[201010],
max1 = 0, i, max2 = 0, prefeixsum[201010], flag = 0, wid, hit, ans;
cin >> n;
width[0] = 0;
for (i = 1; i <= n; i++) cin >> width[i] >> height[i];
max1 = height[1];
long long pos = 1;
for (i = 2; i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int x, y;
string s;
class SegmentTree {
private:
vector<int> st, a, b, c;
int left(int p) { return (p << 1); }
int right(int p) { return (p << 1) + 1; }
void build(int p, int l, int r) {
if (l == r) {
if (s[l] == '(') {
st[p] = 0;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long x, y, n, i, ans;
typedef struct {
long long a, b;
} pp;
pp p[N];
bool compa(pp ta, pp tb) {
return abs(ta.a) + abs(ta.b) < abs(tb.a) + abs(tb.b);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (i = 0; i < n... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e7 + 5;
const int maxn = 1e4 + 5;
int main() {
int i, j, k, l, n, temp[maxn];
while (scanf("%d", &n) != EOF) {
for (i = 1; i <= n; i++) {
k = 0;
for (j = i; j <= (n * n / 2); j += n) {
if (j == i)
printf("%d", j);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<pair<int, int>> a;
for (int i = 0; i < n; i++) {
int t1, t2;
scanf("%d %d", &t1, &t2);
a.push_back(make_pair(t1, t2));
}
sort(a.begin(), a.end());
int ans = 0, mx = a[0].second;
for (int i = 1; i < n; i... | 3 |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
using vi=vector<int>;
#define PB push_back
#define ALL(x) x.begin(),x.end()
//#define LN cerr<<__LINE__<<endl
#define LN 0
using pi=pair<int,int>;
int read(){
int i;
scanf("%d",&i);
return i;
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t, n, x, a, b;
cin >> t;
while (t--) {
int d;
cin >> n >> x >> a >> b;
if (a > b) {
d = a;
a = b;
b = d;
}
if ((a - 1) > x) {
a -= x;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct node {
node *next;
int nodeIndex;
node(node *next, int index) {
this->next = next;
this->nodeIndex = index;
}
};
node *nodeArr[300001];
vector<int> path;
void pathDfs(int x, int y, bool *visited, bool &pathFound) {
node *src = nodeArr[x];
visited[... | 3 |
#include <bits/stdc++.h>
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int k;
int a[n];
for (k = 0; k < n; k++) scanf("%d", &a[k]);
int p = n - 2;
int i, j;
for (i = 0; i < p; i++) {
for (j = i + 2; j < n; j++) {
if (a[i] == a[j]) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int gi() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 3) + (x << 1) + ch - 48;
ch = getchar();
}
return x * f;
}
template <typename T>
inline boo... | 5 |
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef vector<int> vi;
const int INF = 1e9;
//Segment Tree
class SegmentTree{
public:
int n;
vi node;
vi ofset;
SegmentTree(vi a){
int n_ = a.size();
n=1;
while(n<n_)n*=2;
node = vi(2*n-1, INF);
for... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
vector<int> sosedi[maxn];
int parent[maxn], shagi[maxn], start[maxn], finish[maxn], n;
bool visit_vertex[maxn];
void dfs(int v, int predok) {
parent[v] = predok;
shagi[v] = shagi[predok] + 1;
for (auto p : sosedi[v])
if (p != predok) dfs(p... | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.