solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1 << 30;
int main() {
int n, m;
cin >> n >> m;
string str;
cin >> str;
int l, r;
char c1, c2;
for (int i = 0; i < m; i++) {
cin >> l >> r >> c1 >> c2;
for (int j = l - 1; j <= r - 1; j++) {
if (c1 == str[j]) {
str[j]... | 1 |
#include <bits/stdc++.h>
using namespace std;
int v[400][400][10][30];
bool z[500][500];
int n, t[50];
int a[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int b[] = {0, 1, -1, 1, -1, 1, -1, 0};
int ri[10];
int le[10];
void dfs(int x, int y, int k = 0, int i = 0) {
if (v[x + 200][y + 200][k][i]) {
return;
}
if (i == n) ret... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, n;
cin >> a >> b;
n = abs(a - b) / 2;
if ((a - b) % 2 == 0)
cout << n * (n + 1);
else
cout << (n + 1) * (n + 1);
return 0;
}
| 1 |
#include <iostream>
#include <set>
#include <cstring>
using namespace std;
int n;
int main() {
while (cin >> n, n != 0) {
set<int> mod;
for (int i = 1; i < n; i++)
mod.insert( (i*i) % n );
int count[(n-1)/2+1];
memset(count, 0, sizeof(count));
for (set<int>::it... | 0 |
//ceil(a/b) is equal to (a+b-1)/b
#include<bits/stdc++.h>
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define int long long int
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define vec vector <int>
#define pr vector<pair<int,int>>
#define vecv vector <vec>
#d... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool sieve[2000006];
int fprime[2000006];
vector<int> divset;
void primeTable() {
int i, j;
int lim = sqrt((double)2000006) + 6;
memset(fprime, -1, sizeof(fprime));
fprime[2] = 2;
for (i = 4; i < 2000006; i += 2) sieve[i] = true, fprime[i] = 2;
for (i = 3; i < l... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
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];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if ((i + j) & ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int indg[121212];
vector<int> edge[121212];
int par[121212];
void dfs(int w, int bef) {
int i;
par[w] = bef;
indg[bef]++;
for (i = 0; i < edge[w].size(); i++) {
int nxt = edge[w][i];
if (nxt == bef) continue;
dfs(nxt, w);
}
}
int main() {
int n;
sc... | 3 |
#include <bits/stdc++.h>
using namespace std;
string s[11];
int len[11], id[11];
vector<string> ans;
void upd(vector<string> &cur) {
if (!ans.size()) {
ans = cur;
return;
}
for (int i = 0; i < (int)ans.size(); i++) {
if (cur[i] < ans[i]) break;
if (cur[i] > ans[i]) return;
}
ans = cur;
}
int m... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 1e5 + 5;
int n, len = 1, a[maxn], st[4 * maxn];
void compress() {
set<int> s;
map<int, int> ids;
for (int i = 0; i < n; i++) s.insert(a[i]);
for (int x : s) ids[x] = len++;
for (int i = 0; i < n; i++) a[i] = ids[a[i]];
}
void... | 4 |
#include <bits/stdc++.h>
using namespace std;
double fac[200005], ln[200005];
inline double Poi(int x, int P) {
x += P;
return x * ln[P] - P - fac[x];
}
inline double Uni(int x, int P) {
x += P;
if (x < 0 || x > 2 * P) return -1e20;
return -ln[2 * P + 1];
}
const int N = 255;
int T;
int a[N];
int main() {
i... | 6 |
#include <bits/stdc++.h>
static long long other_try(std::vector<int>& attacking,
const std::vector<int>& attack_pos,
const std::vector<int>& def_pos) {
std::sort(attacking.begin(), attacking.end());
long long ret = 0;
for (int i = 0; i < def_pos.size(); i++) {... | 2 |
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loo... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
long long K;
cin>>K;
queue<long long> q;
for(int i=1;i<=9;i++)
{
q.push(i);
}
while(!q.empty())
{
long long x=q.front();
q.pop();
K--;
if (K==0)
{
cout<<x<<endl;
break;
}
for(int y=(x%10)-1;y<=(x%10)+1;y++) {
if (y<0 || y>=10)
... | 0 |
#include <bits/stdc++.h>
#define MAX_N (100010)
using namespace std;
typedef long long Int;
int par[MAX_N];
Int w[MAX_N];
Int abso[MAX_N];
void init(int N)
{
for (int i = 0; i < N; i++) par[i] = i;
}
int goup(int x)
{
if (x == par[x]) return (x);
else {
int p = goup(par[x]);
w[x] += w[par[x]];
return (par... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2 * 1e5;
const long long mod = 1e9 + 7;
long long len, fact[MAXN + 5], inv[MAXN + 5];
long long pref[MAXN + 5], suf[MAXN + 5];
string in;
long long nck(long long n, long long k) {
long long tmp1 = fact[n];
long long tmp2 = inv[k];
long long tmp ... | 4 |
#include <bits/stdc++.h>
int main(void) {
int t;
scanf("%d", &t);
while (t--) {
char a[101], b[101], c[101];
scanf("%s", a);
scanf("%s", b);
scanf("%s", c);
int s = strlen(a);
int i = 0;
for (i = 0; i < s; i++) {
if (a[i] == c[i]) {
continue;
} else if (b[i] == c[i]... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100, LOG = 18, A = 10, inF = 2e9;
int n, m, q, u, v, a, LCA, h[N], upper[N][LOG];
vector<int> nei[N], in[N], vec[N][LOG];
void dfs(int v) {
vector<int> help;
for (int i = 1; i < LOG; i++) {
upper[v][i] = upper[upper[v][i - 1]][i - 1];
help.cl... | 5 |
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
using namespace std;
#define INF 1000000007
#define LINF (1LL << 62)
typedef long long i64;
typedef pair<i64,i64> P;
int h, w, k, ans[303][303];
string s[303];
int main(){
cin >> ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int power[15] = {1, 2, 4, 8, 16, 32, 64, 128,
256, 512, 1024, 2048, 4096, 8192, 16384};
int main() {
int nizNext[2000];
int nizVals[2000];
int nizValsTemp[2000];
int nizDepth[2000];
int n;
cin >> n;
for (int i = 0; i < n; i++) ... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 500010;
struct DSU {
int par[MAXN];
int sz[MAXN];
DSU() {
for (int i = 1; i < MAXN; i++)... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, i;
cin >> n;
int a[n];
int b[10004];
for (i = 0; i < 10004; i++) b[i] = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
b[a[i]]++;
}
long long int x = *max_element(a... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool in1, in2, in3, in4;
int main() {
cin >> in1 >> in2 >> in3 >> in4;
printf("%d\n",
int(((in1 ^ in2) & (in3 | in4)) ^ ((in2 & in3) | (in1 ^ in4))));
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[4][4];
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++) cin >> a[i][j];
if (a[0][3] == 1 &&
(a[0][0] || a[0][1] || a[0][2] || a[1][0] || a[2][1] || a[3][2]))
cout << "YES";
else if (a[1][3] == 1 &&
(a[1][0] || a[1][... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector<int> adj[N];
int sum1[N], now1, wow, cac1, level[N];
bool used[N];
void dfs(int x, int p) {
if (level[x] == now1) {
sum1[x]++;
}
for (int i = 0; i < adj[x].size(); i++) {
if (adj[x][i] != p) {
level[adj[x][i]] = level[x] + 1... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
if (k > 1) {
cout << "Yes" << endl;
return 0;
}
vector<int> v;
int prev;
cin >> prev;
v.push_back(prev);
int index;
if (prev == 0) {
index = 0;
}
for ... | 1 |
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
for(;a;swap(a,b)) b%=a;
return b;
}
ll lcm(ll a,ll b){
return a*b/gcd(a,b);
}
int main(){
for(int n;scanf("%d",&n),n;){
int d[10],v[10];
for(int i=0;i<n;i++){
scanf("%d%d",d+i,v+i);
int g=gcd(d[i],v[i])... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long ans = 0, cnt... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 10;
const double eps = 1e-9;
const int inf = 1e9;
int a[mx];
char vowel[5] = {'a', 'e', 'i', 'o', 'u'};
bool IsPrimeSlow(long long x) {
if (x <= 1) return false;
if (x <= 3) return true;
if (!(x % 2) | !(x % 3)) return false;
long long second = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
for (int o = 0; o < q; o++) {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
double s = 0;
for (int i = 0; i < n; i++) {
s += a[i];
}
s /= n;
int ans = c... | 1 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;ll k;
int a[200010],head[200010],nxt[200010],ne[200010],cz[200010],t[200010];
int sta[200010],top;bool b[200010];
int calc(int pl){
for(int i=pl;i<=n;i++){
if(!b[a[i]])sta[++top]=a[i],b[a[i]]=1;
else {
b[a[i]]=0;
while(sta[top]!=a[i])b[s... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long x) {
long long ans = 1;
for (int i = 0; i < x; ++i) ans *= a;
return ans;
}
int main() {
int n;
cin >> n;
vector<long long> v(n);
for (int i = 0; i < n; ++i) cin >> v[i];
long long sum = 0;
for (int i = 0; i < n; ++i)... | 2 |
#include <iostream>
#include <deque>
#include <vector>
using namespace std;
int n,m;
bool used[100005];
vector<int> g[100005];
deque<int> dq;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
for(int i=0;i<m;i++){
int u,v;
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
dq.push_back(1);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int getint() {
char c;
while ((c = getchar()) < '0' || c > '9')
;
return c - '0';
}
pair<pair<long long, long long>, long long> b[200005];
pair<long long, long long> a[200005];
long long bridge[200005];
map<long long, long long> mp, mp1;
vector<long long> a... | 2 |
#include<queue>
#include<cstdio>
#include<vector>
#include<complex>
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef complex<double> Point;
const double EPS=1e-9;
class Line:public vector<Point... | 0 |
#include <bits/stdc++.h>
int main() {
int p = 0, i = 0;
scanf("%d\n", &p);
for (i = 0; i < p; i++) {
int a = 0, b = 0, c = 0, e = 0;
char d[100];
scanf("%d\n", &a);
gets(d);
if (a >= 11) {
for (b = 0; b < a; b++) {
if (d[b] == '8') {
c = a - b;
break;
... | 1 |
#include <bits/stdc++.h>
char _;
using namespace std;
int N, C, D;
pair<int, int> A[400000];
long long Z, ZO, ZOZ, O, OZ, OZO;
inline bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
if ((b.second < 0) ^ (a.second < 0))
return 1LL * a.first * b.second > 1LL * b.first * a.second;
return 1LL * a.first... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const long long int INFLL = 1e18 + 10;
const long double EPS = 1e-8;
const long double EPSLD = 1e-14;
const long long int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
return a = min(a, b);
}
template <class T>
T &chmax(T &a, con... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x0, y0, x, y;
cin >> n >> x0 >> y0;
unordered_set<double> us;
while (n--) {
cin >> x >> y;
if (x == x0) {
us.insert(1000000000);
continue;
}
double d = (y - y0) / (double)(x - x0);
us.insert(d);
}
cout << us.si... | 2 |
#include <bits/stdc++.h>
using namespace std;
int from[42], to[42];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d %d", from + i, to + i);
}
double res = 0;
for (int ans = 1; ans <= 10007; ans++) {
for (int t = 0; t < (1 << n); t++) {
int cnt = 0;
for (int i... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long mxp2(long long a) {
long long ans = pow(2, 60);
while (a % ans) ans /= 2;
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, q, u, temp;
cin >> n >> q;
string s;
while (q--) {
cin >> u >> s;
for (char... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
const int maxm = 1001100;
int par[maxm];
int ran[maxm];
int num[maxm];
bool check[maxm];
int n, m;
long long k;
int ned;
void init(int n) {
for (int i = 0; i < n; ++i) {
par[i] = i;
ran[i] = 0;
num[i] = 1;
check[i] = 0;
}
}
int cha... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 3e5 + 10;
void init(vector<pair<int, int>>& vp) {
vector<int> v;
for (auto& p : vp) v.push_back(p.second);
sort(v.begin(), v.end());
for (auto& p : vp) {
p.second = lower_bound(v.begin(), v.end(), p.second) - v.begin(... | 6 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int>
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
const int INF = 1001001001;
//int 2×10の9乗
//vector<vector<int>>... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 1e5 + 10;
void solve() {
long long n, k;
cin >> n >> k;
vector<bool> vis(2 * n + 1, false);
vector<pair<long long, long long>> a;
for (long long i = 0; i < k; i++) {
long long x, y;
cin >> x >> y;
if (... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = int(3e5), mod = int(1e9) + 7, block = 316;
int n, m, q;
vector<int> g[N], comp[N], heavy, di[N];
int root[N], cur, sz[N], d[N], dr[N], d1[N], d2[N];
bool used[N];
bool h[N];
long double ans[N], fans[N];
vector<pair<int, int> > qu[N];
void dfs(int v) {
used[v... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 600005;
vector<long long int> gr[N];
long long int deg[N];
long long int nxt;
long long int d, k, n;
void dfs(long long int cur, long long int dep) {
if (dep <= 0) return;
for (long long int i = 0; i < k; i++) {
if (deg[cur] < k && nxt <= n) ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int pnt[100001][2];
long long int s1[100001];
long long int s2[100001];
int main() {
long long int n;
cin >> n;
for (long long int i = 1; i <= n; i++) cin >> pnt[i][0] >> pnt[i][1];
long long int sum = 0;
for (long long int i = 1; i <= n; i++) s1[i] = s1... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const long double PI = 3.141592653589793238462643383279502884197;
priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;
char visit[50];
int vec[50];
long long dp[50][50][50];
long long mp(long long a, long long b) {
long long ... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool compare(const int& a, const int& b) { return a > b; }
int main() {
int a[101];
int i = 0;
int n, k;
cin >> n >> k;
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n, compare);
cout << a[k - 1] << endl;
}
| 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
string itos(int n) {
stringstream ss;
ss << n;
string second = ss.str();
return second;
}
long long ppow(long long x, long long y, long long mod) {
long long res = 1;
while (y) {
if (y & 1) res = res * x % mod;
y >>= 1;
x =... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 20;
long long sum;
int k, p, n, a[N + 1], i, b[N + 1], left_tree[N + 1], right_tree[N + 1];
vector<long long> leftv, rightv;
void update(int index, int value, int tree[]) {
while (index < N + 1) {
tree[index] += value;
index += (index & -index);... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010, inf = 0x7fffffff;
int n, a[maxn], L[maxn][20], R[maxn][20];
inline int read() {
char ch = getchar();
int x = 0;
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + ch - '0';
ch = ge... | 4 |
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
template <class S, class T>
istream& operator>>(istream& is, pair<S, T>& p) ... | 1 |
#include <cstdio>
using namespace std;
// 0A 1X 2Y 3Z 4W 5B 6
typedef struct {
int naw;
int next_1;
int next_0;
}MAP;
int main()
{
char road[150];
MAP ma[6];
ma[0].naw = 0;
ma[0].next_1 = 2;
ma[0].next_0 = 1;
ma[1].naw = 1;
ma[1].next_1 = 3;
ma[1].next_0 = 6;
ma[2].naw = 2;
ma[2].next_1 = 6;
ma[... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool mark[1000];
int main() {
long long n, i, l;
double rad = 0, m;
cin >> n >> l;
long long lamp[n + 10];
for (i = 0; i < n; i++) {
scanf("%lld", &lamp[i]);
}
sort(lamp, lamp + n);
rad = max(lamp[0] - 0, l - lamp[n - 1]);
i = 0;
if (lamp[0] == 0) i ... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s,hitachi="";
cin>>s;
for (register int i=1;i<=5;i++)
{
hitachi+="hi";
if (hitachi==s)
return cout<< "Yes\n",0;
}
return cout<<"No\n",0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<long long int> t;
long long int x;
for (int i = 0; i < n; ++i) {
cin >> x;
t.push_back(x);
}
sort(t.begin(), t.end());
long long int tmin = t[0], tmax = t[n ... | 1 |
#include <bits/stdc++.h>
using namespace std;
char s[30][30];
int data[30][30], common[30][30], b[30][30], dp[(1 << 22)], n, m;
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) scanf("%s", s[i]);
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j) scanf("%d", &data[i][j]);
for (int i = 0;... | 3 |
#include <bits/stdc++.h>
using namespace std;
int c[10];
int main() {
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
int x1, x2, x3, x4;
x2 = (c2 - r2 + d2) / 2;
x3 = (r2 - c2 + d2) / 2;
x1 = r1 - x2;
x4 = c2 - x2;
int flag = 0;
if (x1 + x2 == r1 && x3 + x4 == r2 && x1 + x3 == c1... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline int readChar();
template <class T = int>
inline T readInt();
template <class T>
inline void writeInt(T first, char end = 0);
inline void writeChar(int first);
inline void writeWord(const char *s);
static const int buf_size = 4096;
inline int getChar() {
static char... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1000005;
const long long SQRTN = 1003;
const long long LOGN = 22;
const double PI = acos(-1);
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const long long FMOD = 998244353;
const double eps = 1e-9;
void __print(long long x) { cerr << x; ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 11;
typedef int i_N[maxN];
int N, M, K;
set<int> adj[maxN];
i_N deg, mark;
int ans;
pair<int, int> edge[maxN];
void dfs(int u) {
if (mark[u]++) return;
ans--;
for (set<int>::iterator it = adj[u].begin(); it != adj[u].end(); it++) {
int v = *... | 5 |
#include <bits/stdc++.h>
using namespace std;
int CC;
struct str {
int L, P;
char C[15];
bool operator<(const str& S) const {
if (P > S.P) return true;
if (P < S.P) return false;
return (strcmp(C, S.C) < 0);
}
};
str G[101];
int GetPOS(char* A) {
for (int p = (1); p <= (CC); p += (1))
if (strc... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 2e5 + 9;
const long long mod = 1e9 + 7;
const long long inf = (1ll << 60);
long long n, a[MX], lvl[MX], par[MX], dp[30][MX], V[30][MX], p[MX];
bool vis[MX];
vector<pair<long long, long long> > v[MX];
void build(long long x, long long p) {
if (vis[x]) return... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long l, r;
cin >> l >> r;
if (l - r == 0)
cout << l;
else if (l - r == 3) {
if (l % 3 == 0)
cout << "3";
else
cout << "2";
} else
cout << "2";
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long dp[40][40];
int n, h;
int main(void) {
cin >> n >> h;
for (int i = 0; i <= n; ++i) dp[0][i] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
for (int k = 0; k < j; ++k) {
dp[j][i] += dp[k][i - 1] * dp[j - k - 1][i - 1];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3c3c3c3c;
const long long LINF = 1ll * INF * INF * 2;
const int N = 4100;
const int MOD = 998244353;
int n, m;
long long x[N];
int ans[N][N];
int P[N];
int rev[N];
int cnt[N];
int B = 1;
int _rev(int x) {
if (x == 1) return 1;
return -(1ll * (MOD / x) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 5;
int n;
string s, ans;
int main() {
while (scanf("%d", &n) != EOF) {
cin >> s;
ans = string(n, '9');
for (int add = 0; add < 10; add++) {
for (int shift = 0; shift < n; shift++) {
ans = min(ans, s.substr(shift, n - shift) + ... | 2 |
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const long long mod=1000000007;
int n,po,l,r,mid,ans1,ans2;
long long d[201],K,ma,k,a[201],mi,ans,tot,f[61][61][2],ff[61][61][2],t[61],tmp,len,m,mii[201][24401],le;
struct node
{
long long b,c,d;
int po;
}x[201];
int solve(long long... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,cnt=0;
long long a;
map<long long,bool>mp;
cin>>n;
while(n--){
cin>>a;
if(mp[a]){
cnt--;
mp[a]=0;
}
else{
mp[a]=1;
cnt++;
}
}
cout<<cnt;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pii pair<int,int>
#define mod 998244353
int lowbit(int x) {return x&(-x);}
int n,d;
int a[200010];
vector <pair<ll,pii> > e;
struct UF{
i... | 0 |
#include <bits/stdc++.h>
int main() {
int s, k, i, n, j;
scanf("%d", &n);
int a[1000], b[1000];
for (i = 0; i < n; i++) scanf("%d", &a[i]);
std::sort(a, a + n);
k = n;
for (i = 0; i < n; i++) {
b[i] = 1;
}
for (i = 0; i < n; i = i + b[i])
for (j = i + 1; j < n; j++) {
if (a[i] == a[j]) {... | 1 |
#include<bits/stdc++.h>
using namespace std;
#define nn 65536*4
#define N 2005
#define ll long long
#define mod 1000000007
ll f[nn],rf[nn];int n;
ll qpow(ll x,ll y)
{
ll res=1;
while(y)
{
if(y&1) res=res*x%mod;
x=x*x%mod;y=y/2;
}
return res;
}
ll a[nn],b[nn];
ll dp[N+N][N+N];
ll bas=N-2;
ll C(ll x,ll y)
{
ret... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
vector<string> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
int c = 0, d = 0;
for (long long int i = 0; i < v[0].size(); i++) {
for (long long int j = 0; j < n; j++) {
if (v[j][i] == v[0][i]) {
... | 1 |
#include <bits/stdc++.h>
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)
using namespace std;
typedef lon... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
long long N;
cin >> N;
long long ans=0;
for(auto i=1;i<=N;i++)ans+=(i+(N/i*i))*(N/i)/2;
cout << ans << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 3;
const int MOD = 1e9 + 7;
int pow3[MAX];
int pre[MAX][4];
int add(int a, int b) { return (a + b < MOD) ? (a + b) : (a + b - MOD); }
int sub(int a, int b) { return (a - b >= 0) ? (a - b) : (a - b + MOD); }
int mul(int a, int b) { return (a * 1LL * b) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T min(T &a, T &b) {
return a < b ? a : b;
}
template <class T>
inline T max(T &a, T &b) {
return a > b ? a : b;
}
template <class T>
void read(T &x) {
char ch;
while ((ch = getchar()) && !isdigit(ch))
;
x = ch - '0';
while ((ch = ge... | 1 |
#include <bits/stdc++.h>
using namespace std;
int bits[1000];
int main() {
int n, sum = 0;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> bits[i];
}
bool flag = false;
for (int i = 0; i < n; ++i) {
if (!bits[i] && flag) {
sum += 1;
flag = false;
}
if (bits[i]) {
flag = true... | 2 |
#include<iostream>
using namespace std;
int f(int a,int b,int c){return(a+c)*4+b*9;}
int I[1000],a[1000],b[1000],c[1000];
int P,Q,R,C;
int main()
{
int n;
while(cin>>n,n)
{
for(int i=0;i<n;i++)cin>>I[i]>>a[i]>>b[i]>>c[i];
cin>>P>>Q>>R>>C;
int cnt=0;
for(int i=0;i<n;i++)
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007ll;
inline void print(char pt) { printf("%c\n", pt); }
inline void print(int pt) { printf("%d\n", pt); }
inline void print(long long pt) { printf("%I64d\n", pt); }
inline void print(double pt) { printf("%f\n", pt); }
inline void print(char pt[]) { ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
double eps = 0.0000001;
struct point {
double x, y;
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long a, b, c;
cin >> a >> b >> c;
cout << fixed << setprecision(8);
point q, p;
cin >>... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
int l[150];
string s;
cin >> s;
string ans;
int mx = 0;
for (int j = 26; j >= 0; j--) {
for (int i = mx; i < s.size(); i++) {
if (s[i] == 'a' + j) {
mx = i;
ans += s[i];
}
}
}
cout << ans;
return... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long heights[300001], check[300001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int columns;
cin >> columns;
long long white = 0, black = 0;
int p = 0;
for (int i{1}; i <= columns; ++i) {
cin >> heights[i];
if (p) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve_fast(int n) {
vector<vector<int>> ds(n + 1);
for (int i = 2; i <= n; i++) {
for (int j = i; j <= n; j += i) {
ds[j].push_back(i);
}
}
vector<int> ps;
for (int i = 1; i <= n; i++) {
if (ds[i].size() < 2) {
ps.push_back(i);
}
... | 6 |
#include <bits/stdc++.h>
const int MAX_N = 505 * 505;
const double eps = 1e-6;
const int inf = (int)1e9 + 123;
using namespace std;
int pr[MAX_N], sz[MAX_N], h[MAX_N];
int Parent(int a) {
if (a == pr[a]) return a;
return pr[a] = Parent(pr[a]);
}
void Union(int a, int b) {
a = Parent(a), b = Parent(b);
if (a == ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-15;
const int maxN = 1 * 100000 + 10, mod = (int)1e9 + 7;
int n;
vector<int> v[maxN];
char rang[maxN];
bool mark[maxN];
int zir[maxN];
pair<int, int> pp;
pair<int, int> who(int i, int maxx) {
mark[i] = 1;
zir[i] = 0;
bool vb = 1;
for (int j = 0... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
return x > 0 ? x : -x;
}
int n;
int m;
long long s;
int x[100000];
multiset<int> all;
int main() {
scanf("%d%d", &n, &m);
scanf("%I64d", &s);
for (int i = 0; i < n; i++) scanf("%d", &x[i]);
int ans = n;
long long cur = 0;
for (i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int dr[] = {0, -1, 0, 1, -1, 1, 1, -1};
const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1};
const double eps = 1e-9;
template <class T>
void print(T const &x) {
ostringstream os;
os << x;
cout << os.str() << endl;
}
template <class T>
void print(vector<T> const &v) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long d[100003], sum[403], shelf[403];
int n, m;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
long long x;
int t;
cin >> t;
for (int j = 1; j <= t; j++) {
cin >> x;
sum[j] = ((j == 1) ? 0LL : sum[j - 1]) + x;
}
memset... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[100000];
int main() {
int n, k, ans = 0, i;
scanf("%d %d", &n, &k);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
if (k % 2 == 0) {
for (i = 0; i < n; i++) {
if (a[i] == 2) {
ans ^= 2;
} else if (a[i] % 2 == 0 || a[i] == 1) {
ans ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
bool flag = true;
int one, two, three, flag12 = 0, flag23 = 0, flag13 = 0;
cin >> one >> two >> three;
while (!(one == 0 && two == 0 && three == 0)) {
if ((one == 0 && two == 0 && three != 0) ||
(one != 0 && two == 0 && three == 0) ||
... | 2 |
#include<stdio.h>
#include<vector>
#include<iostream>
#include<map>
#include<tuple>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
std::vector<ll> extended_gcd(ll a, ll b){ //ax+by=zとなる(x,y,z)
ll s=0;
ll old_s=1;
ll t=1;
ll old_t=0;
ll r=b;
ll old_r=a;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int moment;
bool T[26];
for (int i = 0; i < 26; i++) {
T[i] = 0;
}
int shoks = 0;
int shoks2 = 0;
bool give = 1;
for (int i = 0; i < n; i++) {
char c;
string s;
cin >> c >> s;
if (c == '!') {
bool B... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 7;
struct Query {
int type, v;
int id, t;
bool operator<(const Query& a) const { return id < a.id; }
} a[mx], b[mx];
int ans[mx], vis[mx];
int x[mx];
void cdq(int l, int r) {
if (l >= r) return;
int mid = (l + r) >> 1;
cdq(l, mid);
cdq(mid... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e9 + 7;
long long pow(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = ((res) * (x));
res %= N;
y = y >> 1;
x = ((x) * (x));
}
return res;
}
long long pow(long long x, long long y, long long p) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int K, Q;
cin >> K >> Q;
vector<int> D(K);
for(int i=0; i<K; i++) scanf("%d", &D[i]);
while(Q--){
int N, X, M;
scanf("%d %d %d", &N, &X, &M);
N--;
X %= M;
int L = N/K, R = N%K;
int64_t sum =... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200003;
int arr[N];
int n;
void upd(int x) {
for (; x <= n; x += (x & (-x))) arr[x]++;
}
int qry(int x) {
int ans = 0;
for (; x; x -= (x & (-x))) ans += arr[x];
return ans;
}
struct yxh {
int x, id;
bool operator<(const yxh s) const {
if (x < s... | 6 |
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
int n,m;
int d[101][2];
int inf = 1111111111;
vector<pair<int,int> > g[101][2];
void dijkstra(int s){
priority_queue<pair<pair<int,int>,int>,vector<pair<pair<int,int>,int> >,greater<pair<pair<int,int>,int> ... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.