code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using db = double;
using vi = vector<int>;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define debug(x) cout << #x <<" "<< x <<endl
const int inf = 0x3f3f3f3f;
const db eps = 1e-8;
const int mod = 1e9+7;
ll qpow(ll a, ll b){
ll ret = 1;
while(b){
if(b&1)ret = ret*a%mod;
a = a*a%mod;
b>>=1;
}
return ret;
}
const int maxn = 1<<10;
int n;
int a[maxn], b[maxn];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for(int i=1; i<=n; ++i){
a[i] = (2*i)%n+1;
b[i] = (2*i+1)%n+1;
}
for(int i=1; i<=n; ++i)cout << a[i] <<" " << b[i] <<"\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef int_fast32_t int32;
typedef int_fast64_t int64;
const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;
#define YES(n) cout << ((n) ? "YES\n" : "NO\n" )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n" )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n" )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;
template<class T> inline bool chmax(T& a, T b) {
if (a < b) { a = b; return true; } return false;
}
template<class T> inline bool chmin(T& a, T b) {
if (a > b) { a = b; return true; } return false;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int32 n;
cin >> n;
vector<int32> p(n);
REP(i,n)cin >> p[i],--p[i];
queue<int32> que;
vector<bool> used(n,false);
REP(i,n-1){
if(i < p[i] && p[i+1] < i+1)que.emplace(i);
}
vector<int32> ans;
while(que.size()){
int32 i = que.front();que.pop();
if(!(i < p[i] && p[i+1] < i+1))continue;
if(used[i]){
ANS(-1);
return 0;
}
ans.emplace_back(i);
used[i] = true;
swap(p[i],p[i+1]);
if(i-1 >= 0 && i-1 < p[i-1] && p[i] < i)que.emplace(i-1);
if(i+2 < n && i+1 < p[i+1] && p[i+2] < i+2)que.emplace(i+1);
}
REP(i,n){
if(p[i] != i){
ANS(-1);
return 0;
}
}
if(ans.size() != n-1){
ANS(-1);
return 0;
}
REP(i,n-1)ANS(ans[i]+1);
return 0;
} |
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
const int N =2000005;
int cnt[20];
bool check(int x) {
int key[10]={};
while(x) {
key[x%10]++;
x/=10;
}
for(int i=0;i<10;++i) {
if(key[i]>cnt[i])
return false;
}
return true;
}
int main()
{
char ch[N];
scanf("%s",ch);
getchar();
int len=strlen(ch);
for(int i=0;i<len;++i) {
cnt[ch[i]-'0']++;
}
if (len==1) {
if(ch[0]=='8')
puts("Yes");
else
puts("No");
}
else if (len==2) {
int a=(ch[0]-'0')*10+ch[1]-'0';
int b=(ch[1]-'0')*10+ch[0]-'0';
if(a%8==0||b%8==0)
puts("Yes");
else
puts("No");
}
else {
for(int i=104;i<1000;i+=8) {
if (check(i)) {
puts("Yes");
return 0;
}
}
puts("No");
}
return 0;
} | #include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <cmath>
#include <iomanip>
#include <iterator>
#include <unordered_set>
using namespace std;
class InputReader {
public:
InputReader() {}
InputReader(const char *file_name) {
input_file = fopen(file_name, "r");
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
inline InputReader &operator >>(int &n) {
while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
advance();
}
int sign = 1;
if (buffer[cursor] == '-') {
sign = -1;
advance();
}
n = 0;
while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
n = n * 10 + buffer[cursor] - '0';
advance();
}
n *= sign;
return *this;
}
inline InputReader &operator >>(long long &n) {
while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
advance();
}
int sign = 1;
if (buffer[cursor] == '-') {
sign = -1;
advance();
}
n = 0;
while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
n = n * 10 + buffer[cursor] - '0';
advance();
}
n *= sign;
return *this;
}
private:
FILE *input_file;
static const int SIZE = 1 << 17;
int cursor;
char buffer[SIZE];
inline void advance() {
++ cursor;
if(cursor == SIZE) {
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
}
};
const int MAXN = 200000;
int a[1 + MAXN], b[1 + MAXN], p[1 + MAXN];
bool compare(const int &i, const int &j) {
return a[i] > a[j];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
//ifstream cin("input.txt");
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
}
vector<int> bad;
for (int i = 1; i <= n; i++) {
cin >> p[i];
if (p[i] != i) {
if (b[p[i]] >= a[i]) {
cout << "-1\n";
return 0;
}
bad.push_back(i);
}
}
sort(bad.begin(), bad.end(), compare);
vector<pair<int, int> > op;
for (auto x : bad) {
while (p[x] != x) {
int y = p[x];
op.push_back(make_pair(x, y));
swap(p[x], p[y]);
}
}
for (int i = 1; i <= n; i++) {
assert(p[i] == i);
}
cout << op.size() << "\n";
for (auto it : op) {
cout << it.first << " " << it.second << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e2 + 7;
char dp[MAX_N][MAX_N];
char s[MAX_N];
int n, k;
int f_pow(int base, int b, int mod) {
int res = 1;
while (b) {
if (b & 1) res = res * base % mod;
base = base * base % mod;
b >>= 1;
}
return res;
}
char ans(char a, char b) {
if (a == 'P') {
if (b == 'R') return 'P';
if (b == 'S') return 'S';
return 'P';
} else if (a == 'R') {
if (b == 'S') return 'R';
if (b == 'P') return 'P';
return 'R';
} else {
if (b == 'P') return 'S';
if (b == 'R') return 'R';
return 'S';
}
}
int main() {
scanf("%d%d", &n, &k);
scanf("%s", s);
for (int i = 0; i < n; ++i) dp[i][0] = s[i];
for (int j = 1; j <= k; ++j) {
for (int i = 0; i < n; ++i) {
char a = dp[i][j - 1], b = dp[(i + f_pow(2, j - 1, n)) % n][j - 1];
dp[i][j] = ans(a, b);
}
}
printf("%c\n", dp[0][k]);
return 0;
} | #include <bits/stdc++.h>
#define endl '\n'
#define sz(X) X.size()
#define IO cin.tie(0), ios_base::sync_with_stdio(0);
#define FOR(N) for(int i=0;i<N;++i)
#define FORf(X,V,N) for(int X=V;X<N;++X)
#define FORi(X,V,N,S) for(int X=V;(S>0?X<N:X>=N);X+=S)
#define EACH(X, V) for(auto& X : V)
#define For(X, V, N) for(int X = V, Len = N, X < V; ++X)
#define All(X) X.begin(), X.end()
#define ar array
using ll = long long;
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T, class C>
using Pset = tree<T, null_type, C, rb_tree_tag, tree_order_statistics_node_update>;
template<class T, class P> inline bool umax(T& x, P y) {
bool big; x = (big = x>y) ? x : y; return !big;
}
template<class T, class P> inline bool umin(T& x, P y) {
bool big; x = (big = x<y) ? x : y; return !big;
}
template<class T> istream& operator>>(istream& is, vector<T>& vt) {
for(auto& i : vt)
is >> i;
return is;
}
template<class T, unsigned int N> istream& operator>>(istream& is, array<T, N>& ary) {
for(auto& i : ary)
is >> i;
return is;
}
template<class T1, class T2> istream& operator>>(istream& is, pair<T1, T2>& pr) {
is >> pr.first >> pr.second;
return is;
}
template<class T> void read(T& x) {
cin >> x;
cin.get();
}
template<class T, class ... P> void read(T& x, P& ... t) {
cin >> x;
read(t...);
}
template<class T> void readl(T& x) { // readline
getline(cin, x);
}
template<class T, class ... P> void readl(T& x, P& ... t) {
getline(cin, x);
readl(t...);
}
template<class T> void write(T x) {
cout << x;
}
template<class T, class ... P> void write(T x, P ... t) {
cout << x;
write(t...);
}
void print() { cout << '\n'; }
template<class T> void print(T x) {
cout << x << '\n';
}
template<class T, class ... P> void print(T x, P ... t) {
cout << x << ' ';
print(t...);
}
#define fastIO
void solve() {
string n;
int k;
read(n, k);
while(k--) {
if(sz(n) < 3)
n += "200";
else if(n.substr(sz(n)-2, 2) == "00" && ((n[sz(n)-3]-'0')&1) == 0) {
int f = 0;
FOR(2)
n.pop_back();
EACH(s, n) {
int i = s-'0'+f*10;
s = i/2+'0';
f = i&1;
}
} else {
n += "200";
}
}
int id = 0;
while(n[id] == '0')
++id;
print(n.substr(id, sz(n)-id));
}
int main() {
#ifdef fastIO
IO;
#endif
//int t;
//cin >> t;
//while(t--)
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
inline void YesNo(bool b) { WB(b, "Yes", "No"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
return S.find(key) != S.end();
}
template<typename T> inline bool ON(const T &b, i64 idx) {
return ((T(1) << idx) & b) != 0;
}
int main(int argc, char *argv[]) {
i64 i, j, k;
i64 N, M; cin >> N >> M;
map<i64, vector<i64>> PC; //
unordered_set<i64> reachable;
REP(0, M, i) {
i64 X, Y; RI(X); RI(Y);
PC[X].pb(Y);
}
reachable.insert(N);
for(auto &pc: PC) {
if(pc.first == 0) {
continue;
}
vi &xs = pc.second;
vi add, remove;
for(auto &x: xs) {
if(IN(reachable, x)) {
remove.pb(x);
}
if(IN(reachable, x-1) || IN(reachable, x+1)) {
add.pb(x);
}
}
for(auto &r: remove) {
auto it = reachable.find(r);
reachable.erase(it);
}
for(auto &a: add) {
reachable.insert(a);
}
#if 0
cerr << pc.first << endl;
for(auto &r: reachable) {
cerr << r << " ";
}
cerr << endl;
#endif
}
WI(sz(reachable));
return 0;
}
| #include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=200010; //check the limits, dummy
vector<pair<int, int>> a[2*N];
vector<int> b[2*N];
int n, m;
int ans = 0;
bool vis[2*N];
void dfs(int x){
// cout<<x<<endl;
if(vis[x])return;
vis[x]=1;
if(x>m)++ans;
for(auto it:b[x])dfs(it);
}
map<int, int> mp;
int main(){
scanf("%d%d",&n,&m);
int x, y;
int cnt = 1;
for(int i=1; i<=m; ++i){
scanf("%d%d",&x,&y);
if(mp.count(y)==0)
mp[y]=cnt++;
a[mp[y]].push_back(mk(x,i));
}
if(mp.count(n)==0)mp[n]=cnt++;
a[mp[n]].push_back(mk(0,0));
cnt = m+1;
for(auto ii:mp){
int i=ii.sc;
if(a[i].size()==0)continue;
a[i].push_back(mk(2*n+1, cnt++));
sort(a[i].begin(), a[i].end());
}
for(auto ii:mp){
int i=ii.sc;
if(a[i].size()==0)continue;
int p1=0, p2=0, k1 = mp[ii.fs+1], k2 = mp[ii.fs-1];
for(int j=0; j+1<a[i].size(); ++j){
auto it=a[i][j];
for(p1;p1+1<a[k1].size();++p1){
// cout<<ii.fs<<" "<<it.fs<<" "<<a[k1][p1].fs<<endl;
if(a[k1][p1].fs>it.fs && a[k1][p1].fs<=a[i][j+1].fs)
b[it.sc].push_back(a[k1][p1].sc);
if(a[k1][p1].fs>a[i][j+1].fs)
break;
}
for(p2;p2+1<a[k2].size();++p2){
// cout<<ii.fs<<" "<<it.fs<<" %"<<a[k1][p1].fs<<endl;
if(a[k2][p2].fs>it.fs && a[k2][p2].fs<=a[i][j+1].fs)
b[it.sc].push_back(a[k2][p2].sc);
if(a[k2][p2].fs>a[i][j+1].fs)
break;
}
}
int j=a[i].size();
b[a[i][j-2].sc].push_back(a[i][j-1].sc);
}
ans = 0;
dfs(0);
cout<<ans<<endl;
} |
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <set>
#include <iostream>
#include <fstream>
#include <chrono>
using namespace std;
const int MOD = 998244353;
int calcPow(int a, int b) {
if (a == 0)
return 0;
if (b == 0)
return 1;
if (b == 1)
return a % MOD;
int64_t ans = calcPow(a, b / 2);
ans = (ans * ans) % MOD;
if (b % 2 == 1)
ans = (ans * a) % MOD;
return ans;
}
void solve(int test, istream &in) {
int n, m, k;
in >> n >> m >> k;
vector<int> powM(k + 1), powN(k + 1);
for (int i = 0; i <= k; i++) {
powM[i] = calcPow(i, m);
powN[i] = calcPow(i, n);
}
int64_t answer = 0;
for (int c = 1; c <= k; c++) {
int64_t cur1 = (powN[c] - powN[c - 1]) % MOD;
int64_t cur2 = powM[k - c + 1];
if (n == 1 || m == 1)
cur2 = (cur2 - powM[k - c]) % MOD;
answer = (answer + cur1 * cur2) % MOD;
}
if (answer < 0)
answer += MOD;
printf("%lld\n", answer);
}
int main(int argc, char* argv[])
{
#ifdef VLAD_LOCAL
ifstream f("in.txt");
auto start = std::chrono::steady_clock::now();
#else
istream &f = cin;
#endif
int tests = 1;
//f >> tests;
for (int test = 0; test < tests; test++) {
solve(test, f);
}
#ifdef VLAD_LOCAL
auto end = std::chrono::steady_clock::now();
double seconds = (double)std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / 1000;
printf("%.3lf\n", seconds);
#endif
return 0;
}
| //#pragma GCC optimize(3)
#include <bits/stdc++.h>
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<string.h>
#include<iostream>
#define debug(x) cout<<#x<<":"<<x<<endl;
#define dl(x) printf("%lld\n",x);
#define di(x) printf("%d\n",x);
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const ll INF= 1e18+7;
const ll maxn = 2e6+700;
const int M = 2e5+700;
const ll mod= 998244353;
const double eps = 1e-9;
const double PI = acos(-1);
template<typename T>inline void read(T &a){char c=getchar();T x=0,f=1;while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=(x<<1)+(x<<3)+c-'0';c=getchar();}a=f*x;}
ll n,m;
ll a[maxn];
int dp[25][5005];
int s[5005][5005];
ll cal(ll x,ll y){
if(y == 0 || x == y) return s[x][y] = 1;
if(y == 1) return s[x][y] = x%mod;
if(~s[x][y]) return s[x][y];
return s[x][y] = (cal(x-1,y) + cal(x-1,y-1))%mod;
}
int main(){
memset(s,-1,sizeof(s));
read(n);read(m);
dp[0][0] = 1;
for(int i=1;i<=20;i++){
if((1<<(i-1))>m){
printf("%d\n",dp[i-1][m]);
return 0;
}
for(int k=0;k<=n;k+=2){
ll tmp = k*(1<<(i-1));
if(tmp>m) break;
for(ll j=tmp;j<=m;j++){
dp[i][j] = (dp[i][j]+dp[i-1][j-tmp]*cal(n,k))%mod;
}
}
}
return 0;
}
/***
6
1 1 2 2 2 2
***/ |
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
int num;
scanf("%lld",&num);
string str1,str2;
cin>>str1>>str2;
int cur=0,ans=0;
vector<int>v;
for(int i=0;i<num;i++)
{
if(str1[i]=='1')
v.push_back(i);
}
for(int i=0;i<num;i++)
{
if(str1[i]==str2[i]) continue;
while(cur<v.size()&&v[cur]<=i) cur++;
if(cur>=v.size())
{
printf("-1");
return 0;
}
ans+=v[cur]-i;
str1[v[cur]]='0';
cur++;
}
cout<<ans<<endl;
} | #include <bits/stdc++.h>
using namespace std;
#define i64 int64_t
#define u64 uint64_t
const i64 inf = 1e17;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
#define endl "\n"
#define all(a) a.begin(),a.end()
#define overload(_1,_2,_3,_4,name,...) name
#define _rep1(n) for(int i = 0; i < (n); i++)
#define _rep2(i,n) for(int i = 0; i < (n); i++)
#define _rep3(i,a,b) for(int i = (a); i < (b); i++)
#define _rep4(i,a,b,c) for(int i = (a); i < (b); i += (c))
#define rep(...) overload(__VA_ARGS__,_rep4,_rep3,_rep2,_rep1)(__VA_ARGS__)
#define _rrep1(n) for(int i = (n) - 1; i >= 0; i--)
#define _rrep2(i,n) for(int i = (n) - 1; i >= 0; i--)
#define _rrep3(i,a,b) for(int i = (b) - 1; i >= (a); i--)
#define _rrep4(i,a,b,c) for(int i = (b) - 1; i >= (a); i -= (c))
#define rrep(...) overload(__VA_ARGS__,_rrep4,_rrep3,_rrep2,_rrep1)(__VA_ARGS__)
#define ForEach(a,b) for_each(a.begin(),a.end(),b)
#define NextAfter(x) x = nextafter(x, INFINITY)
template <class T> bool chmin(T& a, T b){ if(a > b){ a = b; return 1; } return 0; }
template <class T> bool chmax(T& a, T b){ if(a < b){ a = b; return 1; } return 0; }
struct Edge { int to; i64 cost; Edge(int to, i64 cost) : to(to), cost(cost) {} };
using Graph = vector<vector<Edge>>;
bool check(string &x, i64 n, i64 m) {
i64 val = 0;
rep(x.size()) {
if (val > (m-(x.at(i)-'0')+n-1)/n) {
val = m+1;
break;
}
val = val * n + (x.at(i) - '0');
}
return val <= m;
}
void Main() {
string x;
i64 m;
cin >> x >> m;
if (x.size() == 1) {
if (stoi(x) <= m)
cout << 1 << endl;
else
cout << 0 << endl;
return;
}
i64 lb_init = *max_element(all(x)) - '0';
i64 lb = lb_init, ub = m+1;
while (ub - lb > 1) {
i64 mid = (lb + ub)/2;
if (check(x, mid, m))
lb = mid;
else
ub = mid;
}
cout << lb - lb_init << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(10) << fixed;
Main();
} |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll mod = 1e9 + 7;
const ll linf = 1LL << 62;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}
int N;
ll V[400010];
ll sum;
int main() {
cin >> N;
for (int i = 0; i < 2 * N; i++) {
cin >> V[i];
sum += V[i];
}
priority_queue<ll, vector<ll>, greater<ll>> pq;
ll ans = 0;
for (int i = N - 1; i >= 0; i--) {
pq.push(V[i]);
pq.push(V[2 * N - i - 1]);
ans += pq.top();
pq.pop();
}
cout << sum - ans << endl;
} | #include <bits/stdc++.h>
#include <math.h>
using namespace std;
long long sisu(long long n, long long k) {
long long a = 1;
for (long long i = 0; i < k; i++) {
a *= n;
}
return a;
}
int main() {
int N;
cin >> N;
long long max1=-1, max2=-1, b1,b2;
vector<long long> A(sisu(2, N-1));
vector<long long> B(sisu(2, N-1));
vector<pair<long long, long long>> S;
for (int i = 0; i < sisu(2, N); i++) {
long long k;
cin >> k;
if (i >= sisu(2, N - 1)) {
B.at(i - sisu(2, N - 1)) = k;
if (max2 < k) {
max2 = k;
b2 = i + 1;
}
}
else {
A.at(i) = k;
if (max1 < k) {
max1 = k;
b1 = i + 1;
}
}
S.push_back(make_pair(k, i));
}
sort(S.begin(), S.end());
if (S.at(sisu(2, N) - 1).second >= sisu(2, N - 1)){
cout << b1;
}
else {
cout << b2;
}
}
|
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(ll i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define coy cout<<"Yes"<<endl
#define con cout<<"No"<<endl
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7
#define LINF (ll)1e18+10
using ll = long long;
using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
using PPI = pair<P, int>;
using PIP = pair<int, P>;
using Ps = pair<int, string>;
using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vd = vector<double>;
using vs = vector<string>;
using vp = vector<P>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<double>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
using vvb = vector<vector<bool>>;
template <typename T>
bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; }
//const ll mod=998244353;
const ll mod = 1e9 + 7;
const ll MAX = 100;
template <typename T>
T abs(T a) { if (a < 0)return -a; else return a; }//2020/09/30 stdlib has abs(long) abs(long long) error
//////////////////////////////////////
int main() {
int r, c;
cin >> r >> c;
vvi a(r, vi(c - 1)), b(r - 1, vi(c));
rep(i, r)rep(j, c - 1)cin >> a[i][j];
rep(i, r - 1)rep(j, c)cin >> b[i][j];
vvi dist(r, vi(c, INF));
--r, --c;
priority_queue<PIP, vector<PIP>, greater<PIP>> q;
dist[0][0] = 0;
q.push(PIP(0, P(0, 0)));
auto ok = [&](int x, int y) {
return x >= 0 & x <= r && y >= 0 && y <= c;
};
while (q.size()) {
PIP t = q.top(); q.pop();
P now = t.second;
int d = t.first;
if (d > dist[now.fs][now.sc])continue;
{
int nx = now.fs, ny = now.sc + 1;
if (ok(nx, ny)) {
int nd = dist[now.fs][now.sc] + a[now.fs][now.sc];
if (chmin(dist[nx][ny], nd))q.push(PIP(dist[nx][ny], P(nx, ny)));
}
}
{
int nx = now.fs, ny = now.sc - 1;
if (ok(nx, ny)) {
int nd = dist[now.fs][now.sc] + a[nx][ny];
if (chmin(dist[nx][ny], nd))q.push(PIP(dist[nx][ny], P(nx, ny)));
}
}
{
int nx = now.fs + 1, ny = now.sc;
if (ok(nx, ny)) {
int nd = dist[now.fs][now.sc] + b[now.fs][now.sc];
if (chmin(dist[nx][ny], nd))q.push(PIP(dist[nx][ny], P(nx, ny)));
}
}
rep(i, now.fs) {
int nx = now.fs - i - 1, ny = now.sc;
if (ok(nx, ny)) {
int nd = dist[now.fs][now.sc] + i + 2;
if (chmin(dist[nx][ny], nd))q.push(PIP(dist[nx][ny], P(nx, ny)));
}
}
}
cout << dist[r][c] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;
int main() {
int H, W;
cin >> H >> W;
vector<string> S(H);
REP(i, H) {
cin >> S[i];
}
int edge = 0;
REP(i, H - 1) {
REP(j, W - 1) {
int white = 0;
FOR(k, i, i + 2) {
FOR(l, j, j + 2) {
if(S[k][l] == '.') {
white++;
}
}
}
if(white == 1 || white == 3) {
edge++;
}
}
}
cout << edge << endl;
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
int main()
{
int N;
cin >> N;
std::unordered_map<int, int> mx;
std::unordered_map<int, int> mn;
rep(i, N)
{
int x, c;
cin >> x >> c;
if (mx.find(c) != mx.end())
{
mx[c] = std::max(mx[c], x);
mn[c] = std::min(mn[c], x);
}
else
{
mx[c] = x;
mn[c] = x;
}
}
long long time1 = 0;
long long time2 = 0;
int pos1 = 0;
int pos2 = 0;
for (int i = 1; i <= N; i++)
{
if (mx.find(i) != mx.end())
{
long long diff = std::abs(mx[i] - mn[i]);
long long tmp1 = time1;
long long tmp2 = time2;
// from pos1, mx -> mn
tmp1 += std::abs(pos1 - mx[i]) + diff;
// from pos2, mx -> mn
tmp2 += std::abs(pos2 - mx[i]) + diff;
long long tmp3 = time1;
long long tmp4 = time2;
// from pos1, mn -> mx
tmp3 += std::abs(pos1 - mn[i]) + diff;
// from pos2, mn -> mx
tmp4 += std::abs(pos2 - mn[i]) + diff;
time1 = std::min(tmp1, tmp2);
time2 = std::min(tmp3, tmp4);
pos1 = mn[i];
pos2 = mx[i];
}
}
time1 += std::abs(pos1);
time2 += std::abs(pos2);
cout << std::min(time1, time2) << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
ll H, W;
ll d[2000][2000];
bool onBoard(int y, int x) {
if (y >= 0 && y < H && x >= 0 && x < W) {
return true;
}
return false;
}
int main() {
cin >> H >> W;
vector<string> S(H);
rep(i, H) {
cin >> S[i];
}
vector<set<P>> sets(26);
P start, goal;
rep(i, H) rep(j, W) {
int t = S[i][j] - 'a';
if (t >= 0 && t < 26) {
// cerr << "i=" << i << " j=" << j << "S[i][j] =" << S[i][j] << endl;
sets[t].insert(P(i, j));
}
if (S[i][j] == 'S') {
start = P(i, j);
}
if (S[i][j] == 'G') {
goal = P(i, j);
S[i][j] = '.';
}
}
rep(i, H) rep(j, W) {
d[i][j] = -1;
}
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
queue<P> q;
q.push(start);
d[start.first][start.second] = 0;
while (!q.empty()) {
P p = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int ny = p.first + dy[i];
int nx = p.second + dx[i];
if (onBoard(ny, nx) && S[ny][nx] != '#' && d[ny][nx] == -1) {
d[ny][nx] = d[p.first][p.second] + 1;
q.push(P(ny, nx));
}
}
int t = S[p.first][p.second] - 'a';
if (t >= 0 && t < 26) {
for (auto itr = sets[t].begin(); itr != sets[t].end(); ++itr) {
int ny = itr->first, nx = itr->second;
if (d[ny][nx] == -1) {
d[ny][nx] = d[p.first][p.second] + 1;
q.push(P(ny, nx));
}
}
sets[t].clear();
}
}
cout << d[goal.first][goal.second] << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
const int kN = 2e5 + 10;
int main() {
int n; scanf("%d", &n);
vector<long long> v[3];
auto ID = [&](char c) {
if(c == 'R') return 0;
else if(c == 'G') return 1;
return 2;
};
for(int i = 0; i < 2 * n; i++) {
long long x; char c[2];
scanf("%lld%s", &x, c);
v[ID(c[0])].push_back(x);
}
for(int i = 0; i < 3; i++) sort(v[i].begin(), v[i].end());
bool flag = 1;
for(int i = 0; i < 3; i++) flag &= (int(v[i].size()) % 2 == 0);
if(flag) return puts("0"), 0;
long long ans = 1e17;
for(int i = 0; i < 3; i++) if(int(v[i].size()) % 2 == 0) {
int j1 = (i + 1) % 3, j2 = (i + 2) % 3;
for(int k = 0, r = 0; k < int(v[j1].size()); k++) {
while(r < int(v[j2].size()) && v[j2][r] < v[j1][k]) r++;
if(r < int(v[j2].size())) ans = min(ans, v[j2][r] - v[j1][k]);
}
for(int k = 0, r = 0; k < int(v[j2].size()); k++) {
while(r < int(v[j1].size()) && v[j1][r] < v[j2][k]) r++;
if(r < int(v[j1].size())) ans = min(ans, v[j1][r] - v[j2][k]);
}
long long mn1 = 1e17;
for(auto x : v[j1]) {
auto it = lower_bound(v[i].begin(), v[i].end(), x);
if(it != v[i].end()) mn1 = min(mn1, *it - x);
if(it != v[i].begin()) mn1 = min(mn1, x - *prev(it));
}
long long mn2 = 1e17;
for(auto x : v[j2]) {
auto it = lower_bound(v[i].begin(), v[i].end(), x);
if(it != v[i].end()) mn2 = min(mn2, *it - x);
if(it != v[i].begin()) mn2 = min(mn2, x - *prev(it));
}
ans = min(ans, mn1 + mn2);
printf("%lld\n", ans);
return 0;
}
return 0;
}
| #include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> T[20];
int query(int h, int k, int i, int j)
{
int m = (k << h) + (1 << (h - 1));
if(i == (k << h) && j == ((k + 1) << h) - 1) return T[h][k];
if(j < m) return query(h - 1, k << 1, i, j);
if(i >= m) return query(h - 1, k << 1 | 1, i, j);
return query(h - 1, k << 1, i, m - 1) ^ query(h - 1, k << 1 | 1, m, j);
}
int main()
{
int n, q;
scanf("%d%d", &n, &q);
int d = ceil(log2(n));
for(int i = 0; i <= d; i++)
{
T[i].clear();
T[i].resize(1 << (d - i), 0);
}
for(int i = 0; i < n; i++)
scanf("%I64d", &T[0][i]);
for(int i = 1; i <= d; i++)
for(int j = 0; j < (int)T[i].size(); j++)
T[i][j] = T[i - 1][j << 1] ^ T[i - 1][j << 1 | 1];
for (int i = 0; i < q; i++) {
int t, x, y;
scanf("%d%d%d", &t, &x, &y);
if (t == 2) {
printf("%d\n", query(d, 0, x - 1, y - 1));
} else {
int p = x - 1;
T[0][p] = T[0][p] ^ y;
p >>= 1;
for (int j = 1; j <= d; j++) {
T[j][p] = T[j - 1][p << 1] ^ T[j - 1][p << 1 | 1];
p >>= 1;
}
}
}
return 0;
}
|
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
if(n%2==0)
cout<<"White"<<endl;
else if(n%2!=0)
cout<<"Black"<<endl;
return 0;
} | #include "bits/stdc++.h"
using namespace std;
int main(){
string N;
cin >> N;
N = N.substr(0, N.find_last_not_of('0') + 1);
string s;
s = N;
std::reverse(N.begin(), N.end());
// cout << s << N << endl;
if(N==s){
cout << "Yes" << endl;
return 0;
}
cout << "No" << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define MOD1 998244353
#define ceil(x, y) ((x)%(y))==0? ((x)/(y)) : ((x)/(y)+1)
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long */
void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("in7.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int T=1;
// cin >> T;
FOR1(tt, T){
// cout << "Case #" << tt << ": ";
int m, h; cin >> m >> h;
if(h % m == 0) cout << "Yes";
else cout << "No";
cout << '\n';
}
return 0;
} | //a solutjion from @tanmaymodi
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define ff(i,a,b) for(ll i=a;i<=b;i++)
#define bf(i,a,b) for(ll i=a;i>=b;i--)
const ll INF = 1e18;
//_______________necessary functinos____________
//________________DO NOT REMOVE_________________
ll ADD(ll x, ll y) {
ll res = x + y;
return (res >= mod ? res - mod : res);
}
ll MUL(ll x, ll y) {
ll res = x * y;
return (res >= mod ? res % mod : res);
}
ll SUB(ll x, ll y) {
ll res = x - y;
return (res < 0 ? res + mod : res);
}
ll POWER(ll x, ll y) {
ll res = 1;
x %= mod;
while (y) {
if (y & 1)
res = MUL(res, x);
y >>= 1; x = MUL(x, x);
} return res;
}
ll MOD_INV(ll x) {
return POWER(x, mod - 2);
}
ll maxofarray(ll a[], ll n) {
ll max = a[0];
ff(i, 0, n - 1) {
if (max < a[i])
max = a[i];
}
return max;
}
string lleger_to_binary_str(ll n) {
string s = "";
while (n > 0) {
if (n % 2 == 0) {
s += "0";
}
else {
s += "1";
}
n /= 2;
}
reverse(s.begin(), s.end());
return s;
}
//_______________________________________
void solve() {
ll n;
cin >> n;
ll ans = mod;
vector<ll> x(n), y(n);
ff(i, 0, n - 1) {
cin >> x[i] >> y[i];
}
ff(i, 0, n - 1) {
ff(j, 0, n - 1) {
if (i == j) {
ans = min(ans, x[i] + y[j]);
} else {
ans = min(ans, max(x[i], y[j]));
}
}
}
cout << ans << endl;
}
//_______________________________________
int main() {
//________________________________________
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//_______________________________________
solve();
} |
#include <bits/stdc++.h>
#include <unordered_set>
#include <algorithm>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repll(i,n) for (ll i = 0; i < (ll)(n); i++)
#define fore(x,a) for(auto&(x) : (a))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(a) (a).begin(), (a).end()
const ll INFL = 1e18;
const int INFI = 1e9;
const int MOD = 1e9 + 7;
int main(){
int N;
cin >> N;
vector<ll> A(N);
for (int i = 0; i < N; i++){
cin >> A[i];
}
vector<ll> F(N + 1);
F[0] = 1;
F[1] = 1;
for (int i = 2; i <= N; i++){
F[i] = (F[i - 1] + F[i - 2]) % MOD;
}
ll ans = 0;
ans += F[N] * A[0] % MOD;
for (int i = 1; i < N; i++){
ans += F[i] * F[N - i] % MOD * A[i] % MOD;
ans += F[i - 1] * F[N - i - 1] % MOD * (MOD - A[i]) % MOD;
}
ans %= MOD;
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
#define INF 10000000000000000
#define ff first
#define ss second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pie 3.141592653589793238462643383279
#define PYES cout<<"YES"<<endl
#define PNO cout<<"NO"<<endl
#define SB(a) sort(a.begin(),a.end(),greater<ll>());
#define SS(a) sort(a.begin(),a.end());
#define vll vector<ll>
#define vpll vector<pll>
vector<bool> prime;
vector<ll> fact,inv,primes,factors,pf;
void fast()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
void factorize(ll a)
{
factors.clear();
for(ll i=1;i*i<=a;i++)
{
if (i*i==a) factors.pb(i);
else if (a%i==0)
{
factors.pb(i);
factors.pb(a/i);
}
}
sort(factors.begin(),factors.end());
}
ll power(ll a,ll b)
{
if(a==1||b==0) return 1;
ll c=power(a,b/2);
ll res=1;
res=c*c;
if(res>=mod) res%=mod;
if(b%2) res*=a;
if(res>=mod) res%=mod;
return res;
}
ll modInv(int a)
{
return power(a,mod-2);
}
void factorial(ll n)
{
fact.resize(n+1);
fact[0]=1;
for(ll i=1;i<=n;i++)
{
fact[i]=fact[i-1]*i;
if(fact[i]>=mod) fact[i]%=mod;
}
}
void InvFactorial(ll n)
{
inv.resize(n+1);
inv[0]=1;
for(ll i=1;i<=n;i++) inv[i]=modInv(fact[i]);
}
ll ncr(ll n,ll r)
{
if(n<r||n<0||r<0) return 0;
ll b=inv[n-r];
ll c=inv[r];
ll a=fact[n]*b;
if(a>=mod) a%=mod;
a*=c;
if(a>=mod) a%=mod;
return a;
}
void remove_duplicates(vpll &v)
{
sort(v.begin(),v.end());
ll _size=unique(v.begin(),v.end())-v.begin();
v.resize(_size);
}
unsigned ll gcd(unsigned ll u, unsigned ll v)
{
if(u==0||v==0) return max(u,v);
unsigned ll shift=__builtin_ctz(u|v);
u>>=__builtin_ctz(u);
do{
v>>=__builtin_ctz(v);
if(u>v) swap(u,v);
v-=u;
}while(v!=0);
return u<<shift;
}
void sieve(ll n)
{
prime.assign(n+1,1);
prime[1]=false;
for(ll p=2;p*p<=n;p++)
{
if(prime[p])
{
for(ll i=p*p;i<=n;i+=p) prime[i]=false;
}
}
for(ll i=2;i<n+1;i++)
{
if(prime[i]) primes.push_back(i);
}
}
void prime_sieve(ll n)
{
pf.assign(n+1,0);
rep(i,n+1) pf[i]=i;
for(ll i=2;i<=n;i++)
{
if (pf[i]==i)
{
for(ll j=i;j<=n;j+=i) pf[j]=i;
}
}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
// Always remember: if (condition) if (condition) statement; This doesn't work !!
// Always increase boundaries for global or frequency questions
// pow((ll)10,i) doesn't work sometimes. It is better to use multiple of 10 in arrays. Always remember this.
// delete values when defining global if there are multiple testcases
// don't try to be smart and make stupid mistakes
void solve()
{
ll n;
cin>>n;
vll a(n);
rep(i,n) cin>>a[i];
if (n==1)
{
cout<<a[0];
return;
}
ll sum=0;
vll dp(n+5,0);
dp[0]=1,dp[1]=1;
for(ll i=2;i<=n+4;i++) dp[i]=dp[i-1]+dp[i-2],dp[i]%=mod;
rep(i,n)
{
if (i==0) sum+=dp[n-i]*a[i];
else
{
ll p=dp[n-i]*dp[i];
p%=mod;
p-=dp[n-i-1]*dp[i-1];
if (p<0)
{
ll q=(-p);
q=(q+mod-1)/mod;
p+=q*mod;
p%=mod;
}
p%=mod;
p*=a[i];
p%=mod;
sum+=p;
sum%=mod;
}
sum%=mod;
}
cout<<sum<<endl;
}
int main()
{
fast();
ll T=1;
//cin>>T;
for(ll z=1;z<=T;z++) solve();
} |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,w;
cin >> a >> b >> w;
int m=1e9,M=0;
for(int n=1;n<=1000000;n++){
if(a*n<=1000*w && 1000*w<=b*n){
m=min(m,n);
M=max(M,n);
}
}
if(M==0)cout << "UNSATISFIABLE";
else cout << m << ' ' << M;
} | /// In the name of ALLAH
/// I'm THEOVE46
#include<bits/stdc++.h>
using namespace std;
#define gap " "
#define nn "\n"
#define pi 2*acos(0.0)
#define db double
#define ft float
#define ll long long int
#define ull unsigned long long int
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define sfi(n) sf("%d",&n)
#define sfi2(n, m) sf("%d%d",&n,&m)
#define sfl(n) sf("%lld",&n)
#define sfl2(n, m) sf("%lld%lld",&n,&m)
#define sff(n) sf("%f",&n)
#define sfd(n) sf("%lf",&n)
#define pfi(n) pf("%d",n)
#define pfl(n) pf("%lld",n)
#define pff(n) pf("%f",f)
#define pfd(n) pf("%lf",f)
#define bfi cin.ignore()
#define bfs cin.get()
#define bfc getchar()
#define gl(s) getline(cin, s)
#define loop(a,n) for(i=a; i<n; i++)
#define mloop(i,a,n) for(i=a; i<n; i++)
#define rloop(i,a,n) for(i=a; i>=n; i--)
#define tloop(test) for(ll tl=1; tl<=test; tl++)
#define case1(z) cout<<"Case "<<z<<": "
#define case2(z) printf("Case %d: ",z)
#define vi vector<int>
#define vl vector<ll>
#define vld(vc,rw) vector<vector<ll> >vc(rw)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pis pair<int,string>
#define psi pair<string,int>
#define mls map <ll,string>
#define msl map <string,ll>
#define mll map <ll,ll>
#define mp make_pair
#define pb push_back
#define itr vector<int> :: iterator
#define atl(i, v) for(auto i: v)
#define sz(s) s.size()
#define sl(s) s.length()
#define Sort(s) sort(s.begin(), s.end())
#define SortR(s) sort(s.rbegin(), s.rend())
#define all(x) x.begin(),x.end()
#define rall(x) x.end(), x.begin()
#define MEM(ar,val) memset(ar, (val), sizeof(ar))
#define IN(A,B,C) assert(B<=A && A<=C)
#define MOD 1000000007
#define EPS 1e-9
#define Max 1e9
#define Min -1e9
#define bug1 " **1** "
#define bug2 " ****2**** "
#define artri(b,h) 0.5*b*h
#define artrap(b1,b2,h) (b1+b2)/2*h
#define arcrl(r) pi*r*r
#define vlsyl(r,h) pi*r*r*h
#define vlcone(r,h) pi*r*r*(h/3)
#define vlsph(r) (4/3)*pi*r*r*r
#define flush fflush(stdout)
#define pcn(dg,val) fixed << setprecision(dg) << val
#define ggl pf("Case #%lld: ", tl)
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define showsort(n, a) for(int i=0; i<n; i++) cout << a[i] << gap; cout << endl;
inline string IntToString(ll a) {char x[100]; sprintf(x,"%lld",a); string s=x; return s;}
inline ll StringToInt(string a) {char x[100]; ll res; strcpy(x, a.c_str()); sscanf(x,"%lld",&res); return res;}
///THEOVE46
int main()
{
FastIO;
bool bl = true;
ll a, b, w, mn, mx, x, y, s;
sf("%lld%lld%lld", &a, &b, &w);
w*=1000;
mn = w/b;
if(w%b!=0)
{
x = w%b;
s = w - (a*mn);
if(s<a)
{bl = false;
//cout << bug1 << endl;
}
mn++;
}
mx = w/a;
if(w%a!=0)
{
x = w%a;
s = (b-a)*mx;
if(s<x)
{bl = false;
//cout << bug2 << x << " " << mx << " " << s << endl;
}
}
if(bl) cout << mn << " " << mx << nn;
else cout << "UNSATISFIABLE" << endl;
return 0;
}
/// check for integer overflow, array bounds
/// check for n=1
/// - - - The Ove 46
|
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define pb push_back
#define fi first
#define se second
#define ll long long
#define tp top()
#define fr front()
#define vi vector<int>
#define sz size()
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define mem(a, b) memset(a, (b), sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))
#define sqr(x) ( (x) * (x) )
#define all(v) v.begin(), v.end()
typedef pair<int, int> pii;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
void base(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
//double dist(double x1, double y1, double x2, double y2){
// return hypot(x1-x2,y1-y2);
//}
struct point {
double x,y;
point() {
x=y=0.0;
}
};
bool collinear(point P, point L, point R) { //newly added(luis), cek 3 poin segaris
return P.x*(L.y-R.y)+L.x*(R.y-P.y)+R.x*(P.y-L.y)==0; // bole gnti “dabs(x)<EPS”
}
point ps[120];
//double x[120], y[120];
void solve(){
int n; cin>>n;
rep(i,0,n) cin>>ps[i].x>>ps[i].y;
bool v=0;
rep(i,0,n) rep(j,i+1,n) rep(k,0,n){
if (k==i || k==j) continue;
if (collinear(ps[i],ps[j],ps[k])) {
v = 1;
}
}
if (v) cout<<"Yes\n";
else cout<<"No\n";
}
int main()
{
base();
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
| //Keep calm and carry on..
/* Problem :
URL :
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
# define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
# define pb push_back
# define pi 3.1415926535897932384626
# define mod 1000000007
# define endl '\n'
# define DEBUG false
# define F first
# define S second
# define loop1(i,a,b) for(ll i = a; i<b; i++)
# define loop2(i,a,b) for(ll i = b-1; i>=a; i--)
# pragma GCC optimize "trapv"
void just_solved_it() {
ld sx, sy, gx, gy;
cin >> sx >> sy >> gx >> gy;
ld ans = (gy*sx + sy*gx)/ (sy + gy);
cout << fixed << setprecision(12) << ans ;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast;
ll t; //cin >> t;
t = 1;
while (t--) {
just_solved_it();
cout << endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
// typedef long long int;
#define int long long
int const MAXN = 2e5 + 10, INF = 0x3f3f3f3f3f3f3f3f;
int T;
int a[5], m[5];
int qmi(int a, int b, int mod) {
int res = 0;
while (b > 0) {
if (b & 1) res = (res + a) % mod;
a = (a + a) % mod;
b >>= 1;
}
return res;
}
int exgcd(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int gcd = exgcd(b, a % b, x, y);
int tp = x;
x = y;
y = tp - a / b * y;
return gcd;
}
// a, m --- 第i个方程表示x ≡ ai(mod mi),下标从0开始
// n---- 方程个数
int excrt(int ai[], int mi[], int n) {
int x, y, k;
int M = mi[0], ans = ai[0]; //第一个方程的解特判
for (int i = 1; i < n; i++) {
int a = M, b = mi[i], c = (ai[i] - ans % b + b) % b; // ax≡c(mod b)
int gcd = exgcd(a, b, x, y), bg = b / gcd;
if (c % gcd != 0) return -1; //判断是否无解,然而这题其实不用
x = qmi(x, c / gcd, bg); //把x转化为最小非负整数解
ans += x * M; //更新前k个方程组的答案
M *= bg;
ans = (ans % M + M) % M;
}
return (ans % M + M) % M;
}
signed main() {
cin >> T;
while (T--) {
int x, y, p, q;
cin >> x >> y >> p >> q;
int ans = INF;
for (int i = x; i < x + y; i++) {
for (int j = p; j < p + q; j++) {
a[0] = i, m[0] = 2 * (x + y);
a[1] = j, m[1] = p + q;
// cout << CRT(a, m, n) << endl;
// cout << "a[0] " << a[0] << " " << "m[0] " << m[0] << endl;
// cout << "a[1] " << a[1] << " " << "m[1] " << m[1] << endl;
int t = excrt(a, m, 2);
// cout << "res: " << t << endl;
if (t == -1) continue;
ans = min(ans, t);
}
}
if (!ans || ans == INF)
cout << "infinity" << endl;
else
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define IFOR(i, a, b) for (long long i = (a); i <= (long long)(b); i++)
using namespace std;
using VL = vector<long long>;
using ll = int64_t;
ll mod(ll x,ll m){ll y=x%m;return (y>=0LL)?y:y+m;}
template<class T>bool chmin(T& a, T b){if(a>b){a=b;return true;}else return false;}
ll gcd(ll a,ll b,ll& x,ll& y)
{if(a){ll d=gcd(b%a,a,x,y);y-=(b/a)*x;swap(x,y);if(d<0LL){d=-d;x=-x;y=-y;}return d;}else{x=0;y=1;return b;}}
int main(){
int T;
cin>>T;
string ans = "";
REP(i,T){
ll t = LLONG_MAX;
ll X,Y,P,Q;
scanf("%lld %lld %lld %lld",&X,&Y,&P,&Q);
ll a=(X+Y)<<1, b=P+Q;
ll x, y;
ll d = gcd(a, -b, x, y);
ll u = b/d, v = a/d;
ll stop0=P-X, stop1=P-X+Q-1LL;
ll wake0=P-X-Y+1LL, wake1=P-X;
ll from=min(stop0, wake0), to=max(stop1, wake1);
IFOR(z, from, to){
if(mod(z,d)!=0LL)continue;
if(stop0<=z && z<=stop1){
chmin(t,a*mod(z/d*x,u)+X);
}else{
chmin(t, b*mod(z/d*y,v)+P);
}
}
ans += (t==LLONG_MAX ? "infinity" : (to_string(t)))+"\n";
}
cout << ans;
return 0;
} |
/*input
2021
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e17;
const int INF=0x3f3f3f3f;
const ll MOD=998244353;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
ll mult(ll a,ll b){
return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
if(b<=0) return 1;
if(a<=0) return 0;
ll res=1LL;
while(b){
if(b&1) res=mult(res,a);
a=mult(a,a);
b>>=1;
}
return res;
}
int main(){
int n;
cin>>n;
cout<<((n+99)/100);
}
| #include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define sz(v) (int)v.size()
#define ps(y) cout << fixed << setprecision(y)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define trav(x, v) for(auto &x: v)
#define w(t) int t; cin >> t; while(t--)
#define rep0(i, n) for(int i = 0; i < n; i++)
#define rrep0(i, n) for(int i = n - 1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= n; i++)
#define rrep1(i, n) for(int i = n; i > 0; i--)
#define inp(arr, n) rep0(i, n) cin >> arr[i];
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = a; i >= b; i--)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef map<ll, ll> mii;
typedef map<char, ll> mci;
typedef priority_queue<ll> pq_mx;
typedef priority_queue<ll, vi, greater<>> pq_mn;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> pbds;
/*
* find_by_order(i) -> returns an iterator to the element at ith position (0 based)
* order_of_key(i) -> returns the position of element i (0 based)
*/
const int N = 2e6 + 5;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll inf = 1e18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void fio() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
}
const int M = 1e7 + 5;
ll spf[M], mobius[M];
vi primes;
void sieve() {
rep(x, 2, 1e7) {
if (spf[x] == 0) spf[x] = x, primes.pb(x);
for (int y = 0; y < sz(primes) and primes[y] <= spf[x] and x * primes[y] <= 1e7; y++)
spf[x * primes[y]] = primes[y];
}
}
void Mobius() {
/*
* mobius[x] = 1 => x is a square-free +ve int with even no. of prime factors
* mobius[x] = -1 => x is a square-free +ve int with odd no. of prime factors
* mobius[x] = 0 => x has a squared prime factor
*/
rep1(x, 1e7) {
if (x == 1) mobius[x] = 1;
else {
if (spf[x] == spf[x / spf[x]]) mobius[x] = 0;
else mobius[x] = -mobius[x / spf[x]];
}
}
}
int main() {
fio();
sieve();
Mobius();
int l, r;
cin >> l >> r;
if(l == 1) ++l;
ll res = 0;
rep(x, 2, r) {
ll cur = r / x - (l - 1) / x;
res -= cur * cur * mobius[x];
}
// cout << res << endl;
rep(x, l, r) {
--res;
for (int y = 2 * x; y <= r; y += x) res -= 2;
}
cout << res;
return 0;
} |
#include <bits/stdc++.h>
#define LL long long
#define ft first
#define sd second
#define mp(x,y) make_pair(x,y)
#define int LL
using namespace std;
//const int N = ;
//const int mod = ;
const int INF =numeric_limits<int >::max();
#define For(n) for (int i=1;i<=n;++i)
#define rep(i,n) for (int i=1;i<=n;++i)
#define repp(i,x,y) for (int i=x;i<=y;++i)
void read(int &x)
{
x=0;
char ch=getchar();
int f=1;
while (!isdigit(ch)) (ch=='-'?f=-1:0),ch=getchar();
while ( isdigit(ch)) x=x*10+ch-'0',ch=getchar();
x*=f;
}
int solve(int x)
{
int tmp=0;
for (int i=1;i<=x;++i)
{
int j=x/(x/i);
tmp+=(j-i+1)*(x/i);
i=j;
}
return tmp;
}
int ans,K;
int qsm(int a,int b,int mod)
{
int tmp=1;
while (b)
{
if (b&1) tmp=tmp*a%mod;
b>>=1;
a=a*a%mod;
}
return tmp;
}
int a,b,c,cnt[30];
char s[2000000+2];
signed main()
{
scanf("%s",s+1);
int n=strlen(s+1);
int nxt=n+1;
cnt[s[n]-'a']++;
cnt[s[n-1]-'a']++;
for (int i=n-2;i>=1;--i)
{
if (s[i]==s[i+1]&&s[i+1]!=s[i+2])
{
ans+=n-i-cnt[s[i]-'a'];
memset(cnt,0,sizeof(cnt));
cnt[s[i]-'a']=n-i;
}
cnt[s[i]-'a']++;
}
printf("%lld",ans);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ostream &operator<<(ostream &os, const vector<lli> &x){
os << "{";
for(int i = 0; i < x.size(); i++){
if(i < x.size()-1) os << x[i] << ", ";
else os << x[i];
}
os << "}";
return os;
}
int main(void){
string s;
cin >> s;
lli n = s.size();
lli ans = 0;
char last = '!';
vector<lli> count(26);
for(int i = n-1; i >= 0; i--){
char c = s[i];
count[c-'a']++;
if(last == c){
lli tot = 0;
for(int j = 0; j < 26; j++){
char now = 'a'+j;
lli val = count[now-'a'];
count[now-'a'] = 0;
if(now == c) continue;
tot+=val;
}
ans += tot;
count[c-'a'] = n-i;
last = '!';
}
last = c;
}
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
#define check(x) if(x>=mod) x-=mod
const int inf=0x3f3f3f3f,mod=998244353;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int qpow(int x,int y){
int ret = 1;
while(y) {
if(y & 1) ret = (ll)ret * x % mod;
x = (ll)x * x % mod;
y >>= 1;
}
return ret;
}
template<int md> struct modint{
int x;
modint(int v = 0) {x = v; if(x >= md || x < 0) {x %= md; if(x < 0) x += md;}}
operator int() const {return x;}
friend modint operator +=(modint &a,const modint &b) {
a.x += b.x;
if(a.x >= md) a.x -= md;return a;
}
friend modint operator +(modint a,const modint &b) {
return a += b;
}
friend modint operator -=(modint &a,const modint &b) {
a.x -= b.x;a.x += md;
if(a.x >= md) a.x -= md;return a;
}
friend modint operator -(modint a,const modint &b) {
return a -= b;
}
friend modint operator *=(modint &a,const modint &b) {
a.x = (ll)b.x * a.x % md;
return a;
}
friend modint operator *(modint a,const modint &b) {
return a *= b;
}
friend modint operator *(modint a,int b) {
return a *= modint(b);
}
friend modint operator /=(modint &a,const modint &b) {
a.x = (ll)b.x * qpow(a.x, md - 2) % md;
return a;
}
friend modint operator /(modint a,const modint &b) {
return a /= b;
}
friend modint operator /(modint a,int b) {
return a /= modint(b);
}
friend modint operator ^(modint a,int b) {
return qpow(a.x, b);
}
};
int n,m,k,a[5005][5005],pre[5005][5005];modint<998244353> dp[5005][5005][3],pw[5005];
char s[5];
int main()
{
pw[0] = 1;
rep(i,1,5000) pw[i] = pw[i - 1] * 3;
scanf("%d%d%d",&n,&m,&k);
rep(i,1,k) {
int x,y;
scanf("%d%d%s",&x,&y,s);
if(s[0] == 'X') a[x][y] = 1;
if(s[0] == 'R') a[x][y] = 3;
if(s[0] == 'D') a[x][y] = 2;
}
rep(i,1,n) {
rep(j,1,m) pre[i][j] = pre[i][j-1] + (a[i][j] == 0);
}
dp[1][1][0] = dp[1][1][1] = dp[1][1][2] = 1;
rep(i,1,n) rep(j,1,m) {
int u = a[i][j] - 1;
if(u == 0) dp[i][j][1] = dp[i][j][2] = 0;
if(u == 1) dp[i][j][0] = dp[i][j][2] = 0;
if(u == 2) dp[i][j][0] = dp[i][j][1] = 0;
dp[i+1][j][0] += (dp[i][j][0] + dp[i][j][1]) * pw[pre[i][m] - pre[i][j] + pre[i + 1][j - 1]];
dp[i+1][j][1] = dp[i+1][j][2] = dp[i+1][j][0];
dp[i][j+1][0] += dp[i][j][0] + dp[i][j][2];
dp[i][j+1][1] = dp[i][j+1][2] = dp[i][j+1][0];
//printf("%d %d %d %d %d\n",i,j,dp[i][j][0],dp[i][j][1],dp[i][j][2]);
}
modint<998244353> ans = dp[n][m][0] + dp[n][m][1] + dp[n][m][2];
printf("%d\n",ans.x);
return 0;
} | #include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
struct union_find {
ll par[MAX_N];
ll Size[MAX_N];
union_find(ll n) {
for (int i = 0; i < n; i++) {
par[i] = i;
Size[i] = 1;
}
}
ll root(ll x) {
if (par[x] == x)return x;
return par[x] = root(par[x]);
}
bool same(ll x, ll y) {
return root(x) == root(y);
}
void unite(ll x, ll y) {
if (same(x, y))return;
Size[root(x)] += Size[root(y)];
par[root(y)] = root(x);
}
};
int main(){
int n,q;
cin>>n>>q;
vector<int> c(n);
vector<int> ans(0);
vector<map<int,int> > mps(n);
struct union_find U(n);
for(int i=0;i<n;i++){
cin>>c[i];
c[i]--;
mps[i][c[i]]=1;
}
while(q){
q--;
int type;
cin>>type;
if(type==1){
int a,b;
cin>>a>>b;
a--; b--;
if(U.same(a,b)) continue;
if(U.Size[U.root(a)] > U.Size[U.root(b)]){
for(auto p : mps[U.root(b)]){
mps[U.root(a)][p.first] += p.second;
}
U.unite(a,b);
}else{
for(auto p : mps[U.root(a)]){
mps[U.root(b)][p.first] += p.second;
}
U.unite(b,a);
}
}else{
int x,y;
cin>>x>>y;
x--; y--;
ans.push_back(mps[U.root(x)][y]);
}
}
for(int a:ans) cout<<a<<endl;
} |
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
/*
* coder :: ATUL_PANDEY_2608
* >>> INDIA <<<
*/
using namespace std;
using namespace __gnu_pbds;
// #define part ..
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end()
#define mod 1000000007
//#define maxx 200006
#define ll long long
#define quick ios_base::sync_with_stdio(NULL),cin.tie(0);
#define listll vector< long long >
#define listi vector< int>
#define pii pair<int , int>
#define pll pair<long long , long long >
#define minheap priority_queue<long long , vector< long long >, greater<long long > >
#define rep(i,a,b) for(int i=a;i<b;i++)
#define memo(a) memset( a, 0 ,sizeof ( a) )
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power( ll a, ll n, ll m= 1000000007){
ll ans = 1;
while(n){
if(n&1)
{
ans *= a;
ans%=m;
}
a*=a;
a%=m;
n/=2;
}
return ans ;
}
vector< int > prm ;
vector < bool > vsp ;
void prime ( int nn = 100000 ) {
vsp = vector < bool > ( nn+1, 0 );
int size_prime = nn;
for( ll i =2; i*i < size_prime ; i++){
if( vsp[i] == 1)
continue;
for(ll j = i*i; j < size_prime ;j+=i){
vsp[j] =1;
}
}
for( int i= 2; i < size_prime ; i++)
if (vsp[i] == 0)
prm.pb(i);
}
template < class T > using oset = tree< T , null_type, less < T > , rb_tree_tag , tree_order_statistics_node_update > ;
// end of #define
// define globals ...
const int maxx = 2e5+26;
//write function from here ...
// never forget to recheck your predefined function in template ..
// already defined :: prime , power , gcd : ( ll )..
int Main(){
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<a*d - b*c <<endl;
return 0;
}
int main(){
quick;
int t =1;
//cin>>t;
while(t-- )
Main();
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
int c,d;
cin>>c>>d;
cout<<a*d-b*c<<endl;
} |
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int N;
cin >> N;
int ans;
if (N != 1) ans = N - 1;
else ans = 0;
cout << ans << endl;
} | #include <bits/stdc++.h>
#include<cmath>
#include<string>
#define pb push_back
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) x.begin(),x.end()
#define int long long
#define ll long long
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// look for all edge cases
//search for a pattern
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
if(n < 2){
cout << 0;
return 0;
}
set<pair<int,int>> s;
for(int i=1; i<n; i++){
int a = i;
int b = n - i;
s.insert({a,b});
}
cout << s.size();
return 0;
}
|
// Hail god Yato
#include <bits/stdc++.h>
using namespace std;
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
pair<ll, ll> calc(ll b, ll c){
if(c&1)
return {-b-c/2, -b+c/2};
else{
if(c == 0)
return {b, b};
return {b-c/2, b+c/2-1};
}
}
void solve(){
ll b, c;
cin>>b>>c;
// b = abs(b);
pair<ll, ll> fst = calc(b, c);
pair<ll, ll> snd = calc(b, c-1);
// cout<<fst.second<<" "<<fst.first;
// cout<<snd.second<<" "<<snd.first<<" ";
ll ans = fst.second - fst.first + 1 + snd.second - snd.first + 1;
// if((fst.first <= snd.first && fst.second >= snd.first) || (fst.first >= snd.first && fst.second <= snd.second))
ans -= max(0ll, min(snd.second, fst.second) - max(fst.first, snd.first) + 1);
// else{
// swap(fst, snd);
// if((fst.first <= snd.first && fst.second >= snd.first) || (fst.first >= snd.first && fst.second <= snd.second))
// ans -= min(snd.second, fst.second) - max(fst.first, snd.first) + 1;
// }
cout<<ans;
}
signed main(){
hs;
ll t;
t=1;
// cin>>t;
for (int i=1; i<=t; i++){
//cout<<"Case #"<<i<<": ";
solve();
}
return 0;
} | #include <vector>
#include <iostream>
#define int long long
#define double long double
#define tezz ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
signed main() {
tezz
vector<int> primes;
for (int i = 2; i < 72; i++) {
bool flag = true;
for (int j = 2; j < i; j++) {
if (i % j == 0) flag = false;
}
if (flag) primes.emplace_back(i);
}
int A, B;
cin >> A >> B;
vector<int> v(B - A + 1);
for (int i = A; i <= B; i++) {
int mask = 0;
for (int j = 0; j < primes.size(); j++) {
if (i % primes[j] == 0) {
mask |= (1 << j);
}
}
v[i - A] = mask;
}
vector<int> dp(1<<primes.size());
dp[0] = 1;
for (int x: v) {
for (int mask = 0; mask < (1 << primes.size()); mask++) {
if (dp[mask]&&(mask & x)==0) {
dp[mask ^ x] += dp[mask];
}
}
}
int ans = 0;
for (int i = 0; i < (1 << primes.size()); i++) ans += dp[i];
cout << ans;
} |
#include <bits/stdc++.h>
#define repi(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)
#define rep(i, n) repi(i, 0, n)
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
using namespace std;
using P = pair<int, int>;
struct Vec{
double x, y;
};
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
double norm(int x1, int x2, int y1, int y2){
return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2- y1);
}
int main()
{
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
// cout << fixed << setprecision(15);
int n;
cin >> n;
vector<vector<int>> xy(n, vector<int>(2));
rep(i,n) cin >> xy[i][0] >> xy[i][1];
rep(i, n) repi(k, i+1, n) repi(l, k + 1, n){
int dx1, dx2, dy1, dy2;
dx1 = xy[i][0] - xy[k][0];
dy1 = xy[i][1] - xy[k][1];
dx2 = xy[l][0] - xy[k][0];
dy2 = xy[l][1] - xy[k][1];
if (dx2 * dy1 == dx1 * dy2) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
#define all(x) x.begin(), x.end()
#ifdef _DEBUG
#define disp(x) cout << #x << " : " << x << endl
#else
#define disp(x)
#endif
using namespace std;
using ll = int64_t;
int main(){
int a, b, x, y; cin >> a >> b >> x >> y;
if(a > b) {
int d = a - b;
cout << min((d - 1)*y + x, (2*d - 1)*x) << endl;
} else if(a < b) {
int d = b - a;
cout << min(d*y + x, (2*d + 1)*x) << endl;
} else {
cout << x << endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> solve(int n){
if(n==1){
vector<vector<int>> v;
v.resize(1);
v[0].push_back(0); v[0].push_back(1);
return v;
}
vector<vector<int>> u = solve(n - 1);
vector<vector<int>> v;
int x = (1<<n) - 1;
v.resize(x);
int s = 0;
for(int i=0;i<u.size();i++){
for(int k=0;k<2;k++){
for(int j=0;j<u[i].size();j++){
v[s].push_back(u[i][j]);
}
for(int j=0;j<u[i].size();j++){
v[s].push_back(u[i][j]^k);
}
s++;
}
}
for(int i=0;i<(1<<n);i++){
if(i<(1<<(n - 1))) v[s].push_back(0);
else v[s].push_back(1);
}
return v;
}
int main(){
int i,n; cin >> n;
vector<vector<int>> v = solve(n);
cout << (1<<n) - 1 << endl;
for(i=0;i<(1<<n) - 1;i++){
for(int j: v[i]){
if(j==0) cout << "A";
else cout << "B";
}
cout << endl;
}
} | #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
static char buf[1048576];
static int s = 1048576;
static int e = 1048576;
if(s == e && e == 1048576){
e = fread_unlocked(buf, 1, 1048576, stdin);
s = 0;
}
if(s == e){
return EOF;
}
return buf[s++];
}
inline void rd(int &x){
int k;
int m=0;
x=0;
for(;;){
k = my_getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = my_getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
struct MY_WRITER{
char buf[1048576];
int s;
int e;
MY_WRITER(){
s = 0;
e = 1048576;
}
~MY_WRITER(){
if(s){
fwrite_unlocked(buf, 1, s, stdout);
}
}
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
MY_WRITER_VAR.s = 0;
}
MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
my_putchar_unlocked(a);
}
inline void wt_L(int x){
int s=0;
int m=0;
char f[10];
if(x<0){
m=1;
x=-x;
}
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
if(m){
my_putchar_unlocked('-');
}
while(s--){
my_putchar_unlocked(f[s]+'0');
}
}
inline void wt_L(const char c[]){
int i=0;
for(i=0;c[i]!='\0';i++){
my_putchar_unlocked(c[i]);
}
}
inline int BIT_popcount_L(const int x){
return __builtin_popcount(x);
}
inline int BIT_popcount_L(const long long x){
return __builtin_popcountll(x);
}
char res[300][300];
int ok;
int ng;
int main(){
int N;
rd(N);
int p;
int i;
int j;
int k;
N = (1<<N);
for(i=(0);i<(N-1);i++){
for(j=(0);j<(N);j++){
res[i][j] =BIT_popcount_L(j&(i+1))% 2;
}
}
for(i=(0);i<(N-1);i++){
for(j=(0);j<(N);j++){
res[i][j] += 'A';
}
}
wt_L(N-1);
wt_L('\n');
for(i=(0);i<(N-1);i++){
wt_L(res[i]);
wt_L('\n');
}
return 0;
}
// cLay version 20210103-1 [bug fixed 1]
// --- original code ---
// char res[300][300];
// int ok, ng;
// {
// int @N, p, i, j, k;
// N = (1<<N);
//
// rep(i,N-1){
// rep(j,N) res[i][j] = BIT_popcount(j&(i+1)) % 2;
// }
// rep(i,N-1) rep(j,N) res[i][j] += 'A';
//
// // rep(i,N) rep(j,i+1,N){
// // ok = ng = 0;
// // rep(k,N-1) if(res[k][i]==res[k][j]) ok++;
// // rep(k,N-1) if(res[k][i]!=res[k][j]) ng++;
// // wt(i,j,ok,ng);
// // }
//
// wt(N-1);
// rep(i,N-1) wt(res[i]);
// }
|
#include<bits/stdc++.h>
#include <cmath>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(NULL);
long long n,m,k,l,j,p,i;
cin>>n;
for(i=1; powl(3,i)+5<=n; i++)
{
for(j=1; powl(5,j)+3<=n; j++)
{
k=powl(3,i);
m=powl(5,j);
p=m%10;
//if(p==4)m++;
if(k+m==n)
{
cout<<i<<" "<<j;
return 0;
}
}
}
cout<<-1;
}
| #include<bits/stdc++.h>
using namespace std;
#define rep(i,k,n) for(long long i=k;i<=n;i++)
#define per(i,n,k) for(long long i=n;i>=k;i--)
#define pb push_back
#define fi first
#define se second
///#pragma GCC optimize(3,"Ofast","inline")
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<ll,ll> P;
ll gcd(ll a,ll b)
{
ll r;
while(b>0)
{
r=a%b;
a=b;
b=r;
}
return a;
}
inline void write(ll x)
{
if(x<0)
putchar('-'),x=-x;
if(x>9)
write(x/10);
putchar(x%10+'0');
}
inline ll read()
{
ll x=0;
char f=1,c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
f=-1;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
inline ll fp(ll a,ll b,ll mod)
{
ll ans=1LL;
while(b)
{
if(b&1LL)
ans=ans*a%mod;
a=a*a%mod;
b>>=1LL;
}
return ans;
}
inline ll lcm(ll a,ll b)
{
return a/gcd(a,b)*b;
}
ll a[1000005];
ll b[1000005];
int main()
{
ll n=read();
rep(i,1,n)a[i]=read();
rep(i,1,n)b[i]=read();
ll sum=0;
rep(i,1,n)sum+=a[i]*b[i];
if(sum==0)printf("Yes\n");
else printf("No\n");
return 0;
}
|
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
#define int long long
#define endl "\n"
constexpr long long INF = (long long)1e18;
constexpr long long MOD = 998244353;
struct fast_io {
fast_io(){
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
};
} fio;
signed main(){
cout<<fixed<<setprecision(10);
int ans = 1;
int H, W;
vector<string> S;
vector<vector<int>> con;
cin>>H>>W;
S.resize(H);
con.resize(H+W+1,vector<int>(3));
for(int i = 0; i < H; i++){
cin>>S[i];
for(int j = 0; j < W; j++) {
if(S[i][j] == 'R') {
con[i+j][0]++;
} else if(S[i][j] == 'B'){
con[i+j][1]++;
} else {
con[i+j][2]++;
}
}
}
for(int i = 0; i+1 < H+W; i++){
if(con[i][0] && con[i][1]) {
ans = 0;
} else if(con[i][0] || con[i][1]) {
ans *= 1;
} else {
// cout<<i<<endl;
ans *= 2;
}
ans %= MOD;
}
cout<<ans<<endl;
return 0;
} | #include<stdio.h>
#include<iostream>
using namespace std;
const int maxH=505,mod=998244353;
int H,W,ans;
int val[maxH<<1];
string s;
int main(){
scanf("%d%d",&H,&W);
for(int i=1;i<=H;i++){
cin>>s;
for(int j=1;j<=W;j++)
val[i+j]|=(s[j-1]=='R'? 1:(s[j-1]=='B'? 2:0));
}
ans=1;
for(int i=2;i<=H+W;i++){
if(val[i]==3){
puts("0");
return 0;
}
else ans=1ll*ans*(val[i]==0? 2ll:1ll)%mod;
}
printf("%d\n",ans);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
template<class T> void chmax(T &a, const T b){ a = max(a, b); }
template<class T> void chmin(T &a, const T b){ a = min(a, b); }
long long gcd(long long a, long long b) { return (a % b) ? gcd(b, a % b) : b; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// ifstream in("input.txt");
// cin.rdbuf(in.rdbuf());
ll b, c;
cin >> b >> c;
ll b1l = b - c / 2;
ll b1r = b + (c - 2) / 2;
ll b2l = -b - (c - 1) / 2;
ll b2r = -b + (c - 1) / 2;
ll ans = b1r - b1l + 1 + b2r - b2l + 1;
if (b1r < b2l) {
// nop
}
else if (b2r < b1l) {
// nop
}
else {
ans = max(b1r, b2r) - min(b1l, b2l) + 1;
}
cout << ans << endl;
return 0;
}
| #include <iostream>
#include <fstream>
#include <cstdlib>
#include <bitset>
#include <map>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>
#include <set>
#include <unordered_set>
using namespace std;
#define ll long long
#define ld long double
#define vecint vector<int>
#define vec2int vector<vector<int>>
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecdouble vector<double>
#define vecchar vector<char>
#define vecstr vector<string>
#define vec2str vector<vector<string>>
#define vecbool vector<bool>
#define vec2bool vector<vector<bool>>
#define pairll pair<ll,ll>
#define vecpairll vector<pair<long long,long long>>
#define vec2pairll vector<vector<pair<long long,long long>>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)
#define forbit(s,a) for(int s = 0; s < (1 << a); s++)
#define sortLower(vec) sort(vec.begin(),vec.end())
#define sortGreater(vec,type) sort(vec.begin(),vec.end(),greater<type>())
const ll INF = 1000000000000;
const ld Pi = acos(-1.0);
const ll mod = 1000000007;
const ld EPS = 0.0000000001;
#define out_(s) cout << s << " "
#define out(s) cout << s << "\n"
class UnionFind
{
public:
vecll par;
UnionFind(ll n)
{
par.resize(n, -1);
}
ll root(ll pos)
{
if (par[pos] == -1) return pos;
par[pos] = root(par[pos]);
return par[pos];
}
void unite(ll u, ll v)
{
u = root(u); v = root(v);
if (u == v) return;
par[u] = v;
}
bool same(ll u, ll v)
{
if (root(u) == root(v)) return true;
return false;
}
};
ll gcd(ll a, ll b)
{
if (min(a, b) == 0)
return max(a, b);
return gcd(min(a, b), max(a, b) % min(a, b));
}
ll lcm(ll a, ll b)
{
ll buf = gcd(a, b);
return abs(a * b) / buf;
}
string toBaseNum(ll n, ll base)
{
string s;
while (n > 0)
{
if (base > 10)
{
if (n % base >= 10)
{
string buf;
buf.push_back(n % base - 10 + 'A');
s = buf + s;
}
else
{
s = to_string(n % base) + s;
}
}
else
{
s = to_string(n % base) + s;
}
n /= base;
}
if (s.empty())
s = "0";
return s;
}
ll toDecNum(string n, ll base)
{
ll num = 0;
forll(i, 0, n.size())
{
ll buf = 0;
buf = n[i] >= 'A' ? n[i] - 'A' + 10 : n[i] - '0';
num += pow(base, n.size() - i - 1) * buf;
}
return num;
}
vecpairll primeFactorize(ll n)
{
vecpairll buf;
forll(i, 2, sqrt(n + 1))
{
if (n % i != 0)
continue;
long long ex = 0;
while (n % i == 0)
{
++ex;
n /= i;
}
buf.push_back({ i, ex });
}
if (n != 1) buf.push_back({ n, 1 });
return buf;
}
bool isInField(pairll next, ll row, ll col)
{
return (0 <= next.second && next.second < col) && (0 <= next.first && next.first < row);
}
//逆元((1÷b) mod p、bを掛けるとmod pで1となる数)を求める
ll modinv(ll a, ll m)
{
ll b = m, u = 1, v = 0;
while (b)
{
ll t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
ll Combination(ll n, ll r)
{
ll num = 1;
for (ll i = 1; i <= r; i++)
{
num = num * (n - i + 1) / i;
num %= mod;
}
return num;
}
int main() {
ll n, m, l, ans = 0;
string s = "No";
bool flag = false;
cin >> n;
vecll ans2 = {6,10,15};
ll six = 12, ten = 20,fif=30;
while (ans2.size() < n)
{
if (six <= ten && six <= fif)
{
ans2.push_back(six);
six += 6;
}
else if(ten <= six && ten <= fif)
{
ans2.push_back(ten);
ten += 10;
}
else
{
ans2.push_back(fif);
fif += 15;
}
sortLower(ans2);
if (ans2[ans2.size() - 1] == ans2[ans2.size() - 2])
ans2.pop_back();
}
sortLower(ans2);
forll(i,0,ans2.size())
out_(ans2[i]);
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll x,y,a,b;
void solve()
{
ll ans = 0;
while(x<y && x<=(b/(a-1))){
x*=a;
ans++;
}
if(x>=y){
cout<<ans-1<<'\n';
return;
}
ans+=(y-x)/b;
if((y-x)%b == 0) ans--;
cout<<ans<<'\n';
}
int main()
{
cin >> x >> y >> a >> b;
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
ll x, y, a, b;
cin >> x >> y >> a >> b;
// a 倍 x -> ax dif = (a - 1) * x
// y / x
ll res = 0;
while (1) {
if (a > y / x + 10) break;
if ((a - 1) * x <= b) x *= a;
else break;
if (x >= y) break;
res++;
}
if (x < y) res += (y - x - 1) / b;
cout << res << endl;
return 0;
} |
#include<bits/stdc++.h>
#define rep(i,n) for (int i =0; i <(n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;
const ll MOD = 1000000007;
int main(){
ll S , P ;
cin >> S >> P;
// M = S - Nを代入して N*(S-N) = Pをルートまで
for(ll i = 0; i*i <= P; i++){
if(i* (S-i) == P){
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using ll = long long;
using lint = long long;
typedef vector<long long> vint;
typedef pair<long long, long long> pint;
#define MD 1000000007
#define INF INT32_MAX / 2
#define INF64 INT64_MAX / 2
#define EPS 0.001
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define c(n) cout<<n<<endl;
#define cf(n) cout<<fixed<<setprecision(15)<<n<<endl;
template <class T>inline bool chmin(T&a,T b) {if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T&a,T b) {if(a<b){a=b;return true;}return false;}
template<class T>inline T sum(T n){return n*(n+1)/2;}
map<ll,ll> prime_fac(ll A) {map<ll,ll>mp;for(ll i=2;i*i<=A;i++){while(A%i== 0){mp[i]++;A/=i;}}if(A!=1){mp[A]=1;}return mp;}
bool is_prime(ll N){if(N<=1)return false;for(ll i=2;i*i<=N;i++){if(N%i==0) return false;}return true;}
template<class T>inline T myceil(T a,T b){return (a+(b-1))/b;}
bool is_product_overflow(long long a,long long b) {long prod=a*b;return (prod/b!=a);}
const string YES = "Yes";
const string NO = "No";
void solve(long long S, long long P){
auto map = prime_fac(P);
vint vec;
ll sum = 1;
for (auto m : map) {
REP (i, m.second) {
vec.push_back(m.first);
sum *= m.first;
}
}
ll size = vec.size();
for (int bit = 0; bit < (1 << size); bit++) {
ll cur = 1;
ll sm = sum;
for (int i = 0; i < size; i++) {
if (bit & (1 << i)) {
cur *= vec[i];
sm /= vec[i];
}
}
if (cur + sm == S) {
c(YES)
return;
}
}
c(NO)
}
int main(){
long long S;
scanf("%lld",&S);
long long P;
scanf("%lld",&P);
solve(S, P);
return 0;
}
|
#include<bits/stdc++.h>
#define int long long
#define zmrl(x) (int)((x).size())
#define ahen(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using pii = pair<int,int>;
const int N = 10000000000LL;
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n; cin>>n;
char A[200200]; cin>>(A+1);
int res = 0;
bool yes = true;
int cur = 0;
int th = 1;
for (int i=1; i<=n&&yes; i++) {
if (!cur) {
if (A[i]=='1') {
cur=1;
}
else yes=false;
}
else if (cur==1) {
if (A[i]=='1') {
cur=2;
}
else yes=false;
}
else {
if (A[i]=='0') {
cur=0;
if (i<n) th++;
}
else yes=false;
}
}
if (yes) {
res += N-th+1;
}
cur = 1;
yes = true;
for (int i=1; i<=n&&yes; i++) {
if (!cur) {
if (A[i]=='1') {
cur=1;
}
else yes=false;
}
else if (cur==1) {
if (A[i]=='1') {
cur=2;
}
else yes=false;
}
else {
if (A[i]=='0') {
cur=0;
if (i<n) th++;
}
else yes=false;
}
}
if (yes) {
res += N-th+1;
}
cur = 2;
yes = true;
for (int i=1; i<=n&&yes; i++) {
if (!cur) {
if (A[i]=='1') {
cur=1;
}
else yes=false;
}
else if (cur==1) {
if (A[i]=='1') {
cur=2;
}
else yes=false;
}
else {
if (A[i]=='0') {
cur=0;
if (i<n) th++;
}
else yes=false;
}
}
if (yes) {
res += N-th+1;
}
cout<<res<<'\n';
return 0;
} | #include <bits/stdc++.h>
// clang-format off
using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18;
void print0() {}
template<typename H,typename... T> void print0(H h,T... t){cout<<fixed<<setprecision(15)<<h;print0(t...);}
void print() { print0("\n"); }
template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);}
void ioinit() { cout << fixed << setprecision(15); ios_base::sync_with_stdio(0); cin.tie(0); }
// clang-format on
int main() {
string s;
cin >> s;
ll ans = 0;
for (ll i = 0; i <= 9999; i++) {
string t = to_string(i);
vector<bool> exist(10);
for (auto c : t) {
ll n = c - '0';
exist[n] = true;
}
if (i < 1000) {
exist[0] = true;
}
bool ok = true;
for (ll d = 0; d <= 9; d++) {
if (s[d] == 'o' && !exist[d]) ok = false;
if (s[d] == 'x' && exist[d]) ok = false;
}
if (ok) {
ans++;
}
}
print(ans);
}
|
#include <bits/stdc++.h>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
inline int read()
{
int data = 0, w = 1; char ch = getchar();
while (ch != '-' && !std::isdigit(ch)) ch = std::getchar();
if (ch == '-') w = -1, ch = std::getchar();
while (std::isdigit(ch)) data = data * 10 + (ch ^ 48), ch = std::getchar();
return data * w;
}
const int N(3e5 + 10);
int n;
long long s[N], ans;
std::map<long long, int> c;
int main()
{
#ifndef ONLINE_JUDGE
file(cpp);
#endif
n = read(), c[0] = 1;
for (int i = 1, x; i <= n; i++)
x = read(), (i & 1) ? s[i] = s[i - 1] - x : s[i] = s[i - 1] + x;
for (int i = 1; i <= n; i++) ans += c[s[i]]++;
printf("%lld\n", ans);
return 0;
}
| #include"bits/stdc++.h"
using namespace std;
#define pb push_back
#define eb emplace_back
#define ins insert
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define pii pair<int,int>
#define fir first
#define sec second
#define popcount __builtin_popcount
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")a
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using ll=long long int;
using ld=long double;
#define mp make_pair
#define mt make_tuple
#define bit(x,j) (((ll)x>>j)&1)
#define um unordered_map
#define mem(a,val) memset(a,val,sizeof(a))
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x){cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(ld x){cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x){cerr<<'\"'<<x<<'\"';}
void __print(const string &x) {cerr<<'\"'<<x<<'\"';}
void __print(bool x){cerr<<(x?"true":"false");}
template<typename T, typename V>
void __print(const pair<T, V> &x){cerr<<'{'; __print(x.first);cerr<<','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{ return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{ return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
cerr << " " << to_string(H);
debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#ifndef ONLINE_JUDGE
#define debugt(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debugt(...) 42
#endif
constexpr ll inf=2223372036854775807;
constexpr int mod1=(1e9+7);
constexpr int mod2=(998244353);
constexpr int MAX=(1e4+3);
constexpr int N=2e5+5;
void solve()
{
int n; cin>>n; vector<int>a(n);
for(int i=0;i<=n-1;i++) cin>>a[i];
ll ans=0; vector<ll>ps(n,0);
for(int i=0;i<=n-1;i++)
{
if(i) ps[i]=ps[i-1];
if(i&1) ps[i]+=a[i]; else ps[i]-=a[i];
}
map<ll,int>g;
for(int i=0;i<=n-1;i++)
{
if(!ps[i]) ans++;
ans+=g[ps[i]]; g[ps[i]]++;
}
cout<<ans<<"\n";
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int t=1; int c=1;
while(t--)
{
solve(); c++;
}
} |
#include<bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define All(x) (x).begin(),(x).end()
#define mp make_pair
#define nl "\n"
typedef pair<int,int>ii;
typedef vector<int>vi;
typedef vector<ii>vii;
typedef vector<vi>vvi;
typedef vector<long long>vl;
typedef vector <vl>vvl;
template<class T>
void print(T& a)
{
for(auto x:a)
cout<<x<<" ";
cout<<"\n";
}
int main()
{
FastIO
ll n,q,k; cin>>n>>q;
ll a[n],c[n];
for(int i=0; i<n; i++)
{
cin>>a[i];
if(i==0)c[i]=a[i]-1;
else c[i]=c[i-1]+a[i]-a[i-1]-1;
}
while(q--)
{
cin>>k;
int m,l=0,r=n-1;
if(k>c[n-1])
{
cout<<a[n-1]+k-c[n-1]<<nl;
continue;
}
while(l<r)
{
m=(l+r)/2;
if(c[m]<k)l=m+1;
else r=m;
}
if(l==0)cout<<k<<nl;
else cout<<a[l-1]+k-c[l-1]<<nl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define prin(a) cout<<a<<"\n"
#define kaigyo cout<<"\n"
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define mem(x) memset(x,0,sizeof(x))
#define mem1(x) memset(x,-1,sizeof(x))
const int INF=1<<28;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<string> vst;
typedef vector<char> vc;
typedef vector<long double> vd;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
typedef vector<vector<int>> vint2;
ll mod=1e9+7;
#define int1(x) int x;cin>>x;
#define int2(x,y) int x,y;cin>>x>>y;
#define int3(x,y,z) int x,y,z;cin>>x>>y>>z;
#define int4(x,y,z,w) int x,y,z,w;cin>>x>>y>>z>>w;
#define ll1(x) ll x;cin>>x;
#define ll2(x,y) ll x,y;cin>>x>>y;
#define vint1(a,n) vint a(n);rep(i,n)cin>>a[i];
#define vint2(a,b,n) vint a(n),b(n);rep(i,n)cin>>a[i]>>b[i];
#define vll1(a,n) vll a(n);rep(i,n)cin>>a[i];
const double pi=acos(-1.0);
const ll infl=1LL<<60;
bool isPrime(ll n){if(n<2)return false;for(ll x = 2;
x*x <=n;x++){if(n%x == 0)return false;}return true;}
ll kaizyo(ll k){ll sum=1;rep1(i,k){sum*=i;sum%=mod;}return sum;}
ll ncr(ll n,ll r){return kaizyo(n)/(kaizyo(r)*kaizyo(n-r));}
unsigned keta(unsigned num){
return log10(num)+1;
}
ll gcd(ll a, ll b) {
if (b==0) return a;
else return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
return a * b / gcd(a, b);
}
int main(){
cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
int2(n,q);
ll a[n];
rep(i,n)cin>>a[i];
ll k[q];
rep(i,q)cin>>k[i];
ll b[n];
rep(i,n)b[i]=a[i]-(i+1);
rep(i,q){
auto iter=lower_bound(b,b+n,k[i])-b;
cout<<((iter==n)?a[n-1]+k[i]-b[n-1]:a[iter]-(b[iter]-k[i]+1))<<endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
typedef vector<long long> VL;
int main()
{
long long K, N, M, A, B, count;
cin >> K >> N >> M;
count = M;
priority_queue <VL> pque;
VL now;
for (int i = 0; i < K; i++)
{
cin >> A;
B = A*M;
B /= N;
count -= B;
pque.push(VL{A*M-B*N,B,i});
}
vector<long long> ans(K);
while(!pque.empty())
{
now = pque.top();
pque.pop();
if (count > 0)
{
now.at(1)++;
count--;
}
ans.at(now.at(2)) = now.at(1);
}
for (auto x : ans)
cout << x << " ";
cout << endl;
}
| #include <bits/stdc++.h>
#define rep3(i, s, n, a) for (long long i = (s); i < (long long)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ld = long double;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
int main() {
ll k, n, m;
cin >> k >> n >> m;
vector<ll> a(k);
a.resize(k, 0);
for(auto &x: a) cin >> x;
ll l = -1, r = (ll)1e18+1;
// cout << -7074 / 10006 << endl;
while(r-l>1){
ll mid = (l+r) / 2LL;
// cout << mid << endl;
ll lsum = 0LL, rsum = 0LL;
bool ok = true;
rep(i, k){
ll tmpr = (mid + a[i]*m) / n, tmpl = a[i]*m - mid;
rsum += tmpr;
if((a[i]*m-mid)%n){
if(tmpl < 0){
tmpl /= n;
tmpl--;
}else{
tmpl /= n;
}
lsum += max(0LL, tmpl + 1LL);
}else{
if(tmpl < 0){
tmpl /= n;
tmpl--;
}else{
tmpl /= n;
}
lsum += max(0LL, tmpl);
}
// cout << lsum << " " << rsum << endl;
}
if(!ok){
l = mid;
}
if(lsum <= m && m <= rsum){
r = mid;
}else{
l = mid;
}
}
ll upper = r;
// cout << upper << endl;
vector<ll> llim(k, 0), rlim(k, 0);
ll mrem = m;
rep(i, k){
rlim[i] = (upper + a[i]*m) / n;
ll tmpl = a[i]*m - upper;
if((a[i]*m-upper)%n){
if(tmpl < 0){
tmpl /= n;
tmpl--;
}else{
tmpl /= n;
}
llim[i] = max(0LL, tmpl + 1LL);
}else{
if(tmpl < 0){
tmpl /= n;
tmpl--;
}else{
tmpl /= n;
}
llim[i] = max(0LL, tmpl);
}
// if((a[i]*m-upper)%n){
// llim[i] = max(0LL, (a[i]*m - upper) / n + 1LL);
// }else{
// llim[i] = max(0LL, (a[i]*m - upper) / n);
// }
mrem -= llim[i];
}
rep(i, k){
ll out = min(rlim[i], mrem+llim[i]);
cout << out << " ";
mrem -= out - llim[i];
}
return 0;
} |
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main () {
std::ios::sync_with_stdio(false); std::cin.tie(0);
long double inx, iny, inr;
cin >> inx >> iny >> inr;
long double x = inx + 200005, y = iny + 200005, r = inr;
long long ans = 0;
for (long double p = ceil(x - r); p <= floor(x + r); p += 1) {
long double d = x - p;
long double h = sqrtl(r * r - d * d);
long long top = floor(y + h);
long long bottom = ceil(y - h);
ans += top - bottom + 1;
}
cout << ans << endl;
}
| #pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << '(' << p.first << ',' << p.second << ')';
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << '{';
for(int i = 0; i < (int)v.size(); i++) {
if(i) { os << ','; }
os << v[i];
}
os << '}';
return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
cerr << " " << x;
debugg(args...);
}
#define debug(...) \
cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 4020000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
if(a>b){
a = b; return true;
}
else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
if(a<b){
a = b; return true;
}
else return false;
}
template<typename T> inline void print(T &a){
int sz = a.size();
for(auto itr = a.begin(); itr != a.end(); itr++){
cout << *itr;
sz--;
if(sz) cout << " ";
}
cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;
int main(){
string X,Y,R; cin >> X >> Y >> R;
ll x,y,r; //cin >> x >> y >> r;
auto f = [](string s) -> ll{
int cnt = 4;
ll res = 0;
bool f = false;
for(auto c : s){
cnt -= f;
if(c == '-') continue;
if(c != '.') res = res * 10 + c - '0';
else f = true;
}
rep(i,cnt) res *= 10;
if(s[0] == '-') res = -res;
return res;
};
x = f(X);
y = f(Y);
r = f(R);
x += 2000000000LL;
ll ans = 0;
for(ll i=-2000000000; i<=2000000000; i+=10000){
if(y-r > i || y+r < i) continue;
ll d = abs(y-i);
ll ok = 0, ng = r+1;
while(ng-ok > 1){
ll mid = (ok+ng) / 2;
if(mid*mid <= r*r-d*d) ok = mid;
else ng = mid;
}
//debug(x,ok);
ll p = (x-ok+9999) / 10000;
ll q = (x+ok) / 10000;
//debug(i,p,q);
ans += q-p+1;
}
cout << ans << "\n";
} |
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
const int N = 1e6 + 50;
int k;
int res[10], mul[6];
char s[10], t[10];
int cal(char *s){
int num[10], val = 0;
for(int i = 1; i <= 9; ++i) num[i] = 0;
for(int i = 1; i <= 5; ++i) ++num[s[i] - '0'];
for(int i = 1; i <= 9; ++i) val += mul[num[i]] * i;
return val;
}
int main(){
scanf("%d%s%s", &k, s + 1, t + 1);
mul[0] = 1;
for(int i = 1; i <= 5; ++i) mul[i] = mul[i - 1] * 10;
for(int i = 1; i <= 9; ++i) res[i] = k;
for(int i = 1; i <= 5; ++i){
--res[s[i] - '0'];
--res[t[i] - '0'];
}
int ret = 9 * k - 8;
double ans = 0;
for(int i = 1; i <= 9; ++i)
for(int j = 1; j <= 9; ++j){
if((i == j && res[i] < 2) || res[i] < 1 || res[j] < 1) continue;
int zz = 0;
if(i == j) zz = 1;
s[5] = '0' + i, t[5] = '0' + j;
if(cal(s) > cal(t)){
ans += 1.0 * res[i] / ret * (res[j] - zz) / (ret - 1);
}
}
printf("%lf", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(void){
int k;
cin >> k;
int a[10];
for(int i=1;i<=9;i++) a[i] = k;
string s,t;
cin >> s >> t;
int b[10]={},c[10]={};
for(auto i:s){
if(i!='#'){
a[i-'0']--;
b[i-'0']++;
}
}
for(auto i:t){
if(i!='#'){
a[i-'0']--;
c[i-'0']++;
}
}
double ans = 0;
for(int s=1;s<=9;s++){
if(a[s]==0) continue;
b[s]++;
double d1 = double(a[s])/double(9*k-8);
a[s]--;
for(int j=1;j<=9;j++){
long pt=0,pa=0;
if(a[j]==0) continue;
c[j]++;
double d2 = double(a[j])/double(9*k-9);
a[j]--;
rep(i,10) pt += i*pow(10,b[i]);
rep(i,10) pa += i*pow(10,c[i]);
if(pt>pa) ans += d1*d2;
c[j]--;
a[j]++;
}
a[s]++;
b[s]--;
}
cout <<fixed << setprecision(10) << ans << endl;
}
|
//Bismillahir Rahmanir Raheem
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
#define fi first
#define se second
#define PI 3.14159265
#define mod 11092019
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
///order_of_key find_by_order
const ll INFLL = 1e18;
const ll INF =1e9;
const ll EPS =1e-9;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll lcm(ll a,ll b){ return (a*b)/gcd(a,b);}
ll ncr(ll n,ll r){ ll ans=1;for(ll i=1;i<=r;i++) ans=(ans*(n-i+1))/i;return ans;}
ll cost[2005][2005],vis[2005],n,m;
vector<ll> v[2005];
ll dijsktra(int s)
{
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > pq;
vector<int> dis(n+1,INF);
pq.push({0,s}); // distance from source node,node number
dis[s]=0;
ll ans=INT_MAX;
while(!pq.empty())
{
int num=pq.top().se;
int num_d=pq.top().fi;
pq.pop();
if(num_d!=dis[num]) continue;
for(int i=0;i<v[num].size();i++)
{
if(num_d+cost[num][v[num][i]]<dis[v[num][i]])
{
dis[v[num][i]]=num_d+cost[num][v[num][i]];
pq.push({dis[v[num][i]],v[num][i]});
}
if(v[num][i]==s) ans=min(ans,num_d+cost[num][v[num][i]]);
}
}
if(ans==INT_MAX) return -1;
else return ans;
}
int main()
{
cin>>n>>m;
for(int i=0;i<m;i++)
{
ll x,y,w;
cin>>x>>y>>w;
if(cost[x][y]==0)
cost[x][y]=w;
else
cost[x][y]=min(w,cost[x][y]);
v[x].push_back(y);
}
for(int j=1;j<=n;j++)
{
cout<<dijsktra(j)<<endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define rep(i,n) for (ll i = 0;i<(n);++i)
#define all(v) v.begin(),v.end()
template <typename T>bool chmax(T &a, const T& b) {if (a < b) {a = b;return true;}return false;}
template <typename T>bool chmin(T &a, const T& b) {if (a > b) {a = b;return true;}return false;}
vector<long long> divisor(long long n){vector<long long> res;long long i = 1;while (i*i<=n){if(n%i==0){res.push_back(i);}i++;}if(res.size()==0)return res;for(long long i = res.size()-1-(res.back()*res.back()==n);i>=0;--i){res.push_back(n/res[i]);}return res;}
long long safe_mod(long long x,long long m){x%=m;if(x<0){x+=m;}return x;}
long long modpow(long long x,long long n,long long mod){long long ans=1;while(n>0){if(n&1){ans*=x;ans%=mod;}n>>=1;x*=x;x%=mod;}return ans;}
long long intpow(long long x,long long n){long long ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;}
vector<pair<long long,long long>> factor_lst(long long n){vector<pair<long long,long long>> factor_lst;long long d=2;while(d*d<=n){if(n%d==0){long long num=0;while(n%d==0){num+=1;n/=d;}factor_lst.push_back({d,num});}d+=1;}if(n!=1){factor_lst.push_back({n,1});}return factor_lst;}
int msb(int x){return x==0 ? -1:32-__builtin_clz(x);}//1-indexed
int lsb(int x){return x==0 ? 32:__builtin_ctz(x)+1;}//1-indexed
int popcnt(int x){return __builtin_popcount(x);}
const ll LINF=4*1e18;
const ll MINF=5*1e15;
const int INF=2*1e9;
template<class T>
class Heap{
vector<T> v;
int _size;
function<bool(T,T)> f;
int par(int x){return (x-1)>>1;}
int lch(int x){return (x<<1)+1;}
int rch(int x){return (x<<1)+2;}
void downheapify(int i){
while(1){
int lchid=lch(i),rchid=rch(i);
int smallest=i;
if(lchid<_size&&f(v[lchid],v[smallest]))smallest=lchid;
if(rchid<_size&&f(v[rchid],v[smallest]))smallest=rchid;
if(smallest!=i){
T temp=v[smallest];
v[smallest]=v[i];
v[i]=temp;
i=smallest;
}
else break;
}
}
void upheapify(int i){
T x =v[i];
while(1){
if(i==0)break;
int parid=par(i);
if(f(x,v[parid])){v[i]=v[parid];}
else break;
i=parid;
}
v[i]=x;
}
public:
Heap(function<bool(T,T)> _f):v(vector<T>()),_size(0),f(_f){}
bool empty(){return _size==0;}
T top(){return v[0];}
T pop(){
T res=v[0];
--_size;
v[0]=v[_size];
v.pop_back();
downheapify(0);
return res;
}
void push(T x){
v.push_back(x);
upheapify(_size);
++_size;
}
vector<T>& get_heap(){return v;}
};
void Main();
int main(){cout<<fixed<<setprecision(15);Main();}
void Main(){
int N,M;
cin>>N>>M;
vector<vector<pair<int,int>>> G(N);
rep(i,M){
int A,B,C;
cin>>A>>B>>C;
A--;B--;
G[A].push_back({B,C});
}
int ans[N];
rep(i,N){
Heap<pair<int,int>> heap([](pair<int,int> p1,pair<int,int> p2){return p1.second<p2.second;});
ans[i]=INF;
int dist[N];
rep(j,N)dist[j]=INF;
dist[i]=0;
heap.push({i,0});
while(!heap.empty()){
auto p=heap.pop();
int v=p.first;
int now=p.second;
for(auto edge:G[v]){
int nv=edge.first;
int len=edge.second;
int next=now+len;
if(nv==i){
chmin(ans[i],next);
}
if(next<dist[nv]){
dist[nv]=next;
heap.push({nv,next});
}
}
}
}
rep(i,N){
if(ans[i]==INF)cout<<-1<<endl;
else cout<<ans[i]<<endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); ++i)
ll INF = 1ll << 60;
ll t[8][8];
int main(){
int n, k;
cin >> n >> k;
rep(i, 0, n){
rep(j, 0, n){
cin >> t[i][j];
}
}
vi index(0);
rep(i, 0, n)
index.push_back(i);
ll cnt = 0;
do{
ll sum = 0;
rep(i, 0, n){
sum += t[index[i]][index[(i+1)%n]];
}
if(sum == k)
cnt++;
}while(next_permutation(index.begin()+1, index.end()));
cout << cnt << endl;
return 0;
} | #include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<climits>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
int n, m;
cin >> n >> m;
vector<int> a(m); //青色のマスの場所(初期値1)
rep(i,m) cin >> a[i]; //青色のマスへの入力
if(m==0){
cout << 1 << endl; //全て白マスの場合
}else{
sort(a.begin(), a.end()); //昇順にソート
int val = INT_MAX;
/*白マスの最小値を求める*/
if(a[0]-1 > 0) val = min(val, a[0]-1); //左端と青色のマスとの間の白マスの数を求める
rep(i,m-1){
//青色のマスと青色のマスとの間の白マスの数を求める
if(a[i+1]-a[i]-1 > 0) val = min(val, a[i+1]-a[i]-1);
}
if(n-a[m-1] > 0) val = min(val, n-a[m-1]); //青色のマスと右端との間の白マスの数を求める
/*塗りつぶす回数を求める*/
if(val == INT_MAX) cout << 0 << endl; //全てのマスが青色のマスの場合の塗りつぶす回数
else{
int sum;
if((a[0]-1)%val==0) sum=(a[0]-1)/val;
else sum=(a[0]-1)/val+1;
rep(i,m-1){
if((a[i+1]-a[i]-1)%val==0) sum+=(a[i+1]-a[i]-1)/val;
else sum+=(a[i+1]-a[i]-1)/val+1;
}
if((n-a[m-1])%val==0) sum+=(n-a[m-1])/val;
else sum+=(n-a[m-1])/val+1;
cout << sum << endl;
}
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
long long l;
cin >> l;
long long result = 1;
int a;
for (int i = 1; i < 12; i++)
{
a = l - i;
result *= a;
result /= i;
}
cout << result << endl;
return 0;
}
| #include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<set>
#include<cstdlib>
#include<cmath>
#include<numeric>//fill
#include<iomanip>
#include<functional>//https://cpprefjp.github.io/reference/functional/function.html
#include<cstdlib>//https://cpprefjp.github.io/reference/cstdlib.html
#include<queue>
#include<deque>
#include<cassert>
#include<stack>
#include <iterator> // std::back_inserter
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
const double PI = acos(-1);
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n)for(ll i=0;i<(n);i++)
#define repp(x,arr) for(auto& x:arr)
#define repp2(x,y,arr) for(auto& [x,y]:arr)
#define all(a) (a.begin()),(a.end())
const ll MOD = 1e9 + 7;
const ll inf = 1e18+6;
// デフォルトは整数部も含めた桁数指定
//cout <<setprecision();
ll myPow(ll x, ll n, ll m) {
if (n == 0)
return 1;
if (n % 2 == 0)
return myPow(x * x % m, n / 2, m);
else
return x * myPow(x, n - 1, m) % m;
}
int main() {
ios::sync_with_stdio(false);
double N;
cin >> N;
if ((int)(N * 1.08) < 206)cout << "Yay!";
else if ((int)(N * 1.08) == 206)cout << "so-so";
else cout << ":( ";
}
|
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <random>
#include <chrono>
/* #include <atcoder/all> */
/* using namespace atcoder; */
using namespace std;
void debug_out(){ cout << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cout << H << " ";
debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
/* const ll MOD = 998244353; */
const ll INF = 1ll<<60;
const double PI = acos(-1);
struct INIT { INIT(){
cin.tie(0); ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
}}INIT;
signed main() {
int ans = -1;
int N, X;
cin >> N >> X;
X *= 100;
int now = 0;
REP(i, N){
int v, p;
cin >> v >> p;
now += v*p;
if(now > X){
cout << i+1 << "\n";
return 0;
}
}
cout << ans << "\n";
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define EPS (1e-7)
// string->num
// stoll(str)
// num->string
// to_string(i)
int main() {
ll H, W;
cin >> H >> W;
vector<vector<ll>> A(H, vector<ll>(W - 1));
vector<vector<ll>> B(H - 1, vector<ll>(W));
for (ll i = 0; i < H; i++) {
for (ll j = 0; j < W - 1; j++) {
cin >> A[i][j];
}
}
for (ll i = 0; i < H - 1; i++) {
for (ll j = 0; j < W; j++) {
cin >> B[i][j];
}
}
const ll INF = 1e10;
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<>> q;
vector<ll> dist(H * W, INF);
auto push = [&](ll i, ll j, ll cost) {
ll node = i * W + j;
if (dist[node] > cost) {
dist[node] = cost;
q.emplace(cost, node);
}
};
push(0, 0, 0);
while (!q.empty()) {
auto [cost, node] = q.top();
q.pop();
if (dist[node] != cost) continue;
ll i = node / W;
ll j = node % W;
if (j + 1 < W) push(i, j + 1, cost + A[i][j]);
if (j - 1 >= 0) push(i, j - 1, cost + A[i][j - 1]);
if (i + 1 < H) push(i + 1, j, cost + B[i][j]);
for (ll k = 0; k < i; k++) {
push(k, j, cost + (i - k) + 1);
}
}
cout << dist.back() << endl;
return 0;
}
|
#include <cstdio>
int main(){
int a[4];
for(int i=0; i < 4;i++){
scanf("%d", &a[i]);
}
int min_a = a[0];
for(int i = 1; i < 4; i++)
if(a[i] < min_a)
min_a = a[i];
printf("%d\n", min_a);
} | #include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;
int main(){
lll ii,jj,kk;
vector<int> ret;
string s;
cin >> s;
cout << s[1] << s[2] << s[0] << endl;
return 0;
}
|
/*
ID: omohamadooo
TASK: barn1
LANG: C++
*/
/*
___ ___ ___ ___ ___ ___ ___ _____ ___ ___ ___
/ /\ /__/\ / /\ /__/\ / /\ /__/\ / /\ / /::\ / /\ / /\ / /\
/ /::\ | |::\ / /::\ \ \:\ / /::\ | |::\ / /::\ / /:/\:\ / /::\ / /::\ / /::\
/ /:/\:\ | |:|:\ / /:/\:\ \__\:\ / /:/\:\ | |:|:\ / /:/\:\ / /:/ \:\ / /:/\:\ / /:/\:\ / /:/\:\
/ /:/ \:\ __|__|:|\:\ / /:/ \:\ ___ / /::\ / /:/~/::\ __|__|:|\:\ / /:/~/::\ /__/:/ \__\:| / /:/ \:\ / /:/ \:\ / /:/ \:\
/__/:/ \__\:\ /__/::::| \:\ /__/:/ \__\:\ /__/\ /:/\:\ /__/:/ /:/\:\ /__/::::| \:\ /__/:/ /:/\:\ \ \:\ / /:/ /__/:/ \__\:\ /__/:/ \__\:\ /__/:/ \__\:\
\ \:\ / /:/ \ \:\~~\__\/ \ \:\ / /:/ \ \:\/:/__\/ \ \:\/:/__\/ \ \:\~~\__\/ \ \:\/:/__\/ \ \:\ /:/ \ \:\ / /:/ \ \:\ / /:/ \ \:\ / /:/
\ \:\ /:/ \ \:\ \ \:\ /:/ \ \::/ \ \::/ \ \:\ \ \::/ \ \:\/:/ \ \:\ /:/ \ \:\ /:/ \ \:\ /:/
\ \:\/:/ \ \:\ \ \:\/:/ \ \:\ \ \:\ \ \:\ \ \:\ \ \::/ \ \:\/:/ \ \:\/:/ \ \:\/:/
\ \::/ \ \:\ \ \::/ \ \:\ \ \:\ \ \:\ \ \:\ \__\/ \ \::/ \ \::/ \ \::/
\__\/ \__\/ \__\/ \__\/ \__\/ \__\/ \__\/ \__\/ \__\/ \__\/
*/
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\n'
#define pii pair<ll,ll>
#define F first
#define S second
using namespace std;
const int MOD=1e9+7;
const int N=1000100;
long long po(ll x,ll y)
{
ll ans=1;
while(y){
if(y & 1) ans=(ans*x);//%MOD;
y/=2;
x=(x*x);//%MOD;
}
return ans;
}
ll n;
void solve()
{
ll ans=1e18;
cin>>n;
for(ll i=0;i<70;i++){
if(po(2,i)>n)
break;
ll b=n/po(2,i);
ans=min(ans,i+b+(n-(po(2,i)*b)));
}
cout<<ans<<endl;
}
int main()
{
//ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//freopen("hopscotch.in","r",stdin);freopen("hopscotch.out","w",stdout);
int t=1;
//cin>>t;
while(t--){
solve();
}
}
| #include <iostream>
#include <vector>
#include <complex>
using namespace std;
using C = complex<double>;
C rotate(C center, C vec, double rad) {
C r = {cos(rad), sin(rad)};
return center + (vec-center) * r;
}
int main() {
int N; cin >> N;
double x, y;
cin >> x >> y;
C s = {x, y};
cin >> x >> y;
C t = {x, y};
C center = (s+t)/2.0;
double pi = acos(-1);
double rad = 2*pi/N;
auto res = rotate(center, s, rad);
printf("%.10f %.10f\n", res.real(), res.imag());
} |
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
// #include<atcoder/all>
// using namespace atcoder;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define reve(i,n) for(int i=n-1;i>=0;i--)
#define vec(a,n) vector<long long> a(n,0);
#define ALL(a) (a).begin(),(a).end()
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef int long long ll;
using namespace std;
typedef pair<ll,ll> P;
typedef priority_queue<ll> PQ;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int dx8[8]={1,0,-1,0,1,1,-1,-1};
int dy8[8]={0,1,0,-1,1,-1,1,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// vector<int> a(51,0);
// vector<vector<int> > tate(a,vector<int>(b)) ;
ll spp(ll cnt,ll dis , ll r){
if (dis%r == 0 && dis >= r ){
cnt = dis/r;
return cnt;
}
else if(2*r >= dis ){
cnt += 2;
return cnt;
}
else{
cnt = spp(cnt+1,dis-r,r);
}
return cnt;
}
int main(){
ll r,x,y; cin >> r >> x >> y;
double dis = sqrt(x*x+y*y);
ll cnt = 0;
// else if(dis < r){
// cnt = 2;
// }
// else{
// cnt = spp(cnt,dis,r);
// }
cnt = ceil(double(dis/r));
if(dis < r) cnt = 2;
if(x == 0 && y == 0){
cnt = 0;
}
cout << cnt << endl;
return 0;
}
| #include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
int main() {
long long int R;
long long int X;
long long int Y;
cin >> R >> X >> Y;
double Z;
Z = sqrt(X*X + Y*Y);
if(Z==R){
cout << 1 << endl;
}
else if(Z<2*R){
cout << 2 << endl;
}
else{
cout << ceil(Z/R) << endl;
}
} |
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define LD long double
#define ST string
#define BS bitset
#define PA pair<LL,LL>
#define VE vector
#define VL VE<LL>
#define VP VE<PA>
#define VVL VE<VL>
#define VVVL VE<VVL>
#define PQ priority_queue
#define PQS priority_queue<LL,vector<LL>,greater<LL>>
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define BPL __builtin_popcountll
#define FOR(i,a,n) for(i=a;i<n;++i)
#define FORR(i,a,n) for(i=n-1;i>=a;--i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) FORR(i,0,n)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define UBn(a,n) upper_bound(ALL(a),n)-a.begin()
#define LB(a,n) *lower_bound(ALL(a),n)
#define LBn(a,n) lower_bound(ALL(a),n)-a.begin()
#define INF 1000000000000000003
#define PI 3.14159265358979323846264338327950288
//#define MOD 1000000007
#define MOD 998244353
#define ERR 1e-10
#define coutl cout<<fixed<<setprecision(15)
#define FAST cin.tie(0);ios::sync_with_stdio(false)
void Yn(LL a){if(a)cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void YN(LL a){if(a)cout<<"YES"<<endl;else cout<<"NO"<<endl;}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL dig(LL n){LL ret=0;while(n)n/=10,++ret;return ret;}
LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
LL cmod(LL a,LL m){if(a%m<0)return a%m+abs(m);else return a%m;}
LL DIV(LL a,LL d,LL m){LL l=m,x=1,y=0,k;while(l){k=d/l;d-=k*l;swap(l,d);x-=k*y;swap(x,y);}return cmod(a*cmod(x,m),m);}
LL POW(LL a,LL n,LL m){LL ans=1;while(n>0){if(n&1)ans=ans*a%m;a=a*a%m;n>>=1;}return ans;}
VL fact,finv,inv;
void comi(LL n){LL i;fact.resize(max(2LL,n+1));finv.resize(max(2LL,n+1));inv.resize(max(2LL,n+1));fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[0]=inv[1]=1;FOR(i,2,n+1){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
bool cmps(PA a,PA b){if(a.SE!=b.SE)return a.SE<b.SE;return a.FI<b.FI;}
template<typename T>bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>void vout(VE<T> &v){LL i;rep(i,v.size()){cout<<v[i];if(i<v.size()-1)cout<<" ";}cout<<endl;}
template<typename T>void v2out(VE<VE<T>> &v){for(auto a:v)vout(a);}
int main(){
FAST;
LL i,j,b,ans=0,N,M,K,a;
cin>>N>>M;
VL A(M),B(M);
rep(i,M){
cin>>A[i]>>B[i];
--A[i],--B[i];
}
cin>>K;
VL C(K),D(K);
rep(i,K){
cin>>C[i]>>D[i];
--C[i],--D[i];
}
rep(b,1<<K){
a=0;
VL v(N);
rep(i,K){
if((1<<i)&b)++v[C[i]];
else ++v[D[i]];
}
rep(i,M)if(v[A[i]]&&v[B[i]])++a;
chmax(ans,a);
}
cout<<ans<<endl;
}
| #include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define pb emplace_back
#define MP make_pair
using namespace std;
using ll = long long;
using ii = pair<int,int>;
const int maxn = 1000 + 5;
const int maxk = 16 + 5;
int G[maxn][maxn] = {};
int a[maxk][2];
int seq[maxk];
map<int,int> mp;
int ans = 0;
void dfs(int N, int ith){
if(ith == N){
int tmp = 0;
vector<int> v;
for(auto p : mp){
if(p.second != 0) v.pb(p.first);
}
for(int i = 0; i < SZ(v); i++){
for(int j = i+1; j < SZ(v); j++){
if(G[v[i]][v[j]]){
// printf("[%d][%d], += %d\n", v[i], v[j], G[v[i]][v[j]]);
tmp += G[v[i]][v[j]];
}
}
}
// printf("%d\n", tmp);
ans = max(ans, tmp);
return;
}
for(int i = 0; i < 2; i++){
mp[a[ith][i]]++;
dfs(N, ith+1);
mp[a[ith][i]]--;
}
}
void solve(){
int N, M;
cin >> N >> M;
for(int i = 0; i < M; i++){
int a, b;
cin >> a >> b;
G[a][b]++;
G[b][a]++;
}
int K;
cin >> K;
for(int i = 0; i < K; i++){
cin >> a[i][0] >> a[i][1];
}
dfs(K, 0);
cout << ans << '\n';
}
int main(){
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ll n;
cin >> n;
ll sum = 0;
for(ll i = 1; i <= 1000000; ++i){
sum += i;
if(sum >= n){
cout << i << endl;
return 0;
}
}
return 0;
}
| #pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
using vpi = vector<pair<int, int>>;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define all(v) (v).begin(), (v).end()
#define ar array
#define PB push_back
#define sz(x) (int)(x).size()
template <typename T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v)
{
os << '{';
string sep;
for (const T &x : v)
os << sep << x, sep = ", ";
return os << '}';
}
void dbg_out()
{
cerr << endl;
}
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
cerr << ' ' << H;
dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
struct custom_hash
{
static uint64_t splitmix64(uint64_t x)
{
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const
{
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7; //998244353
void solve()
{
ll n;
cin >> n;
ll l = 1, r = 1e6, ans = 0;
while(l<=r){
ll m = l+(r-l)/2;
if (m*(m+1)/2>=n){
ans = m;
r = m-1;
}else l = m+1;
}
cout << ans << "\n";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int testcase=1;
//cin >> testcase;
while (testcase--)
{
solve();
}
} |
/*
after dusk passed,
there is a starry sky.
*/
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
using namespace std;
const int N=4*1e5+100;
int n,a[N];
char s[N];
inline int read()
{
int f=1,x=0;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
return x*f;
}
inline int cal(int n,int m)
{
if (m>n) return 0;
int ans=1;
for (int i=1;i<=m;i++) ans=ans*(n-i+1)/i;
return ans;
}
int C(int n,int m)
{
if (n<3&&m<3) return cal(n,m);
return C(n/3,m/3)*cal(n%3,m%3)%3;
}
signed main()
{
n=read();
scanf("%s",s+1);
for (int i=1;i<=n;i++)
{
if (s[i]=='B') a[i]=0;
if (s[i]=='R') a[i]=1;
if (s[i]=='W') a[i]=2;
}
int ans=0;
for (int i=1;i<=n;i++) ans=(ans+a[i]*C(n-1,i-1)%3)%3;
if (n%2==0) ans=3-ans;
ans%=3;
if (ans==0) printf("B\n");
if (ans==1) printf("R\n");
if (ans==2) printf("W\n");
}
| #include<iostream>
using namespace std;
typedef long long ll;
int main()
{
int n,i;
ll res=0,x=0,y=1,t;//(n-1)ci=3^x*(3*z+y)
string s,tm="BWR";
cin >> n >> s;
for(i=0;i<n;i++){
if(x==0){
if(s[i]=='W')
res+=y;
else if(s[i]=='R')
res+=y*2;
}
res%=3;
if(i==n-1)
break;
t=n-1-i;
while(t%3==0){
t/=3;
x++;
}
y=(y*t)%3;
t=i+1;
while(t%3==0){
t/=3;
x--;
}
y=(y*t)%3;
}
if(n%2==0)
res=(3-res)%3;
cout << tm[res] << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()
typedef long long ll;
#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)
#define fi first
#define se second
const int N = 1e5+10;
double dp[N];
int main(){
ios::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
for(int i = 1; i<n; i++){
dp[i] = (double)((n-i)*(1+dp[i-1])+i)/(n-i);
}
cout << fixed << setprecision(10) << dp[n-1] << "\n";
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
double check(double d, vector<double>& A) {
double val=0;
for(auto& e:A) val+=(d+e-min(e,2*d))/A.size();
return val;
}
int main() {
ll N; cin>>N;
vector<double> A(N);
for(auto& e:A) cin>>e;
// 三分探索かなあ
double low=0, high=1e10;
ll cnt=1000;
while(cnt--) {
double d1=(low*2+high)/3;
double d2=(low+high*2)/3;
if(check(d1,A)>check(d2,A)) low=d1;
else high=d2;
}
cout<<fixed<<setprecision(20)<<check(low,A)<<endl;
}
|
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef std::vector<int> VI;
typedef long long ll;
typedef std::pair<int, int> ii;
template <class C> C& mini(C& a, C b) { if (b < a) a = b; return a; }
template <class C> C& maxi(C& a, C b) { if (a < b) a = b; return a; }
template <typename T> void read(std::vector<T>& A) { for (T& x: A) std::cin >> x; }
template <typename T> void readv(std::vector<T>& A) { int N; std::cin >> N; A.resize(N); read(A); }
using namespace std;
int solve(const string& S) {
if (S[0] != S.back())
return 1;
for (int i = 1; i + 1 < S.length(); i++) {
if (S[i] != S[0] && S[i+1] != S[0])
return 2;
}
return -1;
}
int main(int argc, const char* argv[]) {
ios_base::sync_with_stdio(0); cin.tie(0); cout.precision(20); cout.setf(ios::fixed);
int N;
string S;
cin >> N >> S;
cout << solve(S) << endl;
return 0;
}
| #include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0ll)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define init() \
cin.tie(0); \
ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v) \
cerr << "[debugV] " << #v << ":"; \
rep(z, v.size()) cerr << " " << v[z]; \
cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;
template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
rep(j, v.size()) i >> v[j];
return i;
}
template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
return i >> v.first >> v.second;
}
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
return to_string(x).size();
}
ll gcd(ll x, ll y) {
return y ? gcd(y, x % y) : x;
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
template <class T>
void chmax(T& a, const T& b) {
if (a < b) a = b;
}
template <class T>
void chmin(T& a, const T& b) {
if (b < a) a = b;
}
signed main() {
init();
ll N;
string S;
cin >> N >> S;
if (S[0] != S[N - 1]) {
COUT(1);
return 0;
}
bool ok = false;
char c = S[0];
rep2(i, 1, N - 1) {
if (S[i] != c and S[i + 1] != c) ok = true;
}
if (ok) {
COUT(2);
} else {
COUT(-1);
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define debug(a) { cerr << #a << ':' << a << endl; }
#define endl '\n'
#define fi first
#define se second
using lint = long long;
using P = pair<int,int>;
template<class T> using V = vector<T>;
template<class T> using priq = priority_queue<T>;
template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
template<class T> T ceil(const T &a, const T &b) { return (a+b-1)/b; }
template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;
template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) {
return in >> p.first >> p.second;
}
template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) {
return out << p.first << ' ' << p.second;
}
template<class T> istream& operator>>(istream &in, vector<T> &v) {
for(auto &&e: v) in >> e;
return in;
}
template<class T> ostream& operator<<(ostream &out, const vector<T> &v) {
for(const auto &e: v) out << e << ' ';
return out;
}
/*----------------------------------------------------------------------------------------------------*/
int main() {
int n, m;
cin >> n >> m;
V<V<P>> ps(n+1);
rep(i,m) {
int x, y, z;
cin >> x >> y >> z;
ps[x].emplace_back(y,z);
}
V<lint> dp(1<<n);
dp[0] = 1;
rep(s,1<<n) {
int x = __builtin_popcount(s);
for(P p: ps[x]) {
int s2 = s&((1<<p.fi)-1);
int cnt = __builtin_popcount(s2);
if(cnt > p.se) dp[s] = 0;
}
rep(i,n) {
if(~s>>i&1) dp[s|1<<i] += dp[s];
}
}
cout << dp[(1<<n)-1] << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
vector<int> X;
vector<vector<pair<int,int>>> B;
ll fact[20];
ll memo[18][1<<18];
bool visited[18][1<<18];
ll f(int p, int q) {
if (p == (int)X.size()-1) return fact[N-X.back()];
if (visited[p][q]) return memo[p][q];
visited[p][q] = true;
int mask = ((1<<N)-1)^q;
int c = X[p+1]-X[p];
ll res = 0;
for (int m = mask; m > 0; m = (m-1)&mask) if (__builtin_popcount(m) == c) {
for (auto [y, z] : B[p]) {
if (__builtin_popcount((q|m)&((1<<y)-1)) > z) goto next;
}
res += f(p+1, q|m);
next:;
}
return memo[p][q] = res * fact[c];
}
int main() {
fact[0] = 1;
for (int i = 1; i < 20; ++ i) fact[i] = fact[i-1] * i;
int M;
cin >> N >> M;
map<int, vector<pair<int,int>>> A;
for (int i = 0; i < M; ++ i) {
int x, y, z;
cin >> x >> y >> z;
A[x].push_back({y,z});
}
X.push_back(0);
for (auto& x : A) {
X.push_back(x.first);
B.push_back(x.second);
}
cout << f(0, 0) << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+7;
bitset<N> pos;
long long a[N];
long long upto[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin>>n>>q;
for (int i=1; i<=n; i++) {
cin>>a[i];
upto[i] = a[i] - i;
}
while (q--) {
long long z;
cin>>z;
int id = lower_bound(upto, upto+n+1, z) - upto - 1;
assert(upto[id] <= z);
cout<<a[id] + z - upto[id]<<endl;
}
}
| #include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
int t =min(a,b);
a=max(a,b);
b =t;
while(a%b!=0)
{
int temp =b;
b=a%b;
a=temp;
}
return b;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,q;
cin>>n>>q;
vector<long long >a(n);
for(int i =0; i<n;i++)
{
cin>>a[i];
}
sort(a.begin(),a.end());
unordered_map<long long int,long long int>mp;
// unordered_map<long long int,long long int>dc;
for(int i =0; i<q;i++)
{
long long k;
cin>>k;
if(mp.find(k)!=mp.end())
{
cout<<mp[k]<<'\n';
}
else
{
int id =int(upper_bound(a.begin(),a.end(),k)-a.begin());
if(id ==0)
{
mp[k]=k;
cout<<k<<"\n";
}else
{
if(id ==n)
{
mp[k]=k+id;
cout<<k+id<<'\n';
}
else
{
while(id<n&&(k+id) >=a[id])
{
id++;
// mp[k+id] =k;
}
mp[k]=k+id;
cout<<k+id<<'\n';;
}
}
}
}
return 0;
} |
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <functional>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <bitset>
#include <cassert>
#include <math.h>
#include <complex>
#include <iomanip>
#include <unordered_map>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#ifdef _OLIMPOLOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1337
#endif
void debug_out() { cout << "\n";}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cout << " " << A; debug_out(B...); }
int test = 1;
#define out(x) {cout << x << "\n";return;}
#define all(N) N.begin(),N.end()
#define allr(N) N.rbegin(),N.rend()
template<typename T1>
void pr(vector<T1> V, int add = 0, int start = -1, int end = -1) {
if (start < 0) start = 0;
if (end < 0) end = V.size() - 1;
for (int i = start; i <= end; i++) {
cout << V[i] + add << ((i == end) ? "\n" : " ");
}
}
template<typename T1>
T1 chmin(T1 &x, const T1 v) { return x = min(x,v); }
template<typename T1>
T1 chmax(T1 &x, const T1 v) { return x = max(x,v); }
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define repsr(i, s, n) for (int i = n-1; i >= s; i--)
#define PI pair<int,int>
//-------------------------- ^ DONT TOUCH ^-----------------------------------------------------------------
#define MAX 50001
#define MOD 1000000007
ll gcd(ll a, ll b) {
if (a == 0 || b == 0) return a+b;
return gcd(b, a % b);
}
ll mult(ll a, ll b, ll m) {
ll x = a;
ll s = 0;
while (b != 0) {
if (b % 2 == 1) s = (s + x) % m;
b /= 2;
x = (x + x) % m;
}
return s;
}
ll gcdExtended(ll a, ll b, ll *x, ll *y, ll mod)
{
if (a == 0)
{
*x = 0;
*y = 1;
return b;
}
ll x1, y1; // To store results of recursive call
ll gcd = gcdExtended(b%a, a, &x1, &y1, mod);
// Update x and y using results of
// recursive call
*x = y1 - (b/a) * x1;
*y = x1;
return gcd;
}
ll minT(ll t1 ,ll m1, ll t2, ll m2) {
if(t1 == t2) return t1;
if (t1 > t2) {
swap(t1,t2);
swap(m1,m2);
}
ll k1, k2;
ll g = gcd(m1,m2);
ll t = t2 - t1;
if (t % g != 0) return LLONG_MAX;
ll g2 = m2 / g;
gcdExtended(m1, m2, &k1, &k2, g2);
//k1 = (((k1 % g2) + g2) % g2);
k1 *= t / g;
k2 *= t / g;
ll lcm = m1 * g2;
ll v1 = ((mult(k1,m1, lcm) + t1) % lcm + lcm) % lcm;
//if (k1 < 0 || k2 < 0) return LLONG_MAX;
if (v1 % m1 != t1) {
while(1) {}
}
return v1;
}
ll x, y, p, q;
void solve() {
cin >> x >> y >> p >> q;
ll m1 = (x + y) * 2;
ll m2 = p + q;
ll b = LLONG_MAX;
rep(i, y) rep(j, q) {
ll t1 = x + i;
ll t2 = p + j;
ll bb = minT(t1, m1, t2, m2);
if (bb == LLONG_MAX) continue;
//if(bb % m1 == t1 && bb % m2 == t2) {
chmin(b, bb);
//}
}
if (b == LLONG_MAX) {
out("infinity");
}
out(b);
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);
int test = 1;
// #ifdef _OLIMPOLOCAL
cin >> test;
// #endif
rep(testCase, test) {
#ifdef _OLIMPOLOCAL
cout << "------------------ TESTCASE: " << testCase << " -------------\n";
#endif
solve();
}
return 0;
} | //Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define For(i,n) for(int i=0;i<n;i++)
#define Forn(i,n) for(int i=1;i<=n;i++)
#define Fors(i,s) for(int i=0;i<s.size();i++)
#define all(v) v.begin(),v.end()
#define sum(v) accumulate(all(v),0)
#define gcd(a, b) __gcd(a , b)
#define lcm(a,b) (a*(b/__gcd(a,b)))
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define Max(a) *max_element(a,a+sizeof(a)/sizeof(a[0]))
#define Min(a) *min_element(a,a+sizeof(a)/sizeof(a[0]))
#define End return 0
#define gt greater<int>()
#define ll long long
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define mod 1e9+7 //1000000007
#define sp(n) fixed<<setprecision(n)
#define YES printf("YES\n")
#define NO printf("NO\n")
#define Erase(s) s.erase(unique(s.begin(),s.end()),s.end())
//%%%%%%%%%%%%%p%%%a%%%r%%%v%%%e%%%z%%%%%%%%%%%%%//
int main()
{
MP;
//int T;cin >> T;while (T--)
{
int n, m, sm = 0, sm1 = 0;
cin >> n >> m;
if (n <= m) {
for (int i = 1; i <= m; i++) {
cout << -i << " ";
sm += i;
}
for (int i = 1; i < n; i++) {
cout << i << " ";
sm1 += i;
}
cout << sm - sm1;
}
else {
for (int i = 1; i <= n; i++) {
cout << i << " ";
sm += i;
}
for (int i = 1; i < m; i++) {
cout << -i << " ";
sm1 += i;
}
cout << sm1 - sm;
}
}
cerr<<endl<<(float)clock()/(float)CLOCKS_PER_SEC<<" sec"<<endl;
End;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
int64_t gcdExtended(int64_t a, int64_t b, int64_t* x, int64_t* y) {
if (a == 0) {
*x = 0, *y = 1;
return b;
}
int64_t x1, y1;
int64_t gcd = gcdExtended(b % a, a, &x1, &y1);
*x = y1 - (b / a) * x1;
*y = x1;
return gcd;
}
int64_t modInverse(int64_t a) {
int64_t x, y;
gcdExtended(a, MOD, &x, &y);
return (x % MOD + MOD) % MOD;
}
int addmod(int x, int y) {
int result = x+y;
if (result >= MOD) {
result -= MOD;
}
return result;
}
int multmod(int x, int y) {
return (x * int64_t(y)) % MOD;
}
int addmodto(int& x, int y) {
x += y;
if (x >= MOD) {
x -= MOD;
}
return x;
}
int solve_slow(int N, int M, int K) {
vector<vector<int>> dp(N+M+1, vector<int>(N+1, 0));
dp[0][0] = 1;
for (int i = 1; i <= N+M; ++i) {
for (int j = 0; j <= i; ++j) {
if (j <= (i-j+K)) {
dp[i][j] = dp[i-1][j];
if (j > 0) {
addmodto(dp[i][j], dp[i-1][j-1]);
}
}
}
}
return dp[N+M][N];
}
const int MAXVAL = 2e6;
int factorial[MAXVAL+1];
int choose(int n, int k) {
if (n < k) {
return 0;
}
return multmod(factorial[n], modInverse(multmod(factorial[n-k], factorial[k])));
}
int solve(int N, int M, int K) {
if (N > (M+K)) {
return 0;
}
return addmod(choose(N+M, N), MOD - choose(M+N, M+K+1));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
factorial[0] = 1;
for (int i = 1; i <= MAXVAL; ++i) {
factorial[i] = multmod(factorial[i-1], i);
}
int N, M, K;
cin >> N >> M >> K;
cout << solve(N, M, K) << endl;
}
| // execute g++ main.cpp -std=c++14 -I C:\Users\naoya\Desktop\code\Atcoder
#include<bits/stdc++.h>
//#include<atcoder/all>
typedef long long ll;
typedef long double ld;
using namespace std;
//using namespace atcoder;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
//ordered_set 重複不可
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// use set_function + find_by_order(select itr-num)
#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}
char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
char Alpha[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
//cout << std::fixed << std::setprecision(15) << y << endl; //小数表示
const ll MAX = 3000000; //テーブルの数
const ll MOD = 1e9+7; //mod宣言
long long fac[MAX], finv[MAX], inv[MAX];
// finv ->階乗割り算
// fac ->階乗掛け算
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;
}
int main(){
COMinit();
ll n, m, k; cin >> n >> m >> k;
if(n > m + k){
cout << 0 << endl;
return 0;
}
ll mid = 0;
cout << (COM(n+m, n) + MOD - COM(n+m, m+k+1)) % MOD << endl;
} |
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>
#include <math.h>
using namespace std;
////using Graph = vector<vector<int>>;
//using Graph = vector<vector<int>>;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> P;
//container util
//------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n) for(int i=0; i<(n); i++)
//constant
//--------------------------------------------
const double PI = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7;
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
if(x == 0) return 0;
return counter_1(x >> 1) + (x & 1);
}*/
//int Counter(int x)
/*int factorial(int n) {
if (n > 0) {
return n * factorial(n - 1);
} else {
return 1;
}
}*/
/*int factorial(int n) {
if (n > 0) {
return n * factorial(n - 1);
} else {
return 1;
}
}
LL sum(LL a, LL b){
LL cnt=0;
cnt=(b-a+1)*(a+b)/2;
return cnt;
}
LL yaku(int x){
vector<pair<LL, LL> a=[];
LL xh;
if(x==1){
pair<LL, LL> tmp;
tmp=MP(1,1);
return tmp;
}
else{
FOR(i, 1, x/2+1){
if(x%i==0){
a.append(MP(i,x/i));
}
}
}
return a;
}*/
LL cul(int a, int b){
LL f = pow(a,4)+pow(a,3)*b+pow(a,2)*pow(b,2)+a*pow(b,3)+pow(b,4);
return f;
}
//using Graph = vector<vector<int>>;
//int H, W;
/*vector<tuple<int,int,int> G;
VI color;
bool dfs(const VVI &G, int v, int iro = 0) {
color[v]=0// v を訪問済にする
for(auto next_v : G[v]){
if(color[next_v] != -1){
if
}
dfs(nh, nw, cnt); // 再帰的に探索
}
}*/
int main(){
char s,t;
cin >> s;
cin >> t;
if(s=='Y'){
t-=32;
}
cout << t <<endl;
}
| #include "bits/stdc++.h"
using namespace std;
// 定義
typedef long long ll;
typedef pair<ll, ll> P;
#define ALL(x) (x).begin(),(x).end()
#define REP(i, n) for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n) for(ll i = m ; i < (ll)n ; ++i)
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define INF (ll)2e9
#define INF_LL 1LL<<60
//#define MOD 998244353
#define MOD 1000000007
ll Ceil(ll val, ll div) { return (val + div - 1) / div; }
ll CeilN(ll val, ll div) { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n) { return (x - x % n); }
bool IsOdd(ll x) { return ((x & 1) == 1); }
bool IsEven(ll x) { return ((x & 1) == 0); }
// dfs
ll ansOne = 0;
vector<vector<int>> G;
vector<bool> isUsed;
void dfs(int from, int to)
{
ansOne++;
for (auto nextTo : G[to]) {
if (from != nextTo) {
if (!isUsed[nextTo]) {
isUsed[nextTo] = true;
dfs(to, nextTo);
}
}
}
}
// 処理
void Solve()
{
ll N, M;
cin >> N >> M;
G.clear();
G.resize(N);
REP(i, M) {
ll a, b;
cin >> a >> b;
a--; b--;
G[a].emplace_back(b);
}
int ans = 0;
REP(i, N) {
isUsed.clear();
isUsed.resize(N, false);
isUsed[i] = true;
ansOne = 0;
dfs(-1, i);
ans += ansOne;
}
cout << ans << endl;
}
// メイン
int main()
{
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Solve();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int check(int n,int base)
{
int flag=0;
while(n!=0)
{
int rem=(n%base);
if(rem==7)
{
flag=1;
break;
}
n/=base;
}
return flag;
}
int main()
{
int n;
cin>>n;
char a[32];
string b;
int count=0;
for(int i=1;i<=n;i++)
{
if(check(i,8)==0&&check(i,10)==0)
count++;
}
cout<<count;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()
typedef long long ll;
#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)
#define fi first
#define se second
bool not7(ll x, ll b){
while(x){
if(x%b==7) return 0;
x/=b;
}
return 1;
}
bool ok(int x){
return not7(x,8) and not7(x,10);
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
ll ans = 0;
for(int i = 1; i<=n; i++) if(ok(i)) ans++;
cout << ans << "\n";
} |
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long int;
int N;
const int MAXN=205;
int A[MAXN];
bool dp[MAXN][MAXN][MAXN];
int ans[MAXN][MAXN][MAXN];
bool dp2[MAXN][MAXN];
int ans2[MAXN][MAXN];
int main(){
scanf("%d",&N);
for(int i=1;i<=N;i++)
scanf("%d",A+i);
dp2[0][0]=true;
for(int i=0;i<N;i++){
for(int j=0;j<200;j++){
if (!dp2[i][j]) continue;
int v=A[i+1]%200;
dp2[i+1][j]=true;
dp2[i+1][(j+v)%200]=true;
ans2[i+1][(j+v)%200]=1;
}
}
vector<int> x,y;
int curv=0;
for(int i=N;i>0;i--){
if (ans2[i][curv]==1){
x.push_back(i);
curv=(curv+200-(A[i]%200))%200;
}else x.push_back(i),y.push_back(i);
}
if (x.size()!=y.size()&&y.size()!=0&&x.size()!=0){
puts("Yes");
printf("%d ",(int)x.size());
while(!x.empty()) printf("%d ",x.back()),x.pop_back();
putchar('\n');
printf("%d ",(int)y.size());
while(!y.empty()) printf("%d ",y.back()),y.pop_back();
putchar('\n');
return 0;
}
dp[0][0][0]=true;
for(int i=0;i<N;i++){
for(int j=0;j<200;j++){
for(int k=0;k<200;k++){
const auto& cur=dp[i][j][k];
if (!cur) continue;
int v=A[i+1]%200;
if (!dp[i+1][j][k]){
dp[i+1][j][k]=true;
ans[i+1][j][k]=0;
// printf("%d %d\n",j,k);
}
if (!dp[i+1][(j+v)%200][k]||ans[i][j][k]!=1||ans[i+1][(j+v)%200][k]==0){
dp[i+1][(j+v)%200][k]=true;
ans[i+1][(j+v)%200][k]=1;
// printf("%d %d\n",(j+v)%200,k);
}
if (!dp[i+1][j][(k+v)%200]||ans[i][j][k]!=2||ans[i+1][j][(k+v)%200]==0){
dp[i+1][j][(k+v)%200]=true;
ans[i+1][j][(k+v)%200]=2;
// printf("%d %d\n",j,(k+v)%200);
}
}
}
}
vector<int> X,Y;
int ANS=0;
for(int i=199;i>=0;i--){
if (dp[N][i][i]){
// printf("i=%d\n",i);
int a=i,b=i;
ANS=i;
for(int i=N;i>0;i--){
// printf("a=%d b=%d\n",a,b);
// printf("ans=%d\n",ans[i][a][b]);
int v=A[i]%200;
if (ans[i][a][b]==1){
X.push_back(i);
a=(a+200-v)%200;
}else if (ans[i][a][b]==2){
Y.push_back(i);
b=(b+200-v)%200;
}
}
break;
}
}
// printf("%d %d\n",(int)X.size(),(int)Y.size());
if (X.size()!=0&&Y.size()!=0){
puts("Yes");
printf("%d ",(int)X.size());
while(!X.empty()) printf("%d ",X.back()),X.pop_back();
putchar('\n');
printf("%d ",(int)Y.size());
while(!Y.empty()) printf("%d ",Y.back()),Y.pop_back();
putchar('\n');
}
// }else if (ANS==0&&(X.size()+Y.size())!=N&&(X.size()+Y.size())!=0){
// puts("Yes");
// for(int i=1;i<=N;i++)
// if (find(X.begin(),X.end(),i)==X.end()&&find(Y.begin(),Y.end(),i)==Y.end()){
// X.push_back(i),Y.push_back(i);
// }
// sort(X.begin(),X.end());
// sort(Y.begin(),Y.end());
// printf("%d ",(int)X.size());
// while(!X.empty()) printf("%d ",X.back()),X.pop_back();
// putchar('\n');
// printf("%d ",(int)Y.size());
// while(!Y.empty()) printf("%d ",Y.back()),Y.pop_back();
// putchar('\n');
// }
else puts("No");
return 0;
} | #pragma region head
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
template <class T>
inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess {
preprocess() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
} ____;
#pragma endregion head
#pragma region library
#pragma endregion library
int main() {
int n;
cin >> n;
string s, t;
cin >> s >> t;
ll ans = 0;
int er = -1;
queue<int> wait;
int cnt = 0;
rep(i, n) {
if (s[i] == '1') cnt++;
if (t[i] == '1') cnt--;
}
if (cnt < 0 || cnt % 2) {
cout << -1 << '\n';
return 0;
}
rep(i, n) {
if (er != -1) {
if (t[i] == '1') {
wait.push(i);
}
if (s[i] == '1') {
ans += i - er;
er = -1;
}
} else {
if (t[i] == '1') {
wait.push(i);
}
if (s[i] == '1') {
if (wait.empty()) {
er = i;
} else {
ans += i - wait.front();
wait.pop();
}
}
}
}
if (er != -1 || !wait.empty()) {
cout << -1 << '\n';
} else {
cout << ans << '\n';
}
}
|
#include <iostream>
#include<string>
using namespace std;
int main() {
string S;
cin >> S;
bool unreadable = true;;
int s = S.length();
for(int i = 0;i < s;i++) {
if(i%2==0){
if(!islower(S[i])){
unreadable=false;
}
}else{
if(!isupper(S[i])){
unreadable=false;
}
}
}
if(unreadable) {
cout << "Yes";
}
else{
cout << "No";
}
return 0;
} | #include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <random>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#include <unordered_map>
#include <iomanip>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define pi 3.141592653589793
#define prique priority_queue
constexpr auto mod=1000000007;
constexpr auto MOD=1000000000000000;
using namespace std;
int gcd(int a,int b){
if(b==0) return a;
return gcd(b,a%b);
}
int lcm(int a,int b){
return a*b/gcd(a,b);
}
bool prime(int n){
int cnt=0;
for(int i=1;i<=sqrt(n);i++){
if(n%1==0)cnt++;
}
if(cnt!=1) return false;
else return n!=1;
}
void syou(int a,double b){
cout<<setprecision(a)<<b<<endl;
}
void Ye(){
cout<<"Yes"<<endl;
}
void No(){
cout<<"No"<<endl;
}
void YE(){
cout<<"YES"<<endl;
}
void NO(){
cout<<"NO"<<endl;
}
struct UnionFind{
vector<int> r;
UnionFind(int N){
r=vector<int>(N,-1);
}
int root(int x){
if(r[x]<0) return x;
return r[x]=root(r[x]);
}
bool unite(int x,int y){
x=root(x);
y=root(y);
if(x==y) return false;
if(r[x]>r[y]) swap(x,y);
r[x]+=r[y];
r[y]=x;
return true;
}
int size(int x){
return -r[root(x)];
}
};
struct Edge{
int to;
int weight;
};
struct fenwick_tree {
typedef int T;
T n;
vector<T> bit;
fenwick_tree(T num) : bit(num+1, 0) { n = num; }
void add(T i, T w) {
for (T x = i; x <= n; x += x & -x) {
bit[x] += w;
}
}
T sum(T i) {
T ret = 0;
for (T x = i; x > 0; x -= x & -x) {
ret += bit[x];
}
return ret;
}
T sum(T left, T right) {
return sum(right) - sum(left);
}
};
bool flag;
int n,m,cnt=0,ans=0,aa[330000];
pair<int,int> pp[220000];
string s,sa,ss[220000];
queue<int> que;
vector<int> v;
signed main(){
cin>>s;
rep(i,s.size()){
if(i%2==0&&s[i]<='Z'){
cout<<"No"<<endl;
return 0;
}elif(i%2==1&&s[i]>='a'){
cout<<"No"<<endl;
return 0;
}
}
cout<<"Yes"<<endl;
} |
#include "bits/stdc++.h"
using namespace std;
int main(){
long long ans = 0;
long long N;
cin >> N;
long long A[N], B[N], C[N];
for(int i = 0; i < N; i++){
cin >> A[i];
A[i]--;
}
for(int i = 0; i < N; i++){
cin >> B[i];
B[i]--;
}
for(int i = 0; i < N; i++){
cin >> C[i];
C[i]--;
}
long long A_num[N] = {0};
for(int i = 0; i < N; i++){
A_num[A[i]]++;
}
long long C_num[N] = {0};
for(int i = 0; i < N; i++){
C_num[C[i]]++;
}
for(int i = 0; i < N; i++){
if(C_num[i] != 0){
ans += (C_num[i] * A_num[B[i]]);
}
}
cout << ans << endl;
}
| #include<bits/stdc++.h>
using namespace std;
// GCC Optimizations
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
//MACROS
#define ll long long
//to be excluded in critical cases(thanks to @Amank2854) https://codeforces.com/contest/1538/submission/119014768
#define int ll
#define endl "\n"
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define umap unordered_map
#define all(v) v.begin() , v.end()
#define min3(a1,b1,cost) min(a1,min(b1,cost))
#define min4(a1,b1,cost,d ) min(a1 , min(b1 , min(cost,d)))
#define max3(a1,b1,cost) max(a1 , max(b1,cost))
#define max4(a1,b1,cost,d) max(max(a1,b1) , max(cost,d))
#define vecti vector<int>
#define ld long double
#define debug(a) cout<<a<<endl;
#define debugtwo(a1,b1) cout<<a1<<" "<<b1<<endl;
#define pq priority_queue
#define pii pair<int,int>
#define frq(NN) for(int UUU=0;UUU<(NN);UUU++)
#define minvec *min_element
#define maxvec *max_element
#define fori(II,GG,HH) for(int II=(GG);II<(HH);II++)
#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl;
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define rep(RRR,FFF) for(auto &RRR:FFF)
#define sz(AA) (int)((AA).size())
#define minus cout<<"-1\n";
#define zero cout<<"0\n";
#define print(x) cout<<(x)<<endl;
#define read(FDFDFDF) for(auto &FFFF:FDFDFDF){cin>>FFFF;}
// Array utils
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
int comb(int n, int r)
{if(r<0||r>n)return 0;if((n-r)<r)r=n-r; // nCr
int a=1;for(int i=n;i>n-r;--i){a=a*i;}for(int i=1;i<r+1;++i){a=a/i;}return a;}
// Bitwise operations
int Set(int qq , int pos){return (qq|(1<<pos));}
int chk(int qq , int pos){return (qq&(1<<pos));}
int p2(int idx){return ((1LL<<idx));};
// Maths//Modular exponential
int modpow(int x, int n, int m)
{
if (n == 0) return 1%m;
int u = modpow(x,n/2,m);
u = (u*u)%m;
if (n%2 == 1) u = (u*x)%m;
return u;
}
int gcd(int a,int b) //gcd function
{
if(b==0)
return a;
else return gcd(b,a%b);
}
int _pow(int a, int b)
{
if(!b)return 1;
ll temp = _pow(a, b/2);
temp = (temp * temp);
if(b%2)return (a * temp);
return temp;
}
int ceil(int a, int b){if(a%b)return 1 + a/b;return a/b;}
void printvec(const vecti &AAA)
{
for(auto SDDD:AAA)cout<<SDDD<<" ";
cout<<endl;
}
int dx[] = {0 , 0 , -1 , 1};
int dy[] = {1 , -1 , 0 , 0};
const int MOD = 1e9 + 7;
const int N = 1e5+10;
const int inf = 1e18;
struct DSU
{
vecti PAR;
DSU(int NN)
{
PAR = vecti(NN+1,-1);
}
int getpar(int x) { return PAR[x] < 0 ? x : PAR[x] = getpar(PAR[x]); }
bool samepar(int a, int b) { return getpar(a) == getpar(b); }
int rank(int x) {return -PAR[getpar(x)]; }
bool unite(int x, int y) { // union by rank
x = getpar(x), y = getpar(y); if (x == y) return 0;
if (PAR[x] > PAR[y]) swap(x,y);
PAR[x] += PAR[y]; PAR[y] = x; return 1;
}
};
void solve()
{
int n;cin>>n;
vecti a(n);read(a);
DSU stt=DSU(2e5+10);
for(int i=0;i<n/2;i++)
{
if(a[i]==a[n-i-1])continue;
stt.unite(a[i],a[n-i-1]);
}
int sum=0;
for(int i=1;i<=2e5+10;i++)
{
if(stt.getpar(i)==i)
{
sum+=(stt.rank(i)-1);
}
}
cout<<sum<<endl;
}
signed main()
{
IOS
int TESTS=1;
// cin>>TESTS;
int GOOOGLE=1;
while(TESTS--)
{
// cout<<"Case #"<<GOOOGLE<<": ";
solve();
// cout<<flush;
GOOOGLE++;
}
} |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
cout<<2*a+100-b<<endl;
} | #pragma region head
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll,ll>;
template <class T> using vv = vector<vector<T>>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
#define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL<<(n))
template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess{preprocess()
{cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head
#pragma region library
#pragma endregion library
int main(){
int a, b; cin >> a >> b;
int ans = max(0,2*a+100-b);
cout << ans << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
for (in_vec_cout res : vec) {cout << res << " ";}
cout << endl;
}
const ll inf = 1e18;
const ll mod = 1e9 + 7;
ll N;
vector<pair<ld,ld>> P;
ld dist[110][110];
map<ld,bool> rad;
void init() {
cin >> N;
rep(i,N) {
ld x, y; cin >> x >> y;
P.push_back({x,y});
}
rep(i,N) {
rep(j,N) {
if (i==j) continue;
ld from_x = P[i].first, from_y = P[i].second;
ld to_x = P[j].first, to_y = P[j].second;
ld dx = to_x - from_x, dy = to_y - from_y;
dist[i][j] = sqrt(dx*dx+dy*dy);
}
dist[i][N] = dist[N][i] = (ld)100 - P[i].second;
dist[i][N+1] = dist[N+1][i] = P[i].second + (ld)100;
}
dist[N][N+1] = dist[N+1][N] = 200.0;
rep(i,N+2) rep(j,N+2) {
rad[dist[i][j]*0.5] = true;
}
rad[100.0] = true;
}
bool judge(ld r) {
ld d = (ld)2*r;
vector<vector<ll>> G(N+2);
rep(i,N+2) rep(j,N+2) {
if (dist[i][j]>=d) continue;
G[i].push_back(j);
}
queue<ll> que;
que.push(N);
vector<bool> seen(N+2);
seen[N] = true;
while (que.size()) {
ll x = que.front();
que.pop();
for (ll y : G[x]) {
if (seen[y]) continue;
seen[y] = true;
que.push(y);
}
}
return seen[N+1];
}
void solve() {
init();
ld ans = 0.0;
for (auto p : rad) {
ld r = p.first;
bool NG = judge(r);
if (NG) break;
ans = r;
}
cout << fixed << setprecision(10);
cout << ans << endl;
}
int main() {
solve();
} | #include <bits/stdc++.h>
using namespace std;
#define vt vector
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
using ll = long long;
using pii = pair<int, int>;
#define die return void(cout << "No")
#define die2 { pass = false; break; }
void solve() {
int n;
cin >> n;
vt<pii> a(n);
for (pii &x : a) cin >> x.fi >> x.se;
sort(all(a));
set<int> check;
for (int i = 0; i < n; i++) {
if (~a[i].fi && ~a[i].se && a[i].fi >= a[i].se) die;
if (~a[i].fi && check.count(a[i].fi)) die;
if (~a[i].se && check.count(a[i].se)) die;
check.insert(a[i].fi);
check.insert(a[i].se);
}
vt<bool> ok(n * 2 + 1);
vt<int> m1cnt(n * 2 + 1);
ok[0] = true;
for (int i = 0; i < n; i++) {
if (!~a[i].fi && !~a[i].se) m1cnt[0]++;
}
for (int i = 0; i < n * 2; i += 2) {
if (!ok[i]) continue;
for (int j = i + 2; j <= n * 2; j += 2) {
int jump = (j - i) / 2;
bool pass = true;
vt<bool> used(n * 2 + 1);
for (pii &x : a) {
if (~x.fi && ~x.se &&
i < x.fi && x.fi <= j &&
i < x.se && x.se <= j) {
if (x.se - x.fi != jump) die2;
if (x.fi > i + jump) die2;
if (x.se <= i + jump) die2;
if (used[x.fi]) die2;
used[x.fi] = true;
} else if (~x.fi && i < x.fi && x.fi <= j) {
if (x.fi > i + jump) die2;
if (used[x.fi]) die2;
used[x.fi] = true;
} else if (~x.se && i < x.se && x.se <= j) {
if (x.se <= i + jump) die2;
if (used[x.se - jump]) die2;
used[x.se - jump] = true;
}
}
if (pass) {
int r_cnt = jump;
for (int k = i + 1; k <= i + jump; k++) {
if (used[k]) r_cnt--;
}
if (m1cnt[i] >= r_cnt) {
m1cnt[j] = max(m1cnt[j], m1cnt[i] - r_cnt);
ok[j] = true;
}
}
}
}
if (ok.back()) cout << "Yes";
else cout << "No";
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int tcs = 1;
for (int tc = 1; tc <= tcs; tc++) {
// cout << "Case " << tc << ": ";
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
int k,p[200005];
vector<int> divk[200005];
long long ans;
int main() {
cin>>k;
for (int i=1; i<=sqrt(k); i++) {
for (int j=i; i*j<=k; j++) {
if (i!=j) p[i*j]+=2;
else p[i*j]++;
}
}
for (int i=1; i<=k; i++) {
for (int j=i; j<=k; j+=i) divk[j].push_back(i);
}
for (int i=1; i<=k; i++) {
for (int j=0; j<divk[i].size(); j++) {
int x=(i/divk[i][j]);
ans+=p[x];
}
}
cout<<ans<<'\n';
} | #include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("inp.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int n;
cin>>n;
if(n%100==0)
cout<<n/100;
else
cout<<(n/100)+1;
return 0;
} |
#include<bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
ll gi(){
ll x=0,f=1;
char ch=getchar();
while(!isdigit(ch))f^=ch=='-',ch=getchar();
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
int ret=1;
while(y){
if(y&1)ret=1ll*ret*x%mod;
x=1ll*x*x%mod;y>>=1;
}
return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
int main(){
#ifdef LOCAL
freopen("in.in","r",stdin);
//freopen("out.out","w",stdout);
#endif
int n=gi();
char caa,cab,cba,cbb;
caa=getchar();getchar();
cab=getchar();getchar();
cba=getchar();getchar();
cbb=getchar();getchar();
if(cab=='B'){
std::swap(caa,cbb);
caa=((caa-'A')^1)+'A';
cba=((cba-'A')^1)+'A';
cab=((cab-'A')^1)+'A';
}
if(caa=='A')puts("1");
else if(cba=='B')printf("%d\n",n==2?1:pow(2,n-3));
else{
int f[1010]={1,1};
for(int i=2;i<=n;++i)f[i]=(f[i-1]+f[i-2])%mod;
printf("%d\n",f[n-2]);
}
return 0;
}
| //yukicoder@cpp14
//coder:luckYrat(twitter:@luckYrat_)
//dijkstraから逃げるな
//おすすめの曲
//https://soundcloud.com/nagiha/alice-in-a-xxxxxxxx
//https://soundcloud.com/synthion/sweetheart
//せんげん!
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <cctype>
#include <utility>
#include <climits>
//なまえくーかん!
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
//てーすう!
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);
//でふぁいん!
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)
//みじかく!
#define pb push_back
#define mkp make_pair
#define fir first
#define scn second
#define ednl endl
//いぇすのー!
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")
//きんぼーnほーこー!!
P ar4[4] = {mkp(0,1),mkp(0,-1),mkp(1,0),mkp(-1,0)};
P ar8[8] = {mkp(-1,-1),mkp(-1,0),mkp(-1,1),mkp(0,-1),mkp(0,1),mkp(1,-1),mkp(1,0),mkp(1,1)};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
__attribute__((constructor))
void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int main(){
int a,b,c;cin>>a>>b>>c;
if(c%2){
if(a>b){
cout << ">" << endl;
}else if(a<b){
cout << "<" << endl;
}else{
cout << "=" << endl;
}
}else{
if(abs(a)==abs(b)){
cout << "=" << endl;
}else if(abs(a)>abs(b)){
cout << ">" << endl;
}else{
cout << "<" << endl;
}
}
return 0;
} |
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
#define all(v) v.begin(), v.end()
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, b) for (ll i = a; i < b; ++i)
#define rep_down(i, a, b) for (ll i = a; i > b; --i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
#define vvvvll vector<vector<vector<vector<ll>>>>
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define vvvvdo vector<vector<vector<vector<double>>>>
#define vvvdo vector<vector<vector<double>>>
#define vvdo vector<vector<double>>
#define vdo vector<double>
#define maze(S, H, W) vector<vector<char>> S(H, vector<char>(W))
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>
constexpr ll INF = (1ll << 60);
// constexpr ll mod = 998244353;
constexpr ll mod = 67280421310721;
// constexpr ll mod = 1e18+3;
// ll mod = 1000000007;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
if (a >= b) {
a = b;
return 1;
}
return 0;
}
template <typename T>
void pt(T val) {
cout << val << "\n";
}
template <typename T>
void pt_vll(vector<T> &v) {
ll vs = v.size();
rep(i, vs) {
cout << v[i];
if (i == vs - 1)
cout << "\n";
else
cout << " ";
}
}
template <typename T>
void pt_vvll(vector<vector<T>> &v) {
ll vs = v.size();
rep(i, vs) pt_vll(v[i]);
}
template <typename X, typename Y>
void pt_pair(pair<X, Y> val) {
cout << val.fi << " " << val.se << "\n";
}
template <typename X, typename Y>
void pt_vpair(vector<pair<X, Y>> &v) {
rep(i, v.size()) pt_pair(v[i]);
}
ll gcd(ll a, ll b) {
if (a % b == 0) return b;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
ll modpow(ll x, ll n) {
ll ret = 1;
if (x < 0) return 0ll;
while (n > 0) {
if (n & 1) ret = ret * x % mod;
x = x * x % mod;
n >>= 1;
}
return ret;
}
ll minv(ll a, ll m) { return modpow(a, m - 2); }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll t;
cin >> t;
while (t--) {
ll N;
cin >> N;
string s1, s2, s3;
cin >> s1 >> s2 >> s3;
string ans;
rep(i, N) ans.push_back('1');
rep(i, N) ans.push_back('0');
ans.push_back('1');
pt(ans);
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
// 負の数にも対応した mod
// 例えば -17 を 5 で割った余りは本当は 3 (-17 ≡ 3 (mod. 5))
// しかし単に -17 % 5 では -2 になってしまう
inline long long mod(long long a, long long m) {
return (a % m + m) % m;
}
// 拡張 Euclid の互除法
// ap + bq = gcd(a, b) となる (p, q) を求め、d = gcd(a, b) をリターンします
long long extGcd(long long a, long long b, long long &p, long long &q) {
if (b == 0) { p = 1; q = 0; return a; }
long long d = extGcd(b, a%b, q, p);
q -= a/b * p;
return d;
}
// 中国剰余定理
// リターン値を (r, m) とすると解は x ≡ r (mod. m)
// 解なしの場合は (0, -1) をリターン
pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2) {
long long p, q;
long long d = extGcd(m1, m2, p, q); // p is inv of m1/d (mod. m2/d)
if ((b2 - b1) % d != 0) return make_pair(0, -1);
long long m = m1 * (m2/d); // lcm of (m1, m2)
long long tmp = (b2 - b1) / d * p % (m2/d);
long long r = mod(b1 + m1 * tmp, m);
return make_pair(r, m);
}
int main(void){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T; cin >> T;
while(T--){
ll X, Y, P, Q; cin >> X >> Y >> P >> Q;
ll ans = LLINF;
//(2X+2Y)n + X <= t <= (2X+2Y)n + X + Y - 1 &&
//(P+Q)n + P <= t <= (P+Q)(n+1) - 1
for(ll alpha = X; alpha <= X+Y-1; alpha++){
for(ll beta = P; beta <= P+Q-1; beta++){
pair<ll, ll> temp = ChineseRem(alpha, X*2 + Y*2, beta, P+Q);
if(temp != pair<ll, ll>(0, -1)) ans = min(ans, temp.first);
}
}
if(ans == LLINF) cout << "infinity" << endl;
else cout << ans << endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int ans;
int t;
int main() {
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'o') {
t++;
}
}
if (t > 4) {
cout << 0 << endl;
return 0;
}
for (int a = 0; a <= 9; a++) {
for (int b = 0; b <= 9; b++) {
for (int c = 0; c <= 9; c++) {
for (int d = 0; d <= 9; d++) {
int r[15];
memset(r, 0, sizeof(r));
if (s[a] == 'o') {
r[a] = 1;
}
if (s[b] == 'o') {
r[b] = 1;
}
if (s[c] == 'o') {
r[c] = 1;
}
if (s[d] == 'o') {
r[d] = 1;
}
int f = 0;
for (int i = 0; i <= 9; i++) {
if (s[i] == 'o') {
if (r[i] == 0) {
f = 1;
break;
}
}
}
if (f == 1) {
continue;
}
if ((s[a] == 'o' || s[a] == '?') && (s[b] == 'o' || s[b] == '?') && (s[c] == 'o' || s[c] == '?') && (s[d] == 'o' || s[d] == '?')) {
ans++;
}
}
}
}
}
cout << ans << endl;
return 0;
}
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
int N;
char s[200001];
int cnt = 0;
char ptr[4] = "110";
char p[200010];
int flag = 0;
long long ans = 0;
scanf("%d", &N);
scanf("%s", s);
for(int k = 0;k < (N + 2)/ 3 + 1;k++){
memcpy(p + k * 3, ptr, 3);
}
p[N + 2] = '\0';
if(!strcmp(p + 2, s))flag = 1;
p[N + 1] = '\0';
if(!flag && !strcmp(p + 1, s))flag = 2;
p[N] = '\0';
if(!flag && !strcmp(p, s))flag = 3;
if(N == 1){
if(s[0] == '0')ans = 10000000000;
else if(s[0] == '1')ans = 20000000000;
}
else if(N == 2){
if(flag == 3 || flag == 2)ans = 10000000000;
else if(flag)ans = 9999999999;
}
else{
if(flag == 3)ans = 10000000001 - (N + 2)/ 3;
else if(flag == 2)ans = 10000000001 - (N + 3)/ 3;
else if(flag == 1)ans = 10000000001 - (N + 4)/ 3;
}
printf("%lld\r\n", ans);
return 0;
} |
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <fstream>
#include <cassert>
#include <numeric>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma region UnionFind
struct UnionFind
{
vector<int> par;
UnionFind(int n) : par(n, -1) {}
void init(int n) { par.assign(n, -1); }
int root(int x)
{
if (par[x] < 0) return x;
else return par[x] = root(par[x]);
}
bool issame(int x, int y)
{
return root(x) == root(y);
}
bool merge(int x, int y)
{
x = root(x); y = root(y);
if (x == y) return false;
if (par[x] > par[y]) swap(x, y);
par[x] += par[y];
par[y] = x;
return true;
}
int size(int x)
{
return -par[root(x)];
}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
if (a%b == 0)return b;
return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
#pragma endregion
#pragma region 一次元座圧
template <typename T>
vector<T> compress(vector<T> &X)
{
vector<T> vals = X;
sort(all(vals));
vals.erase(unique(all(vals)), vals.end());
rep(i, (int)X.size())X[i] = lower_bound(all(vals), X[i]) - vals.begin();
return vals;
}
#pragma endregion
#pragma endregion
int main()
{
int h, w; cin >> h >> w;
vector<string> v(h);
rep(i, h)cin >> v[i];
int res = 0;
rep(i, h)rep(j, w - 1)
{
if (v[i][j] == '.' && v[i][j + 1] == '.')++res;
}
rep(i, h - 1)rep(j, w)
{
if (v[i][j] == '.' && v[i + 1][j] == '.')++res;
}
cout << res << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int h, w, ans = 0;
cin >> h >> w;
char s[h][w];
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
cin >> s[i][j];
for (int i = 0; i < h - 1; i++)
for (int j = 0; j < w; j++)
if (s[i][j] == '.' && s[i + 1][j] == '.')
ans++;
for (int i = 0; i < h; i++)
for (int j = 0; j < w - 1; j++)
if (s[i][j] == '.' && s[i][j + 1] == '.')
ans++;
cout << ans;
return 0;
}
|
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
int main(){
int N,X; std::cin >> N >> X;
std::string s;
std::cin >> s;
for(const auto& c : s){
X += (c == 'o' ? 1 : -1);
X = std::max(0,X);
}
std::cout << X << std::endl;
}
| #include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i <=b ; ++i)
#define per(i, b, a) for(int i = b; i >= a; --i)
#define ll long long
#define pb push_back
using namespace std;
inline void rd(int &x){scanf("%d", &x);}
inline void rd(ll &x){scanf("%lld", &x);}
int n, m, k;
const int maxn = 1145;
int par[maxn << 1];
int findroot(int u)
{
return par[u] == u ? par[u] : (par[u] = findroot(par[u]));
}
void merge(int u, int v)
{
if(findroot(u) == findroot(v)) return;
par[findroot(u)] = v;
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
rep(i, 1, n + m) par[i] = i;
rep(i, 1, n)
{
string s;
cin >> s;
rep(j, 1, m) if(s[j - 1] == '#') merge(i, n + j);
}
merge(1, n + 1), merge(1, n + m), merge(n, n + 1), merge(n, n + m);
int ans = 0;
unordered_set<int> r, c;
rep(i, 1, n) r.insert(findroot(i));
rep(j, 1, m) c.insert(findroot(j + n));
cout << min(r.size(), c.size()) - 1;
} |
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pi 3.1415926535897932384626433832795
#define FOR(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define FORL(i, a, n) for (ll(i) = (a); (i) <= (n); (i)++)
#define FORR(i, a, n) for (ll(i) = (a); (i) >= (n); (i)--)
#define FORSQ(i, a, n) for (ll(i) = (a); (i) * (i) <= (n); ++(i))
#define FOREACH(a, b) for (auto &(a) : (b))
#define f first
#define s second
#define pb push_back
#define pon pop_back
#define mp make_pair
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (ll) v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<pll> vll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef priority_queue<ll> PQMAX;
typedef priority_queue<ll, vector<ll>,
greater<ll>>
PQMIN;
typedef set<ll> setll;
typedef map<ll, ll> mapll;
ll power(ll x, ll y, ll p)
{
ll res = 1;
x = x % p;
if (x == 0)
return 0;
while (y > 0)
{
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
void solve()
{
ll n, m;
cin >> n >> m;
cout << power(10, n, m * m) / m % m << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t = 1;
// cin >> t;
while (t--)
{
solve();
}
return 0;
} | #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include <atcoder/all>
using namespace std;
//using namespace boost::multiprecision;
//using namespace atcoder;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(firstsecond) '(' << first< ',' << second< ')'
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
ll INF = 1001001001001001;
long double EPS = 1e-8;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
vector.erase(vector.begin() + index);
}
random_device seed_gen;
mt19937_64 rnd(seed_gen());
ll range_rand(ll a,ll b){
uniform_int_distribution<ll> dist_res(a,b);
return dist_res(rnd);
}
using Graph = vector<vector<ll>>;
// MOD確認
ll N,M;
Graph G(2010);
ll done[2010];
void dfs(ll x,ll a){
ll n = G[x].size();
done[x] = 1;
rep(i,n){
ll y = G[x][i];
if(y != a && !done[y]) dfs(y,x);
}
return ;
}
int main(){
cin >> N >> M;
rep(i,M){
ll a,b;
cin >> a >> b;
a--;
b--;
G[a].emplace_back(b);
}
ll ans = 0;
rep(i,N){
rep(j,N) done[j] = 0;
dfs(i,-1);
rep(j,N) if(done[j]) ans++;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fio ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#define RED "\033[31m"
#define GREEN "\033[32m"
#define RESET "\033[0m"
#define sleep for (int i = 1, a;i < 100000000;i++, a = a * a)
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ranked_pairset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_map;
const int N = 2001;
vi adj[N];
vb vis;
int ans = 0;
void dfs(int u) {
vis[u] = 1;
ans++;
for (auto v : adj[u])
if (!vis[v])
dfs(v);
}
int main() {
fio;
int n, m;
cin >> n >> m;
for (int i = 0;i < m;i++) {
int u, v;
cin >> u >> v;
adj[u].pb(v);
}
for (int i = 1;i <= n;i++) {
vis.assign(n + 1, 0);
dfs(i);
}
cout << ans << '\n';
}
| #include <bits/stdc++.h>
using namespace std;
const int inf = 1000000009;
const int maxn = 100005;
const int maxk = 17;
vector <int> g_init[maxn];
vector <pair <int, int> > g[maxk];
int d[maxk][1 << maxk];
int32_t main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
g_init[u].push_back(v);
g_init[v].push_back(u);
}
int k;
cin >> k;
vector <int> c(k);
for (int i = 0; i < k; ++i)
cin >> c[i];
bool can = 1;
for (int j = 0; j < k; ++j) {
int root = c[j];
vector <int> dist(n + 1, inf);
queue <int> q;
dist[root] = 0;
q.push(root);
while (!q.empty()) {
int u = q.front();
q.pop();
for (int v: g_init[u]) {
if (dist[v] == inf) {
dist[v] = dist[u] + 1;
q.push(v);
}
}
}
for (int i = 0; i < k; ++i) {
if (dist[c[i]] == inf)
can = 0;
else if (i != j)
g[j].push_back(make_pair(i, dist[c[i]]));
}
}
if (!can) {
cout << "-1\n";
return 0;
}
set <pair <int, pair <int, int> > > dset;
for (int i = 0; i < k; ++i) {
for (int mask = 0; mask < (1 << k); ++mask)
d[i][mask] = inf;
d[i][1 << i] = 1;
dset.insert(make_pair(d[i][1 << i], make_pair(i, (1 << i))));
}
while (!dset.empty()) {
pair <int, int> u = dset.begin() -> second;
dset.erase(dset.begin());
for (pair <int, int> e: g[u.first]) {
int v = e.first, w = e.second;
if (d[v][u.second | (1 << v)] > d[u.first][u.second] + w) {
dset.erase(make_pair(d[v][u.second | (1 << v)], make_pair(v, (u.second | (1 << v)))));
d[v][u.second | (1 << v)] = d[u.first][u.second] + w;
dset.insert(make_pair(d[v][u.second | (1 << v)], make_pair(v, (u.second | (1 << v)))));
}
}
}
int ans = inf;
for (int i = 0; i < k; ++i)
ans = min(ans, d[i][(1 << k) - 1]);
cout << ans << '\n';
}
|
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define pll pair<long long,long long>
#define vl vector<long long>
#define vll vector<pll>
#define vi vector<int>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define tcase int tt; cin>>tt; while(tt--)
#define tcase2 int tt; cin>>tt; for(int qq=1;qq<=tt;qq++)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
const int MAXN = 1000002;
const int MOD2 = 998244353;
const int MOD = 1000000007;
const int INF = 1e8;
const ld EPS = 1e-7;
// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define trav(a, x) for(auto& a : x)
#define fill(x,y) memset(x,y,sizeof(x))
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
ll n,m ;
ll mul(ll x, ll y)
{
return (x * 1ll * y) % m;
}
ll fastpow(ll x, ll y)
{
ll z = 1;
while(y)
{
if(y & 1) z = mul(z, x);
x = mul(x, x);
y >>= 1;
}
return z;
}
ll modinv(ll n,ll p)
{
return fastpow(n,p-2) ;
}
struct Comp {
bool operator()(const std::pair<int, int> &a, const std::pair<int, int> &b) {
if (a.first != b.first) {
return a.first < b.first;
}
return a.second >b.second;
}
};
int main(int argc, char** argv)
{ sws ;
// cout<<setprecision(10);
// ll google=0 ;
// tcase
{
ll l,r ;
cin>>l>>r;
ll ans[r+1]={0} ;
ll val[r+1]={0} ;
for(int i=r;i>=2;i--)
{ ll cnt=0,k=0,temp=0 ; ;
for(int j=2*i;j<=r;j+=i)
{
if(j>=l&&j<=r)
{
k++ ;
temp+=val[j] ;
}
cnt+=ans[j] ;
}
val[i]=k ;
ans[i]=(k*(k-1))/2-cnt-temp ;
// cout<<ans[i]<<" ";
}
ll fin=0 ;
for(int i=2;i<=r;i++)
{
fin+=ans[i] ;
// cout<<2*ans[i]<<" ";
}
cout<<2*fin<<"\n" ;
}
return 0 ;
} | #include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define p(x,y) pair<x,y>
#define oset(x) tree<x, null_type, less<x>, rb_tree_tag, tree_order_statistics_node_update>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define scan(a) for(auto &it:a)cin>>it;
#define print(a) {for(auto it:a)cout<<it<<" ";cout<<endl;}
#define out(x) cout<<((x)?"YES":"NO")<<endl;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define int ll
void solve()
{
int l,r;
cin>>l>>r;
int cnt[r+1]={};//count of distinct prime if more than 1 same prime than INT_MIN
rep(i,2,r+1)
{
if(cnt[i]!=0)
continue;
for(ll j=i;j<=r;j+=i)
cnt[j]++;
for(ll j=i*i*1LL;j<=r;j+=i*i*1LL)
cnt[j]=INT_MIN;
}
//counting comprime in l,r;
int copairs=0;//coprime pairs(x,y) where x<y
rep(i,1,r+1)
{
if(cnt[i]<0)
continue;
ll mul=(r/i)-((l-1)/i);
ll pairs=(mul*(mul-1))/2;
if(cnt[i]%2)
copairs-=pairs;
else
copairs+=pairs;
}
copairs*=2LL;
int gcdgpairs=0; //(x,y) pairs where k*x=y k>1
for(int i=max(l,2LL);i<=r;i++)
gcdgpairs+=(r/i)-1;
gcdgpairs*=2LL;
int equalpairs=r-l+1;
int ans=(r-l+1)*(r-l+1)-gcdgpairs-copairs-equalpairs;
cout<<ans;
}
int32_t main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int t=1;
//init();
//cin>>t;
while(t--)
{
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " = " << x << endl
using namespace std;
typedef long long LL;
const int MAXN = 55;
const int MOD = 1E9 + 7;
LL n, x, a[MAXN], g[MAXN], dp[MAXN][2];
template <class T>
void read(T& x) {
x = 0;
T f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
x *= f;
}
template <class T, class... Args>
void read(T& x, Args&... args) {
read(x), read(args...);
}
signed main() {
read(n, x);
for (int i = 1; i <= n; i++) read(a[i]);
for (int i = n; i >= 1; i--) {
if (!x) break;
g[i] = x / a[i], x %= a[i];
}
for (int i = n - 1; i >= 1; i--) {
LL lim = a[i + 1] / a[i];
if (g[i] == 0) {
dp[i][0] = dp[i + 1][0];
dp[i][1] = dp[i + 1][1] + dp[i + 1][0] + 1;
} else if (g[i] == lim - 1) {
dp[i][0] = dp[i + 1][0] + dp[i + 1][1] + 1;
dp[i][1] = dp[i + 1][1];
} else {
dp[i][1] = dp[i + 1][1] + dp[i + 1][0] + 1;
dp[i][0] = dp[i + 1][0] + dp[i + 1][1] + 1;
}
}
cout << dp[1][0] + 1;
return 0;
} | /**
* author: Dooloper
* created: 01.05.2021 20:57:29
**/
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repp(i,k, n) for(int i = (int)(k); i < (int)(n); i++)
#define ALL(a) (a).begin(),(a).end()
using ll = long long;
using P = pair<int, int>;
struct Edge{int to; ll w; Edge(int to, ll w) : to(to), w(w) {}};
using Graph = vector<vector<Edge>>;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
int n;
vector<vector<int>> x(3030, vector<int>(5));
int getMask(int i, int lim){
int res = 0;
rep(j,5) if(lim <= x[i][j]) res += 1 << j;
return res;
}
vector<int> cnt(1<<5);
bool check(int lim){
rep(i, 1<<5) cnt[i] = 0;
rep(i,n) cnt[getMask(i,lim)]++;
rep(msk1,1 << 5) rep(msk2,1<<5) rep(msk3,1<<5) {
if((msk1 | msk2 | msk3) == (1<<5)-1 && 0 < cnt[msk1] && 0 < cnt[msk2] && 0 < cnt[msk3]) return true;
}
return false;
}
int main(){
cin >> n;
rep(i,n) rep(j,5) cin >> x[i][j];
int ok = 0; int ng = 1000000007;
while(ok + 1 != ng){
int md = (ok+ng)/2;
if(check(md)) ok = md;
else ng = md;
}
cout << ok << endl;
} |
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define t() int t;cin>>t;while(t--)
#define lt() long long int t;cin>>t;while(t--)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define nik(i,k,n) for (int i = k; i < (n); ++i)
void fast()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("inp.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
}
void solve()
{
ll n, m;
cin >> n>> m;
if(m%n == 0){
cout << "Yes" <<endl;
return ;
}
cout << "No" << endl;
}
int32_t main()
{
fast();
//lt(){
solve();
//}
return 0;
} | #include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=200005;
const int inf=1ll<<60;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int a,b;
cin>>a>>b;
cout<<(b%a==0?"Yes":"No");
} |
// This code wrote by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
#define ALL(x) (x).begin(),(x).end()
#define mem(x,y) memset(x,y,sizeof x)
#define sz(x) (int)(x).size()
#define ln std::puts("")
#define lsp std::putchar(32)
#define pb push_back
#define MP std::make_pair
#define dbg(x) std::cerr<<__func__<<"\tLine:"<<__LINE__<<' '<<#x<<": "<<x<<"\n"
#define dprintf(x...) std::fprintf(stderr,x)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
template <class t> inline void read(t &s){s=0;
reg int f=1;reg char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c))s=(s<<3)+(s<<1)+(c^48),c=getchar();s*=f;return;}
template<class t,class ...A> inline void read(t &x,A &...a){read(x);read(a...);}
template <class t> inline void write(t x){if(x<0)putchar('-'),x=-x;
int buf[21],top=0;while(x)buf[++top]=x%10,x/=10;if(!top)buf[++top]=0;
while(top)putchar(buf[top--]^'0');return;}
inline void setIn(std::string s){freopen(s.c_str(),"r",stdin);return;}
inline void setOut(std::string s){freopen(s.c_str(),"w",stdout);return;}
inline void setIO(std::string s=""){setIn(s+".in");setOut(s+".out");return;}
template <class t>inline bool checkmin(t&x,t y){if(x>y){x=y;return 1;}return 0;}
template <class t>inline bool checkmax(t&x,t y){if(x<y){x=y;return 1;}return 0;}
inline int lowbit(int x){return x&(-x);}
inline void work()
{
reg int l,r;read(l,r);
if(r-l+1<l)
return std::puts("0"),void();
reg int ans=(r-l+1-l+1)*(r-l+1);
ans-=(l+r-l+1)*(r-l+1-l+1)/2;
write(ans),ln;
}
signed main(void)
{
int t;read(t);
while(t--)
work();
return 0;
}
/*
* Check List:
* 1. Input / Output File (OI)
* 2. long long
* 3. Special Test such as n=1
* 4. Array Size
* 5. Memory Limit (OI) int is 4 and longlong is 8
* 6. Mod (a*b%p*c%p not a*b*c%p , (a-b+p)%p not a-b )
* 7. Name ( int k; for(int k...))
* 8. more tests , (T=2 .. more)
* 9. blank \n after a case
*/
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//turn on extra precision
//#pragma GCC target("fpmath=387")
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef string str;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define watch(x) cout << (#x) << " is : " << (x) << newl
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
vi dirx = {0,0,1,-1};
vi diry = {1,-1,0,0};
char to_upper (char x){
if( 97 <= int(x) && int(x) <= 122) return char(x-32);
if( 65 <= int(x) && int(x) <= 90) return x;
return -1;
}
char to_lower (char x){
if( 97 <= int(x) && int(x) <= 122) return x;
if( 65 <= int(x) && int(x) <= 90) return char(x+32);
return -1;
}
int numerize (char x){
if(48 <= int(x) && int(x) <= 57) return int(x-'0');
if(97 <= int(x) && int(x) <= 122) return int(x-96);
if(65 <= int(x) && int(x) <= 90) return int(x-64);
return -1;
}
bool isect (int l1, int r1, int l2, int r2){
pii p1 = {l1,r1};
pii p2 = {l2,r2};
if(p1>p2)swap(p1,p2);
return (p2.fi <= p1.se);
}
ll quickpow (ll num1, ll num2, ll MOD){
if(num2==0)return 1%MOD;
else if(num2==1)return num1%MOD;
else{
ll temp = quickpow (num1,num2>>1LL,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
if(num2&1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
}
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
int n;
ll pd[200010],w,sum[200010];
int main(){
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> w;
for(int i = 0; i < n; ++i){
ll l, r, p; cin >> l >> r >> p;
pd[l] += p;
pd[r] -= p;
}
bool ok = true;
for(int i = 0; i <= 2e5; ++i) {
sum[i] = (i ? sum[i-1] : 0) + pd[i];
ok &= (w >= sum[i]);
}
cout << (ok ? "Yes\n" : "No\n");
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int x, y; cin >> x >> y;
if(abs(x-y) < 3){
cout << "Yes";
}else{
cout << "No";
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define tc ll t;cin>>t;while(t--)
#define PI 2*acos(0)
#define mset(pq) memset(pq, 0, sizeof(pq));
ll M=1e9+7;
int sum_digit(int x) { int sum=0; while(x>0){ sum+=x%10; x/=10; } return sum; }
int reverse_num(int n){ int tmp=n, ans=0, r; while(tmp>0){ r=tmp%10; ans=ans*10+r; tmp/=10; } return ans; }
ll factorial(ll n){ ll i, ans=1; for(i=n; i>1; i--){ans*=i;} return ans; }
ll gcd(ll num1, ll num2) { ll a,b,r; a=num1; b=num2; r=a%b; while(r>0){ a=b; b=r; r=a%b; } return b; }
ll lcm(ll num1, ll num2) { return (num1*num2)/gcd(num1, num2); }
bool isprime(ll n) { if(n<2) return false; for(ll i=2;i<=sqrt(n);i++){ if(n%i==0)return false;} return true; }
/// Depression is a leading cause of disability
/// Verily, with hardship comes ease. [94:6], Qur'an
void solve()
{
int a, b, c, d, i, j, k, m, n, x, y, z, p;
int cnt=0, flag=0;
char ch, ch1, ch2;
string s, t;
cin >> a >> b;
m=min(a, b);
if((m+3)>max(a, b))
cout << "Yes";
else
cout << "No";
//cout << cnt << endl;
}
int main()
{
//tc
solve();
return 0;
}
/*
*/
// sort(arr, arr+n);
// reverse(s.begin(), s.end()); // reversing a string
// getline( cin, s);
/*
vector <int> arr;
for(i=0; i<n; i++)
arr.push_back(i);
*/
/* set of string
set<string>s;
for(i=0; i<n; i++)
{
cin >> t;
s.insert(t);
}
for(auto it=s.begin(); it!=s.end(); it++)
{
//string s2 = *it;
cout << *it << endl;
}
*/
|
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <utility>
#include <numeric>
#define pb push_back
#define mk make_pair
#define endl "\n"
#define mod 1000000007
#define mod1 1610612741
#define mul 31
#define PI 3.14159265358979323846264
//#include bits/stdc++.h
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
typedef long long int lli;
typedef long double ld;
typedef pair<lli,lli> ii;
//priority_queue <lli, vector<lli>, greater<lli> > ti;
//priority_queue<pair<lli,pair<lli,lli>>>e;
vector <lli> p[300005],q[300005],f(200005,-1),d(300005,0),a(300005);
//vector<set<lli>>s(200005);
//set<pair<lli,lli>>s;
//vector<vector<lli>> dp(200005,vector<lli>(25,0));
//vector<lli>f(10000005);
//lli b[1000005],l[1000005];
//vector<vector<lli>> d(300005,vector<lli>(18,0));
//vector<pair<lli,ii>>p[300005];
//map<pair<lli,lli>,lli>mp,np;
//vector<pair<pair<lli, lli>,lli> > st;
//queue<lli> qy;
//freopen("codecoder.in", "r", stdin);
//freopen("codecoder.out", "w", stdout);
lli gcd(lli a, lli b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
lli bpow(lli a, lli b) {
lli res = 1;
while (b > 0) {
if (b & 1)
res = (res * a)%mod;
a = (a * a)%mod;
b >>= 1;
}
return res%mod;
}
void fact(lli i)
{
f[0]=1;
for(lli k=1;k<=i;k++)
{
(f[k]=f[k-1]*k)%=mod;
}
}
lli isprime(lli n)
{
if(n==1)
return 0;
for(lli i=2;i<=sqrt(n);i++)
if(n%i==0)
return 0;
return 1;
}
lli find(lli x)
{
if(f[x]==x)
return x;
else
return f[x]=find(f[x]);
}
bool cmp(lli x,lli y)
{
return x<y;
}
void check()
{
cout<<"HI"<<endl;
}
lli comb(lli i,lli j)
{
if(j>i)return 0;
lli k=f[i];
lli g=(f[j]*(f[i-j]))%mod;
lli h=bpow(g,mod-2);
return (k*h)%mod;
}
pair<ld,ld>az(ld a,ld b,ld c,ld d,ld u)
{
ld x1=(a-c)*cos(u)-(b-d)*sin(u)+c;
ld y1=(a-c)*sin(u)+(b-d)*cos(u)+d;
return {x1,y1};
}
/*void sieve()
{
for(lli i=2;i<=sqrt(10000000);i++)
{
if(b[i]==0)
{
k.pb(i);
for(lli j=2;i*j<=sqrt(10000000);j++)
{
b[i*j]=1;
}
}
}
}*/
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli t;t=1;
while(t--)
{
lli n;cin>>n;
vector<lli> a(n);
for(lli i=0;i<n;i++)
cin>>a[i];
lli cnt=min(8ll,n);
vector<vector<lli>> b(200,vector<lli>(0));
for(lli i=1;i<(1ll<<cnt);i++)
{
vector<lli>v;
lli s=0;
for(lli j=0;j<cnt;j++)
{
if(i&(1ll<<j))
{
v.pb(j+1);
(s+=a[j])%=200;
}
}
if(b[s].size()!=0)
{
cout<<"Yes"<<endl;
cout<<b[s].size()<<" ";
for(lli j=0;j<b[s].size();j++)
{
cout<<b[s][j]<<" ";
}
cout<<endl;
cout<<v.size()<<" ";
for(lli j=0;j<v.size();j++)
{
cout<<v[j]<<" ";
}
cout<<endl;
return 0;
}
else
{
b[s]=v;
}
}
cout<<"No"<<endl;
}
}
| #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
using ll = long long;
//using mint = modint;
const vector<int> dx = {1, 1, 1, 0, 0, 0, -1, -1, -1};
const vector<int> dy = {1, 0, -1, 1, -1, 0, 1, 0, -1};
const double PI = 3.141592653589793;
const ll inf = 1001001001;
const ll e9 = 1000000000;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int MAX = 1000000;
const ll MOD = 998244353;
const ll big = 1ll<<60;
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
int main(){
ll n;
cin >> n;
vector<ll>a(n+10);
vector<queue<ll>>v(210);
vector<vector<bool>>seen(n+10, vector<bool>(210, false));
rep(i, 0, n){
cin >> a[i+1];
a[i+1] %= 200;
if(a[i+1]==0){
seen[i+1][200] = true;
}
}
rep(i, 0, n+5){
seen[i][0] = true;
}
lrep(i, 1, n+1){
lrep(j, 0, 201){
if(seen[i-1][j] && v[(j+a[i])%200].empty()){
//queue<ll> temp = v[j];
v[(j+a[i])%200] = v[j];
v[(j+a[i])%200].push(i);
seen[i][(j+a[i])%200] = true;
seen[i][j] = true;
}else if(seen[i-1][j] && !v[(j+a[i])%200].empty()){
queue<ll> temp1 = v[j];
queue<ll> temp2 = v[(j+a[i])%200];
temp1.push(i);
if(temp1==temp2)continue;
cout << "Yes" << endl;
cout << temp1.size() << " ";
while(!temp1.empty()){
cout << temp1.front() << " ";
temp1.pop();
}
cout << endl;
cout << temp2.size() << " ";
while(!temp2.empty()){
cout << temp2.front() << " ";
temp2.pop();
}
return 0;
}
}
}
cout << "No" << endl;
return 0;
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int main()
{
int h, w;
cin >> h >> w;
vector<string> s(h);
rep (i, h)
cin >> s[i];
int ans = 0;
rep (i, h)
rep (j, w)
{
if (j + 1 < w && s[i][j] == '.' && s[i][j + 1] == '.')
ans++;
if (i + 1 < h && s[i][j] == '.' && s[i + 1][j] == '.')
ans++;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define LL long long
#define LD long double
#define MAXN
#define MAXM
#define P 998244353
#define MP make_pair
#define PB push_back
#define INF 0x3f3f3f3f
#define dbg(a...) fprintf(stderr, a)
using namespace std;
int h, w, ans=1;
char mp[505][505];
int main()
{
scanf("%d%d", &h, &w);
for(int i=1; i<=h; ++i) {
scanf("%s", mp[i]+1);
}
for(int i=2; i<=h+w; ++i) {
int flag=0;
for(int j=1; j<i; ++j) {
int x=j, y=i-j;
if(x>h || y>w) continue;
if(mp[x][y]=='B') {
if(flag==2) ans=0;
else flag=1;
}
if(mp[x][y]=='R') {
if(flag==1) ans=0;
else flag=2;
}
//printf("%d %d %d\n", x, y, flag);
}
if(flag==0) ans=ans*2%P;
}
printf("%d\n", ans);
return 0;
} |
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i=(a); i<(n); i++)
#define per(i, a, n) for (int i=(a); i>(n); i--)
typedef long long ll;
const int maxn = 2e5+5;
const int mod = 1e9+7;
using namespace std;
ll a[maxn], ti[maxn];
void solve() {
ll n,q,t; cin >> n;
ll L=0,R=0,add=0,ext=1e18,Lval=-1e18,Rval=1e18;
rep(i,0,n) cin >> a[i] >> ti[i];
rep(i,0,n) {
if (ti[i] == 1) {
if (ext != 1e18) {
ext += a[i];
continue;
}
add += a[i];
if (Lval != -1e18) {
Lval += a[i];
}
if (Rval != 1e18) {
Rval += a[i];
}
} else if (ti[i] == 2) {
if (ext != 1e18) {
ext = max(ext, a[i]);
continue;
}
if (a[i] < Lval) continue;
L = a[i] - add;
Lval = a[i];
if (Lval >= Rval) {
ext = Lval;
}
} else {
if (ext != 1e18) {
ext = min(ext, a[i]);
continue;
}
if (a[i] > Rval) continue;
R = a[i] - add;
Rval = a[i];
if (Rval <= Lval) {
ext = Rval;
}
}
}
cin >> q;
//cout << L << ' ' << Lval << ' ' << R << ' ' << Rval << '\n';
rep(i,0,q) {
cin >> t;
if (ext != 1e18) cout << ext << '\n';
else {
if (Lval == -1e18 && Rval == 1e18) cout << t + add << '\n';
else if (t <= L && Lval != -1e18) cout << Lval << '\n';
else if (t >= R && Rval != 1e18) cout << Rval << '\n';
else if (Rval != 1e18) cout << Rval - (R - t) << '\n';
else cout << Lval + t - L << '\n';
}
}
}
int main(int argc, char * argv[]) {
ios_base::sync_with_stdio(false); cin.tie(0);
//int t; cin >> t; while(t--)
solve();
return 0;
} | #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define all(v) (v).begin(),(v).end()
#define all_rev(v) (v).rbegin(),(v).rend()
#define debug(x) cout << #x << ": " << x << '\n';
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
using P = pair<int,int>;
using PL = pair<ll, ll>;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15);
ll N;
cin >> N;
if (N < 1000) {
cout << 0 << '\n';
exit(0);
}
string t = "9999999999999999";
ll ans = 0;
while (stoll(t) >= N) t = t.substr(0, t.size() - 1);
while (t.size() >= 3 && N > stoll(t)) {
ans += (N - stoll(t)) * (t.size() / 3);
N -= N - stoll(t);
t = t.substr(0, t.size() - 1);
}
cout << ans << '\n';
return 0;
}
|
#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define f first
#define s second
#define pb push_back
// clang-format off
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T_vector>void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) {if (start < 0) start = 0; if (end < 0) end = int(v.size()); for (int i = start; i < end; i++) cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << "(" << v.first << ":" << v.second << ")" << ","; os << "}"; return os; }
auto random_address = [] {char *p = new char; delete p;return uint64_t(p);};
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
// clang-format on
void solve() { }
int main() {
int n;
cin >> n;
int ans = 0;
set<int> st;
for (int i = 1; i <= n; ++i) {
bool ok = true;
for (int base : { 8, 10 }) {
int x = i;
while (x > 0) {
if (x % base == 7) ok = false;
x /= base;
}
}
if (ok)
++ans;
}
// for (auto x : st)
// cout << x << " ";
// cout << st.size();
cout << ans << endl;
return 0;
} | #include<iostream>
using namespace std;
int main(){
int a,i,ii,N,co=0,b;
cin >> N;
for(i=1;i<=N;i++){
a=0;
if(i%10==7||i%100-i%10==70||i%1000-i%100==700||i%10000-i%1000==7000||i%100000-i%10000==70000){
a=a+1;
}
for(ii=i;ii>0;i=i){
b=ii%8;
ii=ii/8;
if(b==7)a=a+1;
}
if(a==0)co=co+1;
}
cout << co << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;
#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back
int main()
{
string S;
cin >> S;
cout << S[1] << S[2] << S[0] << endl;
return 0;
}
/*
*/ | #include <iostream>
#include <string>
using namespace std;
string S;
int main() {
cin >> S;
printf("%c%c%c\n", S[1], S[2], S[0]);
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,srt,end) for(int i = (srt); i < (int)(end); i++)
//cout << std::fixed << std::setprecision(15) << y << endl;
// For debug
// Ref: https://qiita.com/ysuzuki19/items/d89057d65284ba1a16ac
#define dump(var) do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << "\n";}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << "\n";}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ std::cerr << "\n"; for(const auto& v : vv){ view(v); } }
template<typename T> void dump_cout(const T& v) { for(long long i = 0; i < v.size(); i++) std::cout << v[i] << (i == v.size()-1 ? "\n" : " "); }
// mex : https://rsk0315.hatenablog.com/entry/2020/10/11/125049
struct nekoset {
private:
std::set<std::pair<int, int>> s;
std::map<int, int> nums;
public:
nekoset() {
s.emplace(INT_MIN, INT_MIN);
s.emplace(INT_MAX, INT_MAX);
}
bool contains(int x) const {
auto it = std::prev(s.lower_bound(std::make_pair(x+1, x+1)));
auto [l, u] = *it;
return l <= x && x <= u;
}
// 追加した関数
bool erase(int x) {
nums[x] = 0;
auto nit = s.lower_bound(std::make_pair(x+1, x+1));
auto it = std::prev(nit);
auto [l, u] = *it;
if (l == x && x == u) s.erase(it);
else if(l == x) {
s.erase(it);
s.emplace(x+1, u);
}
else if(u == x) {
s.erase(it);
s.emplace(l, x-1);
}
else if(l < x && x < u){
s.erase(it);
s.emplace(l, x-1);
s.emplace(x+1, u);
}
else return false;
return true;
}
bool insert(int x) {
nums[x]++;
auto nit = s.lower_bound(std::make_pair(x+1, x+1));
auto it = std::prev(nit);
auto [l, u] = *it;
auto [nl, nu] = *nit;
if (l <= x && x <= u) return false;
if (u == x-1) {
if (nl == x+1) {
s.erase(it);
s.erase(nit);
s.emplace(l, nu);
} else {
s.erase(it);
s.emplace(l, x);
}
} else {
if (nl == x+1) {
s.erase(nit);
s.emplace(x, nu);
} else {
s.emplace(x, x);
}
}
return true;
}
int mex(int x = 0) const {
auto [l, u] = *std::prev(s.lower_bound(std::make_pair(x+1, x+1)));
if (l <= x && x <= u) {
return u+1;
} else {
return x;
}
}
void view() {
for(auto [u, v] : s) {
cerr << "[" << u << "," << v << "] ";
}
cerr << "\n";
}
bool reduce(int x, int y) {
assert(nums[x] >= y);
nums[x] -= y;
if(nums[x] == 0) return erase(x);
return true;
}
bool reduce(int x) {
return reduce(x, 1);
}
};
int main() {
int n, m;
cin >> n >> m;
vector<int> a(n);
rep(i, 0, n) cin >> a[i];
nekoset s;
rep(i, 0, m) {
s.insert(a[i]);
}
int ans = s.mex();
rep(i, 0, n-m){
s.insert(a[i+m]);
s.reduce(a[i]);
ans = min(ans, s.mex());
}
// set<pair<int,int>> s の中身を見てdebugしたい
s.view();
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define SZ(a) (int)((a).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> Pii;
typedef pair <ll, int> Pli;
typedef unsigned long long ull;
const double eps = 1e-8;
const int mod = (int)(1e9) + 7;
const int inf = 0x7fffffff;
const int N = (int)(2e6) + 7;
int n, m, a[N], g[N];
ll t[N];
int lowbit(int x) {
return x & -x;
}
void upd(int x, ll v) {
while (x <= n) {
t[x] += v;
x += lowbit(x);
}
}
ll sum(int x) {
if (x <= 0) return 0;
ll res = 0;
while (x) {
res += t[x];
x -= lowbit(x);
}
return res;
}
ll query(int x) {
return sum(x) - sum(x - 1);
}
int main() {
// freopen("in.in", "r", stdin);
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
int res = n + 1;
for (int i = 1, j = 1; i <= n; ++i) {
if (++g[a[i] + 1] == 1) upd(a[i] + 1, 1);
while (i - j + 1 > m) {
if (!--g[a[j] + 1])
upd(a[j] + 1, -1);
++j;
}
// printf("[%d, %d]", i, j);
if (i - j + 1 != m) continue;
int L = 0, R = n + 1;
while (L < R) {
int mid = (L + R) / 2;
if (sum(mid + 1) != mid + 1) R = mid;
else L = mid + 1;
}
// printf("(%d, %d: %d)", j, i, L);
res = min(res, L);
}
printf("%lld", res);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
long long a,b,len;
typedef long long ll;
ll dp[75][1<<20],pk;
vector<long long> m,p={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
int main()
{
cin>>a>>b;
len=b-a+1;
for(ll i=a;i<=b;i++) m.push_back(i);
pk=p.size();
dp[0][0]=1;
for(ll i=0;i<len;i++){
ll nowb=0;
for(ll j=0;j<pk;j++)
if(m[i]%p[j]==0) nowb=nowb|(1<<j);//是哪一个质数的倍数
for(ll j=0;j<(1<<pk);j++){
if(i==0){
if(nowb==j)
dp[i][j]+=1;
}
else{
dp[i][j]=dp[i-1][j];
if((nowb&j)==nowb)
dp[i][j]+=dp[i-1][j-nowb];
}
}
}
long long res=0;
for(ll i=0;i<(1<<pk);i++)
res+=dp[len-1][i];
cout<<res<<endl;
system("pause");
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
#define pow(n,m) powl(n,m)
#define sqrt(n) sqrtl(n)
const ll MAX = 5000000000000000000;
const ll MOD = 0;
void randinit(){srand((unsigned)time(NULL));}
int main(){
ll N,M;
cin >> N >> M;
vector<tuple<ll,ll>> A(0);
for(ll i = 0;i < M;i++){
ll x,y;
cin >> x >> y;
if(N - 250000 <= y && y <= N + 250000){
A.emplace_back(make_tuple(x,y));
}
}
sort(A.begin(),A.end());
vector<ll> DP(600000,0);
DP[300000] = 1;
for(ll i = 0;i < A.size();i++){
vector<ll> B(0);
while(true){
ll y = get<1>(A[i]);
B.emplace_back(y);
if(i < A.size() - 1 && get<0>(A[i]) == get<0>(A[i + 1])){
i++;
}
else{
break;
}
}
map<ll,ll> kari;
for(ll j = 0;j < B.size();j++){
kari[B[j] - N + 300000] = DP[B[j] - N + 300000];
if(B[j] > 0){
kari[B[j] - N + 300000 - 1] = DP[B[j] - N + 300000 - 1];
}
if(B[j] < 2 * N){
kari[B[j] - N + 300000 + 1] = DP[B[j] - N + 300000 + 1];
}
}
for(ll j = 0;j < B.size();j++){
DP[B[j] - N + 300000] = 0;
}
for(ll j = 0;j < B.size();j++){
if(B[j] > 0 && kari[B[j] - N + 300000 - 1]){
DP[B[j] - N + 300000] = 1;
}
if(B[j] < 2 * N && kari[B[j] - N + 300000 + 1]){
DP[B[j] - N + 300000] = 1;
}
}
}
ll ans = 0;
for(ll i = 0;i < DP.size();i++) ans += DP[i];
cout << ans << endl;
}
|
#include <bits/stdc++.h>
//#include <atcoder/all>
//#include "Z:\2_Src\31_Luzhiles_s.git\template\template.cpp"
using namespace std; //using namespace atcoder;
template<typename T> using ve=vector<T>;
using ll=long long; using ld=long double; using str=string; using pint=pair<ll,ll>;
using vll=ve<ll>; using vd=ve<ld>; using vs=ve<str>; using vll2=ve<ve<ll>>;
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define b2e(v) v.begin(),v.end()
#define p2a(v, p) v[p.first][p.second]
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repi(i,n) for(ll i=(n-1);i>=0;i--)
#define repe(e,v) for(auto e:v)
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;
//const int MOD=998244353;
vll t1,k1;
ll calc(ll now, ll idx) {
//1. 到着時刻を現在位置の時刻tiを使って動的に求める((ti%k==0? ti: ti+k-ti%k) + t)
ll ans= now%k1[idx]? k1[idx]-now%k1[idx]:0;
return ans + t1[idx];
}
#define TEMPT long long int
template< typename T = TEMPT >
struct Edge {
int from, to;
T cost;
int idx;
Edge() = default;
Edge(int from, int to, T cost = 1, int idx = -1) : from(from), to(to), cost(cost), idx(idx) {}
operator int() const { return to; }
};
template< typename T = TEMPT >
struct Graph {
vector< vector< Edge< T > > > g;
int es;
Graph() = default;
explicit Graph(int n) : g(n), es(0) {}
size_t size() const {
return g.size();
}
void add_directed_edge(int from, int to, T cost = 1) {
g[from].emplace_back(from, to, cost, es++);
}
void add_edge(int from, int to, T cost = 1) {
g[from].emplace_back(from, to, cost, es);
g[to].emplace_back(to, from, cost, es++);
}
void read(int M, int padding = -1, bool weighted = false, bool directed = false) {
for(int i = 0; i < M; i++) {
int a, b;
cin >> a >> b;
a += padding;
b += padding;
T c = T(1);
if(weighted) cin >> c;
if(directed) add_directed_edge(a, b, c);
else add_edge(a, b, c);
}
}
};
template< typename T = TEMPT >
using Edges = vector< Edge< T > >;
#undef TEMPT
#define TEMPT long long int
template< typename T = TEMPT >
struct ShortestPath {
vector< T > dist;
vector< int > from, id;
};
template< typename T = TEMPT >
ShortestPath< T > dijkstra(const Graph< T > &g, int s) {
const auto INF = numeric_limits< T >::max();
vector< T > dist(g.size(), INFL);
vector< int > from(g.size(), -1), id(g.size(), -1);
using Pi = pair< T, int >;
priority_queue< Pi, vector< Pi >, greater<> > que;
dist[s] = 0;
que.emplace(dist[s], s);
while(!que.empty()) {
T cost;
int idx;
tie(cost, idx) = que.top();
que.pop();
if(dist[idx] < cost) continue;
for(auto &e : g.g[idx]) {
//auto next_cost = cost + e.cost;
auto next_cost = cost + calc(cost, e.cost);
if(dist[e.to] <= next_cost) continue;
dist[e.to] = next_cost;
from[e.to] = idx;
id[e.to] = e.idx;
que.emplace(dist[e.to], e.to);
}
}
return {dist, from, id};
}
#undef TEMPT
int main() {
ll nn; cin >> nn;
ll mn; cin >> mn;
ll x; cin >> x;
ll y; cin >> y;
x--; y--;
ve<vll> vv1(mn,vll(4,0));
rep(i,mn) rep(j,4) cin >> vv1[i][j];
Graph<> g1(nn);
rep(i, mn) {
auto &v1=vv1[i];
g1.add_edge(v1[0]-1, v1[1]-1, i);
t1.push_back(v1[2]);
k1.push_back(v1[3]);
}
auto p1=dijkstra(g1, x);
// 3. 各町について、1からkまで + kからnまでの最短経路を求める
ll ans=p1.dist[y];
if(ans<INFL) {
cout << ans << endl;
} else {
cout << -1 << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main(void) {
long long N, M, Q;
cin >> N >> M >> Q;
vector<pair<long long, long long>> v;
for(int i = 0; i < N; ++i) {
long long W, V;
cin >> W >> V;
v.push_back({V, W});
}
sort(v.begin(), v.end(), greater<pair<long long, long long>>());
vector<pair<long long, int>> x;
for(int i = 0; i < M; ++i) {
long long X;
cin >> X;
x.push_back({X, i + 1});
}
sort(x.begin(), x.end());
for(int q = 0; q < Q; ++q) {
long long L, R;
cin >> L >> R;
long long ans = 0;
vector<bool> used(N, false);
for(int i = 0; i < M; ++i) {
if(L <= x[i].second && x[i].second <= R) continue;
for(int j = 0; j < N; ++j) {
if(!used[j] && v[j].second <= x[i].first) {
ans += v[j].first;
used[j] = true;
break;
}
}
}
cout << ans << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define mp make_pair
#define fr first
#define sc second
int n;
ll v[400010];
int main(){
scanf("%d",&n);
for(int i=0;i<2*n;i++)scanf("%lld",&v[i]);
ll ret=0;
priority_queue<ll> que;
for(int i=0;i<n;i++){
que.push(v[i]);
que.push(v[2*n-1-i]);
ret+=que.top();
que.pop();
}
cout<<ret<<endl;
}
| #include <algorithm>
#include <any>
#include <atomic>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define int long long
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define endl '\n'
#define si(v) ((int64_t)(v).size())
#define all(v) begin(v), end(v)
#define rep(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define rep2(i, n, m) for (ll (i) = n; (i) <= (m); ++(i))
#define rep3(i, n, m) for (ll (i) = n; (i) >= (m); --(i))
#define equal(a, b) (fabs((a) - (b)) < EPS)
#define INT(...) int __VA_ARGS__; IN(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__; IN(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__; IN(__VA_ARGS__)
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpi = vector<pii>;
using vvpi = vector<vpi>;
void IN() {}
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>,greater<T>>;
template <class S, class T> inline bool chmax(S &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class S, class T> inline bool chmin(S &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template <class S, size_t N, class T> void Fill(S (&array)[N], const T &val) { fill((T*)array, (T*)(array + N), val); }
template <class S, class... T> void IN(S &a, T &... b) { cin >> a; IN(b...); }
template <class T> ostream &operator << (ostream &os, const vector<T> &v) {
for (auto itr = begin(v); itr != end(v); ++itr) {
if (itr == begin(v)) os << *itr;
else os << " " << *itr;
}
return os;
}
constexpr ll MOD = 1000000007;
/* constexpr ll MOD = 998244353; */
constexpr ll MAX = 500005;
constexpr ll INF = 2147483647;
constexpr ll INFLL = 9223372036854775807;
constexpr ld EPS = (1e-10);
signed main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed; cout.precision(20);
INT(n, k);
int ans = 0;
auto f = [&](int x) {
if (x <= 1 || x > 2*n) return 0LL;
if (x <= n) return x-1;
if (x == 2*n) return 1LL;
int diff = abs(2 * n - x);
if (diff % 2) return (diff + 1) / 2 * 2;
else return (diff / 2) * 2 + 1;
};
for (int b = 0; b + k <= 2 * n; ++b) {
int a = b + k;
if (a < 2) continue;
ans += f(a) * f(b);
}
cout << ans << endl;
return (0);
}
|
/*
Author: QAQAutoMaton
Lang: C++
Code: C.cpp
Mail: [email protected]
Blog: https://www.qaq-am.com/
*/
#include<bits/stdc++.h>
#define debug(qaq...) fprintf(stderr,qaq)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
#define x first
#define y second
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<double> cp;
typedef pair<int,int> pii;
int inf;
const double eps=1e-8;
const double pi=acos(-1.0);
template<class T,class T2>int chkmin(T &a,T2 b){return a>b?a=b,1:0;}
template<class T,class T2>int chkmax(T &a,T2 b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T,class T2>T mmin(T a,T2 b){return a<b?a:b;}
template<class T,class T2>T mmax(T a,T2 b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
template<class T>int dcmp(T a,T b){return a>b;}
template<int *a>int cmp_a(int x,int y){return a[x]<a[y];}
template<class T>bool sort2(T &a,T &b){return a>b?swap(a,b),1:0;}
#define min mmin
#define max mmax
#define abs aabs
struct __INIT__{
__INIT__(){
fill((unsigned char*)&inf,(unsigned char*)&inf+sizeof(inf),0x3f);
}
}__INIT___;
namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
// getchar
#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
// print the remaining part
inline void flush () {
fwrite (obuf, 1, oS - obuf, stdout);
oS = obuf;
}
// putchar
inline void putc (char x) {
*oS ++ = x;
if (oS == oT) flush ();
}
template<typename A>
inline bool read (A &x) {
for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;else if(c==EOF)return 0;
for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
return 1;
}
inline bool read (char &x) {
while((x=gc())==' '||x=='\n' || x=='\r');
return x!=EOF;
}
inline bool read(char *x){
while((*x=gc())=='\n' || *x==' '||*x=='\r');
if(*x==EOF)return 0;
while(!(*x=='\n'||*x==' '||*x=='\r'||*x==EOF))*(++x)=gc();
*x=0;
return 1;
}
template<typename A,typename ...B>
inline bool read(A &x,B &...y){
return read(x)&&read(y...);
}
template<typename A>
inline bool write (A x) {
if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
while (x) qu[++ qr] = x % 10 + '0', x /= 10;
while (qr) putc (qu[qr --]);
return 0;
}
inline bool write (char x) {
putc(x);
return 0;
}
inline bool write(const char *x){
while(*x){putc(*x);++x;}
return 0;
}
inline bool write(char *x){
while(*x){putc(*x);++x;}
return 0;
}
template<typename A,typename ...B>
inline bool write(A x,B ...y){
return write(x)||write(y...);
}
//no need to call flush at the end manually!
struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: read;
using io :: putc;
using io :: write;
char a[400005];
const int c3[3][3]={{1,0,0},{1,1,0},{1,2,1}};
int C(int a,int b){
if(!b)return 1;
if(!a)return 0;
return c3[a%3][b%3]*C(a/3,b/3)%3;
}
signed main(){
#ifdef QAQAutoMaton
freopen("C.in","r",stdin);
freopen("C.out","w",stdout);
#endif
int n;
read(n);
read(a);
int s=0;
for(int i=0;i<n;++i){
s+=C(n-1,i)*(a[i]=='B'?0:a[i]=='W'?1:2);
s%=3;
}
if((n-1)&1)s=(3-s)%3;
write("BWR"[s],'\n');
return 0;
}
| #include<bits/stdc++.h>
#define inf 1e18
#define endl "\n"
#define mp make_pair
#define pb push_back
#define loop(i,x,y) for(int i = x; i < y ; i++ )
#define all(x) (x).begin(),(x).end()
#define in(n) int n; cin>>n;
#define inarr(arr,n) vector<int>arr(n); for(int i = 0; i < n ; i++){cin>>arr[i];}
#define maploop(x) for(auto itr = x.begin(); itr != x.end();itr++)
#define int long long
using namespace std;
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x<<" "; _print(x); cerr << endl;
#else
#define debug(x);
#endif
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(double t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
const int N = 5;
const int mod = 3;
int fac[N];
int mul(int a, int b)
{
return (a * b) % mod;
}
void pre()
{
fac[0] = 1;
loop(i, 1, N)
{
fac[i] = mul(fac[i - 1], i);
}
}
int sub(int a, int b)
{
int l = a - b;
if (l < 0)
{
l += mod;
}
return l;
}
int pow(int a, int b)
{
int z = 1;
while (b > 0 )
{
if (b % 2)
{
z = mul(a, z);
}
a = mul(a, a);
b = b / 2;
}
return z;
}
int div(int a)
{
int ans;
return ans = pow(a, mod - 2);
}
int comb(int n, int k)
{
if (n >= k)
{
return mul(fac[n], div(mul(fac[k], fac[n - k])));
}
else
return 0;
}
int add(int a, int b)
{
a += b;
if (a > mod)
{
a -= mod;
}
return a;
}
int solve(int n, int k)
{
int ans = 1;
while (n > 0)
{
ans = ans * comb(n % 3, k % 3);
n /= 3;
k /= 3;
}
return ans;
}
void Main()
{
in(n)
string s;
cin >> s;
vector<int>arr(n);
loop(i, 0, n)
{
if (s[i] == 'R')
arr[i] = 0;
else if (s[i] == 'B')
arr[i] = 1;
else
arr[i] = 2;
}
//debug(arr)
int l = n - 1;
int ans = 0;
loop(i, 0, n)
{
int l = mul(arr[i], solve((n - 1), i));
l %= 3;
ans = add(ans, l);
debug(ans)
}
loop(i, 1, n)
{
if (ans % 2) ans += 3;
ans /= 2;
}
if (l % 2)
{
debug(ans)
// ans *= -1;
// if (ans < 0)
// {
// ans += 3;
// }
if (ans == 2)
{
cout << "W" << endl;
}
else if (ans == 1)
cout << "B" << endl;
else
cout << "R" << endl;
}
else
{
//ans %= 3;
debug(ans)
if (ans == 2)
{
cout << "W" << endl;
}
else if (ans == 1)
cout << "B" << endl;
else
cout << "R" << endl;
}
}
int32_t main()
{
pre();
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//usaco("runround");
int t = 1;
//cin >> t;
//t = 10000;
for (int i = 1; i <= t; i++)
{
//cout << "Case #" << i << ": ";
Main();
}
} |
#include <bits/stdc++.h>
using namespace std;
#define int ll
typedef long long ll;
typedef long double ld;
void print(vector<int> v) {
cout << " ---> ";
for (auto &x : v) {
cout << x << " ";
}
cout << "\n";
}
int over = 0;
vector<int> get(vector<int> a) {
vector<int> init = a;
vector<int> sol;
int n = (int) a.size(), cur = 0;
while (1) {
//cout << (int) sol.size() << " and " << cur << " | ";
//print(a);
while (1) {
bool Something = 0;
for (int i = 0; i + 1 < n; i++) {
if (i % 2 == cur && a[i] > a[i + 1]) {
sol.push_back(i);
swap(a[i], a[i + 1]);
cur ^= 1;
Something = 1;
break;
}
}
if (!Something) break;
}
bool ok = 1;
for (int i = 0; i < n; i++) {
ok &= (a[i] == i + 1);
}
if (ok) break;
bool Something = 0;
for (int i = 0; i + 1 < n; i++) {
if (a[i] > a[i + 1]) {
if (i + 2 < n) {
sol.push_back(i + 1);
swap(a[i + 1], a[i + 2]);
cur ^= 1;
Something = 1;
break;
}
if (i - 1 >= 0) {
sol.push_back(i - 1);
swap(a[i - 1], a[i]);
cur ^= 1;
Something = 1;
break;
}
}
}
if (!Something) {
cout << "bad\n";
print(a);
}
assert(Something);
}
bool ok = 1;
for (int i = 0; i < n; i++) {
ok &= (a[i] == i + 1);
}
/// over = max(over, (int) sol.size() - n * n);
ok &= ((int) sol.size() <= n * n);
if (!ok) {
cout << "bad\n";
cout << "init"; print(init);
cout << "a"; print(a);
cout << "sol"; print(sol);
exit(0);
}
assert(ok);
return sol;
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
/**
for (int len = 1; len <= 10; len++) {
over = 0;
vector<int> v(len);
iota(v.begin(), v.end(), 1);
auto it = get(v);
while (next_permutation(v.begin(), v.end())) {
it = get(v);
}
cout << "\t\t\t\t done " << len << " and " << over << "\n";
}
return 0;
**/
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
auto it = get(a);
cout << (int) it.size() << "\n";
for (auto &val : it) cout << val + 1 << " ";
cout << "\n";
}
return 0;
}
| #include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(i, v) for(auto& i : v)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
ll n;
ll solve(ll m){
if(m >= n) m -= n;
else m += n;
return m;
}
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
ll q;
string s;
cin >> n >> s >> q;
bool maki = 0;
ll t, a, b;
rep(i, q){
cin >> t >> a >> b;
a--; b--;
if(t == 1){
if(maki) {
a = solve(a);
b = solve(b);
}
swap(s[a], s[b]);
}else{
maki ^= 1;
}
}
if(maki){
cout << s.substr(n, n);
cout << s.substr(0, n) << endl;
}else{
cout << s << endl;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define author "Sihare0riginals"
#define ss string
#define lli long long int
#define ld long double
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define I(a,i) memset(a,i,sizeof(a));
#define pb push_back
#define mp make_pair
#define L(i,start,end) for(lli i=start;i<=end;i++)
#define R(i,start,end) for(lli i=start;i>=end;i--)
#define ip(n) cin>>n;lli ip[n+1];L(i,1,n)cin>>ip[i];
const lli LINF = 1e18,mod=1e9+7;
void Bl0ck_M0mb0();
signed main()
{
Bl0ck_M0mb0();
lli t=1;
//cin>>t;
while(t--){
lli n,m;
cin>>n>>m;
lli ip[n+1],ip1[m+1];
set<lli> X;
L(i,1,n)
{
cin>>ip[i];
X.insert(ip[i]);
}
L(i,1,m)
{
cin>>ip1[i];
if(X.find(ip1[i])!=X.end())
X.erase(ip1[i]);
else
X.insert(ip1[i]);
}
for(auto it:X)
cout<<it<<" ";
cout<<endl;
}
return 0;
}
void Bl0ck_M0mb0(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("ip.txt","r",stdin);
freopen("op.txt","w",stdout);
#endif
}
/*
#define dbg1D(i,start,end,arr) for(lli i=start;i<=end;i++) cout<<i<<"th : "<<arr[i]<<endl;
#define dbg2D(i,j,s1,e1,s2,e2,arr) for(lli i=s1;i<=e1;i++){cout<<i<<"th :";for(lli j=s2;j<=e2;j++)cout<<arr[i][j]<<" ";cout<<endl;}
#define M map<lli,lli> \n #define sz(s) s.size()-1
#define P pair<lli,lli>
#define V vector<lli>
lli dx[4]={-1, 0, 0, +1};
lli dy[4]={0, -1, +1, 0};
lli power(lli a,lli b,lli m){ if(b==0) return 1; if(b==1) return a%m;
lli t=power(a,b/2,m); t=(t*t)%m; if(b&1) t=(t*a)%m; return t;}
lli modInverse(lli a, lli m) { return power(a, m-2, m); } */ | #include <bits/stdc++.h>
#define pi pair<int, int>
#define pb push_back
#define l first
#define r second
using namespace std;
const int maxn = 2e5 + 1, mod = 1e9 + 7;
int n;
string s;
bool subzero[101];
vector<int> v[10001];
int a[101], b[101], vl[101], c[101];
int cc = 0;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> s;
for (int i = 0; i <= n; i++)
cin >> a[i];
for (int i = 0; i <= n; i++) {
b[i] = a[i] - (!i ? 0 : a[i - 1]);
if (b[i] < 0) subzero[i] = 1;
}
int mn = 1e9;
for (int i = 1; i <= n; i++)
mn = min(mn, abs(b[i]));
cout << mn << '\n';
for (int i = 0; i <= n; i++) {
vl[i] = b[i] / mn;
c[i] = abs(b[i]) % mn;
}
for (int i = 0; i < mn; i++) {
v[i].resize(n + 1);
for (int j = 0; j <= n; j++) {
v[i][j] = a[j] / mn;
if (i < a[j] % mn)
++v[i][j];
}
}
for (int i = 0; i < mn; i++)
for (int j = 0; j <= n; j++) {
cout << v[i][j] << (j == n ? '\n' : ' ');
}
return 0;
}
|
#include <bits/stdc++.h>
typedef long long ll;
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//
//
using namespace std;
int ctoi(char c) {
switch (c) {
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
default: return 0;
}
}
long long a,b,c,s,t,x,y,z;
long long cnt;
long double pi=3.14159265358979323846;
ll L=524288;
string N,M;
unsigned long long D;
int main(){
s=x=0;
cin>>a>>b;
vector<vector<ll>> t(51,vector<ll>(51));
vector<bool> tt(50*50);
REP(i,50){
REP(j,50){
cin>>t.at(i).at(j);
tt.at(s++)=true;
}
}
tt.at(t.at(a).at(b))=false;
if(tt.at(t.at(a+1).at(b))==true&&a<49) cout<<'D';
else if(tt.at(t.at(a).at(b+1))==true&&b<49) cout<<'R';
else if(tt.at(t.at(a-1).at(b))==true&&a>0) cout<<'U';
else if(tt.at(t.at(a).at(b-1))==true&&b>0) cout<<'L';
return 0;
}
| #include <bits/stdc++.h>
#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>
#include<time.h>
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define sz(a) ((int)a.size())
#define getmid ((l+r)>>1)
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lowbit(x) x&(-x)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
#ifdef local
#define dbg(args...) cout << #args << " -> ", err(args);
void err(){ cout << endl; }
template<typename T, typename... Args>
void err(T a, Args... args){ cout << a << ' '; err(args...); }
#else
#define dbg(args...)
#endif // local
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <int, ll> pil;
typedef pair <double, double> pdd;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-8;
const int mod=20000311;
const int maxn=2e5+100;
const int N=3e5+100;
const int M=(1<<20)+10;
const ll mm=(1LL<<32);
template <class T>
inline void read(T &x)
{
x = 0;
char c = getchar();
bool f = 0;
for (; !isdigit(c); c = getchar())
f ^= c == '-';
for (; isdigit(c); c = getchar())
x = x * 10 + (c ^ 48);
x = f ? -x : x;
}
template <class T>
inline void write(T x)
{
if (x < 0)
{
putchar('-');
x = -x;
}
T y = 1;
int len = 1;
for (; y <= x / 10; y *= 10)
++len;
for (; len; --len, x %= y, y /= 10)
putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll mod)
{
ll ans=1;
while(b)
{
if(b&1)
ans=(ans*a)%mod;
b>>=1;
a=(a*a)%mod;
}
return ans;
}
int cnt[300];
int num[20];
int main()
{
#ifdef local
freopen("in.txt","r",stdin);
#endif // local
IOS;cout.tie(0);
int tot=0;
string s;cin>>s;
int n=s.size();
rep(i,n) num[s[i]-'0']++;
if(n==1)
{
if(s[0]=='8') cout<<"Yes\n";
else cout<<"No\n";
return 0;
}
else if(n==2)
{
for(int i=10;i<=99;++i) if(i%8==0) cnt[++tot]=i;
int flag=0;
for(int i=1;i<=tot;++i)
{
int x=cnt[i]%10,y=cnt[i]/10;
num[x]--;num[y]--;
if(num[x]>=0&&num[y]>=0){
flag=1;break;
}
num[x]++;num[y]++;
}
if(flag) cout<<"Yes\n";
else cout<<"No\n";
return 0;
}
else{
for(int i=100;i<=999;++i) if(i%8==0) cnt[++tot]=i;
int flag=0;
for(int i=1;i<=tot;++i)
{
int x=cnt[i]%10;
int y=(cnt[i]/10)%10;
int z=(cnt[i])/100;
num[x]--;num[y]--;num[z]--;
if(num[x]>=0&&num[y]>=0&&num[z]>=0)
{
flag=1;break;
}
num[x]++;num[y]++;num[z]++;
}
if(flag) cout<<"Yes\n";
else cout<<"No\n";
}
return 0;
}
|
#include<bits/stdc++.h>
long long n,x;
long long ans[2],k[2],a,b,c,now;
int main()
{
scanf("%lld%lld",&n,&x);
scanf("%lld",&b);
ans[0]=1;ans[1]=0;
for(int i=1;i<n;++i)
{
scanf("%lld",&a);
c=a/b;b=a;
now=x%c;
x/=c;
k[0]=ans[0],k[1]=ans[1];
if(now)k[1]+=ans[0];
if(++now!=c)k[0]+=ans[1];
ans[0]=k[0];ans[1]=k[1];
}
printf("%lld",ans[0]+ans[1]);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; } //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
int n;
ll x;
cin >> n >> x;
if(n==1){
cout << 1 << endl;
return 0;
}
ll a[n];
rep(i,n)cin >> a[i];
ll k[n];
rep(i,n)k[i]=0;
rep(i,n-1){
k[i]=(x%a[i+1])/a[i];
x=(x/a[i+1])*a[i+1];
}
k[n-1]=x/a[n-1];
ll dp[n][3];
rep(i,n)rep(j,3)dp[i][j]=0;
if(k[0]!=0)dp[0][0]=1;
dp[0][1]=1;
rep(i,n-1){
if(k[i+1]==0){
dp[i+1][0]=dp[i][0];
dp[i+1][1]=dp[i][1]+dp[i][2];
dp[i+1][2]=dp[i][0];
}
else{
dp[i+1][0]=dp[i][0]+dp[i][1]+dp[i][2];
dp[i+1][1]=dp[i][1]+dp[i][2];
if(i!=n-2){
if(a[i+2]/a[i+1]==k[i+1]+1)dp[i+1][2]=0;
else dp[i+1][2]=dp[i][0];
}
else dp[i+1][2]=dp[i][0];
}
}
cout << dp[n-1][1]+dp[n-1][2] << endl;
//rep(i,n)cout << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << endl;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define V vector
#define debug(v) for(auto i: v) cout << i << " "; cout <<endl
#define vcin(v) rep(i, v.size()) cin >> v[i]
#define wcin(v, w) rep(i, v.size()) cin >>v[i] >>w[i]
int main(){
ll n,m;
cin >>n >>m;
V<ll> a(m);
vcin(a);
if(n==m){
cout <<0;
return 0;
}
sort(all(a));
reverse(all(a));
a.push_back(0);
reverse(all(a));
a.push_back(n+1);
V<ll> white;
rep(i,m+1)if(a[i+1]-a[i]-1>0)white.push_back(a[i+1]-a[i]-1);
sort(all(white));
ll cnt=0;
ll sz=white.size();
rep(i,sz){
ll num=(white[i]-1)/white[0]+1;
cnt+=num;
}
cout <<cnt;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
ll n,m;
cin>>n>>m;
vector<ll> a(m);
if(m==0){
cout<<1;
return 0;
}
for(int i=0;i<m;i++) cin>>a[i];
sort(a.begin(),a.end());
ll prev=0;
vector<ll> nums;
for(int i=0;i<m;i++){
ll cnt = a[i]-prev-1;
if(cnt>0) nums.push_back(cnt);
prev=a[i];
}
ll cnt= n-prev;
if(cnt>0) nums.push_back(cnt);
ll ans=0;
if(nums.size()==0) ans=0;
else{
ll mini=nums[0];
for(ll i:nums) mini=min(mini,i);
for(ll i:nums){
//cout << i <<" ";
if(i%mini==0) ans+=(i/mini);
else{
ans+=(i/mini);
ans++;
}
}
}
cout<<"\n";
cout<<ans;
return 0;
}
//1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include <bits/stdc++.h>
using namespace std;
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf LLONG_MAX
#define int long long
signed main(void)
{
int n; cin >> n;
int ans = -1;
rep (i, n)
{
int a, p, x;
cin >> a >> p >> x;
int tmp;
x -= a;
if (x > 0 && (ans > p || ans == -1)) ans = p;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int a ;
cin>>a;
vector<vector<int>> s(a,vector<int>(3));
for(int i =0;i<a;i++){
for(int j =0;j<3;j++){
cin>>s.at(i).at(j);
}}
int ans=s.at(0).at(1);
bool bo =true;
for(int i =0;i<a;i++){
if(s.at(i).at(2)-s.at(i).at(0)>0){
ans=min(s.at(i).at(1),ans);
bo=false;
}
}
if(!bo)cout<<ans<<endl;
if(bo)cout<<"-1"<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int64_t beki(int64_t n){
vector<int64_t> vec(50);
int64_t x,i,s,ans;
i=0;
ans=1;
x=1000000005;
while(x>0){
vec.at(i)=x%2;
x=x/2;
i++;
}
s=n;
for(int64_t j=0;j<50;j++){
if(vec.at(j)==1){ans=(ans*s)%1000000007;}
s=(s*s)%1000000007;
}
return ans;
}
int64_t combi(int64_t p,int64_t q){
int64_t syutu;
syutu=1;
for(int64_t j=p;j>=p-q+1;j--){syutu=(syutu*j)%1000000007;}
for(int64_t j=1;j<=q;j++){syutu=(syutu*beki(j))%1000000007;}
return syutu;
}
int main() {
int64_t p,q,a,sum;
sum=0;
int64_t n,m;
cin>>n>>m;
p=n+m;
for(int64_t i=0;i<n;i++){
cin>>a;
sum=sum+a;
}
q=n+sum;
if(p>=q){cout<<combi(p,q)<<endl;}
else{cout<<0<<endl;}
}
| #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <ctype.h>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#define INF 0x3f3f3f3f
#define eps 1e-8
// #define _
using namespace std;
typedef long long ll;
const int maxn=2e3+5;
const int mod=1e9+7;
int x[maxn];
ll fpow(ll a,ll b,ll c)
{
ll ans=1;
while(b)
{
if(b&1) ans=ans*a%c;
a=a*a%c;
b>>=1;
}
return ans;
}
ll inv(ll x)
{
return fpow(x,mod-2,mod);
}
ll C(ll n,ll m)
{
if(n<m) return 0;
m=min(m,n-m);
ll a=1,b=1;
for(int i=1;i<=m;i++)
{
a=a*(n-i+1)%mod;
b=b*i%mod;
}
return a*inv(b)%mod;
}
int main()
{
#ifdef _
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int n,m;
ll sum=0;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%d",&x[i]);
sum+=x[i];
}
printf("%lld\n",C(m+n,sum+n));
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define fp(a,i,c) for ( int (a)=(i); (a)<(c); (a)++)
#define fm(a,b,c) for ( int (a)=(b); (a)>=(c); (a)--)
char a[9999][9999];
vector <pair<int, int>> v[300];
int dis[9999][9999];
int c[999];
void S()
{
int n, m;
cin >> n >> m;
fp(i,0,n+2)
fp(j,0,m+2)
a[i][j] = '#', dis[i][j] = -1;
int s1, c1, s2, c2;
fp(i,1,n+1)
{
fp(j,1,m+1)
{
cin >> a[i][j];
if(a[i][j] == 'S')
s1 = i, c1 = j;
if(a[i][j] == 'G')
s2 = i, c2 = j;
if(a[i][j] >= 'a' && a[i][j] <= 'z')
v[a[i][j]].push_back({i,j});
}
}
queue<pair<int, int>> q;
q.push({s1,c1});
dis[s1][c1] = 0;
while(q.size())
{
int x = q.front().first, y = q.front().second;
// cout << x << " " << y << " " << a[x][y] << "\n";
q.pop();
if(a[x][y] >= 'a' && a[x][y] <= 'z')
{
c[a[x][y]] ++;
if(c[a[x][y]] == 1)
{
for(auto it : v[a[x][y]])
{
if(dis[it.first][it.second] == -1)
dis[it.first][it.second] = dis[x][y]+1, q.push({it.first, it.second});
}
}
}
for(int i = -1; i <= 1; i ++)
for(int j = -1; j <= 1; j ++)
{
if(abs(i-j) == 1)
{
if(a[x+i][y+j] != '#' && dis[x+i][y+j] == -1)
{
q.push({x+i, y+j});
dis[x+i][y+j] = dis[x][y]+1;
}
}
}
}
int ans = dis[s2][c2];
cout << ans;
}
int main()
{
IOS;
S();
}
| #include<bits/stdc++.h>
#define ll long long
using namespace std;
int read()
{
char c;
int w=1;
while((c=getchar())>'9'||c<'0')if(c=='-')w=-1;
int ans=c-'0';
while((c=getchar())>='0'&&c<='9')ans=(ans<<1)+(ans<<3)+c-'0';
return ans*w;
}
int k;
string a,b;
int t[10];
int tot1[10];
int tot2[10];
double check(int id)
{
if(t[id]<=0)return 0;
int s=0;
for(int i=1;i<=9;i++)s+=t[i];
return 1.0*t[id]/s;
}
int pows[10];
bool js()
{
int ans1=0;
for(int i=1;i<=9;i++)ans1+=i*pows[tot1[i]];
int ans2=0;
for(int i=1;i<=9;i++)ans2+=i*pows[tot2[i]];
// cout<<ans1<<" "<<ans2<<endl;
return ans1>ans2;
}
int main(){
pows[0]=1;
for(int i=1;i<=6;i++)pows[i]=pows[i-1]*10;
k=read();
for(int i=1;i<=9;i++)t[i]=k;
cin>>a>>b;
// cout<<a.size()<<endl;
for(int i=0;i<a.size()-1;i++)t[a[i]-'0']--,tot1[a[i]-'0']++;
// cout<<"qweqweqwe"<<endl;
for(int i=0;i<b.size()-1;i++)t[b[i]-'0']--,tot2[b[i]-'0']++;
double ans=0;
// cout<<js()<<endl;
// return 0;
for(int i=1;i<=9;i++)
{
if(!t[i])continue;
double now=check(i);
t[i]--;
tot1[i]++;
for(int j=1;j<=9;j++)
{
if(!t[j])continue;
tot2[j]++;
if(js())
{
ans+=now*check(j);
// cout<<i<<" "<<j<<" "<<now*check(j)<<endl;
}
tot2[j]--;
}
tot1[i]--;
t[i]++;
}
cout<<fixed<<setprecision(8)<<ans<<'\n';
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
int cnt = 0;
int tmp1 = 0;
int tmp2 = 0;
int tmp3 = 0;
while(tmp1 <= 10000){
tmp1 += 6;
if((tmp1 % 5 != 0)&&(tmp1 <= 10000)){
cout << tmp1 << " ";
cnt++;
if(cnt == N) break;
}
tmp2 += 10;
if((tmp2 % 3 != 0)&&(tmp2 <= 10000)){
cout << tmp2 << " ";
cnt++;
if(cnt == N) break;
}
tmp3 += 15;
if(tmp3 <= 10000){
cout << tmp3 << " ";
cnt++;
if(cnt == N) break;
}
}
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;
int main(){
int n; cin >> n;
VI a; a.push_back(15);
for(int i=2;i<=10000;i+=2){
if(a.size()==n)
break;
if(i%5==0||i%3==0)
a.push_back(i);
}
for(int i=45;i<=10000;i+=30){
if(a.size()==n)
break;
a.push_back(i);
}
REP(i,n)REP(j,n){
if(__gcd(a[i],a[j])==1||(i!=j&&a[i]==a[j])){
cout << "No" << endl;
return 0;
}
}
ll g=0;
REP(i,n){
g=__gcd(g,a[i]);
}
if(g!=1||a.size()!=n){
cout << "No" << endl;
return 0;
}
for(auto i:a){
cout << i << " ";
}
cout << endl;
return 0;
} |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;
using ll = long long;
using P = std::pair<ll, ll>;
constexpr ll INF = 1ll<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }
template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }
std::vector<ll> divisors( ll x ) {
std::vector<ll> ret;
for( ll i = 1; i*i <= x; ++i ) if( x%i == 0 ) {
ret.emplace_back( i );
if( i != x/i )
ret.emplace_back( x/i );
}
return ret;
}
std::map<ll, ll> prime_factor( ll x ) {
std::map<ll, ll> ret;
for( ll i = 2; i*i <= x; ++i ) {
while( x % i == 0 ) {
++ret[i];
x /= i;
}
}
if( x != 1 )
++ret[x];
return ret;
}
void sieve() {
return;
}
ll T;
int main() {
std::cin >> T;
rep( t, T ) {
ll N;
std::cin >> N;
ll cnt = 0;
while( N%2 == 0 )
N /= 2, ++cnt;
if( cnt > 1 )
std::cout << "Even" << endl;
else if( cnt == 1 )
std::cout << "Same" << endl;
else
std::cout << "Odd" << endl;
}
return 0;
} | #include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
using namespace std;
#define int long long
main() {
int t;
cin >> t;
while (t--){
int n;
cin >> n;
int cnt = 0;
while (n % 2 == 0){
n /= 2;
cnt++;
}
if (cnt == 1){
cout << "Same\n";
continue;
}
if (cnt > 1){
cout << "Even\n";
continue;
}
if (cnt == 0){
cout << "Odd\n";
continue;
}
}
return 0;
} |
#include<bits/stdc++.h>
#define MAXM 205
typedef long long ll;
using namespace std;
ll n,m;
ll cnt[3],ans;
char a[MAXM];
int main(){
cin>>n>>m;
ll zz = 0;
for(int i = 1 ; i <= n ; i++){
zz = 0;
scanf("%s" , a + 1);
for(int j = 1 ; j <= m ; j++)zz += (a[j] == '1');
zz %= 2;
if(zz % 2 == 1)ans += cnt[0];
else ans += cnt[1];
cnt[zz]++;
}
cout<<ans<<endl;
}
/*
AºÍB¿ÉÒÔÏàµÈ
cnt((A ^ B)) % 2 == 0
A + B % 2 == 0
*/ | #include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
cout<<x;
if(suc==1) cout<<'\n';
else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
for(int i=0;i<v.size();i++)
print(v[i],i==(int)(v.size())-1?suc:2);
}
const int mod=998244353;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
cin>>n>>m;
ll ans=0;
for(int i=1;i<=m;i++)
{
vc<ll> f(n+1),g(n+1),h(n+1);
f[0]=1;
for(int j=1;j<=n;j++)
{
f[j]=(f[j-1]*(m-1)%mod+g[j-1]*(i-1)%mod)%mod;
g[j]=(g[j-1]*(m-i+1)%mod+f[j-1])%mod;
h[j]=(h[j-1]*m%mod+f[j-1])%mod;
}
//dbg(i);
//dbg(f);
//dbg(g);
//dbg(h);
ans=(ans+h[n])%mod;
}
print(ans);
} |
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second
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 ? a = b, 1 : 0;}
//DEBUG TEMPLATE POCINJE OVDE
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for(auto z : x) cerr << (f++ ? "," : ""), __print(z); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if(sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef ljuba
#define debug(x...) cerr << "LINE(" << __LINE__ << ") -> " << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
//DEBUG TEMPLATE SE ZAVRSAVA OVDE
const char nl = '\n';
bool chk(int n, int baza = 10) {
while(n > 0) {
if(n % baza == 7) {
return 0;
}
n /= baza;
}
return 1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int ans = 0;
for(int i = 1; i <= n; ++i) {
if(chk(i) && chk(i, 8)) {
++ans;
}
}
cout << ans << nl;
}
| // C - Unlucky 7
#include <bits/stdc++.h>
using namespace std;
string to_oct(int i){
string r = "";
for(; i; i/=8) r += i%8 + '0';
return r;
}
int main(){
int n; cin>>n;
int ans = 0;
for(int i=1; i<=n; ++i) ans += (int)(to_string(i) + to_oct(i)).find("7") < 0;
cout<< ans <<endl;
}
|
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<vector>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (i64 i = 0; i < (i64)(n); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
vector<bool> used;
vector<vector<i64>> g;
vector<i64> a,b;
P ab = {0,0};
void dfs(i64 now){
used[now] = 1;
ab.first += a[now];
ab.second += b[now];
for(auto v:g[now]){
if(!used[v])dfs(v);
}
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 n,m;
cin >> n >> m;
g.resize(n);
a.resize(n);
b.resize(n);
used.resize(n);
rep(i,n){
cin >> a[i];
}
rep(i,n)cin >> b[i];
rep(i,m){
i64 c,d;
cin >> c >> d;
c--;
d--;
g[c].emplace_back(d);
g[d].emplace_back(c);
}
rep(i,n){
bool flag = 0;
if(!used[i]){
dfs(i);
flag = 1;
}
if(flag){
if(ab.first != ab.second){
cout << "No" << endl;
return 0;
}
ab = {0,0};
}
}
cout << "Yes" << endl;
} | #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()
int main() {
int n;
string s;
cin >> n >> s;
char cl = s.front(), cr = s.back();
if (cl != cr) cout << 1 << endl;
else {
bool ok = false;
rep3r(i, 2, n-1) {
if (s[i-1]!=cl && s[i]!=cr) {
ok = true;
break;
}
}
if (ok) cout << 2 << endl;
else cout << -1 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define fi first
#define se second
#define is_in(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define pb push_back
#define eb emplace_back
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using ll = long long;
using P = pair<int, int>;
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vs vector<string>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int n = 10;
vs g(n);
int dx[] {0, 1, 0, -1};
int dy[] {1, 0, -1, 0};
vvi seen;
int dfs(int x, int y){
int ret = 0;
seen[x][y] = 1;
rep(v, 4){
int nx = x+dx[v];
int ny = y+dy[v];
if(!is_in(nx, 0, n)) continue;
if(!is_in(ny, 0, n)) continue;
if(g[nx][ny] == 'x') continue;
if(seen[nx][ny]) continue;
ret += 1+dfs(nx, ny);
}
return ret;
}
int main()
{
ll n,k;
cin >> n >> k;
if(k < 0) k *= -1;
ll cnt = 0;
rep(i, 2*n+1){
ll A = i+1;
ll B = A+k;
if(A > 2*n) continue;
if(B > 2*n) continue;
if(A-1 <= 0) continue;
if(B-1 <= 0) continue;
ll x = A-1;
ll y = B-1;
if(A > n+1) x = 2*n-A+1;
if(B > n+1) y = 2*n-B+1;
// int x = max(1, 2*n-A);
// int y = max(1, 2*n-B);
cnt += x*y;//(2*n-A)*(2*n-B);
}
cout << cnt << endl;
return 0;
} | #include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int abs(int x){
if(x<0) return -x;
else return x;
}
int ju(int x,int y){
if(x<2||x>2*y) return 0;
else return y-abs(x-(y+1));
}
int main()
{
int n,k;scanf("%d%d",&n,&k);
ll Ans=0;
for(int i=2;i<=2*n;i++) Ans+=((ll)ju(i,n)*ju(i-k,n));
printf("%lld\n",Ans);
return 0;
} |
#include <algorithm>
#include <deque>
#include <iostream>
using namespace std;
int main() {
string S;
cin >> S;
int n = S.length();
deque<char> deq;
bool is_rev = false;
for (int i = 0; i < n; i++) {
char c = S[i];
if (c == 'R') {
is_rev = !is_rev;
} else {
if (is_rev) {
if (deq.size() >= 1 && *deq.begin() == c) {
deq.pop_front();
} else {
deq.push_front(c);
}
} else {
if (deq.size() >= 1 && *(deq.end() - 1) == c) {
deq.pop_back();
} else {
deq.push_back(c);
}
}
}
}
string T = "";
for (auto it = deq.begin(); it != deq.end(); it++) {
T += *it;
}
if (is_rev) {
reverse(T.begin(), T.end());
}
cout << T << endl;
return 0;
} | /*
author: Divy Agrawal
*/
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define bg begin
#define ed end
#define sz size
#define mkp make_pair
#define pb push_back
#define ll long long
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define fe0(i,n) for(int i=0;i<=n;i++)
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vvl vector<vl>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(x) x.bg(), x.ed()
#define allgi(x) x.bg(), x.ed(), greater<int>()
#define allgl(x) x.bg(), x.ed(), greater<ll>()
#define sorti(x) sort(all(x))
#define sortgi(x) sort(allgi(x))
#define sortgl(x) sort(allgl(x))
int main(){
int t=1;
// cin>>t;
while(t--){
string s;
cin>>s;
int cnt=0;
int n=s.sz();
string temp;
deque<char> dq;
f0(i,n){
if(s[i]=='R'){
cnt++;
cnt%=2;
}
else{
// if(cnt){
// // cout<<temp<<endl;
// temp=string(temp.rbegin(),temp.rend());
// cnt=0;
// // cout<<temp<<endl;
// }
if(cnt==0){
if(dq.empty()){
dq.push_back(s[i]);
}
else if(dq.back()==s[i]){
dq.pop_back();
}
else{
dq.push_back(s[i]);
}
}
else{
if(dq.empty()){
dq.push_back(s[i]);
}
else if(dq.front()==s[i]){
dq.pop_front();
}
else{
dq.push_front(s[i]);
}
}
// temp.pb(s[i]);
}
}
// cout<<temp<<endl;
string t1;
while(!dq.empty()){
if(cnt){
t1.pb(dq.back());
dq.pop_back();
}
else{
t1.pb(dq.front());
dq.pop_front();
}
}
// int r;
// f0(i,temp.sz()){
// // cout<<t1<<endl;
// if(i==0){
// t1.pb(temp[i]);
// r=t1.size();
// }
// else{
// // cout<<"&&"<<endl;
// if(t1[r-1]==temp[i]){
// t1.pop_back();
// r=t1.sz();
// }
// else{
// t1.pb(temp[i]);
// r=t1.size();
// }
// }
// }
cout<<t1<<endl;
}
} |
// Problem : B - Orthogonality
// Contest : AtCoder - AtCoder Beginner Contest 188
// URL : https://atcoder.jp/contests/abc188/tasks/abc188_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000009
#define rep(i,n) for (ll i = 0; i < n; i++)
#define pb push_back
#define mp make_pair
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
cin>>n;
ll ans = 0;ll a[n];ll b[n];
rep(i,n){
cin>>a[i];
}
rep(i,n){
cin>>b[i];
}
rep(i,n){
ans += (a[i]*b[i]);
}
if(ans==0){cout<<"Yes"<<endl;}
else{
cout<<"No"<<endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s; cin >> s;
if( s[0] == s[1] && s[0] == s[2] ){
cout << "Won\n";
}
else{
cout << "Lost\n";
}
}
|
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=2e5;
int n;
int a[maxn+5],b[maxn+5];
int c[maxn+5];
int p[maxn+5],id[maxn+5];
int anss;
bool used[maxn+5];
struct Ans{
int x,y;
}ans[maxn+5];
bool check(){
for(int i=1;i<=n;i++)
if(p[i]!=i&&b[p[i]]>=a[i]) return 1;
return 0;
}
bool cmp(int ta,int tb){
return a[ta]<a[tb];
}
void work(int st){
int s=0;
for(;!used[st];st=p[st]){
c[++s]=st; used[st]=1;
}
sort(c+1,c+1+s,cmp);
for(int i=1;i<s;i++){
ans[++anss]=Ans{c[i],id[c[i]]};
p[id[c[i]]]=p[c[i]];
id[p[c[i]]]=id[c[i]];
}
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
scanf("%d",&b[i]);
for(int i=1;i<=n;i++){
scanf("%d",&p[i]);
id[p[i]]=i;
}
if(check()){
printf("-1\n");
return 0;
}
for(int i=1;i<=n;i++)
if(!used[i]) work(i);
printf("%d\n",anss);
for(int i=1;i<=anss;i++)
printf("%d %d\n",ans[i].x,ans[i].y);
return 0;
}
| #include <bits/stdc++.h>
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
using namespace std;
const int maxn = 2e5+10;
int n, a[maxn], b[maxn], p[maxn];
int pre[maxn];
vector<pair<int,int> > ans;
void debug() {
printf("p: ");
REP(i,1,n) printf("%d%c", p[i], " \n"[i==n]);
printf("pre: ");
REP(i,1,n) printf("%d%c", pre[i], " \n"[i==n]);
}
void solve(int i) {
int mn = i;
vector<int> loop;
for (int x = p[i]; x != i; x = p[x]) {
if (b[p[x]] < b[p[mn]]) mn = x;
}
for (int x = pre[mn]; x != mn; x = pre[x]) {
ans.push_back(make_pair(x, p[x]));
}
for (int x = p[i]; x != i; x = p[x]) {
loop.push_back(x);
}
// printf("SOLVE: %d %d\n", i, (int)loop.size());
for (int x = 0; x < (int)loop.size(); ++x) {
p[loop[x]] = pre[loop[x]] = loop[x];
}
}
signed main() {
scanf("%d", &n);
REP(i,1,n) scanf("%d", a+i);
REP(i,1,n) scanf("%d", b+i);
REP(i,1,n) scanf("%d", p+i), pre[p[i]] = i;
REP(i,1,n) {
if (p[i] != i && b[p[i]] >= a[i]) {
puts("-1");
return 0;
}
}
REP(i,1,n) if (p[i] != i) solve(i);
printf("%d\n", (int)ans.size());
REP(i,0,(int)ans.size()-1) {
printf("%d %d\n", ans[i].first, ans[i].second);
}
} |
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double db;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for(i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define at(s,pos) *(s.find_by_order(pos))
#define set_ind(s,val) s.order_of_key(val)
long long int M = 1e9 + 7 ;
long long int inf = 9 * 1e18;
const double PI = acos(-1);
//CLOCK
ll begtime = clock();
#define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//CLOCK ENDED
ll n, m;
// modular exponentiation
ll binpow(ll val, ll deg)
{
if (deg < 0)
return 0;
if (!deg)
return 1 % M;
if (deg & 1)
return binpow(val, deg - 1) * val % M;
ll res = binpow(val, deg >> 1);
return (res * res) % M;
}
//binomial
ll modinv(ll n) {
return binpow(n, M - 2);
}
void google(ll x) {
cout << "Case #" << x << ": ";
}
int main() {
// your code goes here
IOS;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll i, j, t, k, x, y, z, N;
cin >> n;
ll a[n];
rep(i, n) {
cin >> a[i];
}
//even length ke liye ending at even pos
v<ll> b;
for (i = 1; i < n; i += 2) {
b.pb(a[i] - a[i - 1]);
}
//number of segments with sum=0
map<ll, ll> ma;
ll ans = 0;
ll sum = 0;
for (auto u : b) {
sum += u;
ans += ma[sum];
ma[sum]++;
}
ans += ma[0];
//even length ke liye ending at odd pos
b.clear();
for (i = 2; i < n; i += 2) {
b.pb(a[i] - a[i - 1]);
}
ma.clear();
sum = 0;
for (auto u : b) {
sum += u;
ans += ma[sum];
ma[sum]++;
}
ans += ma[0];
//odd length ending at even pos
ma.clear();
sum = 0;
rep(i, n) {
if (i % 2 == 0) {
y = sum - a[i];
if (y == 0) ans++;
ans += ma[y];
}
else {
sum += (a[i] - a[i - 1]);
ma[sum]++;
}
}
ma.clear();
sum = 0;
for (i = 1; i < n; i++) {
if (i % 2) {
y = sum - a[i];
// cout << y << ' ';
if (y == 0) ans++;
ans += ma[y];
}
else {
sum += a[i] - a[i - 1];
ma[sum]++;
}
}
cout << ans;
return 0;
}
| #include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>
#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>
#define sqr(x) (x) * (x)
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double lld;
using namespace std;
using namespace std::chrono;
const ll mod = 1'000'000'000ll + 7;
//const ll mod = 998'244'353ll;
const ll inf = 1'000'000'000'000'000'000ll;
const long double eps = 1e-15;
int main(int argc, char* argv[]) {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cerr.precision(15); cerr.setf(ios::fixed);
ll n;
cin >> n;
vector<ll> a(n + 1);
for (ll i = 1; i <= n; i++) {
cin >> a[i];
if (i % 2) {
a[i] *= -1;
}
}
vector<ll> ps(n + 1);
for (ll i = 1; i <= n; i++) {
ps[i] = ps[i - 1] + a[i];
}
map<ll, ll> q;
for (ll i = 1; i <= n; i++) {
q[ps[i]] += 1;
}
ll R = 0;
for (ll i = 1; i <= n; i++) {
R += q[ps[i - 1]];
q[ps[i]] -= 1;
}
cout << R << endl;
return 0;
} |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
constexpr int INF = 1001001001;
constexpr long long INFL = (1LL<<60);
constexpr double eps = (1e-9);
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin >> s;
for (int i = s.size() - 1; i >= 0; i--) {
if (s[i] != '0') break;
else s.pop_back();
}
string r = s;
reverse(r.begin(), r.end());
if (r == s) puts("Yes");
else puts("No");
return 0;
}
| #include <iostream>
#include <vector>
#define int long long
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int n;
std::cin >> n;
int dp[n+1];
dp[0] = 0;
std::vector<int> poss(26, n+1);
std::string s;
std::cin >> s;
for(int i = 1; i <= n; i++) {
int j = s[i-1]-'a';
dp[i] = n+1;
for(int k = 0; k < 26; k++) {
if(k == j)
continue;
dp[i] = std::min(dp[i], 1 + poss[k]);
}
if(dp[i-1] != n+1)
poss[j] = std::min(poss[j], dp[i-1]);
}
if(dp[n] >= n+1)
std::cout << -1 << std::endl;
else
std::cout << dp[n] << std::endl;
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.