solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long n, a, ans, x[1000005];
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
ans ^= a;
}
for (int i = 1; i <= 1000000; i++) x[i] = i ^ x[i - 1];
for (int i = 2; i <= n; i++) {
long long t = n / i;
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
double x[100010];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%lf", &x[i]);
}
double ans = 0;
for (int i = 1; i <= m; i++) {
int a, b;
double c;
scanf("%d%d%lf", &a, &b, &c);
ans = max(ans, (x[a] + x[b]) ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long cubic_root(long long x) {
long long l = 0, r = 1000005;
while (l < r) {
long long m = (l + r) / 2;
long long f = m * m * m;
if (f > x)
r = m - 1;
else if (f == x)
return m;
else
l = m + 1;
}
return l;
}
int main() {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
priority_queue<int> pq;
int main() {
cin >> n;
int mx = n;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
pq.push(t);
while (!pq.empty() && pq.top() == mx) {
cout << pq.top() << " ";
pq.pop();
mx--;
}
cout << "\n";
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int f[12] = {0};
int main() {
string s;
cin >> s;
int q = 0;
for (int i = 0; i < s.length(); i++)
if (s[i] == '?')
q++;
else if (s[i] >= 'A' && s[i] <= 'J')
f[s[i] - 'A']++;
long long ans = 1;
int start = 10;
if (s[0] == '?') q--, ans = 9;
... | 1 |
/*ุจูุณูู
ู ุงูููููู ุงูุฑููุญูู
ููู ุงูุฑููุญููู
*/
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mx=2e5+5;
char str[mx];
vector <int> idx[26];
int ara[mx],temp[mx];
ll ans;
void inversion_count(int lo,int hi)
{
if (lo==hi) return;
int mid=(lo+hi)/2;
inversion_count(lo,mid);
inve... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
cin>>n>>k;
if(k==1)cout<<"0\n",exit(0);
cout<<n-k<<'\n';
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
vector<int> aa[MAXN];
int x[MAXN], y[MAXN];
int res;
void dfs(int v, int p) {
int bx1 = 0, bx2 = 0;
int by1 = 0, by2 = 0;
int b1 = 0, b2 = 0;
for (int a : aa[v]) {
if (a == p) continue;
dfs(a, v);
if (bx1 < x[a]) {
bx2 = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10000005;
int f[MAXN];
inline int sf(int x) { return x == f[x] ? x : f[x] = sf(f[x]); }
int n, m, k;
int a[MAXN];
int b[MAXN];
int s[MAXN];
int ans[MAXN];
int main() {
scanf("%d%d%d", &n, &m, &k);
int len = 0;
for (int i = 1; i <= n; i++) {
scanf(... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void sci(T& t) {
cin >> t;
}
template <typename T, typename... Ts>
void sci(T& t, Ts&... ts) {
sci(t);
sci(ts...);
}
int32_t main() {
cin.tie(nullptr);
cout.tie(nullptr);
ios_base::sync_with_stdio(false);
int64_t n, k;
cin >> n >> k;
... | 2 |
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
ll inq(ll x, ll y)
{
if (!y) return 1;
ll l = inq(x, y / 2);
if (y % 2) return l * l * x;
return l * l;
}
signed main()
{
ll n, c;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 1e6 + 7;
const int maxm = 6e6 + 7;
const int mod = 1e9 + 7;
int n, r;
int L, ans;
pair<int, int> p[maxn];
int tree[maxm << 2], lazy[maxm << 2];
void modify(int root, int tl, int tr, in... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, x1, y1, x2, y2;
cin >> r >> x1 >> y1 >> x2 >> y2;
long long int p = pow((x1 - x2), 2) + pow((y1 - y2), 2);
double dist = sqrt((double)p);
double fraction = (double)dist / (2 * r);
int ans = ceil(fraction);
cout << ans << endl;
return 0;
}... | 2 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
long double a,b;
cin>>a>>b;
ll ans = a * b ;
cout<<ans<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[305], s2[305];
scanf("%s", &s);
int t = 0;
for (int i = 0; i < strlen(s); i++) {
bool add = 0;
for (int j = 0; j < t; j++)
if (s[i] != s2[j]) {
s2[j] = s[i];
add = 1;
break;
}
if (!add) s2[t++] = s[... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, t0, m;
vector<vector<double>> a;
vector<vector<double>> wr;
vector<vector<double>> dp;
int main() {
scanf("%lld", &n);
m = pow(2, n);
a = vector<vector<double>>(m + 5, vector<double>(m + 5, 0));
for (long long i = 0; i < m; i++) {
for (long long j =... | 4 |
#include <vector>
#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 <cstring>
#include <c... | 0 |
#include<stdio.h>
#include<string.h>
int main(){
int kosu[2][20][20],x,y,c,i,j;
while(~scanf("%d%d",&x,&y)){
if(x==0&&y==0)break;
memset(kosu,0,sizeof(kosu));
for(i=1;i<=y;i++){
for(j=1;j<=x;j++){
scanf("%d",&c);
kosu[1][i][j]=c;
}
}
for(i=1;i<=x;i++){
if(kosu[1][1][i]==0)kosu[0][1][i... | 0 |
#include<iostream>
using namespace std;
int main(){
int n,m,s,i,j,k,l;
static int t[100];
cin>>n>>m;
for(i=0;i<n;i++){
cin>>k;
for(j=0;j<k;j++){
cin>>l;
t[l]+=1;
}
}
s=0;
for(i=1;i<=m;i++){
if(t[i]==n){
s+=1;
}
}
cout<<s;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
long long beauty(vector<long> &v) {
long long res = 0;
for (long long i = 0; i < v.size(); i++) res += ((long long)v[i]) ^ i;
return res;
}
long log(long n) {
long res = 0;
while (n) {
res++;
n /= 2;
}
return res;
}
int main() {
long n;
cin >> n;
... | 3 |
#include <bits/stdc++.h>
#define int long long
using namespace std;
long long gcd(long long a, long long b)
{
if(!b)
return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b)
{
long long z = gcd(a, b);
a /= z;
if(a > 1e18 / b)
return -1;
return a * b;
}
const in... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
const int MOD = 1e9 + 7;
char s[N];
int n, f[N][N], sum[N][N];
int main() {
scanf("%d %s", &n, s + 2);
f[1][1] = sum[1][1] = 1;
for (int i = 2; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
if (s[i] == '>') {
f[i][j] = sum[i -... | 0 |
#include <bits/stdc++.h>
using namespace std;
ostream& operator<<(ostream& os, const pair<int, int>& pai) {
os << pai.first << ' ' << pai.second;
return os;
}
istream& operator>>(istream& is, pair<int, int>& pai) {
is >> pai.first >> pai.second;
return is;
}
int n;
pair<long long, long long> ret;
pair<int, int>... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
int n, Q, a[N], last[N], p[N], ans[N], tree[N];
vector < pair < int, int > > q[N];
void upd(int x, int y) {
if(!x) return;
while(x <= 2 * n) {
tree[x] += y;
x += x & -x;
}
}
int cnt(int x) {
int ans = 0;
while(x)... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int a[1001][1001];
int c[1001];
int r[1001];
vector<pair<int, pair<int, int> > > ret;
cin >> n;
for (int i = 0; i < 1001; i++) {
for (int j = 0; j < 1001; j++) {
a[i][j] = 0;
}
c[i] = 0;
r[i] = 0;
}
for (int i = 0;... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long f[7][11][100005];
int p[100005][10], q[100005][10], n;
int low(int i) { return i & (-i); }
void up(int i, int j, int k, long long w) {
while (k <= n) {
f[i][j][k] += w;
k += low(k);
}
}
long long ask(int i, int j, int k) {
long long t = 0;
while (k... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 100;
const int maxm = 1300000 + 100;
const int maxt = 3000000 + 100;
const int maxk = 10 + 3;
const int M = 2010;
const long long unit = 1LL;
const int INF = 0x3f3f3f3f;
const long long Inf = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const dou... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 5e2 + 4;
int dp[N][N];
int n;
string s;
int rec(int l, int r) {
if (dp[l][r] > -1) return dp[l][r];
if (l > r) return 0;
if (l == r) return 1;
dp[l][r] = 1 + rec(l + 1, r);
for (int i = l + 1; i <= r; i++)
if (s[i] ... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class T1>
void chkmin(T &x, const T1 &y) {
return x > y ? x = y, 1 : 0;
}
template <class T, class T1>
void chkmax(T &x, const T1 &y) {
return x < y ? x = y, 1 : 0;
}
const int MAXN = (1 << 20);
int n;
pair<int, int> a[MAXN];
int main_dir[MAXN];
vecto... | 4 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n)... | 0 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long pow(long long x, long long n) {
long long res = 1;
while (n) {
if (n & 1) res = (res * x);
x = (x * x);
n >>= 1;
}
return res;
}
int32_t main() {
ios_base::sync_with_stdio(0... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n], i, j;
long long sum = 0;
int m = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
m = max(a[i], m);
}
for (i = m; i <= 250; i++) {
if (n * i - sum > sum) {
cout << i << endl;
break;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int v1, v2;
int x, y;
} s[3 * 1005];
int father[3000];
int n, m;
int vist[1005], flg1, flg2, ans, xx, yy;
int cmp(const node a, const node b) {
if (a.x < b.x)
return 1;
else
return 0;
}
int find(int x) {
int root, i = x;
while (x != father[... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> dp, arr;
vector<int> adj[200001];
int ans[200001];
void dfs(int i, int p) {
auto it = lower_bound(dp.begin(), dp.end(), arr[i]);
int rec = *it;
*it = arr[i];
ans[i] = lower_bound(dp.begin(), dp.end(), INT_MAX) - dp.begin() - 1;
for(int... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
list<int> a;
list<int>::iterator it = a.end();
int q, query, t, x;
cin>>q;
for(int i = 0; i < q; i++){
cin>>query;
if(query == 0){
cin>>x;
it = a.insert(it, x);
} else if(query == 1){
cin>>x;
if(x>0) for(int i = 0; i < x; i++)it++;
... | 0 |
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,k,q,i,x;
int a[100010]={0};
cin >> n >> k >> q;
for(i=0;i<q;i++){
cin >> x;
a[x]++;
}
for(i=1;i<=n;i++){
if(k+a[i]-q>0)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
ll ans = 0;
while (n--) {
ll x;
cin >> x;
ans = max(0LL, ans + x);
}
cout << ans << "\n";
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, count = 0;
cin >> n;
string s;
cin >> s;
for (i = 0; i < n; i++) {
if (s[i] == s[i + 1]) count++;
}
cout << count;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
double coord[5];
};
Point read_point() {
Point x;
for (int i = 0; i < 5; i++) {
cin >> x.coord[i];
}
return x;
}
Point vec(const Point &x, const Point &y) {
Point ref;
for (int t = 0; t < 5; t++) {
ref.coord[t] = x.coord[t] - y.coord[t];... | 3 |
#include <bits/stdc++.h>
#define mod 998244353
using namespace std;
int fac[1000005],inv[1000005],n,m;
inline int qpow(int a,int b)
{int tp=a,res=1;
while (b)
{if (b&1) res=1ll*res*tp%mod;
tp=1ll*tp*tp%mod;b>>=1;
}
return res;
}
inline int cal(int a,int b)
{return 1ll*(1ll*fac[a+b]*inv[a]%mod)*inv[b]%mod;}
int main (){... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T& num) {
char CH;
bool F = false;
for (CH = getchar(); CH < '0' || CH > '9'; F = CH == '-', CH = getchar())
;
for (num = 0; CH >= '0' && CH <= '9';
num = num * 10 + CH - '0', CH = getchar())
;
F && (num = -num);
}
int s... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[4], b[4], n, s1, s2;
int main() {
scanf("%d", &n);
for (int i = 3; i >= 1; i--) {
b[i] = n % 10;
n /= 10;
s2 += b[i];
}
for (int i = 3; i >= 1; i--) {
a[i] = n % 10;
n /= 10;
s1 += a[i];
}
if (s1 > s2) {
swap(a[1], b[1]);
sw... | 2 |
#include <stdio.h>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <queue>
#include <array>
#include <bitset>
using namespace std;
typedef l... | 0 |
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
int ans[32769][5];
int main(){
vector<int>data;
for(int i=1;i*i<=32768;i++)data.push_back(i*i);
ans[0][0]=1;
REP(i,data.size()){
REP(j,32769){
if(j+data[i]>32768)break;
REP(k,4)ans[j+da... | 0 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
int sum=0;
int a[510],ans,n,k;
int sum1[510],sum2[510],p[510];
bool check(int x){
int cnt=0;
for(int i=1;i<=n;i++)p[i]=a[i]%x;
sort(p+1,p+n+1);
for(int i=1;i<=n;i++)sum1[i]=sum1[i-1]+p[i];
for(int i=n;i>=1;i--)sum2[i]=sum2[i+1]+x-p[i];
int mi=k;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 200005;
int pos[MAXN];
int main(){
int h, w, n; scanf("%d %d %d",&h,&w,&n);
for(int i=1; i<=h; i++) pos[i] = w + 1;
for(int i=0; i<n; i++){
int x, y; scanf("%d %d",&x,&y);
pos[x] = min(pos[x], y);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
char s[305][305];
int main() {
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> s[i][j];
}
}
for (int r = 1; r < n; r++) {
for (int i = r; i < n - r; i++) {
for (int j = r; j < m - r; j++) {
... | 4 |
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int n,m,i,j,k,ans;
int a[305][305],b[305];
bool ban[305];
int main()
{
scanf("%d%d",&n,&m);
for(i=1;i<=n;++i)
for(j=1;j<=m;++j)
scanf("%d",&a[i][j]);
ans=n;
for(i=1;i<=m;++i)
{
for(j=1;j<=m;++j) b[j]=0;
for(j=1;j<=n;++j)
... | 0 |
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
int main(){
int n;
while(1){
cin >> n;
if(n==0) break;
int a[n+1][n+1];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++) cin >> a[j][i];
a[n][i] = 0;
for(int j=0;j<n;j++) a[n][i] += a[j][i];
}
for(int i=0;i<=n;i++){
a[i][... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 10;
int arr[MAX], lis[MAX], lds[MAX];
int n, m;
void preprocess() {
multiset<int> s;
for (int i = 1; i <= m; ++i) {
s.insert(arr[i]);
auto it = s.upper_bound(arr[i]);
if (it != s.end()) s.erase(it);
lis[i] = s.size();
}
s.clear(... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
if (n % m)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> Shift(vector<int> &v, int first) {
vector<int> t;
int start = n - first;
for (int i = 0; i < n; ++i) {
t.push_back(v[(i + start) % n]);
}
return t;
}
vector<pair<int, int> > rmq;
void build(int i, int l, int r, vector<int> &v) {
if (r - l ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long cnt = 0, n, a;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a;
cnt += (i * a);
}
cout << cnt;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 5000;
vector<int> adj[MX + 1];
int par[32 - __builtin_clz(MX)][MX + 1], f[MX + 1], tin[MX + 1], tout[MX + 1],
id[MX + 1][MX + 1], timer, logn;
tuple<int, int, int> query[MX];
void dfs(int u) {
tin[u] = ++timer;
for (auto c : adj[u]) {
if (c != par... | 6 |
#include <bits/stdc++.h>
using namespace std;
void cass() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const int N = 20;
int n;
long long mul[N], F[N][N];
char re[N][N];
string st;
pair<int, int> pre[N][N];
void sol() {
cin >> n >> st;
st = " " + st;
mul[0] = 1;
for (int i = 1; i <= 18; ++i) mul[... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int h,w; cin>>h>>w;
vector<string> s(h);
for(int i=0; i<h; ++i)cin>>s[i];
vector<vector<int>> lighth(h, vector<int>(w,0));
vector<vector<int>> lightw(h, vector<int>(w,0));
for(int i=0; i<h; ++i){
int l=0;
for(int j=0; j<w; ++j){
if(s... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int h,n,a,b,mx=-1;
cin >> h >> n;
vector<int> c(h+1,1e9);
c[0] = 0;
for(int i=0;i<n;i++){
cin >> a >> b;
for(int j=0;j<h+1;j++) c[j] = min(c[j],(j<a ? 0 : c[j-a])+b);
}
cout << c[h] << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int a[1001];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = n; i > 0; --i) {
a[i] -= a[i - 1];
}
vector<int> ans;
for (int k = 1; k <= n; ++k) {
bool valid = 1;
for (int i = k + 1; i <= n && valid; ++... | 2 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
long long int vis[100005];
long long int arr[100005];
long long int ans[100005];
int32_t main() {
c_p_c();
long long int n;... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int aray[100][100] = {0};
int x = 0, y = 0, x1 = 0, y1 = 0;
int sum = 0;
while (n--) {
cin >> x >> y >> x1 >> y1;
sum += ((x1 - x) + 1) * ((y1 - y) + 1);
}
cout << sum << endl;
return 0;
}
| 1 |
#include <iostream>
int main(){
int a,b,r=1;
char c[12]={};
std::cin>>a>>b>>c;
for(int i=0;i<a+b+1;++i){
if(i==a){r=(c[i]=='-'?r:0);}
else{r=(c[i]>47&&c[i]<58?r:0);}
}
std::cout<<(r?"Yes":"No")<<"\n";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
long n;
cin >> n;
string s;
while(n>0){
n--;
s += char(n%26+97);
n = (n-n%26)/26;
}
reverse(s.begin(),s.end());
cout << s << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long int cnt(int n) {
long long int cnt = 0, temp;
while (n) {
temp = n % 10;
if (temp == 4 || temp == 7) cnt++;
n /= 10;
}
return cnt;
}
int main() {
long long int n, k, cn = 0, temp;
cin >> n >> k;
for (long long int i = 0; i < n; ++i) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 1000 * 1000 + 24;
long long a, b, p, x, ans;
long long pw(int x, int y, int mod) {
if (y == 0) return 1;
long long t = pw(x, y / 2, mod);
t = 1LL * t * t % mod;
if (y & 1) t = 1LL * t * x % mod;
return t;
}
int main() {
cin.tie(0), cout.t... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long bit[4 * 100005], n, m, x, ct[100005], fin[100005];
pair<long long, long long> p[100005], q[100005];
set<long long> s;
vector<long long> vec;
void update(long long idx, long long num) {
while (idx < 100005) {
bit[idx] += num;
idx += (idx & -idx);
}
}
lo... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int prime = 999983;
const int INF = 0x7FFFFFFF;
const long long INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const long long mod = 1e9 + 7;
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
long long qpow(long lon... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
class BIT {
int n;
T *tree;
public:
BIT(int n) : n(n) { tree = (T *)calloc(n + 1, sizeof(T)); }
void update(int idx, T a) {
while (idx <= n) {
tree[idx] += a;
idx += idx & -idx;
}
}
T query(int idx) {
T sum = 0;
... | 6 |
#include <bits/stdc++.h>
const int MAXN = 3e5, MAXQ = 5e5, MAXLG = 18;
int n, q, qu[MAXQ + 5], qv[MAXQ + 5], qw[MAXQ + 5];
bool ans[MAXQ + 5], sum[MAXN + 5];
int ecnt, head[MAXN + 5], dep[MAXN + 5], fa[MAXN + 5][MAXLG + 5];
int dfc, dfn[MAXN + 5], siz[MAXN + 5];
struct Edge {
int to, val, nxt;
} graph[MAXN * 2 + 5];
... | 6 |
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
void solve(std::istream& in, std::ostream& out) {
int k = 0, i = 0, j = 0;
string pat, txt, patr;
in >> pat;
in >> txt;
int t = pat.size();
patr = pat;
reverse(patr.begin(), patr.end());
pat = pat + "$" + patr;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long double PI = acos(-1.0);
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<pair<long double, long double>> a;
cout.precision(15);
for (int i = 0; i <... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long maxN = 1e3 + 17, N = 7, inf = 1e9 + 7, MOD = 1e9 + 7,
Mod = 1e9 + 6;
long long n, d[maxN], pos[N][maxN], b[N], ans, a[N][maxN], k, cnt;
bool v[N][maxN][maxN];
int main() {
cin >> n >> k;
for (long long i = 1; i <= k; i++) {
for (long ... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> W[100005];
int dp[300005], best[300005];
int main() {
int n, m, a, b, c, ans = 0, mx = 0;
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d%d%d", &a, &b, &c);
W[c].push_back(make_pair(a, b));
mx = max(c, mx);
}
for ... | 5 |
#include <iostream>
using namespace std;
int arr[101];
int result[101];
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> arr[i];
if (arr[i] > i) {cout << -1 << endl; return 0;}
}
for (int i = 1; i <= n; i++)
{
for (int j = i; j >= arr[i]; j--)
... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;
void read (int &x) {
char ch = getchar(); x = 0;
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
}
struct mat {
int a[21][21];
/*
rep(i,0,21){
rep(j... | 0 |
#include <bits/stdc++.h>
using namespace std;
string funcname[1111];
int paramtype[1111][5];
int paramcnt[1111];
map<string, int> vartype;
int main(void) {
int n = 0;
scanf("%d\n", &n);
for (int i = 0; i < n; i++) {
char funcstr[1111] = {0};
gets(funcstr);
int len = strlen(funcstr);
for (int j = 0... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
int main(){
int V=10,t,d[10][10],h,w,ans=0;cin>>h>>w;
REP(i,V) REP(j,V) cin>>d[i][j];
REP(k,V) REP(i,V) REP(j,V) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
REP(i,h*w){
cin>>t;
if(t>-1) ans+=d[t][1];
}
cout<<ans;
}
| 0 |
#include <bits/stdc++.h>
#define N 100005
using namespace std;
typedef long long ll;
ll a[N],b[N],n;
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
if(i&1)b[1]+=a[i];
else b[1]-=a[i];
}
for(int i=2;i<=n;i++)
b[i]=2*a[i-1]-b[i-1];
for(int i=1;i<=n;i++){
if(i==1)cout<<b[i];
else cout<<" "<... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const long long INF = 1e18;
const long double PI = 4 * atan((long double)1);
template <class T>
bool ckmin(T& a, const T& b) {
return a > b ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
return a < b ... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool f(string &s) {
bool flag = true;
for (int i = 0; i < s.size() / 2; i++) {
if (s[i] != s[s.size() - 1 - i]) flag = false;
}
return flag;
}
int main() {
ios_base::sync_with_stdio(false);
string s;
cin >> s;
while (s.size() && f(s)) s.pop_back();
cou... | 1 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back
template<class T> inline bool chmin(T &a, T b){
if(a>b){a=b;return t... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,c,l,ll=0;
cin>>n>>c;
int t=1;
for(int i=0;i<n;i++)
{
cin>>l;
ll=ll+l;
if(ll<=c)
{
t++;
}
}
cout<<t<<endl;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 2e3 + 11;
const int mod = 1e9 + 7;
int head[N], nex[N<<1], to[N<<1], size;
int fa[N], n, m;
LL X;
LL wei[N<<1], mi[N], t[N];
struct edge{
int u, v;
LL w;
}e[N];
bool cmp(edge a, edge b){
return a.w < b.w;
}
int find(int x){
return fa[x... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
bool check(long long m) {
long long l = m, r = m, ans = 0;
if (!(m & 1)) ++r;
while (l <= n) {
if (r <= n)
ans += r - l + 1;
else
ans += n - l + 1;
l <<= 1;
r = (r << 1) + 1;
}
return ans >= k;
}
int main() {
cin >> n ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long cnt = 0;
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
cnt = 0;
long long n;
cin >> n;
while (n % 5 == 0) {
n = n / 5;
cnt += 3;
}
while (n % 3 == 0) {
n = n / 3;
cnt += 2;
}
while (n % 2 ... | 1 |
// D - Powerful Discount Tickets
#include <bits/stdc++.h>
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
int main(){
int N,M; cin>>N>>M;
priority_queue<int> A;
while(N--) A.push(in());
for(;M--; A.pop()) A.push(A.top() / 2);
long long ans = 0;
for(;A.size(); A.pop()) ans += A.top();
cout<< an... | 0 |
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
int t,y,ans,mem;
char sign;
while(scanf("%d%d",&t,&y),t + y)
{
int field[510][510] = {0};
ans = 0;
scanf("%c",&sign);
for(int i = 0; i < t; i++)
{
for(int j = 0; j < y + 1; j++)
... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
vector<int> adj[100005];
int vis[100005];
void dfs(int k) {
vis[k] = 1;
for (auto it : adj[k]) {
if (vis[it] == 1) {
cout << "-1" << endl;
exit(0);
} else if (vis[it] == 0) {
dfs(it);
}
}
v.push_back(k);
vis[k] = 2;
}
i... | 3 |
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int a,b,c,r=0,l=0;
while(scanf("%d%*c%d%*c%d",&a,&b,&c)==3) {
if(a*a+b*b==c*c) r++;
else if(a==b) l++;
}
cout << r << endl << l << endl;
return 0;
}
| 0 |
#include <iostream>
using namespace std;
int main(){
int n;
cin >> n;
long long sum = 0;
for(int i = 1; i <=n; i++){
if(i%3!=0&&i%5!=0) sum+=i;
}
cout << sum;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
std::ostream& operator<<(std::ostream& stream, const vector<T>& v) {
for (auto el : v) stream << el << " ";
return stream;
}
template <class T>
std::ostream& operator<<(std::ostream& stream, const vector<vector<T>>& v) {
for (auto line : v) {
fo... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long Set(long long n, long long pos) { return n | (1LL << pos); }
bool Check(long long n, long long pos) { return (bool)(n & (1LL << pos)); }
long long yo = 1000;
char a[1010], b[1010];
long long dp[1010][2][2][1010][2];
long long k;
long long solve(long long pos, bool... | 4 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
const long long MAXN = 1e9 + 7;
long long fastPow(long long x, long long y, long long mod) {
if (y == 0) {
return 1;
}
long long tmp = fastPow(x, y / 2, mod);
if (y % 2 == 0) return tm... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<long long> above(n);
vector<long long> prefix(n);
for (int i = 0; i < n; i++) {
cin >> above[i];
prefix[i] = above[i] + 1;
}
long long cur = prefix[n - 1];
for (int i ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long large = 1e6 + 10;
const long long MOD = 998244353;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
const long long N = 2e2 + 99;
void solve() {
long long n, mod;
cin >> n >> mod;
long long fac[n + 10];
fac[0] = 1;
for (long long i = 1; i... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c[101], d[101], mx = -1e9, cnt;
int main() {
cin >> a >> b;
for (int i = 1; i <= a; ++i) {
cin >> c[i];
}
for (int i = 1; i < a; ++i) {
d[i] = c[i] - c[i + 1] - b;
}
for (int i = 1; i <= a; ++i) {
mx = max(d[i], mx);
}
cout << mx;... | 1 |
#include<iostream>
using namespace std;
int main(){
string S;
cin >> S;
cout << S[0] << S[1] << S[2] << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 100005;
int a[maxN];
char c[maxN];
int main() {
int n, k;
cin >> n >> k;
getchar();
int i;
for (i = 1; i <= n; ++i) {
scanf("%c", &c[i]);
a[i] = c[i] - '0';
}
for (i = 1; i <= n; ++i) {
if (k <= 0) break;
if ((i & 1) == 1 && a[... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[105];
int main() {
int l, r, m, z = 0;
cin >> l >> m;
a[0] = 0;
for (r = 1; r <= l; ++r) cin >> a[r], a[r] += a[r - 1];
while (m--) {
cin >> l >> r;
z += max(0, a[r] - a[l - 1]);
}
cout << z;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, Min = 0, Max = 0, Max1 = 0, mod = 0;
cin >> n >> m;
if (n == m) {
int f = (n + m) / 3;
cout << f << endl;
} else {
Min = min(n, m);
Max = max(n, m);
Max1 = Max / 2;
mod = Max % 2;
if (Max1 >= Min)
cout << Min ... | 3 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:36777216")
long long EPS = 1000000007;
double PI = 3.14159265358979323846;
const int MAXN = 1000010;
long long abss(long long h) {
if (h < 0) {
return -h;
}
return h;
}
double fabss(double h) {
if (h < 0.0) {
return -h;
}
... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.