code_file1
stringlengths 87
4k
| code_file2
stringlengths 85
4k
|
---|---|
#line 1 "/home/siro53/kyo-pro/compro_library/template/template.cpp"
#include <bits/stdc++.h>
using namespace std;
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;
}
#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
struct Setup {
Setup() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} __Setup;
using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define FOR(i, a, b) for(int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//-------------------------------------
#line 2 "d.cpp"
int H, W, A, B;
ll ans;
void dfs(int i, int mask, int a, int b) {
if(i == H * W) {
ans++; return;
}
if(mask >> i & 1) {
dfs(i+1, mask, a, b);
return;
}
if(a > 0) {
if(i % W < W-1 and (mask >> (i+1) & 1) == 0) {
dfs(i+1, mask | (1 << i) | (1 << (i+1)), a-1, b);
}
if(i / W < H-1 and (mask >> (i+W) & 1) == 0) {
dfs(i+1, mask | (1 << i) | (1 << (i+W)), a-1, b);
}
}
if(b > 0) {
dfs(i+1, mask | (1 << i), a, b-1);
}
}
int main() {
cin >> H >> W >> A >> B;
ans = 0;
dfs(0, 0, A, B);
cout << ans << endl;
}
| #include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target ("avx2,avx,fma")
typedef long long int ll;
#define int long long int
typedef long double db;
typedef pair <int,int> ii ;
typedef vector < int > vi ;
typedef vector < ii > vii ;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define repu(i,a,b) for(int i = a ; i <= b ; i++)
#define repd(i,b,a) for(int i = b ; i >= a ; i--)
#define pb push_back
#define fi first
#define se second
#define all(p) p.begin(),p.end()
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Endl endl
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (int)r;}
template <class T>inline void sary(T st, T nd){while(st<nd)cin>>*st++;/*sf("%d", st++);*/}
int mod=998244353;
inline ll mul(ll a, ll b){return ((a%mod)*(b%mod))%mod;}
inline ll add(ll a, ll b){return ((a%mod)+(b%mod))%mod;}
inline ll sub(ll a, ll b){return ((a%mod)-(b%mod)+mod)%mod;}
inline ll divi(ll a, ll b) { return (500000004*(a%mod))%mod; }
const int N= 5002;
void solve() {
int n; cin>>n;
vii v(n);
rep(i,n) cin>>v[i].fi>>v[i].se;
int s=0;
rep(i,n) s+=v[i].fi;
vi a(n);
rep(i,n) a[i]=2*v[i].fi+v[i].se;
sort(all(a),greater<int>());
int t=-s;
rep(i,n) {
t+=a[i];
if(t>0) {
cout<<i+1; return;
}
}
}
int32_t main() {
IOS
int t=1;
//cin>>t;
#ifndef ONLINE_JUDGE
clock_t clk = clock();
#endif
while(t--) solve();
#ifndef ONLINE_JUDGE
cerr << "\nTime (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
#endif
} |
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#include <functional>
#define sz(x) ((int)(x).size())
#define mp make_pair
#define full(a) a.begin(), a.end()
#define pii pair<int, int>
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 3e5 + 5;
// printf("%.2f\n", value); digits after decimal
// 'a' - 97
// 'A' - 65
ll binpow(ll a, ll b)
{
a %= mod;
ll res = 1;
while (b > 0)
{
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(NULL); //cout.tie(NULL);
int h, w; cin >> h >> w;
ll tidy = 0;
vector<vector<char>> v(h, vector<char>(w));
for (int i = 0; i < h; i++)
{
for (int j = 0; j < w; j++)
{
cin >> v[i][j];
if (v[i][j] == '.') tidy++;
}
}
ll all = binpow(2, tidy);
ll c = 0;
ll cnt_row = -1;
vector<ll> col(w, -1);
for (int i = 0; i < h; i++)
{
for (int j = 0; j < w; j++)
{
if (v[i][j] == '#')
{
cnt_row = -1;
col[j] = -1;
continue;
}
if (cnt_row == -1)
{
cnt_row++;
for (int k = j; k < w; k++)
{
if (v[i][k] == '#') break;
cnt_row++;
}
}
if (col[j] == -1)
{
col[j]++;
for (int k = i; k < h; k++)
{
if (v[k][j] == '#') break;
col[j]++;
}
}
ll num = cnt_row + col[j];
num--;
c += (all + mod - binpow(2, tidy - num));
c %= mod;
}
cnt_row = -1;
}
cout << c;
return 0;
} | /*************************************************************************
> File Name: 1.cpp
> Author: Knowledge_llz
> Mail: [email protected]
> Blog: https://blog.csdn.net/Pig_cfbsl
> Created Time: 2020/10/10 20:03:44
************************************************************************/
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define pb push_back
#define pr pair<int,int>
#define fi first
#define se second
#define LL long long
using namespace std;
int read(){
char x=getchar(); int u=0,fg=0;
while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
return fg?-u:u;
}
const int mod=1e9+7;
int n,m,dx[5]={0,0,-1,1},dy[5]={-1,1,0,0};
LL ans=0,num=0,l[2020][2020],r[2020][2020],u[2020][2020],d[2020][2020];
char s[2020][2020];
LL qpow(LL y){
LL x=2,res=1;
while(y){
if(y&1) res=(res*x)%mod;
x=x*x%mod;
y>>=1;
}
return res;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif
n=read(); m=read();
For(i,1,n) scanf("%s",s[i]+1);
For(i,1,n) For(j,1,m){
num+=(s[i][j]=='.');
if(s[i][j]=='.'){
if(s[i-1][j]=='.') u[i][j]=u[i-1][j]+1;
if(s[i][j-1]=='.') l[i][j]=l[i][j-1]+1;
}
}
for(int i=n;i;--i) for(int j=m;j;--j)
if(s[i][j]=='.'){
if(s[i+1][j]=='.') d[i][j]=d[i+1][j]+1;
if(s[i][j+1]=='.') r[i][j]=r[i][j+1]+1;
}
For(i,1,n) For(j,1,m)
if(s[i][j]=='.'){
LL tmp=1+l[i][j]+r[i][j]+u[i][j]+d[i][j];
ans+=(qpow(tmp)-1ll)*qpow(num-tmp)%mod;
ans%=mod;
}
printf("%lld\n",ans);
return 0;
}
|
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 2147483647
#define INF 3223372036854775807
#define MOD 1000000007
#define mod 1000000007
//#define mod 998244353
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
//#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define pi acos(-1.0)
#define me memset
// /#define bit(n,k) ((n>>k)&1)
#define lg length()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invp(a,p)pom(a,p-2,p)
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<Pll,ll> a,pair<Pll,ll> b){
return a.fi.se<b.fi.se;
}
ll cmp2(pair<ll,ll> a,pair<ll,ll> b){
if(a.fi!=b.fi)
return a.fi<b.fi;
else
return a.se<b.se;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
int main(int argc, char * argv[]){
cin.tie(0);
ios::sync_with_stdio(false);
//-------------------------------
//ll begin_t=clock();
//freopen("big.txt", "r", stdin);
//freopen("out3.txt", "w", stdout);
//------------------------------
ll h,w,x,y;cin>>h>>w>>x>>y;
x--;y--;
char s[110][110];
for(ll i=0;i<h;i++){
for(ll j=0;j<w;j++){
cin>>s[i][j];
}
}
ll ans = 1;
for(ll i=x+1;i<h;i++){
if(s[i][y]=='#')break;
ans++;
}
for(ll i=x-1;i>=0;i--){
//cout<<i<<endl;
if(s[i][y]=='#')break;
ans++;
}
for(ll i=y-1;i>=0;i--){
//cout<<i<<endl;
if(s[x][i]=='#')break;
ans++;
}
for(ll i=y+1;i<w;i++){
if(s[x][i]=='#')break;
ans++;
}
cout<<ans<<endl;
//------------------------------
//fclose(stdin);
//fclose(stdout);
//ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
//-------------------------------
return 0;
}
//----------------------------------------------------------------------
| #include<bits/stdc++.h>
#define db double
#define reg register
#define LL long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ull unsigned long long
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
#define erep(i,a) for(int i=head[a];i;i=e[i].nxt)
using namespace std;
bool Handsome;
inline void Mi(int &x,int y){if(x>y && (x=y));}
inline void Mx(int &x,int y){if(x<y && (x=y));}
const int M=1005;
int n,m,ans=1e9;
bool vis[M][M];
vector<int> g[M][30];
struct node{int a,b,st;}tmp;
queue<node> q;
bool Most;
int main(){
// printf("%.2lfMB\n",(&Most-&Handsome)/1024.0/1024.0);
scanf("%d%d",&n,&m);
rep(i,1,m){
int a,b;char c;
scanf("%d %d %c",&a,&b,&c);
g[a][c-'a'].pb(b);
g[b][c-'a'].pb(a);
}
vis[1][n]=1;
q.push((node){1,n,0});
while(!q.empty()){
tmp=q.front();q.pop();
int a=tmp.a,b=tmp.b,st=tmp.st;
if(st>=ans)break;
if(a==b){Mi(ans,st);continue;}
rep(p,0,25){
rep(i,0,g[a][p].size()-1)
if(g[a][p][i]==b)Mi(ans,st+1);
rep(i,0,g[b][p].size()-1)
if(g[b][p][i]==a)Mi(ans,st+1);
rep(i,0,g[a][p].size()-1){
int u=g[a][p][i];
rep(j,0,g[b][p].size()-1){
int v=g[b][p][j];
if(vis[u][v])continue;vis[u][v]=1;
q.push((node){u,v,st+2});
}
}
}
}
if(ans==1e9)ans=-1;
printf("%d\n",ans);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define GODSPEED ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define f first
#define s second
#define newl cout<<"\n";
#define pb push_back
#define mset(a,x) memset(a,x,sizeof(a))
#define debv(a) for(auto it: a)cout<<it<<" ";newl;
#define deb1(a) cout<<a<<"\n";
#define deb2(a,b) cout<<a<<" "<<b<<"\n";
#define deb3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define deb4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define uniq(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll N = 5e5+5;
const ll M = 4e6+5;
const ll mod = 1e9+7;
const ll INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
ll n, a, b;
ll fastmod(ll x, ll y = mod - 2){
ll res = 1;
while(y){
if(y&1) res = res * x % mod;
x = x * x % mod;
y /= 2;
}
return res;
}
ll sum(ll x){
return x * (x + 1) % mod * fastmod(2) % mod;
}
ll mul(ll x, ll y){
return x * y % mod;
}
void solve(){
cin >> n >> a >> b;
ll x = n - b + 1;
ll y = n - a - b + 1;
ll z = n - a + 1;
if(y <= 0){
deb1(0)
return;
}
ll s1 = mul(mul(sum(y), x), z), s2 = mul(sum(y), sum(y));
deb1((4*(s1 - s2) + 4*mod) % mod)
}
int main(){
GODSPEED;
int test = 1;
cin >> test;
for(int i = 1; i <= test; i++){
solve();
}
} | #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;
ll mod=1000000007;
int solve(){
ll N, A, B;
cin >> N >> A >> B;
if(A+B>N){
cout << 0 << endl;
return 0;
}
if(A>B) swap(A, B);
ll sum=(((N-A+1)*(N-A+1)%mod)*((N-B+1)*(N-B+1)%mod))%mod;
ll h=min(A+B-1, N-A+1)%mod;
ll f=h*(N-B+1)%mod, g=(h-B)*(h-B+1)%mod;
(sum += mod-(f+mod-g)*(f+mod-g)%mod) %= mod;
cout << sum << endl;
return 0;
}
int main() {
int T;
cin >> T;
for(int i=0; i<T; ++i){
solve();
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define re register
#define in inline
#define get getchar()
#define ll long long
int main()
{
ll n;
cin>>n;
if(n<=2) cout<<1<<endl;
else
{
ll l=2,r=sqrt(2*n),mid,ans;
while(l<=r)
{
mid=l+r>>1;
if((2+mid)*(mid-1)/2<=n) ans=mid, l=mid+1;
else r=mid-1;
}
cout<<2+((n-1)-ans)<<endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i < n; ++i)
#define exrep(i, a, b) for (ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef vector<vector<double>> vvd;
typedef vector<vector<string>> vvs;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);
template <class T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
template <class T>
void debug(T v)
{
rep(i, v.size()) cout << v[i] << " ";
cout << endl;
}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());
signed main()
{
gearup;
ll n;
cin >> n;
ll ma = 1e9 * 2 + 10, mi = 0;
while (ma - mi > 1)
{
ll mid = (ma + mi) / 2;
// 1 ~ midまでの数が作れるか
ll ttl = mid * (1 + mid) / 2;
if (ttl <= n + 1)
mi = mid;
else
ma = mid;
}
out(n - ma + 2);
}
|
#include <algorithm>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define pii pair<int, int>
#define mii map<int, int>
#define pis pair<int, string>
#define vi vector<int>
#define int long long
#define endl "\n"
#define IOS \
std::ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
const int inf = 1e16;
const int mod = 1e9 + 7;
const int Max = 1e5 + 5;
int pow(int a, int b)
{
int res = 1;
while(b > 0) {
if(b & 1) {
res = (res * a) % mod;
}
a = (a * a) % mod;
b >>= 1;
}
return res;
}
vector<bool> is_prime(Max, true);
void sieve()
{
is_prime[0] = false;
is_prime[1] = false;
for(int i = 2; i * i < Max; i++) {
if(is_prime[i]) {
for(int j = i * i; j < Max; j += i) {
is_prime[j] = false;
}
}
}
}
int32_t main()
{
IOS;
int t;
t = 1;
// cin >> t;
while(t--) {
int a,b,c,d;
cin>>a>>b>>c>>d;
int z=c*d-b;
if(z<=0){
cout<<-1<<endl;
continue;
}
int ans=(a+z-1)/z;
cout<<ans<<endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define SIZE(x) ll(x.size())
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 long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
typedef pair<int, int> P;
int main()
{
int T;
cin >> T;
rep(i, T) {
int N;
string S1, S2, S3;
cin >> N >> S1 >> S2 >> S3;
string ans = "1";
rep(i, N) ans += "0";
rep(i, N) ans += "1";
cout << ans << endl;
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define PI 3.14159265
#define double long double
//#define DB
#ifdef DB
#define el cerr << "\n";
#define db(...) cerr << " [" << #__VA_ARGS__ << " : " << __VA_ARGS__ << "] ";
#else
#define el
#define db(...)
#endif // DB
const int N = 505;
int n;
int p[N];
int sz;
int moves[N * N];
int curPos[N];
void doSwap(int i) {
swap(p[i], p[i + 1]);
curPos[p[i]] = i;
curPos[p[i + 1]] = i + 1;
moves[sz] = i;
++sz;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> p[i];
curPos[p[i]] = i;
}
sz = 0;
for (int i = 1; i <= n; ++i) {
if (p[i] == i) continue;
int j = curPos[i];
if (j % 2 != sz % 2) {
// if (j < n - 2) {
// doSwap(j + 2);
// } else
if (i < j - 1) {
doSwap(j - 2);
} else { // A i j
doSwap(i - 1); doSwap(i);
doSwap(i - 1); doSwap(i);
doSwap(i - 1);
continue;
}
}
for (int k = j - 1; k >= i; --k) {
doSwap(k);
}
}
}
int main() {
// freopen("C:\\Users\\T\\CLionProjects\\cp-chemthan\\atcoder\\regular121\\C.in", "r", stdin);
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
solve();
cout << sz << "\n";
if (sz) {
for (int i = 0; i < sz; ++i) {
cout << moves[i] << " ";
}
cout << "\n";
}
}
return 0;
}
| /*@author Vipen Loka*/
#include <bits/stdc++.h>
#define endl '\n'
#define ff first
#define ss second
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define deb(x) cout << #x << ':' << x << '\n';
using namespace std;
template<class T>void show(vector<T> &a) {cerr << "[ "; for (int ij = 0; ij < (int)a.size(); ij++) {cerr << a[ij] << " ";} cerr << "]\n";}
template<class T>void show(T a) {cerr << a << endl;}
template<typename... T>void show(T... args) {((cerr << args << ' '), ...); cerr << endl;}
template<class T>void read(vector<T> &a) {for (auto &x : a) {cin >> x;}}
template<class T> void read(T &a) {cin >> a;}
void solve() {
int i, j;
int n;
read(n);
vector<int> a(n);
read(a);
vector<int> ans;
int f=0;
while(!is_sorted(a.begin(),a.end())){
bool b=1;
for (int j = 0; j < n-1; ++j)
{
if(a[j]>a[j+1] && j%2==f){
swap(a[j],a[j+1]);
ans.push_back(j+1);
f^=1;
b=0;
}
}
if(b){
ans.push_back(f+1);
swap(a[f],a[f+1]);
f^=1;
}
}
cout << ans.size() << endl;
for(auto &x:ans){
cout << x << ' ';
}
cout << endl;
}
int32_t main(int32_t argc, char *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int T = 1;
cin >> T;
while (T--) {
solve();
}
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
} |
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i @hamayanhamayan0
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
string S1, S2, S3;
#define NOANS "UNSOLVABLE"
//---------------------------------------------------------------------------------------------------
vector<char> chars;
char used[10];
bool check() {
map<char, char> mapping;
rep(i, 0, 10) if (used[i] != 0) mapping[used[i]] = char('0' + i);
string SS1, SS2, SS3;
fore(c, S1) SS1 += mapping[c];
fore(c, S2) SS2 += mapping[c];
fore(c, S3) SS3 += mapping[c];
if (to_string(stoll(SS1)) != SS1) return false;
if (to_string(stoll(SS2)) != SS2) return false;
if (to_string(stoll(SS3)) != SS3) return false;
if (stoll(SS1) + stoll(SS2) != stoll(SS3)) return false;
if (stoll(SS1) == 0) return false;
if (stoll(SS2) == 0) return false;
if (stoll(SS3) == 0) return false;
cout << SS1 << endl;
cout << SS2 << endl;
cout << SS3 << endl;
return true;
}
bool dfs(int cu) {
if (cu == chars.size()) return check();
rep(i, 0, 10) if (used[i] == 0) {
used[i] = chars[cu];
if (dfs(cu + 1)) return true;
used[i] = 0;
}
return false;
}
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> S1 >> S2 >> S3;
fore(c, S1) chars.push_back(c);
fore(c, S2) chars.push_back(c);
fore(c, S3) chars.push_back(c);
sort(all(chars));
chars.erase(unique(all(chars)), chars.end());
if (10 < chars.size()) {
cout << NOANS << endl;
return;
}
bool res = dfs(0);
if (res == false) cout << NOANS << endl;
}
| #pragma region head
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
template <class T>
inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess {
preprocess() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
} ____;
#pragma endregion head
#pragma region library
#pragma endregion library
int main() {
int h, w, n, m;
cin >> h >> w >> n >> m;
vv<ll> vec(h + 1, vector<ll>(w + 1));
vector<pi> lights;
rep(i, n) {
int a, b;
cin >> a >> b;
a--;
b--;
lights.emplace_back(a, b);
}
vv<bool> block(h, vector<bool>(w));
rep(i, m) {
int c, d;
cin >> c >> d;
c--;
d--;
block[c][d] = true;
}
vv<int> right(h, vector<int>(w, w));
vv<int> left(h, vector<int>(w, -1));
vv<int> up(h, vector<int>(w, -1));
vv<int> down(h, vector<int>(w, h));
rep(i,h){
int now = -1;
rep(j,w){
if(block[i][j]){
now = j;
} else {
left[i][j] = now;
}
}
now = w;
rrep(j,w){
if(block[i][j]){
now = j;
} else {
right[i][j] = now;
}
}
}
rep(j,w){
int now = -1;
rep(i,h){
if(block[i][j]){
now = i;
} else {
up[i][j] = now;
}
}
now = h;
rrep(i,h){
if(block[i][j]){
now = i;
} else {
down[i][j] = now;
}
}
}
rep(i,n){
int a, b;
tie(a, b) = lights[i];
int u = up[a][b];
int d = down[a][b];
int l = left[a][b];
int r = right[a][b];
vec[u+1][b]++;
vec[u+1][b+1]--;
vec[d][b]--;
vec[d][b+1]++;
vec[a][l+1]++;
vec[a+1][l+1]--;
vec[a][r]--;
vec[a+1][r]++;
}
rep(i,h)rep(j,w){
vec[i][j+1] += vec[i][j];
}
rep(j,w)rep(i,h){
vec[i+1][j] += vec[i][j];
}
int ans = 0;
rep(i,h)rep(j,w){
if(vec[i][j]>0){
ans++;
}
}
cout << ans << '\n';
}
|
#include <iostream>
using namespace std;
int A, B;
double W;
int isin(double N) {
if(N >= A and N <= B) {
return true;
} else {
return false;
}
}
int main() {
cin >> A >> B >> W;
int max = 0;
int min = 0;
for (int i = 1; i <= W * 1000; i++) {
double pre = W * 1000 / i;
if(isin(pre)) {
min = i;
break;
}
}
for (int i = W * 1000; i > 0; i--) {
double pre = W * 1000 / i;
if(isin(pre)) {
max = i;
break;
}
}
if (min == 0) {
min = max;
}
if (max == 0) {
max = min;
}
if (min == 0 and max == 0) {
cout << "UNSATISFIABLE" << endl;
} else {
cout << min << " " << max << endl;
}
} | #include<set>
#include<queue>
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAXN (1<<18|5)
#define ENDL putchar('\n')
#define LL long long
#define DB double
#define lowbit(x) ((-x) & (x))
LL read() {
LL f = 1,x = 0;char s = getchar();
while(s < '0' || s > '9') {if(s=='-')f = -f;s = getchar();}
while(s >= '0' && s <= '9') {x=x*10+(s-'0');s = getchar();}
return f * x;
}
int n,m,i,j,s,o,k;
int main() {
s = read();o = read();k = read()*1000;
int l = (k+o-1)/o,r = k / s;
if(l > r) printf("UNSATISFIABLE\n");
else printf("%d %d\n",l,r);
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend() //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;
int main(){
int a[4];
rep(i,4) cin >> a[i];
int ans = 200;
for(auto i : a){
ans = min(ans,i);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
int A1,A2,A3,A4;
scanf("%d %d %d %d",&A1,&A2,&A3,&A4);
int A[10]={A1,A2,A3,A4};
int min=A[0];
for(int i=0;i<4;i++){
if(A[i]<min){
min=A[i];
}
}
printf("%d",min);
}
|
#include <bits/stdc++.h>
// #include <atcoder/all>
// #include <boost/multiprecision/cpp_int.hpp>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) a.begin(), a.end()
#define yn(p) cout << (p?"Yes":"No") << endl;
using namespace std;
// using namespace atcoder;
using ll = long long;
// using lll = boost::multiprecision::cpp_int;
using P = pair<int, int>;
void solve() {
int n;
cin >> n;
vector<ll> a(n), b(n);
rep(i, n) cin >> a[i] >> b[i];
ll ans = 0;
rep(i, n) {
ans += (b[i] * (b[i] + 1)) / 2;
ans -= (a[i] * (a[i] - 1)) / 2;
}
cout << ans << endl;
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
int inf = 1001001001;
ll INF = 1001001001001001001;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define rep(i, n) FOR(i, 0, n)
#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
ll MOD = 1000000007;
using P = pair<ll, ll>;
double eps = 1e-12;
int main() {
int N;cin >> N;
vector<vector<ll> > color(3);
rep(i, 2*N) {
ll a;cin >> a;
char c;cin >> c;
if (c == 'R') color[0].pb(a);
else if (c == 'G') color[1].pb(a);
else if (c == 'B') color[2].pb(a);
}
ll rcnt, gcnt, bcnt;
rcnt = (color[0].size())%2;
gcnt = (color[1].size())%2;
bcnt = (color[2].size())%2;
if (rcnt == 0&&gcnt == 0&&bcnt == 0) {
cout << 0 << endl;
return 0;
}
vector<P> wa, wa2, wa3;
ll koho = INF;
ll koho2 = INF;
ll koho3 = INF;
if (rcnt == 0) {
rep(i, color[1].size()) wa.pb(P(color[1][i], 1));
rep(i, color[2].size()) wa.pb(P(color[2][i], 2));
sort(all(wa));
rep(i, wa.size()-1) {
if (wa[i].second == wa[i+1].second) continue;
else koho = min(koho, wa[i+1].first-wa[i].first);
}
rep(i, color[0].size()) wa2.pb(P(color[0][i], 0));
rep(i, color[1].size()) wa2.pb(P(color[1][i], 1));
sort(all(wa2));
rep(i, wa2.size()-1) {
if (wa2[i].second == wa2[i+1].second) continue;
else koho2 = min(koho2, wa2[i+1].first-wa2[i].first);
}
rep(i, color[0].size()) wa3.pb(P(color[0][i], 0));
rep(i, color[2].size()) wa3.pb(P(color[2][i], 2));
sort(all(wa3));
rep(i, wa3.size()-1) {
if (wa3[i].second == wa3[i+1].second) continue;
else koho3 = min(koho3, wa3[i+1].first-wa3[i].first);
}
ll ans = min(koho, koho2+koho3);
cout << ans << endl;
return 0;
}
else if (gcnt == 0) {
rep(i, color[0].size()) wa.pb(P(color[0][i], 0));
rep(i, color[2].size()) wa.pb(P(color[2][i], 2));
sort(all(wa));
rep(i, wa.size()-1) {
if (wa[i].second == wa[i+1].second) continue;
else koho = min(koho, wa[i+1].first-wa[i].first);
}
rep(i, color[0].size()) wa2.pb(P(color[0][i], 0));
rep(i, color[1].size()) wa2.pb(P(color[1][i], 1));
sort(all(wa2));
rep(i, wa2.size()-1) {
if (wa2[i].second == wa2[i+1].second) continue;
else koho2 = min(koho2, wa2[i+1].first-wa2[i].first);
}
rep(i, color[1].size()) wa3.pb(P(color[1][i], 1));
rep(i, color[2].size()) wa3.pb(P(color[2][i], 2));
sort(all(wa3));
rep(i, wa3.size()-1) {
if (wa3[i].second == wa3[i+1].second) continue;
else koho3 = min(koho3, wa3[i+1].first-wa3[i].first);
}
ll ans = min(koho, koho2+koho3);
cout << ans << endl;
return 0;
}
if (bcnt == 0) {
rep(i, color[0].size()) wa.pb(P(color[0][i], 0));
rep(i, color[1].size()) wa.pb(P(color[1][i], 1));
sort(all(wa));
rep(i, wa.size()-1) {
if (wa[i].second == wa[i+1].second) continue;
else koho = min(koho, wa[i+1].first-wa[i].first);
}
rep(i, color[0].size()) wa2.pb(P(color[0][i], 0));
rep(i, color[2].size()) wa2.pb(P(color[2][i], 2));
sort(all(wa2));
rep(i, wa2.size()-1) {
if (wa2[i].second == wa2[i+1].second) continue;
else koho2 = min(koho2, wa2[i+1].first-wa2[i].first);
}
rep(i, color[1].size()) wa3.pb(P(color[1][i], 1));
rep(i, color[2].size()) wa3.pb(P(color[2][i], 2));
sort(all(wa3));
rep(i, wa3.size()-1) {
if (wa3[i].second == wa3[i+1].second) continue;
else koho3 = min(koho3, wa3[i+1].first-wa3[i].first);
}
ll ans = min(koho, koho2+koho3);
cout << ans << endl;
return 0;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void){
int a[4], sum = 0;
bool flag = false;
for(int i = 0; i < 4; i++) cin >> a[i];
for(int i : a) sum += i;
for(int i = 0; i < (1<<4); i++){
int n = 0, m = sum;
for(int j = 0; j < 4; j++){
if((i>>j)%2==1){
n += a[j];
m -= a[j];
}
}
if(n == m){
flag = true;
break;
}
}
if(flag) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define REPS(i, ss, nn ) for(int i = ss ; i < (int) nn; i++)
#define REV(i, ss, nn ) for(int i = ss ; i >= nn; i--)
#define deb(x) std::cout << #x << " " << x << endl;
#define debl(x) std::cout << #x << " " << x << " ";
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
namespace std{
template<class Fun>
class y_combinator_result{
Fun fun_;
public:
template<class T>
explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)){}
template<class ...Args>
decltype(auto) operator()(Args&&...args){
return fun_(std::ref(*this), std::forward<Args>(args)...);
}
};
template<class Fun>
decltype(auto) y_combinator(Fun && fun){
return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}
};
template<typename T>
bool u_max(T& a, T b){
if( a < b){
a = b;
return true;
}
return false;
}
template<typename T>
bool u_min(T& a, T b){
if( a > b){
a = b;
return true;
}
return false;
}
// struct edge{
// int to, from;
// ll cost;
// edge(){ edge(0,0);}
// edge(int to_, ll cost_){ edge(0, -1, 0);}
// edge(int to_, int from_, ll cost_) : to(to_), from(from_), cost(cost_){}
// };
template<typename... T>
void read(T& ... a){
((cin >> a),...);
}
void solve(){
ll n, m , T;
read(n, m, T);
ll cur = n;
ll last = 0;
REP(i, m){
ll a, b;
read(a, b);
cur -= (a - last);
// debl(i) deb(cur)
if(cur <= 0){
// deb(i)
cout << "No\n";
return;
}else{
cur += (b - a);
// deb(cur)
if( cur >= n) cur = n;
last = b;
}
}
cur -= (T - last);
if( cur <= 0){
cout << "No\n";
}else{
cout << "Yes\n";
}
}
int main()
{
//making data IO Fast
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
/****************************/
solve();
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
bool pTakahashi(int i, int j) {
return (i + j) % 2 == 1;
}
void Main() {
int H, W;
cin >> H >> W;
vector<vector<int>> A(H, vector<int>(W, 0));
for (int i = 0; i < H; ++i) {
string s;
cin >> s;
for (int j = 0; j < W; ++j) {
A[i][j] = s[j] == '+' ? 1 : -1;
}
}
if (H == 1 && W == 1) {
cout << "Draw" << endl;
return;
}
vector<vector<pair<int, int>>> p(H, vector<pair<int, int>>(W, make_pair(0, 0)));
if (pTakahashi(H - 1, W - 1)) {
p[H - 1][W - 1].first = A[H - 1][W - 1];
p[H - 1][W - 1].second = 0;
}
else {
p[H - 1][W - 1].first = 0;
p[H - 1][W - 1].second = A[H - 1][W - 1];
}
for (int i = H - 1; i >= 0; --i) {
for (int j = W - 1; j >= 0; --j) {
if (i == H - 1 && j == W - 1) {
continue;
}
pair<int, int>& T_A = p[i][j];
if (pTakahashi(i, j)) {
if (i > 0 || j > 0) {
T_A.first = A[i][j];
}
if (i == H - 1) {
T_A.second += p[i][j + 1].second;
T_A.first += p[i][j + 1].first;
}
else if (j == W - 1) {
T_A.second += p[i + 1][j].second;
T_A.first += p[i + 1][j].first;
}
else {
if (p[i + 1][j].second - p[i + 1][j].first > p[i][j + 1].second - p[i][j + 1].first) {
T_A.second += p[i + 1][j].second;
T_A.first += p[i + 1][j].first;
}
else {
T_A.second += p[i][j + 1].second;
T_A.first += p[i][j + 1].first;
}
}
}
else {
if (i > 0 || j > 0) {
T_A.second = A[i][j];
}
if (i == H - 1) {
T_A.first += p[i][j + 1].first;
T_A.second += p[i][j + 1].second;
}
else if (j == W - 1) {
T_A.first += p[i + 1][j].first;
T_A.second += p[i + 1][j].second;
}
else {
if (p[i + 1][j].first - p[i + 1][j].second > p[i][j + 1].first - p[i][j + 1].second) {
T_A.first += p[i + 1][j].first;
T_A.second += p[i + 1][j].second;
}
else {
T_A.first += p[i][j + 1].first;
T_A.second += p[i][j + 1].second;
}
}
}
}
}
if (p[0][0].first > p[0][0].second) {
cout << "Takahashi" << endl;
}
else if (p[0][0].first < p[0][0].second) {
cout << "Aoki" << endl;
}
else {
cout << "Draw" << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
std::cout << std::fixed << std::setprecision(15);
Main();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 60);
int main(){
int n, m;
cin >> n >> m;
vector<int> h(n), w(m);
rep(i,n) cin >> h[i];
rep(i,m) cin >> w[i];
sort(h.begin(), h.end());
sort(w.begin(), w.end());
vector<int> v(n); //各生徒に対する先生の最適解
for (int i = 0; i < n; i++) {
int itr = lower_bound(w.begin(), w.end(), h[i]) - w.begin();
if (itr == m) itr--;
v[i] = abs(w[itr] - h[i]);
itr--;
if (itr >= 0) v[i] = min(v[i], abs(w[itr] - h[i]));
}
vector<ll> cum1(n / 2 + 2, 0), cum2(n / 2 + 2, 0);
for (int i = 0; i < n; i += 2) {
int j = i / 2;
cum1[j + 1] = cum1[j] + abs(h[i] - h[i + 1]);
}
for (int i = n - 2; i >= 0; i -= 2) {
int j = (i + 1) / 2;
cum2[j] = cum2[j + 1] + abs(h[i] - h[i + 1]);
}
ll res = INF;
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
int l = i / 2, r = (i + 2) / 2;
res = min(res, cum1[l] + cum2[r] + v[i]);
} else {
int l = i / 2, r = (i + 3) / 2;
res = min(res, cum1[l] + cum2[r] + v[i] + abs(h[i - 1] - h[i + 1]));
}
}
cout << res << endl;
return 0;
} |
#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
template<class T>
bool chmax(T &val, T nv) { return val < nv ? (val = nv, true) : false; }
template<class T>
bool chmin(T &val, T nv) { return nv < val ? (val = nv, true) : false; }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T1, class ...T2>
void kout (T1 v, T2 ...e) { cerr << v << ' ', kout(e...); }
template<class T>
void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
// What I should check
// 1. overflow
// 2. corner cases
// Enjoy the problem instead of hurrying to AC
// Good luck !
const int MAX_N = 300010;
#define int ll
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, c;
cin >> n >> c;
map<int,ll> cnt;
for (int a, b, c, i = 0;i < n;++i) {
cin >> a >> b >> c;
cnt[a] += c;
cnt[b+1] -= c;
}
ll sum = 0;
for (auto &[a, b] : cnt)
b = sum += b;
ll ret = 0;
for (auto [a, b] : cnt) {
if (b == 0) continue;
int nxt = cnt.upper_bound(a)->first;
ret += min(b, c) * (nxt - a);
}
cout << ret << '\n';
}
| #include<bits/stdc++.h> //Written by ThiDaiLoc
using namespace std; //Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> trp;
typedef vector<ll> vi;
typedef vector<pll> vp;
#define fu(i,a,b) for(ll i=a;i<=b;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fs(i,s) for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a) for(ll i=b;i>=a;i--)
#define fuv(i,a) for(ll i=0;i<a.size();i++)
#define fdv(i,a) for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x) memset(a, x, sizeof a)
#define prec(n) fixed<<setprecision(n)
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb(i) push_back(i)
#define pob pop_back()
#define sc(a) cin>>a
#define sc2(a,b) cin>>a>>b
#define sc3(a,b,c) cin>>a>>b>>c
#define pr(a) cout<<a<<endl
#define pr2(a,b) cout<<a<<" "<<b<<endl
#define rpr(a) return cout<<a<<endl,0
#define prY cout<<"YES"<<endl
#define prN cout<<"NO"<<endl
#define bit(n,i) (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x) lower_bound(all(a),x) -a.begin()
#define all(x) (x).begin(), (x).end()
#define sz(a) (ll)a.size()
#define le(s) (ll)s.length()
#define re return
#define mp(a,b) make_pair(a,b)
#define mp3(a,b,c) make_pair(a,make_pair(b,c))
#define se second
#define fi first
#define sse second.second
#define sfi second.first
#define soA sort(A+1,A+1+n)
#define so(A,n) sort(A+1,A+1+n)
#define sov(v) sort(all(v))
#define sovr(v) sort(all(v),greater<ll>())
#define debug(x) cerr << #x << " = " << x << endl
#define INPUT freopen("locin.txt", "r", stdin)
#define OUTPUT freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;
ll A[MAXN+5],B[MAXN+5],C[MAXN+5];
class cmppq{
public: bool operator()(pll a,pll b){
re a.fi>b.fi;
}
};
bool cmp(ll a,ll b){
return A[a]>A[b];
}
ll Solves(){
ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
// PROCESS IN HERE
sc2(n,m);
vi vec;
vi v2;
f1(i,n){
v2.pb(i);
cin>>A[i];
cin>>B[i];
cin>>C[i];
vec.pb(A[i]);
vec.pb(B[i]);
if(A[i]-1>0)vec.pb(A[i]-1);
}
sov(vec); uni(vec);
sort(all(v2),cmp);
priority_queue<pll,vector<pll>,cmppq> pq;
ll last=1;
fuv(i,vec){
x=vec[i];
while(sz(v2) and A[v2.back()]==x){
sum+=C[v2.back()];
pq.push(mp(B[v2.back()],C[v2.back()]));
v2.pob;
}
// debug(x); debug(last); debug(min(sum,m));
ans+=(x-last+1)*min(sum,m);
while(sz(pq) and pq.top().fi==x)sum-=pq.top().se,pq.pop();
last=x+1;
}
pr(ans);
re 0;
// Hack it if you can :)
}
int main(){
//INPUT;
if(fopen("locin.txt", "r"))INPUT;
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll test=1;
// sc(test);
fu(T,1,test){
// cout<<"Case #"<<T<<": ";
Solves();
}
} |
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
ll n,a[N],b[N],l,r,ans=0,bit[N],nxt[N],plc[N],nm[N];
bool vis[N];
vector<pair<ll,ll> > pa,pb,rd;
void upd(ll x,ll v)
{
x++;
while(x<N)
{
bit[x]+=v;
x+=(x&(-x));
}
return;
}
void update(ll x)
{
upd(0,1);
upd(x,-1);
return;
}
ll query(ll x)
{
x++;
ll ret=0;
while(x>0)
{
ret+=bit[x];
x-=(x&(-x));
}
return ret;
}
int main(){
ll i;
scanf("%lld",&n);
for(i=0;i<n;i++)
{
scanf("%lld",&a[i]);
a[i]+=i;
}
for(i=0;i<n;i++)
{
scanf("%lld",&b[i]);
b[i]+=i;
}
for(i=0;i<n;i++)
{
pa.push_back(make_pair(a[i],i));
pb.push_back(make_pair(b[i],i));
}
sort(pa.begin(),pa.end());
sort(pb.begin(),pb.end());
for(i=0;i<pa.size();i++)
{
if(pa[i].F!=pb[i].F)
{
puts("-1");
return 0;
}
nm[pa[i].S]=pa[i].S;
plc[pa[i].S]=pa[i].S;
rd.push_back(make_pair(pb[i].S,pa[i].S));
}
sort(rd.begin(),rd.end());
for(i=0;i<rd.size();i++)
{
ans+=abs((rd[i].S+query(rd[i].S))-rd[i].F);
update(rd[i].S);
}
printf("%lld\n",ans);
return 0;
} | #pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#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
const int bm = 200001;
int BIT[bm];
void add(int A) {
while (A > 0) {
BIT[A]++;
A -= A & -A;
}
}
int query(int A) {
int ret = 0;
while (A <= bm) {
ret += BIT[A];
A += A & -A;
}
return ret;
}
ll A[200001], B[200001], tmp[200001];
void pakuri_sort(int N, ll A[]) {
const int b = 8;
rep(k, 4) {
int kazu[1 << b] = {}, kazu2[1 << b] = {};
rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
k++;
rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
}
}
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;
if ((tmp & ma0) ^ ma0) {
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);
}
else {
tmp = tmp & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
ci += 8;
if ((ct = *ci++) >= '0') {
tmp = tmp * 10 + ct - '0';
if (*ci++ == '0') {
tmp = tmp * 10;
ci++;
}
}
}
return tmp;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N = getint();
rep1(i, N) A[i] = ll(i) << 32 | i + getint();
rep1(i, N) B[i] = ll(i) << 32 | i + getint();
pakuri_sort(N, A + 1);
pakuri_sort(N, B + 1);
rep1(i, N) {
if ((A[i] ^ B[i]) & (1ll << 32) - 1) {
co(-1);
return 0;
}
tmp[A[i] >> 32] = B[i] >> 32;
}
ll kotae = 0;
rep1(i, N) {
kotae += query(tmp[i]);
add(tmp[i]);
}
co(kotae);
Would you please return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
sort(v.begin(), v.end());
bool is_ok = true;
for (int i = 1; i <= n; i++) {
if (i != v[i-1]) {
is_ok = false;
break;
}
}
cout << (is_ok ? "Yes" : "No") << endl;
} | #include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1e9 + 7;
const int64_t MOD2 = 998244353;
const int INF = 2e9;
const long long inf = 1LL<<62;
long long gcd(long long x, long long y) {
if (x==0||y==0) {
return x+y;
}
if (x%y == 0) {
return y;
} else {
return gcd(y, x%y);
}
}
int main() {
int n;
cin >> n;
vector<long long> x(n);
for (int i=0; i<n; i++) {
cin >> x[i];
}
vector<int> ep;
vector<int> pr(51, 1);
pr[0] = pr[1] = 0;
for (int i=2; i<=50; i++) {
if (pr[i]) {
for (int x = i*2; x<=50; x += i) {
pr[x] = 0;
}
}
}
for (int i=0; i<51; i++) {
if (pr[i]) ep.push_back(i);
}
long long res = inf;
for (long long bit = 0; bit<(1<<15); bit++) {
long long ans = 1;
for (int i=0; i<15; i++) {
if ((1<<i) & bit) ans *= ep[i];
}
int flag = 1;
for (int i=0; i<n; i++) {
if (gcd(ans, x[i]) == 1) {
flag = 0;
break;
}
}
if (flag) {
res = min(ans, res);
}
}
cout << res << endl;
}
|
#include<bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for(int i = 0; i < (n); ++i)
//#define DEBUG
#ifdef DEBUG
#define DEBUG_PRINT(fm, ...) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout << "DEBUG PRINT ";std::printf(fm, __VA_ARGS__);}while(0)
#define DEBUG_VAL(a, b) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout <<"DEBUG VAL " << a << ":" << b << endl;}while(0)
#else
#define DEBUG_PRINT(...)do{}while(0);
#define DEBUG_VAL(a, b)do{}while(0);
#endif
using namespace std;
//using namespace atcoder;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;
ll gcd(ll x,ll y){
if(x<y) swap(x,y);
ll r;
while(y>0){
r=x%y;
x=y;
y=r;
}
return x;
}
int main(){
int n;
cin >> n;
vl A(n);
rep(i, n){
cin >> A[i];
}
ll ans = gcd(A[0], A[1]);
for(int i = 2; i < n;i++){
ans = gcd(ans, A[i]);
}
cout << ans << endl;
}
| #include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {return b?gcd(b, a%b):a;}
int main() {
int n; cin >> n;
vector<int> a(n);
for (int i=0;i<n;i++) cin >> a[i];
int ans = a[0];
for (int i=0;i<n;i++) ans = gcd(ans,a[i]);
cout << ans << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define REP(i,j,n) for(int i=(j);i<(n);++i)
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using vll=vector<ll>;
using GrafPair=vector<vector<P>>;
using Graf=vector<vll>;
#define MAX 1000000007
#define DOUBLE fixed << setprecision(15)
int main()
{
ll n;
cin >> n;
ll num=sqrt(n+1);
ll sum=num*(num+1)/2;
num++;
while(sum<=n+1){
sum+=num;
num++;
}
num--;
if(n==2){
cout << 1 << endl;
}else{
cout << n+2-num << endl;
}
} | #include<bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin>>n;
if (0==n%3) {
cout<<"0\n";
return 0;
} else if (n<=2) {
cout<<"-1\n";
return 0;
}
int cnt[3]={};
int sum=0;
int tot=0;
while (n) {
int p=n%10;
n/=10;
sum+=p;
tot++;
cnt[p%3]++;
}
if (1==sum%3) {
if (tot>1 && cnt[1]>=1) {
cout<<"1\n";
} else if (tot>2 && cnt[2]>=2) {
cout<<"2\n";
} else {
cout<<"-1\n";
}
} else if (2==sum%3) {
if (tot>1 && cnt[2]>=1) {
cout<<"1\n";
} else if (tot>2 && cnt[1]>=2) {
cout<<"2\n";
} else {
cout<<"-1\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve() {
int n;
cin >> n;
vector<ll> A(n);
vector<ll> S(n);
for (int i = 0; i < n; i++) {
cin >> A[i];
}
sort(A.begin(), A.end());
S[0] = A[0];
for (int i = 1; i < n; i++) {
S[i] = A[i] + S[i-1];
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ans += (S[n-1] - S[i]) - A[i] * (n - i - 1);
}
cout << ans << endl;
}
int main() {
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define d long double
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define dscf(n) scanf("%Lf",&n)
#define pri(n) printf("%d ",(int)n)
#define lpri(n) printf("%lld ",n)
#define dpri(n) printf("%Lf ",n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define dprin(n) printf("%Lf\n",n)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,ini,n) for(ll i=ini;i<(int)n;i++)
#define all(x) x.begin(),x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define bitcount(n) __builtin_popcount(n)
#define tc int tt; scf(tt); while(tt--)
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265358979323846264
const ll M =1e9+7;
const int N = 1e6+7;
int main()
{
ll n;
lscf(n);
ll a[n+1];
rep(i,1,n+1)
lscf(a[i]);
sort(a+1,a+n+1);
ll sum=a[1];
ll ans=0;
rep(i,2,n+1)
{
ans+=((i-1)*a[i]-sum);
sum+=a[i];
}
lpri(ans);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<ll,ll>;
#define pb push_back
int main(){
vvl tate(29, vl(30,5000));
vvl yoko(30, vl(29,5000));
rep(_,1000){
int a, b, ato, bto;
cin >> a >> b >> ato >> bto;
int ma = a;
int mb = b;
string ans;
while(a != ato || b != bto){
if (a == ato){
if (b < bto){
b++;
ans.pb('R'); continue; // continueの貼り付けを忘れると
} else { // バグる ato btoが連続するからです
b--; // 全てに張り付けておく必要があるので
ans.pb('L'); continue;
}
}
if (b == bto){
if (a < ato){
a++;
ans.pb('D'); continue;
} else {
a--;
ans.pb('U'); continue;
}
}
if (a < ato && b < bto){
// 下 右
if (tate[a][b] < yoko[a][b]){
a++; // 縦移動優先
ans.pb('D'); continue;
} else {
b++;
ans.pb('R'); continue;
}
}
if (a < ato && b > bto){
// 下 左
if (tate[a][b] < yoko[a][b-1]){
a++; // 縦移動優先
ans.pb('D'); continue;
} else {
b--;
ans.pb('L'); continue;
}
}
if (a > ato && b < bto){
// 上 右
if (tate[a-1][b] < yoko[a][b]){
a--; // 縦移動優先
ans.pb('U'); continue;
} else {
b++;
ans.pb('R'); continue;
}
}
if (a > ato && b > bto){
// 上 左 ここから続き
if (tate[a-1][b] < yoko[a][b-1]){
a--; // 縦移動優先
ans.pb('U'); continue;
} else {
b--;
ans.pb('L'); continue;
}
}
}
cout << ans << endl; // flushを炊く
ll score;
cin >> score;
score /= ans.size(); // 通った数で割り一歩当たりのコスト計算
// cout << score << endl; // debug
ll change = (score - 5000) / (ll)ans.size();
// cout << change << endl; // debug
rep(i,ans.size()){
if (ans[i] == 'U'){
tate[ma-1][mb] += change;
if (score < 3500) tate[ma-1][mb] += -100000;
if (score > 6500) tate[ma-1][mb] += 100000;
ma--;
}
if (ans[i] == 'D'){
tate[ma][mb] += change;
if (score < 3500) tate[ma][mb] += -100000;
if (score > 6500) tate[ma][mb] += 100000;
ma++;
}
if (ans[i] == 'L'){
yoko[ma][mb-1] += change;
if (score < 3500) yoko[ma][mb-1] += -100000;
if (score > 6500) yoko[ma][mb-1] += 100000;
mb--;
}
if (ans[i] == 'R'){
yoko[ma][mb] += change;
if (score < 3500) yoko[ma][mb] += -100000;
if (score > 6500) yoko[ma][mb] += 100000;
mb++;
}
}
// for(auto x : tate){ // コスト計算debug
// for(auto y : x){
// cout << y << " ";
// } cout << endl;
// }
// for(auto x : yoko){
// for(auto y : x){
// cout << y << " ";
// } cout << endl;
// }
}
} | #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
#include <random>
#include <ctime>
#include <cassert>
#include <chrono>
#include <fstream>
using namespace std;
using LL = long long;
using LD = long double;
const LD PI = acos(-1);
int main() {
int N;
cin >> N;
LD x, y, X, Y;
cin >> x >> y >> X >> Y;
LD phi = atan2(Y - y, X - x);
LD theta = 2 * PI / N;
LD hen = phi - PI / 2 + theta / 2;
LD radius = sqrt((X - x) * (X - x) + (Y - y) * (Y - y)) / 2;
LD length = 2 * radius * sin(theta / 2);
LD vx = length * cos(hen);
LD vy = length * sin(hen);
LD ax = x + vx;
LD ay = y + vy;
cout.precision(20);
cout << fixed;
cout << ax << " "<< ay << endl;
return 0;
} |
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;
#define ll long long
const ll N = 2e5 + 5;
ll a[N];
ll b[N];
ll t[N];
ll gcd(ll a, ll b)
{
return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
return a / gcd(a, b) * b;
}
signed main()
{
int a, b, w;
cin >> a >> b >> w;
w *= 1000;
if (w % a > b || w%a<=(b-a)*(w/a))
{
printf("%d %d\n", w%b==0?(w / b):(w/b+1), w/a);
}
else
puts("UNSATISFIABLE");
} | #include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<string>
#include<vector>
#include<set>
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;
int main(void){
int a,b,w;
cin >> a >> b >> w;
//最小値
int min,max;
//キログラムをグラムに変換
w = w*1000;
bool flag1=false,flag2=false;
//iは個数
for(int i=1;i<=1000*1000;i++){
if((double)w/(double)i>=(double)a&&(double)w/i<=(double)b){
flag1 = true;
min = i;
break;
}
}
//最大値
for(int i=1000*1000;i>0;i--){
if((double)w/(double)i>=(double)a&&(double)w/(double)i<=(double)b){
flag2 = true;
max = i;
break;
}
}
if(flag1&flag2){
cout << min << " "<< max << endl;
}
else{
cout << "UNSATISFIABLE" << endl;
}
return 0;
} |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
//reverse(s.begin(),s.end())
ll gcd(ll a,ll b){
ll s=1,c;
while(a&&b){
if((~a&1)&&(~b&1))
a>>=1,b>>=1,s<<=1;
else if(~a&1)a>>=1;
else if(~b&1)b>>=1;
else if(a>b)a=a-b;
else c=b-a,b=a,a=c;
}
if(!a)return b*s;
if(!b)return a*s;
}
int main(){
ll n=1;cin>>n;
ll k;ll ans = 6987268688401;
cout<<ans;
}
| /** これを翻訳している間、あなたはあなたの人生のいくつかの貴重な瞬間を無駄にしました **/
#include<bits/stdc++.h>
using namespace std;
#ifdef Zoro
#include "headers/debug.h"
#else
#define debug(x...)
#define deb(x...)
#endif
#define rep(i,x,y) for(int i=x;i<y;i++)
#define repr(i,x,y) for(int i=x;i>=y;i--)
#define int long long
#define pb push_back
#define ff first
#define ss second
#define sz(x) ((int)x.size())
#define all(x) begin(x), end(x)
#define memo(x,y) memset((x),(y),sizeof((x)))
#define line cout<<"[At "<<__LINE__<<"]"<<endl;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<pair<int, int>>;
constexpr int mod = 1e9 + 7, N = 2e5 + 5;
constexpr long long inf = 1e18;
constexpr long double eps = 1e-6;
void Onigiri() {
int a[3];
rep(i,0,3)cin>>a[i];
sort(a,a+3);
if(a[0] == a[1] ) cout<<a[2];
else if(a[1]==a[2]) cout<<a[0];
else cout<<0;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//cout.precision(10);cout<<fixed;
#ifdef Zoro
freopen("/home/pritish/Competitive/io/in", "r", stdin);
freopen("/home/pritish/Competitive/io/out", "w", stdout);
#endif
int t = 1;
//cin >> t;
while(t--) {
Onigiri();
cout << "\n";
}
cerr << "\n" << (float)clock() / CLOCKS_PER_SEC * 1000 << " ms" << endl;
return 0;
} |
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000000000000000;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
signed main(){
string S;
cin >> S;
string T = "";
for( int i = 0; i < S.size(); i++ ){
if( S[i] == '.' ) break;
T += S[i];
}
cout << T << endl;
}
|
// Problem: B - Round Down
// Contest: AtCoder - AtCoder Beginner Contest 196
// URL: https://atcoder.jp/contests/abc196/tasks/abc196_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include<bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const int MOD = 1e9 + 7;
//const int ULTRA = 1e14;
const int PROMAX = 1e6 + 5;
const int PRO = 1e5 + 5;
#define ll long long
#define int ll
#define all(x) x.begin(), x.end()
#define lla(x) x.rbegin(), x.rend()
#define pb push_back
#define ThinkTwice ios_base::sync_with_stdio(false); cin.tie(NULL);
int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = { 0, 1, 0, -1, -1, 1, 1, -1};
char dir[] = {'U','R','D','L'};
inline int powmod(int a, int b, int mod) {int res=1; while(b>0) {if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res;}
inline int power(int a, int b) {int res=1; while(b>0) {if(b&1) res*=a; a*=a; b>>=1;} return res; }
//__________________________________________________________________
void solve() {
string a; cin>>a;
for(auto x: a) {
if(x == '.') return ;
cout<<x;
}
cout<<endl;
}
signed main() {
ThinkTwice
int t;
t = 1;
// cin>>t;
for(int i = 1; i<=t; i++) {
// cout<<"Case #"<<i<<": ";
solve();
}
}
//__________________________________________________________________
/*
Sample Input:
Sample Output:
*/
|
#include<bits/stdc++.h>
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define pii pair<int,int>
#define fi first
#define se second
#define PB push_back
#define ll long long
#define ull unsigned long long
#define pll pair<ll,ll>
#define y1 orzkcz
using namespace std;
int n,bi[500];
int main(){
scanf("%d",&n);
For(i,0,(1<<n)-1) bi[i]=bi[i/2]+(i&1);
printf("%d\n",(1<<n)-1);
For(i,1,(1<<n)-1){
For(j,0,(1<<n)-1) putchar((bi[i&j]&1)?'A':'B');
puts("");
}
} | #include<bits/stdc++.h>
using namespace std;
vector<int>a,b;
int main(){
int n,p,q,ans=0;
scanf("%d",&n);
for(int i=1;i<=n;++i){
char c=getchar();
while(c<'0')c=getchar();
if(c=='0')a.push_back(i);
}
for(int i=1;i<=n;++i){
char c=getchar();
while(c<'0')c=getchar();
if(c=='0')b.push_back(i);
}
if(a.size()==b.size()){
for(int i=0;i<a.size();++i){
if(a[i]!=b[i])++ans;
}
cout<<ans;
}
else cout<<-1;
}
|
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <cassert>
using namespace std;
const int N = 30;
const int Q = 1000;
const int di[4] = {-1, 1, 0, 0};
const int dj[4] = {0, 0, -1, 1};
const int REV[4] = {1, 0, 3, 2};
const string DIR = "UDLR";
struct Edge {
int i, j, k;
};
struct Path {
int cost;
bool used[30][30][2];
vector<Edge> edge;
Path() : cost(0), edge(0) {
memset(used, 0, sizeof(used));
}
void add_edge(const Edge& e) {
assert(not used[e.i][e.j][e.k] and "Invalid Edge");
used[e.i][e.j][e.k] = true;
edge.push_back(e);
}
};
class EstimatedGrid {
private:
int weight[30][30][2];
vector<Path> sample_path;
public:
EstimatedGrid() {
for (int i=0; i<N; ++i) {
for (int j=0; j<N; ++j) {
weight[i][j][0] = 5000;
weight[i][j][1] = 5000;
}
}
}
Edge get_edge(int i, int j, int d) {
if (DIR[d] == 'U') return Edge{i - 1, j, 0};
if (DIR[d] == 'D') return Edge{i, j, 0};
if (DIR[d] == 'L') return Edge{i, j - 1, 1};
if (DIR[d] == 'R') return Edge{i, j, 1};
assert(false and "Invalid Direction");
}
vector<int> estimated_shortest_path(int si, int sj, int ti, int tj) {
struct State {
int i, j, c;
bool operator > (const State& o) const { return c > o.c; }
};
vector<vector<int>> cost(N, vector<int>(N, 1L << 30));
vector<vector<int>> memo(N, vector<int>(N, -1));
priority_queue<State, vector<State>, greater<State>> que;
que.push(State{si, sj, 0});
cost[si][sj] = 0;
while (!que.empty()) {
State sta = que.top(); que.pop();
if (cost[sta.i][sta.j] < sta.c) continue;
if (sta.i == ti and sta.j == tj) break;
for (int d=0; d<4; ++d) {
int ni = sta.i + di[d];
int nj = sta.j + dj[d];
if (ni < 0 or ni >= N) continue;
if (nj < 0 or nj >= N) continue;
Edge e = get_edge(sta.i, sta.j, d);
int nc = sta.c + weight[e.i][e.j][e.k];
if (cost[ni][nj] > nc) {
que.push(State{ni, nj, nc});
cost[ni][nj] = nc;
memo[ni][nj] = d;
}
}
}
vector<int> P;
int i = ti, j = tj;
while (memo[i][j] != -1) {
P.push_back(memo[i][j]);
int d = REV[memo[i][j]];
i += di[d];
j += dj[d];
}
reverse(P.begin(), P.end());
return P;
}
string path_to_string(const vector<int>& P) {
string ret = "";
for (int d : P) ret += DIR[d];
return ret;
}
void add_path(
int si, int sj, int ti, int tj,
const vector<int>& P, int cost
) {
Path path;
path.cost = cost;
int i = si, j = sj;
for (int d : P) {
Edge e = get_edge(i, j, d);
path.add_edge(e);
i += di[d];
j += dj[d];
}
assert(i == ti and j == tj);
sample_path.push_back(path);
}
};
int main() {
EstimatedGrid G;
for (int q=0; q<Q; ++q) {
int si, sj, ti, tj;
cin >> si >> sj >> ti >> tj;
vector<int> P = G.estimated_shortest_path(si, sj, ti, tj);
cout << G.path_to_string(P) << endl;
int cost;
cin >> cost;
G.add_path(si, sj, ti, tj, P, cost);
}
} | // This code wrote by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
#define ALL(x) (x).begin(),(x).end()
#define mem(x,y) memset(x,y,sizeof x)
#define sz(x) (int)(x).size()
#define ln std::puts("")
#define lsp std::putchar(32)
#define pb push_back
#define MP std::make_pair
#ifdef _LOCAL_
#define dbg(x) std::cerr<<__func__<<"\tLine:"<<__LINE__<<' '<<#x<<": "<<x<<"\n"
#define dprintf(x...) std::fprintf(stderr,x)
#else
#define dbg(x) 42
#define dprintf(x...) 42
#endif
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
template <class t> inline void read(t &s){s=0;
reg int f=1;reg char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c))s=(s<<3)+(s<<1)+(c^48),c=getchar();s*=f;return;}
template<class t,class ...A> inline void read(t &x,A &...a){read(x);read(a...);}
template <class t> inline void write(t x){if(x<0)putchar('-'),x=-x;
int buf[21],top=0;while(x)buf[++top]=x%10,x/=10;if(!top)buf[++top]=0;
while(top)putchar(buf[top--]^'0');return;}
inline void setIn(std::string s){freopen(s.c_str(),"r",stdin);return;}
inline void setOut(std::string s){freopen(s.c_str(),"w",stdout);return;}
inline void setIO(std::string s=""){setIn(s+".in");setOut(s+".out");return;}
template <class t>inline bool ckmin(t&x,t y){if(x>y){x=y;return 1;}return 0;}
template <class t>inline bool ckmax(t&x,t y){if(x<y){x=y;return 1;}return 0;}
inline int lowbit(int x){return x&(-x);}
const int MaxN=3050;
const int Mod=1e9+7;
const int Mod_Is_Prime=1;
namespace MINT
{
inline long long exgcd(long long a,long long b,long long &x,long long &y)
{long long c;return (!b)?(x=1,y=0,a):(c=exgcd(b,a%b,y,x),y-=a/b*x,c);}
}
struct mint
{
int x;
mint(){x=0;}
template <class T> mint(T v){x=(v%Mod+Mod)%Mod;}
inline int val() const{return x;}
inline mint operator ++ (){return (++x)>=Mod&&(x-=Mod);}
inline mint operator -- (){return (--x)<0&&(x+=Mod);}
inline mint operator + (const mint &nt) const
{return (x+nt.x)>=Mod?(x+nt.x-Mod):(x+nt.x);}
inline mint operator - (const mint &nt) const
{return x<nt.x?(x+Mod-nt.x):(x-nt.x);}
inline mint operator * (const mint &nt) const{return 1LL*x*nt.x%Mod;}
inline mint& operator += (const mint &nt){return *this=*this+nt;}
inline mint& operator -= (const mint &nt){return *this=*this-nt;}
inline mint& operator *= (const mint &nt){return *this=*this*nt;}
inline mint fpow(long long b) const
{
assert(b>=0);
reg mint a=*this,res=1;
for(;b;b>>=1,a*=a)if(b&1)res*=a;
return res;
}
inline mint inv() const
{
if(Mod_Is_Prime)return fpow(Mod-2);
long long X,Y,G=MINT::exgcd(x,Mod,X,Y);
assert(G==1);
return (X%Mod+Mod)%Mod;
}
inline mint operator / (const mint &nt) const{return nt.inv()*x;}
inline mint operator /= (const mint &nt){return *this=*this/nt;}
inline mint operator == (const mint &nt)const{return x==nt.x;}
inline mint operator != (const mint &nt)const{return x!=nt.x;}
};
int a[MaxN],s[MaxN],n;
mint f[MaxN][MaxN],w[MaxN][MaxN];
signed main(void)
{
read(n);
for(int i=1;i<=n;++i)read(a[i]),s[i]=s[i-1]+a[i];
f[0][0]=1,w[1][0]=1;
for(int i=1;i<=n;++i)
{
for(int j=1;j<=i;++j)f[i][j]+=w[j][s[i]%j];
if(i<n)for(int j=0;j<=i;++j)w[j+1][s[i]%(j+1)]+=f[i][j];
}
reg mint ans=0;
for(int i=1;i<=n;++i)ans+=f[n][i];
write(ans.val()),ln;
return 0;
}
/*
* Check List:
* 1. Input / Output File (OI)
* 2. long long
* 3. Special Test such as n=1
* 4. Array Size
* 5. Memory Limit (OI) int is 4 and longlong is 8
* 6. Mod (a*b%p*c%p not a*b*c%p , (a-b+p)%p not a-b )
* 7. Name ( int k; for(int k...))
* 8. more tests , (T=2 .. more)
* 9. blank \n after a case
*/
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
vector<long long int> A(N),B(N);
vector<vector<long long int>> C(N,vector<long long int>(N));
vector<pair<long long int,int>> S(N);
for(int i=0;i<N;i++){
long long int s = 0;
for(int j=0;j<N;j++){
cin >> C[i][j];
s = C[i][j];
}
S[i] = make_pair(s,i);
}
sort(S.begin(),S.end());
A[S[0].second] = 0;
for(int i=0;i<N;i++) B[i] = C[S[0].second][i];
bool flag = true;
for(int i=0;i<N;i++){
bool ok = true;
A[i] = C[i][0]-B[0];
for(int j=1;j<N;j++) if(C[i][j]-B[j] != A[i]) ok = false;
if(!ok) flag = false;
}
if(flag){
cout << "Yes" << endl;
cout << A[0];
for(int i=1;i<N;i++) cout << " " << A[i];
cout << endl;
cout << B[0];
for(int i=1;i<N;i++) cout << " " << B[i];
cout << endl;
}
else cout << "No" << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr long long INF = 1000000000 + 100;
constexpr long long LINF = 1000000000000000000 + 100;
#define all(x) (x).begin(),(x).end()
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rep(i,n) for(int i=0;i<(n);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; }
template<class T> using V = vector<T>;
int main(){
int N; cin >> N;
vector<vector<int>> C(N, vector<int>(N));
int minId = -1, minNum = INF;
rep(i, N){
rep(j, N){
cin >> C[i][j];
if(j==0){
if(chmin(minNum, C[i][j])){
minId = i;
}
}
}
}
vector<int> sa(N-1);
rep(i, N-1)sa[i] = C[0][i] - C[0][i+1];
for(int i=1; i<N; i++){
rep(j, N-1){
if(C[i][j]-C[i][j+1] != sa[j]){
cout << "No" << ln;
return 0;
}
}
}
cout << "Yes" << ln;
rep(i, N){
cout << C[i][0] - minNum << " ";
}
cout << ln;
rep(i, N){
cout << C[minId][i] << " ";
}
cout << ln;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define maxn 2000007
void solve(){
int n,m;
cin>>n>>m;
vector<int> a(m);
for(int i=0;i<m;i++){
cin>>a[i];
}
sort(a.begin(),a.end());
int l=0;
vector<int> diff;
for(auto x : a){
if(x-l-1){
diff.push_back(x-l-1);
}
l=x;
}
if(n-l){
diff.push_back(n-l);
}
if(diff.empty()){
cout<<0<<endl;
return ;
}
sort(diff.begin(),diff.end());
ll ans=1;
for(int i=1;i<diff.size();i++){
ans+=(diff[i]+diff[0]-1)/diff[0];
}
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
//cin>>t;
for(int i=0;i<t;i++)
solve();
return 0;
}
| #include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#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> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <climits>
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using ld = long double;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using namespace std;
int main(){
int n,m;
cin >> n >> m;
int white = n - m;
int before = 0;
int mn = 1000000000;
vi a(m);
rep(i, m) cin >> a[i];
sort(all(a));
vi length;
rep(i, m){
int num = a[i] - before - 1;
if(num){
mn = min(mn, num);
length.push_back(num);
}
before = a[i];
}
if(n - before){
mn = min(mn, n - before);
length.push_back(n - before);
}
int ans = 0;
for(int num : length){
ans += ceil((double)num / mn);
}
cout << ans << endl;
} |
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)
#define DEB(x) cout << #x << " " << x << endl;
#define DEB_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))
typedef long long int LL;
typedef pair<int, int> PI;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VL;
const LL INF = numeric_limits<LL>::max() / 4;
void solve() {
int n;
cin >> n;
LL lo = -INF, hi = INF, add = 0;
REP(i, n) {
LL a, t;
cin >> a >> t;
if (t == 1) {
lo += a;
if (hi < LONG_MAX)
hi += a;
add += a;
} else if (t == 2) {
CHMAX(lo, a);
CHMAX(hi, a);
} else {
CHMIN(lo, a);
CHMIN(hi, a);
}
}
int q;
cin >> q;
REP(qi, q) {
LL x;
cin >> x;
x += add;
// cout << clamp(x, lo, hi) << endl;
cout << (x < lo ? lo : (x > hi ? hi : x)) << endl;
}
}
int main() {
IOS
// int t;
// cin >> t;
// while (t--) {
solve();
// }
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#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;
void Main() {
ll n,T;
R n;
P a[n];
rep(i,n) cin >> a[i].F >> a[i].S;
ll Mi=-MAXL,Ma=MAXL;
{
rep(i,n) {
if(a[i].S==1) Mi+=a[i].F;
if(a[i].S==2) Mi=max(Mi,a[i].F);
if(a[i].S==3) Mi=min(Mi,a[i].F);
}
rep(i,n) {
if(a[i].S==1) Ma+=a[i].F;
if(a[i].S==2) Ma=max(Ma,a[i].F);
if(a[i].S==3) Ma=min(Ma,a[i].F);
}
}
ll l=-MAXL,r=MAXL;
while(l+1<r) {
ll m=(l+r)/2;
ll x=m;
rep(i,n) {
if(a[i].S==1) x+=a[i].F;
if(a[i].S==2) x=max(x,a[i].F);
if(a[i].S==3) x=min(x,a[i].F);
}
if(x<=Mi) l=m;
else r=m;
}
ll z=l;
R T;
while(T--) {
ll x;
R x;
if(x<z) pr(Mi);
else pr(min(Ma,x-z+Mi));
}
}
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
|
#include "bits/stdc++.h"
using namespace std;
int main(){
int n;
cin >> n;
vector<long long> pos, neg;
for(int i = 0; i < n; i++){
int a;
cin >> a;
if(a > 0) pos.push_back(a);
else neg.push_back(a);
}
sort(pos.begin(), pos.end());
sort(neg.begin(), neg.end());
long long npos = pos.size();
long long nneg = neg.size();
vector<long long> sum_pos, sum_neg;
sum_pos.push_back(0);
sum_neg.push_back(0);
for(int i = 0; i < npos; i++){
sum_pos.push_back(pos[i] + sum_pos[i]);
}
for(int i = 0; i < nneg; i++){
sum_neg.push_back(neg[i] + sum_neg[i]);
}
long long sum = 0;
for(int i = 0; i < npos; i++){
sum += sum_pos[npos] - sum_pos[i] - (npos - i) * pos[i];
}
for(int i = 0; i < nneg; i++){
sum += sum_neg[nneg] - sum_neg[i] - (nneg - i) * neg[i];
sum += sum_pos[npos] - neg[i] * npos;
}
cout << sum << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
N = 1 << N;
int pos[2] = {}, val[2] = {};
for (int i = 0; i < N; i++) {
int A;
cin >> A;
int id = i / (N / 2);
if (A > val[id]) {
val[id] = A;
pos[id] = i;
}
}
cout << (val[0] < val[1] ? pos[0] : pos[1]) + 1;
return 0;
} |
// Problem : B - Palindrome with leading zeros
// Contest : AtCoder - AtCoder Beginner Contest 198
// URL : https://atcoder.jp/contests/abc198/tasks/abc198_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#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 w(x) int x; cin>>x; while(x--)
using namespace std;
const long long N=200005, INF=2000000000000000000;
/*------------- Modular exponentiation -------------*/
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;
}
/*------------- Sieve --------------*/
vector <int> prime;
bool is_composite[N];
void sieve (int n) {
fill (is_composite, false);
for (int i = 2; i < n; ++i) {
if (!is_composite[i]) prime.push_back (i);
for (int j = 0; j < prime.size () && i * prime[j] < n; ++j) {
is_composite[i * prime[j]] = true;
if (i % prime[j] == 0) break;
}
}
}
/*------------ Utitlity function ---------------*/
void print(bool n){
if(n){
cout<<"Yes";
}else{
cout<<"No";
}
}
int32_t main()
{
IOS;
int n;
cin>>n;
if(n==0){
print(1);
return 0;
}
while(n%10==0) n/=10;
string s = to_string(n);
bool ok=1;
for(int i=0;i<s.size();i++){
int j = s.size()-1-i;
if(s[i]!=s[j]){
ok=0;
break;
}
}
print(ok);
}
// Written by abhidot | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
main()
{
int n,i;
cin>>n;
int d=n/100;d++;
cout<<100*d-n<<endl;
}
|
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
int main() {
int a, b;
cin >> a >> b;
vector<ll> ans1, ans2;
ll q = 0;
for (int i = 1; i <= a; ++i) {
ans1.emplace_back(i);
q += i;
}
for (int i = 1; i <= b; ++i) {
ans2.emplace_back(-i);
q -= i;
}
if(q < 0){
ans1.back() -= q;
}else {
ans2.back() -= q;
}
for (auto &&i : ans2) {
ans1.emplace_back(i);
}
for (int i = 0; i < ans1.size(); ++i) {
if(i) printf(" ");
printf("%lld", ans1[i]);
}
puts("");
return 0;
} | #line 2 "/home/defineprogram/Desktop/Library/template/template.cpp"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define REV(i, n) for (int i = n - 1; i > 0; i--)
#define all(v) v.begin(), v.end()
#define PL pair<ll, ll>
#define PI pair<int,int>
#define len(s) (int)s.size()
template <class T, class U>
inline bool chmin(T &a, U b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T, class U>
inline bool chmax(T &a, U b) {
if (a < b) {
a = b;
return true;
}
return false;
}
constexpr ll inf = 3e18;
#line 2 "main.cpp"
ll N, K;
ll dp[5][1 << 22];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N >> K;
dp[0][0] = 1;
dp[0][1] = -1;
rep(i, 4) {
rep(j, 3000000) {
dp[i][j + 1] += dp[i][j];
if (!dp[i][j]) continue;
dp[i + 1][j + 1] += dp[i][j];
if (j + N + 1 <= 3000000) dp[i + 1][j + N + 1] -= dp[i][j];
}
}
ll sum = 0;
rep(i, 1 << 22) {
if (sum + dp[3][i] >= K) {
for (ll j = 1; j <= i - 2; j++) {
ll l = max(i - (j + N), 1ll), r = min(i - (j + 1), N);
int cnt = max(r - l + 1, 0ll);
if (sum + cnt >= K) {
cout << j << " " << l + (K - sum - 1) << " "
<< i - j - (l + (K - sum - 1)) << "\n";
return 0;
}
sum += cnt;
}
}
sum += dp[3][i];
}
}
|
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define test(t) ll int t; cin>>t; while(t--)
#define F(i,L,R) for(ll int i=L;i<R;i++)
#define F2(i,L,R) for(ll int i=L;i>=R;i--)
#define get1(a) ll int a; cin>>a;
#define get2(a,b) ll int a,b; cin>>a>>b;
#define get3(a,b,c) ll int a,b,c; cin>>a>>b>>c;
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
int main()
{
ios_base::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
get1(n);
vector<ll int> v(n,-1);
F(i,0,n)
{
cin>>v[i];
}
ordered_set<ll int> ms;
vector<ll int> inversions(n,0);
ll int total=0;
F(i,0,n)
{
total+=( ms.size() - ms.order_of_key(v[i]) );
ms.insert(v[i]);
}
F(i,0,n)
{
cout<<total<<"\n";
total += (n - 1 - 2*v[i]);
}
return 0;
} | // Atcoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
#include <sstream>
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
//#define LINF (1e18)
#define MOD (1e9+7)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define all(x) (x).begin(),(x).end()
//#define int long long
const int INF = 1e9;
const ll LINF = 1e18;
typedef pair < ll, ll> P;
//元がintの分けたものを返す p[0]は1桁目
vector<int> divnum(ll num) {
int dig;
vector<int>p;
while (num) {
dig = num % 10;
p.push_back(dig);
num /= 10;
}
return p;
}
//桁数を返す
int digiter(ll num) {
int dig;
vector<int>p;
while (num) {
dig = num % 10;
p.push_back(dig);
num /= 10;
}
return p.size();
}
//元がstringの分けたものを返す d[0]は一桁目
vector<int> convertstring(string s) {
vector<int> d;
ll n = s.size();
reverse(s.begin(), s.end());
rep(i, n) {
d.push_back(s[i] - '0');
}
return d;
}
/*long double は%Lf*/
//queue古い順,stack新しい
//bool operator<(const Info &another) const {return x > another.x;}//struct(構造体)内の比較演算子のオバーロード
/****Union-Find-Tree***/
int par[int(0x7ffffff)];//Parent
int Rank[int(0x7ffffff)];//Deep_of_the_Tree
//n要素で初期化
void init(int n) {
for (int i = 0; i < n; i++) {
par[i] = i;
Rank[i] = 0;
}
}
//木の根探し
int find(int x) {
if (par[x] == x) {
return x;
}
else {
return par[x] = find(par[x]);
}
}
//xとyの属する集合を併合
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)return;
if (Rank[x] < Rank[y]) {
par[x] = y;
}
else {
par[y] = x;
if (Rank[x] == Rank[y])Rank[x]++;
}
}
bool same(int x, int y) {
return find(x) == find(y);
}
int N; int A[200005];set<int>s[200005];
int32_t main() {
cin >> N;
init(200005);
rep(i, N)cin >> A[i];
rep(i, N / 2) {
unite(A[i], A[N - 1 - i]);
}
rep(i, N) {
s[find(A[i])].insert(A[i]);
}
int ans = 0;
rep(i, 200001) {
int res =s[i].size();
if (res == 0)continue;
ans += res - 1;
}
cout << ans << endl;
}
|
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;
// cout << fixed << setprecision(桁数);
int main(){
int X, Y, Z;
cin >> X >> Y >> Z;
cout << (Z * Y - 1) / X << endl;
} | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define REP(i,k,n) for(ll i=k;i<ll(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define UNIQUE(a) sort(all(a));a.erase(unique(all(a)),a.end())
#define decimal cout<<fixed<<setprecision(10)
using ll=long long;
using P=pair<ll,ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
constexpr ll inf=1001001001001001;
constexpr int INF=1001001001;
constexpr int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
void YesNo(bool b){if(b)out("Yes");else out("No");}
void yesno(bool b){if(b)out("yes");else out("no");}
void YESNO(bool b){if(b)out("YES");else out("NO");}
ll modpow(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;}
vi calc(ll x){vi v;while(x>0){v.eb(x%10);x/=10;}reverse(all(v));return v;}
int main(){
ll t,n;
cin>>t>>n;
vi unused;
ll mae=0;
REP(i,1,101){
REP(j,mae+1,(100+t)*i/100) unused.eb(j);
mae=(100+t)*i/100;
}
//outv(unused);
ll sz=unused.size();
n--;
out(unused[n%sz]+(100+t)*(n/sz));
}
|
#include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
//#include <atcoder/modint>
//using namespace atcoder;
//using mint = modint998244353;
//using mint = modint1000000007;
#pragma endregion
#pragma region macros
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define overload4(_1,_2,_3,_4,name,...) name
#define overload3(_1,_2,_3,name,...) name
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i=n;i--;)
#define rrep2(i,n) for(ll i=n;i--;)
#define rrep3(i,a,b) for(ll i=b;i-->(a);)
#define rrep(...) overload3(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var) do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cerr << endl;int cnt = 0;for(const auto& v : vv){cerr << cnt << "th : "; view(v); cnt++;} cerr << endl;}
#pragma endregion
#pragma region int128
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
if (s) {
__uint128_t tmp = value < 0 ? -value : value;
char buffer[128];
char *d = std::end(buffer);
do {
--d;
*d = "0123456789"[tmp % 10];
tmp /= 10;
} while (tmp != 0);
if (value < 0) {
--d;
*d = '-';
}
int len = std::end(buffer) - d;
if (dest.rdbuf()->sputn(d, len) != len) {
dest.setstate(std::ios_base::badbit);
}
}
return dest;
}
#pragma endregion
const ll mod = 1000000007;
const int inf = 1001001001;
const ll INF = 1001001001001001001ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
template<class T, class K>bool chmax(T &a, const K b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class K>bool chmin(T &a, const K b) { if (b<a) { a=b; return 1; } return 0; }
ll rudiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // 20 / 3 == 7
ll rddiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // -20 / 3 == -7
ll power(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a;} a = a * a; p >>= 1;} return ret;}
ll modpow(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;}
/*---------------------------------------------------------------------------------------------------------------------------------*/
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
//cout << fixed << setprecision(20);
int n; cin >> n;
V<int> dp(n + 1);
dp[1] = 1;
for(int i = 1; i <= n; i++){
for(int j = 2*i; j <= n; j += i){
dp[j] = max(dp[j], dp[i] + 1);
}
}
rep(i,1,n+1) cout << dp[i] << " ";
}
/*
* review you code when you get WA (typo? index?)
* int overflow, array bounds
* special cases (n=1?)
*/ | //ye moh moh ke dhaage,tere ungliyon se ja uljhe
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
void gcd(ll a,ll b,ll &x,ll &y){
if(b==0){
x=1;
y=0;
}
else{
gcd(b,a%b,x,y);
ll te=y;
y=x-(a/b)*y;
x=te;
}
}
int main(){
ll t;
cin>>t;
while(t--){
ll n,s,k;
cin>>n>>s>>k;
ll q=n-s;
ll g=__gcd(k,n);
if(g!=1){
if(q%g!=0){
cout<<"-1"<<endl;
continue;
}
q/=g;
n/=g;
k/=g;
}
ll x,y;
gcd(k,n,x,y);
x=(x+n)%n;
cout<<(x*q)%n<<endl;
}
} |
#include <bits/stdc++.h>
#include <unordered_set>
#include <algorithm>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repll(i,n) for (ll i = 0; i < (ll)(n); i++)
#define fore(x,a) for(auto&(x) : (a))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(a) (a).begin(), (a).end()
const ll INFL = 1e18;
const int INFI = 1e9;
const int MOD = 1e9 + 7;
int main(){
ll N;
cin >> N;
vector<pll> x(N),y(N);
repll(i,N) {
ll X,Y;
cin >> X >> Y;
x[i] = make_pair(X,i);
y[i] = make_pair(Y,i);
}
sort(ALL(x));
sort(ALL(y));
ll a,ax,ay,b;
a = abs(x[N-1].first-x[0].first);
ax = x[0].second;
ay = x[N-1].second;
if(abs(x[N-2].first-x[0].first)>abs(x[N-1].first-x[1].first)) {
b = abs(x[N-2].first-x[0].first);
}
else {
b = abs(x[N-1].first-x[1].first);
}
ll c,cx,cy,d;
c = abs(y[N-1].first-y[0].first);
cx = y[0].second;
cy = y[N-1].second;
if(abs(y[N-2].first-y[0].first)>abs(y[N-1].first-y[1].first)) {
d = abs(y[N-2].first-y[0].first);
}
else {
d = abs(y[N-1].first-y[1].first);
}
if(b > c) cout << b << endl;
else if(d > a) cout << d << endl;
else if(ax == cx && ay == cy) {
cout << max(b,d) << endl;
}
else if(ax == cy && ay == cx) {
cout << max(b,d) << endl;
}
else {
cout << min(a,c) << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mpi map<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define pl pair<ll,ll>
#define pi pair<int,int>
#define forn(i,n) for(ll i=0;i<n;i++)
#define ff first
#define ss second
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inf 1000000000000
#define MOD 1000000007
ll binpow(ll a,ll b,ll m){
a%=m;
ll res=1;
while(b>0){
if(b&1)
res=res*a%m;
a=a*a%m;
b>>=1;
}
return res;
}
void solve(){
ll a,b;
cin>>a>>b;
for(ll i=b;i>=1;i--){
ll k=b/i;
if(k>=2){
ll x=k-1;
if(x*i>=a){
cout<<i;
return;
}
}
}
}
int main(){
ll t=1;
// cin>>t;
while(t--){
solve();
cout<<endl;
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
cout<<x;
if(suc==1) cout<<'\n';
else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
for(int i=0;i<v.size();i++)
print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=1e4+7;
const int mod=998244353;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
vi a(n);
for(int i=0;i<n;i++) cin>>a[i];
vc<vi> dp(n+1,vi(maxn));
int sum=0;
dp[0][0]=1;
for(int i=1;i<=n;i++)
{
sum+=a[i-1];
for(int j=n-1;j>=0;j--)
{
for(int k=a[i-1];k<maxn;k++)
dp[j+1][k]=(dp[j+1][k]+dp[j][k-a[i-1]])%mod;
}
}
if(sum%2!=0) print(0);
else{
ll ans=0;
for(int i=0;i<=n;i++)
{
ll cur=dp[i][sum/2];
//dbg(i,cur);
for(int j=1;j<=i;j++) cur=cur*j%mod;
for(int j=1;j<=n-i;j++) cur=cur*j%mod;
ans=(ans+cur)%mod;
}
print(ans);
}
} | #include<bits/stdc++.h>
using namespace std;
int n , a[110] , noww , las;
long long dp[2][22000][220] , ans , fac[200];
const int mod = 998244353;
int main()
{
scanf("%d" , &n); fac[0] = 1;
for(int i = 1 ; i <= n ; i++ ) scanf("%d" , &a[i]) , fac[i] = fac[i - 1] * i % mod;
dp[0][10000][100] = 1;
for(int i = 1 ; i <= n ; i++ )
{
las = noww; noww ^= 1; memset(dp[noww] , 0 , sizeof(dp[noww]));
for(int s = 0 ; s <= 20000 ; s++ )
{
for(int x = 0 ; x <= 200 ; x++ )
{
if(s + a[i] <= 20000 && x + 1 <= 200)
(dp[noww][s + a[i]][x + 1] += dp[las][s][x]) %= mod;
if(s - a[i] >= 0 && x - 1 >= 0)
(dp[noww][s - a[i]][x - 1] += dp[las][s][x]) %= mod;
}
}
}
for(int i = 0 ; i <= 200 ; i++ )
{
int a = (n + 100 - i) / 2 , b = (n - 100 + i) / 2;
(ans += fac[a] * fac[b] % mod * dp[noww][10000][i] % mod) %= mod;
}
cout << ans;
return 0;
}
/*
100
2 8 4 7 5 3 1 2 4 1 2 5 4 3 3 8 1 7 8 2
2 8 4 7 5 3 1 2 4 1 2 5 4 3 3 8 1 7 8 2
2 8 4 7 5 3 1 2 4 1 2 5 4 3 3 8 1 7 8 2
2 8 4 7 5 3 1 2 4 1 2 5 4 3 3 8 1 7 8 2
2 8 4 7 5 3 1 2 4 1 2 5 4 3 3 8 1 7 8 2
*/ |
#include <iostream>
using namespace std;
int main(void)
{
int a, b, c, d;
cin >> a >> b >> c >> d;
int difference = b - c;
cout << difference << endl;
} | /** Seek God..Trust God..Praise God..**/
#include<bits/stdc++.h>
using namespace std;
#define fRead(x) freopen("x.txt","r",stdin)
#define fWrite(x) freopen ("x.txt","w",stdout)
#define mt make_tuple
#define ld long double
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define INF 2e16
#define PI acos(-1.0)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<LL,LL>
#define endl "\n";
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define SQR(a) ((a)*(a))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,b) for(int i=0;i<b;i++)
#define MEM(a,x) memset(a,x,sizeof(a))
#define ABS(x) ((x)<0?-(x):(x))
#define SORT(v) sort(v.begin(),v.end())
#define REV(v) reverse(v.begin(),v.end())
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define Yes cout << "YES" << endl;
#define No cout << "NO" << endl;
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(nullptr);
///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
return a.second>b.second;
/*
2 89
1 20
9 11
5 10
5 9
4 7
4 6
*/
}
///..................Sort by second element in a pair in increasing order............. ///
bool SortbySecInc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
return a.second<b.second;
/*
4 6
4 7
5 9
5 10
9 11
1 20
2 89
*/
}
///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
const pair<int,int> &b)
{
return (a.first > b.first);
/*
9 11
5 10
5 9
4 6
4 7
2 89
1 20
*/
}
///..................................Binary Search in Pair(Pair er 1st element er upor binary search korbe)..................//////
struct compare
{
bool operator()(const pair<int,int> & value, const int &key)
{
return (value.first<key);
}
bool operator()(const int &key, const pair<int,int> &value)
{
return (key<value.first);
}
};
///.............................................................TEMPLATE................................................./////
/// Convert String to Int ////
int String_to_int(string s)
{
stringstream geek(s);
int ans = 0;
geek >> ans;
return ans;
}
/// string to int ///
int S_I(string s)
{
return stoi(s);
}
/*
/// int to string ///
string I_S(int n)
{
return atoi(n);
}
*/
/*
long long Prime[3000000],nPrime;
long long mark[10000002];
void seive(long long int n)
{
long long int i,j,limit=sqrt(n*1.0)+2;
mark[1]=1;
for(i=4; i<=n ;i+=2)
mark[i]=1;
Prime[nPrime++]=2;
for(i=3; i<=n; i+=2)
{
if(!mark[i])
{
Prime[nPrime++]=i;
if(i<=limit)
{
for(j=i*i; j<=n ;j+=i*2)
{
mark[j]=1;
}
}
}
}
}
*/
///std::cin.ingore() used for line of a string///
int main()
{
FASTIO;
ll a , b , c , d;
cin >> a >> b >> c >> d;
cout << max(a,b)-min(c,d) << endl;
return 0;
}
|
/**
* author: tomo0608
* created: 06.02.2021 20:59:55
**/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define all(x) x.begin(),x.end()
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
template<class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T> >;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> ostream& operator << (ostream& os, set<T>& set_var) {os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {os << *itr;++itr;if(itr != set_var.end()) os << ", ";itr--;}os << "}";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) {os << "{";for(auto itr = map_var.begin(); itr != map_var.end(); itr++) {os << *itr;itr++;if (itr != map_var.end()) os << ", ";itr--;}os << "}";return os;}
template<class T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
#define pb push_back
#define eb emplace_back
#define elif else if
#define mp make_pair
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template<typename T> T gcd(T x, T y){if(x%y == 0)return y;return gcd(y, x%y);}
template<typename T> T gcd(vector<T> a){T res = a[0];for(auto &x: a)res = gcd(res, x);return res;}
template <typename T>T mypow(T x, ll n){T ret = 1;while(n > 0){if(n & 1)(ret *= x);(x *= x);n >>= 1;}return ret;}
#define endl '\n'
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
// Primality test
class Prime {
public:
const int N;
vector<int> min_prime;
vector<int> primes;
Prime(int size): N(size), min_prime(N+1){
rep(i,N+1)min_prime[i] = i;
min_prime[0] = -1;
min_prime[1] = -1;
for(int i = 2;i<=N;i++){
if(min_prime[i]!=i)continue;
primes.push_back(i);
int tmp = 2*i;
while(tmp <= N){
if(min_prime[tmp]==tmp)min_prime[tmp] = i;
tmp += i;
}
}
}
bool check(int x){ return min_prime[x] == x;}
};
void solve(){
int h,w;cin >> h >> w;
V<string> S(h);cin >> S;
VV<int> T(h, V<int>(w,0));
rep(i,h)rep(j,w)if(S[i][j] == '#')T[i][j]++;
ll ans = 0;
rep2(i,1,h)rep2(j,1,w){
if((T[i][j] + T[i-1][j] + T[i][j-1] + T[i-1][j-1])%2){
ans++;
//cout << i << ' ' << j << endl;
}
}
cout << ans << endl;
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << setprecision(20);
int codeforces = 1;
//cin >> codeforces;
while(codeforces--){
solve();
}
return 0;
} | #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
using ll = long long;
//using mint = modint;
const vector<int> dx = {1, 1, 1, 0, 0, 0, -1, -1, -1};
const vector<int> dy = {1, 0, -1, 1, -1, 0, 1, 0, -1};
const double PI = 3.141592653589793;
const ll inf = 1001001001;
const ll e9 = 1000000000;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int MAX = 1000000;
const ll MOD = 998244353;
const ll big = 1ll<<60;
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
int main(){
int k;
ll n, m;
cin >> k >> n >> m;
vector<ll>a(k), b(k);
rep(i, 0, k)cin >> a[i];
ll ng = -1, ok = big, mid;
while(ok-ng > 1){
mid = (ok+ng)/2;
ll left = 0, right = 0;
rep(i, 0, k){
left += (m*a[i]-mid+(n-1))/n;
right += (m*a[i]+mid)/n;
}
if(left<=m && m<=right){
ok = mid;
}else{
ng = mid;
}
}
mid = ok;
ll sum = 0, rest;
rep(i, 0, k){
b[i] = (m*a[i]-mid+(n-1))/n;
sum += b[i];
}
rest = m-sum;
rep(i, 0, k){
ll temp = (m*a[i]+mid)/n;
if(temp-b[i]<rest){
rest -= (temp-b[i]);
b[i] = temp;
}else{
b[i] += rest;
rest = 0;
}
cout << b[i] << " ";
}
cout << endl;
return 0;
} |
/*
Author: Ritik Patel
*/
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& LIBRARIES &&&&&&&&&&&&&&&&&&&&&&&&&&&
#include <bits/stdc++.h>
using namespace std;
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEFINES &&&&&&&&&&&&&&&&&&&&&&&&&&&
#define int long long int
// #define ll long long int
#define all(i) i.begin(), i.end()
#define sz(a) (int)a.size()
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CODE &&&&&&&&&&&&&&&&&&&&&&&&&&&
const int MAXN = 55;
vector<int> rows[MAXN], col[MAXN];
int g[MAXN][MAXN];
int N, K;
void checkr(int r1, int r2) {
bool poss = true;
for(int c = 1; c <= N; ++c) {
poss &= g[r1][c] + g[r2][c] <= K;
}
if(poss) {
rows[r1].push_back(r2);
rows[r2].push_back(r1);
}
}
void checkc(int c1, int c2) {
bool poss = true;
for(int r = 1; r <= N; ++r) {
poss &= g[r][c1] + g[r][c2] <= K;
}
if(poss) {
col[c1].push_back(c2);
col[c2].push_back(c1);
}
}
bool rvis[MAXN], cvis[MAXN];
int len = 0;
void dfs(int v) {
rvis[v] = 1;
++len;
for(auto &to: rows[v]) {
if(!rvis[to])
dfs(to);
}
}
void dfs0(int v) {
cvis[v] = 1;
++len;
for(auto &to: col[v]) {
if(!cvis[to])
dfs0(to);
}
}
const int MOD = 998244353;
void solve() {
cin >> N >> K;
for(int r = 1; r <= N; ++r)
for(int c = 1; c <= N; ++c)
cin >> g[r][c];
for(int r = 1; r <= N; ++r)
for(int rr = r + 1; rr <= N; ++rr)
checkr(r, rr);
for(int r = 1; r <= N; ++r)
for(int rr = r + 1; rr <= N; ++rr)
checkc(r, rr);
int fact[MAXN];
fact[0] = 1;
for(int i = 1; i < MAXN; ++i) fact[i] = fact[i - 1] * i % MOD;
int ans = 1;
for(int r = 1; r <= N; ++r) {
if(!rvis[r]) {
len = 0;
dfs(r);
ans *= fact[len]; ans %= MOD;
}
if(!cvis[r]) {
len = 0;
dfs0(r);
ans *= fact[len]; ans %= MOD;
}
}
cout << ans << '\n';
}
int32_t main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int T = 1;
// cin >> T;
for(int i = 1; i <= T; ++i){
// cout << "Case #" << i << ": ";
solve();
}
return 0;
}
/*
Sample inp
*/ | #include<bits/stdc++.h>
#define N 60
#define A(i,m,n) for(int i=m;i<=n;++i)
using namespace std;
typedef long long LL;
const LL mod=998244353;
int a[N][N],n,k;
inline bool check1(int x,int y){
A(i,1,n)if(a[x][i]+a[y][i]>k)return 0;
return 1;
}
inline bool check2(int x,int y){
A(i,1,n)if(a[i][x]+a[i][y]>k)return 0;
return 1;
}
LL fc[N];
int fa[N],siz[N];
int findfa(int x){
if(fa[x]!=x)fa[x]=findfa(fa[x]);
return fa[x];
}
inline void mer(int x,int y){
int tx=findfa(x),ty=findfa(y);
if(tx!=ty){
fa[tx]=ty;
siz[ty]+=siz[tx];
}
}
int main(){
cin>>n>>k;
fc[1]=1;
A(i,2,n)fc[i]=(fc[i-1]*i)%mod;
A(i,1,n){
A(j,1,n)cin>>a[i][j];
fa[i]=i;
siz[i]=1;
}
A(i,1,n)
A(j,i+1,n)
if(findfa(i)!=findfa(j)&&check1(i,j)==1)mer(i,j);
LL ans=1;
A(i,1,n)
if(findfa(i)==i)ans=ans*fc[siz[i]]%mod;
A(i,1,n)fa[i]=i,siz[i]=1;
A(i,1,n)
A(j,i+1,n)
if(findfa(i)!=findfa(j)&&check2(i,j)==1)mer(i,j);
A(i,1,n)
if(findfa(i)==i)ans=ans*fc[siz[i]]%mod;
printf("%lld\n",ans);
return 0;
} |
#include "bits/stdc++.h"
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int N;
vector<int> C;
vector<vector<int>> T;
void input(){
cin >> N;
C.resize(N);
REP(i,N) cin >> C[i];
T.resize(N);
REP(i,N-1){
int A,B;
cin >> A >> B;
A--; B--;
T[A].push_back(B);
T[B].push_back(A);
}
}
void DFS(int s,vector<bool> &flag,vector<int> &memo,priority_queue<int,vector<int>,greater<int>> &res){
flag[s] = true;
if(memo[C[s]] == 0) res.push(s);
memo[C[s]]++;
for(auto v : T[s]){
if(!flag[v]) DFS(v,flag,memo,res);
}
memo[C[s]]--;
}
int main(){
input();
vector<bool> flag(N,false);
vector<int> memo(100010,0);
priority_queue<int,vector<int>,greater<int>> res;
DFS(0,flag,memo,res);
while(!res.empty()){
cout << res.top()+1 << endl;
res.pop();
}
return 0;
} | /*
author: Yash Gupta
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
#define mem(x, y) memset(x, y, sizeof(x))
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
const int N = 2e5 + 5;
const int inf = 9e18 + 9;
const int mod = 1e9 + 7;
struct node
{
int x, y;
};
int n, m;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
vector<vector<node>> v(26, vector<node>{});
bool vis[2005][2005];
int dist[2005][2005];
vector<bool> used(26, false);
char a[2005][2005];
bool check(node p)
{
if (vis[p.x][p.y])
return false;
if (a[p.x][p.y] == '#')
return false;
if (p.x < 0 || p.y < 0)
return false;
if (p.x >= n || p.y >= m)
return false;
return true;
}
void solve()
{
mem(vis, false);
mem(dist, 0);
cin >> n >> m;
node start, end;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cin >> a[i][j];
if (a[i][j] == 'S')
{
start = {i, j};
}
else if (a[i][j] == 'G')
{
end = {i, j};
}
else if (a[i][j] == '#')
{
vis[i][j] = true;
}
else if (a[i][j] == '.')
{
continue;
}
else
{
v[a[i][j] - 'a'].pb({i, j});
}
}
}
queue<node> q;
q.push(start);
vis[start.x][start.y] = true;
dist[start.x][start.y] = 0;
bool f = false;
while (!q.empty())
{
node curr = q.front();
q.pop();
if (end.x == curr.x && end.y == curr.y)
{
f = true;
break;
}
else
{
for (int i = 0; i < 4; i++)
{
if (check({curr.x + dx[i], curr.y + dy[i]}))
{
q.push({curr.x + dx[i], curr.y + dy[i]});
vis[curr.x + dx[i]][curr.y + dy[i]] = true;
dist[curr.x + dx[i]][curr.y + dy[i]] = 1 + dist[curr.x][curr.y];
}
}
if (a[curr.x][curr.y] != 'S' && a[curr.x][curr.y] != '.' && !used[a[curr.x][curr.y] - 'a'])
{
used[a[curr.x][curr.y] - 'a'] = true;
for (auto p : v[a[curr.x][curr.y] - 'a'])
{
if (!vis[p.x][p.y])
{
q.push(p);
vis[p.x][p.y] = true;
dist[p.x][p.y] = 1 + dist[curr.x][curr.y];
}
}
}
}
}
if (f)
{
cout << dist[end.x][end.y] << endl;
}
else
{
cout << "-1" << endl;
}
}
int32_t main()
{
IOS;
int t = 1;
// cin>>t;
for (int i = 1; i <= t; i++)
{
solve();
}
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
double X, Y, Z;
cin >> X >> Y >> Z;
int ans = 0;
bool flag = true;
while (flag) {
if (Y / X <= ans / Z) {
flag = false;
} else {
ans++;
}
}
cout << ans - 1 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define ll long long int
#define pb push_back
#define MAX 100007
#define End return 0;
#define pi acos(-1)
#define no cout<<"NO"<<endl
#define yes cout<<"YES"<<endl
int const N=1e7+3;
ll MOD=1e9+7,fact[N];
const long long inf=(long long)1e18;
const long double PI=3.14159265358979;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
fast
ll n,m,j,i,k,tc=1,p,r;
ll x,y,z;
//cin>>tc;
while(tc--)
{
vector<ll>v,v1;
map<ll,ll>mp;
map<ll,ll>mp2;
cin>>x>>y>>z;
cout<<(y*z-1)/x<<endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<(n);i++)
#define rep2(i,n,m) for(ll i=n;i<(m);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
void YES(int a){
if(a) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
void Yes(int a){
if(a) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
//#include <atcoder/all>
//using namespace atcoder;
//typedef modint998244353 mint;
ll inf=1001001001001001001;
ll gcd(ll a,ll b){
if(b==0) return a;
return gcd(b,a%b);
}
int main(){
string S;
cin>>S;
string T;
rep(i,S.size()){
if(S[i]=='6') T+='9';
else if(S[i]=='9') T+='6';
else T+=S[i];
}
reverse(all(T));
cout<<T<<endl;
}
| #include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1000000007ll
#define md 998244353ll
#define e1 1e-9
#define v vector< long long >
#define vv vector< vector< long long > >
#define p pair < long long,long long >
#define vp vector< pair < long long,long long > >
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ft first
#define sd second
#define all(x) x.begin() , x.end()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define bb(i,a,b) for(ll i=a;i>=0;i--)
#define test \
ll tt{0}; \
cin>>tt; \
while(tt--)
using namespace std;
bool prime(ll n) {
if (n < 2)return false;
for (ll x = 2; x * x <= n; x++) {
if (n % x == 0)return false;
}
return true;
}
vector<ll> Seiveprime(ll n)
{
vector<bool> isPrime(n, true);
for (int i = 2; i * i < n; i++)
{
if (isPrime[i])
{
for (int j = i * i; j < n; j += i)
isPrime[j] = false;
}
}
vector<ll> prime;
prime.push_back(2);
for (int i = 3; i < n; i += 2)
if (isPrime[i])
prime.push_back(i);
return prime;
}
vector<ll> factors(ll n) {
vector<ll> f;
for (ll x = 2; x*x <= n; x++) {
while (n%x == 0) {
f.pb(x);
n /= x;
}
}
if (n > 1) f.pb(n);
return f;
}
vp pri_fact(ll n) {
v x = factors(n);
vp y;
y.eb(x[0], 1);
for (ull i = 1; i < x.size(); i++) {
if (x[i] == x[i - 1]) {
y.back().second++;
} else {
y.eb(x[i], 1);
}
}
return y;
}
tuple<int,int,int> gcd(int a, int b) {
if (b == 0) {
return {1,0,a};
} else {
int x,y,g;
tie(x,y,g) = gcd(b,a%b);
return {y,x-(a/b)*y,g};
}
}
ll mult(ll x,ll y,ll m) {
return (x * y) % m;
}
//returns x^n (mod m)
ll bin_pow(ll x,ll n,ll m) {
if (n == 0)return 1;
if (n & 1)return mult(x, bin_pow(x, n - 1, m), m);
return bin_pow(mult(x, x, m), n / 2, m);
}
ll ind_of_2(ll x) {
ll i = 0;
while (x / (1 << i) != 1)
i++;
return i;
}
ll add(ll x,ll y)
{
x+=y;
if(x>=md)return x-md;
return x;
}
ll digitno(ll n){
ll x{0};
while(n>0){
x++;
n/=10;
}
return x;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
bitset<100005ll> bit,bit1;
bit[0]=1;
ll n{0},sum{0};
cin>>n;
v t(n);
f(i,0,n){
cin>>t[i];
sum+=t[i];
bit= bit | (bit<<t[i]);
}
ll mn=INT_MAX;
ll ans{0};
f(i,1,100005){
if(bit[i]){
if(abs(sum-2*i)<mn)
{
mn=abs(sum-2*i);
ans=i;
}
}
}
ans=max(ans,sum-ans);
cout<<ans;
return 0;
} |
// abc193_e
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../../debug_util/cxx-prettyprint/prettyprint.hpp"
#include "../../debug_util/rng.hpp"
#include "../../debug_util/timer.hpp"
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
#define REP(i, n) for (int i = 0 ; i < (int)(n) ; ++i)
#define REPN(i, m, n) for (int i = m ; i < (int)(n) ; ++i)
#define REP_REV(i, n) for (int i = (int)(n) - 1 ; i >= 0 ; --i)
#define REPN_REV(i, m, n) for (int i = (int)(n) - 1 ; i >= m ; --i)
#define ALL(x) x.begin(), x.end()
#define INF (ll)(2e18)
#define MOD (1000000007)
#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
//struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;
// 拡張 Euclid の互除法
// ax + by = gcd(a, b) となる (x, y) を求め、d = gcd(a, b) を返す
ll extgcd(ll a, ll b, ll& x, ll& y) { ll d = a; if(b != 0){ d = extgcd(b, a%b, y, x); y -= (a/b) * x; } else{ x = 1; y = 0; } return d; }
// 負の数にも対応した mod
// 例えば -17 を 5 で割った余りは本当は 3 (-17 ≡ 3 (mod. 5))
// しかし単に -17 % 5 では -2 になってしまう
inline long long mod(long long a, long long m) {
return (a % m + m) % m;
}
// 拡張 Euclid の互除法
// ap + bq = gcd(a, b) となる (p, q) を求め、d = gcd(a, b) をリターンします
long long extGcd(long long a, long long b, long long &p, long long &q) {
if (b == 0) { p = 1; q = 0; return a; }
long long d = extGcd(b, a%b, q, p);
q -= a/b * p;
return d;
}
// 中国剰余定理
// リターン値を (r, m) とすると解は x ≡ r (mod. m)
// 解なしの場合は (0, -1) をリターン
pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2) {
long long p, q;
long long d = extGcd(m1, m2, p, q); // p is inv of m1/d (mod. m2/d)
if ((b2 - b1) % d != 0) return make_pair(0, -1);
long long m = m1 * (m2/d); // lcm of (m1, m2)
long long tmp = (b2 - b1) / d * p % (m2/d);
long long r = mod(b1 + m1 * tmp, m);
return make_pair(r, m);
}
int main() {
#ifdef LOCAL
ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif
int T;
cin >> T;
while (T--){
ll X, Y, P, Q;
cin >> X >> Y >> P >> Q;
ll ans = -1;
REP(j, Q){
int i = 0;
ll n1 = 2*X + 2*Y;
ll b1 = X + i;
ll n2 = P + Q;
ll b2 = P + j;
auto res = ChineseRem(b1, n1, b2, n2);
if (res.second == -1){
continue;
}
ll tmp = res.first;
ans = ans == -1 ? tmp : min(ans, tmp);
}
REP(i, Y) {
int j = 0;
ll n1 = 2*X + 2*Y;
ll b1 = X + i;
ll n2 = P + Q;
ll b2 = P + j;
auto res = ChineseRem(b1, n1, b2, n2);
if (res.second == -1){
continue;
}
ll tmp = res.first;
ans = ans == -1 ? tmp : min(ans, tmp);
}
if (ans == -1){
print("infinity");
} else {
print(ans);
}
}
return 0;
}
| #include <bits/stdc++.h>
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#define hh "\n"
#define fi first
#define se second
#define inf 2147483647
#define llf 9223372036854775807
#define For(i,a) for(auto &i:a)
#define mapa(a,b) make_pair(a,b)
#define tty template <typename T>
#define mm(a,b) memset(a,b, sizeof(a));
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define cf int t;cin>>t;while (t--) solve();
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
tty T gcd (T a, T b) {while (b ^= a ^= b ^= a %= b); return a;}
inline char nc() {static char buf[1000000], *p1 = buf, *p2 = buf;return p1 == p2 && (p2 = (p1 = buf) + fread (buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++;}
//#define nc getchar
tty inline void read(T &sum) {char ch = nc();T tf = 0;sum = 0;while((ch < '0' || ch > '9') && (ch != '-')) ch = nc();tf = ((ch == '-') && (ch = nc()));while(ch >= '0' && ch <= '9') sum = sum * 10+ (ch - 48), ch = nc();(tf) && (sum = -sum);}
tty inline void write(T x){char F[200];T tmp=x>0?x:-x ;if(x<0)putchar('-') ;T cnt=0 ;while(tmp>0){F[cnt++]=tmp%10+'0';tmp/=10;}while(cnt>0)putchar(F[--cnt]) ;}
tty inline T ksc(T x, T y, T mod){return ( x * y - (ll) ( (long double) x / mod*y )*mod + mod ) % mod;}
tty inline T exgcd(T a, T b, T &x, T &y) {if (!b) {x = 1,y=0;return a;}T d = exgcd(b, a % b, x, y);T t = x;x=y;y=t-(a/b)*y;return d;}
tty inline void rmqmin(T f[][20],T n){for (int i = 1; i <= n; i++)cin >> f[i][0];for (int j = 1; j <= 20; j++)for (int i = 1; i <= n; i++)if (i + (1 << j) - 1 <= n)f[i][j] = min(f[i][j - 1], f[i + (1 << (j-1))][j - 1]);}
tty inline T zymin(T f[][20],T z,T y){int x=int (log(y-z+1)/log(2));return min(f[z][x],f[y-(1<<x)+1][x]);}
tty inline void rmqmax(T f[][20], T n, int i1) {for (int i = 1; i <= n; i++)cin >> f[i][0];for (int j = 1; j <= 20; j++)for (int i = 1; i <= n; i++)if (i + (1 << j) - 1 <= n)f[i][j] = max(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);}
tty inline T zymax(T f[][20],T z,T y){int x=int (log(y-z+1)/log(2));return max(f[z][x],f[y-(1<<x)+1][x]);}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ll excrt(ll n , ll ai[] , ll bi[])
{
ll x,y;
ll M=bi[1] , ans=ai[1];
for(int i=2;i<=n;i++)
{
ll a=M , b=bi[i] , c=(ai[i]-ans%b+b)%b;
ll gcd=exgcd(a,b,x,y) , bg=b/gcd;
if(c%gcd != 0) return -1;
x = ksc(x,c/gcd,bg);
ans += x * M;
M *= bg;
ans=(ans%M+M)%M;
}
return (ans%M+M)%M;
}
ll a[5],b[5];
void solve()
{
ll x , y , p , q; cin >> x >> y >> p >> q;
ll ans = llf;
for (int i = x ; i < x + y ; i++){
for (int j = p ; j < p + q ; j++){
a[1] = i , b[1] = 2 * (x + y);
a[2] = j , b[2] = p + q;
ll res = excrt(2 , a , b);
if (res == -1) continue;
ans = min(ans , res);
}
}
if (ans == llf) cout<<"infinity"<<endl;
else cout<<ans<<endl;
}
int main()
{
IOS;cf
return 0;
}
|
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
using ll = int64_t;
using db = double;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
constexpr char newl = '\n';
constexpr double eps = 1e-10;
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define show(x) cout << #x << " = " << (x) << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
F0R(j, sz(v)) i >> v[j];
return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) {
o << "(" << v.first << "," << v.second << ")";
return o;
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
F0R(i, v.size()) {
o << v[i] << ' ';
}
o << newl;
return o;
}
template<class T> ostream& operator<<(ostream& o, const set<T>& v) {
for (auto e : v) {
o << e << ' ';
}
o << newl;
return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
for (auto& p : m) {
o << p.first << ": " << p.second << newl;
}
o << newl;
return o;
}
#if 1
#ifdef __GNUC__
#define popcount __builtin_popcountll
#else
constexpr int popcount(ll x)
{
x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555);
x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333);
x = (x & 0x0f0f0f0f0f0f0f0f) + (x >> 4 & 0x0f0f0f0f0f0f0f0f);
x = (x & 0x00ff00ff00ff00ff) + (x >> 8 & 0x00ff00ff00ff00ff);
x = (x & 0x0000ffff0000ffff) + (x >> 16 & 0x0000ffff0000ffff);
return (int)((x & 0x00000000ffffffff) + (x >> 32 & 0x00000000ffffffff));
}
#endif
struct Cst {
int x, y, z;
bool operator<(const Cst& v) const {
return x < v.x;
}
};
// INSERT ABOVE HERE
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N, M; cin >> N >> M;
v(Cst) cs(M);
vv(Cst) ds(N + 1);
F0R(i, M) {
cin >> cs[i].x >> cs[i].y >> cs[i].z;
ds[cs[i].x].push_back(cs[i]);
}
vl dp(1 << N); // 既に並べた数が 集合i のときの場合の数
dp[0] = 1;
FOR(b, 1, 1 << N) {
F0R(i, N) {
if ((b >> i) & 1) {
dp[b] += dp[b ^ (1 << i)];
}
}
int pc = popcount(b);
for (auto [x, y, z] : ds[pc]) {
int a = b & ((1 << y) - 1);
if (popcount(a) > z) {
dp[b] = 0;
break;
}
}
}
cout << dp[(1 << N) - 1] << newl;
}
#endif
| #include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int,int> ii;
const int mod = 1e9 + 7;
const ll INF = 3e18;
const double EPSILON = 1e-9;
const int N = 200005;
struct ST{
int pos, qt, val;
};
bool valid[1<<19];
int n, m;
ll dp[1<<19];
ll solve(int msk){
if(msk == (1<<n)-1)
return 1;
if(dp[msk] != -1)
return dp[msk];
ll ans = 0;
for(int j = 0; j < n; j++){
if(!(msk&(1<<j)) and valid[msk+(1<<j)]){
ans += solve(msk+(1<<j));
}
}
return dp[msk] = ans;
}
int main(){
fastio;
memset(dp, -1, sizeof(dp));
cin >> n >> m;
ST v[m];
for(int i = 0; i < m; i++){
cin >> v[i].pos >> v[i].val >> v[i].qt;
}
for(int msk = 0; msk < (1<<n); msk++){
int x = __builtin_popcount(msk);
vi sum(n+1);
for(int i = 0; i < n; i++){
if(msk&(1<<i)){
sum[i+1]++;
}
sum[i+1] += sum[i];
}
bool flag = true;
for(int j = 0; j < m; j++){
if(v[j].pos < x)continue;
if(sum[v[j].val] > v[j].qt)
flag = false;
}
valid[msk] = flag;
}
cout << solve(0) << "\n";
return 0;
}
|
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;
int main(void){
int a,b;
scanf("%d%d", &a, &b);
if(b%a==0){
printf("Yes\n");
} else {
printf("No\n");
}
return 0;
}
| #include<bits/stdc++.h>
#define forn(i,s,t) for(int i=(s);i<=(t);++i)
using namespace std;
typedef long long LL ;
LL S,P;
int main() {
scanf("%lld%lld",&S,&P);
LL TMP;
for(LL i=1;i*i<=P;++i) if(P%i == 0) {
TMP = P/i;
if(TMP + i == S) {
puts("Yes");
return 0;
}
}
puts("No");
return 0;
}
// A+B = S;
// A*B = P;
// A = S-B
// (S-B)*B = P
// P + (B-S) * B = 0
// B^2 - S*B + P = 0;
// delta = S^2-4*P |
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define ll long long
#define pr pair<int,int>
#define N 100005
#define mod 1000000007
#define INF 2147483647
using namespace std;
int main() {
IOS;
int n;
string t;
cin>>n>>t;
if(n==1){
if(t=="1"){
cout<<20000000000;
}
else cout<<10000000000;
return 0;
}
bool los=0;
int cnt1=0,cnt0=0;
bool hs0=0;
for(int i=0;i<n;i++){
if(t[i]=='0'){
if(hs0&&cnt1!=2)los=1;
hs0=1;
cnt1=0;
cnt0++;
}
else cnt1++,cnt0=0;
if(cnt1>2||cnt0>1)los=1;
if(los)break;
}
if(los)cout<<0;
else{
ll len=10000000000;
ll ans=n;
if(t[0]=='0'){
ans=(2+n)/3+((n+2)%3!=0);
}
else if(t[1]=='0'){
ans=(1+n)/3+((n+1)%3!=0);
}
else{
ans=n/3+(n%3!=0);
}
cout<<len-ans+1;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}
#ifdef LOCAL
void _debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void _debug_out(Head H, Tail... T) { cerr << " " << to_string(H); _debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", _debug_out(__VA_ARGS__)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 42
#define eprintf(...) 42
#endif
int main() {
int n; string t; cin >> n >> t;
if(n == 1) {
if(t[0] == '0') cout << (ll)1e10 << endl;
else cout << 2 * (ll)1e10 << endl;
return 0;
}
if(n==2) {
if(t=="11") cout << (ll)1e10 << endl;
if(t=="10") cout << (ll)1e10 << endl;
if(t=="01") cout << (ll)(1e10)-1 << endl;
if(t=="00") cout << 0 << endl;
return 0;
}
auto ttt = t.substr(0,3);
if(!(ttt=="110" || ttt =="101" || ttt=="011")) {
cout << 0 << endl;
return 0;
}
for(int i=0; i<n-3; i++) {
if(t[i] != t[i+3]) {
cout << 0 << endl;
return 0;
}
}
int zero = 0;
for(auto c:t) zero += (c=='0');
cerr << zero << endl;
ll ans = (ll)1e10 - zero;
if(t.back() == '0') ans++;
cout << ans << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define endl '\n'
void fast_io()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
}
ll gcd(ll a , ll b) {
if (b == 0) return a;
return gcd(b, a % b);
}
void dfs(vi g[], int vis[], int src, int a[]) {
vis[src] = 1;
for (int v : g[src]) {
if (!vis[v]) {
dfs(g, vis, v, a);
}
}
}
int cnt;
void dfs2(vi g[], int vis[], int src, int a[], int n) {
vis[src] = 1;
if (cnt >= (n - 1)) return;
for (int v : g[src]) {
if (!vis[v]) {
cout << src + 1 << " ";
cout << v + 1 << endl;
cnt++;
dfs2(g, vis, v, a, n);
}
}
}
void bfs(vi g[], ll n, int dis[], int p[]) {
int visi[n + 1];
for (int i = 1; i <= n; i++) visi[i] = 0;
queue<int> q;
q.push(1); visi[1] = 1;
p[1] = -1;
while (!q.empty()) {
int top = q.front(); q.pop();
for (int v : g[top]) {
if (!visi[v]) {
q.push(v);
visi[v] = 1;
dis[v] = dis[top] + 1;
p[v] = top;
}
}
}
}
// bool vis[100010];
// int subtreesize[100010];
// vi adjacency_list[100010];
pair<ll, int> subtree_size_dfs(vi adjacency_list[], int node, bool vis[], int subtreesize[] ) {
vis[node] = true;
int cur = 1;
ll mex = 0;
for (int child : adjacency_list[node]) {
if (!vis[child]) {
// p[child] = node;
auto tmp = subtree_size_dfs(adjacency_list, child, vis, subtreesize);
mex = max(mex, tmp.first);
cur += tmp.second;
}
}
subtreesize[node] = cur;
return {cur + mex, cur};
}
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
const int max_r = 2000;
const int max_c = 2000;
int bfs_grid(char grid[][max_c], int n, int m, int sx, int sy, vpii al[], int desx, int desy) {
bool vis[n][m];
int dis[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
vis[i][j] = false;
dis[i][j] = -1;
}
}
int visc[26] = {0};
for (int i = 0; i < 26; i++) {
visc[i] = false;
}
queue<pii> q;
q.push({sx, sy});
vis[sx][sy] = true;
dis[sx][sy] = 0;
while (!q.empty()) {
pii top = q.front(); q.pop();
int nx = top.ff;
int ny = top.ss;
for (int i = 0; i < 4; i++) {
int tx = top.ff + dx[i];
int ty = top.ss + dy[i];
if (tx >= 0 && tx < n && ty >= 0 && ty < m && !vis[tx][ty] && grid[tx][ty] != '#') {
vis[tx][ty] = true;
q.push({tx, ty});
dis[tx][ty] = dis[top.ff][top.ss] + 1;
}
}
if (grid[nx][ny] >= 'a' && grid[nx][ny] <= 'z' && !visc[grid[nx][ny] - 'a']) {
int num = grid[nx][ny] - 'a';
visc[num] = 1;
for (int i = 0; i < (int)al[num].size(); i++) {
int tx = al[num][i].ff;
int ty = al[num][i].ss;
if (tx >= 0 && tx < n && ty >= 0 && ty < m && !vis[tx][ty] && grid[tx][ty] != '#') {
vis[tx][ty] = true;
q.push({tx, ty});
dis[tx][ty] = dis[nx][ny] + 1;
}
}
}
}
return dis[desx][desy];
}
int main()
{
fast_io();
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// cin >> t;
while (t--)
{
char grid[max_r][max_c];
int n, m; cin >> n >> m;
int sx, sy, desx, desy;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> grid[i][j];
if (grid[i][j] == 'S') {
sx = i; sy = j;
}
if (grid[i][j] == 'G') {
desx = i; desy = j;
}
}
}
vpii al[26];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (grid[i][j] >= 'a' && grid[i][j] <= 'z') {
int num = grid[i][j] - 'a';
al[num].pb({i, j});
}
}
}
cout << bfs_grid(grid, n, m, sx, sy, al, desx, desy) << endl;
}
} | #include <bits/stdc++.h>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define P pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
#define mp make_pair
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rev(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define revs(i, n) for (int i = ((int)(n)); i > 0; --i)
// template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
// template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;
const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);
// template <class T> void plus_mod(T &a, const T &b) {a = (a + b) % MOD;}
vector<P> warps[30];
ll warp_points[2010][2010];
ll maze[2010][2010];
vector<P> get_warp(ll y, ll x) {
ll wid = warp_points[y][x];
return warps[wid];
// auto point1 = warps[wid][0];
// auto point2 = warps[wid][1];
// if (point1.first == y && point1.second == x) {
// return point2;
// } else {
// return point1;
// }
}
int main() {
// std::cout << std::fixed << std::setprecision(10);
ll H, W;
scanf("%lld %lld", &H, &W);
fill(maze[0], maze[2005], -1);
ll sy, sx, gy, gx;
// インデックス1開始なので注意
reps(y, H) {
string line;
cin >> line;
reps(x, line.size()) {
char ch = line[x - 1];
if (ch == '#') {
maze[y][x] = -1;
} else if (ch == '.') {
maze[y][x] = INF;
} else if (ch == 'S') {
sy = y;
sx = x;
maze[y][x] = 0;
} else if (ch == 'G') {
gy = y;
gx = x;
maze[y][x] = INF;
} else {
// ワープ
ll wid = ch - 'a' + 1;
warps[wid].emplace_back(mp(y, x));
warp_points[y][x] = wid;
maze[y][x] = INF;
}
}
}
//--------------------------------------------------
deque<l_l> que;
que.emplace_back(mp(sy, sx));
maze[sy][sx] = 0;
for (;;) {
if (que.empty()) {
break;
}
auto pos = que.front();
que.pop_front();
ll y = pos.first;
ll x = pos.second;
// cout << "y:" << (y) << ",x:" << (x) << endl;
ll c = maze[y][x];
for (auto e : {mp(y - 1, x), mp(y, x - 1), mp(y + 1, x), mp(y, x + 1)}) {
if (maze[e.first][e.second] == -1) {
continue;
}
if (maze[e.first][e.second] <= c + 1) {
continue;
}
maze[e.first][e.second] = c + 1;
que.emplace_back(make_pair(e.first, e.second));
}
if (warp_points[y][x]) {
ll wid = warp_points[y][x];
auto warp_list = get_warp(y, x);
rep(i, warp_list.size()) {
auto next = warp_list[i];
warp_points[next.first][next.second] = 0;
if (maze[next.first][next.second] > c + 1) {
// cout << "WARP!:"
// << "next.first:" << (next.first) << ",next.second:" << (next.second) << endl;
maze[next.first][next.second] = c + 1;
que.emplace_front(make_pair(next.first, next.second));
}
warp_points[next.first][next.second] = 0;
}
}
}
ll ans = maze[gy][gx];
if (ans == INF) {
cout << (-1) << endl;
return 0;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define MP make_pair
using namespace std;
#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 foreach(itr, c) for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); ++ itr)
typedef long long LL;
typedef pair<int, int> pii;
int ret;
string s;
void dfs(int pos, int cnt, int cur)
{
if (pos == 10) {
if (cnt == 4) ret += cur;
return ;
}
if (s[pos] == 'x') {
dfs(pos + 1, cnt, cur);
return ;
}
int st = s[pos] == 'o' ? 1 : 0;
for (int i = st; i + cnt <= 4; ++ i) {
int ncur = cur;
for (int j = cnt + 1; j <= cnt + i; j ++) ncur *= j;
for (int j = 1; j <= i; j ++) ncur /= j;
dfs(pos + 1, cnt + i, ncur);
}
}
int main()
{
cin >> s;
dfs(0, 0, 1);
printf("%d\n", ret);
return 0;
} | #include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
const ll MOD=998244353;
ll dp[102][102][10004];
int main(){FIN;
ll n; cin>>n;
vector<ll> a(n);
fore(i,0,n)cin>>a[i];
for(ll x=n;x>=0;x--){
for(ll y=x;y>=0;y--){
fore(z,0,10004){
ll &res=dp[x][y][z];
if(x==n){
if(z==0)res=1;
else res=0;
}else{
res=dp[x+1][y+1][z+a[x]]*(y+1);
if(a[x]<=z){
res=(res+dp[x+1][y][z-a[x]]*(x+1-y))%MOD;
}else{
res=(res+dp[x+1][x-y+1][a[x]-z]*(x+1-y))%MOD;
}
}
}
}
}
cout<<dp[0][0][0]<<"\n";
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = long double; // or double, if TL is tight
using str = string; // yay python!
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
#define tcT template<class T
#define tcTU tcT, class U
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcT> using PR = pair<T,T>;
// pairs
#define mp make_pair
#define f first
#define s second
// vectors
// oops size(x), rbegin(x), rend(x) need C++17
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
tcT> int lwb(V<T>& a, const T& b) { return int(lb(all(a),b)-bg(a)); }
// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const db PI = acos((db)-1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;
// bitwise ops
// also see https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { // assert(x >= 0); // make C++11 compatible until USACO updates ...
return x == 0 ? 0 : 31-__builtin_clz(x); } // floor(log2(x))
constexpr int p2(int x) { return 1<<x; }
constexpr int msk2(int x) { return p2(x)-1; }
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
tcT> bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0; }
tcTU> T fstTrue(T lo, T hi, U f) {
hi ++; assert(lo <= hi); // assuming f is increasing
while (lo < hi) { // find first index such that f is true
T mid = lo+(hi-lo)/2;
f(mid) ? hi = mid : lo = mid+1;
}
return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
lo --; assert(lo <= hi); // assuming f is decreasing
while (lo < hi) { // find first index such that f is true
T mid = lo+(hi-lo+1)/2;
f(mid) ? lo = mid : hi = mid-1;
}
return lo;
}
tcT> void remDup(vector<T>& v) { // sort and remove duplicates
sort(all(v)); v.erase(unique(all(v)),end(v)); }
tcTU> void erase(T& t, const U& u) { // don't erase
auto it = t.find(u); assert(it != end(t));
t.erase(it); } // element that doesn't exist from (multi)set
void solve()
{
int n; cin>>n;
ll sum=0;
int a[n],b[n];
FOR(i,0,n) cin>>a[i];
FOR(i,0,n) cin>>b[i];
FOR(i,0,n) sum += a[i]*b[i];
if(sum==0) cout<<"Yes";
else cout<<"No";
}
int main()
{
cin.tie(0)->sync_with_stdio(0);
int ct=1;
// cin>>ct;
while(ct--)
{
solve();
}
} | #include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <climits>
#include <cassert>
#include <fstream>
#define rep(i, n) for(int i = 0; i < n; i++)
#define per(i, n) for(int i = n - 1; i >= 0; i--)
using ll = long long;
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
using namespace std;
#define y first
#define x second
constexpr bool istest = false;
constexpr int n = 50;
ifstream file;
ofstream out;
void input_setup(){
if(istest){
cout << "write the in file number\n";
string s;
cin >> s;
file.open("C:/Users/souta/downloads/ahc/tools/in/" + s + ".txt");
if(file.fail()){
cout << "the file was not found\n";
return;
}
cin.rdbuf(file.rdbuf());
}
}
//答えるときのやつ
string ans = "";
void output(){
if(istest){
out.open("C:/users/souta/downloads/ahc/tools/out.txt");
if(out.fail()){
cout << "the file was not found\n";
return;
}
cout.rdbuf(out.rdbuf());
}
cout << ans << "\n";
}
pii st_pos;
vvi tiles(n, vi(n)), point(n, vi(n));
void inputs(){
//start position
cin >> st_pos.y >> st_pos.x;
//tiles
rep(i, n) rep(j, n) cin >> tiles[i][j];
//points
rep(i, n) rep(j, n) cin >> point[i][j];
}
//過去に同じ番号のタイルを通ったことがあるのかを確認する
bool checkVisited(const int &Y, const int &X, const vector<pii> &logs){
int col = tiles[Y][X];
for(auto a : logs){
if(col == tiles[a.y][a.x]) return true;
}
return false;
}
//とりあえずBFSで探索してみる
int dy[] = {-1,1,0,0};
int dx[] = {0,0,-1,1};
char dir[] = {'U', 'D', 'L', 'R'};
void bfs(){
priority_queue<pair<pii, int>> que;
vvi checked(n, vi(n, -1));
checked[st_pos.y][st_pos.x] = point[st_pos.y][st_pos.x];
vector<vector<vector<pii>>> logs(n, vector<vector<pii>>(n));
logs[st_pos.y][st_pos.x].push_back(make_pair(st_pos.y, st_pos.x));
que.push(make_pair(st_pos, point[st_pos.y][st_pos.x]));
while(!que.empty()){
pii pos; int score;
tie(pos, score) = que.top();
que.pop();
if(checked[pos.y][pos.x] > score) continue;
rep(i, 4){
int Y = pos.y + dy[i];
int X = pos.x + dx[i];
if(Y >= n || X >= n || Y < 0 || X < 0) continue;
if(checkVisited(Y, X, logs[pos.y][pos.x])) continue;
int v = score + point[Y][X];
if(checked[Y][X] == -1 || checked[Y][X] <= v){
que.push(make_pair(make_pair(Y, X), v));
checked[Y][X] = v;
logs[Y][X] = logs[pos.y][pos.x];
logs[Y][X].push_back(make_pair(Y, X));
}
}
}
int mx = 0;
pii bestpos = st_pos;
rep(i, n) rep(j, n){
if(mx < checked[i][j]){
bestpos = make_pair(i, j);
mx = checked[i][j];
}
}
vector<pii> track = logs[bestpos.y][bestpos.x];
pii last = st_pos;
for(auto a : track){
rep(i, 4){
if(last.y + dy[i] == a.y && last.x + dx[i] == a.x){
ans += dir[i];
break;
}
}
last = a;
}
}
int main(){
input_setup();
inputs();
bfs();
output();
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
typedef long long ll;
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}
#ifdef _DEBUG
inline void dump() { cerr << endl; }
template <typename Head> void dump(Head &&head) { cerr << head; dump(); }
template <typename Head, typename... Tail> void dump(Head &&head, Tail &&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do { cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif
template <typename T> struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;
const ll LINF = 1LL << 60;
const int INF = 1001001001;
/////////////////////////////////////////////////////////////////////
int main()
{
int a,b,c; cin>>a>>b>>c;
vector<vector<vector<double>>> dp(101, vector<vector<double>>(101, vector<double>(101)));
for (int i=99; i>=0; i--) {
for (int j=99; j>=0; j--) {
for (int k=99; k>=0; k--) {
if (i == 0 && j == 0 && k == 0) continue;
dp[i][j][k] += dp[i+1][j][k]*((double)i/(i+j+k));
dp[i][j][k] += dp[i][j+1][k]*((double)j/(i+j+k));
dp[i][j][k] += dp[i][j][k+1]*((double)k/(i+j+k));
dp[i][j][k] += 1;
}
}
}
printf("%.10lf\n", dp[a][b][c]);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef stack<ll> stll;
typedef pair<ll,ll> pll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
#define FOR(i,s,e) for(ll i=s;i<e;i++)
#define mp make_pair
#define pb push_back
#define fi first
#define sec second
#define in insert
#define sz size
#define ln length
#define vec vector
#define all(v) v.begin(),v.end()
#define allg(v) v.begin(),v.end(),greater<ll>()
#define nl() cout << "\n"
#define mst(a) memset(a,-1,sizeof(a))
#define endl "\n"
#define debug(z) cout << #z << "=" << z << endl
#define MAX ll(1e9+7)
void solve();
double dp[101][101][101];
double calcu(ll a,ll b,ll c){
if(a==100 || b==100 || c==100)
return 0;
if(dp[a][b][c])
return dp[a][b][c];
double ans=0;
ans+=(calcu(a+1,b,c)+1)*a/(a+b+c);
ans+=(calcu(a,b+1,c)+1)*b/(a+b+c);
ans+=(calcu(a,b,c+1)+1)*c/(a+b+c);
return dp[a][b][c]=ans;
}
void solve(){
ll a[3];
FOR(i,0,3){
cin >> a[i];
}
printf("%.9f",calcu(a[0],a[1],a[2]));
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
ll t=1;
while(t--)
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using LD = long double;
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> void coutall(T v) { for(auto i = v.begin(); i != --v.end(); i++){cout << *i << " ";} cout << *--v.end() << endl; }
void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; }
void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; }
void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; }
ll myceil(ll a, ll b) { return (a + (b - 1)) / b; }
void Main(){
int n; cin >> n;
n = (1<<n);
cout << n-1 << endl;
rep3(i, 1, n-1){
rep(j, n){
int tmp = __builtin_popcount(i&j);
cout << (tmp&1 ? 'B' : 'A');
}
cout << endl;
}
return;
}
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
} | #include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;
const int Maxx=1000001,Maxn=2001,INF=0x3f3f3f3f,Mod=1e9+7;
inline int read()
{
int res=0,bj=0;char ch=getchar();
while(ch<'0'||ch>'9')bj|=(ch=='-'),ch=getchar();
while(ch>='0'&&ch<='9')res=(res<<3)+(res<<1)+(ch^48),ch=getchar();
return bj?-res:res;
}
void print(int x)
{
if(x>9)print(x/10);
putchar(x%10^48);
}
inline void printnum(int x,char ch)
{
if(x<0)putchar('-'),x=-x;
print(x),putchar(ch);
}
char S[1005],P[10]="atcoder";
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int T=read()+1,n;
while(--T){
scanf("%s",S),n=strlen(S);
int ans=1e9,p=0;
for(int i=0;i<8;++i)
if(S[i]!=P[i]){
if(S[i]>P[i])ans=0;
i=8;
}
for(int i=0,x;i<min(7,n);++i){
x=n;
for(int j=i;j<n;++j)
if(S[j]>P[i])x=j,j=n;
if(x<n)ans=min(ans,p+x-i);
x=n;
for(int j=i;j<n;++j)
if(S[j]>=P[i])x=j,j=n;
if(x==n)break;
p+=x-i;for(int j=x;j>i;--j)swap(S[j],S[j-1]);
}
cout<<(ans==1e9?-1:ans)<<"\n";
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int main()
{
int n;
cin>>n;
VII dp(2,vector<ll>(n+1));
dp[0][0] = dp[1][0] = 1;
for(int i=1;i<=n;i++){
string s;
cin>>s;
if(s == "AND"){
dp[1][i] += dp[1][i-1];
dp[0][i] += dp[1][i-1] + 2*dp[0][i-1];
}else{
dp[1][i]+=2*dp[1][i-1]+dp[0][i-1];
dp[0][i]+=dp[0][i-1];
}
}
cout<<dp[1][n];
}
| #pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<cstring>
#include<algorithm>
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 SZ = 400000;
class UF {
public:
ll P[SZ + 1];
UF() : P() {
rep1(i, SZ) P[i] = -(1 << 20);
}
int find(int A) {
if (P[A] < 0) return A;
return P[A] = find(P[A]);
}
void unite(int A, int B) {
int a = find(A);
int b = find(B);
if (a == b) {
P[a]--;
return;
}
if (P[a] > P[b]) swap(a, b);
P[a] += P[b];
P[b] = a;
}
} uf;
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;
}
int main() {
//cin.tie(0);
//ios::sync_with_stdio(false);
int N = getint();
rep(i, N) {
int a = getint(), b = getint();
uf.unite(a, b);
}
int kotae = 0;
rep1(i, 400000) {
ll a = -uf.P[i];
if (a > 0) {
kotae += (a >> 20) - 1;
kotae += bool(a & ((1 << 20) - 1));
}
}
printf("%d", kotae);
Would you please return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;
struct Ad{ll x, y, r, num;};
struct Recang{
ll x1, y1, x2, y2;
ll size(){
return abs(x2-x1)*abs(y2-y1);
}
};
mt19937 mt(123);
const int MAX=9999;
int n;
bool overlap(Recang a, Recang b){
return max(a.x1,b.x1)<min(a.x2,b.x2)&&max(a.y1,b.y1)<min(a.y2,b.y2);
}
bool check(vector<Recang> ans, Recang a, int k){
REP(i,n){
if(i==k)
continue;
if(overlap(a,ans[i]))
return 1;
}
return 0;
}
bool extension(vector<Recang>& ans, int i, vector<ll> weight){
Recang& tmpr=ans[i];
vector<bool> used(4,0);
vector<int> perm;
REP(i,4){
ll sum=0;
REP(j,4){
if(!used[j])
sum+=weight[j];
}
ll r;
if(sum==0)
r=-1;
else
r=mt()%sum;
REP(j,4){
if(used[j])
continue;
r-=weight[j];
if(r<0){
perm.push_back(j);
used[j]=1;
break;
}
}
}
REP(j,4){
if(perm[j]==0){
tmpr.x2++;
if(tmpr.x2>MAX||check(ans,tmpr,i))
tmpr.x2--;
else
return 1;
}
else if(perm[j]==1){
tmpr.y2++;
if(tmpr.y2>MAX||check(ans,tmpr,i))
tmpr.y2--;
else
return 1;
}
else if(perm[j]==2){
tmpr.x1--;
if(tmpr.x1<0||check(ans,tmpr,i))
tmpr.x1++;
else
return 1;
}
else{
tmpr.y1--;
if(tmpr.y1<0||check(ans,tmpr,i))
tmpr.y1++;
else
return 1;
}
}
return 0;
}
void solve(){
cin >> n;
vector<Ad> ads(n);
int x, y, r;
REP(i,n){
cin >> x >> y >> r;
ads[i]=Ad{x,y,r,i};
}
vector<vector<ll>> weight(n,vector<ll>(4,0));
REP(i,n)REP(j,i){
if(ads[i].x<ads[j].x){
weight[i][0]+=ads[j].r;
weight[j][2]+=ads[i].r;
}
else{
weight[i][2]+=ads[j].r;
weight[j][0]+=ads[i].r;
}
if(ads[i].y<ads[j].y){
weight[i][1]+=ads[j].r;
weight[j][3]+=ads[i].r;
}
else{
weight[i][3]+=ads[j].r;
weight[j][1]+=ads[i].r;
}
}
REP(i,n){
ll sum=0;
REP(j,4)
sum+=weight[i][j];
REP(j,4)
weight[i][j]=sum-weight[i][j];
}
vector<Recang> ans(n);
REP(i,n){
Ad ad=ads[i];
ans[i]={ad.x,ad.y,ad.x+1,ad.y+1};
}
priority_queue<pair<double,int>,vector<pair<double,int>>,greater<pair<double,int>>> que;
REP(i,n) que.push({(double)1/ads[i].r,i});
while(!que.empty()){
int i=que.top().second;
que.pop();
if(extension(ans,i,weight[i])){
if(ans[i].size()<ads[i].r)
que.push({(double)ans[i].size()/ads[i].r,i});
}
}
REP(i,n){
Recang tmpr=ans[i];
cout << tmpr.x1 << " ";
cout << tmpr.y1 << " ";
cout << tmpr.x2 << " ";
cout << tmpr.y2 << endl;
}
}
int main(){
solve();
return 0;
} | #pragma region header
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define int ll
#define each(i, a) for (auto &&i : (a))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vd = vector<ld>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using vp = vector<P>;
using int128 = __int128_t;//cin coutはできない
template <class T>
using greater_queue = priority_queue<T, vector<T>, greater<T>>;
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;};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
template <class T>
void CVEC(const T &v) {
int c = v.size() - 1;
for (int i = 0; i < c; i++) cout << v[i] << ' ';
if (c > -1) cout << v[c];
cout << '\n';
}
#pragma endregion header
int XMAX = 10000;
int YMAX = 10000;
struct Rectangle{
int a, b, c, d;
};
struct Point{
int id, x, y, r;
bool operator<( const Point& right ) const {
return x == right.x ? y < right.y : x < right.x;
}
};
void COUT(Rectangle x){
cout << x.a << " " << x.b << " " << x.c << " " << x.d << endl;
}
int n;
set<P> occupied;
vector<int> area(n, 0);
signed main(){
cin >> n;
vector<Point> Ps;
map<int, Rectangle> ans;
rep(i,n){
int x, y, r; cin >> x >> y >> r;
Ps.push_back({i, x, y, r});
}
sort(ALL(Ps));
/*
rep(i,n){
int a = Ps[i].x;//x
int b = Ps[i].y;//y
int r = Ps[i].r;
cout << a << " " << b << " " << r << endl;
}
*/
rep(i,n){
int x = Ps[i].x;
int y = Ps[i].y;
int id = Ps[i].id;
if(i == 0) ans[id] = {0, 0, x+1, y+1};
else if(i == n-1) ans[id] = {x, y, XMAX, YMAX};
else ans[id] = {x, y, x+2, y+2};
}
rep(i,n){
COUT(ans[i]);
}
} |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int A,B;
cin>>A>>B;
if(B < 2*A + 100)
{
cout<<2*A + 100 - B<<"\n";
}
else
{
cout<<0<<"\n";
}
} | #include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
#include <assert.h>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
#define v(t) vector<t>
#define vv(t) vector<vector<t>>
#define vvv(t) vector<vector<vector<t>>>
typedef long long ll;
typedef double lf;
typedef short int si;
void Main(){
ll A, B;
cin >> A >> B;
ll res = 2 * A + 100 - B;
cout << res <<endl;
}
int main(){
Main();
} |
#include<bits/stdc++.h>
using namespace std;
int Large_digit(int a,int b){
int sum1=0,sum2=0;
while(a!=0){
int r=a%10;
sum1+=r;
a/=10;
}
while(b!=0){
int p=b%10;
sum2+=p;
b/=10;
}
return max(sum1,sum2);
}
int main()
{
int a,b;
cin>>a>>b;
cout<<Large_digit(a,b)<<endl;
}
| #include<bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long int ll;
#include<string.h>
#define pi 3.1415926535897932384626433832795028841971
#define fastttt ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define str_max_len 4294967295
#define mod 1000000007
#define max_ll LLONG_MAX
#define min_ll LLONG_MIN
#define cps CLOCKS_PER_SEC
#define pb push_back
#define fi first
#define se second
#define in insert
#define m_p make_pair
#define p_q priority_queue
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define vii vector <pair<ll,ll>>
#define pii pair<ll,ll>
#define vi vector <ll>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
ll ll_max(ll a,ll b,ll c){return max(a,max(b,c));}
int int_max(int a,int b,int c){return max(a,max(b,c));}
ll ll_min(ll a,ll b,ll c){return min(a,min(b,c));}
int int_min(int a,int b,int c){return min(a,min(b,c));}
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);}
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}
ll fact[250005],fact_inv[250005];
ll power(ll a,ll b){
ll ans=1;
while(b>0){
if(b&1){ans=(ans*a)%mod;}
a=(a*a)%mod;
b>>=1;
}
return ans;
}
void pre(){
fact[0]=1;
fact_inv[0]=1;
for(int i=1;i<250005;i++){
fact[i]=fact[i-1]*i;
fact[i]%=mod;
fact_inv[i]=power(fact[i],mod-2);
}
}
ll ncr(ll n,ll r){
if(n<r){return 0;}
if(n==r||r==0){return 1;}
return (((fact[n]*fact_inv[n-r])%mod)*fact_inv[r])%mod;
//return x;
}
ll mod_inverse(ll x){
return power(x,mod-2);
}
bool sortbysec(const pair<ll,ll> &a,
const pair<ll,ll> &b)
{
return (a.second < b.second);
}
#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
#define nx 100005
//before dp think greedy
/***************************code begins here*****************************/
class solver{
public:
ll f(ll x)
{
ll s=0;
while(x!=0)
{
s+=x%10;
x=x/10;
}
return s;
}
void solve()
{
ll a,b;cin>>a>>b;
cout<<max(f(a),f(b));
}
};
int main(){
fastttt
// cout<<fixed<<setprecision(10);
int test=1,c=1;
//pre();
//cin>>test;
while(test--){
//cout<<"Case #"<<c<<": ";c++;
solver o;
o.solve();
}
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
for (in_vec_cout res : vec) {cout << res << " ";}
cout << endl;
}
const ll inf = 1e18;
const ll mod = 1e9 + 7;
int main() {
vector<string> S(3);
rep(i,3) cin >> S[i];
map<char,bool> used;
rep(i,3) rep(j,S[i].size()) used[S[i][j]] = true;
if (used.size()>10) Cout("UNSOLVABLE");
vector<ll> num(10);
rep(i,10) num[i] = i;
do {
map<char,ll> id;
ll index = 0;
for (auto p : used) {
id[p.first] = num[index];
index++;
}
vector<ll> N(3);
bool NG = false;
rep(i,3) {
if (id[S[i][0]]==0) NG = true;
rep(j,S[i].size()) N[i] = N[i]*10 + id[S[i][j]];
}
if (NG) continue;
if (N[0]+N[1]==N[2]) {
rep(i,3) cout << N[i] << endl;
return 0;
}
} while (next_permutation(all(num)));
Cout("UNSOLVABLE");
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for (int i = (m); i < (int)(n); i++)
using ll = long long;
ll solve(ll b, ll c) {
if (b == 0) return 1 + c / 2 + (c - 1) / 2;
ll ret = 2;
if (b > 0) ret += (c - 1) / 2 + (c - 2) / 2;
else ret += c / 2 + (c - 1) / 2;
if (b < 0) {
b *= -1;
c--;
}
ll l = max(-b + 1, b - c / 2);
ll r = min(b, (c - 1) / 2 - b + 1);
if (l <= r) ret += 2 * b - 1;
else ret += (b - l) + (b + r - 1);
return ret;
}
int main() {
// input
ll B, C;
cin >> B >> C;
//solve
ll ans = solve(B, C);
cout << ans << endl;
}
|
//红太阳zhouakngyang txdy!
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
using namespace std;
//#define int long long
inline int read()
{
int sum=0,nega=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')nega=-1;ch=getchar();}
while(ch<='9'&&ch>='0')sum=sum*10+ch-'0',ch=getchar();
return sum*nega;
}
int n,L=500001,R=500000,flag,top;
char a[500009],ans[1000009],res[1000009];
char out[1000009];
int main()
{
scanf("%s",a+1);n=strlen(a+1);
for(int i=1;i<=n;i++)
{
if(a[i]=='R')flag^=1;
else
{
if(flag)L--,res[L]=a[i];
else R++,res[R]=a[i];
}
}
if(!flag)
for(int i=1;i<=R-L+1;i++)ans[i]=res[i+L-1];
else
for(int i=1;i<=R-L+1;i++)ans[i]=res[R+1-i];
for(int i=1;i<=R-L+1;i++)
{
out[++top]=ans[i];
while(top!=0&&out[top]==out[top-1])top-=2;
}
for(int i=1;i<=top;i++)putchar(out[i]);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
deque<char> t;
bool f = 1;
cin >> s;
for(int i = 0; i < s.size(); i++){
if(s.at(i) == 'R'){
f = !f;
}else if(t.empty()){
t.push_back(s.at(i));
}else if(f){
if(s.at(i) != t.back()){
t.push_back(s.at(i));
}else{
t.pop_back();
}
}else if(!f){
if(s.at(i) != t.front()){
t.push_front(s.at(i));
}else{
t.pop_front();
}
}
}
if(!f){
for(int i = t.size() - 1; i >= 0; i--){
cout << t.at(i);
}
}else{
for(int i = 0; i < t.size(); i++){
cout << t.at(i);
}
}
} |
#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
int main()
{
double a,b;
cin>>a>>b;
cout<<100*(1-(b/a));
return 0;
} | #include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
using namespace std;
using Graph = vector<vector<int>>;
int main(){
ll n, k; cin >> n >> k;
ll ans = 0;
k = abs(k);
for(int i=k+2; i<=2*n; i++){
ll tmp;
if(i > n + 1) tmp = 2*n - i + 1;
else tmp = i - 1;
if(i - k > n + 1) tmp *= (2*n - (i - k) + 1);
else tmp *= (i - k - 1);
ans += tmp;
}
print(ans);
} |
#include <bits/stdc++.h>
using namespace std;
void solve()
{
int n, m; cin >> n >> m;
unordered_set<int> a, b;
int curr;
for (int i = 0; i < n; ++i) {
cin >> curr;
a.insert(curr);
}
for (int i = 0; i < m; ++i) {
cin >> curr;
b.insert(curr);
}
set<int> ans;
for (int num : a) {
if (b.find(num) == b.end()) {
ans.insert(num);
}
}
for (int num : b) {
if (a.find(num) == a.end()) {
ans.insert(num);
}
}
for (int num : ans) {
cout << num << ' ';
}
cout << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
} | #include<bits/stdc++.h>
#define RT register
#define ll long long
#define ull unsigned long long
#define lowbit(x) (x&(-x))
using namespace std;
template<typename T>
inline void read(T &x){
x=0; bool f=0;char ch=getchar();
while(ch<'0'||ch>'9'){f|=ch=='-';ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
x=f?-x:x;
}
template<typename T>
inline void print(T x){
if(x<0) x=-x,putchar('-');
if(x>9) print(x/10);
putchar(x%10+'0');
}
const int N=1004;
int a[N],b[N];
int n,m;
int main(){
read(n),read(m);
for(int i=1;i<=n;i++) read(a[i]);
for(int i=1;i<=m;i++) read(b[i]);
a[n+1]=b[m+1]=100000;
for(int i=1,j=1;i<=n||j<=m;){
if(a[i]<b[j]){
print(a[i]),putchar(' ');i++;
}
else if(a[i]==b[j]){
i++,j++;
}
else{
print(b[j]),putchar(' ');j++;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int maxk = 20;
char s[maxn];
ll f[maxn][maxk];
int n, k;
inline int c(char ch) { return isdigit(ch) ? ch - '0' : ch - 'A' + 10;}
ll calc(int pos, int state, bool flag)
{
if((!flag && state) || pos == n) return f[pos][__builtin_popcount(state)];
ll ret = 0;
int end = flag ? c(s[pos]) : 15;
for(int i = 0; i <= end; ++i)
{
int nxtstate = (!state && !i) ? 0 : state | (1 << i);
ret = (ret + calc(pos + 1, nxtstate, flag && (i == end))) % mod;
}
return ret;
}
int main()
{
scanf("%s%d", s, &k);
n = strlen(s);
f[n][k] = 1;
for(int i = n - 1; ~i; --i)
for(int j = 0; j <= k; ++j)
f[i][j] = (f[i + 1][j] * j % mod + f[i + 1][j + 1] * (16 - j) % mod) % mod;
printf("%lld\n", calc(0, 0, 1));
return 0;
} | #pragma GCC optimize(2)
#include<unordered_map>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
#define Buff ios::sync_with_stdio(false)
#define rush() int Case = 0; int T; cin >> T; while(T--)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define per(i, a, b) for(int i = a; i >= b; i --)
#define reps(i, a, b) for(int i = a; b; i ++)
#define clc(a, b) memset(a, b, sizeof(a))
#define Buff ios::sync_with_stdio(false)
#define readl(a) scanf("%lld", &a)
#define readd(a) scanf("%lf", &a)
#define readc(a) scanf("%c", &a)
#define reads(a) scanf("%s", a)
#define read(a) scanf("%d", &a)
#define lowbit(n) (n&(-n))
#define pb push_back
#define lson rt<<1
#define rson rt<<1|1
#define ls lson, l, mid
#define rs rson, mid+1, r
#define y second
#define x first
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int>PII;
const double eps = 1e-6;
const int INF = 1e9 + 7;
const int N = 2007;
const int M = 1e6 + 7;
const ll mod = 1e9 + 7;
ll dp[N][N];
ll sum[4][N][N];
char a[N][N];
signed main()
{
Buff;
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
cin >> a[i][j];
dp[1][1] = sum[1][1][1] = sum[2][1][1] = sum[3][1][1] = 1;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
if(a[i][j] == '#' || (i == j && j == 1))
continue;
else
{
dp[i][j] = (sum[1][i - 1][j] + sum[2][i][j - 1] + sum[3][i - 1][j - 1]) % mod;
sum[1][i][j] = (sum[1][i - 1][j] + dp[i][j]) % mod;
sum[2][i][j] = (sum[2][i][j - 1] + dp[i][j]) % mod;
sum[3][i][j] = (sum[3][i - 1][j - 1] + dp[i][j]) % mod;
}
}
}
cout << dp[n][m] << endl;
return 0;
} |
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }
vector<int> subtree_size, score;
void dfs(vector<vector<int>> &g, int v){
int sum = 0;
vector<int> vec;
for(auto nv : g[v]){
dfs(g, nv);
subtree_size[v] += subtree_size[nv];
if(subtree_size[nv]%2 == 1) vec.push_back(-score[nv]);
else if(score[nv] < 0) score[v] -= -score[nv];
else sum += -score[nv];
}
sort(vec.rbegin(), vec.rend());
vec.push_back(sum);
rep(i,vec.size()){
if(i%2 == 1) score[v] += vec[i];
else score[v] -= vec[i];
}
}
void solve(){
int n;
cin >> n;
vector<vector<int>> g(n);
subtree_size.assign(n, 1);
score.assign(n, 1);
rep(i,n-1){
int p;
cin >> p;
--p;
g[p].push_back(i+1);
}
dfs(g, 0);
int ans = (n + score[0]) / 2;
cout << ans << endl;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
} | #include <iostream>
#include <algorithm>
#include <vector>
const int MAXN = 100005;
std::vector<int> Adj[MAXN];
std::pair<int, int> dfs(int u) {
std::pair<int, int> ret = {1, 1};
std::vector<int> choices[2];
for(int j : Adj[u]) {
std::pair<int, int> next = dfs(j);
ret.second ^= next.second;
choices[next.second].push_back(next.first);
}
int odd = choices[1].size();
for(int i = 0; i < choices[0].size(); i++) {
if(choices[0][i] < 0)
ret.first += choices[0][i];
else
ret.first += (1 - 2*(odd%2))*choices[0][i];
}
std::sort(choices[1].begin(), choices[1].end());
for(int i = 0; i < choices[1].size(); i++)
ret.first += (1 - 2*(i%2))*choices[1][i];
return ret;
}
signed main() {
int n;
std::cin >> n;
for(int i = 1; i < n; i++) {
int p;
std::cin >> p;
p--;
Adj[p].push_back(i);
}
std::cout << (dfs(0).first + n)/2 << std::endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using ml = map<ll, ll>;
using vl = vector<ll>;
using vp = vector<pl>;
using vvl = vector<vl>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define fore(i_in,a) for (auto& i_in: a)
#define forp(x,y,a) for(auto& [x, y]: a)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pq(T) priority_queue<T, vector<T>, greater<T>>
#define fio() cin.tie(nullptr);ios::sync_with_stdio(false);
#define CEIL(a, b) (a+b-1)/b;
#define offset_FLOOR(a, b) (a-1)/b;
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<(int)v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
template<class T> bool chmax(T &a, const T &b) {if (a<b) { a = b; return true; } return 0;}
template<class T> bool chmin(T &a, const T &b) {if (a>b) { a = b; return true; } return 0;}
template<class T> void print(const T &t) { cout << t << "\n"; }
ll n, ans;
string s;
int main() {
fio(); cin>>n;
vvl dp(n+1, vl(2, 0));
dp[0][0]=1;dp[0][1]=1;
rep(i,n) {
cin>>s;
if (s=="OR") {
dp[i+1][0] = dp[i][0];
dp[i+1][1] = dp[i][0] + 2 * dp[i][1];
}
else {
dp[i+1][0] = 2 * dp[i][0] + dp[i][1];
dp[i+1][1] = dp[i][1];
}
}
print(dp[n][1]);
} | #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<bitset>
#include<vector>
#include<queue>
#include<deque>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
inline int read(){
int x=0;
bool f=0;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-'){
f=1;
}
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
if(f){
return -x;
}
return x;
}
inline uint readu(){
uint x=0;
char ch=getchar();
while(ch<'0'||ch>'9'){
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x;
}
void fp(){
freopen(".in","r",stdin);
freopen(".out","w",stdout);
}
char a[500005],t[1000005],tt[500005];
bool b[1000005];
int main(){
//fp();
int i,len,zz=500000,zz1=499999,fz=1,zz2=1;
scanf("%s",a+1);
len=strlen(a+1);
for(i=1;i<=len;i++){
if(a[i]=='R'){
fz^=1;
}
else{
if(fz){
t[++zz1]=a[i];
}
else{
t[--zz]=a[i];
}
}
}
if(!fz){
for(i=zz1;i>=zz;i--){
if(tt[zz2]==t[i]){
zz2--;
}
else{
tt[++zz2]=t[i];
}
}
for(i=2;i<=zz2;i++){
printf("%c",tt[i]);
}
return 0;
}
for(i=zz;i<=zz1;i++){
if(tt[zz2]==t[i]){
zz2--;
}
else{
tt[++zz2]=t[i];
}
}
for(i=2;i<=zz2;i++){
printf("%c",tt[i]);
}
return 0;
} |
// Problem: A - ABC Preparation
// Contest: AtCoder - AtCoder Beginner Contest 185
// URL: https://atcoder.jp/contests/abc185/tasks/abc185_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;
struct splitmix64_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
template <typename K, typename V, typename Hash = splitmix64_hash>
using hash_map = __gnu_pbds::gp_hash_table<K, V, Hash>;
template <typename K, typename Hash = splitmix64_hash>
using hash_set = hash_map<K, __gnu_pbds::null_type, Hash>;
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;
// sprawdz MODULO!
int main() {
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << min(min(a, b), min(c, d));
return 0;
}
| #include<iostream>
using namespace std;
int main(){
int V, T, S, D;
cin >> V >> T >> S >> D;
if(D / V >= T && S >= ((D + (V-1))/ V)){
cout << "No" << endl;
}else{
cout << "Yes" << endl;
}
return 0;
} |
#include <bits/stdc++.h>
#include <time.h>
#include <queue>
#define ll long long int
#define mp make_pair
#define ff first
#define ss second
#define forr(i,a,n) for(ll i=a;i<n;i++)
#define ford(i,a,n) for(ll i=n-1;i>=a;i--)
#define all(v) v.begin(),v.end()
#define testc ll ts;\
cin>>ts;\
while(ts--)
#define arn ll n;\
cin>>n;\
ll a[n];\
forr(i,0,n)cin>>a[i];\
#define arr(a,n) ll a[n];\
forr(i,0,n)cin>>a[i];\
#define sss <<" "<<
#define nnn <<"\n"
#define nl cout<<"\n";
#define prtitr(v) for(auto itr=v.begin(); itr!=v.end() ; itr++)cout<<*itr<<" ";
#define fitr(v) for(auto itr=v.begin(); itr!=v.end() ; itr++)
using namespace std;
ll M=1e9+7;
ll cdiv(ll a,ll b){
return (a%b==0)?a/b:a/b+1;
}
ll myMod(ll a, ll b){
ll r = a % b;
return r < 0 ? r + b : r;
}
ll ModPow(ll a,ll b,ll M)
{
if(M==1)return 0;
a%=M;
ll ans=1,t=1;
while(t>0&&t<=b)
{
if(t&b)
{
ans*=a;
ans%=M;
}
t<<=1;
a*=a;
a%=M;
}
return ans;
}
ll Pow(ll a,ll b)
{
if(M==1)return 0;
ll ans=1,t=1;
while(t>0&&t<=b)
{
if(t&b)
{
ans*=a;
}
t<<=1;
a*=a;
}
return ans;
}
ll gcd(ll a, ll b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
int countSetBits(int n)
{
int count = 0;
while (n > 0)
{
count++;
n &= (n-1);
}
return count;
}
// Function that return count of
// flipped number
int FlippedCount(int a, int b)
{
// Return count of set bits in
// a XOR b
return countSetBits(a^b);
}
struct Point{
int x,y;
};
bool isPrime(ll n){
if (n <= 1)
return false;
for (ll i = 2; i*i <= n; i++)
if (n % i == 0)
return false;
return true;
}
ll modInverse(ll n, ll p)
{
return ModPow(n, p - 2, p);
}
ll nCrModP(ll n, ll r, ll p)
{
if (n < r)
return 0;
if (r == 0)
return 1;
ll fac[n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = (fac[i - 1] * i) % p;
return (fac[n] * modInverse(fac[r], p) % p
* modInverse(fac[n - r], p) % p)
% p;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n;
cin>>n;
ll a[n],b[n];
forr(i,0,n)cin>>a[i];
forr(i,0,n)cin>>b[i];
ll mxa=-1,mxp=-1;
forr(i,0,n){
mxa=max(a[i],mxa);
mxp=max(mxp,b[i]*mxa);
cout<<mxp nnn;
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
int n;cin>>n;
ll arr[n+3],arr1[n+3];
for(int i=0;i<n;i++)cin>>arr[i];
for(int j=0;j<n;j++)cin>>arr1[j];
ll prev=-1,mx=0;
for(int i=0;i<n;i++)
{
mx=max(mx,arr[i]);
ll k=(arr[i]*arr1[i]);
prev=max(prev,k);
if(i>0)
{
prev=max(mx*arr1[i],prev);
}
cout<<prev<<endl;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long int ll;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ull unsigned long long
#define d1(x) cout<<#x<<" "<<x<<endl;
#define d2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define d2i(x,y,i) cout<<#x<<i<<" "<<x<<" "<<#y<<i<<" "<<y<<endl;
#define fr(i,l,r) for(ll i=l;i<r;i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define mod 1000000007
#define ff first
#define ss second
#define pb(x) push_back(x)
#define vll vector<ll>
#define pbp(x,y) push_back(make_pair(x,y))
#define all(v) v.begin(),v.end()
#define mat vector<vector<ll>>
#define el cout<<'\n';
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double slope( pair<ll,ll>&a,pair<ll,ll>&b){
return ((double)(b.ss-a.ss))/((double)(b.ff-a.ff));
}
void solve(){
ll n ;
cin>>n;
// map<string,int>mp;
// string ans="satisfiable";
// fr(i,0,n){
// string s;
// cin>>s;
// if(s[0]=='!' && mp.count(s.substr(1)))
// ans=s.substr(1);
// else if(mp.count("!"+s))
// ans=s;
// mp[s]++;
// }
// cout<<ans;
vector<pair<ll,ll>>v(n);
fr(i,0,n)
cin>>v[i].ff>>v[i].ss;
ll ans=0;
fr(i,0,n){
for(int j=i+1;j<n;j++){
double slp=slope(v[i],v[j]);
if(slp<=1 && slp>=-1)
ans++;
}
}
cout<<ans;
}
int main(){
boost
ll t=1;
// cin>>t;
while(t--){
solve();
el
}
return 0;
}
| #include<stdio.h>
float X(int a, int b, int c, int d)
{
return ((b-d)*1.0)/(a-c);
}
int main()
{
int m, t=0;
scanf("%d", &m);
int a[1001], b[1001];
for (int i = 0; i < m; i++)
scanf("%d %d", &a[i], &b[i]);
for (int j = 0; j < m; j++)
{
for (int k = j+1; k < m; k++)
{
if((X(a[j], b[j], a[k], b[k])>=-1)&&(X(a[j], b[j], a[k], b[k])<=1))
t++;
}
}
printf("%d", t);
return 0;
} |
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
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 rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,L,R) for(int i=L;i<R;i++)
using namespace std;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<vector<int>> Graph;
typedef vector<string> Grid;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
//#define DEBUG
//declaration area
//struct area
//function area
//main area
int main(){
int h, m;
cin >> h >> m;
cout << (m%h==0 ? "Yes":"No") << endl;
}
/*
*/ | #include <bits/stdc++.h>
using namespace std;
int m,h;
int main()
{
cin>>m>>h;
if(h%m==0) cout<<"Yes";
else cout<<"No";
}
|
#include<bits/stdc++.h>
// using namespace std;
#if __has_include(<atcoder/all>)
#include<atcoder/all>
// using namespace atcoder;
#endif
#define int long long
#pragma region header
#pragma region alias
using lint = long long;
using ll = long long;
using P = std::pair<int,int>;
template<class T> using prique = std::priority_queue<T,std::vector<T>,std::greater<T>>;
#pragma endregion
#pragma region macros
#define rep(i, n) for(int i = 0;i<(int)(n);i++)
#define REP(i, m, n) for(int i = (m);i<(int)(n);i++)
#define drep(i, n) for(int i = (n)-1;i>=0;i--)
#define DREP(i, m, n) for(int i = (m)-1;i>=(int)(n);i--)
#define all(v) (v).begin(),(v).end()
#define reall(v) (v).rbegin(),(v).rend()
template<class T, class U>
bool chmax(T& a,const U b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T, class U>
bool chmin(T& a,const U b) {
if(a>b) {
a = b;
return true;
}
return false;
}
std::map<int,int> prime_div(int n) {
std::map<int,int> mp;
if(~n&1) while(~n&1) n>>=1,mp[2]++;
for(int i = 3;i<=std::sqrt(n);i+=2) {
if(n%i==0) {
while(n%i==0) {
n/=i;
mp[i]++;
}
}
}
if(n!=1) mp[n]++;
return mp;
}
#pragma endregion
#pragma region constant
constexpr long long inf = 1LL << 61;
constexpr int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
constexpr int dy[9] = {0, 1, 0, -1, 1, -1, 1, -1, 0};
constexpr long long mod = 1e9+7;
constexpr long long MOD = 998244353;
#pragma endregion
#pragma region inout
template<class T>
std::ostream& operator<<(std::ostream& stream, const std::vector<T>& v) {
for(int i = 0; i < (int)(v.size()); i++) {
stream << v[i];
if(i != (int)(v.size()) - 1) stream << ' ';
}
return stream;
}
template<typename Itr>
inline void print(const Itr& begin, const Itr& end, bool endline = true, const char* BEGIN = "{", const char* mid = ", ", const char* END = "}") {
if(begin == end) return;
std::cout << BEGIN << *begin;
for(Itr itr = begin+1; itr < end; itr++) std::cout << mid << *itr;
std::cout << END;
if(endline) std::endl(std::cout);
return;
}
template<class T>
std::istream& operator>>(std::istream& stream, std::vector<T>& v) {
for(T& p:v) stream >> p;
return stream;
}
template<typename Itr>
inline void input(Itr begin, Itr end) {
for(Itr& itr = begin; itr < end; itr++) std::cin >> *itr;
return;
}
template<class T, class U>
std::ostream& operator<<(std::ostream& stream, const std::pair<T,U>& pair) {
return stream << pair.first << ' ' << pair.second;
}
template<class T, class U>
inline void print(const std::pair<T,U>& pair,const bool endline = true, const char* begin = "(", const char* mid = ", ", const char* end = ")") {
std::cout << begin << pair.first << mid << pair.second << end;
if(endline) std::endl(std::cout);
else std::cout << ' ';
return;
}
template<class T, class U>
std::istream& operator>>(std::istream& stream, std::pair<T,U>& pair) {
return stream >> pair.first >> pair.second;
}
template<class T, class U>
inline void input(std::pair<T,U>& pair, const bool first = true, const bool second = true) {
if(first) std::cin >> pair.first;
if(second) std::cin >> pair.second;
}
#pragma endregion
#pragma region DEBUG
#ifdef _DEBUG
#define debug(x) do{std::cout << #x << ": ";view(x);}while(0);
#else
#define debug(x)
#endif
template<class T> inline void view(const T& x) {
std::cout << x << std::endl;
}
template<class T> inline void view(const std::vector<T>& v) {
print(all(v));
}
#pragma endregion
#pragma endregion
signed main() {
int n;
std::cin >> n;
long double ans = 0;
for(int i = n-1;i>=1;i--) ans+=(double)n/i;
std::cout << std::fixed << std::setprecision(10) << ans << std::endl;
return 0;
} | #pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define setbits(n) __builtin_popcountll(n)
#define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin());
const ll mod=1e7+7;
const int N=1e5+10;
double dp[N];
bool vis[N];
ll n;
double go(ll pos){
if(pos==n) return 0;
if(vis[pos])
return dp[pos];
vis[pos]=true;
ll ans=0;
dp[pos] = (double)((double)1 + (double)pos/n*go(pos+1)) / ((double)pos/n);
return dp[pos];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll T=clock();
cin>>n;
cout<<fixed<<setprecision(10);
cout<<go(1);
cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
T = clock();
return 0;
} |
#include <bits/stdc++.h>
#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 sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
ll h,w;
vector<vector<char>> t(2010,vector<char>(2010));
int roty[2]={1,0},rotx[2]={0,1};
int main(void){
cin>>h>>w;
rep(i,h)rep(j,w){
cin>>t[i][j];
}
vector<vector<ll>> d(h,vector<ll>(w,0));
for(int y=h-1;y>=0;y--){
for(int x=w-1;x>=0;x--){
ll tot=-1e9;
if(y==h-1&&x==w-1){
d[y][x]=0;
continue;
}
rep(k,2){
ll ny=y+roty[k],nx=x+rotx[k];
if(ny<0||ny>=h||nx<0||nx>=w)continue;
ll buf=(t[ny][nx]=='+')? 1:-1;
buf-=d[ny][nx];
chmax(tot,buf);
}
d[y][x]=tot;
}
}
ll res=d[0][0];
if(res>0)cout<<"Takahashi"<<endl;
else if(res==0)cout<<"Draw"<<endl;
else cout<<"Aoki"<<endl;
} | #include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define endl '\n'
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define Pi 3.14159265358979
#define A first
#define B second
typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector<ll> vl;
typedef pair <int, int> pi;
typedef pair <ll, int> pl;
typedef pair <ll, ll> pll;
typedef pair <double, double> pd;
//change these according to prob constraints
const int INF = 0x3f3f3f3f;
const int MAX = 100005;
const int MAX1 = 1005;
const int MAX2 = 105;
const int LEN = 105;
const int BASE = 1000000000;
const double EPS = 1e-7;
const int MOD = 1000000007;
//g++ -std=c++11 your_file.cpp -o your_program
ll mypow(ll a, ll b){
ll ans=1;
while(b){
if(b&1)
ans=(ans*a)%MOD;
b/=2;
a=(a*a)%MOD;
}
return ans;
}
string x;
ull m;
bool solve(ull mid){
ull curr = 0;
ull pow = 1;
RREP(i, SZ(x)){
if (pow > m) return 0;
curr += (ull)((ull)x[i] - '0') * pow;
if (curr > m) return 0;
pow = pow * mid;
}
return 1;
}
int main(void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ifstream in("");
ofstream out("");
clock_t begin = clock();
cin >> x >> m;
if (SZ(x) == 1){
if (stoll(x) > m){
cout << 0 << endl;
}
else cout << 1 << endl;
return 0;
}
int d = 0;
REP(i, SZ(x)){
d = max(d, (int)x[i] - '0');
}
ull lo = d + 1, hi = 10e18, mid, ans = d;
while (lo <= hi){
mid = (lo + hi) / 2;
if (solve(mid)){
lo = mid + 1;
ans = max(ans, mid);
}
else hi = mid - 1;
}
cout << ans - d << endl;
clock_t end = clock();
double esecs = double(end - begin) / CLOCKS_PER_SEC;
//cout << esecs << " seconds" << endl;
return 0;
} |
#include<bits/stdc++.h>
//#include <atcoder/all>
#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define ALL(a) (a).begin(),(a).end()
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int)x.size())
using namespace std;
//using namespace atcoder;
using ld = long double;
using ll = long long;
//using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
//using mint = modint998244353;
const ll ZER = 0;
const ll MOD = 998244353 ;
// UnionFind木(サイズ持ち)
class UnionFind {
public :
vector<int> par;
UnionFind(int N){
par = vector<int>(N, -1);
}
int parent(int x){
return par[x];
}
int root(int x){
if(par[x] < 0)return x;
return par[x] = root(par[x]);
}
int size(int x){
return -par[root(x)];
}
void merge(int x, int y){
int rx = root(x);
int ry = root(y);
if(rx == ry)return;
if(size(rx) < size(ry))swap(rx, ry);
par[rx] += par[ry];
par[ry] = rx;
return;
}
bool same(int x, int y){
return root(x) == root(y);
}
};
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, K;
cin >> n >> K;
vector<ll> fac(1001, 1);
REP(i, 2, 1000){
fac[i] = fac[i - 1] * i;
fac[i] %= MOD;
}
vector<vector<int>> a(n, vector<int>(n));
rep(i, n)rep(j, n)cin >> a[i][j];
UnionFind uf1(n), uf2(n);;
rep(i, n){
REP(j, i + 1, n - 1){
bool f = true;
rep(k, n){
if(a[i][k] + a[j][k] > K)f = false;
}
if(f)uf1.merge(i, j);
}
}
rep(i, n){
REP(j, i + 1, n - 1){
bool f = true;
rep(k, n){
if(a[k][i] + a[k][j] > K)f = false;
}
if(f)uf2.merge(i, j);
}
}
ll tate = 1;
vector<bool> se1(n, false);
rep(i, n){
if(se1[uf1.root(i)])continue;
tate *= fac[uf1.size(i)];
tate %= MOD;
se1[uf1.root(i)] = true;
}
ll yoko = 1;
vector<bool> se2(n, false);
rep(i, n){
if(se2[uf2.root(i)])continue;
yoko *= fac[uf2.size(i)];
yoko %= MOD;
se2[uf2.root(i)] = true;
}
ll res = tate * yoko % MOD;
cout << res << endl;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 998244353;
const int N = 55;
int n, k, a[N][N], fac[N], far[N], s1[N], s2[N], flag[N];
ll ans = 1;
int find1(int x) {
return far[x] == x ? x : far[x] = find1(far[x]);
}
int find2(int x) {
return fac[x] == x ? x : fac[x] = find2(fac[x]);
}
int main() {
cin>>n>>k;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) cin>>a[i][j];
for (int i = 1; i <= n; i++) far[i] = fac[i] = i, s1[i] = s2[i] = 1;
for (int r1 = 1; r1 <= n; r1++)
for (int r2 = r1 + 1; r2 <= n; r2++) {
bool flag = true;
for (int j = 1; j <= n; j++)
if (a[r1][j] + a[r2][j] > k) flag = false;
if (flag)
if (find1(r1) != find1(r2)) s1[find1(r2)] += s1[find1(r1)], far[find1(r1)] = find1(r2);
}
for (int c1 = 1; c1 <= n; c1++)
for (int c2 = c1 + 1; c2 <= n; c2++) {
bool flag = true;
for (int i = 1; i <= n; i++)
if (a[i][c1] + a[i][c2] > k) flag = false;
if (flag)
if (find2(c1) != find2(c2)) s2[find2(c2)] += s2[find2(c1)], fac[find2(c1)] = find2(c2);
}
for (int i = 1; i <= n; i++)
if (!flag[find1(i)]) {
flag[find1(i)] = 1;
for (int j = 2; j <= s1[find1(i)]; j++)
ans = ans * j % mod;
}
for (int i = 1; i <= n; i++) flag[i] = 0;
for (int i = 1; i <= n; i++)
if (!flag[find2(i)]) {
flag[find2(i)] = 1;
for (int j = 1; j <= s2[find2(i)]; j++)
ans = ans * j % mod;
}
cout<<ans;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#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 REP(i,a,b) for(int i = (a); i < (b); i++)
#define MOD 1000000007
// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
seen[v] = true; // v を訪問済にする
// v から行ける各頂点 next_v について
for (auto next_v : G[v]) {
if (seen[next_v]) continue; // next_v が探索済だったらスルー
dfs(G, next_v); // 再帰的に探索
}
}
int N;
vector<vector<int>> es;
vector<int> A,B;
vector<int> depth;
vector<ll> dp;
void DepthDFS(int a, int d) {
depth[a]=d;
for (int next : es[a]) {
if(depth[next]==-1) {
DepthDFS(next,d+1);
}
}
}
void ImosDFS(int a, long now) {
now += dp[a];
dp[a] = now;
for (int next : es[a]) {
if(depth[next] > depth[a]) {
ImosDFS(next,now);
}
}
}
int main(void) {
cin >> N;
es.resize(N);
A.resize(N);
B.resize(N);
depth.resize(N,-1);
dp.resize(N,0);
rep(i,N-1) {
cin >> A[i] >> B[i];
A[i]--; B[i]--;
es[A[i]].push_back(B[i]);
es[B[i]].push_back(A[i]);
}
DepthDFS(0,0);
int Q;
cin >> Q;
rep(i,Q) {
int t,e,x;
cin >> t >> e >> x;
e--;
int va,vb;
if (t==1) {
va = A[e];
vb = B[e];
} else {
va = B[e];
vb = A[e];
}
if(depth[va] < depth[vb]) {
dp[0] += x;
dp[vb] -= x;
} else {
dp[va] += x;
}
}
ImosDFS(0,0);
rep(i,N) {
cout << dp[i] << endl;
}
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 2e5;
vector<int> adj[MAXN];
int par[MAXN];
int nbSommets;
int id[MAXN];
bool onPath[MAXN];
int cnt;
int getFurthest(int source) {
vector<int> dis(nbSommets, -1);
dis[source] = 0;
queue<int> q;
q.push(source);
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto v : adj[u])
if (dis[v] == -1) {
dis[v] = dis[u] + 1;
par[v] = u;
q.push(v);
}
}
int sol = 0;
for (int i(0); i < nbSommets; ++i)
if (dis[i] > dis[sol])
sol = i;
return sol;
}
void dfs(int u, int p) {
id[u] = ++cnt;
for (auto v : adj[u])
if (v != p and !onPath[v])
dfs(v, u);
for (auto v : adj[u])
if (v != p and onPath[v])
dfs(v, u);
++cnt;
}
signed main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> nbSommets;
for (int i = 0; i < nbSommets - 1; ++i) {
int u, v;
cin >> u >> v;
--u, --v;
adj[u].push_back(v);
adj[v].push_back(u);
}
int s = getFurthest(0);
int t = getFurthest(s);
while (1) {
onPath[t] = true;
if (t == s)
break;
t = par[t];
}
dfs(s, s);
for (int i = 0; i < nbSommets; ++i) {
cout << id[i] << ' ';
}
cout << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main(void) {
int x;
cin >> x;
int ans = x >= 0 ? x : 0;
cout << ans << endl;
}
| #include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define MX 100005
#define inf INT_MAX
#define mod 1000000007
#define endl "\n"
#define W(t) while(t--)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define all(v) v.begin(),v.end()
#define clr(a,x) memset(a,x,sizeof(a))
#define rep(i,a,b) for(i = a; i <= b; i++)
#define irep(i,b,a) for(i = b; i >= a; i--)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template <typename T> using ordered_set =
tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;
int main()
{
IOS
ll n,x;
string s;
cin >> x;
cout << (x < 0?0:x);
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
#define sz(a) int((a).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define inin(a, n, i) memset(a, i, sizeof(a[0])*(n))
#define contains(c, i) ((c).find(i) != (c).end())
#define present(i, c) (find(all(c), i) != (c).end())
#define trav(x, c) for(auto& x : c)
#define rep(i, n) for(int i = 0; i < n; i++)
#define repa(i, b, e) for(int i = (b)-((b)>(e)); i != (e)-((b)>(e)); i += 1-2*((b)>(e)))
template<class T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; }
template<class T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; }
template<class A, class B> A cvt(B x) { stringstream s; s << x; A r; s >> r; return r; }
void read() {}
void print() {}
template<class T, class... Args> void read(T& a, Args&... args) { cin >> a; read(args...); }
template<class T, class... Args> void print(T a, Args... args) { cout << a << ' '; print(args...); }
template<class... Args> void println(Args... args) { print(args...); cout << '\n'; }
#define debug(args...) { string s_(#args); replace(all(s_), ',', ' '); stringstream ss_(s_); istream_iterator<string> it_(ss_); cerr_(it_, args); }
void cerr_(istream_iterator<string> it) { (void) it; }
template<class T, class... Args> void cerr_(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; cerr_(++it, args...); }
template<class T, class S> ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<class T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<class T, class S> ostream& operator<<(ostream &os, const map<T, S> &m) { os << '{'; string sep; for (const auto &x : m) os << sep << x, sep = ", "; return os << '}'; }
template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
const int INF = 0x3F3F3F3F;
const int MAXN = (int) 1e6;
const int MOD = (int) 1e9+7;
//=========================
void run_test() {
int n; read(n);
vi a(n), b(n);
rep(i, n) read(a[i], b[i]);
int ans = INF;
rep(i, n) repa(j, i + 1, n) chkmin(ans, max(a[i], b[j])), chkmin(ans, max(a[j], b[i]));
rep(i, n) chkmin(ans, a[i] + b[i]);
println(ans);
}
//=========================
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
//int t_ = 1, t__; cin >> t__; while(t_ <= t__) { cout << "Case #" << t_++ << ": "; run_test(); }
// int t_; cin >> t_; while(t_--) run_test();
run_test();
return 0;
}
| #include<iostream>
using namespace std;
//n是电量上线,m是到咖啡馆的次数,t是归家时间,power是当前电量,a、b分别是进入、离开咖啡馆的次数
int n,m,t;
int power;
int a[1005],b[1005];
int main()
{
cin>>n>>m>>t;
//设定初始变量
power=n;
for(int i=1;i<=m;i++)//因为M是1000,最小,一定是用来用的
{
//读入a,b
cin>>a[i]>>b[i];
//求出上一次离开后花了多少电
int temp1=a[i]-b[i-1];
power=power-temp1;
if(power<=0)
{
cout<<"No";
return 0;
}
//然后加上充进去的电量
int temp2=b[i]-a[i];
power=min(power+temp2,n);
}
//加上归家路上耗费的电量
int tmp=t-b[m];
power=power-tmp;
if(power<=0)
{
cout<<"No";
return 0;
}
//如果没有在途中被“0”拦截,就不会有“0”
cout<<"Yes"<<endl;
return 0;
} |
/* 十 聖イシドールスよ、迷えるプログラマを導き給え! 十 */
/* 重ならないように置く でかい四角を縦線か横線で区切ったとき、2つの四角形にぶつからずに区切れるか? */
/* 1つのパターンで沢山区切れるので単純にやると重複が沢山出るが、
* 片方の四角形を基準に線を引いてそれで考えればよい */
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD(n) n=n%MOD;if(n < 0){n += MOD;}
int main()
{
ll N;
std::cin >> N;
std::vector<ll> A(N, 0);
ll ans = 0;
ll zahyo = 0;
ll all_mv = 0;
ll max_point = 0;
rep(i, N)
{
ll pre_all_mv = all_mv;
ll now = 0;
std::cin >> now;
// 一番動いた位置
ll max = zahyo + max_point;
ans = std::max(ans, max);
all_mv += now;
if(all_mv > max_point)
{
max_point = all_mv;
}
// 最後の位置
zahyo += pre_all_mv;
zahyo += now;
ans = std::max(ans, zahyo);
}
std::cout << ans;
return 0;
} | #include<bits/stdc++.h>
#include<iomanip>
/*
#include<atcoder/all>
using namespace atcoder;
*/
using namespace std;
#define REP(i,n) for(int i = 0;i < n;i++)
#define RNG(i,s,n) for(int i = s;i <= n;i++)
#define _RNG(i,e,s) for(int i = e;i >= s;i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define dup(x,y) (x + y - 1) / (y)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define lb(x,key) lower_bound(all(x) , (key))
#define ub(x,key) upper_bound(all(x) , (key))
#define _size(v) int((v).size())
#define prt(x) cout << x << '\n'
#define re return
#define re0 return 0
#define PQ(type) priority_queue<type>
#define PQD(type) priority_queue<type,vector<type>,greater<type>>
template<class T> bool chmax(T& a,T b){ if(a < b){ a = b; return true; }else return false; }
template<class T> bool chmin(T& a,T b){ if(a > b){ a = b; return true; }else return false; }
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using vpi = vector<pi>;
using vpl = vector<pl>;
#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a,b) cout<<"["<<#a<<","<<#b<<"] = "<<"["<<a<<","<<b<<"]\n"
#define debug3(a,b,c) cout<<"["<<#a<<","<<#b<<","<<#c<<"] = "<<"["<<a<<","<<b<<","<<c<<"]\n"
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
cout << "{"; for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i]; cout << "}";
return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
cout << "{\n"; for (auto& vec : arr)cout << " " << vec << ",\n"; cout << "}";
return out;
}
template<class S,class T> ostream &operator << (ostream& out, const pair<S,T>& p){
cout << "{" << p.first << "," << p.second << "}" << '\n';
return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
for (auto& i : arr)cin >> i; return in;
}
template<class S,class T> istream &operator >> (istream& in,pair<S,T>& p){
cin >> p.first >> p.second; return in;
}
#define F first
#define S second
/********************************************************************************/
/* BE CAREFUL : OVERFLOW / MIN&MAX OF THE CONSTRAINTS / INDEX LABELING!! */
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
//cout << fixed << setprecision(20);
int n;cin >> n;
vl a(n);cin >> a;
vl add(n),addmax(n);
REP(i,n){
if(i==0){
add[i] = a[i];
addmax[i] = a[i];
}else{
add[i] = add[i-1] + a[i];
if(add[i] > addmax[i-1]){
addmax[i] = add[i];
}else{
addmax[i] = addmax[i-1];
}
}
}
ll max_pos = 0;
ll cur = 0;
REP(i,n){
chmax(max_pos,cur + addmax[i]);
cur += add[i];
}
cout << max_pos << '\n';
return 0;
}
|
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using vb = vector<bool>;
using ll = long long; //約9.0*10^18
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll =vector<vvll>;
using std::reverse;
const double PI = 3.14159265358979323846;
const ll inf = 9223372036854775807;
const ll mod = 1000000007;
#define rep0(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
ll fac(ll n) {ll ans=1;rep0(i,n){ans=ans*(n-i);};return ans;}//n!
ll conb(ll n,ll m){return fac(n)/fac(m)/fac(n-m);}//nCm
//小数点以下を指定したい時 →→→→ cout << fixed << setprecision();
//int→string string str = to_string(num);
//string→int int num = atoi(numStr.c_str());
//複数のvector管理→;vector<tuple<string, int, int>> SP(N);
//int max = *max_element(all(A));最大値
//int min = *min_element(all(B));最小値
//floor(x)=[x]
// *max_element(a.begin(),a.begin()+5);aの最初から6番目までの最大値/計算量に不安あり
// *min_element(,);
// sort は昇順12345
//普通の割り算がしたい→cout<<(double)3/2/2<<endl;
//ll A = lower_bound(a,a+n,x) - a;xになった瞬間のi
//ll B = upper_bound(c,c+n,x) - c;xを超えた瞬間のi
//true=1,false=0
//ll n;cin>>n;vll a(n);rep0(i,n){cin>>a[i];}
int main() {
vll x(3);cin>>x[0]>>x[1]>>x[2];
sort(all(x));
cout<<x[1]+x[2]<<endl;
} | #include<bits/stdc++.h>
#define cpu() ios::sync_with_stdio(false); cin.tie(nullptr)
#define ps() cout << "\n"
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
using namespace std;
const int MOD = 1e9 + 7, MOD1 = (119 << 23) | 1;
const int INF = 1e9 + 5, MAX = 2e5 + 5;
int main(){
cpu();
int n; cin >> n;
string s, t; cin >> s >> t;
int ans = 0;
for(int id1 = 0, id2 = 0; max(id1, id2) <= n; id1++, id2++){
while(id1 < n && s[id1] == '1'){
id1++;
}
while(id2 < n && t[id2] == '1'){
id2++;
}
if((id1 == n) ^ (id2 == n)){
cout << "-1\n";
return 0;
}
ans += (id1 != id2);
}
cout << ans << "\n";
return 0;
} |
#define _USE_MATH_DEFINES
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
int n;
double x, y, x0, y0, x2, y2, xc, yc, d;
cin >> n >> x0 >> y0 >> x2 >> y2;
xc = (x0 + x2) / 2, yc = (y0 + y2) / 2;
x = x0 - xc, y = y0 - yc;
d = M_PI / (n / 2);
cout << setprecision(10) << fixed;
cout << xc + x * cos(d) - y * sin(d) << " " << yc + x * sin(d) + y * cos(d);
return 0;
} | #include <bits/stdc++.h>
#define N 200005
#define M 400005
#define inf 1e18
#define mp make_pair
#define int long long
using namespace std;
int n,m;
int head[N],v[M],C[M],D[M],nxt[M],tot;
priority_queue<pair<int,int> > q;
int dis[N];
bool vis[N];
int read()
{
int 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<<1)+(x<<3)+(c^48);
c=getchar();
}
return x*f;
}
inline void add(int x,int y,int c,int d)
{
tot++;
v[tot]=y;
C[tot]=c;
D[tot]=d;
nxt[tot]=head[x];
head[x]=tot;
}
inline int Dij(int s)
{
for(int i=2;i<=n;i++) dis[i]=inf;
dis[s]=0;
q.push(mp(0,s));
while(!q.empty())
{
int x=q.top().second,s=q.top().first;q.pop();
if(x==n) return -s;
if(vis[x]) continue;
vis[x]=1;
for(int i=head[x];i;i=nxt[i])
{
if(dis[v[i]]>((dis[x]>floor(sqrt(D[i]+1))-1)?dis[x]+C[i]+(D[i]/(dis[x]+1)):floor(sqrt(D[i]+1))-1+C[i]+(D[i]/(floor(sqrt(D[i]+1))))))
{
dis[v[i]]=((dis[x]>floor(sqrt(D[i]+1))-1)?dis[x]+C[i]+(D[i]/(dis[x]+1)):floor(sqrt(D[i]+1))-1+C[i]+(D[i]/(floor(sqrt(D[i]+1)))));
q.push(mp(-dis[v[i]],v[i]));
}
}
}
return -1;
}
signed main()
{
n=read();
m=read();
int a,b,c,d;
for(int i=1;i<=m;i++)
{
a=read();
b=read();
c=read();
d=read();
//if(a==b) continue;
add(a,b,c,d);
add(b,a,c,d);
}
printf("%lld\n",Dij(1));
return 0;
} |
#include <iostream>
#include <algorithm>
using namespace std;
const int N=1010;
struct moun{
string name;
int high;
}Mou[N];
int n;
bool cmp(moun a,moun b){
return a.high>b.high;
}
int main(){
cin>>n;
for(int i=0;i<n;i++)
{
cin>>Mou[i].name;
cin>>Mou[i].high;
}
sort(Mou,Mou+n,cmp);
cout<<Mou[1].name;
return 0;
} | // Created by Kshitij Anand NSIT
#include <bits/stdc++.h>
//#include <ext/numeric>
//using namespace __gnu_cxx;
using namespace std;
#define int long long
#define pb push_back
#define P pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mp(a, b) make_pair(a, b)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define ps(x,y) fixed<<setprecision(y)<<x
#define db(x) cout<<#x<<" : "<<x<<endl
#define filler(arr, n) \
for (int i = 0; i < n; i++) \
cin >> arr[i];
#define filler2(arr, n , m) \
for (int i = 0; i < n; i++) \
for(int j=0; j<m; j++) \
cin >> arr[i][j];
const int N = 1e9 + 7;
inline int add(int a,int b) {return ((a%N)+(b%N))%N;}
inline int sub(int a,int b) {return ((a%N)-(b%N)+N)%N;}
inline int mul(int a,int b) {return ((a%N)*(b%N))%N;}
void solve(){
int n,a,b,c,k,m, ans=0, count=0, sum=0;
cin>>n;
vector<pair<int , string>> v(n);
for(int i=0; i<n; i++) {
string s;
cin>>s>>a;
v[i] = mp(a , s);
}
sort(all(v) );
cout<<v[sz(v )-2].S<<endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
// int t; cin>>t; while(t--)
{
solve();
}
return 0;
}
/*Things to do if you are stuck:-
1.Read the problem statement again, maybe you've read something wrong.
2.See the explanation for the sample input .
3.If the solution is getting too complex in cases where no. of submissions
are high ,then drop that idea because there is something simple which you are
missing.
4.Check for runtime errors if unexpected o/p is seen.
5.Check on edge cases before submitting.
6.Ensure that you have read all the inputs before returning for a test case.
7.Try to think of brute force first if nothing is striking.
8.Take more examples
9.Don't give up , maybe you're just one statement away!
*/
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> xn(n), yn(n);
for(int i=0; i<n; ++i) cin >> xn[i] >> yn[i];
int ans = 0;
for(int i=0; i<n-1; ++i) for(int j=i+1; j<n; ++j){
int dx = xn[j] - xn[i];
int dy = yn[j] - yn[i];
if(abs(dx) >= abs(dy)) ++ans;
}
cout << ans << endl;
} | // C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int x[1010], y[1010];
int main(){
// 1. 入力情報.
int N;
scanf("%d", &N);
rep(i, N) scanf("%d %d", &x[i], &y[i]);
// 2. 傾きが, -1 以上 かつ 1 以下 である(i, j) の 個数は?
int ans = 0;
rep(i, N){
repx(j, i + 1, N){
// 点 (x[i], y[i]) と (x[j], y[j]) を 通る直線の傾きは?
// -> a = (y[i] - y[j]) / (x[i] - x[j]) が -1 以上 かつ 1 以下.
if(abs(y[i] - y[j]) <= abs(x[i] - x[j])) ans++;
}
}
// 3. 出力.
printf("%d\n", ans);
return 0;
} |
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define MOD 1000000007
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define PI 3.14159265358979323846
int main()
{
double a, b;
scanf("%lf %lf", &a, &b);
printf("%lf\n", (a - b) * 100 / a);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using ld=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
using vp=vector<P>;
using vvp=vector<vp>;
const int inf=1e9+7;
const ll INF=9e18/2;
const long double PI = acosl(-1.0);
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;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
int main(){cout<<fixed<<setprecision(20);
ld a,b;
cin>>a>>b;
cout<<(1-b/a)*100<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <typename T> struct SegmentTree {
using F = function<T(T, T)>;
T n;
vector<T> d;
const F f;
const T e;
// 要素数, 操作関数, 単位元
SegmentTree(T m, F f, T e) : f(f), e(e) {
n = 1;
while (n < m) n *= 2;
d = vector<T>(2 * n, e);
}
void update(int i, T x) {
i += n;
d[i] = x;
while (i > 1) {
i /= 2;
d[i] = f(d[2 * i], d[2 * i + 1]);
}
}
// [a, b)
T query(int a, int b) { return query_sub(a, b, 1, 0, n); }
T query_sub(int a, int b, int k, int l, int r) {
// index k: [l, r)
if (r <= a || b <= l) return e;
if (a <= l && r <= b) return d[k];
T lv = query_sub(a, b, 2 * k, l, (l + r) / 2);
T rv = query_sub(a, b, 2 * k + 1, (l + r) / 2, r);
return f(lv, rv);
}
T get(int i) { return d[n + i]; }
};
int f(int x, int y) { return x ^ y; }
int main() {
int n, q;
cin >> n >> q;
SegmentTree<int> st(n, f, 0);
rep(i, n) {
int a;
cin >> a;
st.update(i, a);
}
rep(iq, q) {
int t, x, y;
cin >> t >> x >> y;
--x;
if (t == 1) {
st.update(x, st.get(x) ^ y);
} else {
printf("%d\n", st.query(x, y));
}
}
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
#define dbg(var) cout<<#var<<"="<<var<<" "
#define nl cout<<"\n"
#define fr(i,n) for(int i=0;i<n;i++)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(v) (int)(v.size())
#define int long long
#define kill(x) { cout << x << "\n"; return;}
const int N=3e5+100;
int B[N];
int sm(int i){int r=0;for(;i;i-=i&-i)r^=B[i];return r;}
void up(int i,int v){for(;i<N;i+=i&-i)B[i]^=v;}
int vid(int i){int r=B[i],z=i-(i&-i);for(i--;i!=z;i-=i&-i)r-=B[i];return r;}
int rsm(int l,int r){return sm(r)^sm(l-1);}
void solve(){
int n,m; cin >> n >>m ;
int x;
fr(i,n) { cin >> x; up(i+1,x);}
while(m--){
int t,y; cin >> t >> x >> y;
if(t & 1) {
up(x,y);
}
else cout << rsm(x,y) << "\n";
}
}
int32_t main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// int tst; cin >> tst; while(tst--)
{
solve();
}
} |
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define st first
#define nd second
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
template <class T> T read(T &a) {
a=0;char x=getchar();bool f=0;
for(;x<'0'||x>'9';x=getchar())f|=x=='-';
for(;x>='0'&&x<='9';x=getchar())a=(a<<3)+(a<<1)+x-'0';
if(f)a=-a;
return a;
}
using namespace std;
const int N = 1e5 + 5;
int a[N], b[N], n, m;
int main() {
read(n), read(m);
for (int i = 1; i <= n; ++i) {
read(a[i]);
}
for (int i = 1; i <= n; ++i) {
read(b[i]);
}
n++;
a[0] = b[0] = 0;
a[n] = b[n] = m + 1;
for (int i = n; i >= 1; --i) {
a[i] = a[i] - a[i - 1] - 1;
b[i] = b[i] - b[i - 1] - 1;
}
LL ans = 0;
for (int i = 1, j = 1; i <= n; ++i) {
if (!b[i]) continue;
while (!a[j]) j++;
int k = j, sum = 0;
while (sum < b[i] && j <= n) {
sum += a[j++];
}
if (sum != b[i]) {
puts("-1");
return 0;
}
ans += max(i - k, 0) + max(j - i - 1, 0);
}
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
#define int long long
using namespace std;
int n,k;
char dp[5005][5005],a[1000005];
int ddd[1000]={0};
char win(char a,char b){
if(a==b) return a;
if(a=='S'&&b=='P')
return a;
if(a=='P'&&b=='S')
return b;
if(ddd[a]>ddd[b])
return a;
else return b;
}
int getmod(int ppp,int n){
if(ppp%n==0)
return n;
else
return ppp%n;
}
int quick_power(int x,int y){
int res=1;
for(;y;y=y>>1,x=(x*x)%n)
if(y&1)
res=(res*x)%n;
return res;
}
signed main(){
ios::sync_with_stdio(false);
cin>>n>>k;
ddd['P']=2,ddd['R']=1,ddd['S']=0;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=n+1;i<=2*n;i++)
a[i]=a[i-n];
for(int i=1;i<=2*n;i++)
dp[i][0]=a[i];
for(int i=1;i<=k;i++){
for(int j=1;j<=n;j++)
dp[j][i]=win(dp[j][i-1],dp[getmod(j+quick_power(2,i-1),n)][i-1]);
for (int j=n+1;j<=2*n;j++)
dp[j][i]=dp[j-n][i];
}
cout<<dp[1][k]<<endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
unsigned long long N, t = 0;
cin >> N;
string S = "999";
if (N>999) t += N-999;
if (N>999999) t += N-999999;
if (N>999999999) t += N-999999999;
if (N>999999999999) t += N-999999999999;
if (N>999999999999999) t += N-999999999999999;
cout << t;
} | #include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <bitset>
using namespace std;
typedef long long ll;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll N;
cin >> N;
ll n = N;
ll d = 0;
while(n/1000 > 0) {
n /= 1000;
d++;
}
ll ans = 0;
ll base = pow(1000, d);
ans += d*(N - base + 1);
d--;
while(d > 0) {
ll base_next = pow(1000, d);
ans += d * (base - base_next);
d--;
base = base_next;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ts to_string
#define all(x) (x).begin(), (x).end()
#define dbg(a); cerr<<#a<<"="<< (a)<<endl;
#define dbg2(a,b); cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<endl;
#define dbgarr(a); for(int elem:a)cerr<<elem<<" ";cerr<<endl;
#define panic(); cout<<"we're fine"<<endl;
using namespace std;
int main()
{
int n;cin>>n;
if(n&1)
cout<<"Black"<<endl;
else
cout<<"White"<<endl;
}
| #include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)
int main() {
int N;
cin >> N;
vector<vector<int>> C(N, vector<int>(N, 0));
REP(i, N) {
REP(j, N) {
cin >> C[i][j];
}
}
int m = *min_element(C[0].begin(), C[0].end());
vector<int> A(N, 0), B(N, 0);
REP(i, N) B[i] = C[0][i] - m;
REP(i, N) A[i] = C[i][0] - B[0];
bool check = true;
REP(i, N) if (A[i] < 0) check = false;
REP(i, N) if (B[i] < 0) check = false;
REP(i, N) REP(j, N) if (C[i][j] != A[i] + B[j]) check = false;
if (check) {
cout << "Yes" << endl;
REP(i, N) cout << A[i] << " ";
cout << endl;
REP(i, N) cout << B[i] << " ";
cout << endl;
}
else {
cout << "No" << endl;
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using LD = long double;
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> void coutall(T v) { for(auto i = v.begin(); i != --v.end(); i++){cout << *i << " ";} cout << *--v.end() << endl; }
void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; }
void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; }
void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; }
ll myceil(ll a, ll b) { return (a + (b - 1)) / b; }
/*** mod int ***/
// const int mod = 1000000007;
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;
}
// for prime mod
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, 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];
}
}; //comb(2000005);
using vm = vector<mint>;
using vvm = vector<vm>;
void Main(){
int n, m, k; cin >> n >> m >> k;
//*
if(n == 1 && m == 1){
cout << k << endl;
return;
}
//*/
if(n == 1) swap(n, m);
mint ans = 0;
rep3(amax, 1, k){
mint a = (n > 1 ? ((mint)amax).pow(n) - ((mint)amax-1).pow(n) : 1);
mint b = (m > 1 ? ((mint)k-amax+1).pow(m) : 1);
ans += a * b;
//cout << amax << " " << a << " " << b << " " << ans << endl;
}
cout << ans << endl;
return;
}
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
} | //#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#include<string.h>
#define un unsigned
#define srd srand(time(0))
#define ll long long
#define con continue
#define gtc getchar()
#define ptc putchar
#define dou double
#define eps 0.00000000001
#define opr operator
#define cl(x,a) memset(x,a,sizeof(x))
#define fo0(i,k) for(i=fr[k];i;i=nx[i])
#define fo1(i,l,r) for(i=l;i<=r;i++)
#define fo2(i,l,r) for(i=l;i>=r;i--)
#define fo(i,n) for(i=1;i<=n;i++)
#define ret return
#define x first
#define cint const int
#define y second
#define opi(x) freopen(x,"r",stdin)
#define opo(x) freopen(x,"w",stdout)
#define tpl template<class T>
#define priq priority_queue
#define mp make_pair
#define use using namespace
#define WT while(T--)
#define pb push_back
#define sz size()
use std;
typedef pair<int,int> pii;typedef pair<int,ll> pil;typedef pair<ll,int> pli;typedef pair<ll,ll> pll;
namespace io
{
void _(int &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;}
void _(ll &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;}
void _(char &c){while((c=gtc)==' '||c=='\n');}void _(dou &c){scanf("%lf",&c);}void _(char *s){char c;while((c=gtc)!=EOF&&c!=' '&&c!=10)*s++=c;}
template<class t1,class t2>void _(t1 &a,t2 &b){_(a);_(b);}template<class t1,class t2,class t3>void _(t1 &a,t2 &b,t3 &c){_(a);_(b);_(c);}
template<class t1,class t2,class t3,class t4>void _(t1 &a,t2 &b,t3 &c,t4 &d){_(a);_(b);_(c);_(d);}
template<class t1,class t2,class t3,class t4,class t5>void _(t1 &a,t2 &b,t3 &c,t4 &d,t5 &e){_(a);_(b);_(c);_(d);_(e);}
void _p(dou k){printf("%.6lf",k);}void _p(char *c){for(;*c;ptc(*c++));}void _p(const char *c){for(;*c;ptc(*c++));}void _p(char c){ptc(c);}
tpl void _p0(T k){if(k>=10)_p0(k/10);ptc(k%10+'0');}tpl void _p(T k){if(k<0){ptc('-');_p0(-k);}else _p0(k);}tpl void __p(T k){_p(k);ptc(' ');}
tpl void _pn(T k){_p(k);ptc('\n');}template<class t1,class t2>void _p(t1 a,t2 b){__p(a);_pn(b);}
template<class t1,class t2,class t3>void _p(t1 a,t2 b,t3 c){__p(a);__p(b);_pn(c);}
template<class t1,class t2,class t3,class t4>void _p(t1 a,t2 b,t3 c,t4 d){__p(a);__p(b);__p(c);_pn(d);}
tpl void op(T *a,int n){int i;n--;fo(i,n)__p(a[i]);_pn(a[n+1]);}int gi(){int x;_(x);ret x;}ll gll(){ll x;_(x);ret x;}
}
int gcd(int a,int b){ret b?gcd(b,a%b):a;}void fcl(){fclose(stdin);fclose(stdout);}
void fop(const char *s){char c[256],d[256];cl(c,0);cl(d,0);strcpy(c,s);strcpy(d,s);opi(strcat(c,".in"));opo(strcat(d,".out"));}
int eq(dou a,dou b){return a+eps>=b&&b+eps>=a;}tpl void _ma(T &a,T b){if(a<b)a=b;}tpl void _mi(T &a,T b){if(a>b)a=b;}
cint N=1234567,EE=100000000,GG=1000000000,ima=2147483647,p=998244353;
use io;
int n,m,k,T;
int ksm(int a,int b)
{
if(!b)
return 1;
int t=ksm(a,b/2);
t=(ll)t*t%p;
return b%2?(ll)t*a%p:t;
}
int main()
{
int i,j,a1,a2;
_(n,m,k);
if(n+m==2)
_pn(k);
else if(n==1||m==1)
_pn(ksm(k,n+m-1));
else
{
int an=0;
//m=max(n,m);
//n=t;
fo(i,k)
an=(an+(ll)ksm(i,n)*(ksm(k-i+1,m)-ksm(k-i,m)+p))%p;
_pn(an);
}
}
|
#include<bits/stdc++.h>
using namespace std;
void dfs(int i,vector<int>k[],long int&c,bool v[]){
if(v[i]){
return;
}
v[i]=true;
c++;
for(auto &x: k[i]){
dfs(x,k,c,v);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,q,a,b;
cin>>n>>q;
vector<int>adj[10000];
for(int i=0;i<q;i++){
cin>>a>>b;
adj[a-1].push_back(b-1);
}
long int s=0;
long int c=0;
for(int i=0;i<n;i++){
c=0;
bool visited[n+1]={false};
dfs(i,adj,c,visited);
s+=c;
}
cout<<s;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define print(a) \
for (auto x : a) \
cout << x << " "; \
cout << endl
#define print_upto(a, n) \
for (ll i = 1; i <= n; i++) \
cout << a[i] << " "; \
cout << endl
#define take(a, n) \
for (ll i = 1; i <= n; i++) \
cin >> a[i];
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x, y) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << "\n"
#define watch3(x, y, z) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << " and " << (#z) << " is " << (z) << "\n"
void my_debugger(string s, int LINE_NUM)
{
cerr << endl;
}
template <typename start, typename... end>
void my_debugger(string s, int LINE_NUM, start x, end... y)
{
if (s.back() != ',')
{
s += ',';
cerr << "LINE(" << LINE_NUM << "): ";
}
int i = s.find(',');
cerr << s.substr(0, i) << " = " << x;
s = s.substr(i + 1);
if (!s.empty())
cerr << ", ";
my_debugger(s, LINE_NUM, y...);
}
#define debug(...) my_debugger(#__VA_ARGS__, __LINE__, __VA_ARGS__);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define null NULL
#define all(c) (c).begin(), (c).end()
#define allr(c) (c).rbegin(), (c).rend()
#define nl "\n"
#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define MOD 1000000007
#define inf 1e17
// cout << fixed << setprecision(15) << ans << nl;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> ppll;
const ll N = 200009;
void solve()
{
ll n, m, q;
cin >> n >> m >> q;
vl vn[n + 5];
for (ll i = 1; i <= n; i++)
{
ll w, v;
cin >> w >> v;
vn[i] = {w, v};
}
ll x[m + 5];
for (ll i = 1; i <= m; i++)
{
cin >> x[i];
}
while (q--)
{
ll l, r;
cin >> l >> r;
ll vis[n + 5] = {0};
vl avail;
for (ll i = 1; i < l; i++)
{
avail.pb(x[i]);
}
for (ll i = r + 1; i <= m; i++)
{
avail.pb(x[i]);
}
sort(all(avail));
ll ans = 0;
for (ll i = 0; i < avail.size(); i++)
{
// watch(i);
vl temp = {INT_MIN, -1ll}; //value, index
for (ll j = 1; j <= n; j++)
{
if (vis[j] == 1)
continue;
if (avail[i] >= vn[j][0] && temp[0] < vn[j][1])
{
temp[0] = vn[j][1];
temp[1] = j;
}
}
if (temp[1] != -1)
{
// watch2(temp[0], temp[1]);
vis[temp[1]] = 1;
ans += temp[0];
}
}
cout << ans << nl;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll T = 1;
// cin >> T;
while (T--)
{
solve();
}
return 0;
}
|
#include<bits/stdc++.h>
#define pii pair<int,int>
#define N 1000005
using namespace std;
int n,q,f[N];
inline int find(int x){return x==f[x]?x:f[x]=find(f[x]);}
map<int,int>mp[N];
int main()
{
scanf("%d%d",&n,&q);
for(int i=1,c;i<=n;++i)
{
scanf("%d",&c);
mp[i][c]=1;
f[i]=i;
}
while(q--)
{
int t,x,y;
scanf("%d%d%d",&t,&x,&y);
if(t==1)
{
x=find(x);y=find(y);
if(x!=y)
{
if(mp[x].size()<mp[y].size())swap(x,y);
for(pii p:mp[y])mp[x][p.first]+=p.second;
f[y]=x;
}
}
else printf("%d\n",mp[find(x)][y]);
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m, t[200200], p[200200];
ll a[200200], x[200200], ans[200200];
int find(int a){
if(a == p[a]) return a;
return p[a] = find(p[a]);
}
void merge(int a, int b){
a = find(a), b = find(b);
p[a] = b;
}
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n;
for(int i=1;i<=n;i++) cin >> a[i] >> t[i];
cin >> m;
for(int i=1;i<=m;i++) cin >> x[i], p[i] = i;
set<pair<ll, int>> s;
for(int i=1;i<=m;i++) s.insert({x[i], i});
ll pl = 0;
for(int i=1;i<=n;i++){
vector<set<pair<ll, int>>::iterator> v;
if(t[i] == 1){
pl += a[i];
}if(t[i] == 2){
auto it = s.upper_bound({a[i]-pl, n+1});
if(it != s.begin()){
it = prev(it);
for(auto u = s.begin(); u != it; u++){
merge((*u).second, (*next(u)).second);
v.push_back(u);
}
auto [x, y] = *it;
s.erase(it), s.insert({a[i]-pl, y});
}
}if(t[i] == 3){
auto it = s.lower_bound({a[i]-pl, 0});
if(it != s.end()){
for(auto u = prev(s.end()); u != it; u--){
merge((*u).second, (*prev(u)).second);
v.push_back(u);
}
auto [x, y] = *it;
s.erase(it), s.insert({a[i]-pl, y});
}
}
for(auto x : v) s.erase(x);
}
for(auto [x, y] : s) ans[y] = x;
for(int i=1;i<=m;i++) ans[i] = ans[find(i)];
for(int i=1;i<=m;i++) cout << ans[i]+pl << "\n";
} |
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int N = 25e5 + 100;
int dp[1<<20];
int p[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
void solve() {
int a,b;
cin>>a>>b;
dp[0]=1;
for (int i = a; i <=b; ++i) {
int res=0;
for (int j = 0; j < 20; ++j) {
if (i%p[j]==0) res|=1<<j;
}
for (int j = 0; j < 1 << 20; ++j) {
if (!(res&j)){
dp[j|res]+=dp[j];
}
}
}
int ans=0;
for (int k = 0; k < 1 << 20; ++k) {
ans+=dp[k];
}
cout<<ans<<"\n";
}
signed main() {
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--) {
solve();
}
return 0;
} | #include<iostream>
#include<vector>
#include<unordered_map>
#include<queue>
#include<string>
using namespace std;
using ll = long long;
ll dp[75][1<<20];
ll A, B;
vector<int> prime;
bool vis[100];
int state[100];
int main()
{
cin >> A >> B;
for(int i = 2; i <= B - A; ++i)
{
if(!vis[i])
{
prime.push_back(i);
for(int j = i + i; j <= B - A; j += i)
vis[j] = true;
}
}
const int prime_siz = prime.size();
for(ll i = A; i <= B; ++i)
{
ll cur = i;
for(int j = 0; j < prime_siz; ++j)
{
while(cur % prime[j] == 0)
{
cur /= prime[j];
state[i - A + 1] |= (1 << j);
}
}
}
dp[0][0] = 1;
for(int i = 0; i <= B - A; ++i)
{
for(int s = 0; s < (1 << prime_siz); ++s)
{
dp[i + 1][s] += dp[i][s];
if(!(state[i + 1] & s))
dp[i + 1][s | state[i + 1]] += dp[i][s];
}
}
ll res = 0;
for(int i = 0; i < (1 << prime_siz); ++i)
res += dp[B - A + 1][i];
cout << res << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
//bool vis[1000];
//int x[]={1,-1,0,0};
//int y[]={0,0,1,-1};
//int f=0;
//"'';
int main(){
ll n,k;
cin>>n>>k;
ll sum=3*n;
vector<vector<ll> > dp(4,vector<ll>(sum+1,0));
vector<vector<ll> > sm(4,vector<ll>(sum+1,0));
dp[0][0]=1;
for(int i=0;i<=sum;i++){
sm[0][i]=1;
}
for(int i=1;i<=3;i++){
for(int j=1;j<=sum;j++){
int mx=j-1;
int mn=max(0ll,j-n);
dp[i][j]=sm[i-1][mx];
if(mn>0){
dp[i][j]=dp[i][j]-sm[i-1][mn-1];
}
// cout<<i<<-1<<j<<-1<<dp[i][j]<<endl;
sm[i][j]+=sm[i][j-1]+dp[i][j];
}
}
int a;
for(int i=1;i<=sum;i++){
if(sm[3][i]>=k){
k=k-sm[3][i-1];
a=i;
break;
}
}
//cout<<k<<endl;
//cout<<a<<endl;
for(int i=3;i>=1;i--){
for(int j=1;j<=n;j++){
if(a-j>=0&&dp[i-1][a-j]>=k){
cout<<j<<" ";
a=a-j;
break;
}
else{
k=k-dp[i-1][a-j];
}
}
}
cout<<endl;
}
| #include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
cout<<x;
if(suc==1) cout<<'\n';
else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
for(int i=0;i<v.size();i++)
print(v[i],i==(int)(v.size())-1?suc:2);
}
#define int unsigned long long
const int maxn=3e6+7;
int sum[maxn];
int a[maxn];
signed main()
{
int n,k;
cin>>n>>k;
for(int i=3;i<=3*n;++i)
{
if(i<=n+2) sum[i]=sum[i-1]+(i-1)*(i-2)/2;
else if(i<=2*n) sum[i]=sum[i-1]+(i-2)*(2*n-i+1)/2+(3*n-i+2)*(i-n-1)/2;
else {
int p=3*n+3-i;
sum[i]=sum[i-1]+(p-1)*(p-2)/2;
}
}
sum[3*n+1]=1000000000000000000+1;
//cout<<sum[3*n]<<endl;
int L=3,R=3*n;
int s=-1;
while(L<=R)
{
int mid=L+R>>1;
if(sum[mid]<=k) s=mid,L=mid+1;
else R=mid-1;
}
//cout<<sum[4]<<endl;
if(sum[s]!=k) s++;
//print(s);
//cout<<k<<endl;
int tar=k-sum[s-1];
//cout<<tar<<endl;
int res=0,pre=0;
int beauty,taste;
for(int i=1;i<=n;++i)
{
if(s-i>2*n||s-i<2) continue;
if(s-i<=n+1) res+=s-i-1;
else res+=2*n-s+i+1;
if(res>=tar)
{
beauty=i;
taste=tar-pre;
break;
}
pre=res;
}
int ss=s-beauty;
if(ss<=n+1) ;
else taste=taste+ss-n-1;
cout<<beauty<<" "<<taste<<" "<<s-beauty-taste<<endl;
} |
#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
//#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
char cn[1200010];
char* ci = cn, * di = cn, ct;
//char tc[200002], *d1 = tc + 100000, *d2 = tc + 200000;
const char d[2] = "0";
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
fread(cn, 1, 1200010, stdin);
int T = 0;
while ((ct = *ci++) >= '0') T = T * 10 + ct - '0';
rep(t, T) {
int N = 0;
while ((ct = *ci++) >= '0') N = N * 10 + ct - '0';
memset(di, '0', N);
di += N;
memset(di, '1', N);
di += N;
*di++ = '0';
*di++ = '\n';
ci += 6 * N + 3;
}
fwrite(cn, 1, di - cn, stdout);
Would you please return 0;
} | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <iostream>
#include <fstream>
#include <chrono>
using namespace std;
void solve(int test, istream &in) {
int n;
string s[3];
in >> n >> s[0] >> s[1] >> s[2];
bool has[2] = { false, false };
for (int k = 0; k < 3; k++) {
has[s[k][0] - '0'] = true;
}
char start = 0;
if (!has[start])
start = 1;
string answer(2 * n + 1, '0');
answer[0] = '0' + start;
for (int i = 0; i < n; i++) {
answer[1 + i] = '1' - start;
answer[1 + n + i] = '0' + start;
}
printf("%s\n", answer.c_str());
}
int main(int argc, char* argv[])
{
#ifdef VLAD_LOCAL
//FILE *f = fopen("in.txt", "r");
ifstream f("in.txt");
auto start = std::chrono::steady_clock::now();
#else
//FILE *f = stdin;
istream &f = cin;
#endif
int tests = 1;
f >> tests;
for (int test = 0; test < tests; test++) {
solve(test, f);
}
#ifdef VLAD_LOCAL
auto end = std::chrono::steady_clock::now();
double seconds = (double)std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / 1000;
printf("%.3lf seconds\n", seconds);
#endif
return 0;
}
|
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
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; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
int main(){
int n;
cin>>n;
V<ll> l(n),r(n);
for(int i=0;i<2*n;i++){
if(i<n)cin>>l[i];
else cin>>r[i-n];
}
reverse(all(l));
ll ans=-inf,res=0;
priority_queue<ll,V<ll>,greater<ll>> a,b;
a.emplace(l[0]);
for(int i=1;i<n;i++){
a.emplace(l[i]);
b.emplace(r[i]);
if(a.top()<b.top()){
a.pop();
}else{
b.pop();
}
}
while(a.size()){
res+=a.top();
a.pop();
}
while(b.size()){
res+=b.top();
b.pop();
}
ans=res;
res=0;
b.emplace(r[0]);
for(int i=1;i<n;i++){
a.emplace(l[i]);
b.emplace(r[i]);
if(a.top()<b.top()){
a.pop();
}else{
b.pop();
}
}
while(a.size()){
res+=a.top();
a.pop();
}
while(b.size()){
res+=b.top();
b.pop();
}
cout<<max(ans,res)<<"\n";
} | #include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for (int i=0; i<(int)(n); i++)
#define REP(i, n) for (int i=1; i<=(int)(n); i++)
#define For(i, n, m) for (int i=(n); i<=(int)(m); i++)
#define ll long long
const ll INF=1LL<<60;
int main() {
string S;
cin >> S;
vector<int> a,b,c;
Rep(i,S.size()) {
char s=S.at(i);
if (s=='o') a.push_back(i);
if (s=='x') b.push_back(i);
if (s=='?') c.push_back(i);
}
int cnt = 0;
Rep(i,10) {
bool no=false;
Rep(I,b.size()) if(i==b.at(I)) no = true;
if (no) continue;
Rep(j,10) {
bool no=false;
Rep(I,b.size()) if(j==b.at(I)) no = true;
if (no) continue;
Rep(k,10) {
bool no=false;
Rep(I,b.size()) if(k==b.at(I)) no = true;
if (no) continue;
Rep(l,10) {
bool no=false;
Rep(I,b.size()) if(l==b.at(I)) no = true;
if (no) continue;
bool can=true;
Rep(I,a.size()) {
if (i!=a.at(I) && j!=a.at(I) && k!=a.at(I)&& l!=a.at(I)) can = false;
}
if (can) cnt++;
}
}
}
}
cout << cnt << endl;
} |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
int res = 1;
x = x % p;
while (y > 0)
{
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res % p;
}
int lcm(int a, int b)
{
return a / __gcd(a, b) * b;
}
void solve()
{
int n;
cin >> n;
int a[n];
ordered_set<int> se;
int ans = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
int g = se.order_of_key(a[i]);
ans += i - g;
se.insert(a[i]);
}
cout << ans << endl;
for (int i = 1; i < n; i++) {
ans += (n - a[i - 1] - 1) - a[i - 1];
cout << ans << endl;
}
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tc;
tc = 1;
#ifndef ONLINE_JUDGE
freopen("inputf.txt", "r", stdin);
freopen("outputf.txt", "w", stdout);
#endif
// cin >> tc;
while (tc--)
{
solve();
}
return 0;
} | // 解き直し.
// https://atcoder.jp/contests/abc190/editorial/631
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
LL a[303030];
// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT{
int n;
vector<T> d;
BIT(int n = 0) : n(n), d(n + 1) {}
void add(int i, T x = 1){
for(i++; i <= n; i += i & -i) d[i] += x;
}
T sum(int i){
T x = 0;
for(i++; i; i -= i & -i) x += d[i];
return x;
}
T sum(int l, int r){
return sum(r - 1) - sum(l - 1);
}
};
int main(){
// 1. 入力情報.
int N;
scanf("%d", &N);
rep(i, N) scanf("%lld", &a[i]);
// 2. 転倒数(数列 A) を 計算.
BIT<LL> ft(N + 1);
LL per = 0;
rep(i, N){
// 2-1. 位置 a[i] に, 1 を 加算.
ft.add(a[i], 1LL);
// 2-2. 区間[a[i] + 1, N] の 合計は?
LL t = ft.sum(a[i] + 1, N + 1);
// 2-3. 集計.
per += t;
}
// 3. 転倒数(数列 B) を 計算しながら出力.
LL ans = per;
rep(i, N){
// 3-1. 出力.
printf("%lld\n", ans);
// 3-2. 差分更新(※解説通り).
ans += (LL)(N - 1 - 2 * a[i]);
}
return 0;
} |
#include<bits/stdc++.h>
#define maxn 4000005
#define int long long
using namespace std;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
int vis[26],n,ans;
string s;
signed main() {
cin>>s;
n=s.size();
// vis[s[]]
for(int i=s.size()-1;i>=0;i--) {
if(i!=s.size()-1 && s[i]==s[i+1]) {
for(int j=0;j<=25;j++) {
if(j!=s[i]-'a') {
ans+=vis[j],vis[s[i]-'a']+=vis[j],vis[j]=0;
}
}
}
vis[s[i]-'a']++;
}
cout<<ans<<endl;
}
| #include<iostream>
#include<map>
#include<algorithm>
using namespace std;
const int BUF = 2005;
int nVal;
int val[BUF];
void read() {
cin >> nVal;
for (int i = 0; i < nVal; ++i) {
cin >> val[i];
}
}
int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
void work() {
int minV = *min_element(val, val + nVal);
map<int, int> divisor2gcd;
for (int loop = 0; loop < nVal; ++loop) {
int n = val[loop];
for (int i = 1; i * i <= n; ++i) {
if (n % i == 0) {
int divisor[] = {i, n / i};
for (int j = 0; j < 2; ++j) {
if (j == 1 && divisor[0] == divisor[1]) continue;
if (divisor[j] > minV) continue;
if (!divisor2gcd.count(divisor[j])) {
divisor2gcd[divisor[j]] = n / divisor[j];
} else {
divisor2gcd[divisor[j]] = gcd(n / divisor[j], divisor2gcd[divisor[j]]);
}
}
}
}
}
int cnt = 0;
for (map<int, int>::iterator it = divisor2gcd.begin(); it != divisor2gcd.end(); ++it) {
cnt += it->second == 1;
}
cout << cnt << endl;
}
int main() {
read();
work();
return 0;
}
|
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
//typedef vector<vector<int> > Graph;
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; }
const ll INF = 1e18;
#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T>
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template<typename T>
inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } }
template <typename T>
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
/*
S={2,3,5,7,11,13,17,19,}
dp[i][S]=i番目の数まで見た時に使った素数の集合がSであるような選び方の場合の数
dp[0][0]=1
ans:dp[b-a][j](jは任意)
今考えている数:m
dp[i+1][S|(mの素因数)](mの素因数とSのbitがかぶっている時は遷移しない)
*/
/* divisor(n)
入力:整数 n
出力:nのすべての約数
計算量:O(√n)
*/
vector<ll>divisor(ll n){
vector<ll>ret;
for(ll i=1;i*i<=n;i++){
if(n%i==0){
ret.push_back(i);
if(i*i!=n)ret.push_back(n/i);
}
}
sort(ret.begin(),ret.end());
return ret;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll a,b;
cin >> a >> b;
vector<ll>prime;
for(int i=1;i<=b-a;i++){
if(divisor(i).size()==2)prime.push_back(i);
}
ll psz = prime.size();
vector<vector<ll> >dp(b-a+2,vector<ll>(1<<psz,0));
dp[0][0]=1;
map<ll,ll>mp;
for(ll m=a;m<=b;m++){
ll bit = 0;
rep(j,prime.size()){
if(m%prime[j]==0)bit|=(1<<j);
}
mp[m]=bit;
}
for(ll m=a;m<=b;m++){
rep(s,(1<<psz)){
ll i = m-a;
//if(__builtin_popcount(s)!=i)continue;
dp[i+1][s]+=dp[i][s];
ll bit = mp[m];
if((s^bit)!=(s|bit))continue;
dp[i+1][s|bit]+=dp[i][s];
}
}
//debug(dp);
cout << accumulate(dp[b-a+1].begin(),dp[b-a+1].end(),0) << endl;
return 0;
} | #include<stdio.h>
#define rep(i,N) for(long i=0;i<(long)N;i++)
const int d[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
static inline long IN(void)
{
long x=0,f=0,c=getchar();while(c<48||c>57){f^=(c==45),c=getchar();}
while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long x){if(x<0){putchar('-'),x=-x;}if(x>=10){OUT(x/10);}putchar(x%10+48);}
int bitdp[1<<20]={1};
int main(void)
{
long A=IN(),B=IN(),num=0,result=0;
rep(i,B-A+1)
{
num=0;
rep(j,20){if(((i+A)%d[j])==0){num+=(1<<j);}}
rep(j,1<<20){if(j&num){continue;}bitdp[j|num]+=bitdp[j];}
}
rep(i,1<<20){result+=bitdp[i];}
OUT(result);
} |
#include<bits/stdc++.h>
#define rint register int
#define ll long long
using namespace std;
int T;
string s="atcoder";
string S;
int main(){
cin>>T;
while(T--) {
cin>>S;
int len=S.length();
int ans=-1;
for(rint i=0;i<len;++i){
if(S[i]!='a') {ans=i;break;}
}
if(S>s) {
cout<<0<<"\n";
continue;
}
if(ans==-1) {
cout<<-1<<'\n';
}
else {
if(S[ans]>'t') ans--;
cout<<ans<<'\n';
}
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define pqb priority_queue<int>
#define pqs priority_queue<int,vi,greater<int> >
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x,y) cout<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) int x; cin>>x; while(x--)
#define pw(b,p) pow(b,p) + 0.1
#define endl "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void fastIO()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
void __print(int32_t x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
int C(int n,int r)
{
int ans=1;
for(int i=1;i<=r;i++)
{
ans*=n--;
ans/=i;
}
return ans;
}
bool valid(int n,auto &c,auto &t)
{
set<int> cused;
for(int i=0;i<4;i++)
{
int cur= n%10;
n/=10;
if(c.count(cur))
{
cused.insert(cur);
}
else if(t.count(cur))
{
}
else
{
return false;
}
}
return cused==c;
}
void solve()
{
string str;
cin>>str;
set<int> contained,ns;
for(int i=0;i<10;i++)
{
if(str[i]=='o') contained.insert(i);
else if(str[i]=='?') ns.insert(i);
}
int ans=0;
for(int i=0;i<=9999;i++)
{
if(valid(i,contained,ns)) ans++;
}
cout<<ans;
}
int32_t main()
{
fastIO();
//w(t)
{
solve();
cout<<endl;
}
return 0;
} |
#include <iostream>
#include <iomanip>
#include <vector>
#include <tuple>
#include <algorithm>
#include <unordered_set>
#include <cmath>
using ull = unsigned long long;
using ll = long long;
#define REP(i, n) for(ll i=0;i<(ll)n;i++)
constexpr bool bitp(ull bits, ull pos) { return bits & (1ULL << pos); }
struct shiki {
static constexpr ll limit = std::numeric_limits<ll>::max() / 4;
ll min = 10000000000000000;
ll max = -10000000000000000;
ll a = 0;
shiki(ll _a, ll t) {
switch (t)
{
case 1: a = _a; break;
case 2: max = _a; break;
case 3: min = _a; break;
}
}
void gousei(const shiki& sotogawa) {
if(sotogawa.min < 10000000000000000) min = std::min(min, sotogawa.min - a);
if(sotogawa.max > -10000000000000000) max = std::max(max, sotogawa.max - a);
a += sotogawa.a;
}
void gousei(ll _a, ll t) {
switch (t)
{
case 1: a += _a; max += _a; min += _a; break;
case 2: max = std::max(max, _a); min = std::max(min, _a); break;
case 3: min = std::min(min, _a); max = std::min(max, _a); break;
}
}
ll execute(ll x) {
return std::min(std::max(x + a, max), min);
}
void print() { std::cout << min << " " << max << " " << a << "\n"; }
};
int main() {
ull N, Q;
std::cin >> N;
shiki f(0,0);
REP(i, N) {
ll a, t;
std::cin >> a >> t;
f.gousei(a, t);
//f.gousei(shiki(a, t));
//f.print();
}
std::cin >> Q;
std::vector<ll> x(Q);
REP(i, Q) std::cin >> x[i];
REP(i, Q) std::cout << f.execute(x[i]) << "\n";
}
| // #pragma GCC target ("avx,avx2")
// #include <bits/extc++.h>
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define f first
#define s second
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
// typedef tree<int, null_type, less<int>,
// rb_tree_tag, tree_order_statistics_node_update> oset;
//========================================================
const int N = 1e5+5, K = 19, M = 5e4+5, mod = 1e9+7, len = 30, inf = 0x3f3f3f3f;
int n, m;
ll dist[N];
vector<pair<int, pair<ll, ll>>> adj[N];
void dijkstra(int src)
{
priority_queue<pair<ll, int>> q;
fill(dist, dist+n, 1e18);
q.push({0, src});
dist[src] = 0;
while(!q.empty())
{
auto t = q.top();
q.pop();
int u = t.s;
if(dist[u] != -t.f)
continue;
if(u == n-1)
break;
for(auto e : adj[u])
{
ll v = e.f, c = e.s.f, d = e.s.s;
auto dis = [&](ll T)
{
ll res = c + ll(d / (T + 1)) + T;
return res;
};
ll s = 1ll * sqrt(d) - 1;
s = max(s, 0LL);
if(dist[u] > s)
s = dist[u];
ll D = min(dis(s), dis(s+1));
// assert(D > 0);
if(dist[v] > D)
dist[v] = D, q.push({-D, v});
}
}
if(dist[n-1] == 1e18)
dist[n-1] = -1;
}
void run_case()
{
scanf("%d %d", &n, &m);
for(int i=0, u, v, c, d; i<m; i++)
{
scanf("%d %d %d %d", &u, &v, &c, &d);
adj[u-1].push_back({v-1, {c, d}});
adj[v-1].push_back({u-1, {c, d}});
}
dijkstra(0);
printf("%lld\n", dist[n-1]);
}
int main()
{
// ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);
int t;
t = 1;
// cin >> t;
while(t--)
run_case();
}
|
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define PI acos(-1)
typedef long long ll;
ll MOD=1000000007;
ll gcd(ll x,ll y){
if(y==0) return x;
else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
return x/gcd(x,y)*y;
}
using Graph=vector<vector<int>>;
int H=50,W=50;
bool seen[55][55];
int t[55][55];
int p[55][55];
const int dx[5]={-1,1,0,0,0};
const int dy[5]={0,0,-1,1,0};
set<int> tile;
int cnt=0;
bool f=true;
void dfs(int h,int w){
if(f==false){
return;
}
/*
cnt++;
if(cnt>55){
return;
}
*/
//cout<<h<<":"<<w<<":";
seen[h][w]=true;
tile.insert(t[h][w]);
//cout<<t[h][w]<<":"<<p[h][w]<<":"<<f<<endl;
for(int dir=0;dir<=4;++dir){
if(dir==4){
f=false;
return;
}
int nh=h+dx[dir];
int nw=w+dy[dir];
int newtile=t[nh][nw];
if(nh<0 || nh>=H || nw<0 || nw>=W) {
continue;
}
if(tile.find(newtile)!=tile.end()){
continue;
}
if(seen[nh][nw]==true){
continue;
}
if(dir==0 &&f){
cout<<"U";
}
else if(dir==1 &&f){
cout<<"D";
}
else if(dir==2 &&f){
cout<<"L";
}
else if(dir==3 &&f){
cout<<"R";
}
dfs(nh,nw);
}
}
int main(){
int si,sj;
cin>>si>>sj;
rep(i,H){
rep(j,W){
cin>>t[i][j];
}
}
rep(i,H){
rep(j,W){
cin>>p[i][j];
}
}
rep(i,55){
rep(j,55){
seen[i][j]=false;
}
}
dfs(si,sj);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
cin >> x >> y;
vector<vector<int>> t(50, vector<int> (50));
for (int i=0;i<50;i++) {
for (int j=0;j<50;j++) {
cin >> t[i][j];
}
}
vector<vector<int>> p(50, vector<int> (50));
for (int i=0;i<50;i++) {
for (int j=0;j<50;j++) {
cin >> p[i][j];
}
}
vector<int> jud(2510,0);
jud[t[x][y]]++;
while (true) {
if (x<49) {
if (jud[t[x+1][y]]==0) {
cout << "D";
x++;
jud[t[x][y]]++;
continue;
}
}
if (y>0) {
if(jud[t[x][y-1]]==0) {
cout << "L";
y--;
jud[t[x][y]]++;
continue;
}
}
if (y<49) {
if (jud[t[x][y+1]]==0) {
cout << "R";
y++;
jud[t[x][y]]++;
continue;
}
}
if (x>0) {
if(jud[t[x-1][y]]==0) {
cout << "U";
x--;
jud[t[x][y]]++;
continue;
}
}
break;
}
} |
#include <iostream>
#include <algorithm>
using namespace std;
string s;
int main(void) {
cin >> s;
bool flag = true;
for (int i = 0; i < s.size(); ++i) {
int j = s.size() - i - 1;
if (s[i] != s[j]) flag = false;
}
if (flag) {
cout << "Yes" << endl;
return 0;
}
int zero = 0;
for (int i = s.size() - 1; i >= 0; --i)
if (s[i] == '0') zero ++;
reverse(s.begin(), s.end());
while (zero--) s += '0';
for (int i = 0; i < s.size(); ++i)
if (s[i] != s[s.size() - i - 1]) {
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
bool check(string s){
int size = s.size();
bool flag = true;
for(int i=0;i < size/2;i++){
if(s.at(i) == s.at(size -i -1)) continue;
else flag = false;
}
return flag;
}
int main(){
int N;
cin >> N;
string s = to_string(N);
for(int i=0;i<10;i++){
if(check(s)){
cout << "Yes" << endl;
break;
}
s = '0' + s;
}
if(!check(s)){
cout << "No" << endl;
}
} |
#include<stdio.h>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define SIZE 5000000
ll inv[SIZE + 1];
ll kai[SIZE + 1];
ll invkai[SIZE + 1];
void invinit()
{
inv[1] = 1;
for (int i = 2; i <= SIZE; i++)
{
inv[i] = mod - (mod / i) * inv[mod % i] % mod;
}
kai[0] = invkai[0] = 1;
for (int i = 1; i <= SIZE; i++)
{
kai[i] = kai[i - 1] * i % mod;
invkai[i] = invkai[i - 1] * inv[i] % mod;
}
}
ll com(ll a, ll b)
{
if (b < 0 || a < b)return 0;
return (invkai[b] * invkai[a - b]) % mod * kai[a] % mod;
}
int main()
{
int n, m;
cin >> n >> m;
int s = n;
invinit();
for (int i = 0; i < n; i++)
{
int z;
cin >> z;
s += z;
}
ll r = 1;
if (n + m < s)
{
printf("0\n");
return 0;
}
for (int i = 0; i < s; i++)
{
r = r * inv[s - i] % mod;
r = r * (n + m - i) % mod;
}
printf("%lld\n", r);
} | #include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;
#define MAXN 200006
//#define int long long
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define all(x) (x).begin() , (x).end()
#define mem( a ) memset( a , 0 , sizeof a )
typedef long long ll;
const int P = 1e9 + 7;
int n , m;
int A[MAXN];
int Pow( int x , int a ) {
int ret = 1;
while( a ) {
if( a & 1 ) ret = ret * 1ll * x % P;
x = x * 1ll * x % P , a >>= 1;
}
return ret;
}
int C( int a , int b ) {
int ret = 1;
per( i , a , a - b + 1 ) ret = ret * 1ll * i % P;
rep( i , 1 , b ) ret = ret * 1ll * Pow( i , P - 2 ) % P;
return ret;
}
void solve() {
cin >> n >> m;
int sa = 0;
rep( i , 1 , n ) scanf("%d",A + i) , sa += A[i];
cout << C( m + n , sa + n ) << endl;
}
signed main() {
// freopen("input","r",stdin);
// int T;cin >> T;while( T-- ) solve();
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define mp make_pair
#define hello cout<<"hello"<<"\n"
#define forr(i,a,b) for(int i=a;i<b;i++)
#define it(s) for(auto itr:s)
#define dvg(s) for(auto itr:s) cout<<itr<<" ";cout<<endl;
#define dbg(s) cout<<#s<<"= "<<s<<endl;
typedef long long int lli;
typedef unsigned long long int ulli;
const lli INF=(lli)1e17+5;
const ulli MOD=1e9+7;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
std::cout<< std::fixed;
std::cout.precision(6);
lli b,c;
cin>>b>>c;
if(c==1 && b!=0) {cout<<"2\n";return 0;}
if(c<=2*b) {cout<<2*c-1<<"\n";return 0;}
if(b>0) {cout<<c+2*b-1<<"\n";return 0;}
else cout<<c+abs(b)*2<<"\n";
return 0;
}
| #include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef int64_t lint;
#define rep(i, n) for(int i=0; i<n; i++)
#define repx(i, l, n) for(int i=l; i<n; i++)
#define all(v) v.begin(), v.end()
#define show(x) cout << #x << ": " << x << endl;
#define list(x) cout << #x << ": " << x << " ";
#define pb push_back
using vi = vector<lint>;
using vvi = vector<vector<lint>>;
template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(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; }
template<class T> inline void drop(T x) { cout << x << endl; exit(0); }
template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }
constexpr lint LINF = LLONG_MAX/2;
int N, M, TIME=clock();
vector<pair<int, string>> V;
vi C(8);
int sum = 0;
vector<string> S(20);
int total() {
string s;
int p = 0;
set<string> t, u;
rep(i, M) t.insert(V[i].second);
vector<string> v(20);
rep(i, N) v[i] = S[i];
rep(q, 2) {
rep(i, N) {
s = v[i] + v[i];
for (auto a : t) {
bool f = false;
rep(j, N) {
if (a == s.substr(j, a.size())) {
f = true;
break;
}
}
if (f) p += a.size();
else u.insert(a);
}
t.clear();
swap(t, u);
}
rep(i, N) { v[i].clear(); rep(j, N) v[i] += S[j][i]; }
}
return p;
}
int delta(int a, int b, int x, int y) {
string s;
int p = 0;
set<string> t, u;
rep(i, M) t.insert(V[i].second);
rep(q, 2) {
s = S[a] + S[a];
for (auto a : t) {
bool f = false;
rep(j, N) {
if (a == s.substr(j, a.size())) {
f = true;
break;
}
}
if (f) p += a.size();
else u.insert(a);
}
t.clear();
swap(t, u);
swap(a, x);
}
rep(q, 2) {
s = "";
rep(i, N) s += S[i][b];
rep(i, N) s += S[i][b];
for (auto a : t) {
bool f = false;
rep(j, N) {
if (a == s.substr(j, a.size())) {
f = true;
break;
}
}
if (f) p += a.size();
else u.insert(a);
}
t.clear();
swap(t, u);
swap(b, y);
}
return p;
}
int main() {
cin >> N >> M;
string s;
rep(i, M) {
cin >> s;
V.pb({s.size(), s});
rep(j, s.size()) C[s[j]-'A']++;
}
rep(i, 8) sum += C[i];
rep(i, 7) C[i+1] += C[i];
sort(all(V));
int a=0, b=0, c=0, x, y, z;
rep(i, N) {
rep(j, N) {
x = rand()%sum;
rep(k, 8) {
if (x < C[k]) {
S[i] += 'A'+k;
break;
}
}
}
}
// show(total())
int count = 0;
while (true) {
count++;
a = rand()%N;
b = rand()%N;
x = rand()%N;
y = rand()%N;
c = delta(a, b, x, y);
swap(S[a][b], S[x][y]);
z = delta(a, b, x, y);
if (c > z) swap(S[a][b], S[x][y]);
// list(c)list(z) show(total())
if (clock()-TIME > 2.9 * CLOCKS_PER_SEC) break;
}
// show(count)
rep(i, N) std::cout << S[i] << '\n';
}
|
//#include <atcoder/maxflow.hpp>
#include <memory>
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
#include <complex>
#include <thread>
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
typedef long long ll;
using namespace std;
//using namespace atcoder;
ll modd = (1000LL * 1000LL * 1000LL + 7LL);
//ll modd = 998244353;
int main() {
ios_base::sync_with_stdio(false);
cout.precision(17);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<int> rand_gen(0, modd); // rand_gen(rng) gets the rand no
auto start = chrono::steady_clock::now();
// readint(test_cases);
int test_cases = 1;
forr(t, 1, test_cases) {
readint(n);
int ct = 0;
forr(i,1,n) {
bool has7 = false;
int nn = i;
while (nn>0) {
if (nn%10==7) {has7=true;}
nn/=10;
}
nn = i;
while (nn>0) {
if (nn%8==7) {has7=true;}
nn/=8;
}
if (!has7) {
++ct;
}
}
cout << ct << endl;
}
// auto stop = chrono::steady_clock::now();
// auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
// cout << "Duration: " << duration.count() << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
long long f(long long n){
return (n-1)/3;
}
long long g(long long n){
long long ans=0;
while(n>0){
ans++;
n/=10;
}
return ans;
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int tt=1;
while(tt--){
long long n,d,i,ans=0; cin>>n;
d=(long long)pow(10,g(n)-1);
for(i=1;i<g(n);i++){
ans+=(long long)pow(10,i-1)*9*f(i);
}
ans+=(n-d+1)*f(i);
cout<<ans;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
void solve() {
ll n;
cin >> n;
ll p = (n + 1) * 2;
ll x = sqrt(p);
if (x * (x + 1) / 2 > n + 1) {
x--;
}
dump(n+1, x, x*(x+1)/2);
cout << n - x + 1 << endl;
// cout << c << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
// freopen("temp.1", "r", stdin);
solve();
return 0;
} | //#include <bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<unordered_map>
#include<queue>
#define INF 0x3f3f3f3f
#define ll long long
#define LL long long
#define ull unsigned long long
#define endl '\n'
#define ios ios::sync_with_stdio(false);
#define open freopen("in.in","w",stdout);
using namespace std;
const int maxn = 1e5 + 10;
const ll mod = 1e9 + 7;
int main() {
int n;
cin>>n;
int ans = 100 - n%100;
cout<<ans<<endl;
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.