solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
bool isSubSequence(string str1, string str2, int m, int n) {
int j = 0;
for (int i = 0; i < n && j < m; i++) {
if (str1[j] == str2[i]) j++;
}
return (j == m);
}
int isPrime(long long n) {
for (int i = 2; i < sqrt(n); i++)
if (n % i == 0) return 0;
return... | 2 |
#include <bits/stdc++.h>
using namespace std;
int N, H, R, mxH;
int t, cnt;
struct SCR {
int pow, dmg;
} scr[2000];
vector<int> sec, num;
int main() {
scanf("%d %d %d", &N, &H, &R);
mxH = H;
for (int Ni = 0; Ni < N; Ni++) {
scanf("%d %d", &scr[Ni].pow, &scr[Ni].dmg);
}
while (1) {
t++;
bool flag... | 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:268435456")
using namespace std;
long long _gcd(long long a, long long b) {
if (b == 0) return a;
_gcd(b, a % b);
}
int main() {
int n, s, x, y, res = -1;
cin >> n >> s;
for (int i = 0; i < n; ++i) {
cin >> x >> y;
if (y != 0) x++;
if (x <= ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int L = 18;
int a[300000];
int fn(long long m) {
int ret = 0;
for (int i = 0; i < L; i++) {
ret *= 2;
if (m % 2) ret++;
m /= 10;
}
return ret;
}
int main() {
int n;
scanf("%d\n", &n);
for (int i = 0; i < n; i++) {
char op;
long long x... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long dp[2123456][2];
int main() {
long long t, n;
cin >> t;
dp[2][0] = 0;
dp[2][1] = 0;
dp[3][0] = 4;
dp[3][1] = 0;
for (int i = 4; i <= 2000000; i++) {
dp[i][0] = (4 + 2 * dp[i - 2][1] + dp[i - 1][1]) % 1000000007;
if (i % 3 == 0) {
dp[i][1... | 4 |
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define sc(a) scanf("%c",&a)
#define ss(a) scanf("%s",a)
#define pi(a) printf("%d\n",a)
#define pl(a) printf("%lld\n",a)
#define pc(a) putchar(a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i, a, b) f... | 2 |
#include <bits/stdc++.h>
using namespace std;
string A[100001];
string B[100001];
int cA[100001];
int cB[100001];
bool cmpA(int a, int b) { return A[a] < A[b]; }
bool cmpB(int a, int b) { return B[a] < B[b]; }
int matA[100000];
int matB[100000];
int solve(int a1, int a2, int b1, int b2, int ch) {
if (a1 > a2 || b1 > ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long gcdll(long long a, long long b) {
if (!b) return a;
return gcdll(b, a % b);
}
void seive(int n) {
vector<bool> is_prime(n + 1, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i * i <= n; i++) {
if (is_prime[i]) {
... | 4 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
double eps = 1e-10;
using namespace std;
int n, m;
long long pref[2][200005], d[200005], h[200005], sum[200005];
pair<pair<long long, int>, pair<long long, int> > t[2][800005];
pair<pair<long long, int>, pair<long long, int> > Merge(
pair<pair<long... | 3 |
#include <bits/stdc++.h>
int main() {
int n, k, s = 0, a;
int nivel[110];
scanf("%d %d ", &n, &k);
memset(nivel, 0, sizeof(nivel));
int menor = 110;
while (n--) {
scanf("%d ", &a);
if (menor == 110) menor = a;
nivel[a]++;
}
while (menor < k) {
for (int i = k - 1; i > 0; i--) {
if (... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long s = 0, t = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') t = -1;
c = getchar();
}
while (isdigit(c)) s = s * 10 + c - 48, c = getchar();
return s * t;
}
const int N = 1e5 + 5, inf = 1e9 + 7;
int n, a[N], b... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5;
vector<vector<int>> adj, dadj;
vector<int> ind;
vector<int> pass;
vector<int> curu;
int tmp[100001];
void dfs(int u) {
if (pass[u]) return;
pass[u] = 1;
curu.push_back(u);
for (auto v : adj[u]) dfs(v);
}
int main() {
ios::sync_with_stdio(0);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, L, a;
cin >> n >> L >> a;
long long i;
long long x = 0, ans = 0;
for (i = 0; i < n; i++) {
long long t, l;
cin >> t >> l;
ans += (t - x) / a;
x = t + l;
}
ans += (L - x) / a;
cout << ans << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
int ax[200005];
using namespace std;
char chars[151][151];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
int total = 0, library = -1, fibona = -1, lojebs = -1, fojebs = -1;
for (int i = 1; i <= n; i++) {
int c = 0;
for (int j = 1; j <= m; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long head[200100], nxt[200100 << 1], ver[200100 << 1], tot;
inline void addedge(long long a, long long b) {
nxt[++tot] = head[a];
ver[tot] = b;
head[a] = tot;
nxt[++tot] = head[b];
ver[tot] = a;
head[b] = tot;
}
long long f[200100][5], s[200100];
long long ... | 4 |
#include <cstdio>
#include <algorithm>
int n, x[1009], y[1009], dp[1009][1009];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d%d", &x[i], &y[i]);
for (int i = 2; i <= n; i++) {
for (int l = 0; l <= n - i; l++) {
int r = l + i; dp[l][r] = 999999999;
for (int k = l + 1; k < r; k++) {
d... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[2001];
int first[2001];
int last[2001];
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
}
sort(a, a + n);
if (k >= n) {
cout << a[n - 1] * 2 << endl;
return 0;
}
int r = n % k;
int sum = 0;
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int nn = 1e5 + 8;
int fre[nn];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
fre[x]++;
}
bool ok = false;
for (int i = 1; i <= 1e5; i++) ok |= (fre[i] & 1);
if (ok)
cout << "Conan";
else
cout << "Agas... | 2 |
#include <iostream>
#include <vector>
using namespace std;
int bolder(vector<int> &v, int n, int k)
{
int i = 0;
while (i < n)
{
if (v[i] >= v[i + 1])
i++;
else
{
v[i] += 1;
k--;
if (!k)
return i + 1;
i = 0;... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, t;
int main() {
scanf("%d%d%d", &n, &k, &t);
if (t <= k) {
printf("%d", t);
return 0;
}
if (t < n + k && t >= n + 1) {
printf("%d", k - (t - n));
return 0;
}
if (t >= k + 1 && t <= n) {
printf("%d", k);
return 0;
}
ret... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& num) {
num = 0;
bool f = true;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = false;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
num = num * 10 + ch - '0';
ch = getchar();
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int a[100001];
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n && k; i++) {
if (a[i] < 0) {
a[i] *= -1;
k--;
}
}
if (k && k & 1) {
sort(a, a + n);
a[0] *= -1;
}
int ans = 0;
f... | 2 |
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstr... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, ans, mod = 1e9 + 7;
string s;
int arr[2][101010], dp[101010], sz[101010];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int i, j, temp = 0;
cin >> s;
int cnt[2] = {0, 0};
j = 1;
for (i = 0; i < s.size(); i++) {
if (s[i] == '0') {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, d, tic, tin[N], tout[N], dist[N], a[2 * N], tree[8 * N], add[8 * N],
ans;
vector<int> gr[N];
bool bad[N];
void build(int v, int vl, int vr) {
if (vl == vr) {
tree[v] = a[vl];
return;
}
int mid = (vl + vr) / 2;
build(v + ... | 4 |
#include<iostream>
#include<string>
#include<cstdlib>
#include<vector>
//#include<cctype>
using namespace std;
class Player{
public:
int id;
};
int main()
{
while(true){
int m,n;
cin >> m >> n;
if( m == 0 && n == 0 ) break;
vector< Player > p;
for(int i = 0; i < m; ++i){
Player tp;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int Size = 1024;
const int mod = 998244353;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 15;
struct node {
long long num, v1, v2;
} a[maxn];
bool cmp(node a, node b) { return a.v1 - a.v2 > b.v1 - b.v2; }
long long k, n, s;
long long check(long long p) {
long... | 2 |
#include <bits/stdc++.h>
using namespace std;
int i, j, x, y, n, m, con[100001];
int c1, c2, cn;
bool bus = false, ring = false, star = false;
int main() {
cin >> n >> m;
for (i = 0; i < m; i++) {
cin >> x >> y;
con[x]++;
con[y]++;
}
for (i = 1; i <= n; i++) {
if (con[i] == 1)
c1++;
el... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, s, x;
cin >> t >> s >> x;
if (x == t) {
cout << "YES";
} else {
long long a = (x - t) % s;
long long b = (x - t) / s;
if ((a == 0 || a == 1) && b >= 1) {
cout << "YES";
} else {
cout << "NO";
}
}
}
| 1 |
#include <bits/stdc++.h>
int main() {
long long n;
scanf("%I64d", &n);
long long a[n];
long long i, j;
for (i = 0; i < n; i++) {
scanf("%I64d", &a[i]);
}
long long count = 0;
long long less = 0;
long long more = 0;
for (i = 1; i < n; i++) {
for (j = 0; j < i; j++) {
if (a[j] < a[i]) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m;
cin >> n >> m;
int arr[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> arr[i][j];
}
}
int sum = 0, temp, flag = 1;
for (int i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(void){
int n,i,ans=0;
cin >> n;
vector<int> p(n+3,0);
for (i=0;i<n;i++) cin >> p.at(i);
for (i=1;i<n-1;i++) if ((p.at(i-1)-p.at(i)) * (p.at(i)-p.at(i+1)) > 0) ans++;
cout << ans << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
vector<long long int> primes;
void Sieve(long long int n) {
bool prime[n + 1];
for (long long int i = 0; i < n + 1; ++i) prime[i] = true;
for (long long int p = 2; p * p <= n; ++p) {
if (prime[p] == true) {
for (long long int ... | 3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
template <class T>
inline void gmax(T &a, T b) {
if (b > a) a = b;
}
template <class T>
inline void gmin(T &a, T b) {
if (b < a) a = b;
}
using namespace std;
const int N = 1e5 + 10, M = 2e6 + 10, Z = 1e9 + 7, maxint = 2147483647,
... | 2 |
#include <iostream>
using namespace std;
int N;
long long sum;
int cnt[100005];
int Q;
int main()
{
cin >> N;
for (int i = 1; i <= N; i++)
{
int A;
cin >> A;
sum += A;
cnt[A]++;
}
for (cin >> Q; Q--; )
{
int B, C;
cin >> B >> C;
sum -= 1LL * B * cnt[B];
sum += 1LL * C * cnt[B];
cnt[C] += cnt[... | 0 |
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n;
while (scanf("%d", &n), n != 0){
int t[11][11] = {0};
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
cin >> t[i][j];
t[i][n] += t[i][j];
t[n][j] += t[i][j];
}
t[n][n] += t[i][n];
}
for (int i ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long quickmod(long long a, long long n) {
long long s = 1;
while (n) {
if (n & 1) {
s = s * a % mod;
}
a = (a * a) % mod;
n = n / 2;
}
return s;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
char good[30], bad[30], str[N], str1[N];
int vis[1100];
int k1;
int main() {
memset(vis, 0, sizeof(vis));
cin >> good;
for (int i = 0; good[i]; i++) {
vis[good[i]] = 1;
}
cin >> str;
int k1 = -1, len = strlen(str);
for (int i = 0; st... | 2 |
#include <bits/stdc++.h>
#pragma optimize("Ofast")
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1000000007;
int modpow(int x, int y, int md = mod) {
if (y == 0) return 1;
int ret = modpow(x, y >> 1, md);
ret = (long long)ret * ret % md;
if (y & 1) ret = (long long)re... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int maxn = 1e7 + 10;
const int maxm = 1e4 + 10;
int t, n, m, k;
inline int read() {
int x = 0, k = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') k = -1;
for (; isdigit(ch); ch = getchar()) x = x * 10 + ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int d[999999];
int a[999999];
int b[999999];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
string s;
cin >> s;
long long postP = s.find('^'), answer = 0;
for (int i = 0; i < s.size(); i++)
if (s[i] >= '0' && s[i] <= '9') answer += (s[i... | 1 |
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000;
int main(){
int V, E;
cin >> V >> E;
vector<vector<int>> dist(V, vector<int>(V, INF));
for (int i = 0; i < E; i++){
int s, t, d;
cin >> s >> t >> d;
dist[s][t] = d;
}
vector<vector<int>> dp(1 << V, vector<int>(V, INF));
dp[0][0] ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, k1, k2, i, j, k, c2, m, cnt = 0;
;
cin >> n >> k1 >> k2;
long long a[n], b[n];
priority_queue<long long> v;
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < n; i++) cin >> b[... | 2 |
#include <iostream>
#include <cstring>
using namespace std;
int main() {
int t;
cin >> t;
while (t--){
int n;
cin >> n;
int q[n + 5], dp[n + 5];
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++)
cin >> q[i];
fo... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, k, dp[N], y, level[N], kol[N], mx;
vector<int> g[N], a;
void dfs(int x, int p) {
if (p != 0) dp[x] = dp[p] + 1;
if (dp[x] > dp[y]) y = x;
for (int i = 0; i < g[x].size(); ++i) {
if (g[x][i] != p) dfs(g[x][i], x);
}
}
bool get_ans(in... | 2 |
#include<iostream>
using namespace std;
int N;
long A[300][300];
long ans;
int main()
{
cin>>N;
for(int i=0;i<N;i++)for(int j=0;j<N;j++)cin>>A[i][j];
for(int i=0;i<N;i++)for(int j=i+1;j<N;j++)
{
int flag=0;
for(int k=0;k<N;k++)
{
if(k==i||k==j)continue;
if(A[i][k]+A[k][j]==A[i][j])flag|=1;
if(A[i][k]... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long a, b, p, cost = 0;
string s;
int flag = 0;
cin >> a >> b >> p >> s;
if (s[s.length() - 2] == 'A')
cost = a;
else
cost = b;
if (cost > p) {
cout << s.length() << "\n";
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int sz = 1e6 + 100;
bitset<sz> b;
int p[sz], len[sz];
bool used[sz];
int main() {
ios_base::sync_with_stdio(false);
int n, k, sum = 0, cnt = 0, i;
cin >> n >> k;
for (i = 0; i < n; i++) {
cin >> p[i];
p[i]--;
}
for (i = 0; i < n; i++)
if (!used... | 6 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(nullptr));
const long long INF = 2e9, P = 1e9 + 7, N = 1e5 + 10;
const long double EPS = 1e-9;
int n;
pair<int, int> a[N], pref[N], suff[N];
bool check(long long d) {
int j = -1;
for (int i = 0; i < n; i++) {
while (j + 1 < n && (long long)abs(a[i].... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, x, ans;
int main() {
scanf("%d%d", &n, &x);
for (int i = 1; i * i <= x; i++)
if (x % i == 0) {
if (x / i <= n) {
ans++;
if (i * i != x) ans++;
}
}
printf("%d\n", ans);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
long long int n;
cin >> n;
long long int a[n];
long long int x = 0;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
x ^= a[i];
}
if (x != 0 && n % 2 == 0)
cout << "NO"
... | 4 |
#include<bits/stdc++.h>
using namespace std;
using Lint=long long;
Lint get(Lint l,Lint r){ return r-l+1; }
int main()
{
Lint a,b; cin>>a>>b;
if(a==b){ cout<<1<<endl; return 0; }
const int LOG=60;
Lint m=0,n=0;
for(int i=LOG-1;i>=0;i--){
if((a>>i&1)!=(b>>i&1)){
m=1LL<<i; n=1LL<<i;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long b[n / 2];
for (int i = 0; i < n / 2; i++) cin >> b[i];
long long a[n];
a[0] = 0;
a[n - 1] = b[0];
long long luu2 = a[0];
long long luu1 = a[n - 1];
for (int i = 1; i < n / 2; i++) {
if (b[i] - luu1 >= luu2) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
void io() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout.precision(15);
}
const int MAXN = 8e5 + 10;
int id[MAXN];
int n;
int mx;
vector<pair<int, long long> > g[MAXN];
void build(int idx = 1, int l = 1, int r = n) {
if (l == r) {
id[l] = id... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void umax(T &a, T b) {
if (a < b) a = b;
}
template <class T>
inline void umin(T &a, T b) {
if (a > b) a = b;
}
template <class T>
inline T abs(T a) {
return a > 0 ? a : -a;
}
template <class T>
inline T gcd(T a, T b) {
return __gcd(a, b);
... | 4 |
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
string map[1000];
int DP[1000][1000];
int main(){
int H, W;
while(true){
cin >> H >> W;
if(H == 0 && W == 0){
break;
}
for(int i = 0; i < H; i++){
cin >> map[i];
}
int ans = 0;
int count = 0;
... | 0 |
#include <iostream>
using namespace std;
int main(void) {
// your code goes here
int n;
cin >> n;
if(n<=3||n==5||n==6||n==9||n==10||n==13||n==17) cout << "No" << endl;
else cout << "Yes" << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2013;
int n, m, seq[N], deg[N];
bool mark[N];
pair<int, int> e[N];
vector<int> path;
vector<pair<int, int> > adj[N];
bool check(int u, int v) {
int res = (adj[u].size() & 1 ^ 1) + (adj[v].size() & 1 ^ 1);
for (int i = 0; i < n; i++)
if (i != u && i != ... | 4 |
#include<bits/stdc++.h>
using namespace std;
int t[100000];
int main(void)
{
int n;
int max;
int i,j;
int sum;
int cnt,cnt2,MC[1000];
cin>>n;
max=-1;
for(i=0;i<n;i++){
cin>>t[i];
if(max<t[i]) max=t[i];
}
cnt=1; cnt2=0;
while(cnt!=max){
if(max%cnt==0){
MC[cnt2]=cnt;
cnt2++;
}
cnt++;
}
MC[cnt... | 0 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
set<pair<int, int> > st;
vector<int> v;
set<pair<int, int> >::iterator P;
long long A[200001], n, m, i, j, t, k, x, y;
string s, s1;
long long B[200001], a, b, a1, b1;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
cin >>... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s;
scanf("%d %d", &n, &s);
int ans = s;
for (int i = 0; i < n; i++) {
int f, t;
scanf("%d %d", &f, &t);
ans = max(t + f, ans);
}
printf("%d\n", ans);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
string str;
int ans;
int main() {
cin >> str;
for (int i = 0; i < str.size(); i++) {
if (str[i] >= 'A' && str[i] <= 'Z')
ans += str[i] - 'A' + 1;
else if (str[i] >= 'a' && str[i] <= 'z')
ans -= str[i] - 'a' + 1;
else
ans += 0;
}
cout <<... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s,t,u; cin>>s>>t>>u;
cout << 'A' << t[0] << 'C' << endl;
} | 0 |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
puts(n > 33500 ? "3" : "2");
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
const long long mod = 1000000007;
int n, a[maxn][maxn];
long long dp1[maxn][maxn], dp2[maxn][maxn];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) scanf("%d", &a[i][j]);
for (int i = 0; i < n; ++i) dp1[i... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
long long ans = (a * b) / gcd(a, b);
return ans;
}
int main() {
long long x;
cin >> x;
vector<long long> v;
for (long long i = 1... | 3 |
#include <bits/stdc++.h>
using namespace std;
int banyak[10] = {}, banyak2[10] = {};
char s[205], t[205];
int main() {
scanf("%s", &s);
int len = strlen(s);
for (int i = 0; i < len; i++)
if (s[i] == '5')
banyak[2]++;
else if (s[i] == '9')
banyak[6]++;
else
banyak[s[i] - '0']++;
sca... | 2 |
#include<iostream>
#include<cstdio>
using namespace std;
int r,l,a,f,t;
char o[10];
int main()
{
int n,i,p,ans;
while(scanf("%d",&n)&&n!=0)
{
a=1;f=2;r=3;l=4;t=5;ans=1;
for(i=1;i<=n;i++)
{
scanf("%s",o);
if(o[0]=='N')
{
t=a;a=f;f=7-t;
}else if(o[0]=='S')
{
f=a;a=t;t=7-f;
}else if(o[0]=='W')
{
... | 0 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int n;
while( cin >> n , n ){
vector<int> v;
int h[10000] = {0};
for(int i=1 ; i < n ; i++ ){
int a = (i * i) % n;
if( count(v.begin() , v.end() , a ) == 0 ){
v.push_back( a );
}
}
for(int i=0 ; i < ... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool bb(pair<int, int> a, pair<int, int> b) {
return a.first < b.first || (a.first == b.first && a.second > b.second);
}
int main() {
int n;
bool b = 0, d = 0, z = 1;
cin >> n;
char a[300][300];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
string isuniquee(string A) {
sort(A.begin(), A.end());
A.erase(unique(A.begin(), A.end()), A.end());
return A;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin >> s;
vector<int> n;
int digits = 0, vo = 0;
... | 1 |
#include <iostream>
using namespace std;
int main()
{
int n,m;cin>>n>>m;
cout<<(n==m?"Yes\n":"No\n");
} | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000000")
using namespace std;
const long long int INF = 2e18;
long long int us[400][400];
int main() {
long long int n, m, k;
cin >> n >> m >> k;
vector<long long int> used(n, 0);
vector<long long int> op(k);
for (long long int i = 0; i < k; i+... | 5 |
#include <bits/stdc++.h>
int diru[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dirv[] = {-1, 0, 1, -1, 1, -1, 0, 1};
using namespace std;
template <class T>
T sq(T n) {
return n * n;
}
template <class T>
T gcd(T a, T b) {
return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
return (a / gcd<T>(a,... | 4 |
#include <bits/stdc++.h>
using namespace std;
int x, y, z, a, b, c;
int main() {
cin >> x >> y >> z >> a >> b >> c;
if (a < x) return cout << "NO", 0;
a -= x;
if (a + b < y) return cout << "NO", 0;
int p = a + b + c;
p -= y;
if (p < z) return cout << "NO", 0;
cout << "YES" << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
const int MAXN = 105;
const int MOD = 1e9 + 7;
using namespace std;
string a[105];
int lleft[105][105];
int rright[105][105];
int ddown[105][105];
int uup[105][105];
int r, c;
bool visited[105][105];
void print(int x[][105]) {
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
... | 5 |
#include<bits/stdc++.h>
using namespace std;
int n,m,x,y,p[100005];
vector<int>v[100005];
int vv[100005];
void bfs(int x)
{
queue<int>q;
q.push(x);
while(!q.empty())
{
int now=q.front();q.pop();
for(int i=0;i<v[now].size();i++)
{
vv[v[now][i]]--;
p[v[now][... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int k = sqrt(n);
int q = n / k;
int r = n % k;
if ((k * k == n) && (k != 1))
cout << k * 4;
else if (n == 1)
cout << "4";
else if (n == 2)
cout << "6";
else if (k == 1)
cout << "8";
else if (r == 0) {
cou... | 2 |
#include <bits/stdc++.h>
using namespace std;
int pictureTime[50001];
int ti[5][50001];
int main() {
int n, m;
cin >> m >> n;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
cin >> ti[j][i];
}
}
for (int i = 0; i < n; i++) {
int start = 0;
for (int j = 0; j < m; j++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<vector<pair<int, pair<int, pair<int, int> > > > > g(n + 1);
vector<int> s(n + 1, 0);
for (int i = 1; i <= m; ++i) {
int u, v, w;
cin >> u >> v >> w;
g[... | 5 |
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
int l, a, b, c, d;
cin >> l >> a >> b >> c >> d;
int n = max( (a+c-1)/c, (b+d-1)/d );
cout << l-n << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int mn = 510;
int a[mn], b[mn];
int dp[mn][mn], bac[mn][mn];
int main() {
int n, m, i, j;
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", a + i);
scanf("%d", &m);
for (i = 1; i <= m; i++) scanf("%d", b + i);
b[0] = -1;
for (i = 1; i <= n; i++) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, tot, S, T, an;
char c[405];
int s[405];
int g[205][205][205], flag[205][205], si[205];
int id1[205], id2[205];
struct mxr {
int a, b;
int t[405][405];
} mb, ans;
int adt(int a, int b) {
if (a + b >= 10007) return a + b - 10007;
return a + b;
}
mxr operator... | 5 |
#include<bits/stdc++.h>
using namespace std;
int a[20];
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
int sum=0;
for(int i=0;i<n;i++) sum+=a[i];
if(a[n-1]+a[n-1]>=sum) cout<<"No\n";
else cout<<"Yes\n";
} | 0 |
#include <iostream>
using namespace std;
char s[32];
int main() {
cin >> s;
cout << s[0] << s[1] << s[2] << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100010], b[100010], f[100010], x, cr, u[100010];
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
if (!u[a[i]] && a[i] <= n) u[a[i]] = 1, f[i] = 1;
}
for (int i = 1; i <= n; ++i) {
if (!u[i]) b[cr++] = i;
}
x = 0;
for (in... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int maxn = 1010;
long long dp[maxn][3000][2];
int t, k;
string s1, s2;
long long dfs(int pos, int dis, int isok) {
if (pos == 0) return isok;
if (dp[pos][dis][isok] != -1) return dp[pos][dis][isok];
long long ans = 0;
for (int i = 0... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
const long long M = 998244353;
int n, a[N], pos[N], num[N], digits;
long long p[N];
void init() {
digits = 1;
p[1] = 1;
for (int i = 1; i <= n; i++) {
while (digits < 10 && a[i] >= p[digits] * 10) {
digits++;
p[digits] = p[di... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
struct SegmentTree {
vector<pair<int, int>> tree;
int n, root, size;
SegmentTree(int currSize) : n(currSize), root(1) {
int x = (int)(ceil(log2(currSize)));
size = 2 * (int)pow(2, x);
tree.resize(size, {1e18, 0});
}
pair<int, i... | 5 |
#include <bits/stdc++.h>
using namespace std;
double const pi = 3.1415926536;
int main() {
int n, m;
cin >> n >> m;
int a[n][m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) cin >> a[i][j];
int t = n;
while (t % 2 == 0) {
int f = 1;
int i = 0;
while (i < t / 2) {
for (int j ... | 2 |
#include<iostream>
using namespace std;
#include<algorithm>
#define REP(i,a) for(int i=0;i<a;i++)
int A[100000];
int main(){
int a,b=0,c,n,j,k,x,y,p,N,M;
cin>>n;
REP(i,n){
cin>>x>>y>>b>>p;
c=x*b+y*p;
if(b>4&&p>1){
c=c*0.8;
}
else {
if(b<5) b=5;
if(p<2) p=2;
M=(x*b+y*p)*0.8;
c=min(c,M);
}
cout<<c<... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<list<long long int> > adj(1000), Adj(1000);
long long int visited[1000];
void dfs(long long int u, long long int temp) {
visited[u] = temp;
list<long long int>::iterator iter;
for (iter = adj[u].begin(); iter != adj[u].end(); iter++) {
if (visited[*iter] ==... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double PI = acos(-1.0);
const int INF = 1e9 + 10;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
int f[N], p[N], pp[N];
int vis1[N], vis2[N];
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
int main() {
int n;
while (~scanf... | 4 |
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#defi... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
int n;
cin >> n;
vector<pair<int, int>> v;
vector<vector<int>> adj(101, vector<int>(101, 0));
for (int i = 0; i < 101; i++) adj[i][i] = 1;
for (int i = 0; i < n; i++) {
int x, l, r;
cin >> x >> l >> r;
if (x ==... | 5 |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
int n; cin>>n;
vector<ll> v(n+1,0),w(n,0);
for(int i=0;i<=n;i++)
cin>>v[i];
for(int i=0;i<n;i++)
cin>>w[i];
ll ans=0;
for(int i=0;i<n;i++){
ll x=min(w[i],v[i]);
ans+=x;
w[i]-=x; v[i]-=x;
x= min(w[i],v... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int mod1 = 998244353;
void fastscan(long long int &number) {
bool negative = false;
register int c;
number = 0;
c = getchar();
if (c == '-') {
negative = true;
c = getchar();
}
for (; (c > 47 && c < 58... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, const U &b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, const U &b) {
if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
char c, sg = 0;
while (c = getchar(), ... | 5 |
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
const int M = 200005;
#define int long long
#define pii pair<int,int>
#define make make_pair
int read()
{
int x=0,f=1;char c;
while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;}
while(c>='0' && c<='9') {... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
vector<int> parent, size;
UnionFind(int n) : parent(n), size(n, 1) {
for (int i = 0; i < n; i++) {
parent[i] = i;
}
}
int operator[](int x) {
if (parent[x] == x) return x;
return parent[x] = operator[](parent[x]);
}
bool merge(int x, ... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.