solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> a;
a.resize(n);
for (int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
long long ans = 0;
for (int i = 0; i < n; i++) {
ans += abs(a[i] - (i + 1));
}
cout << ans;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int n, a[1002];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i < n; i++)
for (int j = 1; j < n; j++)
if (i != j) {
int l = min(a[i], a[i + 1]), r = max(a[i], a[i + 1]),
x = min(a[j], a[j + 1]), y = max(... | 1 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1e5 + 5;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector<int> in(n + 1);
for (int i = 1; i <= n; i++) cin >> in[i];
vector<int> res;
for (int i = n; i >= 1; i--) {
int x ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, s[100005];
char t[100005];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &s[i]);
scanf("%s", t);
int tot = 0, ans = 0;
for (int i = 0; i < n; i++) {
if (t[i] == '1') ans = max(tot, ans + s[i]);
tot += s[i];
}
printf("%d\n... | 3 |
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
struct RollingHash{
typedef unsigned long long ull;
string S;
ull B;
int len;
vector<ull> hash,p;
RollingHash(){}
RollingHash(string S_,ull B_=1000000007LL):
S(S_),B(B_),len(S.length()),hash(len+1),p(len+1){
hash[0]... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int inf = 10000000;
vector<int> g[100005];
long long p[100005], m[100005], c[100005];
bool vis[100005];
void dfs(int u) {
vis[u] = 1;
long long pp = 0, mm = 0;
for (int i = 0; i < (((int)(g[u]).size())); i++) {
int v = g[u][i];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll N,K; cin >> N >> K;
vector<ll> A(N);
for (int i=0;i<N;++i) cin >> A[i];
sort(A.begin(),A.end());
ll ub=1e18,lb=-ub; ++ub,--lb;
while(ub-lb>1){
ll mid=(ub+l... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
cin >> n >> m >> k;
vector<int> v(n);
vector<pair<int, int> > vp(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
vp[i] = make_pair(v[i], i);
}
sort(begin(vp), end(v... | 2 |
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;
signed main(){
while(true){
int m,f,r;
cin>>m>>f>>r;
if(m==-1&&f==-1&&r==-1)break;
if(m==-1||f==-1)cout<<"F"<<endl;
else if(m+f>=80)cout<<"A"<<endl;
else if(m+f>=65)cout<<"B"<<endl;
else if(m+f>=50)cout<<"C... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> g;
vector<int> toposort;
vector<bool> visited;
unordered_map<string, int> edges;
int n;
void clear() {
for (int i = (0); i < (n); ++i) {
g[i].clear();
visited[i] = false;
}
toposort.clear();
}
void dfs(int v) {
if (visited[v]) return;
v... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
const int mod = 998244353;
int a[maxn], b[maxn];
long long dp1[maxn][maxn];
long long dp2[maxn][maxn];
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (int i = 1; i < n; ++i) b[i] = a[i + 1];
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr[5][5], i, j, k, p, l, d;
for (i = 0; i <= 3; i++) {
for (j = 0; j < 4; j++) cin >> arr[i][j];
}
d = 0;
for (i = 0; i <= 3; i++) {
if (arr[i][3] == 1) {
if (arr[i][1] == 1) d = 1;
if (arr[i][0] == 1) d = 1;
if (arr[i][... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long nxt() {
long long x;
cin >> x;
return x;
}
void solve() {
long long n = nxt(), k = 0;
vector<int> vc(n);
for (int i = 0; i < n; ++i) {
cin >> vc[i];
}
sort(vc.begin(), vc.end());
for (int i = 1; i < n; ++i) {
if (vc[i] - vc[i - 1] > 1) k ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
int color[200200];
vector<int> g[200200];
void dfs(int p, int u) {
printf("%d ", u);
if (color[u] == 1)
color[u] = -1;
else
color[u] = 1;
for (auto v : g[u])
if (v != p) {
dfs(u, v);
printf("%d ", u);
if (color[u] == 1)
c... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long x, n;
vector<long long> pms;
vector<long long> gs;
bool nisp[100005];
const long long md = 1000000007;
inline long long qp(long long x, long long y) {
long long rt = 1;
for (; y; y >>= 1, (x *= x) %= md)
if (y & 1) (rt *= x) %= md;
return rt;
}
vector<lo... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e4 + 5;
int n, m, a, b, ans[N], vis;
bool mark[N];
vector<int> v[N];
void dfs(int k) {
mark[k] = true;
for (int i = 0; i < v[k].size(); i++) {
if (!mark[v[k][i]]) {
dfs(v[k][i]);
}
}
ans[++vis] = k;
}
int main() {
scanf("%d %d", &n, &m... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long mxn = 505;
void solve() {
long long n, m;
cin >> n >> m;
vector<long long> a(n);
for (long long& x : a) cin >> x;
multiset<pair<long long, pair<long long, long long>>> f;
reverse(a.begin(), a.end());
a.push_back(-1e11);
reverse(a.begin(), a.e... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const int maxN = 111;
vector<int> g[maxN];
vector<int> grev[maxN];
double dp1[maxN];
double dp2[maxN];
void dfs1(int v) {
if (dp1[v] > 0.5) {
return;
}
for (auto u : g[v]) {
dfs1(u);
dp1[v] += dp1[u];
}
}
void dfs2(int v) {
if... | 3 |
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
string S;
cin >> S;
reverse(S.begin(), S.end());
cout << S << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long max3 = 1003;
const long long max4 = 10004;
const long long max5 = 100005;
const long long max6 = 1000006;
const long long max7 = 10000007;
const long long lg4 = 13;
const long long lg5 = 17;
const long long lg6 = 20;
const long long INF = 2LL * 1000000000;
c... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool isprime(int64_t n) {
for (int64_t i = 2; i * i <= n; ++i) {
if (n % i == 0) {
return false;
}
}
return true;
}
int64_t factorial(int64_t n) {
return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
int64_t gcd(int64_t a, int64_t b) {
if (a == 0)... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, i1, x1, ans, res, kol, k[2], a[105][105], x[105];
int main() {
ios::sync_with_stdio(false);
cin >> n >> m >> kol;
if (n >= m)
for (i = 0; i < n; i++)
for (j = 0; j < m; j++) cin >> a[i][j];
else {
for (i = 0; i < n; i++)
for (j = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, ans;
string str;
map<string, long long> m1;
long long solve() {
cin >> str;
n = (long long)str.size();
for (long long i = 0; i <= n - 10; ++i) {
string s = str.substr(i, 10);
vector<long long> v1;
for (long long j = 0; j <= 9; ++j) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const double PI = 4 * atan((double)1);
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int t;
cin >> t;
w... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
string s;
cin >> n >> s;
int cnt = n - 1;
for (int i = 0; i < n; i++) {
if (s[i] == '>' || s[n - 1 - i] == '<') {
cnt = i;
break;
}
}
cout << cnt << endl;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MaxQ = 15e4, N = 5e4 + 1, LOG = 16, SQ = 9;
int ans[MaxQ], a[N], st[N], fn[N], par[N], hd[N], timer, n, q;
vector<int> g[N];
vector<pair<int, int> > Q[N];
int t[LOG * (1 << SQ)][2], sz;
int add(const int &x) {
int cur = 0;
for (int i = LOG - 1; i >= 0; i--) {
... | 5 |
#include <bits/stdc++.h>
#define INF 999999999
using namespace std;
typedef pair<int,int>P;
const int MAX_N = 100000;
vector<P> G[MAX_N];
int d[MAX_N];
bool visited[MAX_N];
void dfs(int v)
{
visited[v] = true;
for(int i=0; i<G[v].size(); i++){
if(!visited[G[v][i].first]){
d[G[v][i].... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
int n, a[N];
int main(void) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
long long ans = 0;
for (int i = 1; i <= n; i++) {
if (a[i] >= a[i - 1]) {
ans += 1ll * (a[i] - a[i - 1]) * (n - a[i] + 1);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int t, n, m, k, s, mq;
int a[105][105] = {0};
bool bj;
int main() {
cin >> t;
while (t--) {
cin >> n >> m >> k;
s = n * m / 2 - k;
bj = true;
for (int i = 0; i <= (n + 1); i++)
for (int j = 0; j <= (m + 1); j++) a[i][j] = -1;
if (n % 2) {
... | 4 |
#include <iostream>
#include <string>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
#include <vector>
using namespace std;
#define max 6
int main(void){
int div[] = {1, 10, 100, 1000, 10000, 100000, 1000000 };
//FILE *fp_in = freopen("data.txt", "r", stdin);
while(1) {
int t, num,... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, x, y, res = 0;
while (cin >> a >> b) {
if (a == 1) {
cout << b << endl;
continue;
}
res = 0;
while (a > 1) {
res = res + a / b;
a %= b;
if (a == 0) break;
swap(a, b);
}
cout << res ... | 1 |
#include<iostream>
using namespace std;
int main(){
int N, A[110];
cin>>N;
for(int i=0; i<N; i++) cin>>A[i];
for(int i=0; i<N; i++){
int j = i - 1, v = A[i];
while(j>=0 && A[j]>v){
A[j+1]=A[j];
j--;
}
A[j+1]=v;
for(int k=0;k<N-1;k++) cout<<A[k]<<" ";
cout<<A[N-1]<<endl;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
cin >> s;
string t;
for(int i = 0; i < s.size(); i++) {
if(s[i] == 'B') {
if(t.size()) t.pop_back();
}
else t += s[i];
}
cout << t << endl;
return 0;
} | 0 |
#include <set>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 200100;
const int MOD = (int) 1e9 + 7;
int n;
char s[N];
long long fact(int n) {
long long ret = 1;
for (int i = 1; i <= n; i++) {
ret = ret * i % M... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
pair<int, int> a[N];
int main() {
int n, s;
scanf("%d %d", &n, &s);
for (int i = 0; i < n; i++) {
scanf("%d %d", &a[i].first, &a[i].second);
}
sort(a, a + n);
reverse(a, a + n);
int now = s, ans = 0;
for (int i = 0; i < n; i++) {
i... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
string s;
vector<int> x;
vector<int> y;
for (int i = 0; i < n; i++) {
cin >> s;
for (int j = 0; j < m; j++) {
if (s[j] == '*') {
x.push_back(i);
y.push_back(j);
}
}
}
int xx, yy;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, po[22][3], l, r;
double dp[1 << 20];
const double pi = acos(-1);
const double eps = 1e-7;
double cal(double l, double x, double y, double a) {
double afa = a * 1.0 / 180 * pi;
if (l - x > eps) {
double theta = atan((l - x) / y);
if ((theta + afa - pi / 2)... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
for(int i=0; i<n; ++i) {
string s1, s2;
cin >> s1;
s2 = s1;
sort(s1.begin(), s1.end());
sort(s2.rbegin(), s2.rend());
cout << stoi(s2) - stoi(s1) << endl;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
int n, m, x;
int a[N + 100], f[N + 100][3][3];
void init() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%d", &x);
++a[x];
}
}
void checkmax(int &a, int b) {
if (b > a) a = b;
}
void solve() {
int ans = 0;
for (int... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c, ans;
cin >> a >> b >> c;
if(a%2==0 or b%2==0 or c%2==0) ans = 0;
else ans = min({a*b, b*c, c*a});
cout << ans << "\n";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e16;
const long long MAXN = 1e6;
long long n, i, x, l, r;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (i = 0; i < n; i++) {
cin >> l >> r >> x;
if (x < l)
cout << x << endl;
else {
cout << r / x... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const long long int LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI = acos(-1.0L);
__attribute__((constructor)) void initial() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
l... | 3 |
#include<iostream>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
for(int i=1;i<10001;i++){
int a1=(i*8)/100,a2=i/10;
if(a1==a&&a2==b)return cout<<i<<endl,0;
}
cout<<"-1"<<endl;
return 0;
} | 0 |
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
int N,budget;
int table[10];
bool FLG;
int ans[6],TMP[6];
void recursive(int num,int count,int rest)... | 0 |
#include <bits/stdc++.h>
const long long N = 200005;
std::priority_queue<long long> q;
long long n, m, pre[N], a[N], x, cnt;
signed main() {
scanf("%lld%lld", &n, &m);
for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
for (long long i = n; i >= 1; i--)
if (a[i] < 0)
q.push(a[i]);
else {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mmp;
long long pre = 0;
long long n, k, Mx;
long long ans = 0;
signed main() {
cin >> n >> k;
Mx = (1 << k) - 1;
ans = n * (long long)(n + 1) / 2;
mmp[0] = 1;
for (long long i = 1; i <= n; ++i) {
long long x;
cin >> x;
long lo... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, mx = 0, my = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int x, y;
char op;
cin >> op >> x >> y;
if (op == '+')... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int dp[s.size()];
dp[0] = 0;
for (int i = 1; i < s.size(); i++) {
if (s[i - 1] == s[i])
dp[i] = dp[i - 1] + 1;
else
dp[i] = dp[i - 1];
}
int q;
cin >> q;
while (q--) {
int m, n;
cin >> m >> n;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
int n, m, q;
bool ok(int x) {
int res = 0;
while (x) {
res += x % 10;
x /= 10;
}
if (res % 4 == 0) return 1;
return 0;
}
int main() {
scanf("%d", &n);
while (!ok(n)) ++n;
pri... | 1 |
#include <bits/stdc++.h>
#define MOD 256
using namespace std;
long long m, n;
vector<string> e;
map<string, set<int>> mp;
stack<set<int>> st;
bool solve();
int main() {
cin >> m;
for(int i = 0; i < m; ++i) {
string s;
int l, r;
cin >> s >> l >> r;
for(int i = l; i <= r; ++i) mp[s].insert(i);
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a[150];
long long b(int x, int y) {
if (y % x == 0) return x;
if (x % y == 0) return y;
if (y > x) return b(y % x, x);
if (x > y) return b(x % y, y);
}
int main() {
int n;
cin >> n;
long long mx = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool comp(int x, int y) { return x > y; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, i, j, arr[100001], brr[100001], crr[100001];
set<int> s;
cin >> n;
for (i = 0; i < n; i++) {
cin >> arr[i];
s.insert(arr[i]);
}
if (n <= 2 || ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
set<long long int> s;
long long int a;
for (int i = 0; i < n; i++) {
cin >> a;
s.insert(a);
}
if (s.size() == 1) {
cout << n << endl;
} else {
cout << ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, x[3010], y[3010];
pair<int, int> s[3010 * 3010 / 2];
int dist(int a, int b) {
return (x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]);
}
bool cmp(pair<int, int> a, pair<int, int> b) {
return dist(a.first, a.second) < dist(b.first, b.second);
}
bitset... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
const int B = 1e9 + 7;
int n, k;
long long a[N], b[N];
long long tmp[N];
long long h[N];
void mul(long long *a, long long *b) {
memset(tmp, 0, sizeof(tmp));
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
tmp[i] = (tmp[i] + a[... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string x;
cin >> x;
int xn, yn;
xn = yn = 0;
for (int i = 0; i < (int)x.length(); i++) {
if (x[i] == 'x')
xn++;
else
yn++;
}
if (xn > yn) {
for (int i = 0; i < abs(xn - yn); ++i) cout << 'x';
} else {
for (int i = 0; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n + 10, 0);
for (int i = 1; i <= n; i++) cin >> a[i];
++n;
constexpr long long inf = 1e16;
vector<vector<long long>> dp(n + 10, vector<long long>(n + 10, inf));
struct P {
int x, y, i;
};
vector<vector<P>> ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int testcases;
cin >> testcases;
while (testcases--) {
long long int n, m;
cin >> n >> m;
if (n == 1 || m == 1)
cout << "YES" << endl;
else if... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
int a[n];
vector<int> v, w;
for (i = 0; i < n; i++) {
int b;
cin >> b;
v.push_back(b);
w.push_back(b);
}
int count = 0;
int flag = 1;
sort(w.begin(), w.end());
for (i = 0; i < n - 1; i++) {
if (v[i + 1... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int c, r;
cin >> c >> r;
char arr[c][r];
int flag = 0;
int leftr = c;
int rightr = -1;
int leftc = r;
int rightc = -1;
int tot = 0;
for (int i = 0; i < c; i++) {
for (int j = 0; j < r; j++) {
cin >> arr[i][j];
if (arr[i][j] =... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, c = 0;
cin >> n >> k;
int *a = new int[n];
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < n; ++i) {
if (a[i] >= a[k - 1] && a[i] != 0) c++;
}
cout << c << endl;
}
| 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
const long long remi = 998244353;
using namespace std;
void Sun_god() {
long long x1, x2, p1, p2;
cin >> x1 >> p1 >> x2 >> p2;
string s1 = to_string(x1);
string s2 = to_string(x2);
if ((s1.length() + p1) > (s2.leng... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll LINF = 1001002003004005006ll;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T &b... | 4 |
#include<iostream>
#include<cstdio>
using namespace std;
bool ans;
void solve(int cntnum[],int progress){
int cntnum_c[10],cntcont=0;
/*printf("%d: ",progress);
for(int i=0;i<10;i++){
printf("%d",cntnum[i]);
}puts("");*/
for(int i=0;i<10;i++){
for(int j=0;j<10;j++) cntnum_c[j]=cn... | 0 |
#include <iostream>
#include <cstring>
#include <string>
#define loop for (;;)
#define repeat(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main() {
loop {
int H, W;
cin >> H >> W;
if (!H && !W) return 0;
string room[H];
bool visited[H][W];
memset(visited, 0, sizeof visited);... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d %d", &n, &k);
long long left = 0;
long long shift = 0;
for (int i = 0; i < n; ++i) {
int a;
scanf("%d", &a);
if (left - (1LL * (i - shift) * (n - i - 1) * a) < k) {
++shift;
printf("%d\n", i + 1);
} else... | 3 |
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long
signed main() {
int n; cin >> n;
int m = 1001, sum = 0;;
for (int i = 0; i < n; i++) {
int a; cin >> a;
sum += a;
if (a % 2)m = min(m, a);
}
if (sum % 2)sum -= m;
cout << sum / 2 << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int M = 140;
int n, x;
double p[M];
double A[M][M], b[M][M];
double ans[M][M];
void times1() {
memset(b, 0, sizeof(b));
for (int i = 0; i <= 127; i++) {
for (int j = 0; j <= 127; j++) {
for (int k = 0; k <= 127; k++) {
b[i][j] ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long v[100000];
int main() {
int n, x;
scanf("%d%d", &n, &x);
--x;
long long mn = INT_MAX;
for (int i = 0; i < n; ++i) {
cin >> v[i];
mn = min(mn, v[i]);
}
long long c = mn * n;
for (int i = 0; i < n; ++i) v[i] -= mn;
int j;
for (j = x; v[j]... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1000000000;
int main() {
int n;
cin >> n;
vector<ll> neg_max{-INF, -INF};
vector<ll> pos_min{INF, INF};
vector<ll> a(n);
for (ll &ai : a) {
cin >> ai;
}
ll sum = accumulate(a.begin(), a.end(), 0, [](int prev, int curr... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
if(N==1||N==2||N==3||N==5||N==6||N==9||N==10||N==13||N==17)
cout << "No";
else
cout << "Yes";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 1000 + 10;
const int MOD = 1000000007;
int n, k;
string s;
long long fre[MAXN];
long long freb[MAXN], frew[MAXN];
long long can[MAXN];
long long canb[MAXN], canw[MAXN];
long long mod(long long x, long long m) { return ((x % m) + m) % m; }
void pre() ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[1005];
int main() {
int n;
while (~scanf("%d", &n)) {
memset(a, 0, sizeof(a));
int avg = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
avg += a[i];
}
avg /= n;
int pnt = 0, l = -1, r = -1;
for (int i = 1; i <= n; i++... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 100;
int num[4];
char str[maxn];
int main() {
int len;
scanf("%d", &len);
scanf("%s", str);
for (int i = 0; i < len; i++) {
num[str[i] - '0']++;
}
int tmp = len / 3;
if (num[0] > tmp) {
for (int i = len - 1; i >= 0; i--) {
... | 4 |
#include <bits/stdc++.h>
int solve(int a[], int n) {
int switches;
int ones = 0, twos = 0, threes = 0, fours = 0;
for (int i = 0; i < n; i++) {
std::cin >> a[i];
if (a[i] == 4) {
fours = fours + 1;
}
if (a[i] == 3) {
threes = threes + 1;
}
if (a[i] == 2) {
twos = twos + 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
int init[N], goal[N];
bool vis[N];
vector<int> G[N], v;
void dfs(int node, int lvl, int odd, int even) {
vis[node] = true;
if (odd || even) {
if (lvl & 1)
if (odd & 1) goal[node] ^= 1;
if (!(lvl & 1))
if (even & 1) goal[node] ^... | 1 |
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
class UnionFind {
private:
vector<ll> data;
vector<ll> sum;
public:
UnionFind(ll n, vector<ll> sum): data(n, -1), sum(sum) {
}
ll size(ll i) { return -data[find(i)]; }
bool ro... | 0 |
#include <bits/stdc++.h>
using namespace std;
__attribute__((constructor)) void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int main() {
int n;
cin >> n;
int f = 0;
string s;
cin >> s;
for (int i = (1); i < (n); i++) {
if (s[i] != '?' && s[i - 1] != '?' && s[i] == s[i - 1]) {
cout <... | 1 |
#include <cstdio>
int H, A;
int main() {
scanf("%d %d", &H, &A);
printf("%d\n", H/A + (H%A>0));
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, maxl = INT_MIN, current = 0;
scanf("%d", &n);
while (n--) {
scanf("%d", &a);
scanf("%d", &b);
current -= a;
current += b;
if (current > maxl) maxl = current;
}
printf("%d", maxl);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[1005][1005];
int n, c = 0, i;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s", str[i]);
}
for (i = 0; i < n; i++) {
if (str[i][0] == 'O' && str[i][1] == 'O') {
str[i][0] = '+';
str[i][1] = '+';
c = 1;
b... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
T div_floor(T a, T b) {
... | 2 |
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
using namespace std;
#define... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 210000;
char s[N];
int n;
int a[N];
int b[N];
const int S = 200;
long long ksm() {
long long ans = 0;
for (int k = (int)(1); k <= (int)(S); k++) {
for (int i = (int)(0); i <= (int)(n); i++) b[i] = k * a[i] - i;
sort(b, b + 1 + n);
for (int i = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long a[310000], b[310000], cnt, cnt1, ans, sum[310000], c[320000];
bool cmp(int a, int b) { return a > b; }
int main() {
long long n, m, d;
cin >> n >> d >> m;
for (int i = 1; i <= n; i++) {
long long x;
cin >> x;
if (x > m)
a[++cnt] = x;
el... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 200010;
long long a[mod], cur[mod], dop[mod];
int l[mod], r[mod], d[mod];
int main() {
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= m; ++i) {
cin >> l[i] >> r[i] >> d[i];
}
for (int i = 1; i ... | 1 |
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
cout << k * (int)pow(k - 1, n - 1);
return 0;
} | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60000000")
using namespace std;
template <class T>
T sqr(T x) {
return x * x;
}
double const pi = 3.1415926535897932384626433832795;
long long const inf64 = (long long)4e18;
const string name = "c";
int n, m, x1, qqqqqqq, x2, y2;
void answer(int zn) {
if (zn ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, k;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n;
cin >> n;
vector<long long> count(n + 1, 0);
for (i = (0); i < (n - 1); i++) {
long long a, b;
cin >> a >> b;
if (b != n) {
cout << "NO" << '\n';
r... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int Imx = 2147483647;
const long long Lbig = 2e18;
const int mod = 1e9 + 7;
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 (... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 2e5 + 5;
int n, m, k;
vector<pair<int, int>> edge;
set<int> adj[N];
bool gone[N];
vector<int> res;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
for (int i = 1; i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
cerr << n << endl;
vector<int> mn(n, 1e+9);
vector<int> cnt(n);
vector<int> t(n);
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
--a;
--b... | 1 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK: 1024000000,1024000000")
using namespace std;
inline int getint() {
int _x = 0;
char _tc = getchar();
while (_tc < '0' || _tc > '9') _tc = getchar();
while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
return _x;
}
pair<double... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[10000];
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
int s = 0;
for (int i = 1; i <= 5; i++) {
if ((sum + i) % (n + 1) != 1) s++;
}
cout << s;
return 0;
}
| 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
inline long long input() {
long long n;
cin >> n;
return n;
}
long long poww(long long a, long long b, long long md) {
return (!b ? 1
: (b & 1 ? a * poww(a * a % md, b / 2, md) % md
: poww(a * a % md, b /... | 6 |
#include <bits/stdc++.h>
const int inf = (1ll << 31) - 1;
const int maxn = (int)1e5 + 10;
using namespace std;
int main() {
set<pair<long long, long long> > S;
int n, k;
scanf("%d %d\n", &n, &k);
for (int i = 0; i < n; i++) {
long long x, y;
scanf("%I64d %I64d", &x, &y);
if (S.size() == k) {
p... | 4 |
#include <bits/stdc++.h>
using namespace std;
int Gcd(int a, int b) {
if (b == 0) return a;
return Gcd(b, a % b);
}
int Lcm(int a, int b) { return a / Gcd(a, b) * b; }
inline long long read() {
long long f = 1, x = 0;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') f = -f;
ch = getc... | 1 |
#include <bits/stdc++.h>
using namespace std;
int arr[1000], arr2[1000];
int main() {
int n, m;
cin >> m >> n;
int a, b, c, d;
for (int i = 0; i < n; i++) {
cin >> a >> b >> c >> d;
for (int j = a; j <= b; j++) {
if (arr[j] == 0) {
arr[j] = c;
arr2[j] = d;
} else if (arr[j] >... | 2 |
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
vector<int> e[2010];
char s[2010];
int sd;
pair<int, int> dp[2010];
int cnt[2010];
void go(int v, int d = 0, int p = -1) {
vector<pair<int, int> > c;
cnt[v] = 0;
if (s[v]) {
sd += d;
cnt[v]++;
}
for (int i = 0; i <... | 0 |
#include <bits/stdc++.h>
int N;
int64_t K;
std::vector<int64_t> A, F;
bool able(int64_t);
int main()
{
scanf("%d%lld", &N, &K);
A.resize(N);
F.resize(N);
for (auto& e: A) scanf("%lld", &e);
for (auto& e: F) scanf("%lld", &e);
std::sort(A.rbegin(), A.rend());
std::sort(F.begin(), F.end());
int64_t ng{-1}, ok{... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.