code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
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() {
LL N, C;
cin >> N >> C;
vector<LL> a(N), b(N), c(N);
set<LL> zipped;
LL M = -1;
REP(i, N) {
cin >> a[i] >> b[i] >> c[i];
b[i]++;
zipped.insert(a[i]);
zipped.insert(b[i]);
}
map<LL, int> dic;
map<int, LL> inv;
int n = 0;
for(auto i : zipped) {
dic[i] = n;
inv[n] = i;
n++;
}
vector<LL> cost(dic.size() + 1, 0);
REP(i, N) {
cost[dic[a[i]]] += c[i];
cost[dic[b[i]]] -= c[i];
}
FOR(i, 1, dic.size() + 1) {
cost[i] += cost[i - 1];
}
REP(i, dic.size() + 1) {
cost[i] = min(cost[i], C);
}
LL s = 0;
REP(i, dic.size()) {
s += (inv[i + 1] - inv[i])*cost[i];
}
cout << s << 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<int, int>;
double dp[105][105][105];
int main() {
ll A, B, C;
cin >> A >> B >> C;
for (int i = 0; i <= 100; i++) {
for (int j = 0; j <= 100; j++) {
for (int k = 0; k <= 100; k++) {
dp[i][j][k] = 0;
}
}
}
dp[A][B][C] = 1;
for (int i = A; i <= 100; i++) {
for (int j = B; j <= 100; j++) {
for (int k = C; k <= 100; k++) {
if (i != A && j != 100 && k != 100) {
dp[i][j][k] += dp[i - 1][j][k] * (i - 1) / (i + j + k - 1);
}
if (j != B && k != 100 && i != 100) {
dp[i][j][k] += dp[i][j - 1][k] * (j - 1) / (i + j + k - 1);
}
if (k != C && i != 100 && j != 100) {
dp[i][j][k] += dp[i][j][k - 1] * (k - 1) / (i + j + k - 1);
}
}
}
}
double ans = 0;
rep(i, 100) rep(j, 100) {
ans += dp[i][j][100] * (i + j + 100 - (A + B + C));
ans += dp[i][100][j] * (i + j + 100 - (A + B + C));
ans += dp[100][i][j] * (i + j + 100 - (A + B + C));
}
cout << fixed << setprecision(8) << ans << endl;
// for (int i = 98; i <= 99; i++) {
// for (int j = 98; j <= 99; j++) cout << dp[100][i][j] << " ";
// cout << endl;
// }
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=200005,INF=1<<30;
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int Q;cin>>Q;
while(Q--){
int N;cin>>N;
vector<int> p(N+1);
for(int i=0;i<N;i++) cin>>p[i+1];
vector<int> ans;
if(N==2){
if(p[1]==1){
cout<<0<<endl;
cout<<endl;
}else{
cout<<1<<endl;
cout<<1<<endl;
}
continue;
}
int t=1;
for(int i=1;i<=N-3;i++){
int pos=-1;
for(int j=i;j<=N;j++){
if(p[j]==i){
pos=j;
break;
}
}
if(pos==i){
for(int j=i+1;j<N;j++){
if((j&1)==(t&1)){
ans.push_back(j);
swap(p[j],p[j+1]);
t++;
break;
}
}
}else{
if((pos&1)==(i&1)){
for(int j=i;j<N;j++){
if((j&1)==(t&1)&&j!=pos){
ans.push_back(j);
swap(p[j],p[j+1]);
t++;
break;
}
}
}
for(int j=pos-1;j>=i;j--){
ans.push_back(j);
swap(p[j],p[j+1]);
t++;
}
}
}
if(p[N-2]==N-2){
if(p[N-1]==N){
ans.push_back(N-2);
ans.push_back(N-1);
ans.push_back(N-2);
ans.push_back(N-1);
ans.push_back(N-2);
}
}else{
if(p[N-1]==N-2){
ans.push_back(N-2);
swap(p[N-2],p[N-1]);
t++;
}else{
ans.push_back(N-2);
swap(p[N-2],p[N-1]);
t++;
ans.push_back(N-1);
swap(p[N-1],p[N]);
t++;
ans.push_back(N-2);
swap(p[N-2],p[N-1]);
t++;
}
if(p[N-1]==N){
ans.push_back(N-1);
}
}
cout<<si(ans)<<endl;
for(int a:ans) cout<<a<<" ";
cout<<endl;
}
}
| #include<bits/stdc++.h>
#define rep(i, n) for (int i = 0, length = n; i < length; i++)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ep emplace
#define epb emplace_back
#define scll static_cast<long long>
#define sz(x) static_cast<int>((x).size())
#define pfll(x) printf("%lld\n", x)
#define ci(x) cin >> x
#define ci2(x, y) cin >> x >> y
#define ci3(x, y, z) cin >> x >> y >> z
#define ci4(w, x, y, z) cin >> w >> x >> y >> z
#define co(x) cout << x << endl
#define co2(x, y) cout << x << " " << y << endl
#define co3(x, y, z) cout << x << " " << y << " " << z << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> PQ;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
typedef priority_queue<P> PQP;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;
const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9;
int t, n[250];
vector<int> v[250], ans[250];
int main() {
ci(t);
rep(i, t) {
ci(n[i]);
rep(j, n[i]) {
int p;
ci(p);
v[i].epb(p - 1);
}
}
rep(i, t) {
if (n[i] == 2) {
if (v[i][0]) ans[i].epb(1);
continue;
}
vector<int> memo(n[i]);
rep(j, n[i]) memo[v[i][j]] = j;
int cnt = 0;
rep(j, n[i] - 3) {
int a = memo[j];
if (a == j) continue;
if (cnt % 2 == a % 2) {
cnt++;
if (a > j + 1) {
swap(v[i][a - 2], v[i][a - 1]);
swap(memo[v[i][a - 2]], memo[v[i][a - 1]]);
ans[i].epb(a - 1);
}
else if (a + 3 < n[i]) {
swap(v[i][a + 2], v[i][a + 3]);
swap(memo[v[i][a + 2]], memo[v[i][a + 3]]);
ans[i].epb(a + 3);
}
else {
ans[i].epb(a + 1);
ans[i].epb(a);
ans[i].epb(a + 1);
swap(v[i][a - 1], v[i][a + 1]);
swap(memo[v[i][a - 1]], memo[v[i][a + 1]]);
cnt += 2;
}
}
for (int k = a - 1; k >= j; k--) {
memo[v[i][k]]++;
swap(v[i][k], v[i][k + 1]);
cnt++;
ans[i].epb(k + 1);
}
memo[j] = j;
}
for (bool j = (cnt + n[i] + 1) % 2; v[i][n[i] - 3] != n[i] - 3 ||
v[i][n[i] - 2] != n[i] - 2 ||
v[i][n[i] - 1] != n[i] - 1; j = !j) {
swap(v[i][n[i] - 3 + j], v[i][n[i] - 2 + j]);
ans[i].epb(n[i] - 2 + j);
}
}
rep(i, t) {
co(ans[i].size());
rep(j, ans[i].size() - 1) cout << ans[i][j] << " ";
if (ans[i].empty()) cout << endl;
else cout << ans[i].back() << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
// freopen("input.in", "r", stdin);
int n, k, m;
scanf("%d %d %d", &n, &k, &m);
m *= n;
for (int i = 1; i < n; ++i) {
int a;
scanf("%d", &a);
m -= a;
}
m = max(m, 0);
if (m <= k)
printf("%d\n", m);
else
puts("-1");
return 0;
}
| #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
int main() {
int n,k,m;
cin>>n>>k>>m;
vi a(n-1);
int sum=0;
rep(i,n-1) {
cin>>a[i];
sum+=a[i];
}
int ja=m*n-sum;
if(ja>k){
cout<<-1<<endl;
return 0;
}
if(ja<=0){
cout<<0<<endl;
return 0;
}
cout<<ja<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define FIO ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
#define int long long
#define mod 1000000007
typedef vector<int> vi;
typedef vector<bool> vb;
#define ff first
#define ss second
#define pb push_back
#define Pob pop_back
#define mp make_pair
void solve() {
int n; cin >> n;
int a;
int ans = 0;
for (int i = 0; i < n; i++) {
cin >> a;
if (a > 10) {
ans += a - 10;
}
}
cout << ans;
}
int32_t main() {
FIO
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// cin >> t;
while (t--)solve();
return 0;
}
| #include <bits/stdc++.h>
const int N = 2*100000;
char S1[N + 5], S2[N + 5], S3[N + 5];
bool tag[4];
void solve() {
int n; scanf("%d%s%s%s", &n, S1, S2, S3);
for(int o=0;o<4;o++) tag[o] = 0;
tag[(S1[0] - '0') << 1 | (S1[2*n - 1] - '0')] = true;
tag[(S2[0] - '0') << 1 | (S2[2*n - 1] - '0')] = true;
tag[(S3[0] - '0') << 1 | (S3[2*n - 1] - '0')] = true;
if( !tag[0] ) {
for(int i=0;i<n;i++) putchar('0');
putchar('1');
for(int i=0;i<n;i++) putchar('0');
puts("");
} else if( !tag[3] ) {
for(int i=0;i<n;i++) putchar('1');
putchar('0');
for(int i=0;i<n;i++) putchar('1');
puts("");
} else if( !tag[2] ) {
putchar('0');
for(int i=0;i<n;i++) putchar('1');
for(int i=0;i<n;i++) putchar('0');
puts("");
} else {
putchar('1');
for(int i=0;i<n;i++) putchar('0');
for(int i=0;i<n;i++) putchar('1');
puts("");
}
}
int main() {
int T; scanf("%d", &T);
while( T-- ) solve();
} |
#include<bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define N 2005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
string s[2005];
int h,w;
ll dp[N][N][5];
bool valid(int i,int j)
{
return i>=0&&i<h&&j>=0&&j<w&&s[i][j]=='.';
}
ll run(int i,int j,int c)
{
if(i==h-1&&j==w-1)
{
return 1;
}
if(dp[i][j][c]!=-1)
return dp[i][j][c];
ll ans=0;
if(c==0)
{
if(valid(i,j+1)) ans=(ans+run(i,j+1,1));
if(valid(i+1,j)) ans=(ans+run(i+1,j,2));
if(valid(i+1,j+1)) ans=(ans+run(i+1,j+1,3));
}
else if(c==1)
{
ans=(ans+run(i,j,0));
if(valid(i,j+1)) ans=(ans+run(i,j+1,1));
}
else if(c==2)
{
ans=(ans+run(i,j,0));
if(valid(i+1,j)) ans=(ans+run(i+1,j,2));
}
else if(c==3)
{
ans=(ans+run(i,j,0));
if(valid(i+1,j+1)) ans=(ans+run(i+1,j+1,3));
}
ans%=M;
return dp[i][j][c]=ans;
}
main()
{
memset(dp,-1,sizeof dp);
cin>>h>>w;
for(int i=0;i<h;i++)
cin>>s[i];
cout<<run(0,0,0);
}
| #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
#include<time.h>
#include<deque>
#include<cstring>
#define ll long long
#define DB double
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pf push_front
#define MOD (ll)(998244353)
#define INF (ll)(1e9)
#define M 5000005
#define AC ios::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class T> using PQ=priority_queue<T,vector<T>,greater<T> >;
ll fpow(ll x,ll y){
ll r=1;
while(y){
if(y&1){
r*=x;
r%=MOD;
}
x=x*x%MOD;
y>>=1;
}
return r;
}
ll gcd(ll x,ll y){
if(x<y) swap(x,y);
return y?gcd(y,x%y):x;
}
ll dp[105][10005],s[105];
signed main(){
AC;
s[0]=1;
FOR(i,1,101) s[i]=(s[i-1]*i)%MOD;
int n,w[105],sum=0;
cin>>n;
FOR(i,1,n+1){
cin>>w[i];
sum+=w[i];
}
if(sum&1) {
cout<<0<<endl;
return 0;
}
sum/=2;
dp[0][0]=1;
FOR(i,1,n+1)for(int j=i;j>0;j--)for(int k=sum;k>=w[i];k--) dp[j][k]=(dp[j][k]+dp[j-1][k-w[i]])%MOD;
ll ans=0;
FOR(i,1,n){
ll tmp=s[i]*s[n-i]%MOD;
tmp*=dp[i][sum];
tmp%=MOD;
ans=(ans+tmp)%MOD;
}
cout<<ans<<endl;
}
|
/**
* Author: Daniel
* Created Time: 2021-01-24 23:19:13
**/
// time-limit: 2000
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ER erase
#define IS insert
#define PI acos(-1)
#define PB pop_back
#define EB emplace_back
#define lowbit(x) (x & -x)
#define SZ(x) ((int)x.size())
#define MP(x, y) make_pair(x, y)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define SOS; ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<fixed<<setprecision(10);
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef unsigned long long ULL;
template <typename A> using VE = vector<A>;
template <typename A> using USET = unordered_set<A>;
template <typename A> using HEAP = priority_queue<A>;
template <typename A, typename B> using PA = pair<A, B>;
template <typename A, typename B> using UMAP = unordered_map<A, B>;
template <typename A> using RHEAP = priority_queue<A, vector<A>, greater<A> >;
///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////
// check the limitation!!!
const int N = 100010, M = 1010;
char a, b, c;
// read the question carefully!!!
int main()
{
SOS;
cin >> a >> b >> c;
if (a == b && b == c) cout << "Won\n";
else cout << "Lost\n";
return 0;
}
// GOOD LUCK!!!
| //A
#include<bits/stdc++.h>
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)
using namespace std;
bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }
const string YES = "";
const string NO = "";
typedef long long ll;
typedef pair<int,int> ii;
void solve() {
}
int main() {
string s;
cin >> s;
if( s[0] == s[1] && s[1] == s[2] ) puts("Won");
else puts("Lost");
return 0;
}
|
#include <bits/stdc++.h>
#define clog(x) std::clog << (#x) << " is " << (x) << '\n';
using LL = long long;
const int N = 2002;
struct Edge {
int to;
LL c, d;
Edge(int x, LL y, LL z) : to(x), c(y), d(z) {}
};
const LL INF = 1e18;
int main() {
//freopen("in", "r", stdin);
std::cin.tie(nullptr)->sync_with_stdio(false);
int cas = 1;
// std::cin >> cas;
while (cas--) {
int n, m;
std::cin >> n >> m;
std::vector<std::vector<Edge>> e(n);
for (int i = 0, u, v; i < m; ++i) {
LL c, d;
std::cin >> u >> v >> c >> d;
if (--u == --v) continue;
e[u].emplace_back(v, c, d);
e[v].emplace_back(u, c, d);
}
auto f = [&](LL c, LL d, LL t) -> LL {
int sn = std::sqrt(d);
if (t > sn) return c + t + d / (t + 1);
return c + sn + std::min(d / (sn + 1), d / (sn + 2) + 1);
};
std::vector<LL> dist(n, INF);
dist[0] = 0;
std::priority_queue<std::pair<LL, int>> Q;
Q.push({0, 0});
while (!Q.empty()) {
auto [du, u] = Q.top();
Q.pop();
if (du != -dist[u]) continue;
for (auto [v, c, d] : e[u]) {
LL now = f(c, d, -du);
if (dist[v] > now) {
dist[v] = now;
Q.push({-now, v});
}
}
}
std::cout << (dist[n - 1] == INF ? -1 : dist[n - 1]) << '\n';
}
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
template <class T>
using idx_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define ull unsigned long long
#define arr array
#define vt vector
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define all(v) (v).begin(), (v).end()
#define pi acosl(-1)
//ofstream out("debug.txt");
const int MxN = 1e5, md = 1e9 + 7;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, C;
cin >> n >> C;
vt<arr<ll, 2>> v;
ll a, b, c;
for (int i = 0; i < n; ++i)
cin >> a >> b >> c, v.push_back({a, c}), v.push_back({b + 1, -c});
sort(all(v));
ll cf = 0, tf = 0, ld = 0;
for (auto a : v)
{
tf += min(cf, C) * (a[0] - ld);
cf += a[1];
ld = a[0];
}
cout << tf << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T, class U>
void chmin(T& t, const U& u) {
if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
if (t < u) t = u;
}
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 << "{";
rep(i, v.size()) {
if (i) os << ",";
os << v[i];
}
os << "}";
return os;
}
#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << H;
debug_out(T...);
}
#define debug(...) \
cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
int main() {
int N;
cin >> N;
V<int> A(N), B(N);
rep(i, N) cin >> A[i];
rep(i, N) cin >> B[i];
ll ans = 0;
ll s = 0;
V<ll> v1, v2;
rep(i, N) {
s += A[i];
if (i & 1) {
v1.pb(A[i] - B[i]);
} else {
v2.pb(A[i] - B[i]);
}
}
sort(ALL(v1));
sort(ALL(v2));
ans = s;
rep(i, N / 2) {
s -= v1[i] + v2[i];
chmax(ans, s);
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
#define pu push
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define rrep(i,x) for(int i=1;i<=x;i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define BITSC(x,v) (binary_search(x.begin(),x.end(),v)
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}
const double eps =1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
int main(){
int n;cin>>n;
vi a(n);
vi b(n);
rep(i,n){
cin>>a[i];
b[i]=i+1;
}
sort(rng(a));
bool flag=1;
rep(i,n){
if(a[i]!=b[i])flag=0;
}
if(flag)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
} |
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_ll.hpp>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1e9+7;
#define f first
#define s second
#define pii pair< ll, ll >
#define vi vector<ll>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc ll t; cin >> t; while(t--)
// using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
vector<vector<pii>> adj;
vector<ll> store;
void dfs(ll u,ll p){
for(auto i:adj[u]){
if(i.f!=p){
store[i.f]=store[u]^i.s;
dfs(i.f,u);
}
}
}
void solve(){
ll n,x,y,w;
cin>>n;
adj=vector<vector<pii>>(n);
store=vector<ll>(n,0);
rep(i,0,n-1){
cin>>x>>y>>w;
adj[x-1].pb({y-1,w});
adj[y-1].pb({x-1,w});
}
dfs(0,0);
ll dp[61],dp1[61];
rep(i,0,61) dp[i]=0,dp1[i]=0;
ll ans=0,c1,c2;
rep(j,0,61){
c1=0,c2=0;
rep(i,0,n){
if( store[i] & (1LL<<j)) c1++;
else c2++;
}
ll z=1LL<<j;
z%=mod;
ans=(ans+(((z*c1)%mod)*c2)%mod)%mod;
}
cout<<ans<<endl;
}
int main(){
optimizeIO();
solve();
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=205;
int n,a[N];
vector<int>v,res1,res2;
vector<int>save[N];
bool flag;
void dfs(int cur,int sum){
sum%=200;
if(flag) return;
if(cur==n+1){
if(save[sum].size()&&v.size()){
flag=true;
res1=save[sum];
res2=v;
}
else save[sum]=v;
return;
}
dfs(cur+1,sum);
v.push_back(cur);
dfs(cur+1,sum+a[cur]);
v.pop_back();
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
dfs(1,0);
if(flag){
puts("Yes");
cout<<res1.size()<<" ";
for(int i=0;i<res1.size();i++) cout<<res1[i]<<" ";
puts("");
cout<<res2.size()<<" ";
for(int i=0;i<res2.size();i++) cout<<res2[i]<<" ";
}
else puts("No");
return 0;
}
/*
鸽巢原理
如果n个巢里有kn+1个鸽子,那么至少有一个巢里面有kn+1个鸽子
*/
|
// <Rahil Malhotra / ViciousCoder>
#include "bits/stdc++.h"
using namespace std;
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double
int32_t main()
{
IOS;
int n;
cin>>n;
int mul=1;
int fl=0;
for(int i=1;;i++)
{
mul*=3ll;
int temp=n-mul;
if(temp<5)
break;
int ctr=0;
while(temp%5==0)
{
temp/=5;
ctr++;
}
if(temp!=1 || ctr==0)
continue;
cout<<i<<" "<<ctr<<endl;
fl=1;
break;
}
if(!fl)
cout<<-1;
} | #include<bits/stdc++.h>
using namespace std;
long long n;
long long m3[40],m5[30];
int main(){
scanf("%lld",&n);
m3[0]=1ll;m5[0]=1ll;
for(int i=1;i<=38;i++) m3[i]=m3[i-1]*3;
for(int i=1;i<=26;i++) m5[i]=m5[i-1]*5;
for(int i=1;i<=38;i++) for(int j=1;j<=26;j++) if(m3[i]+m5[j]==n){
printf("%d %d\n",i,j);
return 0;
}
puts("-1");
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define light ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pb push_back
#define cases() ll t;cin>>t;while(t--)
#define all(c) c.begin(),c.end()
#define PI 3.14159265358979323846
const ll MAX = 2e5+5;
const ll INF = 1e18;
const ll MOD = 1e9+7;
int main()
{
ll i,j,k,l,p,q,x,y,n;
cin >> n;
multiset<pair<ll,pair<ll,ll>>> mp;
p = 0;
for(i=0;i<n;i++)
{
cin >> x >> y;
mp.insert({2*x+y,{x,y}});
p+=x;
}
l = 0;k = 0;
while(l<=p)
{
pair<ll,ll> pi = mp.rbegin()->second;
x = pi.first;y = pi.second;
p = p-x;l = l+x+y;
k++;
mp.erase(prev(mp.end()));
}
cout << k;
} | //#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].l+tr[u].r>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;
//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const int N=200010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;
int n;
struct Node
{
LL a,b;
bool operator < (const Node&W) const
{
return a*2+b>W.a*2+W.b;
}
}node[N];
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
scanf("%d",&n);
LL sum=0,ans=0;
for(int i=1;i<=n;i++) scanf("%lld%lld",&node[i].a,&node[i].b),sum+=node[i].a;
sort(node+1,node+1+n);
int res=0;
for(int i=1;i<=n;i++)
{
ans+=node[i].a*2+node[i].b;
res++;
if(ans>sum) break;
}
printf("%d\n",res);
return 0;
}
/*
*/
|
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define fd(i,a,b) for(int i=(a);i>=(b);--i)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 2e5 + 5;
int n;
int a[maxn], b[maxn], lg[maxn], st[maxn][22];
void init() {
fo(i, 1, n)st[i][0] = a[i];
fo(i, 2, n)lg[i] = lg[i >> 1] + 1;
for (int j = 1; j <= lg[n]; ++j) {
for (int i = 1; i + (1 << j) - 1 <= n; ++i) {
st[i][j] = max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
}
}
}
int f(int l, int r) {
int k = lg[r - l + 1];
return max(st[l][k], st[r - (1 << k) + 1][k]);
}
int main() {
IOS;
cin >> n;
fo(i, 1, n)cin >> a[i];
fo(i, 1, n)cin >> b[i];
init();
ll ans = 0;
fo(i, 1, n) {
ans = max(ans, 1ll * f(1, i) * b[i]);
cout << ans << endl;
}
return 0;
}
/*
*/ | #include <bits/stdc++.h>
#include <vector>
#include <string>
using namespace std;
#define int long long
#define ld long double
#define vint vector<int>
#define vpair vector<pair<int, int>>
#define vvec vector<vector<int>>
#define vvpair vector<vector<pair<int, int>>>
#define qint queue<int>
#define pint pair<int, int>
#define ps(x,y) fixed<<setprecision(y)<<x
#define all(x) x.begin(), x.end()
#define revall(x) x.rbegin(), x.rend()
#define in(v, s, e) for(int i = s; i<e; i++){cin >> v[i];}
#define out(v, s, e) for(int i = s; i<e; i++){cout << v[i];}
const int mod = 1e9 + 7;
const int MAX = 1e18;
int sol(int n)
{
int ans = 1;
while(n > 0)
{
ans *= 10;
n--;
}
return ans;
}
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int ans = 0;
int x = log10(n);
while(x >= 3)
{
// cout << n << " " << x << endl;
int y = sol(x);
// cout << y << endl;
ans += (n - y + 1)*(x/3);
// cout << y << " " << x << " " << ans << endl;
n = y;
n--;
x--;
}
cout << ans;
} |
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
int main(){
double n,ans=0; cin >> n;
for(int i=1; i<n; i++){
ans += n/i;
}
cout << fixed << setprecision(15) << ans << endl;
}
| #pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
// include
#include <bits/stdc++.h>
using namespace std;
// 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();
}
// change
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
// math
template <class T>
inline T sqr(T x) {
return x * x;
}
template <class T>
inline T nCr(T n, T r) {
T num = 1;
for (int i = 1; i <= r; ++i) {
num *= (n - i + 1) / i;
}
return num;
}
template <class T>
inline T nPr(T n, T r) {
r = n - r;
T sum = 1;
int i;
for (i = n; i >= r + 1; --i) sum *= i;
return sum;
}
template <class T>
inline T facctorial(T k) {
T sum = 1;
for (int i = 1; i <= k; ++i) {
sum *= i;
}
return sum;
}
// numeric
template <class T>
inline T gcd(T a, T b) {
if (a < b) {
a ^= b;
b ^= a;
a ^= b;
}
return b ? gcd(b, a % b) : a;
}
template <class T>
inline T lcm(T a, T b) {
return a * b / gcd(a, b);
}
// using
using VI = vector<int>;
using VVI = vector<VI>;
using VS = vector<string>;
using PII = pair<int, int>;
using LL = int64_t;
// container util
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) static_cast<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())
// repetition
#define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); ++i)
#define REP(i, n) FOR(i, 0, n)
// constant
constexpr double EPS = 1e-10;
const double PI = acos(-1.0);
constexpr LL INF = 1e10;
// 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;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int N;
cin >> N;
double ans = 0;
for (int i = 1; i < N; i++) {
ans += 1.0 * N / (N - i);
}
printf("%.10f\n", ans);
return 0;
}
|
#pragma GCC optimize("Ofast")
//#pragma GCC target ("sse4")
#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<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#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 all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);
ll mod_pow(ll x, ll n, ll m = mod) {
if (n < 0) {
ll res = mod_pow(x, -n, m);
return mod_pow(res, m - 2, m);
}
if (abs(x) >= m)x %= m;
if (x < 0)x += m;
ll res = 1;
while (n) {
if (n & 1)res = res * x % m;
x = x * x % m; n >>= 1;
}
return res;
}
struct modint {
ll n;
modint() :n(0) { ; }
modint(ll m) :n(m) {
if (n >= mod)n %= mod;
else if (n < 0)n = (n % mod + mod) % mod;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
if (n == 0)return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[a - b];
}
void solve() {
int n; cin >> n;
int ans = mod;
rep(i, n) {
int a, p, x; cin >> a >> p >> x;
if (a < x) {
ans = min(ans, p);
}
}
if (ans == mod)ans = -1;
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(5);
//init_f();
//init();
//expr();
//int t; cin >> t; rep(i,t)
solve();
return 0;
} | #include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>
using namespace std;
class DisjointSet {
public:
DisjointSet(int n) : N(n), sz(n), pars(n, -1) {
}
void reset() { sz = N, fill(pars.begin(), pars.end(), -1); }
int find(int x) { return pars[x] < 0 ? x : pars[x] = find(pars[x]); }
int size() { return sz; }
int count(int x) { return -pars[find(x)]; }
bool unite(int x, int y) {
x = find(x), y = find(y);
if (x == y) { return false; }
--sz;
if (pars[x] < pars[y]) { swap(x, y); }
pars[y] += pars[x];
pars[x] = y;
return true;
}
private:
int N, sz;
vector<int> pars;
};
int main(int argc, char** argv) {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(12);
int n;
cin >> n;
vector<int> X(n);
vector<int> Y(n);
for (int i = 0; i < n; ++i) {
cin >> X[i] >> Y[i];
}
long double eps = 1e-9;
long double lo = 0, hi = 100;
int rnd = 150;
DisjointSet ds(n + 2);
int s = n, t = n + 1;
auto ok = [&](long double r) {
ds.reset();
for (int i = 0; i < n; ++i) {
if (Y[i] - 2 * r - (-100) < eps) {
ds.unite(i, s);
}
if (100 - (Y[i] + 2 * r) < eps) {
ds.unite(i, t);
}
}
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
auto d = hypot(X[i] - X[j], Y[i] - Y[j]);
if (d <= 2 * r + eps) {
ds.unite(i, j);
}
}
}
return ds.find(s) != ds.find(t);
};
while (rnd-- > 0) {
auto mi = (lo + hi) / 2;
if (ok(mi)) {
lo = mi;
} else {
hi = mi;
}
}
cout << lo << '\n';
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)
template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;
#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif
const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
int main() {
ll N, K;
cin >> N >> K;
vvc<ll> T(N, vl(N));
rep(i, N) rep(j, N) cin >> T[i][j];
vl A(N);
iota(all(A), 0ll);
ll ans = 0;
do{
if (A[0] != 0) continue;
ll t = 0;
rep(i, N - 1) t += T[A[i]][A[i + 1]];
t += T[A[N - 1]][A[0]];
if (t == K) ans++;
} while (next_permutation(all(A)));
cout << ans << endl;
} | //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v){
if(v.empty()){
os<<"{ }";
return os;
}
os<<"{"<<v.front();
for(auto itr=++v.begin();itr!=v.end();itr++){
os<<", "<<*itr;
}
os<<"}";
return os;
}
template<typename T_first,typename T_second>
ostream& operator<<(ostream& os,const pair<T_first,T_second>& P){
os<<"("<<P.first;
os<<", "<<P.second;
os<<")";
return os;
}
int main(){
int a,b; cin>>a>>b;
cout<<(a+b)/2<<" "<<(a-b)/2<<endl;
} |
#include<bits/stdc++.h>
using namespace std;
signed main(){
int n;
int a;
bool f=false;
map<int,int> v;
cin>>n;
for(int i=0;i<n;i++){
cin>>a;
v[a]++;
if(v[a]!=1) f=true;
}
if(f) cout<<"No\n";
else cout<<"Yes\n";
} | #include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#define ordered_set tree<int, null_type, less<int >,rb_tree_tag, tree_order_statistics_node_update>
//using namespace __gnu_pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ll long long
#define ld long double
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vii vector<int>
#define vll vector<ll>
#define clr(v, d) memset(v,d,sizeof(v))
using namespace std;
const int N = 2e5 + 9;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin>>n;
set<int>st;
for (int i = 0; i < n; ++i) {
int a;
cin>>a;
st.insert(a);
}
vector<int>v;
v.assign(all(st));
if(v.size()!=n||v[0]!=1)cout<<"No\n";
else{
for(int i=1;i<n;i++){
if(v[i]-v[i-1]!=1)return cout<<"No\n",0;
}
cout<<"Yes\n";
}
return 0;
} |
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#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 rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define forn(i, n) rep(i, 0, n)
#define rof(i, n) per(i, n, 0)
#define forone(i, n) for (int i = 1; i <= (n); ++i)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define ff first
#define ss second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define int long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define setbits(x) __builtin_popcountll(x)
#define zerbefone(x) __builtin_ctzll(x)
#define pqb priority_queue<int> // maxheap
#define pqs priority_queue<int, vector<int>, greater<int>> // minheap
#define piipqs priority_queue<pii, vector<pii>, greater<pii>> // minheap for pair<int,int>
#define piipqb priority_queue<pii> // maxheap for pair<int,int>
#define mod 1000000007 //1e9+7
#define mod1 998244353
#define inf 2000000000000000000 //2e18
#define PI 3.141592653589793238
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define meminf(a) memset(a, 0x7f, sizeof(a))
#define precise(x, y) fixed << setprecision(y) << x
#define FastIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
// #define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 rng(61378913);
/* usage - just do rng() */
// *************************** Code Begins **************************** //
void solve()
{
string str;
cin>>str;
reverse(all(str));
forn(i,str.size())
{
if(str[i]=='6')
str[i] = '9';
else if (str[i] == '9')
str[i] = '6';
}
cout<<str;
}
signed main()
{
FastIO;
int tt = 1;
// cin >> tt;
for (int i = 1; i <= tt; i++)
solve();
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
typedef complex<double> Point;
const ll mod = 1e9 + 7;
const double Pi = 3.14159265358979;
int run_test(){
string s;
cin >> s;
reverse(s.begin(), s.end());
for(int i = 0; i < s.length(); i++){
if(s[i]=='6'){
s[i]='9';
}
else if(s[i] == '9'){
s[i]='6';
}
}
cout << s;
return 0;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int tt;
tt = 1;
while(tt--){
run_test();
}
} |
#include <bits/stdc++.h>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
int main() {
int N;
cin>>N;
N*=1.08;
if(N<206)cout<<"Yay!"<<endl;
else if(N==206)cout<<"so-so"<<endl;
else cout<<":("<<endl;
} | #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <complex>
#include <regex>
#define Debug cout << "line: " << __LINE__ << "Debug" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;
#define ALL(a) (a).begin(), (a).end()
#define MP make_pair
#define MOD 1000000007
#define PI 3.14159265358979323846
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vd = vector<double>;
using vl = vector<long long>;
void set_FPD(int n){
cout << fixed << setprecision(n);
return;
}
void Main(){
int n;
cin>>n;
if(floor(n*1.08)<206) cout<<"Yay!"<<endl;
else if(floor(n*1.08)>206) cout<<":("<<endl;
else cout<<"so-so"<<endl;
return;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
Main();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,tune=native")
#define ll long long
#define int ll
#define ull unsigned ll
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
//#define inf 1010000000
#define inf 4000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(vector<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(set<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 826
#endif
template<typename T> void print(T && x) {cout << x << "\n";}
template<typename T, typename... S> void print(T && x, S&&... y) {cout << x << ' ';print(y...);}
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
const int maxn=505;
//i_am_noob
#define wiwihorz
int n,a[maxn];
vector<int> res;
void op(int x){
if((x+sz(res))&1){
bug(x,sz(res));
}
if(sz(res)==60604) bug(x);
assert((x+1+sz(res))&1);
res.pb(x+1);
swap(a[x],a[x+1]);
}
void report(){
print(sz(res));
for(auto i: res) print0(i);
cout << "\n";
}
void orzck(){
res.clear();
cin >> n;
rep(n) cin >> a[i];
rep(n) a[i]--;
if(n<=3){
while(!is_sorted(a,a+n)){
if(sz(res)&1) op(1);
else op(0);
}
report();
return;
}
rep3(i,n-1,4){
int pos;
rep1(j,n) if(a[j]==i) pos=j;
if((pos+sz(res))&1){
if(sz(res)&1) op(pos==2?3:1);
else op(pos==1?2:0);
}
rep2(j,pos,i) op(j);
}
bug(sz(res));
rep(n) bug(a[i]);
int pos;
if(sz(res)&1) op(1);
rep(4) if(a[i]==3) pos=i;
if((pos+1+sz(res))&1){
rep2(i,pos,3) op(i);
}
else if(pos<3){
op(2);
rep2(i,pos,3) op(i);
}
rep(n) bug(a[i]);
while(!is_sorted(a,a+n)){
if(sz(res)&1) op(1);
else op(0);
}
assert(is_sorted(a,a+n));
report();
}
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
#ifdef i_am_noob
freopen("input1.txt","r",stdin);
freopen("output1.txt","w",stdout);
freopen("output2.txt","w",stderr);
#endif
cout << fixed << setprecision(15);
int t;
#ifdef wiwihorz
cin >> t;
#else
t=1;
#endif
while(t--) orzck();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define x first
#define y second
const int N = 2e5 + 10;
int a[N], res[N], pos[N];
void Swap(int p, int &idx) {
swap(pos[a[p]], pos[a[p + 1]]);
swap(a[p], a[p + 1]);
res[idx++] = p;
}
void solve() {
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
pos[a[i]] = i;
}
int idx = 1;
for(int i = n; i >= 1; i--) {
if(a[i] == i) continue;
while(idx % 2 != pos[i] % 2) {
if(idx & 1) Swap(1, idx);
else Swap(2, idx);
}
while(pos[i] != i) {
Swap(pos[i], idx);
}
}
printf("%d\n", idx - 1);
for(int i = 1; i < idx; i++) {
printf("%d ", res[i]);
}
puts("");
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
int t; cin >> t; while(t--)
solve();
return 0;
}
|
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cctype>
#include <cmath>
#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <queue>
#include <ctime>
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
inline int read_int(){
int t=0;bool sign=false;char c=getchar();
while(!isdigit(c)){sign|=c=='-';c=getchar();}
while(isdigit(c)){t=(t<<1)+(t<<3)+(c&15);c=getchar();}
return sign?-t:t;
}
inline LL read_LL(){
LL t=0;bool sign=false;char c=getchar();
while(!isdigit(c)){sign|=c=='-';c=getchar();}
while(isdigit(c)){t=(t<<1)+(t<<3)+(c&15);c=getchar();}
return sign?-t:t;
}
inline char get_char(){
char c=getchar();
while(c==' '||c=='\n'||c=='\r')c=getchar();
return c;
}
inline void write(LL x){
char c[21],len=0;
if(!x)return putchar('0'),void();
if(x<0)x=-x,putchar('-');
while(x)c[++len]=x%10,x/=10;
while(len)putchar(c[len--]+48);
}
inline void space(LL x){write(x),putchar(' ');}
inline void enter(LL x){write(x),putchar('\n');}
const int MAXN=3005,Mod=998244353;
int dp[MAXN][MAXN];
int dfs(int n,int k){
if(k>n)return 0;
if(n==0||k==0)return n==0&&k==0;
if(~dp[n][k])return dp[n][k];
return dp[n][k]=(dfs(n-1,k-1)+dfs(n,k<<1))%Mod;
}
int main()
{
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
int n=read_int(),k=read_int();
mem(dp,-1);
enter(dfs(n,k));
return 0;
} | #include <stdio.h>
#include <bits/stdc++.h>
#define ll long long int
#define inf 1000000000000
#define mod 998244353
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define ps(x, y) fixed << setprecision(y) << x
using namespace std;
void solve()
{
ll n, kl;
cin >> n >> kl;
vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 0));
dp[1][1] = 1;
for(int i=2;i<=n;i++)
{
for(int k=i;k>=1;k--)
{
dp[i][k] = (dp[i][k] + dp[i - 1][k - 1] + (2 * k <= i ? dp[i][2 * k] : 0)) % mod;
}
}
cout << dp[n][kl] << endl;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int t = 1;
// cin>>t;
while (t--)
{
solve();
}
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
int main(){
int n; cin>>n;
int cnt=1000000001;
rep(i,n){
int a,p,x; cin>>a>>p>>x;
if(x-a>0) cnt=min(cnt,p);
}
if(cnt!=1000000001) cout<<cnt<<endl;
else cout<<-1<<endl;
} | #include<bits/stdc++.h>
using namespace std;
#define MAXN 100005
#define lowbit(x) (x&-x)
#define reg register
#define mkpr make_pair
#define fir first
#define sec second
typedef long long LL;
typedef unsigned long long uLL;
const int INF=0x3f3f3f3f;
const int mo=998244353;
const LL jzm=2333;
const int iv2=499122177;
const double Pi=acos(-1.0);
typedef pair<int,int> pii;
const double PI=acos(-1.0);
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
template<typename _T>
void read(_T &x){
_T f=1;x=0;char s=getchar();
while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();}
while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();}
x*=f;
}
template<typename _T>
void print(_T x){if(x<0){x=(~x)+1;putchar('-');}if(x>9)print(x/10);putchar(x%10+'0');}
int n,minn;
struct ming{int a,p,x;}s[MAXN];
signed main(){
read(n);minn=INF;
for(int i=1;i<=n;i++)read(s[i].a),read(s[i].p),read(s[i].x);
for(int i=1;i<=n;i++)if(s[i].x>s[i].a)minn=min(s[i].p,minn);
if(minn>INF-1)puts("-1");else printf("%d\n",minn);
return 0;
}
|
#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_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 pi 3.14159265358979323846264338327950288419716939937510
#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;
//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);
}
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], b[n];
ll p[n];
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
rep(i, n) {
cin >> p[i];
p[i]--;
}
ll flg = 0;
rep(i, n) {
if (a[i] <= b[p[i]] && p[i] != i)flg = 1;
}
if (flg) cout << "-1";
else {
v<pll> vec;
rep(i, n) {
vec.eb(a[i], i);
}
sortv(vec);
map<ll, ll> ma;
rep(i, n) {
ma[p[i]] = i;
}
v<pll> out;
for (auto u : vec) {
x = ma[u.se];
if (x == u.se) continue;
else {
ma[p[u.se]] = x;
ma[p[x]] = u.se;
swap(p[x], p[u.se]);
out.eb(u.se + 1, x + 1);
}
}
cout << out.size() << '\n';
for (auto u : out) cout << u.fi << ' ' << u.se << '\n';
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
namespace Sakurajima_Mai{
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(int i=a,bbb=b;i<=bbb;++i)//attention reg int or reg ll ?
#define repd(i,a,b) for(int i=a,bbb=b;i>=bbb;--i)
#define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define ce(i,r) i==r?'\n':' '
#define pb push_back
#define all(x) x.begin(),x.end()
#define gmn(a,b) a=min(a,b)
#define gmx(a,b) a=max(a,b)
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const int infi=2e9;//infi较大,注意涉及inf相加时爆int
const ll infl=4e18;
inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; }
inline ll pos_mod(ll a,ll b){ return (a%b+b)%b; }
//std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0));
}
using namespace Sakurajima_Mai;
namespace Fast_Read{
inline int qi(){
int f=0,fu=1; char c=getchar();
while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
return f*fu;
}
inline ll ql(){
ll f=0;int fu=1; char c=getchar();
while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
return f*fu;
}
inline db qd(){
char c=getchar();int flag=1;double ans=0;
while((!(c>='0'&&c<='9'))&&c!='-') c=getchar();
if(c=='-') flag=-1,c=getchar();
while(c>='0'&&c<='9') ans=ans*10+(c^48),c=getchar();
if(c=='.'){c=getchar();for(int Bit=10;c>='0'&&c<='9';Bit=(Bit<<3)+(Bit<<1)) ans+=(double)(c^48)*1.0/Bit,c=getchar();}
return ans*flag;
}
}
namespace Read{
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define rai(x,a,b) repi(i,a,b) x[i]=qi()
#define ral(x,a,b) repi(i,a,b) x[i]=ql()
}
namespace Out{
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define ps(x) printf("%s",x)
#define pc(x) printf("%c",x)
#define pe() puts("")
}
namespace DeBug{
#define MARK false
#define DB if(MARK)
#define pr(x) cout<<#x<<": "<<x<<endl
#define pra(x,a,b) cout<<#x<<": "<<endl; \
repi(i,a,b) cout<<x[i]<<" "; \
puts("");
#define FR(a) freopen(a,"r",stdin)
#define FO(a) freopen(a,"w",stdout)
}
using namespace Fast_Read;
using namespace Read;
using namespace Out;
using namespace DeBug;
const int MAX_N=2e5+5;
const int mod=1e9+7;
char s[MAX_N];
int n,num[MAX_N],k;
int dp[MAX_N][17];
int main()
{
ss(s+1),si(k);
n=strlen(s+1);
repi(i,1,n) num[i]=isdigit(s[i])?s[i]-'0':s[i]-'A'+10;
int sta=0;
repi(i,0,n-1){
repi(j,1,16){
dp[i+1][j]=(1ll*dp[i+1][j]+1ll*dp[i][j]*j%mod)%mod;
dp[i+1][j+1]=(1ll*dp[i+1][j+1]+1ll*dp[i][j]*(16-j)%mod)%mod;
}
dp[i+1][1]=(1ll*dp[i+1][1]+1ll*dp[i][0]*15%mod)%mod;
dp[i+1][0]=1;
repi(j,0,num[i+1]-1)if(i||j){
int nxt=sta|1<<j;
dp[i+1][__builtin_popcount(nxt)]++;
}
sta|=1<<num[i+1];
}
pl(pos_mod(dp[n][k]+(__builtin_popcount(sta)==k),mod)),pe();
return 0;
} |
/**
* Dont raise your voice, improve your argument.
* --Desmond Tutu
*/
#include <bits/stdc++.h>
using namespace std;
const bool ready = [](){
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(12);
return true;
}();
using ld=long double;
const ld PI = acos((ld)-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)
#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) ld d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }
using pii= pair<int, int>;
using pdd= pair<ld, ld>;
using vd= vector<ld>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;
#define endl "\n"
void solve() {
cini(a);
cini(b);
cini(c);
cini(d);
int ans=b-c;
cout<<ans<<endl;
}
signed main() {
solve();
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,d;
cin >> a >> b >> c >> d;
cout << b - c << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define pb push_back
#define ss second
#define ff first
#define all(v) v.begin(), v.end()
#define deb(x) cerr << "\n" \
<< #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n" \
<< #x << "=" << x << "\n" \
<< #y << "=" << y << "\n";
#define w(x) \
int x; \
cin >> x; \
while (x--)
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,k;
cin >> n >> k;
vector<pair<int,int>> v(k);
for(int i = 0; i < k; ++i)
cin >> v[i].ff >> v[i].ss;
sort(all(v));
set<int> can;
can.insert(n);
for(int i = 0; i < k;) {
vector<int> rem,add;
int temp = v[i].ff;
while(i < k && v[i].ff == temp) {
int l = can.count(v[i].ss - 1);
int r = can.count(v[i].ss + 1);
if(l + r == 0)
rem.push_back(v[i].ss);
else add.pb(v[i].ss);
i++;
}
for(int j: rem)
can.erase(j);
for(int j: add)
can.insert(j);
}
cout << can.size();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct P {
bool operator<(const P &p) const {
return x != p.x ? x < p.x : y < p.y;
}
int x, y;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
int l = m + 1;
vector<P> p;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
y += l - n;
if (!(0 <= y && y <= l * 2)) continue;
p.push_back({ x, y });
}
sort(p.begin(), p.end());
vector<int> c(l * 2 + 1, 0);
c[l] = 1;
int x0 = -10, y0 = -10, c0 = -10;
for (const auto &[x, y] : p) {
int c1 = (x0 == x && y0 == y - 1) ? c0 : c[y - 1];
x0 = x;
y0 = y;
c0 = c[y];
c[y] = c1 | c[y + 1];
}
int r = 0;
for (const auto &i : c) {
r += i;
}
cout << r << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int _ = (cout << fixed << setprecision(9), cin.tie(0), ios::sync_with_stdio(0));
using Int = long long;
int main() {
Int N; cin >> N;
const int M = 44;
vector<Int> X(M), Y(M);
for (int i = 0; i < M; i++) {
// X = X + 1
X[i] = 1;
if (i + 1 == M) break;
// Y = X + Y
for (int j = 0; j < M; j++) {
Y[j] += X[j];
}
// X = X + Y
for (int j = 0; j < M; j++) {
X[j] += Y[j];
}
}
vector<Int> A(M);
for (int i = 0; i < M; i++) {
while (X[i] <= N) {
A[i]++;
N -= X[i];
}
}
vector<int> op;
for (int i = 0; i < M; i++) {
for (int j = 0; j < A[i]; j++) {
op.push_back(1);
}
if (i + 1 == M) break;
op.push_back(4);
op.push_back(3);
}
cout << op.size() << '\n';
for (auto x : op) cout << x << '\n';
return 0;
}
| #include <bits/stdc++.h>
int ri() {
int n;
scanf("%d", &n);
return n;
}
template<int mod>
struct ModInt{
int x;
ModInt () : x(0) {}
ModInt (int64_t x) : x(x >= 0 ? x % mod : (mod - -x % mod) % mod) {}
ModInt &operator += (const ModInt &p){
if ((x += p.x) >= mod) x -= mod;
return *this;
}
ModInt &operator -= (const ModInt &p) {
if ((x += mod - p.x) >= mod) x -= mod;
return *this;
}
ModInt &operator *= (const ModInt &p) {
x = (int64_t) x * p.x % mod;
return *this;
}
ModInt &operator /= (const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt &operator ^= (int64_t p) {
ModInt res = 1;
for (; p; p >>= 1) {
if (p & 1) res *= *this;
*this *= *this;
}
return *this = res;
}
ModInt operator - () const { return ModInt(-x); }
ModInt operator + (const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator - (const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator * (const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator / (const ModInt &p) const { return ModInt(*this) /= p; }
ModInt operator ^ (int64_t p) const { return ModInt(*this) ^= p; }
bool operator == (const ModInt &p) const { return x == p.x; }
bool operator != (const ModInt &p) const { return x != p.x; }
explicit operator int() const { return x; }
ModInt &operator = (const int p) { x = p; return *this;}
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
a -= t * b;
std::swap(a, b);
u -= t * v;
std::swap(u, v);
}
return ModInt(u);
}
friend std::ostream & operator << (std::ostream &stream, const ModInt<mod> &p) {
return stream << p.x;
}
friend std::istream & operator >> (std::istream &stream, ModInt<mod> &a) {
int64_t x;
stream >> x;
a = ModInt<mod>(x);
return stream;
}
};
typedef ModInt<1000000007> mint;
template<int mod> struct MComb {
using mint = ModInt<mod>;
std::vector<mint> fact;
std::vector<mint> inv;
MComb (int n) { // O(n + log(mod))
fact = std::vector<mint>(n + 1, 1);
for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * mint(i);
inv.resize(n + 1);
inv[n] = fact[n] ^ (mod - 2);
for (int i = n; i--; ) inv[i] = inv[i + 1] * mint(i + 1);
}
mint ncr(int n, int r) {
return fact[n] * inv[r] * inv[n - r];
}
mint npr(int n, int r) {
return fact[n] * inv[n - r];
}
mint nhr(int n, int r) {
assert(n + r - 1 < (int) fact.size());
return ncr(n + r - 1, r);
}
};
int main() {
int64_t n;
std::cin >> n;
int T = 87;
int64_t fib[T];
fib[0] = fib[1] = 1;
for (int i = 2; i < T; i++) fib[i] = fib[i - 1] + fib[i - 2];
std::vector<int> demand;
for (int i = T; i--; ) {
if (n >= fib[i]) n -= fib[i], demand.push_back(i);
}
int top = demand.front();
demand.erase(demand.begin());
std::vector<int> res;
for (int i = 0; i <= top; i++) {
int command;
if (i == 0) command = 1;
else if (i == 1) command = 2;
else command = ((top ^ i) & 1) ? 4 : 3;
res.push_back(command);
if (std::count(demand.begin(), demand.end(), top - i)) res.push_back(command == 4 ? 2 : 1);
}
printf("%d\n", (int) res.size());
for (auto i : res) printf("%d\n", i);
/*
int64_t x = 0;
int64_t y = 0;
for (auto i : res) {
if (i == 1) x++;
else if (i == 2)y++;
else if (i == 3) x += y;
else y += x;
}
printf("%" PRId64 " %" PRId64 "\n", x, y);*/
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
const int N=111;
int n,vis[N][N],now,sum[N];
char a[N][N];
void dfs(int x){sum[x]++;vis[now][x]=1;
for(int i=1;i<=n;i++){if(a[x][i]=='1'&&!vis[now][i])
dfs(i);
}
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)scanf("%s",a[i]+1);
for(int i=1;i<=n;i++)now=i,dfs(i);double ans=0;
for(int i=1;i<=n;i++){
ans+=1.0/sum[i];
}printf("%.10lf",ans);
} | #include<bits/stdc++.h>
using namespace std;
const int N = 100;
char mat[N][N];
int n;
int tout[N];
bool used[N];
int timer = 0;
int colored[N];
int c = 0;
set <int> g[N];
int _sz[N], _sz1[N];
void dfs(int v)
{
used[v] = 1;
for(int i = 0; i < n; i++)
{
if(mat[v][i] == '1' && !used[i])
{
dfs(i);
}
}
tout[v] = timer++;
}
void dfs1(int v)
{
colored[v] = c;
used[v] = 1;
_sz[c]++;
for(int i = 0; i < n; i++)
{
if(mat[i][v] == '1' && !used[i])
{
dfs1(i);
}
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
cin >> mat[i][j];
}
}
for(int i = 0; i < n; i++)
{
if(!used[i])
{
dfs(i);
}
}
vector <pair <int, int> > mass;
for(int i = 0; i < n; i++)
{
used[i] = 0;
mass.push_back({tout[i], i});
}
sort(mass.begin(), mass.end());
for(int i = mass.size() - 1; i >= 0; i--)
{
int v = mass[i].second;
if(used[v])
{
continue;
}
dfs1(v);
c++;
}
set <int> g1[N];
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
if(mat[i][j] == '1')
{
g[colored[i]].insert(colored[j]);
g1[colored[j]].insert(colored[i]);
}
}
}
double ans = 0;
for(int i = 0; i < c; i++)
{
for(int j = 0; j < c; j++)
{
used[j] = 0;
}
queue <int> q;
q.push(i);
used[i] = 1;
int _sz2 = 0;
while(q.size() != 0)
{
int v = q.front();
q.pop();
if(v != i)
{
_sz2 += _sz[v];
}
set <int> :: iterator it;
for(it = g1[v].begin(); it != g1[v].end(); it++)
{
if(!used[*it])
{
used[*it] = 1;
q.push(*it);
}
}
}
double pw = 1;
for(int j = 0; j <= n - _sz2 - _sz[i]; j++)
{
ans += pw * _sz[i] * 1.0 / (n - j);
pw = pw * (n - j - _sz[i] - _sz2) * 1.0 / (n - j);
}
}
cout << fixed << setprecision(10) << ans;
return 0;
}
|
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 200005;
const ll inf = 1e18 + 5;
int n, m;
ll a[maxn];
ll b[maxn];
ll pref[maxn];
ll sufi[maxn];
int main()
{
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
cin >> n >> m;
ff(i,1,n)cin >> a[i];
ff(i,1,m)cin >> b[i];
sort(a + 1, a + n + 1);
// cout << endl;
// ff(i,1,n)cout << a[i] << " ";
// cout << endl;
// cout << endl;
ff(i,1,n)pref[i] = pref[i - 1] + (i % 2 == 1 ? -a[i] : a[i]);
fb(i,n,1)sufi[i] = sufi[i + 1] + (i % 2 == 1 ? a[i] : -a[i]);
// ff(i,1,n)cout << pref[i] << " ";
// cout << endl;
// ff(i,1,n)cout << sufi[i] << " ";
// cout << endl;
ll rez = inf;
ff(i,1,m){
ll x = b[i];
int l = 1, r = n, ans = 0;
while(l <= r){
int mid = (l + r) / 2;
if(a[mid] <= x){
ans = mid;
l = mid + 1;
}
else r = mid - 1;
}
// cout << "ans: " << ans << endl;
ans += (ans % 2 == 0);
ll kol = pref[ans - 1] + abs(x - a[ans]) + sufi[ans + 1];
// cout << "kol: " << kol << endl;
rez = min(rez, kol);
}
cout << rez << endl;
return 0;
}
/**
// probati bojenje sahovski ili slicno
**/
|
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define debug(...) fprintf(stderr, __VA_ARGS__);
#define rep(i, j, k) for(int i = j; i <= k; ++ i)
#define per(i, j, k) for(int i = j; i >= k; -- i)
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
const int N = 4e5 + 10;
const int mod = 1e9 + 7;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 Rand(seed);
uniform_int_distribution<ll> ran(0, 1ll << 62);
void ucin() {
ios::sync_with_stdio(0); cin.tie(0);
}
// uniform_real_distribution<double> dbran;
template<class T> inline void chkmax(T &x, const T &y) { if(x < y) x = y; }
template<class T> inline void chkmin(T &x, const T &y) { if(x > y) x = y; }
inline ll sqr(ll x) { return x * x; }
inline ll cub(ll x) { return x * x * x; }
int main() {
ucin();
int n, s, d, ans = 0;
cin >> n >> s >> d;
rep(i, 1, n) {
int x, y;
cin >> x >> y;
if(x < s && y > d) {
ans = 1;
}
}
cout << (ans ? "Yes" : "No") << endl;
return 0;
} |
//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
int N, M;
int to[400005], ne[400005], c[200005], he[100001];
int kotae[100001];
const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
if (ci - owa > 0) {
memcpy(cn, owa, CL);
ci -= CM;
fread(cn + CL, 1, CM, stdin);
}
ll tmp = *(ll*)ci;
int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
tmp = tmp << dig & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
ci += 72 - dig >> 3;
return tmp;
}
const int MAX = 1000;
class shuturyoku_unko {
public:
char C[MAX * 4];
constexpr shuturyoku_unko() : C() {
rep(i, MAX) {
int X = i;
rep(j, 3) {
C[i * 4 + 2 - j] = '0' + X % 10;
X /= 10;
}
C[i * 4 + 3] = ' ';
}
}
};
constexpr shuturyoku_unko f;
const int dm = 1 << 17;
char* dn = cn, * di = dn, * owad = dn + dm - 20;
void putint(int A) {
if (owad < di) {
fwrite(dn, 1, di - dn, stdout);
di = dn;
}
if (A >= 1000) {
int dig = 1;
if (A >= 100000) dig = 3;
else if (A >= 10000) dig = 2;
memcpy(di, f.C + A / 1000 * 4 + 3 - dig, dig);
memcpy(di + dig, f.C + A % 1000 * 4, 4);
di += dig + 4;
}
else {
int dig = 1;
if (A >= 100) dig = 3;
else if (A >= 10) dig = 2;
memcpy(di, f.C + A * 4 + 3 - dig, dig + 1);
di += dig + 1;
}
}
int main() {
//cin.tie(0);
//ios::sync_with_stdio(false);
N = getint();
M = getint();
int k = 2;
rep1(i, M) {
int u = getint(), v = getint();
c[i] = getint();
to[k] = v;
ne[k] = he[u];
he[u] = k++;
to[k] = u;
ne[k] = he[v];
he[v] = k++;
}
int Q[100001], q = 0;
Q[q++] = 1;
kotae[1] = 1;
while (q) {
int tmp = Q[--q];
int oya = kotae[tmp];
for (int k = he[tmp]; k; k = ne[k]) {
int t = to[k];
if (!kotae[t]) {
int e = c[k >> 1];
kotae[t] = e + (oya == e);
Q[q++] = t;
}
}
}
rep1(i, N) putint(kotae[i] - ((kotae[i] > N) << 1));
fwrite(dn, 1, di - dn, stdout);
Would you please return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep0(i, n) for (ll i = 0; i <= (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep1(i, n) for (ll i = (n); i > 0; --i)
#define rrep0(i, n) for (ll i = (n); i >= 0; --i)
#define srep(i, s, t) for (ll i = s; i < t; ++i)
#define srep1(i, s, t) for (ll i = s; i <= t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cerr << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
constexpr ll MAX = 200002;
int main()
{
ll n;
cin >> n;
vl a(MAX, 0);
ll b = 0, maxb = 0, sum = 0, ans = 0;
rep1(i, n) cin >> a[i];
rep1(i, n)
{
b += a[i];
maxb = max(maxb, b);
ans = max(ans, sum + maxb);
sum += b;
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll ;
int main(){
double n , d , h;
cin >> n >> d >> h ;
vector<double> D(n) , H(n) ;
double a = h / d ;
double ans = 0 ;
rep(i,n){
cin >> D[i] >> H[i] ;
if( a *(d - D[i]) > h - H[i] ){
a = ( h - H[i] ) / ( d - D[i] ) ;
ans = h - d * a ;
}
}
cout << ans << endl ;
} | //a.9
#include<bits/stdc++.h>
#define ll long long
#define all(x) x.begin(),x.end()
#define CASE(t) cout<<"Case #"<<(t)<<": ";
#define endll endl
#define endl '\n'
#define mod 1000000007
#define INF 1e18
#define maxN 500005
#define deb(x) cout << "[" << (#x) << "=" << x << "]" << '\n'
#define deb2(x,y) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "]" << '\n'
#define deb3(x,y,z) cout << "[" << (#x) << "=" << x << "] [" << (#y) << "=" << y << "] [" << (#z) << "=" << z << "]" << '\n'
#define popcnt __builtin_popcountll
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
ll ceill(ll a,ll b){return a/b+bool(a%b);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b, a % b);}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll power(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x)%mod;x=(x*x)%mod;y>>=1;}return res;}
void bin(unsigned n,string &str){str="";if(n>1)bin(n>>1,str);str+=to_string(n&1);}
bool isPrime(ll n)
{
if(n<=1)return false;if(n<=3)return true;if(n%2==0 || n%3==0)return false;
for(ll i=5;i*i<=n;i=i+6)if(n%i==0 || n%(i+2)==0) return false; return true;
}
vector<ll> primeFactors(ll n)
{
vector<ll>vec;
while(n%2==0)vec.push_back(2),n/=2;
for(ll i=3;i<=sqrt(n);i+=2)while(n%i==0)vec.push_back(i),n/=i;
if(n>2)vec.push_back(n);
return vec;
}
vector<ll>primes;
void SieveOfEratosthenes()
{
bool prime[maxN];primes.clear();
memset(prime, true, sizeof(prime));
for(ll i=2;i*i<maxN;i++)if(prime[i]==true)for(ll j=i*i;j<maxN;j+=i)prime[j]=false;
for(ll i=2;i<maxN;i++)if(prime[i])primes.push_back(i);
}
//vector<ll>fact(maxN);
//void factpre(){fact[0]=1;for(ll i=1;i<maxN;i++)fact[i]=(fact[i-1]*1LL*i);}
//ll mul(ll a,ll b){return (a*1LL*b)%mod;}
//ll nCr(ll n,ll k){return mul(fact[n],power(mul(fact[k],fact[n-k]),mod-2));}
void solve()
{
double n,d,h;cin>>n>>d>>h;
double ans=0;
for(double i=0;i<n;i++)
{
double di,hi;cin>>di>>hi;
double tmp=(d*double(hi)-double(di)*h)/double(d-di);
ans=max(ans,tmp);
}
cout<<fixed<<setprecision(12)<<ans<<endl;
}
signed main()
{
ios;
ll tc=1; //cin>>tc;
for(ll t=1;t<=tc;t++)
{
//CASE(t);
solve();
}
}
|
// clang-format off
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
using namespace std;
using namespace __gnu_pbds;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;
template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
// clang-format on
int main() {
fastio();
int n;
cin >> n;
cout << (n % 2 ? "Black" : "White") << endl;
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
long long ret = 1;
for (long long i = 2; i <= n; i++)ret = ret * i / __gcd(ret, i);
cout << ret + 1 << endl;
return 0;
} |
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cfenv>
#include <cmath>
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) a.begin(),a.end()
#define P pair<long,long>
#define INF 10000000000000000
#define EX 100000000000000000
using namespace std;
struct edge{long to,cost,k;};
int main() {
int N;cin>>N;
vector<long> a(N);
vector<long> t(N);
rep(i,N)cin>>a[i]>>t[i];
int Q;cin>>Q;
vector<long> x(Q);
rep(i,Q)cin>>x[i];
long U=INF;
long M=0;
long D=-INF;
rep(i,N){
long A=a[N-i-1],T=t[N-i-1];
if(T==1){
D-=A;U-=A;M+=A;
}
if(T==2){
if(A>D)D=A;
if(D>U)D=U;
}
if(T==3){
if(A<U)U=A;
if(D>U)U=D;
}
}
rep(i,Q){
if(x[i]<D)cout<<D+M<<endl;
else if(x[i]>U)cout<<U+M<<endl;
else cout<<x[i]+M<<endl;
}
}
| #define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
struct fast_ios {
fast_ios() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
};
} fast_ios_;
int main() {
int cas;
cin >> cas;
while (cas--) {
int n;
cin >> n;
string A, B, C;
cin >> A >> B >> C;
cout << string(n, '1') + string(n, '0') + "1" << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
// 小数点以下桁数
// fixed << setprecision(i)
int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int a,int b){return (int64_t)a*b/gcd(a, b);}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}
//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1); // v に 1, 2, ... N を設定
// do {
// for(auto x : v) cout << x << " "; cout << "\n"; // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) );
//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
// bitset<ビット数> s(tmp);
// // (ビット列sに対する処理)
// }
int main()
{
int n, ans;
vector<int> a(100000);
vector<int> b(100000);
ans = 0;
cin >> n;
for (int i = 0; i < n; ++i)
cin >> a[i];
for (int i = 0; i < n; ++i)
cin >> b[i];
for (int i = 0; i < n; ++i)
ans += a[i] * b[i];
cout << (ans == 0 ? "Yes" : "No") << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<ll, pi> ipi;
typedef pair<pi, pi> pipi;
#define mp make_pair
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define size(v) (ll) v.size()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (ll) (1e9 + 100)
#define LLINF (ll) 1e18
#define mod (const ll) (1e9 + 7)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusive
ll n, a[100005], b, ans;
int main() {
fastio; cin >> n;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, n) {
cin >> b;
ans += b * a[i];
}
cout << (ans == 0 ? "Yes" : "No");
}
|
#include<bits/stdc++.h>
using namespace std;
int N,M;
int P[51][51];
int main(void)
{
register int i,j;
cin>>N>>M;
for(i=1;i<=50;i++)for(j=1;j<=50;j++)cin>>P[i][j];
N++,M++;
if(M>1&&P[N][M-1]!=P[N][M])cout<<"L"<<endl,exit(0);
if(M<50&&P[N][M+1]!=P[N][M])cout<<"R"<<endl,exit(0);
if(N>1&&P[N-1][M]!=P[N][M])cout<<"U"<<endl,exit(0);
if(N<50&&P[N+1][M]!=P[N][M])cout<<"D"<<endl,exit(0);
cout<<"D"<<endl;
return 0;
} | #include <bits/stdc++.h>
#define LIMTIME 1930
using namespace std;
using P = pair<int, int>;
using B = bitset<2500>;
struct dat {
B b;
int x, y;
dat(int _x = 0, int _y = 0, B _b = B()) : b(_b), x(_x), y(_y) {}
bool operator<(const dat r) const {
if (x != r.x) return x < r.x;
if (y != r.y) return y < r.y;
for (int i = 0; i < 2500; ++i)
if (b[i] != r.b[i]) return b[i];
return 0;
}
};
using node = pair<int, dat>;
const int n = 50;
int d[4] = {0, 1, 0, -1};
string dir = "RDLU";
vector<vector<int>> t, p;
P st;
map<dat, int> dp;
map<dat, string> memo;
string solve();
bool isvalid(int x, int y) { return x >= 0 && x < n && y >= 0 && y < n; }
int main() {
cin >> st.first >> st.second;
t.resize(n);
for (auto& v : t) {
v.resize(n);
for (auto& x : v) cin >> x;
}
p.resize(n);
for (auto& v : p) {
v.resize(n);
for (auto& x : v) cin >> x;
}
cout << solve() << endl;
return 0;
}
string solve() {
vector<node> v;
string ress;
int resp;
{ // make start node
B stb;
stb[t[st.first][st.second]] = 1;
dat stdat(st.first, st.second, stb);
resp = dp[stdat] = p[st.first][st.second];
memo[stdat] = "";
v.push_back(node(dp[stdat], stdat));
}
auto start = chrono::system_clock::now();
auto nowt = chrono::system_clock::now();
auto dur = nowt - start;
auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
int cnt = 0;
vector<int> did = {0, 1, 2, 3};
{
vector<int> dists = {49 - st.second, 49 - st.first, st.second, st.first};
sort(did.begin(), did.end(),
[&](int l, int r) { return dists[l] > dists[r]; });
}
int bf = resp, nch = 0;
while (v.size() && msec < LIMTIME) {
{
if (bf == resp) {
if (++nch >= 300) {
int len = max(1, (int)v.size() / 2);
while (v.size() > len) v.pop_back();
nch = -1e8;
}
} else
nch = 0, bf = resp;
}
// cerr << cnt++ << " " << resp << " " << v.size() << " " << msec << endl;
const auto [score, now] = v.back();
v.pop_back();
string s = memo[now];
if (score != dp[now]) continue;
for (int i : did) {
int tx = now.x + d[i], ty = now.y + d[1 ^ i];
if (!isvalid(tx, ty)) continue;
int id = t[tx][ty], tscore = score + p[tx][ty];
if (now.b[id]) continue;
// pushed = 1;
dat to(tx, ty, now.b);
to.b[id] = 1;
if (dp.count(to) && dp[to] >= tscore) continue;
dp[to] = tscore;
memo[to] = s + dir[i];
v.push_back(node(tscore, to));
if (resp < tscore) resp = tscore, ress = memo[to];
}
nowt = chrono::system_clock::now();
dur = nowt - start;
msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
}
cerr << cnt << " " << v.size() << " " << resp << endl;
return ress;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 998244353
void solve(){
int H, W; cin>>H>>W;
//set<int> s;
int a[H][W];
int sum[10001] = {0};
int chk = 1;
for(int i = 0; i<H; i++){
string S; cin>>S;
for(int j = 0; j<W; j++){
if(S[j]=='R'){
if(sum[i+j]!=0&&sum[i+j]!=1) chk = 0;
else sum[i+j] = 1;
}
else if(S[j]=='B'){
if(sum[i+j]!=0&&sum[i+j]!=-1) chk = 0;
else sum[i+j] = -1;
}
}
}
if(!chk){
cout<<0;
return;
}
int ans = 1;
for(int i = 0; i<H+W-1; i++){
if(sum[i]==0){
ans*=2;
ans%=mod;
}
}
cout<<ans<<'\n';
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif // ONLINE_JUDGE
//int t; cin>>t;
int t = 1;
for(int i =0 ; i<t; i++)
solve();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int mod=1e9+7;
int h,w;
char s[2003][2003];
int dp[2003][2003];
int s1[2003][2003],s2[2003][2003],s3[2003][2003];
int main(){
ios::sync_with_stdio(false);
cin>>h>>w;
for(int i=1;i<=h;i++)
cin>>s[i]+1;
dp[1][1]=1;s1[1][1]=1;
s2[1][1]=1;s3[1][1]=1;
for(int i=1;i<=h;i++)
for(int j=1;j<=w;j++){
if(s[i][j]=='#')continue;
dp[i][j]+=(s2[i-1][j]+s1[i][j-1])%mod;
dp[i][j]=(dp[i][j]+s3[i-1][j-1])%mod;
s1[i][j]=(s1[i][j-1]+dp[i][j])%mod;
s2[i][j]=(s2[i-1][j]+dp[i][j])%mod;
s3[i][j]=(s3[i-1][j-1]+dp[i][j])%mod;
//printf("dp[%d][%d]=%d\n",i,j,dp[i][j]);
}
printf("%d\n",dp[h][w]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<ll>>;
struct UnionFind{
vector<ll> par,siz;
UnionFind(int n):par(n,-1),siz(n,1){}
ll root(int x){
if(par[x]==-1) return x;
else return par[x]= root(par[x]);
}
bool issame(int x,int y){
return root(x)==root(y);
}
bool unite(ll x,ll y){
x=root(x);
y=root(y);
if(x==y) return false;
if(siz[x]<siz[y]) swap(x,y);
par[y]=x;
siz[x]+=siz[y];
return true;
}
ll size(int x){
return siz[root(x)];
}
};
int main(){
ll N;
cin >> N;
vector<ll>A(N);
for(int i=0;i<N;i++){
cin >> A[i];
}
UnionFind uf(201010);
for(int i=0;i<N/2;i++){
uf.unite(A[i],A[N-i-1]);
}
int ans=0;
for(int i=0;i<201010;i++){
if(uf.root(i)==i) ans+= uf.size(i)-1;
}
cout << ans;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;
struct union_find {
vector<int> par, siz;
union_find(int n) {
par.resize(n);
siz.resize(n);
for(int i = 0; i < n; i++){
par[i] = i;
siz[i] = 1;
}
}
int find(int x) {
if (par[x] == x) return x;
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)return;
if (siz[x] < siz[y]) {
par[x] = y;
siz[y] += siz[x];
}
else {
par[y] = x;
siz[x] += siz[y];
}
}
long long size(int x){
return siz[find(x)];
}
bool same(int x, int y) {
return (find(x) == find(y));
}
};
int main(){
cin.tie(0); ios::sync_with_stdio(false);
ll n; cin >> n;
ll a[n]; zep(i, 0, n)cin >> a[i];
union_find u(2e5 + 100);
ll ans = 0;
zep(i, 0, n / 2){
if(!u.same(a[i], a[n - 1 - i])){
ans++;
u.unite(a[i], a[n - 1 - i]);
}
}
print(ans)
return 0;
} |
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev coyhhhhhhyoc
#define next sdNNNmNNNNNNNmds
#define y0 hNNNNy_yNNNNNN_sNh
#define y1 mNNNNNdtdNNNNNNtsNNm
#define yn mNNNNNNNNy___smNNNms
#define tm oooooosyysooooot
#define read tyhyt
#define rank ytmNmo
#define index yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;
struct Ed {
int u, v, d;
};
bool comp(const Ed& a, const Ed& b) {
return a.d < b.d;
}
const int N = 111;
int x[N], y[N], dsu[N], rank[N];
vector<Ed> ev;
int n;
int find(int u) {
if(dsu[u] == u) return u;
dsu[u] = find(dsu[u]);
return dsu[u];
}
bool merge(int u, int v) {
u = find(u), v = find(v);
if(u == v) return false;
if(rank[u] > rank[v]) {
dsu[v] = u;
} else {
dsu[u] = v;
if(rank[u] == rank[v]) {
rank[v]++;
}
}
return true;
}
int solve() {
cin >> n;
rep(i, 1, n) {
cin >> x[i] >> y[i];
}
rep(i, 1, n + 2) {
dsu[i] = i;
}
rep(i, 1, n) {
rep(j, 1, i - 1) {
int dx = x[i] - x[j], dy = y[i] - y[j];
ev.pb({i, j, dx * dx + dy * dy});
}
int dy1 = y[i] + 100, dy2 = 100 - y[i];
ev.pb({i, n + 1, dy1 * dy1});
ev.pb({i, n + 2, dy2 * dy2});
}
sort(rng(ev), comp);
int ans = 0;
rall(e, ev) {
ans = max(ans, e.d);
merge(e.u, e.v);
int u = find(n + 1), v = find(n + 2);
if(u == v) {
break;
}
}
double anss = sqrt(ans) * .5;
cout << fixed << setprecision(13) << anss << endl;
return 0;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
while(t--) {
solve();
}
return 0;
}
| #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;
const long double eps = 1e-6;
int read(){
int x=0,f=1;
char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
return x*f;
}
int k,m,n;
struct node{
int x,y;
int zx,zd;
}a[110];
int fa[110];
int find(int x){if(x==fa[x])return x;return fa[x]=find(fa[x]);}
long double dis(int x,int y){return sqrt((a[x].x-a[y].x)*(a[x].x-a[y].x)+(a[x].y-a[y].y)*(a[x].y-a[y].y));}
bool check(long double mid){
for(int i=1;i<=n;i++){
fa[i]=i;
a[i].zx=100;a[i].zd=-100;
}
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
if(dis(i,j)<=mid)fa[find(i)]=fa[find(j)];
}
}
for(int i=1;i<=n;i++){
int x=find(i);
a[x].zx=min(a[x].zx,a[i].y);
a[x].zd=max(a[x].zd,a[i].y);
}
for(int i=1;i<=n;i++){
if(i==find(i)){
//cout<<i<<" "<<a[i].zx<<" "<<a[i].zd<<" "<<mid<<endl;
if(a[i].zx+100<=mid && 100-a[i].zd<=mid)return false;
}
}
return true;
}
int main(){
n=read();
for(int i=1;i<=n;i++){
a[i].x=read();a[i].y=read();
}
long double l=0,r=200,ans=0;
while(l+eps<=r){
long double mid=(l+r)/2;
if(check(mid)){ans=r;l=mid;}
else r=mid;
}
printf("%.6Lf\n",ans/2);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int N,c,z;
vector<vector<int>> adj(105), tc(105, vector<int>(105));
void dfs(int u, int s) {
tc[s][u] = true;
//if (s == 1) cout << u << "\n";
for (int v: adj[u]) {
// if (u == 1) cout << v << " ";
if (!tc[s][v]) dfs(v,s);
}
}
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
char c;
cin >> c;
if (c=='1') {
adj[i].push_back(j);
}
}
}
for (int i = 0; i < N; i++) {
dfs(i, i);
}
double res = 0;
for (int i = 0; i < N; i++) {
int c = 0;
for (int j = 0; j < N; j++) {
if (tc[j][i]) {
// cout << j << " " << i << "\n";
c++;
}
}
res += 1.0/c;;
}
cout << setprecision(15) << res << "\n";
return 0;
} | #include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define rep(i,n) repi(i,0,n)
#define repi(i,a,n) for(ll i = a;i < (ll)n;++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SHOW(str,val) cout<<(str)<<" : "<<(val)<<endl;
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
// using P = pair<int, int>;
void YN(bool a) { cout << (a ? "Yes" : "No"); }
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;}
// 最大公約数 : 3,4 -> 1
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
void solve()
{
ll n, a;
cin >> n;
ll ans = 0;
for(int i = 0; i < n; ++i)
{
cin >> a;
ans = gcd(ans, a);
}
cout << ans;
}
int main()
{
fastio;
solve();
return 0;
} |
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <map>
#include <vector>
#include <queue>
#include <cmath>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main()
{
ll s,p;
cin>>s>>p;
for(ll i=1; i<=sqrt(p); i++)
{
if(p%i==0)
{
if(i+p/i==s){ cout<<"Yes"<<endl; return 0; }
}
}
cout<<"No"<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}
int main2() {
ll S = nextLong();
ll P = nextLong();
for (ll a = 1; a * a <= P; a++) {
if (P % a == 0) {
ll b = P / a;
if (a + b == S) {
return 1;
}
}
}
return 0;
}
int main() {
bool ans = main2();
cout << (ans ? "Yes":"No") << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
vector<int> a;
long long ans = 1;
for(long long i = 1; i <= n; ++i){
string s; cin >> s;
if(s == "OR"){ans += (long long)pow(2, i);}
}
cout << ans << endl;
}
| #include <cstring>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
int n;
ll dp[100][2] = { 0 };
int main()
{
cin >> n;
vector<string> s(n, "");
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
dp[0][0] = dp[0][1] = 1;
for (int i = 1; i <= n; ++i) {
if (s[i - 1] == "AND") {
dp[i][1] = dp[i - 1][1];
dp[i][0] = dp[i - 1][1] + dp[i - 1][0] * 2;
} else {
dp[i][0] = dp[i - 1][0];
dp[i][1] = dp[i - 1][1] * 2 + dp[i - 1][0];
}
}
cout << dp[n][1] << endl;
return 0;
}
|
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define inf 0x7fffffff
//#define ll long long
#define int long long
//#define double long double
#define re register int
#define void inline void
#define eps 1e-8
//#define mod 1e9+7
#define ls(p) p<<1
#define rs(p) p<<1|1
#define pi acos(-1.0)
#define pb push_back
#define P pair < int , int >
using namespace std;
const int mod=998244353;
const int M=5e6;
const int N=2*1e5+5;//?????????? 4e8
int n,m;
char s[505][505];
int ans,flag;
int op,ret;
int power(int a,int b)
{
int sum=1;
while(b)
{
if(b&1) sum=sum*a%mod;
a=a*a%mod;
b>>=1;
}
return sum;
}
void solve()
{
cin>>n>>m;
for(re i=1;i<=n;i++) scanf("%s",s[i]+1);
// for(re i=1;i<=n;i++) for(re j=1;j<=m;j++) if(s[i][j]=='.') op=1;
// if(!op) ans++;
for(re i=1;i<=n;i++)
{
int x=i,y=1;
int red=0,blue=0,cnt=0;
while(x>=1&&y<=m)
{
if(s[x][y]=='.') cnt++;
if(s[x][y]=='R') red=1;
if(s[x][y]=='B') blue=1;
x--,y++;
}
if(red==1&&blue==1) flag=1;
else if((red==1&&blue==0)||(red==0&&blue==1))
{
// if(cnt) ans=(ans+1)%mod;
}
else
{
if(cnt) ret++;
}
}
for(re i=1;i<=m;i++)
{
if(i==1) continue;
int x=n,y=i;
int red=0,blue=0,cnt=0;
while(x>=1&&y<=m)
{
if(s[x][y]=='.') cnt++;
if(s[x][y]=='R') red=1;
if(s[x][y]=='B') blue=1;
x--,y++;
}
if(red==1&&blue==1) flag=1;
else if((red==1&&blue==0)||(red==0&&blue==1))
{
// if(cnt) ans=(ans+1)%mod;
}
else
{
if(cnt) ret++;
}
}
ans=(ans+power(2,ret))%mod;
if(flag) ans=0;
cout<<ans<<endl;
}
signed main()
{
int T=1;
// cin>>T;
for(int index=1;index<=T;index++)
{
solve();
// puts("");
}
return 0;
}
/*
#((((#
*/ | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vc = vector<T>;
template<class T> using vvc = vc<vc<T>>;
template<class T> using vvvc = vc<vvc<T>>;
template<class T> using vvvvc = vvc<vvc<T>>;
template<class T> using PQ = priority_queue<T>;
template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>;
using IP = pair<int, int>;
using LP = pair<ll, ll>;
#define all(x) begin(x), end(x)
#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 = (n) - 1; (i) >= 0; i--)
#define rep3r(i, m, n) for (int i = (n) - 1; (i) >= (int)(m); i--)
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; }
constexpr int INF = 1070000000;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int R, C;
cin >> R >> C;
vvc<int> A(R, vc<int>(C-1)), B(R-1, vc<int>(C));
rep (i, R) rep (j, C-1) cin >> A[i][j];
rep (i, R-1) rep (j, C) cin >> B[i][j];
invPQ<tuple<int, int, int, int>> que;
que.push({0, 0, 0, 1});
vvvc<int> dist(R, vvc<int>(C, vc<int>(2, INF)));
dist[0][0][1] = 0;
while (!que.empty()) {
while (!que.empty()) {
int d, r, c, t;
tie(d, r, c, t) = que.top();
que.pop();
if (d > dist[r][c][t]) continue;
if (c < C-1) if (chmin(dist[r][c+1][1], d + A[r][c])) que.push({ dist[r][c+1][1], r, c+1, 1 });
if (c > 0) if (chmin(dist[r][c-1][1], d + A[r][c-1])) que.push({ dist[r][c-1][1], r, c-1, 1 });
if (r < R-1) if (chmin(dist[r+1][c][1], d + B[r][c])) que.push({ dist[r+1][c][1], r+1, c, 1 });
if (r > 0) if (chmin(dist[r-1][c][0], d + t + 1)) que.push({ dist[r-1][c][0], r-1, c , 0 });
}
}
cout << dist[R-1][C-1][1] << endl;
} |
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
using ll = long long;
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
typedef long long int ll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<vector<ll>> vvll;
typedef long double ld;
const int INF = 1 << 30;
const ll MOD = 1000000007;
int main()
{
int n;
cin >> n;
vi a(n);
rep(i, n) cin >> a[i];
Sort(a);
bool jd=false;
rep(i,n){
if(a[i]==a[i+1]){
jd=true;
break;
}
}
if(jd)cno;
else cyes;
} | #include<bits/stdc++.h>
using namespace std;
int a[4],n,y,z,x[1001];
string s[1001],c;
int main(){
cin>>n;
for (int i=1;i<=n;i++){
cin>>s[i]>>x[i];
y=max(x[i],y);
}
for (int i=1;i<=n;i++)
if (x[i]!=y&&x[i]>z) z=x[i],c=s[i];
cout<<c;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(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(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------
ll N;
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N;
double phi=(1+sqrt(5))/2;
ll A=N/(1+phi),B=N-A;
for(i=-3000;i<=3000;i++) {
ll X=A+i;
ll Y=B-i;
if(X<0||Y<0) continue;
vector<int> V;
V.push_back(3);
while(X && V.size()<=130) {
if(X>=Y) {
V.push_back(3);
X-=Y;
}
else if(X<Y) {
V.push_back(4);
Y-=X;
}
}
if(Y+V.size()>130) continue;
FOR(i,Y) V.push_back(2);
reverse(ALL(V));
cout<<V.size()<<endl;
FORR(v,V) cout<<v<<endl;
return;
}
assert(0);
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
| //#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
int N;
vector<pair<int, int>> E[200001];
int A[200001], B[200001];
ll zentai = 0;
ll kari = 0;
ll q[200001];
ll kotae[200001];
void dfs(int a, int mae) {
kotae[a] = kari;
for (auto p : E[a]) {
int to = p.first;
int e = p.second;
if (mae == to) continue;
if (B[e] == a) {
kari += q[e];
dfs(to, a);
kari -= q[e];
}
else {
zentai += q[e];
kari -= q[e];
dfs(to, a);
kari += q[e];
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
rep1(i, N - 1) {
int a, b;
cin >> a >> b;
A[i] = a;
B[i] = b;
E[a].pb(mp(b, i));
E[b].pb(mp(a, i));
}
int Q;
cin >> Q;
rep(i, Q) {
int t, e, x;
cin >> t >> e >> x;
if (t == 2) {
zentai += x;
q[e] += -x;
}
else q[e] += x;
}
dfs(1, 0);
rep1(i, N) {
co(zentai + kotae[i]);
}
Would you please return 0;
} |
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define bg begin()
#define en end()
#define endl "\n"
#define vvl(n,m) vector<vector<ll> > a( n , vector<ll> (m))
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
using namespace std;
ll gcd(ll a,ll b){
if(a==0)
return b;
else return gcd(b%a,a);
}
ll power(ll x, ll y, ll m)
{
if (y == 0)
return 1;
ll p = power(x, y / 2, m) % m;
p = (p * p) % m;
return (y % 2 == 0) ? p : (x * p) % m;
}
ll modInverse(ll a, ll m)
{
return power(a, m - 2, m);
}
ll ncr(ll n, ll k)
{
ll res = 1;
if (k > n - k)
k = n - k;
for (ll i = 0; i < k; ++i) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
void permute(string str)
{
set<string> s;
sort(str.begin(), str.end());
do {
if(s.count(str)==0)
cout << str << endl;
s.insert(str);
} while (next_permutation(str.begin(), str.end()));
}
void solve()
{
ll n,i;
cin>>n;
ll r=power(2,n,10000000);
ll a[r+1],l=1,b[r+1][2];
for(i=1;i<=r;i++){
cin>>a[i];
b[i][1]=a[i];
b[i][0]=i;
}
while(r!=2){
for(l=1;l<=r/2;l++){
if(b[2*l-1][1]>b[2*l][1]){
b[l][0]=b[2*l-1][0];
b[l][1]=b[2*l-1][1];
}
else{
b[l][0]=b[2*l][0];
b[l][1]=b[2*l][1];
}
}
r/=2;
}
if(b[1][1]<b[2][1]){
cout<<b[1][0];
}
else
cout<<b[2][0];
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast
solve();
#ifndef ONLINE_JUDGE
cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<ll,ll>
int main(){
cout<<setprecision(15)<<fixed;
int n;
cin>>n;
vector<ll> x(n);
rep(i,n){
ll a; cin>>a;
x[i]=abs(a);
}
ll M=0, C=0;
double E=0;
rep(i,n) M+=x[i];
rep(i,n) E+=x[i]*x[i];
E=sqrt(E);
rep(i,n) C=max(C,x[i]);
cout<<M<<endl;
cout<<E<<endl;
cout<<C<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define rep(i,a,b) for (int i = (int)(a); i < (int)(b); i++)
ll compute(ll a){
ll ans =0;
while(a != 0){
ans += a-1;
a--;
}
return ans;
}
int main(){
ll N; cin >> N;
vector<ll> A(N);
rep(i,0,N){
cin >> A.at(i);
}
sort(A.begin(),A.end());
ll cnt =0;
ll sub_cnt =0;
rep(i,1,N){
if(A.at(i)==A.at(i-1)){
sub_cnt++;
}
else{
cnt += compute(sub_cnt+1);
sub_cnt=0;
}
}
if(sub_cnt!=0){
cnt += compute(sub_cnt+1);
}
cout << compute(N) - cnt << endl;
}
| #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include <cassert>
#include <numeric>
#include <unordered_map>
typedef long long ll;
#define FOR(i, a, b) for(int i=(a); i<(b);i++)
#define REP(i, n) for(int i=0; i<(n);i++)
#define ROF(i, a, b) for(int i=(b-1); i>=(a);i--)
#define PER(i, n) for(int i=n-1; i>=0;i--)
using namespace std;
int main() {
unordered_map<string, int> map;
ll n;
cin >> n;
vector<string> s;
s.resize(n);
REP(i, n) {
cin >> s[i];
}
ll ans = 0;
REP(i, n) {
if (s[i][0] == '!') {
map[s[i]] = 1;
}
}
REP(i, n) {
if (s[i][0] != '!') {
string tmp = '!' + s[i];
if (map[tmp] == 1) {
cout << s[i];
return 0;
}
}
}
cout << "satisfiable";
return 0;
} |
#include<bits/stdc++.h>
typedef int LL;
typedef double dl;
#define opt operator
#define pb push_back
#define pii std::pair<LL,LL>
const LL maxn=1e5+9,mod=998244353,inf=0x3f3f3f3f;
LL Read(){
LL x(0),f(1); char c=getchar();
while(c<'0' || c>'9'){
if(c=='-') f=-1; c=getchar();
}
while(c>='0' && c<='9'){
x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
}return x*f;
}
void Chkmin(LL &x,LL y){
if(y<x) x=y;
}
void Chkmax(LL &x,LL y){
if(y>x) x=y;
}
LL add(LL x,LL y){
return x+=y,x>=mod?x-mod:x;
}
LL dec(LL x,LL y){
return x-=y,x<0?x+mod:x;
}
LL mul(LL x,LL y){
return 1ll*x*y%mod;
}
LL Pow(LL base,LL b){
LL ret(1); while(b){
if(b&1) ret=mul(ret,base); base=mul(base,base); b>>=1;
}return ret;
}
LL n;
LL size[maxn],f[maxn];
std::vector<LL> V[maxn];
void Dfs(LL u){
size[u]=1;
for(LL i=0;i<V[u].size();++i){
LL v(V[u][i]);
Dfs(v);
size[u]^=size[v];
}
static LL p[maxn];
LL tot(0);
LL sum1(0),sum2(0);
for(LL i=0;i<V[u].size();++i){
LL v(V[u][i]);
LL a(f[v]),b(size[v]);
if(b){
p[++tot]=a;
}else if(a<=0){
sum1+=a;
}else{
sum2+=a;
}
}
std::sort(p+1,p+1+tot);
f[u]=1; f[u]+=sum1;
for(LL i=1;i<=tot;++i){
if((i-1)&1){
f[u]-=p[i];
}else{
f[u]+=p[i];
}
}
if(tot&1){
f[u]-=sum2;
}else{
f[u]+=sum2;
}
}
int main(){
// freopen("y1.txt","r",stdin);
n=Read();
for(LL i=2;i<=n;++i){
LL x(Read());
V[x].pb(i);
}
Dfs(1);
// for(int i=1;i<=n;++i){
// printf("%d ",f[i]);
// }puts("");
assert(!(n+f[1]&1));
printf("%d\n",n+f[1]>>1);
return 0;
}
| #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define fo(i,x,y) for(int i = x;i <= y;++i)
#define fd(i,x,y) for(int i = x;i >= y;--i)
using namespace std;
int n,e[200010][2],lst[100010],stk[100010],tot,c[100010],x,y;
bool bz[100010];
char ch[20];
int rd()
{
int x=0,sig=1;
char c;
for (c=getchar();c<'0' || c>'9';c=getchar()) if (c=='-') sig=-1;
for (;c>='0' && c<='9';c=getchar()) x=x*10+c-48;
return x*sig;
}
void print(int x,char sp)
{
int w = -1,sig = 0;
if(x == 0) w = 0,ch[0] = 48;
if(x < 0) sig = 1,x = -x;
while(x > 0) ch[++w] = x % 10 + 48,x /= 10;
if(sig == 1) putchar('-');
fd(i,w,0) putchar(ch[i]),ch[i] = 0;putchar(sp);
}
void add(int x,int y)
{
e[++tot][0] = y,e[tot][1] = lst[x],lst[x] = tot;
}
void dg(int x,int fa)
{
stk[c[x]]++;
if(stk[c[x]] <= 1) bz[x] = 1;
for(int i = lst[x];i;i = e[i][1])
{
int v = e[i][0];
if(v == fa) continue;
dg(v,x);
}
stk[c[x]]--;
}
int main()
{
//freopen("E.in","r",stdin);
// freopen("E.out","w",stdout);
n = rd();
fo(i,1,n) c[i] = rd();
fo(i,1,n - 1) x = rd(),y = rd(),add(x,y),add(y,x);
dg(1,0);
fo(i,1,n) if(bz[i]) print(i,'\n');
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define N 200000
unsigned long long dp[N][2];
using namespace std;
int main(void) {
unsigned long long n;
cin >> n;
map<long long, std::vector<long long> > balls;
for (long long i = 0; i < n; i++) {
long long x, c;
cin >> x >> c;
if (balls.count(c) == 0) {
balls[c] = std::vector<long long>();
}
balls[c].push_back(x);
}
for (const auto& b: balls) {
sort(balls[b.first].begin(), balls[b.first].end());
}
long long current_pos_left = 0;
long long current_pos_right = 0;
auto it = balls.begin();
long long i;
for (it = balls.begin(), i = 0; it != balls.end(); it++, i++) {
long long left = (*it).second.front();
long long right = (*it).second.back();
if (it == balls.begin()) {
dp[i][0] = abs(right) + right - left;
dp[i][1] = abs(left) + right - left;
current_pos_left = left;
current_pos_right = right;
//cout << "i = " << i << ", left = " << dp[i][0] << ", right = " << dp[i][1]
// << ", pos_left = " << current_pos_left << ", pos_right = " << current_pos_right << endl;
} else {
dp[i][0] = min(dp[i-1][0] + abs(current_pos_left - right) + right - left,
dp[i-1][1] + abs(current_pos_right - right) + right - left);
dp[i][1] = min(dp[i-1][0] + abs(current_pos_left - left) + right - left,
dp[i-1][1] + abs(current_pos_right - left) + right - left);
current_pos_left = left;
current_pos_right = right;
//cout << "i = " << i << ", left = " << dp[i][0] << ", right = " << dp[i][1]
// << ", pos_left = " << current_pos_left << ", pos_right = " << current_pos_right << endl;
}
}
cout << min(dp[balls.size() - 1][0] + abs(current_pos_left), dp[balls.size() - 1][1] + abs(current_pos_right)) << endl;
} | #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);
}
#define N 200020
ll mins[N], maks[N];
ll memo[N][5];
int n;
ll dp(int id, int state, ll pos){
if (id == n+1) return abs(pos);
if (memo[id][state] != -1) return memo[id][state];
if (maks[id] == -1e18) return memo[id][state] = dp(id+1,state,pos);
ll ans = 1e18;
ans = min(ans, dp(id+1, 0, mins[id]) + abs(pos-maks[id]) + abs(maks[id]-mins[id]));
ans = min(ans, dp(id+1, 1, maks[id]) + abs(pos-mins[id]) + abs(maks[id]-mins[id]));
return memo[id][state] = ans;
}
ll pos[N], c[N];
void solve(){
mem(memo,-1);
cin>>n;
rep(i,1,n+1) {
mins[i] = 1e18;
maks[i] = -1e18;
}
rep(i,0,n){
cin>>pos[i]>>c[i];
maks[c[i]] = max(maks[c[i]], pos[i]);
mins[c[i]] = min(mins[c[i]], pos[i]);
}
cout<<dp(1,0,0)<<"\n";
}
int main()
{
base();
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long int
const double pi = 3.14159265358979;
const int inf = 1e13;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
#define pii pair<int,int>
#define endl "\n"
#define dtor(deg) (((deg)/360)*2*pi)
#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 rrep(...) overload(__VA_ARGS__,_null,_rrep3,_rrep2,_rrep1)(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define vv(type,name,size,...) vector<vector<type>> name(size,vector<type>(__VA_ARGS__))
#define ForEach(a,b) for_each(a.begin(),a.end(),b)
struct Edge { int to, cost; Edge(int to, int cost) : to(to), cost(cost) {} };
using Graph = vector<vector<Edge>>;
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; }
void Main(){
int b, c, ans;
cin >> b >> c;
if(b == 0){
cout << c << endl;
}else if(b > 0 && c >= b * 2){
ans = b * 2 + 1 + (c - 2);
cout << ans << endl;
}else if(b < 0 && c >= abs(b) * 2 + 1){
ans = abs(b) * 2 + c;
cout << ans << endl;
}else if(b > 0 && c == 3){
cout << 5 << endl;
}else if(b > 0 && c == 2){
cout << 3 << endl;
}else if(b > 0 && c == 1){
cout << 2 << endl;
}else if(b > 0){
cout << 5 + (c - 3) * 2 << endl;
}else if(b < 0 && c == 3){
cout << 5 << endl;
}else if(b < 0 && c == 2){
cout << 3 << endl;
}else if(b < 0 && c == 1){
cout << 2 << endl;
}else if(b < 0){
cout << 5 + (c - 3) * 2 << endl;
}
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(10) << fixed;
Main();
} | #include <bits/stdc++.h>
int nextInt() {
int temp; scanf("%d", &temp);
return temp;
}
long long nextLL() {
long long temp; scanf("%lld", &temp);
return temp;
}
void print(int x, char endc = '\n') {
printf("%d%c", x, endc);
return;
}
void print(long long x, char endc = '\n') {
printf("%lld%c", x, endc);
return;
}
void print(size_t x, char endc = '\n') {
printf("%zu%c", x, endc);
return;
}
void print(float x, char endc = '\n') {
printf("%f%c", x, endc);
return;
}
void print(double x, char endc = '\n') {
printf("%lf%c", x, endc);
return;
}
template<typename T1, typename T2>
void print(std::pair<T1, T2> &p, char sepc = ' ', char endc = '\n') {
print(p.first, sepc);
print(p.second, endc);
return;
}
template<typename T>
void print(std::vector<T> &v, char sepc = ' ', char endc = '\n') {
for(T e : v) print(e, sepc);
printf("%c", endc);
return;
}
template<typename T>
void print(const std::set<T> &v, char sepc = ' ', char endc = '\n') {
for(T e : v) print(e, sepc);
printf("%c", endc);
return;
}
using namespace std;
void eachTC() {
long long B = nextLL(), C = nextLL();
long long res;
if(B == 0)
res = C;
else if(C == 1) {
res = 2;
}
else if((B > 0 && B <= C/2) || (B < 0 && -B <= (C-1)/2)) {
long long B1, B2;
if(B > 0 && B <= C/2) {
B1 = -B - (C-1)/2;
B2 = B + (C-2)/2;
}
else {
B1 = B - C/2;
B2 = -B + (C-1)/2;
}
res = B2 - B1 + 1;
}
else res = 2*C - 1; // 2 * (C/2 + (C-1)/2)
print(res);
}
int main() {
int T = 1;
while(T--) eachTC();
return 0;
} |
#include <sys/time.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>
#include <cstdlib>
#include <typeinfo>
/*
#include <atcoder/all>
using namespace atcoder;
*/
/*
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using BigInt = mp::cpp_int;
*/
using namespace std;
using ll = long long;
using i_i = pair<int, int>;
using l_l = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
const ll MOD = 1000000007LL;
const ll INF = 1e9 + 1;
//#define pos(x, y) (x) + (y) * w
int main() {
int n;
cin >> n;
ll min_v = - 1e9;
ll max_v = 1e9;
ll total_a = 0;
rep(i, n) {
ll a, t;
cin >> a >> t;
if (t == 1) {
total_a += a;
max_v += a;
min_v += a;
} else if (t == 2) {
min_v = max(a, min_v);
max_v = max(a, max_v);
} else if (t == 3) {
min_v = min(a, min_v);
max_v = min(a, max_v);
}
}
//cout << "max_v:" << max_v << " min_v:" << min_v << " total_a:" << total_a << endl;
int q;
cin >> q;
rep(i, q) {
ll x;
cin >> x;
ll ans = x + total_a;
ans = min(ans, max_v);
ans = max(ans, min_v);
cout << ans << endl;
}
return 0;
}
| #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;
int main()
{
#ifdef _
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int n;
ll ans=0;
scanf("%d",&n);
string s,t;
while(s.size()<n+3) s+="110";
cin>>t;
for(int i=0;i<3;i++)
{
if(s.substr(i,n)==t)
{
ll l=i,r=3e10-n;
ans+=ceil((r-l+1)/3.0);
}
}
printf("%lld\n",ans);
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;
}
int n,C[305][305],k,ans[305],a[200005],ab[305][305],suma[305],inv2 = 499122177;
int pwa[200005][305];
int main()
{
scanf("%d%d",&n,&k);
C[0][0] = 1;
rep(i,1,k) rep(j,0,k) {
C[i][j] = C[i-1][j];
if(j) {C[i][j] += C[i-1][j-1]; check(C[i][j]);}
}
rep(i,1,n) scanf("%d",a+i);
rep(i,1,n) {
pwa[i][0] = 1;suma[0] += pwa[i][0];
rep(j,1,k) {
pwa[i][j] = (ll)pwa[i][j-1] * a[i] % mod;
suma[j] += pwa[i][j];
check(suma[j]);
}
}
rep(i,0,k) rep(j,0,k - i) {
ab[i][j] = ((ll)suma[i] * suma[j] % mod - suma[i + j] + mod) % mod;
ab[i][j] = (ll)ab[i][j] * inv2 % mod;
ans[i + j] += (ll)C[i + j][j] * ab[i][j] % mod;
check(ans[i + j]);
}
rep(i,1,k) printf("%d\n",ans[i]);
return 0;
} | /*
P_r_A_d_Y ☹
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define mod 1000000007
#define inf 1e18
#define pb push_back
#define all(x) x.begin(),x.end()
#define arr_max(x) *max_element(x.begin(),x.end())
#define arr_min(x) *min_element(x.begin(),x.end())
#define pii pair<int,int>
#define ff first
#define ss second
#define vec vector<int>
const int N = 300005;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
bool cmp(vector<int>a , vector<int>b) {
return a[0] < b[0];
}
int poww(int x, int n)
{
if (n == 0 ) return 1 ;
int u = poww(x, n / 2);
u = (u * u) ;
if (n % 2 == 1)u = (u * x) ;
return u;
}
//(x**n)%m
int mod_pow(int x, int n, int m)
{
if (n == 0 ) return 1 % m;
int u = mod_pow(x, n / 2, m);
u = (u * u) % m;
if (n % 2 == 1)u = (u * x) % m;
return u;
}
int query(int l, int r)
{
int x;
cout << "? " << l << " " << r << endl;
cin >> x;
return x;
}
// int xd[4] = {1, 0, -1, 0};
// int yd[4] = {0, -1, 0, 1};
int32_t main()
{
fastIO;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
t = 1;
//cin >> t;
int ert = 1;
while (t--)
{
string s; cin >> s;
map<char, int>mp;
int n = s.length();
int ans = 0;
for (int i = n - 1; i >= 0; i--)
{
if (i + 1 < n && i - 1 >= 0 && s[i] == s[i - 1] && s[i] != s[i + 1])
{
int g = n - 1 - i;
// cout << g << endl;
if (mp.count(s[i]))
g -= mp[s[i]];
ans += g;
mp.clear();
mp[s[i]] = n - 1 - i;
s[i + 1] = s[i];
}
mp[s[i]]++;
}
cout << ans << endl;
}
return 0;
} |
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
using namespace std;
using ll = long long;
using ull = unsigned long long;
template <class ...Args>
void Input(Args &...args)
{
(cin >> ... >> args);
}
template <class T>
void InputArray(std::size_t size, T &t)
{
t.resize(size);
for (auto &e : t) {
cin >> e;
}
}
template <class ...Args>
void InputArray(std::size_t size, Args &...args)
{
(InputArray(size, args), ...);
}
template <class ...Args>
void InputVerticalArray(std::size_t size, Args &...args)
{
(args.resize(size), ...);
for (int i = 0; i < size; i++) {
((cin >> args[i]), ...);
}
}
template <class ...Args>
void Output(const Args &...args)
{
((cout << args << ' '), ...) << endl;
}
template <class ...Args>
void OutputVertical(const Args &...args)
{
((cout << args << endl), ...);
}
template <class T>
void OutputArray(const T &t)
{
for (const auto &e : t) {
cout << e << ' ';
}
cout << endl;
}
template <class ...Args>
void OutputArray(const Args &...args)
{
(OutputArray(args), ...);
}
template <class ...Args>
void OutputVerticalArray(const Args &...args)
{
for (int i = 0; i < min({ args.size()... }); i++) {
((cout << args[i] << ' '), ...) << endl;
}
}
#define inp(type, ...) \
type __VA_ARGS__; \
Input(__VA_ARGS__)
#define inpa(type, size, ...) \
type __VA_ARGS__; \
InputArray((size), __VA_ARGS__)
#define inpva(type, size, ...) \
type __VA_ARGS__; \
InputVerticalArray((size), __VA_ARGS__)
#define otp(...) \
Output(__VA_ARGS__)
#define otpv(...) \
OutputVertical(__VA_ARGS__)
#define otpa(...) \
OutputArray(__VA_ARGS__)
#define otpva(...) \
OutputVerticalArray(__VA_ARGS__)
#define rep(counter, range) \
for (int (counter) = 0; (counter) < (range); (counter)++)
#define repi(range) \
rep(i, range)
#define rrep(counter, range) \
for (int (counter) = (range) - 1; (counter) >= 0; (counter)--)
#define rrepi(range) \
rrep(i, range)
#define repc(element, container) \
for (auto &(element) : (container))
#define repe(container) \
repc(e, container)
#define all(container) \
(begin(container)), (end(container))
#ifdef __CCR__
# define dlog(x) clog << #x " = " << x << endl
#else
# define dlog(x)
#endif
constexpr ll mod = 998244353;
int main()
{
inp(ll, a, b, c);
ll sa = a * (a + 1) / 2 % mod;
ll sb = b * (b + 1) / 2 % mod;
ll sc = c * (c + 1) / 2 % mod;
ll sbc = sb * sc % mod;
ll sabc = sa * sbc % mod;
otp(sabc);
return 0;
}
| #include<bits/stdc++.h>
#define int long long
//#define PI pair<int,int>
using namespace std;
const int maxm=2e6+5;
const int mod=998244353;
int cal(int x){
return x*(x+1)/2%mod;
}
void solve(){
int a,b,c;cin>>a>>b>>c;
int C=cal(c);
int B=cal(b)*C%mod;
int A=cal(a)*B%mod;
cout<<A<<endl;
}
signed main(){
solve();
return 0;
}
/*
*/
|
#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)-1;
const ll linf = 1LL<<61;
const int MAX = 510000;
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(){
int n; cin >> n;
string s,x; cin >> s >> x;
vl b(n+1,0);
b[n] = 1;
ll now = 1;
for(int i=n-1; i>=0; i--){
int c = s[i] - '0';
if(x[i] == 'T'){
b[i] = b[i+1];
rep(j,7){
if(b[i+1]>>((j+c*now)%7) & 1) b[i] |= 1<<j;
}
}else{
rep(j,7){
if((b[i+1]>>j & 1) && (b[i+1]>>((j+c*now)%7) & 1)){
b[i] |= 1<<j;
}
}
}
now = now * 10 % 7;
}
if(b[0] & 1) cout << "Takahashi\n";
else cout << "Aoki\n";
} | /*
*/
#include <bits/stdc++.h>
using namespace std;
#define rng(x) x.begin(), x.end()
#define pb push_back
#define ff first
#define ss second
typedef double db;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<bool> vb;
typedef unsigned long long int lld;
/*-----------------------------Code begins----------------------------------*/
ll mod = 1e9 + 7;
void solve(){
int n,m; cin>>n>>m;
int a[n][m] ;
int dp[n][m] ;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
char c; cin>>c;
if(c=='-'){a[i][j]=-1;}
else{a[i][j]=1;}
}
}
dp[n-1][m-1]=0;
for(int i=n-1; i>=0; i--){
for(int j=m-1; j>=0; j--){
if(i<(n-1) && j<(m-1)){
dp[i][j] = max(a[i][j+1] - dp[i][j+1] , a[i+1][j] - dp[i+1][j]);
}
else if(i<(n-1)){
dp[i][j] = a[i+1][j] - dp[i+1][j];
}
else if(j<(m-1)){
dp[i][j] = a[i][j+1] - dp[i][j+1];
}
}
}
if(dp[0][0]==0){
cout<<"Draw\n";
}
else if(dp[0][0]>0){
cout<<"Takahashi\n";
}
else{
cout<<"Aoki\n";
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
//cin >> T;
while (T--){
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
// #define _GLIBCXX_DEBUG
template <class T> using V = vector<T>;
#define ALL(v) (v).begin(),(v).end()
#define endl '\n'
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1000000007LL;
// const ll MOD = 998244353LL;
const ll INF = 1LL << 60;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
const int dy2[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dx2[] = {1, 1, 0, -1, -1, -1, 0, 1};
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
/*--------------------------------------------------------------------------------
--------------------------------------------------------------------------------*/
int main() {
ll n; cin >> n;
V<ll> a(n), b(n);
V<ll> c(n);
ll ao = 0;
rep(i, 0, n) cin >> a[i] >> b[i], ao += a[i];
rep(i, 0, n){
c[i]= b[i]+2*a[i];
}
sort(ALL(c));
reverse(ALL(c));
ll cnt = 0;
rep(i, 0, n){
ao -= c[i];
cnt++;
if(ao < 0){
cout << cnt << endl;
return 0;
}
}
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,n) for(ll i=0;i<n;i++)
#define loopn(i,j,n) for(ll i=j;i<n;i++)
#define m_arr(arr, n) vector<ll>arr(n)
#define m_arre(arr) vector<ll>arr
#define m_set(sat) set<ll>sat
#define ppn(name) pair<ll,ll>name
#define pp pair<ll,ll>
#define ff first
#define ss second
#define sort_all(arr) sort(arr.begin(), arr.end())
#define pi 3.141592653589793238
#define mod 998244353
ll gcd(ll a, ll b){if(a==0)return b;if(b==0)return a;return gcd(b%a, a);}
ll power(ll a, ll b){ll res=1;while(b>0){if(b%2!=0)res=res*1ll*a;b/=2;a=a*1ll*a;}return res;}
#define inf (power(2, 63)-1)
#define ninf (power(2, 63)+1)
void solve()
{
ll l ,r ;
cin>>l>>r;
ll ans = (r-l);
if(ans<l)
{
cout<<0<<endl;
return;
}
ans=ans-l+1;
ans = ans*1ll*(ans+1)/2;
cout<<ans<<endl;
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;cin>>t;while(t--)
solve();
return 0;
}
|
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
#define REP(i,b,e) for(int i=b; i<e; i++)
#define PRINT(vec) {printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");}
#define fi first
#define se second
const int MOD = 1e9+7;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int main(){
int n;
scanf("%d", &n);
char s[n+1];
scanf("%s", s);
std::vector<char> st;
REP(i, 0, n){
st.push_back(s[i]);
int l = st.size();
if(st[l-3]=='f' && st[l-2]=='o' && st[l-1]=='x'){
st.pop_back();
st.pop_back();
st.pop_back();
}
}
printf("%ld\n", st.size());
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <deque>
using namespace std;
int main() {
int n; cin >> n;
map<int, int> mp;
for(int i = 1;i < n ; i++){
mp[i] = i - 1;
}
string s; cin >> s;
reverse(s.begin(), s.end());
long num = 0;
if(n == 1 || n == 2) {
cout << n << endl;
return 0;
}
if(n == 3) {
if(s == "xof"){
cout << 0 << endl;
return 0;
}else{
cout << 3 << endl;
return 0;
}
}
for(int i = 2 ;i < n; i++) {
if(s.at(i) == 'f'){
if(mp[mp[i]] < 0) break;
if(s.at(mp[i]) == 'o' && s.at(mp[mp[i]]) == 'x'){
mp[i + 1] = mp[mp[mp[mp[i + 1]]]];
num++;
}
}
}
cout << n - 3*num << endl;
} |
// #include <atcoder/all>
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
/*-------------------------------------------*/
int n;
ll a[200009], b[200009];
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> n;
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
ll sum = 0;
rep(i, n) sum += a[i];
vector<int> odd, even;
rep(i, n)(i & 1 ? odd : even).push_back(b[i] - a[i]);
sort(ALL(odd), greater<int>());
sort(ALL(even), greater<int>());
ll ans = sum;
rep(i, n / 2) chmax(ans, sum += odd[i] + even[i]);
cout << ans << endl;
return 0;
} | #include <cstdio>
#include <cctype>
namespace io{
#define cs const
#define il inline
#define tpl template
#define tpn typename
typedef cs int&ci;
typedef unsigned size_t;
typedef cs size_t&cst;
#ifndef ONLINE_JUDGE
using std::getchar;
using std::putchar;
using std::isdigit;
#else
const size_t _I_Buffer_Size = 1 << 23, _O_Buffer_Size = 1 << 23;
char _I_Buffer[_I_Buffer_Size],*_I_pos=_I_Buffer-1;
const char *_I_end=_I_Buffer + _I_Buffer_Size;
char _O_Buffer[_O_Buffer_Size],*_O_pos=_O_Buffer-1;
const char *_O_end=_O_Buffer + _O_Buffer_Size,*_O_preend=_O_end-1;
struct io{
~io(){
fwrite(_O_Buffer,1,_O_pos-_O_Buffer+1,stdout);
}
}ios;
il char getchar(){
return *((++_I_pos==_I_end)?fread(_I_Buffer,1,_I_Buffer_Size,stdin),_I_pos=_I_Buffer:_I_pos);
}
il bool isdigit(ci ch){
return '0'<=ch;
}
il void putchar(ci x){
*((_O_pos==_O_preend)?fwrite(_O_Buffer,1,_O_end-_O_Buffer,stdout),_O_pos = _O_Buffer:++_O_pos)=x;
}
#endif
template<typename T1>il void readuint(T1&x){
int ch;
while(!isdigit(ch=getchar()));
for(x=ch^'0'; isdigit(ch=getchar()); x=x*10+(ch^'0'));
}
template<typename T>void writeuint(cs T&x){
if(x>9)
writeuint(x/10);
putchar((x%10)|'0');
}
template<typename T>il void writelnuint(cs T&x){
writeuint(x);
putchar('\n');
}
#undef cs
#undef il
#undef tpl
#undef tpn
}
#include <algorithm>
#define max_n 100000
using io::readuint;
using io::writelnuint;
using namespace std;
typedef long long ll;
int a[max_n];
#define a0 a
int main(){
int n,k;
readuint(n);
int*a1=a+(k=n>>1);
for(int*i=a1; --i>=a0; ){
readuint(*i);
readuint(*(i+k));
}
ll ans=0;
for(int*i=a1,x; --i>=a0; ){
readuint(x);
*i-=x,ans+=x;
readuint(x);
*(i+k)-=x,ans+=x;
}
stable_sort(a0,a1),stable_sort(a1,a1+k);
for(int*i=a1,x; --i>=a0&&(x=*i+*(i+k))>0; ans+=x);
writelnuint(ans);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
template<class V, int ME> class BIT {
public:
V bit[1<<ME],val[1<<ME];
V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
void add(int e,V v) { val[e++]+=v; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
void set(int e,V v) { add(e,v-val[e]);}
int lower_bound(V val) {
V tv=0; int i,ent=0;
for(i=ME-1;i>=0;i--) if(tv+bit[ent+(1<<i)-1]<val) tv+=bit[ent+(1<<i)-1],ent+=(1<<i);
return ent;
}
};
BIT<int,20> TL,TR;;
int N,L;
int A[101010],B[101010];
int T[101010];
map<int,int> le,ri;
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N>>L;
A[0]=B[0]=0;
FOR(i,N) {
cin>>A[i+1];
A[i+1]-=i+1;
}
A[N+1]=B[N+1]=L-N;
FOR(i,N) {
cin>>B[i+1];
B[i+1]-=i+1;
}
N+=2;
FOR(i,N) if(ri.count(A[i])==0) ri[A[i]]=i;
for(i=N-1;i>=0;i--) if(le.count(A[i])==0) le[A[i]]=i;
FOR(i,N) {
if(A[i]==B[i]) T[i]=i;
if(A[i]<B[i]) {
if(ri.count(B[i])==0) return _P("-1\n");
T[i]=ri[B[i]];
TR.set(T[i],1);
}
if(A[i]>B[i]) {
if(le.count(B[i])==0) return _P("-1\n");
T[i]=le[B[i]];
TL.set(T[i],1);
}
}
ll ret=0;
FOR(i,N) {
if(A[i]<B[i]) {
ret++;
ret+=TR(T[i]-1)-TR(i);
}
if(A[i]>B[i]) {
ret++;
ret+=TL(i-1)-TL(T[i]);
}
}
cout<<ret<<endl;
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
| #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define MOD_Q 998244353
#define PI 3.14159265358979
#define ll long long
using namespace std;
int main()
{
int h, w;
cin >> h >> w;
int ans = 0;
vector<vector<bool>> dp(h + 2, vector<bool>(w + 2, false));
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
char tmp;
cin >> tmp;
if (tmp == '.') {
dp[i][j] = true;
}
}
}
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
if (dp[i][j]) {
if (dp[i - 1][j])ans++;
if (dp[i + 1][j])ans++;
if (dp[i][j - 1])ans++;
if (dp[i][j + 1])ans++;
}
}
}
printf("%d", ans / 2);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define cin(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define cin2(a,b,n) for(int i=0;i<n;i++) cin>>a[i]>>b[i]
#define mod 998244353
#define pb push_back
#define pie 3.141592653589793238462643383279
vector<bool> prime;
vector<int> fact,inv,primes,factors;
void factorize(int a)
{
fact.clear();
for(int 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());
}
int power(int a,int b)
{
if(a==1||b==0) return 1;
int c=power(a,b/2);
int res=1;
res=c*c;
if(res>=mod) res%=mod;
if(b%2) res*=a;
if(res>=mod) res%=mod;
return res;
}
int modInv(int a)
{
return power(a,mod-2);
}
void factorial(int n)
{
fact.resize(n+1);
fact[0]=1;
for(int i=1;i<=n;i++)
{
fact[i]=fact[i-1]*i;
if(fact[i]>=mod) fact[i]%=mod;
}
}
void InvFactorial(int n)
{
inv.resize(n+1);
inv[0]=1;
for(int i=1;i<=n;i++) inv[i]=modInv(fact[i]);
}
int ncr(int n,int r)
{
if(n<r||n<0||r<0) return 0;
int b=inv[n-r];
int c=inv[r];
int a=fact[n]*b;
if(a>=mod) a%=mod;
a*=c;
if(a>=mod) a%=mod;
return a;
}
void remove_duplicates(vector<pair<int,int>> &v)
{
sort(v.begin(),v.end());
int _size=unique(v.begin(),v.end())-v.begin();
v.resize(_size);
}
unsigned int gcd(unsigned int u, unsigned int v)
{
if(u==0||v==0) return max(u,v);
unsigned int 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(int n)
{
prime.assign(n+1,1);
prime[1]=false;
for(int p=2;p*p<=n;p++) if(prime[p]) for(int i=p*p;i<=n;i+=p) prime[i]=false;
for(int i=2;i<n+1;i++) if(prime[i]) primes.push_back(i);
}
//----------------------------------------------------------------------------------------------------------------------------------------------------
void solve()
{
int n;
cin>>n;
int a[n];
cin(a,n);
sort(a,a+n);
int sum=0,exp=a[0];
for(int i=1;i<n;i++)
{
sum=(sum+a[i]*exp)%mod;
exp=(2*exp+a[i])%mod;
}
for(int i=0;i<n;i++) sum=(sum+a[i]*a[i])%mod;
cout<<sum;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T=1;
//cin>>T;
for(int i=1;i<=T;i++) solve();
} | #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int N = 0;
cin >> N;
vector<long long> A(N, 0);
for(int i = 0; i < A.size(); i++){
cin >> A[i];
}
sort(A.begin(), A.end());
long long MOD = 998244353;
long long ans = 0;
for(int i = 0; i < A.size(); i++){
ans = (ans + (A[i] * A[i]) % MOD) % MOD;
}
if(N != 1){
vector<long long> sub(N-1,0);
sub[N-2] = A[N-1];
for(int i = N-3;i >= 0;i--){
sub[i] = (((sub[i+1] * 2) % MOD) + A[i+1]) % MOD;
}
for(int i = 0; i < sub.size(); i++){
sub[i] = (sub[i] * A[i]) % MOD;
}
for(int i = 0; i < sub.size(); i++){
ans = (ans + sub[i]) % MOD;
}
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using std::cout;
using ll=long long;
using ld=long double;
ll I=1167167167167167167;
ll Q=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end());reverse(v.begin(),v.end());}
template<class T> void print(vector<T> v) {rep(i,v.size()) cout<<v[i]<<endl;}
//バイトで15分ほど遅れて参加
int main() {
ll N;
cin>>N;
ll A=1000;
ll Z=0,X=N;
while(X>=A){
Z+=(X-A+1);
A*=1000;
}
cout<<Z<<endl;
} | #include <iostream>
using namespace std;
typedef long long ll;
int main(void) {
ll n;
ll ans = 0;
cin >> n;
if (n >= 1000) {
ans += n - 999;
}
if (n >= 1000000) {
ans += n - 999999;
}
if (n >= 1000000000) {
ans += n - 999999999;
}
if (n >= 1000000000000) {
ans += n - 999999999999;
}
if (n >= 1000000000000000) {
ans += n - 999999999999999;
}
cout << ans << endl;
return 0;
} |
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define fill(arr,c) memset(arr,c,sizeof(arr))
#define perm(r) next_permutation(all(r))
//it gives bool value ans permute the string lexoggraphically
#define sortdesc greater<int>()
#define ll long long int
//std::setfill('0') << std::setw(5) << 25; it adds leaing zeroes;
#define f(i,a) for(int i=0;i<a;i++)
#define fo(i,a) for(int i=1;i<=a;i++)
#define foo(i,x,n,c) for(ll i=x;i<n;i+=c)
#define foi(i,x,n,c) for(ll i=x;i>=n;i+=c)
#define fauto(i,m) for(auto i:m)
#define forall(a) for( auto itr=a.begin();itr!=a.end();itr++)
#define ld long double
#define in push_back
#define mll map<ll,ll>
#define mcl map<char,ll>
#define msl map<string,ll>
#define vi vector<int >
#define vl vector<ll >
#define vp vector< pair<int,int> >
#define vs vector <string>
#define vc vector <char>
#define o(a) cout<<a
#define os(a) cout<<a<<" "
#define en cout<<"\n";
#define testcase ll t ;cin>>t; while(t--)
#define ff first
#define ss second
#define pl pair<ll,ll>
#define pi pair<int,int>
#define all(a) (a).begin(), (a).end()
#define sz(a) (a).size()
#define prec(n) fixed<<setprecision(n)
#define mp make_pair
#define bitcount __builtin_popcountll
#define imin o("imin");en;
using namespace std;
bool comp(const pair<int,int> &a , const pair<int,int> &b){
if(a.first == b.first) return a.second < b.second;
return a.first < b.first;
}
bool comps(const pair<int,int> &a , const pair<int,int> &b){
if(a.second == b.second) return a.first< b.first;
return a.second < b.second;
}
//ll pi=acos(0.0)*2;
void fastio()
{
ios::sync_with_stdio(0);
cin.tie(0);
}
void inout()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
ll gcd(ll bb,ll aa)
{
if(bb==0)
return aa;
else
return gcd(aa%bb,bb);
}
ll N=1e9+7;
int main()
{
fastio();
ll n,k;
cin>>n>>k;
ll x,y;
ll ans=0;
foo(i,2,2*n+1,1)
{
if(i-k>=2 && i-k<=2*n)
ans=ans+(min(i-1,2*n-i+1))*min(i-1-k,2*n-i+1+k);
}
o(ans);
en;
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 pii = pair<int, int>;
int main() {
int n, k;
cin >> n >> k;
k = abs(k);
vector<ll> v(2 * n + 1);
for (int i = 2; i <= 2 * n; i++) {
v[i] = min(i - 1, 2 * n - i + 1);
}
ll ans = 0;
for (int i = k + 1; i <= 2 * n; i++) {
ans += v[i] * v[i - k];
}
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
bool flg[100][100];
int main() {
int n; cin >> n;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
char c; cin >> c;
flg[i][j] = (c == '1');
}
flg[i][i] = true;
}
for(int k = 0; k < n; ++k) {
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
flg[i][j] |= (flg[i][k] & flg[k][j]);
}
}
}
double ans = 0;
for(int i = 0; i < n; ++i) {
int cnt = 0;
for(int j = 0; j < n; ++j) {
cnt += flg[j][i];
}
ans += 1.0 / (double)cnt;
}
printf("%.15f\n", ans);
return 0;
}
| /*
author : TAPAN SAVANI
codeforces : savanitapan2001
codechef : savanitapan17
*/
/*
------------------------------------------------------------------------
░██╗░░░░░░░██╗░█████╗░██████╗░██╗░░██╗ ██╗░░██╗░█████╗░██████╗░██████╗░
░██║░░██╗░░██║██╔══██╗██╔══██╗██║░██╔╝ ██║░░██║██╔══██╗██╔══██╗██╔══██╗
░╚██╗████╗██╔╝██║░░██║██████╔╝█████═╝░ ███████║███████║██████╔╝██║░░██║
░░████╔═████║░██║░░██║██╔══██╗██╔═██╗░ ██╔══██║██╔══██║██╔══██╗██║░░██║
░░╚██╔╝░╚██╔╝░╚█████╔╝██║░░██║██║░╚██╗ ██║░░██║██║░░██║██║░░██║██████╔╝
░░░╚═╝░░░╚═╝░░░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝ ╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░
------------------------------------------------------------------------
*/
#include <bits/stdc++.h>
using namespace std;
#define HAPPY_CODING \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define Debug(x) cout << #x " = " << (x) << endl
#define SORT(a) sort(a.begin(), a.end())
#define SORTR(a) sort(a.rbegin(), a.rend())
#define mod 1000000007
#define pi 3.141592653589793238
#define ll long long int
#define ull unsigned long long
#define be begin()
#define en end()
#define FOR(i, a, b) for (long long int i = a; i < b; i++)
#define FORI(i, a, b) for (int i = a; i >= b; i--)
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef vector<PI> VPI;
int main()
{
HAPPY_CODING;
int n;
cin >> n;
string s;
cin >> s;
int q, swapq = 0;
cin >> q;
while (q--)
{
int t, a, b;
cin >> t >> a >> b;
a--, b--;
if (t == 1)
{
if (swapq % 2 == 0)
{
char x = s[a];
s[a] = s[b];
s[b] = x;
}
else
{
if (a >= n)
a -= n;
else
a += n;
if (b >= n)
b -= n;
else
b += n;
char x = s[a];
s[a] = s[b];
s[b] = x;
}
}
else
{
swapq++;
}
}
if (swapq % 2 == 1)
{
string s1 = s.substr(0, n);
string s2 = s.substr(n);
s = s2 + s1;
}
cout << s << "\n";
return 0;
}
|
#pragma region Region_1
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
using ll = long long;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VP = vector<P>;
using VS = vector<string>;
using VC = vector<char>;
#define MOD 1000000007
const int INF = 1e9 + 10;
template <class T, class C>
bool chmax(T& a, C b) { if (a <= b) { a = b; return true; } return false; }
template <class T, class C>
bool chmin(T& a, C b) { if (a >= b) { a = b; return true; } return false; }
template <class T> T sum(const vector<T>& v) {
T res = 0;
for (size_t i = 0; i < v.size(); ++i) res += v[i];
return res;
}
/////////////////////////////////////////////////////////
// print like python
// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed
/////////////////////////////////////////////////////////
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
cout << head;
if (sizeof...(tail) != 0) cout << " ";
print(forward<Tail>(tail)...);
}
template <class T> void print(vector<T>& vec) {
for (auto& a : vec) {
cout << a;
if (&a != &vec.back()) cout << " ";
}
cout << endl;
}
template <class T> void print(vector<vector<T>>& df) {
for (auto& vec : df) {
print(vec);
}
}
#pragma endregion Region_1
/////////////////////////////////////////////////////////
int main() {
//入力の高速化用のコード
ios::sync_with_stdio(false);
cin.tie(nullptr);
std::cout << std::setprecision(15);
//////////////////////////////////////////
double sx,sy,gx,gy;
cin >> sx >> sy >> gx >> gy;
print((sy*gx+gy*sx)/(gy+sy));
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int r1, c1, r2, c2;
cin >> r1 >> c1 >> r2 >> c2;
int answer;
int dr = r2 - r1;
int dc = c2 - c1;
if (dr == 0 && dc == 0) {
answer = 0;
} else if (dr == -dc || dr == dc || abs(dr) + abs(dc) <= 3 ) {
answer = 1;
} else if ((dr + dc) % 2 == 0 || abs(dr + dc) <= 3 || abs(dr - dc)<= 3 || abs(dr) + abs(dc) <= 6) {
answer = 2;
} else {
answer = 3;
}
cout << answer << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef pair< int , int >PII;
vector< PII >deltas(vector< int >X) {
vector< PII >vd;
for (int i = 0; i+1 < X.size(); i++) {
if (X[i]+1 < X[i+1]) {
vd.emplace_back(X[i+1]-X[i]-1, i);
}
}
return vd;
}
void impossible() {
cout << -1 << "\n";
exit(0);
}
int main() {
// ios::sync_with_stdio(false);
// cin.tie(0);
int n, l;
cin >> n >> l;
vector< int >A(n+2);
A[0] = 0;
A[n+1] = l+1;
for (int i = 1; i <= n; i++) cin >> A[i];
vector< int >B(n+2);
B[0] = 0;
B[n+1] = l+1;
for (int i = 1; i <= n; i++) cin >> B[i];
vector< PII >da = deltas(A);
vector< PII >db = deltas(B);
long long ans = 0;
for (int i = db.size()-1; i >= 0; i--) {
vector< PII >fromA;
int sum = 0;
while (sum < db[i].first) {
assert(!da.empty());
// if (da.empty()) impossible();
sum += da.back().first;
fromA.push_back(da.back());
da.pop_back();
}
if (sum != db[i].first) impossible();
int mn = fromA.back().second;
int mx = fromA.front().second;
mn = min(mn, db[i].second);
mx = max(mx, db[i].second);
ans += mx-mn;
}
if (!da.empty()) {
impossible();
}
cout << ans << "\n";
return 0;
}
| #include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define ull unsigned long long
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i,k,j) for(int i=(k);i>=(j);i--)
#define For(i,k,j) for(int i=(k);i<=(j);i++)
#define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Fin(s) freopen(s,"r",stdin)
#define Fout(s) freopen(s,"w",stdout)
#define file(s) Fin(s".in"),Fout(s".out")
#define INF ((1<<30)-1)
#define int long long
const int P=1e9+7; //
using namespace std;
template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);}
template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);}
inline int mul(int a,int b) {return 1ull*a*b%P;}
inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;}
inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;}
inline void mulmod(int &a,int b) {a=mul(a, b);}
inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);}
inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);}
inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline void fprint(const int &x,char c=' ') {fprintf(stderr,"%d%c",x,c);}
inline void fprint(const pii &x,char c='\n') {fprintf(stderr,"%d %d%c",x.first,x.second,c);}
inline void fprint(const int *f,const int &n,char c='\n') {for(int i=1;i<=n;i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline void fprint(const vector<int> &f,char c='\n') {for(int i=0;i<(int)f.size();i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline int inv(int a) {return ksm(a,P-2);}
namespace FastIO {
const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt;
int read(char *s) {
while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}
int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn;
}
bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;}
void write(int x) {
if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];}
if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}
}
void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}}
void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;}
};
inline int read() {int x; FI(x); return x;}
const int MN=1e5+5;
int n,f[MN],ned[MN];
vi ans; int now,X,Y;
void doit(int x) {
if(x==0) X++;
if(x==1) Y++;
if(x==2) X+=Y;
if(x==3) Y+=X;
ans.pb(x+1);
// cerr<<X<<' '<<Y<<endl;
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("pro.in","r",stdin);
freopen("pro.out","w",stdout);
#endif
f[0]=f[1]=1; For(i,2,87) f[i]=f[i-1]+f[i-2];
int n=read(),mx=-1;
foR(i,87,0) {
while(n>=f[i]) {
if(mx==-1) mx=i;
n-=f[i];
// cerr<<mx<<' '<<i<<endl;
ned[mx-i]++;
}
}
// cerr<<"?"<<endl;
//cerr<<mx<<endl;
now=(mx&1);
For(i,0,mx) {
while(ned[i]) {
doit(now);
ned[i]--;
}
doit(now+2); now^=1;
}
cout<<ans.size()<<endl;
for(auto it:ans) {
printf("%d\n",it);
}
return FastIO::Fflush(),0;
}
|
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define ll long long
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define pob pop_back()
#define Mod (ll)(1e9+7)
#define mod (ll)(998244353)
#define setp(x) setprecision((ll)(n))
#define INF (ll)(1000000000000000000)
using namespace std;
using vi=vector<int>;
using vc=vector<char>;
using vl=vector<long long>;
using vvi=vector<vi>;
using vvl=vector<vl>;
using vpl=vector<pair<ll,ll>>;
using vs=vector<string>;
using pii=pair<int, int>;
using pll=pair<ll,ll>;
int main(){
int n,k; cin>>n>>k;
ll res=0;
for(int i=1;i<=n;++i){
for(int j=1;j<=k;++j){
res+=100*i+j;
}
}
cout<<res<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N,K;
cin>>N>>K;
cout<<50*K*N*(N+1)+N*(K*K+K)/2<<endl;
}
|
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int a[4];
cin>>a[0]>>a[1]>>a[2]>>a[3];
sort(a,a+4);
cout<<a[0];
}
| #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr int int_max = (1<<30)+((1<<30)-1);
constexpr int int_min = -(1<<30)-(1<<30);
constexpr ll ll_max = (1LL<<62)+((1LL<<62)-1LL);
constexpr ll ll_min = -(1LL<<62)-(1LL<<62);
int main(){
int ans = INT32_MAX;
for(int i = 0; i < 4; ++i){
int a;
cin >> a;
ans = min(ans, a);
}
cout << ans << endl;
}
|
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
char maze[15][15];
struct node {
int x, y;
};
bool cmp1(node a, node b) {
return a.x != b.x ? a.x < b.x : a.y < b.y;
}
bool cmp2(node a, node b) {
return a.y != b.y ? a.y < b.y : a.x < b.x;
}
void solve() {
int n, m, ans = 0; scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%s", maze[i] + 1);
}
vector<node> vt;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (maze[i][j] == '#' and maze[i - 1][j] == '.') {
vt.push_back(node{i, j});
}
}
}
double t1 = 0;
for(int j = 0; j < 12; j++) t1++;
double t2 = 0;
t2--;
for (int i = 0; i < 4; i++) t1 -= t2;
sort(vt.begin(), vt.end(), cmp1);
for (int i = 1; i < vt.size(); i++) {
if (vt[i].x == vt[i - 1].x && vt[i].y == vt[i - 1].y + 1) {
continue;
}
ans++;
}
t2++;
t1++;
ans += 1;
vt.clear();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (maze[i][j] == '#' && maze[i + 1][j] == '.') {
vt.push_back(node{i, j});
}
}
}
for (int i = 0; i < 4; i++) t1 -= t2;
sort(vt.begin(), vt.end(), cmp1);
for (int i = 1; i < vt.size(); i++) {
if (vt[i].x == vt[i - 1].x && vt[i].y == vt[i - 1].y + 1) {
continue;
}
ans++;
}
t2++;
t1++;
ans++;
vt.clear();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (maze[i][j] == '#' && maze[i][j + 1] == '.') {
vt.push_back(node{i, j});
}
}
}
for (int i = 0; i < 4; i++) t1 -= t2;
sort(vt.begin(), vt.end(), cmp2);
for (int i = 1; i < vt.size(); i++) {
if (vt[i].y == vt[i - 1].y && vt[i].x == vt[i - 1].x + 1) {
continue;
}
ans++;
}
for (int i = 0; i < 4; i++) t1 -= t2;
t2++;
t1++;
ans += 1;
vt.clear();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (maze[i][j] == '#' && maze[i][j - 1] == '.') {
vt.push_back(node{i, j});
}
}
}
for (int i = 0; i < 4; i++) t1 -= t2;
sort(vt.begin(), vt.end(), cmp2);
for (int i = 1; i < vt.size(); i++) {
if (vt[i].y == vt[i - 1].y && vt[i].x == vt[i - 1].x + 1) {
continue;
}
ans++;
}
for (int i = 0; i < 4; i++) t1 -= t2;
t2++;
t1++;
printf("%d\n", ++ans);
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T = 1; //cin >> T;
while(T--) {
solve();
}
return 0;
} | #include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
///--->>> CONTAINERS <<<---///
using i64 = int64_t;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vector< ll > >;
using vpi = vector<pair<ll,ll> >;
using pi = pair<ll,ll>;
using st = set<ll>;
using stk = stack<ll>;
using kiwi = queue<ll>;
using pkiwi = priority_queue<ll>;
using mp = map<ll,ll>;
using ump = unordered_map<ll,ll>;
///--->>> TEMPLATES <<<---///
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update >;
template<typename T>
T modpow(T a, T b){ll ans = 1; while(b>0) { if(b&1) ans*=a, b--; else a*=a, b>>=1;} return ans; }
///--->>> MACROS<<<---///
const ll mx = 3e6+123;
#define MOD 998244353
#define mod 1000000007
#define isb(z) __builtin_popcount(z)
#define lisb(z) __builtin_popcountll(z)
#define iclz(z) __builtin_clz(z)
#define lclz(z) __builtin_clzll(z)
#define ictz(z) __builtin_ctz(z)
#define lctz(z) __builtin_ctzll(z)
#define REP(i,n) for (ll i=1;i<=n;++i)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
///--->>>OPTIMIZE<<<---///
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
///--->>> DEBUGGER<<<---///
#define dbg(args...) do {cerr<<#args<<" : "; diraf(args); } while(0)
void diraf () {cerr << endl;}
template < typename T, typename ... hello>
void diraf( T arg, const hello &... rest) {cerr<<arg<< ' ';diraf(rest...);}
///--->>> RANDOMIZER<<<---///
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/* usage - just do rng() */
int main(int argc, char* argv[]){
fastio;
///freopen("input.txt","r",stdin);
///freopen("output.txt","w",stdout);
///cout<<fixed<<setprecision(20);
cin.exceptions(cin.failbit);
ll height, width; cin>>height>>width;
char ch;
vector<vector<bool> > grid(height+1, vector<bool>(width+1, 0));
for(ll i = 0 ; i<height; ++i){
for(ll j = 0 ; j<width; ++j){
cin>>ch;
grid[i][j] = (ch=='#'? 1 : 0);
}
}
ll sides = 0;
for(ll i = 0 ; i<height - 1; ++i){
for(ll j = 0 ; j <width - 1; ++j){
ll borders = 0;
borders ^= grid[i+1][j];
borders ^= grid[i][j+1];
borders ^= grid[i+1][j+1];
borders ^= grid[i][j];
sides += borders;
}
}
cout<<sides<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef __int128 ll;
typedef pair<int,int> ii;
void solve(){
int n; cin >> n;
long long ci; cin >> ci;
ll C = ci;
vector<tuple<int,int,ll>> v; // point, ev, price
for (int i=0; i<n; i++){
int a,b,c; cin >> a >> b >> c;
v.push_back(make_tuple(a,0,c));
v.push_back(make_tuple(b+1,1,c));
}
sort(v.begin(), v.end());
ll curr = 0;
ll answer = 0;
ll lastpoint = -1;
for (int i=0; i<n*2; i++){
int j;
ll change = 0;
for (j=i; j<n*2 && get<0>(v[j]) == get<0>(v[i]); j++){
if (get<1>(v[j]) == 0) change += get<2>(v[j]);
else change -= get<2>(v[j]);
}
if (lastpoint == -1) lastpoint = get<0>(v[i]);
ll dist = get<0>(v[i]) - lastpoint;
if (dist > 0){
answer = answer + min(dist * curr, dist * C);
}
curr += change;
lastpoint = get<0>(v[i]);
i = j-1;
}
vector<int> ans;
while(answer > 0){
ans.push_back(answer%10);
answer = answer / (ll)10;
}
reverse(ans.begin(), ans.end());
for (int i=0; i<ans.size(); i++) cout << ans[i];
cout << '\n';
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
// NK
| #include<bits/stdc++.h>
#define int long long int
//Compute XOR of all numbers from 1 to n in O(1) complexity
#define xor1toN(n) (n&((n&1)-1)&~1 | ((n>>1)^n)&1)
using namespace std;
const int M = 998244353;
const int mod = 1e9+7;
const int inf = 1e18;
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
int power(int x,int y,int p){
int 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(){
int n;
cin>>n;
int a[n];
int b[n];
int sum=0;
int ans=INT_MAX;
for(int i=0;i<n;i++)
{
cin>>a[i]>>b[i];
sum=a[i]+b[i];
ans = min(sum,ans);
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i!=j)
{
int val =max(a[i],b[j]);
ans = min(ans,val);
}
}
}
cout<<ans<<endl;
}
signed main(){
fast;
int t=1;
//cin>>t;
while(t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1e9
typedef long long ll;
typedef long double ld;
int main(){
ll n;
cin >> n;
vector<pair<double,double>> v(n);
REP(i,n){
ll t;
double l, r;
cin >> t >> l >> r;
if(t == 2)r-=0.1;
else if(t==3)l+=0.1;
else if(t==4){
l+=0.1;
r-=0.1;
}
v[i] = {l,r};
}
ll cnt = 0;
REP(i,n-1){
FOR(j,i+1,n){
if(v[j].first <= v[i].second && v[i].first <= v[j].second)cnt++;
}
}
cout << cnt << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll inf = (1ll << 60);
vector<int> dy {0,1,0,-1};
vector<int> dx {-1,0,1,0};// ← ↓ → ↑
int main(){
ll x, y; cin >> x >> y;
ll a, b; cin >> a >> b;
ll ans = 0;
while(1){
if(x > y/a) break;
if(a*x >= y) break;
if(a*x >= x + b) break;
x *= a;
ans++;
}
ans += (y-x-1)/b;
cout << ans << endl;
}
|
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word
//Incase of close mle change language to c++17 or c++14
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007ll //998244353ll
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
int g=__gcd(a, b);
return a/g*b;
}
int power(int a, int b, int p)
{
if(a==0)
return 0;
int res=1;
a%=p;
while(b>0)
{
if(b&1)
res=(res*a)%p;
b>>=1;
a=(a*a)%p;
}
return res;
}
int l;
int dp[300][15];
int fun(int pos, int rem)
{
if(rem<0)
return 0;
if(pos>=l)
{
if(rem==0)
return 1;
return 0;
}
if(dp[pos][rem]!=-1)
return dp[pos][rem];
return dp[pos][rem]=fun(pos+1, rem)+fun(pos+1, rem-1);
}
int32_t main()
{
IOS;
fill(dp, -1);
cin>>l;
cout<<fun(1, 11);
} | #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;
#define FIFO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define inf 2e18
#define mod 998244353
#define bg begin()
#define en end()
#define ll long long int
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<long long int>
#define vpll vector<pair<long long int,long long int> >
#define vpii vector<pair<int,int> >
#define vstr vector<string>
#define mpii map<int ,int>
#define mpll map<long long int,long long int >
#define max3(arr,brr,ser) max(arr,max(brr,ser))
#define min3(arr,brr,ser) min(arr,min(brr,ser))
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtinctzll(x) //zeros after rightmost set bit
#define w(t) ll t; cin>>t; while(t--)
#define vin(v,G) for(int i=0;i<G;i++){ll x;cin>>x; v.pb(x);}
#define for0(i,G) for(int i=0;i<G;i++)
#define for1(i,G) for(int i=1;i<=G;i++)
#define forn(i,arr,brr) for(int i=arr;i<=brr;i++)
#define forv(it,v) for(auto it=v.begin();it!=v.end();it++)
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define eb emplace_back
#define bs binary_search
#define lb(v,arr) lower_bound(v.begin(),v.end(),arr)
#define ub(v,arr) upper_bound(v.begin(),v.end(),arr)
#define deb1(x) cerr<<#x<<": "<<x<<" "<<endl
#define deb2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define deb3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define deb4(arr, brr, ser, d) cerr<<#arr<<": "<<arr<<" | "<<#brr<<": "<<brr<<" | "<<#ser<<": "<<ser<<" | "<<#d<<": "<<d<<endl
#define FF first
#define SS second
#define yes "YES"
#define no "NO"
#define PI 3.141592653589793238462643383279502884L
#define printv(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" "
// find_by_order(p) returns iterator to kth element starting from 0;
// order_of_key(p) returns count of elements strictly smaller than p;
//order of key returns the index if the element was present.(If not present)
template <typename T>
using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll Ceil(ll arr, ll brr) {return arr / brr + (arr % brr != 0);}
ll Logn(ll G, ll right) {return (G > right - 1) ? 1 + Logn(G / right, right) : 0;}
ll fastModExp(ll arr, ll brr) { ll res = 1; while (brr > 0) { if (brr & 1)res = (res * arr) % mod; arr = (arr * arr) % mod; brr = brr >> 1; } return res;}
ll GCD(ll arr, ll brr) { if (brr == 0)return arr; else return GCD(brr, arr % brr);}
//Chrnlgy: Binary Search,Greedy,dp,dfs and similar
int main()
{
// w(t)
// {
ll n;
cin >> n;
string s;
cin >> s;
ll q;
cin >> q;
string s1, s2;
s1 = s.substr(0, n);
s2 = s.substr(n, n);
while (q--) {
ll t, a, b;
cin >> t >> a >> b;
if (t == 1)
{
a--;
b--;
if (a < s1.length() && b < s1.length())
{
swap(s1[a], s1[b]);
}
else if (a >= s1.length() && b >= s1.length())
swap(s2[a - n], s2[b - n]);
else
{
char ch = s1[a];
s1[a] = s2[b - n];
s2[b - n] = ch;
}
}
if (t == 2)
{
swap(s1, s2);
}
}
cout << s1 + s2 << endl;
return 0;
}
|
#include<bits/stdc++.h>
#define M 1000000007
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output1.txt","w",stdout);
#endif
string s;
cin >> s;
if( (s[0]==s[1] && s[1]==s[2])){
cout << "Won";
}
else{
cout << "Lost";
}
return 0;
} | #include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<int> primes;
ll isPrime(ll n){
if(n==1){
return 1;
}
for(int j=2; j*j<=n; j++){
if(n%j==0){
return 0;
}
}
return 1;
}
void solve(){
string in; cin >> in;
set<char> s;
for(int i=0; i<in.size(); i++){
s.insert(in[i]);
}
if(s.size()==1){
cout << "Won\n";
}else{
cout << "Lost\n";
}
return;
}
int main(){
int t=1;
// cin >> t;
while(t--){
solve();
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1000000000+7;
//template<typename T>
vector<ll> findall(string target,string find_word){
vector<ll> a;
ll pos=target.find(find_word);
while(pos!=std::string::npos){
a.push_back(pos);
pos=target.find(find_word,pos+find_word.length());
}
return a;
}
int main(){
double n;cin>>n;
if(floor(n*1.08)<206)cout << "Yay!";
else if(floor(n*1.08)==206)cout << "so-so";
else cout << ":(";
#ifdef _DEBUG //-D_DEBUG
#endif
} | #include<cstdio>
using namespace std;
int main(void)
{
int n;
scanf("%d",&n);
if(n%2==0) printf("White\n");
else printf("Black\n");
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF =1001001001;
using P = pair<int,int>;
int main(void)
{
int h,w;
ll n,m;
cin >> h >> w >> n >> m;
vector<vector<bool>>ab(h,vector<bool>(w,false));
vector<vector<bool>>cd(h,vector<bool>(w,false));
rep(i,n)
{
int ai,bi;
cin >> ai >> bi;
ab[ai-1][bi-1] = true;
}
rep(i,m)
{
int ci,di;
cin >> ci >> di;
cd[ci-1][di-1] = true;
}
int ans = 0;
rep(i,h)
{
rep(j,w)
{
if(cd[i][j])
{
continue;
}
if(ab[i][j])
{
ans++;
continue;
}
//上下左右に探索
bool ok = false;
for(int hh = i; hh < h; hh++)
{
if(cd[hh][j]) break;
if(ab[hh][j])
{
ans++;
ok =true;
break;
}
}
if(ok) continue;
for(int hh = i; hh >= 0; hh--)
{
if(cd[hh][j]) break;
if(ab[hh][j])
{
ans++;
ok =true;
break;
}
}
if(ok) continue;
for(int ww= j; ww >= 0; ww--)
{
if(cd[i][ww]) break;
if(ab[i][ww])
{
ans++;
ok =true;
break;
}
}
if(ok) continue;
for(int ww= j; ww < w; ww++)
{
if(cd[i][ww]) break;
if(ab[i][ww])
{
ans++;
ok =true;
break;
}
}
if(ok) continue;
}
}
cout << ans << endl;
return 0;
} | #include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));
signed main() {
int X, Y, A, B;
cin >> X >> Y >> A >> B;
int ans = 0;
while (1) {
if (X * A < Y && (double)A <= 1e18 / (double)X && X * A < X + B) {
ans++;
X = X * A;
}
else break;
}
ans += (Y - X - 1) / B;
cout << ans << endl;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using P = pair<int,int>;
#define rep(i,n) for (int i = 0; i < (int)(n) ; i++)
#define rep2(i,a,b) for (int i = (a); i < (int)(b); i++)
#define repR(i,n) for (int i = (int)(n)-1; i >= 0; i--)
#define repR2(i,a,b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ENDL '\n'
#define pb push_back
#define SIZE(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define UNIQUE(a) a.erase(unique(all(a)),a.end());
#define debug(x) cout<<(#x)<<" is : "<<x<<endl;
#define debugc(vec) {cout<<(#vec)<<" is below; ---"<<endl;for(auto elements:vec)cout<<elements<<" ";cout<<endl<<"----------------"<<endl;}
inline string rev(string s) {string t(s.rbegin(), s.rend()); return t;}
template<class T> inline bool chmin(T &a, T b) { if(a>b) {a=b; return 1;} return 0;}
template<class T> inline bool chmax(T &a, T b) { if(a<b) {a=b; return 1;} return 0;}
constexpr ll INF = (1LL<<30)-1;
constexpr ll INFLL = (1LL<<62)-1;
constexpr ld PI = 3.14159265358979323846L;
int main() {
cout << fixed << setprecision(15);
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int n,m; cin>>n>>m;
ll ans=INFLL;
vll a(n), w(m), lsum(n), rsum(n);
rep(i, n) cin>>a[i];
rep(i, m) cin>>w[i];
sort(ALL(a));
sort(ALL(w));
for(int i=1; i<=n-2; i+=2) {
if(i==1) lsum[i]=a[i]-a[i-1];
else lsum[i]=lsum[i-2] + a[i]-a[i-1];
}
for(int i=n-2; i>=1; i-=2) {
if(i==n-2) rsum[i]=a[i+1]-a[i];
else rsum[i]=rsum[i+2] + a[i+1]-a[i];
}
auto floorodd = [](int x) -> int {
if(x<=0) return 0;
if(x%2==0) return x-1;
return x;
};
auto ceilodd = [&](int x) -> int {
if(x>=n-1) return n-1;
if(x%2==0) return x+1;
return x;
};
int left=0, right=1;
ll sum=0;
if(w[0]<a[0]) {left=-1; right=0;}
else {
while(left<n-1 && a[left+1]<w[0]) {
left++;
right++;
}
}
sum += lsum[floorodd(left)] + rsum[ceilodd(right)];
if(left%2==0) sum+=w[0]-a[left];
else sum+=a[right]-w[0];
chmin(ans, sum);
for(int i=1; i<m; i++) {
sum=0;
while(left<n-1 && a[left+1]<w[i]) {
left++;
right++;
}
sum += lsum[floorodd(left)] + rsum[ceilodd(right)];
if(left%2==0) sum+=w[i]-a[left];
else sum+=a[right]-w[i];
chmin(ans, sum);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
constexpr ll mod=1e9+7;
char c[2010][2010];
int yoko[2010][2010];
int tate[2010][2010];
ll mod_pow(ll a,ll b){
a%=mod;
if(b==0)return 1;
if(b==1)return a;
ll res=mod_pow(a,b/2)%mod;
res*=res; res%=mod;
if(b%2)res*=a;
return res%mod;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int h,w; cin >> h >> w;
int al=0;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cin >> c[i][j];
if(c[i][j]=='.')al++;
}
}
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(c[i][j]=='.'){
int cnt=0;
int jj=j;
while(jj<w and c[i][jj]=='.'){
cnt++; jj++;
}
while(j<jj){
yoko[i][j]=cnt;
j++;
}
}
}
}
for(int i=0;i<w;i++){
for(int j=0;j<h;j++){
if(c[j][i]=='.'){
int cnt=0;
int jj=j;
while(jj<h and c[jj][i]=='.'){
cnt++; jj++;
}
while(j<jj){
tate[j][i]=cnt;
j++;
}
}
}
}
ll res=0;
ll aaa=mod_pow(2,al);
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(c[i][j]=='.'){
res+=aaa;
res-=mod_pow(2,al-tate[i][j]-yoko[i][j]+1);
if(res>mod)res-=mod;
if(res<0)res+=mod;
}
}
}
if(res<0)res+=mod;
cout << res << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxl=4e5+10;
const int mod=998244353;
int n,m;ll ans;
int p[maxl],dy[maxl];
ll fac[maxl],inv[maxl],dp[maxl];
bool no[maxl];
inline void shai()
{
for(int i=2;i<maxl;i++)
{
if(!no[i]) p[++p[0]]=i,dy[i]=i;
int j=1,t=p[1]*i;
while(j<=p[0] && t<maxl)
{
no[t]=true;dy[t]=p[j];
if(i%p[j]==0)
break;
t=p[++j]*i;
}
}
}
inline ll qp(ll a,ll b)
{
ll ans=1,cnt=a;
while(b)
{
if(b&1) ans=ans*cnt%mod;
cnt=cnt*cnt%mod;
b>>=1;
}
return ans;
}
inline void prework()
{
shai();
fac[0]=1;
for(int i=1;i<maxl;i++)
fac[i]=fac[i-1]*i%mod;
inv[maxl-1]=qp(fac[maxl-1],mod-2);
for(int i=maxl-2;i>=0;i--)
inv[i]=inv[i+1]*(i+1)%mod;
scanf("%d%d",&n,&m);
}
inline ll c(int n,int r)
{
if(r>n || r<0) return 0;
return fac[n]*inv[n-r]%mod*inv[r]%mod;
}
inline void add(ll &a,ll b){a=(a+b)%mod;}
inline void mainwork()
{
dp[1]=1;ans=1;
for(int i=2;i<=m;i++)
{
int x=i,d=dy[i],cnt=0;
while(x%d==0 && x>1)
cnt++,x/=d;
dp[i]=dp[x]*c(cnt+n-1,n-1)%mod;
add(ans,dp[i]);
}
}
inline void print()
{
printf("%lld\n",ans);
}
int main()
{
prework();
mainwork();
print();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int mod = 998244353;
long long fac[200005], finv[200005], inv[200005];
void COMinit(int m) {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < 200005; i++){
fac[i] = fac[i - 1] * i % m;
inv[i] = m - inv[m % i] * (m / i) % m;
finv[i] = finv[i - 1] * inv[i] % m;
}
}
long long COM(int n, int k,int m){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % m) % m;
}
long long dp[35][200005];
int main() {
int N,M;
cin >> N >> M;
COMinit(mod);
for(int i = 1; i <= M; i++) {
dp[0][i] = 1;
}
for(int i = 0; i < 30; i++) {
for(int j = 1; j <= M; j++) {
for(int k = 2; j*k <= M; k++) {
dp[i+1][j*k] += dp[i][j];
}
}
}
long long ans = 0;
for(int i = 0; i < 30; i++) {
long long sum = 0;
for(int j = 1; j <= M; j++) {
sum += dp[i][j];
}
ans += sum*COM(N-1,i,mod)%mod;
ans %= mod;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
void solve()
{
int a,b,c,d;cin>>a>>b>>c>>d;
int ans=INT_MIN;
for(int i=a;i<=b;i++)
{
for(int j=c;j<=d;j++)
{
ans=max(ans,i-j);
}
}
cout<<ans<<endl;
}
int32_t main()
{
rapido;
int t=1;
//cin>>t;
while(t--)
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,d;
cin >> a >> b >> c >> d;
cout << b - c << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
bool flag;
string x[10000010];
int main(void){
long long n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>x[i];
reverse(x[i].begin(),x[i].end());
}
sort(x+1,x+n+1);
for(int i=1;i<n;i++){
if(x[i]+'!'==x[i+1]){
reverse(x[i].begin(),x[i].end());
cout<<x[i]<<endl;
flag=1;
break;
}
}
if(flag!=1){
cout<<"satisfiable";
}
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mod 998244353
#define big 1e18 + 1000000
#define small -big
#define pb push_back
#define endl "\n"
template <typename T>
void prarr(T a)
{
cerr << "[ ";
for(auto i : a){
cerr << i << " ";
}
cerr << "]" << endl;
}
#define trace(...) _er(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void _er(const char* name, Arg1&& arg1){
cerr << "[" << name << " : " << arg1 << "]" << endl;
}
template <typename Arg1, typename... Args>
void _er(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr << "[" ; cerr.write(names, comma - names) << " : " << arg1 << "] ";
_er(comma+2, args...);
}
void solve() {
ll N;
cin >> N;
char A[N + 1];
for(ll i = 1; i <= N; i++) {
cin >> A[i];
}
ll ans[N + 1][26];
memset(ans, 0, sizeof(ans));
for(ll i = 1; i <= N; i++) {
for(ll j = 0; j < 26; j++) {
ans[i][j] += ans[i - 1][j];
}
ans[i][A[i] - 65]++;
}
ll d = 0;
for(ll i = 1; i <= N; i++) {
for(ll j = i; j <= N; j++) {
ll a = ans[j]['A' - 65] - ans[j - i]['A' - 65];
ll c = ans[j]['C' - 65] - ans[j - i]['C' - 65];
ll g = ans[j]['G' - 65] - ans[j - i]['G' - 65];
ll t = ans[j]['T' - 65] - ans[j - i]['T' - 65];
if(a == t && g == c) {
d++;
}
}
}
cout << d << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
//cin >> t;
for(int i = 1; i <= t; i++) {
solve();
}
return 0;
}
|
//#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 +7; const ll INF = 1e18;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}
//using mint = atcoder::modint1000000007;
int main()
{
cin.tie(0); ios_base::sync_with_stdio(false);
int m,h;
cin >>m >>h;
int ok = 0;
if(h%m==0) ok=1;
puts(ok? "Yes":"No");
return 0;
}
| #include <cstdio>
#include <iostream>
using namespace std;
int n, m;
int main() {
cin >> n >> m;
if (m % n == 0) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (ll i = (ll)(start); i < (ll)(n); ++i)
static const ll INFTY = 1L << 62L;
ll solver(ll n, ll k)
{
ll a1, a2, b1, b2, c1, c2, d1, d2, p, q, ans = 0;
for (p = 2; p <= 2 * n - k; ++p)
{
q = p + k;
b1 = min(n, p - 1);
a1 = p - b1;
d1 = min(n, q - 1);
c1 = q - d1;
ans += (b1 - a1 + 1) * (d1 - c1 + 1);
}
return ans;
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
ll n, k;
cin >> n >> k;
cout << solver(n, abs(k)) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll N,K;
cin>>N>>K;
for(int i=0;i<K;i++){
if(N%200==0)
N/=200;
else{
N=N*1000+200;
}
}
cout<<N;
}
|
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define re
#define X first
#define Y second
#define mp std::make_pair
#define pb push_back
#define ohh(hhh...) fprintf(stderr,hhh)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> pii;
template<class T1> inline bool cmax(T1 &x,T1 y) {return x<y?(x=y,1):0;}
template<class T1> inline bool cmin(T1 &x,T1 y) {return x>y?(x=y,1):0;}
int read()
{
int x=0,w=0;
char ch=0;
while(ch<'0'||ch>'9') w|=ch=='-',ch=getchar();
while('0'<=ch&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return w?-x:x;
}
int main()
{
re int n=read();
n=floor(1.08*n);
if(n<206) printf("Yay!\n");
else if(n==206) printf("so-so\n");
else printf(":(\n");
return 0;
} | #include<iostream>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
int t[210000];
int main(){
int a;scanf("%d",&a);
int at=0;
for(int i=0;i<a;i++){
int s;scanf("%d",&s);
t[s]++;
while(t[at]){
at++;
}
printf("%d\n",at);
}
} |
#include<iostream>
using namespace std;
typedef long long LL;
const int N=1e6+5;
LL l,r;
LL cnt[N],num[N];
void init(){
for(int i=2;i<=N;i++)
for(int j=i;j<=r;j+=i){
if(j<l)continue;
cnt[i]++;
}
}
int main(){
cin>>l>>r;
init();
LL ans=0;
for(int i=r;i>=2;i--){
num[i]=cnt[i]*cnt[i];
for(int j=i+i;j<=r;j+=i){
num[i]-=num[j];
}
ans+=num[i];
if(i>=l)ans-=cnt[i]*2-1;
}
cout<<ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
#include <cstdint>
#include <string>
#include <sstream>
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,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using P = pair<int,int>;
const int INF=1001001001;
const int mod =998244353;
struct mint {
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
struct combination {
vector<mint> fact, ifact;
combination(int n):fact(n+1),ifact(n+1) {
assert(n < mod);
fact[0] = 1;
for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n) return 0;
return fact[n]*ifact[k]*ifact[n-k];
}
} c(200005);
int main() {
ll N,K;
cin>>N>>K;
vector<mint>A(N);
rep(i,N){
int a;
cin>>a;
A[i]=a;
}
vector<mint>sum(K+1);
rep(i,N){
mint ki=1;
rep(k,K+1){
sum[k]=(sum[k]+ki);
ki=ki*A[i];
}
}
for(int x=1;x<=K;x++){
mint ans=0;
rep(k,x+1){
ans+=c(x,k)*sum[k]*sum[x-k];
}
mint p=mint(2).pow(x)*sum[x];
cout<<(ans-p)/2<<endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
void read (int &x) {
char ch = getchar(); x = 0; int f = 0;
while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); }
while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
if (f) x = -x;
} const int N = 3e5 + 5;
int n, k, res, a[N], c[N];
signed main() {
read (n), read (k);
for (int i = 1; i <= n; ++i)
read (a[i]), ++c[a[i]];
int now = k;
for (int i = 0; i <= n; ++i) {
if (now > c[i]) res += (now - c[i]) * i, now = c[i];
}
printf ("%lld\n", res);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define TEZ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rf(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define vi vector<pair<ll,ll>>
#define ff first
#define ss second
#define mp map<ll,ll>
#define test ll t; cin>>t; while(t--)
#define srt(v) sort(v.begin(),v.end())
double pi=acos(-1);
const ll MOD=1000000007;
void OJ(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
}
int main(){
TEZ;
ll ans=0;
string s;
cin>>s;
f(i,0,10000){
vector<bool> present(10,false);
ll x=i;
f(j,0,4){
present[x%10]=true;
x/=10;
}
bool fl=true;
f(i,0,s.length()){
if(s[i]=='o' and present[i]==false)
fl=false;
if(s[i]=='x' and present[i]==true)
fl=false;
}
ans+=fl;
}
cout<<ans;
} |
#include<iostream>
#include<sstream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<numeric>
#include<queue>
#define rep(i,p) for(long long int i=0;i<p;i++)
#define reep(i,p) for(long long int i=1;i<=p;i++)
#define ll long long
#define mod 1000000007
using namespace std;
int main(){
ll int N;
cin >> N;
if(N==1){
cout << "2";
return 0;
}
ll int n;
ll int karii=0;
ll int counter=0;
for(ll int i=1;i<=100000000;i++){
if((i*i-i)%2==0){
n=N-(i*i-i)/2;
if(n<=0){
break;
}
if(n%i==0){
// cout << n << endl;
if(n==floor(n)){
counter+=2;
// cout << "dfd"<< i-karii << endl;
karii=i;
}
}
}
}
cout << counter;
return 0;
}
|
// Problem: D - Staircase Sequences
// Contest: AtCoder - AtCoder Beginner Contest 190
// URL: https://atcoder.jp/contests/abc190/tasks/abc190_d
// 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 ll;
#define mod 1e9+7
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
int main() {
fast;
ll t=1;
// cin>>t;
while(t--){
ll n;
cin>>n;
ll ans=0;
for(ll i=2;i*(i+1)/2<=n;i++) if((n-i*(i+1)/2)%i==0) ans++;
cout<<2*(ans+1)<<"\n";
}
return 0;
}
|
#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;
#define deb(x) cerr << #x << " = " << x << "\n";
#define deb2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << "\n";
#define deb3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << "\n";
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define f first
#define s second
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
template<typename T>
using oset = tree<T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
void solve(int tc) {
int n;
cin >> n;
vector<ll> v(n);
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
ll g = v[0];
for (int i = 0; i < n-1; ++i) {
g = __gcd(g, v[i+1]);
}
cout << g << '\n';
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int tc = 1;
//cin >> tc;
for (int i = 1; i <= tc; ++i) {
solve(i);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < n; i++)
using ll = long long;
using P = pair<int,int>;
const ll INF = 1e18;
const int MX = 2005;
ll factorial(ll l){
if(l == 1 || l == 0){
return 1;
}else{
return l * factorial(l-1);
}
}
int main() {
ll L;
cin >> L;
ll ans = 1;
vector<bool> ch(11,true);
rep(i,11){
ans *= L - i - 1;
rep(j,11){
if(ch[j]){
if(ans % (j+1) == 0){
ans /= j+1;
ch[j] = false;
}
}
}
}
cout << ans << endl;
} |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N = 4e5 + 5, mod = 1e9 + 7;
vector<int> adj[N];
int in[N];
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin >> n;
for(int i = 0; i < n; i++){
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
in[u]++;
in[v]++;
}
queue<int> q;
for(int i = 1; i < N; i++){
if(in[i] == 1){
q.push(i);
}
}
int ans = 0;
while(q.size()){
int node = q.front();
q.pop();
if(in[node] == 0) continue;
ans++;
for(auto i: adj[node]) {
in[i]--;
if (in[i] == 1) {
q.push(i);
}
}
}
for(int i = 1; i < N; i++){
ans += (in[i] > 1);
}
cout << ans;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define setIO(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
#define closefile fclose(stdin), fclose(stdout)
#define m_p make_pair
#define sz(x) (int)x.size()
#define see(x) cerr << x << " "
#define seeln(x) cerr << x << endl
#define out(x) cerr << #x << " = " << x << " "
#define outln(x) cerr << #x << " = " << x << endl
#define outarr(x, l, r) {cerr<< #x"[" << l << " ~ " << r << "] = "; for (int _i = l; _i <= r; ++_i) cerr << x[_i] << " "; cerr << endl;}
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define gc() getchar()
//#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 21], *p1 = buf, *p2 = buf;
template <class T> void read(T &x)
{
x = 0; int c = gc(); int flag = 0;
while (c < '0' || c > '9') flag |= (c == '-'), c = gc();
while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) +(c ^ 48), c = gc();
if (flag) x = -x;
}
template <class T> T _max(T a, T b){return b < a ? a : b;}
template <class T> T _min(T a, T b){return a < b ? a : b;}
template <class T> bool checkmax(T &a, T b){return a < b ? a = b, 1 : 0;}
template <class T> bool checkmin(T &a, T b){return b < a ? a = b, 1 : 0;}
const int N = 200005, inf = 0x3f3f3f3f;
int n, k;
vector<int> G[N];
int l[N], z1, Q;
int dis[N], dp[N], far[N];
void add_edge(int x, int y)
{
G[x].push_back(y);
}
void dfs(int x, int f, int d)
{
l[x] = d;
for (int i = 0; i < sz(G[x]); ++i)
{
int to = G[x][i];
if (to == f) continue;
dfs(to, x, d + 1);
}
}
void init()
{
read(n); read(k);
for (int i = 1, v, u; i < n; ++i)
{
read(u); read(v);
add_edge(u, v);
add_edge(v, u);
}
dfs(1, 0, 0);
int mx = 0;
for (int i = 1; i <= n; ++i) if (checkmax(mx, l[i])) z1 = i;
}
void run(int x, int f)
{
dp[x] = 0; far[x] = -inf; dis[x] = inf;
int child = 0;
for (int i = 0; i < sz(G[x]); ++i)
{
int to = G[x][i];
if (to == f) continue;
++child;
run(to, x);
checkmin(dis[x], dis[to] + 1);
dp[x] += dp[to];
}
if (child == 0)
{
dp[x] = far[x] = 0;
dis[x] = inf;
}
else
{
for (int i = 0; i < sz(G[x]); ++i)
{
int to = G[x][i];
if (to == f) continue;
if (Q < dis[x] + far[to] + 1) checkmax(far[x], far[to] + 1);
}
//out(x); out(far[x]); outln(dis[x]);
if (far[x] == Q || dis[x] == Q + Q + 1)
{
++dp[x];
dis[x] = 0; far[x] = -inf;
}
}
//out(Q); out(x); out(dp[x]); out(dis[x]); outln(far[x]);
}
bool check(int mid)
{
Q = mid;
run(z1, 0);
if (dis[z1] > Q) ++dp[z1];
if (dp[z1] <= k) return 1;
else return 0;
}
void solve()
{
int l = 1, r = n - 1, mid, best = n - 1;
while (l <= r)
{
mid = (l + r) >> 1;
if (check(mid)) best = mid, r = mid - 1;
else l = mid + 1;
}
printf("%d\n", best);
}
int main()
{
//setIO("");
init();
solve();
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
string s;
cin>>s;
if ((s[0]==s[1])&&(s[1]==s[2])&&(s[2]==s[0] )) cout<<"Won";
else cout<<"Lost";
return 0;
} | //KEEP IT SIMPLE STUPID
#include<bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define print(v) for(auto it=(v).begin();it!=(v).end();it++) {cout<<*it<<" ";}
#define ll long long
#define w(t) ll t;cin>>t;while(t--)
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
using namespace std;
bool prime(int n)
{
if (n < 2)
return false;
for (int x = 2; x * x <= n; x++)
{
if (n % x == 0)
return false;
}
return true;
}
/* Function to get prime factorization of n */
vector<int> getFactors(int n)
{
vector<int> f;
for (int x = 2; x * x <= n; x++)
{
while (n % x == 0)
{
f.push_back(x);
n /= x;
}
}
if (n > 1)
f.push_back(n);
return f;
}
ll k=0;
ll su(ll a, ll x)
{
if(a%x !=0)
return k;
else
{
return k+su(a/x,x);
}
}
void solve()
{
string s;
cin>>s;
ll c=0;
forn(i,s.length())
{
if(s[0]==s[i])
c++;
}
if(c==s.length()) cout<<"Won";
else cout<<"Lost";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
//cout<<su(12,2);
//st("2");
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
*/
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;
#define fi first
#define se second
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);
void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}
ll GCD(ll A, ll B){
if (A < B) swap(A, B);
while (A % B != 0){
A %= B; swap(A, B);
}
return B;
}
ll extgcd(ll a, ll b, ll &x, ll &y){
if (b == 0) {
x = 1; y = 0; return a;
}
ll d = extgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
int T;
int Solve(){
ll N, S, K; cin >> N >> S >> K;
ll G = GCD(GCD(N, S), K);
N /= G; S /= G; K /= G;
if (GCD(K, N) != 1) {
cout << -1 << endl;
return 0;
}
ll x, y; extgcd(K, N, x, y);
while (x < 0) x += N;
cout << x * (N - S) % N << endl;
return 0;
}
int main(){
cin >> T;
for (int i = 0; i < T; i++){
Solve();
}
return 0;
} | #include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);cout << fixed;
#define dbset(x) for(int i=0 ; i<x.size(); i++) cerr << x[i] << " "; cerr << endl;
#define inf 1000000007
#define INF 1000000000000000000LL
#define PI 3.14159265358979323846
#define mod 1000000007
#define mod1 1000696969
#define flusz fflush(stdout);
#define VI vector<int>
#define VPI vector < pair<int,int> >
#define PII pair<int, int>
#define BIT bitset<N>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define REP(x, y) for(int x = 0; x < (y); ++x)
#define FOR(x, y, z) for(int x = y; x <= (z); ++x)
#define FORR(x, y, z) for(int x = y; x >= (z); --x)
using namespace std;
#define int long long
#define N 200007
int test;
int n;
string s,ss;
VPI g[N];
ull dp[N]; // ilosc zapalonych w wierzcholku
ull siz[N];
ull res;
void dfs(int v,int p,ull val){
siz[v] = 1;
for(auto it:g[v]){
if (it.st != p){
dfs(it.st,v,val);
if (it.nd&val){
res += 1LL*(((siz[it.st] - dp[it.st]) * (siz[v] - dp[v]))%mod) * (val%mod);
res %= mod;
res += ((dp[v] * dp[it.st])%mod) * (val%mod);
res %= mod;
}else{
res += (((siz[it.st] - dp[it.st]) * (dp[v]))%mod) * (val%mod);
res %= mod;
res += ((dp[it.st] * (siz[v] - dp[v]))%mod) * (val%mod);
res %= mod;
}
siz[v] += siz[it.st];
if (it.nd&val){
dp[v] += (siz[it.st] - dp[it.st] + mod);
dp[v] %= mod;
}else{
dp[v] += dp[it.st];
dp[v] %= mod;
}
}
}
return;
}
void solve()
{
cin >> n;
FOR(i,1,n-1){
ull a,b,c;
cin >> a >> b >> c;
g[a].eb(b,c);
g[b].eb(a,c);
}
FOR(i,0,61){
FOR(j,1,n){
dp[j] = siz[j] = 0;
}
dfs(1,1,(1ll<<i));
}
cout << res;
return;
}
int32_t main()
{
boost
test=1;
while(test--)
{
solve();
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5, INF = 1e17 + 5;
long long n, m, a, b, c, d, dist[N];
bool vis[N];
struct Edge{
long long b, c, d;
};
vector<Edge> graph[N];
long double findtime(long long t, long long wait, Edge e){
return wait + e.c + ((e.d / (long double)(t + 1 + wait)));
}
long long findwait(long long t, Edge e){
long long l = 0, r = INF, m1, m2;
long double m1ans, m2ans;
while(r - l > 2){
m1 = l + (r - l) / 3;
m2 = r - (r - l) / 3;
m1ans = findtime(t, m1, e);
m2ans = findtime(t, m2, e);
if(m1ans <= m2ans) r = m2;
else l = m1;
}
vector<pair<long double, long long>> v;
for(long long i = l; i <= r; i++){
v.push_back({findtime(t, i, e), i});
}
sort(v.begin(), v.end());
return v.front().second;
}
void dijkstra(){
for(int i = 1; i <= n; i++) dist[i] = INF;
priority_queue<pair<long long, long long>> pq;
dist[1] = 0;
pq.push({0, 1});
long long v;
while(!pq.empty()){
v = pq.top().second, pq.pop();
if(!vis[v]){
vis[v] = true;
for(auto e : graph[v]){
if(!vis[e.b]){
long long waitt = findwait(dist[v], e);
long long edget = findtime(dist[v], waitt, e);
if(dist[v] + edget < dist[e.b]){
dist[e.b] = dist[v] + edget;
pq.push({-dist[e.b], e.b});
}
}
}
}
}
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n >> m;
for(int i = 0; i < m; i++){
cin >> a >> b >> c >> d;
graph[a].push_back({b, c, d});
graph[b].push_back({a, c, d});
}
dijkstra();
cout << (dist[n] == INF ? -1 : dist[n]);
} | #include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl "\n"
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define sz(x) (int)((x).size())
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define mii map<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define ppc __builtin_popcount
#define ppcll __builtin_popcountll
#define INF 100000000000000000
#define mod 1000000007
#define esp 10e-7
const int mx=3e5+7;
int a[mx];
int st[4*mx];
void construct_st(int ss,int se,int si)
{
if(ss==se)
{
st[si]=a[ss];
return;
}
int mid=(ss+se)/2;
construct_st(ss,mid,2*si+1);
construct_st(mid+1,se,2*si+2);
st[si]=st[2*si+1]^st[2*si+2];
}
int get_xor(int qs,int qe,int ss,int se,int si)
{
if(ss>qe||qs>se)
return 0;
if(qs<=ss&&se<=qe)
{
return st[si];}
int mid=(ss+se)/2;
return get_xor(qs,qe,ss,mid,2*si+1)^
get_xor(qs,qe,mid+1,se,2*si+2);
// return 0;
}
void update_st(int si,int idx,int y,int ss,int se)
{
if(idx<ss||idx>se)
return;
st[si]^=y;
int mid=(ss+se)/2;
if(ss!=se)
{update_st(2*si+1,idx,y,ss,mid);
update_st(2*si+2,idx,y,mid+1,se);
}
}
signed main()
{
//#ifndef ONLINE_JUDGE
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//freopen("error.txt" , "w" , stderr);
//#endif
IOS
int t=1,n,q;
// cin>>t;
while(t--)
{
cin>>n>>q;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int type,x,y;
construct_st(0,n-1,0);
// for(int i=0;i<=n;i++)
// cout<<st[i]<<" ";
// cout<<endl;
while(q--)
{
cin>>type>>x>>y;
if(type==1)
{
x--;
update_st(0,x,y,0,n-1);
}else
{
x--;
y--;
cout<<get_xor(x,y,0,n-1,0)<<endl;
}
}
}
return 0;
} |
#include <iostream>
#include <math.h>
using namespace std;
void aaa(int *a,int start,int end){
if(start<end){
for(int i=start;i<end; i++){
if(a[i]>a[i+1]){
int tmp=a[i];
a[i]=a[i+1];
a[i+1]=tmp;
}
}
aaa(a,start,end-1);
}
}
int main() {
long long h, w;
int a[10000];
int sum=0;
cin >> h >> w;
for(int i=0;i<h*w;i++){
cin >> a[i];
//cout << a[i];
sum=sum+a[i];
}
aaa(a, 0, h*w-1);
cout << sum - a[0]*h*w << endl;
}
| #include<bits/stdc++.h>
using namespace std;
int max(int a,int b){
return a>b?a:b;
}
int min(int a,int b){
return a<b?a:b;
}
int main()
{
int h,w,m=2000000000;
scanf("%d %d",&h,&w);
int a[102][102];
for(int i=1;i<=h;i++)
for(int j=1;j<=w;j++) {scanf("%d",&a[i][j]);m=min(m,a[i][j]);}
int sum=0;
for(int i=1;i<=h;i++)
for(int j=1;j<=w;j++) sum+=(a[i][j]-m);
cout<<sum<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mems(p) memset(p,-1,sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"
const int mxN = 8e5 + 100;
const ll MOD = 1e9 + 7;
void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
ll gcd(ll a, ll b) {
return b ? gcd(b, a%b) : a;
}
vector<ll> factorial;
ll expo(ll x, ll exp) {
if (exp <= 0) return 1;
ll tmp = (x*x)% MOD;
if (exp%2) {
return (expo(tmp, exp/2) * x) % MOD;
}
return (expo(tmp, exp/2)) % MOD;
}
ll choice(ll n, ll r) {
if (n < r) return 0;
ll numer = factorial[n];
ll denom = (factorial[r] * factorial[n-r]) % MOD;
return numer * expo(denom, MOD - 2) % MOD;
}
int main() {
fast();
int a,b,c,d;
cin>>a>>b>>c>>d;
cout<<a*d-b*c<<nl;
}
| #include <iostream>
using namespace std;
long long dp[16*16] = {0};
int H, W;
bool used[16][16] = {false};
int dfs(int h, int w, int a, int b)
{
if ((a < 0) || (b < 0)) return 0;
if (w == W) w = 0, h++;
if (h == H) return 1;
if (used[h][w]) return dfs(h, w+1, a, b);
int res = 0;
used[h][w] = true;
res += dfs(h, w+1, a, b-1);
if (w+1 < W && !used[h][w+1]) {
used[h][w+1] = true;
res += dfs(h, w+1, a-1, b);
used[h][w+1] = false;
}
if ((h+1 < H && !used[h+1][w])) {
used[h+1][w] = true;
res += dfs(h, w+1, a-1, b);
used[h+1][w] = false;
}
used[h][w] = false;
return res;
}
int main(void) {
int A, B;
cin >> H >> W >> A >> B;
int ans = dfs(0, 0, A, B);
cout << ans << endl;
return 0;
}
|
// Problem :
// bit.ly/pentagon03
#include<bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define sz(v) (int)((v).size())
#define ini(st,en,X) fill(&st,&en,decltype(st)(X))
#define rep(i,n) for(int i=0;i<(n);i++)
#define repr(i,a,b) for(int i=(a);i<=(b);i++)
#define nl '\n'
#define sp ' '
using ll = long long;
using pii = pair<int,int>;
void dbg(string s = "STILL WORKING"){puts(s.c_str());}
void solve(){
int n,m;
cin>>n>>m;
vector<int> arr(n);
vector<pii> v(m+1);
rep(i,n) cin>>arr[i];
repr(i,1,m) cin>>v[i].second>>v[i].first;
rep(i,n){
int flag=0;
repr(j,1,m){
if(arr[i]>v[j].first){
flag=1;
break;
}
}
if(flag){
cout<<-1<<nl;
return;
}
}
sort(all(v));
int dp[m+1]={};
repr(i,1,m)
dp[i] = max(dp[i-1],v[i].second);
sort(all(arr));
int ans = 2e9;
do{
int psum[n],dis[n]={0,},sum=0;
rep(i,n){
sum+=arr[i];
psum[i]=sum;
}
rep(i,n){
repr(j,i+1,n-1){
int rsum = psum[j];
if(i) rsum-=psum[i-1];
int idx = lower_bound(all(v),pii(rsum,0)) - v.begin() - 1;
dis[j] = max(dis[j],dis[i]+dp[idx]);
}
}
ans = min(ans,dis[n-1]);
}while(next_permutation(all(arr)));
cout<<ans<<nl;
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
int TC=1;
repr(tc,1,TC){
solve();
}
return 0;
}
// Solution
/*
*/
| #include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
typedef long long ll;
typedef std::pair<ll, ll> pll;
const ll INF = (1LL << 60);
struct segtree {
int i, j;
ll val;
segtree *l, *r;
segtree(std::vector<pll> &ar, int _i, int _j) : i(_i), j(_j) {
if (i == j) {
val = ar[i].second;
l = r = NULL;
} else {
int k = (i+j) >> 1;
l = new segtree(ar, i, k);
r = new segtree(ar, k+1, j);
val = std::max(l->val, r->val);
}
}
ll query(int _i, int _j) {
if (_i <= i and j <= _j) {
return val;
} else if (_j < i or j < _i) {
return 0;
} else {
return std::max(l->query(_i, _j), r->query(_i, _j));
}
}
};
struct graph {
int n;
ll **mat;
ll *dp;
graph (int n) : n(n) {
mat = new ll*[n];
for (int u = 0; u < n; ++u)
mat[u] = new ll[n];
dp = new ll[n];
}
void change_edge(int u, int v, ll w) {
mat[u][v] = w;
}
ll dfs(int u) {
if (u == n-1) return 0;
if (dp[u] != -1) return dp[u];
dp[u] = 0;
for (int v = u+1; v < n; ++v)
dp[u] = std::max(dp[u], dfs(v) + mat[u][v]);
return dp[u];
}
};
int N, M;
std::vector<ll> W;
std::vector<pll> P;
int main() {
std::cin >> N >> M;
ll maxw = 0;
for (int i = 0; i < N; ++i) {
ll w; std::cin >> w;
W.push_back(w);
maxw = std::max(maxw, w);
}
std::sort(W.begin(), W.end());
bool unavoid_collapse = false;
for (int i = 0; i < M; ++i) {
ll l, v; std::cin >> l >> v;
P.push_back({v, l});
if (maxw > v)
unavoid_collapse = true;
}
std::sort(P.begin(), P.end());
segtree *root = new segtree(P, 0, M-1);
if (unavoid_collapse) {
std::cout << "-1\n";
return 0;
}
graph g(N);
ll ans = (1LL << 60);
do {
/*for (int w : W)
std::cout << w << " ";
std::cout << "\n";*/
for (int i = 0; i < N; ++i) {
ll s = W[i];
for (int j = i+1; j < N; ++j) {
s += W[j];
int k = -1;
for (int jump = M; jump >= 1; jump >>= 1)
while (k + jump < M and P[k + jump].first < s)
k += jump;
//std::cout << i << " " << j << " " << k << "\n";
g.change_edge(i, j, root->query(0, k));
}
}
for (int u = 0; u < N; ++u) g.dp[u] = -1;
ll dist = g.dfs(0);
ans = std::min(ans, dist);
//std::cout << dist << "\n";
//std::cout << "-----\n";
} while (std::next_permutation(W.begin(), W.end()));
std::cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef vector<vector<bool> > vvb;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rrep(i, n) for (int i = 1; i <= int(n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = int(n)-1; i >= 0; --i)
#define MES(a) MES2 a
#define MES2(a0,a1,a2,a3,a4,x,...) x
#define mes_1(x1) cout<<x1<<endl
#define mes_2(x1,x2) cout<<x1<<" "<<x2<<endl
#define mes_3(x1,x2,x3) cout<<x1<<" "<<x2<<" "<<x3<<endl
#define mes_4(x1,x2,x3,x4) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<endl
#define mes_5(x1,x2,x3,x4,x5) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<" "<<x5<<endl
#define mes(...) CHOOSE((__VA_ARGS__,mes_5,mes_4,mes_3,mes_2,mes_1,~))(__VA_ARGS__)
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#define ynmes(a) (a) ? mes("Yes") : mes("No")
#define YNmes(a) (a) ? mes("YES") : mes("NO")
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
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; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
ll fact_mod(ll n, ll mod) {
ll f = 1; for (ll i = 2; i <= n; i++) f = f * (i % mod) % mod;
return f;
}
ll modpow(ll x, ll n, ll mod) {
if(n == 0) return 1;
ll res = modpow((x * x) % mod, n / 2 , mod);
if(n & 1) res = (res * x) % mod;
return res;
}
ll modncr(ll n, ll r, ll mod) {
if(r > n-r) r = n-r;
if(r == 0) return 1;
ll a = 1;
rep(i, r) a = a * ((n-i) % mod) % mod;
ll b = modpow(fact_mod(r, mod), mod-2, mod);
return (a % mod) * (b % mod) % mod;
}
signed main() {
string s;
cin >> s;
ll r = 0;
ll n = s.size();
stack <char> stk;
rep(i, n) {
if (i && s[i] == s[i-1]) stk.push(s[i]);
}
if (stk.empty()) {
mes(0);
re0;
}
ll tmp = 0;
drep(i, n) {
if (stk.empty()) break;
if (i && s[i] == s[i-1]) {
stk.pop();
r += tmp;
tmp = 0;
if (!stk.empty() && stk.top() != s[i-1]) tmp += n-i;
} else {
if (stk.top() != s[i]) tmp++;
}
}
mes(r);
}
| #include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
string s;
ll ans,raod[200];
int main(){
ios::sync_with_stdio(false);
cin >> s;
for(int i=(int)s.size() - 1; i>=1; i--){
if(s[i] == s[i - 1]){
ans += (int)s.size() - i - 1 - raod[s[i] - 'a'];
for(int j=0; j<26; j++)
raod[j] = 0;
raod[s[i] - 'a'] = (int)s.size() - i;
}
else {
raod[s[i] - 'a']++;
}
}
cout << ans << '\n';
return 0;
}
|
//IQ134高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007
#define MODB 998244353
template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
for (T& x: vec) { is >> x; }
return is;
}
int main() {
ll ans = 0;
ll tmp = 0;
int n; cin >> n;
string s; cin >> s;
vector<int> a(n+1); cin >> a;
int mi[n+1] = {};
REP(i, n) if(s[i] == '<') mi[i+1] = max(mi[i+1], mi[i]+1);
for(int i = n; i >= 0; i--) if(s[i] == '>') mi[i] = max(mi[i], mi[i+1]+1);
ans = INF;
//REP(i, n+1) if(mi[i] > 0) ans = min(ans, (ll)(a[i]/mi[i]));
REP(i, n) ans = min(ans, (ll)abs(a[i] - a[i+1]));
cout << ans << endl;
REP(i, ans){ REP(j, n+1){cout << (a[j] + i)/ ans << " ";} cout << endl;}
//REP(i, ans - 1){ REP(j, n+1){cout << mi[j] << " ";} cout << endl;}
//REP(i, n+1){cout << a[i] - mi[i] *(ans - 1) << " ";} cout << 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 rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;
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; }
#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T> ostream &operator<<(ostream &os, multiset<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }
#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }
#ifdef DEBUG
#define dbg(...) { dump_func(__VA_ARGS__) }
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif
const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/
int main() {
int N;
string S;
cin >> N >> S;
vector<int> A(N+1);
rep(i,N+1)cin >> A[i];
// x個に分けることができるか
auto check = [&](int x, bool out = false) -> bool{
vector<vector<int>> vv(x, vector<int>(N+1, 0));
rep(i,x)rep(j,N+1){
vv[i][j] = A[j]/x;
}
rep(j,N+1){
int rem = A[j]%x;
rep(i,rem)vv[i][j] += 1;
}
if(out){
rep(i,x){
rep(j,N+1){
cout << vv[i][j] << " ";
}
cout << endl;
}
}
//
dump(x);
rep(i,x)rep(j,N+1)if(vv[i][j] < 0)return false;
rep(i,x){
rep(j,N){
if(S[j] == '<'){
if(vv[i][j] >= vv[i][j+1])return false;
}
else{
if(vv[i][j] <= vv[i][j+1])return false;
}
}
}
return true;
};
int ok = 1;
int ng = 1e5;
while(ng - ok > 1){
int mid = (ok + ng) / 2;
dump(mid);
if(check(mid))ok = mid;
else ng = mid;
}
cout << ok << endl;
check(ok, true);
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef pair<int,lld> pil;
typedef pair<lld,int> pli;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
if(0<=y&&y<n&&0<=x&&x<m) return true;
return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
const int MAX = 202020;
int vis1[MAX],vis2[MAX],seg[MAX*4],start = 1;
bool tmr(pi a,pi b){
return a.x > b.x;
}
void upd(int x){
x += start;
seg[x]--;
for(int e=(x/2);e>=1;e/=2) seg[e] = seg[e*2] + seg[e*2+1];
}
int getn(int l,int r){
l += start;
r += start;
int ans = 0;
while(l<=r){
if(l&1) ans += seg[l++];
if(!(r&1)) ans += seg[r--];
l >>= 1;
r >>= 1;
}
return ans;
}
int main(void){
while(start<MAX) start *= 2;
int n,m,que;
scanf("%d%d%d",&n,&m,&que);
for(int e=1;e<=n;e++){
vis1[e] = m;
}
for(int e=1;e<=m;e++){
vis2[e] = n;
}
while(que--){
int y,x;
scanf("%d%d",&y,&x);
vis1[y] = min(vis1[y],x-1);
vis2[x] = min(vis2[x],y-1);
}
lld ans = 0;
vector<pi> v;
for(int e=1;e<=vis1[1];e++){
ans += vis2[e];
v.push_back(mk(vis2[e],e));
}
sort(all(v),tmr);
for(int e=start;e<2*start;e++) seg[e] = 1;
for(int e=start-1;e>=1;e--) seg[e] = seg[e*2] + seg[e*2+1];
int st = 0;
for(int p=vis2[1];p>=1;p--){
for(;st<sz(v)&&v[st].x>=p;st++) upd(v[st].y);
ans += getn(1,vis1[p]);
}
printf("%lld",ans);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7
#define INF LONG_MAX/3
#define bit(n) (1LL<<(n))
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; }
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
struct segtree {
vector<long long> data;
long long n;
segtree(long long nin){
n = pow( 2, ceil( log(nin) / log(2) ) );
long long size = 2 * n - 1;
this->data.resize(size, 0);
}
//API for update val
void update(long long idx, long long val){
update(idx, val, 0, 0, n);
}
long long update(long long idx, long long val, long long node_id, long long left, long long right){
//if query idx is within range return val
if( !( left <= idx && idx < right ) ){
return data[node_id];
}
if( left + 1 < right ) {
//when node range is not 1, get update children val and update node data
long long mid = (left + right) / 2 ;
long long L = update(idx, val, 2 * node_id + 1, left, mid);
long long R = update(idx, val, 2 * node_id + 2, mid, right);
data[node_id] = L + R;
} else {
//when node range is 1, update node data
data[node_id] = data[node_id] + val;
}
return data[node_id];
}
//API for get value of [l, r)
long long get(long long l, long long r){
return get(l, r, 0, 0, n);
}
/*
*internaly used function
*query_l: query left range
*query_r: query right range
*node_id: node id of
*node_l: node left range
*node_r: node right range
*/
long long get(long long query_l, long long query_r, long long node_id, long long node_l, long long node_r){
//query range is outside of node range: return INF
if( query_r <= node_l || node_r <= query_l ){
return 0;
}
//query range is within node range: return node val
if( query_l <= node_l && node_r <= query_r ){
return data[node_id];
}
long long mid = (node_l + node_r) / 2;
long long L = get(query_l, query_r, 2 * node_id + 1, node_l, mid);
long long R = get(query_l, query_r, 2 * node_id + 2, mid, node_r);
return L + R;
}
};
vector<ll> yvec[200005];
int main(){
ll H, W, M;
cin >> H >> W >> M;
vector<ll>X(M);
vector<ll>Y(M);
ll maxx = W;
ll maxy = H;
segtree ysg(H+5);;
rep(i, M) cin >> Y[i] >> X[i];
rep(i, M) X[i]--;
rep(i, M) Y[i]--;
rep(i, M) {
yvec[X[i]].push_back(Y[i]);
if(Y[i] == 0) chmin(maxx, X[i]);
if(X[i] == 0) chmin(maxy, Y[i]);
}
rep(i, W) sort(yvec[i].begin(), yvec[i].end());
set<ll> ngy;
rep(i, maxy) ysg.update(i, 1);
ll ans = 0;
for(ll y = maxy; y < H; y++) ngy.insert(y);
for(ll x = 0; x < W; x++) {
ll miny = H;
if(x >= maxx) miny = 0;
for(ll y: yvec[x]) {
chmin(miny, y);
if(!ngy.count(y)) {
ngy.insert(y);
ysg.update(y, -1);
}
}
//cout << "x = " << x << " uekara " << miny << " yokokara " << ysg.get(miny, H) << endl;
//上からいけるやつ
ans += miny;
//上からいけなくて横からいけるやつ
ans += ysg.get(miny, H);
}
cout << ans << endl;
}
|
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int n;
ll ans=1;
ll gcd(ll ta,ll tb){
return tb?gcd(tb,ta%tb):ta;
}
int main(){
scanf("%d",&n);
for(int i=2;i<=n;i++) ans=ans*i/gcd(ans,i);
if(ans+1<=n) ans=(n/ans+1)*ans;
printf("%lld\n",ans+1);
return 0;
}
| #include <cctype>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <climits>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <regex>
#include <set>
#include <bitset>
const int64_t infl = 1LL << 60;
const int64_t cc = pow(10, 9) + 7;
bool sort_pair(std::pair<int64_t, int64_t> origin, std::pair<int64_t, int64_t> another){return origin.first < another.first;}
template <typename T> bool chmin(T &a, const T& b) {if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b) {if(a < b) {a = b;return true;}return false;}
int main()
{
int64_t n,m,q,k;
std::vector< int64_t > list;
n = 0;
std::string s;
std::cin>> s;
for( int i = 0; i < s.size(); i++ )
{
if( ( i % 2 == 0 ) && std::isupper( s[i] ) )
{
n = -1;
break;
}
if( ( i % 2 == 1 ) && std::islower( s[i] ) )
{
n = -1;
break;
}
}
if( n == -1 ) std::cout<< "No";
else std::cout<< "Yes";
}
|
#include <bits/stdc++.h>
using namespace std;
int N, T;
long long A[44];
auto calc(int S, int T) {
vector<long long> v;
for (int b = 0, e = 1 << (T - S); b < e; ++b) {
long long q = 0;
for (int i = 0; i < T - S; ++i) {
if (b & (1 << i)) q += A[S + i];
}
v.push_back(q);
}
sort(v.begin(), v.end());
return v;
}
int main() {
cin >> N >> T;
for (int i = 0; i < N; ++i) cin >> A[i];
auto a = calc(0, N / 2);
auto b = calc(N / 2, N);
long long x = 0;
auto set = [&](long long v) {
if (v > T) return;
x = max(x, v);
};
for (long long z : a) {
set(z);
set(z + b.back());
auto i = upper_bound(b.begin(), b.end(), T - z);
if (*i == 0) continue;
set(z + *(i - 1));
}
cout << x << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<endl
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;
vector<string> C(vector<string> s) {
ll n=s.size();
rep(i,n)REP(j,i+1,n) swap(s[i][j],s[j][i]);
return s;
}
ll n,m;
string s[1000];
ll calc(vector<string> t) {
ll cnt=0;
rep(k,m) {
ll f=0;
rep(l,2) {
rep(i,n) {
rep(j,n) {
if(t[i].substr(0,s[k].size())==s[k]) f=1;
rotate(t[i].begin(),t[i].begin()+1,t[i].end());
}
}
t=C(t);
}
cnt+=f;
}
return cnt;
}
vector<string> ans;
ll MM;
void solve(vector<string> t) {
ll d=calc(t);
if(MM<d) {
MM=d;
ans=t;
}
rep(k,5) {
random_shuffle(all(t));
rep(i,n) rotate(t[i].begin(),t[i].begin()+rand()%n,t[i].end());
ll d=calc(t);
if(MM<d) {
MM=d;
ans=t;
}
}
}
void Main() {
srand((unsigned)time(NULL));
cin >> n >> m;
rep(i,m) R s[i];
vector<string> v[15];
rep(i,m) v[s[i].size()].pb(s[i]);
rep(e,35) {
vector<string> t(n);
rrep(i,15) {
random_shuffle(all(v[i]));
rep(j,v[i].size()) {
ll M=MAX,x=0;
string rr;
rep(k,n) {
rep(l,t[k].size()+1) {
string r1=t[k].substr(l);
if(r1.size()<=v[i][j].size()) {
string r2=v[i][j].substr(0,r1.size());
if(r1==r2) {
ll d=t[k].size()+v[i][j].size()-r1.size();
if(d<=n&&M>d) {
M=d;
x=k;
rr=t[k]+v[i][j].substr(r1.size());
}
}
}
if(l+v[i][j].size()<=t[k].size()) {
r1=t[k].substr(l,v[i][j].size());
if(r1==v[i][j]) {
M=0;
x=k;
rr=t[k];
}
}
}
}
if(rand()%(i+1)==0) M=MAX;
if(M!=MAX) t[x]=rr;
}
}
rep(i,n) {
while(t[i].size()<n) {
//t[i]+='.';
t[i]+=(char)(rand()%8+'A');
}
}
solve(t);
}
rep(i,n) pr(ans[i]);
}
int main(){Main();return 0;}
|
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
#define INF 1e9
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int h, w;
cin >> h >> w;
vi arr(h*w);
for(auto& x: arr)
cin >> x;
sort(arr.begin(), arr.end());
int md = arr[0], ans = 0;
for(auto x: arr)
ans += abs(x-md);
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
//indexed set is using "int" here---------
// typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
while (y > 0)
{
if (y & 1)
res = (res * x) % p;
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
ll modInverse(ll n, ll p)
{
return power(n, p - 2, p);
}
int main()
{
FAST
// freopen("input1.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
/*ll tests;
cin>>tests;
rep (gg,0,tests)
{}*/
ll h,w;
cin>>h>>w;
ll arr[h][w];
ll val=4e18;
rep (i,0,h)
{
rep (j,0,w)
{
cin>>arr[i][j];
val=min(val,arr[i][j]);
}
}
ll ans=0;
rep (i,0,h)
{
rep (j,0,w)
{
ans+=abs(val-arr[i][j]);
}
}
cout<<ans<<"\n";
}
|
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define IOS ios::sync_with_stdio(0); cin.tie(0); mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define F first
#define S second
#define PI 4.0*atan(1.0);
#define pb push_back
using namespace std;
typedef pair<int, int> pi;
int mod=1e9+7,gaymod=998244353,MAX=1000000000,pomod=1073741824;
//long long int gcd(long long int x,long long int y){
// if(y==0)return x;
//return gcd(y,x%y);
//}
template<typename T>
T gcd(T x , T y){
if(y==0)return x;
return gcd(y,x%y);
}
template<typename L>
L lcm(L x,L y){
L g=gcd(x,y);
return x/g*y;
}
ll binexp(ll a,ll b){
if(b==0)return 1;
ll res=binexp(a,b/2);
if(b%2)return((res%mod)*(res%mod)*(a%mod));
else return((res%mod)*(res%mod));
}
int prime(ll x){
if(x%2==0&&x!=2)
return 0;
else if(x==1)return 0;
else{
for(int i=3;ll(i*i)<=x;i+=2){
if(x%i==0)
return 0;
}
}
return 1;
}
bool secsort(const pair<int,int> &a,const pair<int,int> &b){
return(a.S<b.S);
}
//main
/*
vector<char> is_prime(N+1, true);
void sieve(int n){
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; i++) {
if (is_prime[i] && (long long)i * i <= n) {
for (int j = i * i; j <= n; j += i)
is_prime[j] = false;
}
}
}
*/
//freopen("input.txt","r",stdin);
//freopen("input.txt","w",stdin);
const int N=2e5+5;
const int Z=1e6+5;
//
int main(){
IOS;
int t=1;
//cin>>t;
while(t--){
int n;
cin>>n;
int arr[n];
map<int,ll> M;
ll ans=0;
for(int i=0;i<n;i++){
cin>>arr[i];
}
M[arr[0]]++;
for(ll i=1;i<n;i++){
M[arr[i]]++;
ans+=(i+1)-M[arr[i]];
}
cout<<ans;
cout<<"\n";
}
return 0;
}
| //IF YOU GIVE UP,THEN YOU DON'T DESERVE IT
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define PI 3.14159265358979323846264
#define isz(x) (int)x.size()
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define typ int
#define ordered_set tree<typ, null_type, less<typ>, rb_tree_tag, tree_order_statistics_node_update>
//*s.find_by_order(x) --> value at position x(0-indexed)
//s.order_of_key(x) --> number of elements less than x
#define eps 1e-9
#define int long long
int32_t main()
{
int n;
cin>>n;
int u = 0,v = 0,mx =-INT_MAX;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
mx = max(mx,abs(x));
u+=abs(x);
v+=(x*x);
}
cout<<u<<" \n"<<setprecision(50)<<sqrt(v)<<" \n"<<mx;
}
|
/*
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=2*1e5+100;
int n,a[N],b[N],p[N],vi[N],wh[N];
vector <pair<int,int> > ans;
priority_queue <pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q;
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;
}
signed main()
{
n=read();
for (int i=1;i<=n;i++) a[i]=read();
for (int i=1;i<=n;i++) b[i]=read();
for (int i=1;i<=n;i++) p[i]=read();
for (int i=1;i<=n;i++)
{
if (p[i]==i){vi[i]=1;continue;}
if (a[i]<=b[p[i]])
{
printf("-1\n");
return 0;
}
q.push(m_k(a[i],i));wh[p[i]]=i;
}
while (!q.empty())
{
int x=q.top().second,y;q.pop();
if (vi[x]) continue;
vi[x]=1;y=wh[x];
ans.push_back(m_k(x,y));
wh[p[x]]=y;
swap(p[x],p[y]);
if (y==p[y]) vi[y]=1;
}
printf("%d\n",(int)ans.size());
for (int i=0;i<(int)ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
}
| #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
using ld = long double;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define mp make_pair
const int MOD = 998244353;
int mul(int a, int b) {
return (1LL * a * b) % MOD;
}
int add(int a, int b) {
int s = (a+b);
if (s>=MOD) s-=MOD;
return s;
}
int sub(int a, int b) {
int s = (a+MOD-b);
if (s>=MOD) s-=MOD;
return s;
}
int po(int a, ll deg)
{
if (deg==0) return 1;
if (deg%2==1) return mul(a, po(a, deg-1));
int t = po(a, deg/2);
return mul(t, t);
}
int inv(int n)
{
return po(n, MOD-2);
}
mt19937 rnd(time(0));
const int LIM = 200000;
vector<int> facs(LIM), invfacs(LIM);
void init()
{
facs[0] = 1;
for (int i = 1; i<LIM; i++) facs[i] = mul(facs[i-1], i);
invfacs[LIM-1] = inv(facs[LIM-1]);
for (int i = LIM-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}
int C(int n, int k)
{
if (n<k) return 0;
if (n<0 || k<0) return 0;
return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}
/*
struct DSU
{
vector<int> sz;
vector<int> parent;
void make_set(int v) {
parent[v] = v;
sz[v] = 1;
}
int find_set(int v) {
if (v == parent[v])
return v;
return find_set(parent[v]);
}
void union_sets(int a, int b) {
a = find_set(a);
b = find_set(b);
if (a != b) {
if (sz[a] < sz[b])
swap(a, b);
parent[b] = a;
sz[a] += sz[b];
}
}
DSU (int n)
{
parent.resize(n);
sz.resize(n);
for (int i = 0; i<n; i++) make_set(i);
}
};*/
const int N = 10000;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
init();
int n; cin>>n;
vector<int> w(n);
for (int i = 0; i<n; i++) cin>>w[i];
vector<vector<int>> dp(N+1, vector<int>(n+1));
dp[0][0] = 1;
for (int i = 0; i<n; i++)
{
for (int W = N; W>=w[i]; W--)
for (int cnt = i+1; cnt>=1; cnt--) dp[W][cnt] = add(dp[W][cnt], dp[W-w[i]][cnt-1]);
}
int tot = 0; for (auto it: w) tot+=it;
if (tot%2==1) {cout<<0<<endl; return 0;}
int need = tot/2;
int ans = 0;
for (int take = 0; take<=n; take++)
{
ans = add(ans, mul(dp[need][take], mul(facs[take], facs[n-take])));
}
cout<<ans;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define all(x) x.begin(),x.end()
template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }
const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }
const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
x += y;
if( x >= m )
x -= m;
}
template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
x -= y;
if( x < 0 )
x += m;
}
char grid[2002][2002];
int up[2002][2002], lft[2002][2002], diag[2002][2002];
ll dp[2002][2002], prefix_row[2002][2002], prefix_col[2002][2002], prefix_diag[4004][2002];
int main()
{
#ifdef gupta_samarth
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fastio();
int h,w;
cin>>h>>w;
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
cin>>grid[i][j];
if( grid[i][j] == '#' )
{
lft[i][j] = j;
up[i][j] = i;
diag[i][j] = i;
}
else
{
lft[i][j] = ( j-1 >= 0 ? lft[i][j-1] : 0 );
up[i][j] = ( i-1 >= 0 ? up[i-1][j] : 0 );
diag[i][j] = ( i-1 >= 0 && j-1 >= 0 ? diag[i-1][j-1] : 0 );
}
dp[i][j] = 0;
}
}
auto sum_row = [&]( int row, int lc, int rc ) -> ll
{
if( rc < lc )
return 0;
ll ans = prefix_row[row][rc];
if( lc )
sub( ans, prefix_row[row][lc] );
return ans;
};
auto sum_col = [&]( int col, int lr, int rr ) -> ll
{
if( rr < lr )
return 0;
ll ans = prefix_col[rr][col];
if( lr )
sub( ans, prefix_row[lr][col] );
return ans;
};
auto sum_diag = [&]( int dg, int l, int r ) -> ll
{
if( r < l )
return 0;
ll ans = prefix_diag[dg][r];
if( l )
sub( ans, prefix_diag[dg][l] );
return ans;
};
auto update = [&]( int i, int j, ll val )
{
if( j-1 >= 0 )
prefix_row[i][j] = prefix_row[i][j-1];
add( prefix_row[i][j], val );
if( i-1 >= 0 )
prefix_col[i][j] = prefix_col[i-1][j];
add( prefix_col[i][j], val );
if( i-1 >= 0 )
prefix_diag[j-i+2000][i] = prefix_diag[j-i+2000][i-1];
add( prefix_diag[j-i+2000][i], val );
};
dp[0][0] = 1;
update(0,0,1);
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
if( grid[i][j] == '#' || ( i == 0 && j == 0 ) )
continue;
// cout<<"NOW: "<<i<<" "<<j,nl;
// cout<<"Left: "<<i<<" "<<lft[i][j],nl;
// cout<<"Up: "<<up[i][j]<<" "<<j,nl;
// for(int a=0;a<=j;a++)
// cout<<prefix_row[i][a]<<" ";
// nl;nl;
ll now = 0;
add( now, sum_row(i,lft[i][j],j-1) );
add( now, sum_col(j,up[i][j],i-1) );
add( now, sum_diag(j-i+2000,diag[i][j],i-1));
add( dp[i][j], now );
update(i,j,dp[i][j]);
}
}
cout<<dp[h-1][w-1],nl;
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
| #include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#define ll long long int
#define ld double
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;
#define br "\n"
#define ff first
#define ss second
#define gcd __gcd
ll mod = 1e9 + 7;
ll dirx[] = {-1,-1,0};
ll diry[] = {-1,0,-1};
ll sum[2000][2000][3];
ll dp[2000][2000];
vector<vll> grid;
void solve(){
ll n,m;
cin >> n >> m;
grid.assign(n,vll(m));
rep(i,0,n){
rep(j,0,m){
char c;
cin >> c;
if(c == '.') grid[i][j] = 1;
rep(k,0,3){
sum[i][j][k] = 0;
}
dp[i][j] = 0;
}
}
dp[0][0] = 1;
rep(i,0,n){
rep(j,0,m){
rep(k,0,3){
if(!grid[i][j]){
continue;
}
ll x = i + dirx[k], y = j + diry[k];
if(x < 0 || y < 0 || x >= n || y >= m) continue;
(dp[i][j] += sum[x][y][k]) %= mod;
(sum[i][j][k] += sum[x][y][k]) %= mod;
}
rep(k,0,3){
(sum[i][j][k] += dp[i][j]) %= mod;
}
}
}
cout << dp[n - 1][m - 1];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t = 1;
// cin >> t;
rep(i,0,t){
// cout << "Case #" << i + 1 << ": ";
solve();
// test();
}
} |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define deb(x...) cout << #x << " = ["; _print(x)
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
// =================
#define f(i, k, n) for (int i = k; i < n; i++)
#define r(i, k, n) for (int i = k; i >= n; i--)
#define ll long long
#define pb push_back
#define fr first
#define sc second
#define len(s) s.size()
#define all(v) v.begin(), v.end()
#define tr(it, v) for (auto &it : v)
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<vi> vvi;
// =================
const int mod = 1e9+7;
const int N = 3e5 + 1;
void solve()
{
ll x,y;
int a,b;
cin>>x>>y>>a>>b;
int req=(b+a-2)/(a-1);
ll days=0;
while (1ll*x*a<req && 1ll*x*a<y && 1ll*x*a>0)
{
x*=a;
days++;
}
// if(x*a<x+b && x*a<y && 1ll*x*a>0) {
// x*=a;
// days++;
// }
// else if(x+b<y && x+b>0) {
// x+=b;
// days++;
// }
if(x<y && x>0) {
days+=(y-1-x)/b;
}
cout<<days;
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
while (t--)
solve();
return 0;
} | #pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 200001;
using ll = long long;
using db = double;
#define FOR(i, x, n) for (int i = x; i < n; i++)
#define TRAV(it, x) for (auto it = x.begin(); it != x.end(); it++)
#define endl "\n"
int n;
ll a[INF];
ll ps1[INF], ps2[INF];
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);
// ifstream fin(".in");
// ofstream fout(".out");
cin >> n;
FOR(i, 1, n + 1) {
cin >> a[i];
}
FOR(i, 1, n + 1) {
ps1[i] = ps1[i - 1] + a[i];
}
FOR(i, 1, n + 1) {
ps2[i] = max(ps1[i], ps2[i - 1]);
}
ll current = 0;
ll ans = -1e9;
FOR(i, 1, n + 1) {
ans = max(ans, current + ps2[i]);
current += ps1[i];
}
cout << ans << endl;
return 0;
}
/*
*
*/
|
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#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 ll long long
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
// SOME BITMASK KNOWLEDGE
// 1)x & (x - 1):sets the last one bit of x to zero
// power of two exactly when x & (x − 1) = 0.
// 2)x & -x:sets all the one bits to zero, except last one bit
// 3)x | (x - 1):inverts all the bits after the last one bit
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
typedef tree<string,null_type,less<string>,rb_tree_tag,tree_order_statistics_node_update> indexed_set2;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ll power(ll a,ll n,ll c){
if(n == 0) return 1 % c;
ll s = power(a,n/2,c);
s = (s * s) % c;
if(n % 2) s = (s * a) % c;
return s;
}
int main()
{
ll n,t;
cin>>n>>t;
ll arr1[n/2],arr2[n-n/2];
REP(i,0,n/2) cin>>arr1[i];
REP(i,0,n-n/2) cin>>arr2[i];
set<ll> s;
REP(i,0,(1 << (n/2))){
ll sum = 0;
REP(j,0,n/2){
if((i >> j) & 1){
sum += arr1[j];
}
}
s.insert(sum);
}
vector<ll> v;
for(auto it:s) v.push_back(it);
sort(v.begin(),v.end());
ll ans = 0;
REP(i,0,(1 << (n - n/2))){
ll sum = 0;
REP(j,0,n - n/2){
if((i >> j) & 1){
sum += arr2[j];
}
}
ll p = t - sum;
if(p >= 0){
ll p1 = upper_bound(v.begin(),v.end(),p) - v.begin();
if(p1 > 0){
ans = max(ans,sum + v[p1-1]);
}
else {
ans = max(ans,sum);
}
}
}
cout<<ans<<endl;
return 0;
} | #pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
const int mod = 998244353;
constexpr ll modpow(ll A, ll B) {
ll kotae = 1;
while (B > 0) {
if (B & 1) kotae = kotae * A % mod;
A = A * A % mod;
B >>= 1;
}
return kotae;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, M;
cin >> N >> M;
ll MI = modpow(M, mod - 2);
ll kotae = 0;
rep1(k, M) {
ll tmp = 0;
ll pre = 1;
ll MK = (M - k) * MI % mod;
rep(i, N) {
kotae += tmp + pre;
tmp += (k - 1) * MI % mod * pre % mod;
tmp %= mod;
pre = pre * MK % mod;
}
}
kotae = kotae % mod * modpow(M, N - 1) % mod;
co(kotae);
Would you please return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#pragma optimize("-O3")
#define int long long int
#define f first
#define s second
#define pb push_back
#define endl '\n'
main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(int i=1; i<=n; i++){
cout<<((2*i)%n)+1<<" "<<((2*i+1)%n)+1<<endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define mii map<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define ppc __builtin_popcount
#define ppcll __builtin_popcountll
#define INF 100000000000000000
#define mod 1000000007
#define esp 10e-7
const int mx=1e5+7;
bool isseven(int n){
while(n){
if(n%10==7){
return true;
}
n/=10;
}
return false;
}
bool isoctalseven(int n){
while(n){
if(n%8==7){
return true;
}
n/=8;
}
return false;
}
int main(){
int n;
cin>>n;
int m=7;
unordered_set<int> st;
// int c1=0;
// while(m<=n){
// c1++;
// st.insert(m);
// m+=8;
// }
// cout<<c1;
int c2=0;
rep(i,1,n+1){
if((isseven(i) )|| isoctalseven(i)){
// cout<<i<<" ";
c2++;
}
}
cout<<n-(c2);
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.