solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
string str;
int n;
struct oper {
int d;
string t;
} p[maxn];
long long val[10], wei[10];
int main() {
cin >> str;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i].d >> p[i].t;
}
for (int i = 0; i < 10... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const long long INF = 1e9;
inline long long pwr(long long base, long long n, long long m) {
long long ans = 1;
while (n > 0) {
if (n % 2 == 1) ans = (ans * base) % m;
base = (base * base) % m;
n /= 2;
}
return ans;
}
const in... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 505;
vector<int> graf[MAXN];
int n, m, bio[MAXN], flag;
vector<pair<int, int> > edges;
pair<int, int> forbid;
bool dfs(int node) {
bio[node] = flag + 2;
for (int nex : graf[node]) {
if (bio[nex] == flag + 1 || forbid == make_pair(node, nex)) continu... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int n, m;
void solve() {
long long int t, k, z, p, q, u, v, x, y, ct = 0, flag = 0;
cin >> n;
double diagonal = 2 / (sqrt(2 * (1 - cos(3.1415926535897932384626 / n))));
double angle = double(180) / double(2 * n);
double cosAngle = cos(angle * 3.141592653... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MOD2 = 1007681537;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
long long r;
while (... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long N;
vector<long long> V;
inline void Get(const long long& A, const long long& B, const long long& C,
int k) {
long long L = 0, R = min(1LL << 31, N / B) + 1;
while (R - L > 1) {
long long M = (L + R) >> 1;
if ((unsigned long long)A * M *... | 2 |
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){
int a, b, c, d, e, f;
while(1){
scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
if((a|b|c|d|e|f) == 0) break;
a += d;
b += e;
c += f;
int lim = min(a, min(b, c)), ans = 0;
for(int i=0;i<=lim... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char x[100][100];
int n, m;
bool f = false, f1 = false;
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
if (f == false)
x[i][j] = '#';
else
x[i][j] = '.';
f = !f;
}
for (int i = 1; i < n... | 1 |
#include <iostream>
#include <vector>
using namespace std;
int main(){
int r,c;
while(cin >> r >> c && r && c){
vector<vector<int> > v(r,vector<int>(c)), v2;
int ans = 0;
for(int i=0;i<r;i++) for(int j=0;j<c;j++) cin >> v[i][j];
for(int i=0;i<(1<<(r-1));i++){
v2 = v;
for(int j=0;j<r-1;... | 0 |
#include <bits/stdc++.h>
using namespace std;
double a[100005], b[100005], p, q;
int n;
double y, l, r;
double check(double x) {
y = 1000000000;
for (int i = 1; i <= n; i++) y = min(y, (1 - a[i] * x) / b[i]);
return p * x + q * y;
}
int main() {
scanf("%d", &n);
scanf("%lf%lf", &p, &q);
for (int i = 1; i <=... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main()
{int N, a, c{}; cin >> N;
for (int i{1}; i <= N; ++i) cin >> a, c += i % 2 * (a % 2);
cout << c;} | 0 |
#include<cstdio>
char a[10],b[10];
int ans;
int main()
{
scanf("%s%s",a,b);
for(int i=0;i<3;i++)
if(a[i]==b[i])ans++;
printf("%d",ans);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, bel[25], tag[25], F[1 << 20];
char S[100005], T[100005];
int Getbel(int x) { return bel[x] == x ? x : (bel[x] = Getbel(bel[x])); }
void Merge(int a, int b) {
a = Getbel(a), b = Getbel(b);
if (a != b) bel[a] = b;
}
int main() {
int C;
scanf("%d", &C);
while ... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> failureFunc(const string &s) {
vector<int> longestPreSuf(s.size() + 1);
longestPreSuf[0] = 0;
longestPreSuf[1] = 0;
for (int i = 2; i <= s.size(); ++i) {
for (int j = longestPreSuf[i - 1];; j = longestPreSuf[j]) {
if (s[j] == s[i - 1]) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, m, q;
long long w[N];
struct node {
int l, r;
long long sum, maxx, minn, tag;
} tr[N * 4];
void pushup(int u) {
tr[u].sum = tr[u << 1].sum + tr[u << 1 | 1].sum;
tr[u].minn = min(tr[u << 1].minn, tr[u << 1 | 1].minn);
tr[u].maxx = max... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int mod = 1e9 + 7;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, x, y, z, w, i, j, k, l;
vector<int> v;
cin >> n;
if (!n)
return cout << "YES\n1\n2\n2\n3", 0;
else if (n == 1) {
cin >> x;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N;
cin >> N;
for (int i = 0; i <= N; i++) if (i * 27 / 25 == N) {
cout << i << endl;
return 0;
}
cout << ":(" << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e, f[105][3005], g, h, i, j, k, l, m, n;
char s[10005];
int main() {
f[0][0] = 1;
for (i = 1; i <= 100; i++)
for (j = 0; j <= i * 26; j++)
for (k = 0; k < 26 && k <= j; k++) {
(f[i][j] += f[i - 1][j - k]) %= 1000000007;
}
int t;... | 5 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int N;
int a[110000];
bool e[33];
signed main() {
cin>>N;
for(... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int dirx[4] = {0, 1, 0, -1};
const int diry[4] = {1, 0, -1, 0};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
;
long long int t, n, x;
cin >> t;
while (t--) {
cin >> n;
vector<int> odd, even;
for (int i = 0; i < n; i++) {
cin >> x... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
bool graph[3010][3010];
vector<int> graph2[3010], out;
int dis[3010][3010];
vector<pair<int, int> > v1[3010], v2[3010];
int ans;
void bfs(int start) {
memset(dis[start], -1, sizeof(dis[0]));
dis[start][start] = 0;
queue<int> que;
que.push(start);
while (... | 2 |
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9;
int dp[10000010][2];
int main(){
string s; cin >> s;
int N=s.size();
dp[0][0]=0;
dp[0][1]=1;
for(int i=0;i<N;i++){
int d=s[i]-'0';
dp[i+1][0]=min(dp[i][0]+d,dp[i][1]+10-d);
dp[i+1][1]=min(dp[i][0]+d+1,dp[i][1]+... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main() {
int k;
cin >> k;
string second;
cin >> second;
long long sum = 0;
vector<int> a;
for (int i = 0; i < second.size(); i++) {
sum += second[i] - 48;
a.push_back(second[i] - 48);
}
sort((a).begin(), (a).end());
i... | 2 |
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 300005;
int n, m, q, cc, cnt, top, Top, dfn_cnt, Dfn_cnt, bcc_ct, Bcc_ct, node_ct,
edge_ct, used_ct, times[Maxn], used[Maxn], c[Maxn], father[Maxn], bel[Maxn],
Bel[Maxn], sta[Maxn], Sta[Maxn], dep[Maxn], anc[Maxn][20], node[Maxn],
real_node[Maxn... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void clear(T &x) {
T t;
x.swap(t);
}
template <class T>
void miz(T &a, T b) {
if (b < a) a = b;
}
template <class T>
void maz(T &a, T b) {
if (b > a) a = b;
}
template <class T>
T gcd(T a, T b) {
while (b) {
a %= b;
swap(a, b);
}
ret... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
struct point {
int x, y;
} a[4];
double d(point a, point b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double ans;
void gan(point p1, point p2, point p3, point p4) {
double temp = d(p1, p2) + d(p2, p3) + d(p3, p4);
if (temp > a... | 2 |
#include <bits/stdc++.h>
using namespace std;
int inf = 1000001000;
long long INF = 1e18;
long long MOD = INF;
long long mod = INF;
int main() {
int n;
string s;
cin >> n >> s;
int u = n - 1;
for (int(i) = 0; (i) < (n - 1); (i)++) {
if (s[i] > s[i + 1]) {
u = i;
break;
}
}
for (int(i) ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string s;
bool c=true,d=false;
cin >> s;
for(n=2;n<s.length();n++){
if(isupper(s[n])&&d){
c=false;
}else if(s[n]=='C'){
d=true;
}
}
if(s[0]=='A'&&islower(s[1])&&d&&c&&s[s.length()-1]!='C'){
cout << "AC" << endl;
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 50 + 10;
int n = 50;
ll k;
int main()
{
scanf("%lld", &k);
ll base = k / n + 49;
int l = k % n;
printf("%d\n", n);
for(int i = 1; i <= n - l; ++i) printf("%lld ", base - l);
for(int i = n - l + 1; i <= n; ++i) printf("%lld ", bas... | 0 |
#include<stdio.h>
int main()
{
int k;
scanf("%d", &k);
while(k--) printf("ACL");
printf("\n");
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
string s;
cin>>s;
long long ans=0LL,cnt=0LL;
for (int i = 2; i < s.size(); ++i)
{
if (s.at(i-2)=='A')
{
++cnt;
}
else
{
cnt=0LL;
}
if (s.at(i-1)=='B'&&s.at(i)=='C')
{
ans+=cnt;
--cnt;
s.at(i)='A';... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MOD2 = 15000007;
const long long int MAX = 9187201950435737471;
const int N = 100005;
const int M = 100005;
const int INF = 2;
const double EPS = 1e-9;
const long double PI = acos(-1);
long long int po(long long int x, long long int y) ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int dp[21][100005];
int sum[100005];
int main() {
memset(dp, -1, sizeof(dp));
int n, q, a;
scanf("%d%d", &n, &q);
sum[0] = 1;
for (int i = 1; i <= n; i++) {
scanf("%d", &a);
for (int j = 0; j < 20; j++) dp[j][i] = dp[j][i - 1];
... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> a, pair<int, int> b) { return a.second > b.second; }
int main() {
int n, m;
cin >> n >> m;
vector<pair<int, int>> arr(m, {0, 0});
for (int i = 0; i < m; i++) {
cin >> arr[i].first >> arr[i].second;
}
sort(arr.begin(), arr.end(), comp... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[1005];
scanf("%s", str);
int cc = -1;
while (str[++cc] != '.') {
}
if (str[cc - 1] == '9') {
printf("GOTO Vasilisa.\n");
return 0;
}
if (str[cc + 1] >= '5') {
for (int i = 0; i < cc - 1; i++) printf("%c", str[i]);
printf... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
char s[200005], g[200005];
int p[200005], q[200005], ans;
signed main() {
scanf("%s", s + 1);
scanf("%s", g + 1);
int n = strlen(s + 1), m = strlen(g + 1), now = 1;
for (int i = 1; i <= n; i++)
if (now <= m && s[i] == g[now]) q[now++] = i;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long s[n], c[n];
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < n; i++) cin >> c[i];
long long s0, s1, s2, ans = 1e18;
for (int j = 1; j < n; j++) {
bool f1 = 0, f2 = 0;
s0 = c[j];
s1 = 1e10;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[1000005];
bool c[1000005];
int dp[1000005][20];
bool f[1000005];
int dd(int x, int n) {
for (int i = 0; i < 20; i++) {
if ((1 << i) & n) x = dp[x][i];
}
return x;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int Z;
cin >> Z;
while (... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
;
int T;
cin >> T;
while (T--) {
int n, a[550];
bool b[550];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
bool l = 0,... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int M = 300010;
bool taken[M];
char s[M];
int main(int argc, char** argv) {
int len, m;
scanf("%d%d\n", &len, &m);
scanf("%s\n", s + 1);
s[0] = 'x';
s[len + 1] = 'x';
len += 2;
int out = 0;
memset(taken, 0, sizeof taken);
for (int i = 1; i < len; i++... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 400 + 10;
struct Graph {
int id, next, b[MAXN];
} g[MAXN * 2];
int n, k, st[MAXN], f[MAXN][MAXN], size[MAXN];
void Add(int tot, int first, int second) {
g[tot].id = second, g[tot].next = st[first], st[first] = tot;
}
void Tree_dp(int first, int fa) {
... | 4 |
#include<cstdio>
using namespace std;
int a[100050];
int main(){
int n;
scanf("%d",&n);
for (int i=1;i<=n;i++)
scanf("%d",&a[i]);
for (int i=2;i<=n;i++)
if (a[i]>a[i-1]) a[i]--;else
if (a[i]<a[i-1]) return printf("No\n"),0;
printf("Yes\n");
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
int n, k;
void solve0()
{
if (n == 1) {
cout << k / 2;
cout << endl;
return;
}
cout << k / 2 << " ";
rep(i, n-2) {
cout << k << " ";
}
cout << k << endl;
}
inline void sub(vector<int>& v, int& pos)
{
... | 0 |
#include <bits/stdc++.h>
using namespace std;
map<string, pair<int, vector<int> > > m;
vector<string> s;
int t;
bool search(string x) {
for (int i = 0; i < s.size(); i++)
if (x == s[i]) return true;
return false;
}
void prep(string x) {
for (int i = 0; i < 60; i++) m[x].second.push_back(0);
}
string check(str... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int N = 200043;
int add(int x, int y) { return (x + y) % MOD; }
int sub(int x, int y) { return add(x, MOD - y); }
int mul(int x, int y) { return (x * 1ll * y) % MOD; }
int binpow(int x, int y) {
int z = 1;
while (y > 0) {
if (y % 2 =... | 5 |
#include <bits/stdc++.h>
using namespace std;
int l1, l2, l3, dp[105][105][105];
char s1[105], s2[105], s3[105];
int dfs(int n1, int n2, int n3) {
if (n1 > l1 || n2 > l2) return dp[n1][n2][n3] = 0;
if (~dp[n1][n2][n3]) return dp[n1][n2][n3];
int &re = dp[n1][n2][n3];
re = 0;
if (s1[n1] == s2[n2]) {
if (s1... | 4 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long n;
cin >> n;
vector<long long> a(n);
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
vector<long long> b(25);
for (long long i = 0; i < n; i++) {
for (long long j = 0; j < 25; j++) {
if (a[i] & (1 << j)) b[j]++;
}... | 4 |
#include <bits/stdc++.h>
using namespace std;
int t, n, a, b, c, d;
int main() {
cin >> t;
while (t--) {
cin >> n >> a >> b >> c >> d;
if (((a - b) * n > c + d) || ((a + b) * n < c - d))
cout << "NO\n";
else
cout << "YES\n";
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 100;
int n, m, lastans = 0;
map<int, int> E[N];
int fa[N], sz[N], ans[N];
int top;
struct pi {
int x, y;
} st[N];
struct OP {
int op, x, y;
} o[N];
struct node {
int l, r;
int op, x, y;
vector<OP> id;
} t[N << 2];
int find(int x) { return x == ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, a[1005], ans[1005][1005];
int bl[1005], br[1005], tp;
int sg[1005];
void print() {
for (int i = 1; i <= (n + 1); ++i) {
int ok = 0;
for (int j = 1; j <= (n); ++j)
if (ans[i][j]) ok = 1;
if (!ok) continue;
for (int j = 1; j <= (n); ++j) printf(... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c;
scanf("%d%d", &n, &c);
int a[n], b[n - 1];
scanf("%d", &a[0]);
for (int i = 1; i < n; i++) {
scanf("%d", &a[i]);
b[i - 1] = a[i - 1] - a[i] - c;
}
int max = 0;
for (int i = 0; i < n - 1; i++) {
if (b[i] > max) max = b[i];
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000100;
const long long P1 = 998244353;
const long long P2 = 1004535809;
const long long E = 3;
long long a[maxn], b[maxn], c[maxn];
int rev[maxn];
int n, k, lim;
long long qpow(long long a, long long b, long long mod) {
long long res = 1;
for (; b > 0... | 5 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long int ans = 0;
void fun(int x, int n) {
if (x > n) return;
ans++;
fun(x * 10, n);
fun(x * 10 + 1, n);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long... | 3 |
#include <bits/stdc++.h>
using namespace std;
string tostr(long long a) {
stringstream rr;
rr << a;
return rr.str();
}
long long pow(long long c, long long d) { return d == 0 ?: c * pow(c, d - 1); }
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long... | 4 |
#include <bits/stdc++.h>
using namespace std;
int t, n, ans, mpos;
struct node {
int a, id;
} x[200010];
bool cmp(node a, node b) { return a.a < b.a; }
int main() {
cin >> t;
while (t--) {
cin >> n;
ans = 0;
for (int i = 1; i <= n; i++) {
cin >> x[i].a;
x[i].id = i;
}
stable_sort(x... | 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64777215")
using namespace std;
const long long maxn = 1001;
const long long maxq = 1000001;
const long long maxk = 11;
const long long mo = 5;
const long long maxseg = 262144;
const long long secret_number = -87468267;
const pair<int, int> secret_pair = make_pai... | 4 |
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <ve... | 0 |
#include <bits/stdc++.h>
using namespace std;
map<long long, map<long long, map<long long, map<long long, int>>>> d;
int go(long long lx, long long ly, long long ax, long long ay, long long bx,
long long by) {
if (lx == 0 && ly == 0) return 1;
if (d[ax][ay][bx][by]) return d[ax][ay][bx][by];
int &ret = d[a... | 5 |
#include<cstdio>
#include<iostream>
using namespace std;
const int step[8][2]={-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};
char a[55][55];
int s[55][55];
int n,m;
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>a[i][j];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(a[i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int q;
cin >> q;
for (int noob = 0; noob < q; noob++) {
string str;
cin >> str;
if (str[str.size() - 1] == 'o')
cout << "FILIPINO\n";
else if (str[str.size() - 1] =... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1000000;
map<long long int, long long int> idx, Xor[N + 5];
vector<long long int> v[N + 5];
long long int par[N + 5];
void init() {
for (long long int i = 1; i <= N; ++i) {
par[i] = i;
v[i].push_back(i);
Xor[i][i] = 0;
}
}
long long i... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long labs(long long a) { return a < 0 ? (-a) : a; }
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
const int MAXN = 6;
const int MAXK = 26;
const int MAXRES = 5 * 1001;
struct Var {
... | 6 |
#include <iostream>
#include <string>
using namespace std;
int main(){
string str;
while(cin>>str){
int num[10];
for(int i=0;i<10;i++){
num[i] = str[i]-48;
}
for(int j=9;j>=0;j--){
for(int k=0;k<j;k++){
if(num[k]+num[k+1]>9) num[k]=num[k]+num[k+1]-10;
else num[k]=num[k]+num[k+1];
}
}
cout... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int pos, len;
int n, k, m, t;
cin >> n >> k >> m >> t;
pos = k;
len = n;
for (int i = 0; i < t; i++) {
int a, b;
cin >> a >> b;
if (a == 0) {
if (b < pos) {
pos -= b;
len -= b;
} else {
len = b;
... | 4 |
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lpin(a,i,n) for(int i=0;i<n;i++){cin>>a[i];}
int main(){
int n,i=1;
cin>>n;
while(1){
int count=0;
for(int j=1;j<i+1;j++){
if(i%j==0) count++;
}
if(count==n) break;
i++;
}
cout<<i<<endl;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000100;
const int INF = 1e9 + 10;
struct Node {
int k, a;
friend bool operator<(Node A, Node B) { return A.k < B.k; }
};
Node b[maxn];
int n;
bool check(long long m) {
for (int i = 1; i <= n; i++) {
if ((m - b[i].k) * 2 >= log2(b[i].a)) continue;... | 3 |
#include <bits/stdc++.h>
const int N = 100100;
using namespace std;
int d[N][2];
int n, a[N];
int mod = 1e9 + 7;
vector<int> v[N];
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 2; i <= n; i++) {
int p;
cin >> p;
v[p + 1].push_back(i);
}
for (int i = 1; i <= n; i++) cin >> a[i];... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
static void rmin(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
static void rmax(T &x, U y) {
if (x < y) x = y;
}
const double eps = 1e-9;
const double pi = acos(-1.0);
const int MOD = 1e9 + 7;
const int INF = 1e9 + ... | 3 |
#include <bits/stdc++.h>
using namespace std;
pair<char, int> a[100007];
string s[1007];
pair<int, int> pos[30];
int q;
int n, m;
int sum[1007][1007];
string ans;
bool isvalid(int x, int y, int xx, int yy) {
if (xx >= n || xx < 0 || yy >= m || yy < 0) return false;
if (x == xx) {
if (y > yy) swap(y, yy);
re... | 4 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=305,mod=998244353;
int n,k,m,a[N],sum[N];
int dp[N][N][N];
//dp[i][j][h] 第i个坑,用了j个1,移动了k次的方案数
char s[N];
int main()
{
scanf("%s%d",s+1,&k);
for(int i=1;s[i];i++) m+=s[i]=='1';
int t=0;
for(int i=1;s[i];i++)
if(s[i]=='... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int M = 50 + 10;
int n, m;
char board[100][100];
int cor[8] = {0, 1, 0, -1, 1, 0, -1, 0};
int low[M][M];
int layer[M][M];
int visited[M][M];
int timestamp;
int rootchild;
int sx, sy;
bool ok = false;
void tarjan(pair<int, int> cur, pair<int, int> father) {
int curx ... | 3 |
#include<bits/stdc++.h>
using namespace std;
typedef pair< int , int > Pi;
typedef long long int64;
int N;
Pi data[300000];
bool calc(int value){ //閉じこめられる微生物value
priority_queue < Pi, vector< Pi >, greater< Pi > > que; //許容量が小さい順に取り出す(?)
int64 sum = 0; //放出量の和
for(int i = 0; i < N; i++){ //人数分入れる
sum += d... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 500;
int a[N], s[2 * N + 1];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; ++i) cin >> a[i];
memset(s, 0, sizeof(s));
for (int i = 0... | 2 |
#include<iostream>
using namespace std;
#define M 1000000
#define NIL -1
struct N{ int p,cl,sr;};
N nd[M];
int de[M];
void print(int x){
int i,j;
cout<<"node "<<x<<": parent = "<<nd[x].p<<", depth = ";
cout<<de[x]<<", ";
if(nd[x].p==NIL)cout<<"root, [";
else if(nd[x].cl==NIL)cout<<"leaf, [";
else cout<<"in... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, m, k;
int b[N], a[N];
int main() {
scanf("%d%d%d", &n, &m, &k);
int ans = n;
k = n - k;
for (int i = 1; i <= n; ++i) scanf("%d", &b[i]);
for (int i = 1; i < n; ++i) a[i] = b[i + 1] - b[i] - 1;
nth_element(a + 1, a + k, a + n);
ans ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6;
struct fastIO {
fastIO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
};
int n, ans;
vector<vector<int> > v;
queue<int> q;
int main() {
fastIO();
cin >> n;
v.resize(n);
for (int i = 1; i <= n - 1; i++) {
int j;... | 4 |
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <iostream>
using namespace std;
char st[5010];
int f[5010][5010];
int main()
{
int n;scanf("%d",&n);
scanf("%s",st+1);
int ans=0;
for (int i=1;i<=n;i++)
for (int j=i+1;j<=n;j++)
{
if (st[i]==st[j]) f[i][j]=f[i-1][j-1]+1;... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool isUsed(int row, int col, int k) {
if (row == 1 && col == 3) {
cout << "";
}
int seat = (row - 1) * 3 + col;
if (row != 1) {
seat++;
}
if (col == 3 && seat <= k) {
return row == 1;
} else if (col == 4 && row > 1) {
seat--;
}
return seat... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string text;
getline(cin, text);
map<char, int> mapping;
for (int i = 0; i < text.size(); i++) {
mapping[text[i]]++;
}
int no_of_i = mapping['i'];
while (no_of_i) {
if ((mapping['n'] / 3 >= no_of_i ||
mapping['n'] >= 3 + (no_of_i ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
string in;
int nm = 0;
int nm2 = 0;
int x;
char c;
int main() {
cin >> n >> m;
cin >> in;
for (int i = 0; i < n; i++) {
if (in[i] == '.') nm++;
}
if (in[0] == '.') nm2++;
for (int i = 1; i < n; i++) {
if (in[i] == '.' && in[i - 1] != '.') {
... | 3 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
using namespace std;
class BIT {
private:
int size_; vector<int>x;
public:
BIT() : size_(0), x(vector<int>()) {};
BIT(int size__) : size_(size__) {
x.resize(size__ + 1);
for (int i = 0; i < size__ + 1; i++)x[i] = 0;
}
int size() { return s... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 2e5 + 10;
const long long int mod = 1e9 + 7;
const long long int level = 20;
long long int dp[505][505];
int main() {
ios::sync_with_stdio(false);
long long int n;
cin >> n;
long long int arr[n + 1];
for (long long int i = 1; i < n + 1; i++... | 4 |
#include <bits/stdc++.h>
using namespace std;
using pi = pair<int, int>;
const int MAXN = 1005;
const int MAXM = 200005;
vector<int> gph[MAXN];
int adj[MAXN][MAXN], vis[MAXN];
int n, m;
int s[MAXM], e[MAXM];
void dfs(int r, int v){
vis[v] = 1;
adj[r][v]++;
for(auto &i : gph[v]){
if(i == r) continue;
if(!vis[i]... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
const T& max(const T& a, const T& b, const T& c) {
return max(a, max(b, c));
}
template <class T>
const T& min(const T& a, const T& b, const T& c) {
return min(a, min(b, c));
}
long long stoi(string& str) {
istringstream second(str);
long long i;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
int n, ans;
string s, ss;
int f[11][4][10][100005];
int N = 100005;
int type(char ch) {
if (ch == 'A') return 0;
if (ch == 'T') return 1;
if (ch == 'G') return 2;
return 3;
}
void upd(int j, int typ, int id, int pos, int val) {
for (; p... | 5 |
#include <bits/stdc++.h>
using namespace std;
void make_unique(vector<int> &a) {
sort(a.begin(), a.end());
a.erase(unique(a.begin(), a.end()), a.end());
}
int Set(int N, int cur) { return N = N | (1 << cur); }
int Reset(int N, int cur) { return N = N & ~(1 << cur); }
bool Check(int N, int cur) { return (bool)(N & (... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
string a[100005];
set<int> b;
pair<int, int> c[2000005];
void mark(int l, int r, int i) {
while (1) {
auto it = b.lower_bound(l);
if (it == b.end() || *it > r) break;
c[*it] = {i, *it - l};
b.erase(it);
}
}
int main() {
ios_base::sync_with_stdio... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
const double eps = 1e-8;
int A[55][55], t[55][55];
void mul(int (&a)[55][55], int (&b)[55][55], int (&c)[55][55]) {
int t[55][55];
memset(t, 0, sizeof(A));
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (a[i][j])
for (int k = 1; ... | 5 |
#include <bits/stdc++.h>
char m[510][510];
int a[510][510];
int r1, c1, rr, cr, sum;
int main() {
int r, c, q;
while (~scanf("%d%d", &r, &c)) {
for (int i = 0; i < r; i++) scanf("%s", m[i]);
a[0][0] = 0;
for (int i = 1; i < c; i++) {
a[0][i] = a[0][i - 1];
if (m[0][i] == '.' && m[0][i - 1] =... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 256;
int n, A[MAXN], indeg[MAXN];
vector<int> G[MAXN];
bool r[MAXN];
int sim(int id) {
memset(r, false, sizeof r);
memset(indeg, 0, sizeof indeg);
for (int i = (0); i < (int)(n); i++)
for (int j = (0); j < (int)(G[i].size()); j++) indeg[G[i][j]]++... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100500;
const int N = 50;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
long long n, p, w, d;
scanf("%lld%lld%lld%lld", &n, &p, &w, &d);
long long s = w * d / gcd(w, d);
long long nw = s / w;
long long... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int i, j, tmp = 0;
string s, s1;
cin >> s;
cin >> s1;
long long int a[27] = {0}, a1[27];
for (i = 0; i < s.size(); i++) {
long long int ta = s[i] - 'a' + 1;
long long... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, a[N], ans[N];
int b[N];
int ask(int x) {
int ans = 0;
for (; x; x -= x & -x) ans = max(ans, b[x]);
return ans;
}
void add(int x, int c) {
for (; x <= n; x += x & -x) b[x] = max(b[x], c);
}
int main() {
cin >> n;
for (int i = 1; i <= ... | 2 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n;cin>>n;
vector<int> v(n);
for(int i=0;i<n;i++)cin>>v[i];
map<int,int> m;
int ans=0;
for(int i=n-1;i>=0;i--){
ans+=m[v[i]+i];
m[i-v[i]]++;
}
cout<<ans<<endl;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a;
while(cin>>a,a){
vector<unordered_set<string>>V(50);
for(int b=0;b<a;b++){
string c;cin>>c;
string d="a";d[0]=c[0];
for(int e=1;e<c.length();e++){
if(c[e-1]=='a'||c[e-1]=='i'||c[e-1]=='u'||c[e-1]=='e'||c[e-1]=='o'){... | 0 |
#include<iostream>
using namespace std;
int main(){
string s;
cin>>s;
if(s=="A")cout<<"T";
else if(s=="T")cout<<"A";
else if(s=="G")cout<<"C";
else cout<<"G";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, int> > in(n);
vector<int> out(n);
for (int i = 0; i < n; ++i) {
cin >> in[i].first;
in[i].second = i;
}
sort(in.begin(), in.end());
int type;
bool valid = true;
int outCont = 1;
for (int i = 0; i <... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n4 = 0, n7 = 0;
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '4') n4++;
if (s[i] == '7') n7++;
}
if (n4 == 0 && n7 == 0) {
cout << "-1" << endl;
return 0;
}
if (n4 > n7) {
cout << "4" << endl;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
queue<pair<int, long long> > Q[3];
int Pr[3];
int Cap[3];
int E[100005];
int N;
long long ans = 0;
void push(int k, int man, long long t) {
if (k == 3) {
ans = max(ans, t - E[man]);
return;
}
while ((int)(Q[k]).size() && Q[k].front().second + Pr[k] <= t) {
... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.