code_file1
stringlengths 80
4k
| code_file2
stringlengths 91
4k
| similar_or_different
int64 0
1
|
---|---|---|
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
LL f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
if(x<0){putchar('-');x=-x;}
if(!x){putchar('0');return;}
int top=0;
while(x)stack[++top]=x%10,x/=10;
while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int mod=998244353;
const int MAXN=3000005;
int pre[MAXN],inv[MAXN];
int C(int n,int m)
{
if(n<m)return 0;
return 1LL*pre[n]*inv[m]%mod*inv[n-m]%mod;
}
int n,m;
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
void dl(int &x,int y){x-=y;if(x<0)x+=mod;}
int pow_mod(int a,int b)
{
int ret=1;
while(b)
{
if(b&1)ret=1LL*ret*a%mod;
a=1LL*a*a%mod;b>>=1;
}
return ret;
}
int main()
{
pre[0]=1;for(int i=1;i<MAXN;i++)pre[i]=1LL*pre[i-1]*i%mod;
inv[MAXN-1]=pow_mod(pre[MAXN-1],mod-2);
for(int i=MAXN-2;i>=0;i--)inv[i]=1LL*inv[i+1]*(i+1)%mod;
n=read();m=read();
int ans=0;
for(int i=0;i<=m;i++)
if(!((3*m-i)&1))
ad(ans,1LL*C(n,i)*C(((3*m-i)>>1)+n-1,n-1)%mod);
// dl(ans,1LL*n*C(m-2+n-1,n-1)%mod);
dl(ans,1LL*n*C(m-1+n-1,n-1)%mod);
pr2(ans);
return 0;
}
| #include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<LL,int> pa;
typedef vector<int> vec;
void getint(int &v){
char ch,fu=0;
for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
if(ch=='-') fu=1, ch=getchar();
for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
if(fu) v=-v;
}
const LL INF=1e18;
int n,D,a[500010];
bool u[500010];
LL ans;
struct node{
pa v[2][2]; //[in MST now];[use + -]
pa t;
node(){
v[0][0]=v[0][1]=v[1][0]=v[1][1]=mp(INF,0);
t=mp(INF,0);
}
}T[800010];
void pushup(int rt){
T[rt].t=min(T[rt<<1].t,T[rt<<1|1].t);
T[rt].t=min(T[rt].t,mp(T[rt<<1].v[0][0].fi+T[rt<<1|1].v[1][1].fi,T[rt<<1].v[0][0].se));
T[rt].t=min(T[rt].t,mp(T[rt<<1].v[1][0].fi+T[rt<<1|1].v[0][1].fi,T[rt<<1|1].v[0][1].se));
T[rt].v[0][0]=min(T[rt<<1].v[0][0],T[rt<<1|1].v[0][0]);
T[rt].v[0][1]=min(T[rt<<1].v[0][1],T[rt<<1|1].v[0][1]);
T[rt].v[1][0]=min(T[rt<<1].v[1][0],T[rt<<1|1].v[1][0]);
T[rt].v[1][1]=min(T[rt<<1].v[1][1],T[rt<<1|1].v[1][1]);
}
void build(int l,int r,int rt){
if (l==r){
T[rt].v[u[l]][0]=mp(a[l]-1ll*l*D,l);
T[rt].v[u[l]][1]=mp(a[l]+1ll*l*D,l);
T[rt].v[u[l]^1][0]=mp(INF,0);
T[rt].v[u[l]^1][1]=mp(INF,0);
return;
}
int m=l+r>>1;
build(l,m,rt<<1);
build(m+1,r,rt<<1|1);
pushup(rt);
}
void upd(int l,int r,int rt,int x){
if (l==r){
T[rt].v[u[l]][0]=mp(a[l]-1ll*l*D,l);
T[rt].v[u[l]][1]=mp(a[l]+1ll*l*D,l);
T[rt].v[u[l]^1][0]=mp(INF,0);
T[rt].v[u[l]^1][1]=mp(INF,0);
return;
}
int m=l+r>>1;
if (x<=m) upd(l,m,rt<<1,x);
else upd(m+1,r,rt<<1|1,x);
pushup(rt);
}
void prim(){
build(1,n,1);
u[1]=1;
upd(1,n,1,1);
FOR(rp,2,n){
pa tmp=T[1].t;
ans+=tmp.fi;
u[tmp.se]=1;
upd(1,n,1,tmp.se);
}
}
int main(){
cin>>n>>D;
FOR(i,1,n) getint(a[i]);
prim();
printf("%lld\n",ans);
return 0;
}
| 0 |
#include <iostream>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
int n;
int p[100];
int main(){
cin >> n;
rep(i, n * (n - 1) / 2){
int a, b, c, d;
cin >> a >> b >> c >> d;
--a;
--b;
if(c == d){
--p[a];
--p[b];
}
else{
if(c < d){
swap(a, b);
}
p[a] -= 3;
}
}
vector<int> v(p, p + n);
sort(v.begin(), v.end());
rep(i, n){
cout << lower_bound(v.begin(), v.end(), p[i]) - v.begin() + 1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define INF 100000005
#define MAX 100001
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
pair<int,int> a[101];
int b[101];
bool comp(pair<int,int> x, pair<int,int> y){
return x.fi > y.fi;
}
int main(){
int n, m, t[4], p, s = INF;
scanf("%d", &n);
m = (n*(n-1))/2;
rrep(i,n)a[i].se = i;
rep(i,m){
rep(j,4)scanf("%d", &t[j]);
if(t[2] > t[3])a[t[0]].fi += 3;
if(t[2] < t[3])a[t[1]].fi += 3;
if(t[2] == t[3])a[t[0]].fi++, a[t[1]].fi++;
}
sort(a+1, a+n+1, comp);
for(int i = 1;i <= n;i++){
if(s > a[i].fi){
s = a[i].fi;
p = i;
}
a[i].fi = p;
b[a[i].se] = i;
}
rrep(i,n)printf("%d\n", a[b[i]].fi);
return 0;
} | 1 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main(){
int n, m;
cin >> n >> m;
vector<int> c(n+2);
rep(i,m){
int l, r;
cin >> l >> r;
c[l]++;
c[r+1]--;
}
rep(i,n+1) c[i+1] += c[i];
int ans = 0;
rep(i,n+1) if(c[i] == m) ans++;
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i< n; i++)
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; }
const long long INF = 1LL << 60;
#define PI 3.14159265359
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
vector.erase(vector.begin() + index);
}
int gcd(int a, int b){
if(b == 0) return a;
else return gcd(b, a%b);
}
long long lcm (int a, int b){
return (long long) a*b /gcd(a,b);
}
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
int main(){
int N, M;
cin >> N >> M;
int low = 0;
int high = N;
rep(i,M){
int a, b;
cin >> a >> b;
if(low<a)low = a;
if(b<high)high = b;
}
if(high-low<0)cout << 0 << endl;
else cout << high-low+1<< endl;
}
| 1 |
#include<functional>
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}
template <typename T>
class BIT {
// 1-indexed
private:
size_t node_size_;
T identity_;
function<T(T, T)> operation_;
function<T(T, T)> update_;
vector<T> node_;
public:
BIT(size_t node_size, T identity, function<T(T, T)> operation, function<T(T, T)> update):
node_size_(node_size), identity_(identity), operation_(operation), update_(update), node_(vector<T>(node_size + 1, identity)) {}
void change(int idx, T new_value) {
node_[idx] = update_(node_[idx], new_value);
while (idx <= (int)node_size_) {
idx += idx & -idx;
if (idx > (int)node_size_) {
break;
}
node_[idx] = operation_(node_[idx], new_value);
}
}
T query(int idx) {
T res = identity_;
while (idx > 0) {
res = operation_(res, node_[idx]);
idx -= idx & -idx;
}
return res;
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, Q;
cin >> N >> Q;
BIT<ll> bit(N, 0, [](ll a, ll b) {return a + b;}, [](ll a, ll b) {return a + b;});
ll a;
rep(i, 0, N) {
cin >> a;
bit.change(i + 1, a);
}
int q, p, l, r;
ll x;
rep(i, 0, Q) {
cin >> q;
if (q) {
cin >> l >> r;
cout << bit.query(r) - bit.query(l) << endl;
} else {
cin >> p >> x;
bit.change(p + 1, x);
}
}
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <atcoder/all>
using ll=long long;
using namespace std;
using namespace atcoder;
int main(){
int N,Q;
cin>>N>>Q;
fenwick_tree<ll> fw(N);
ll a;
for(int i=0;i<N;i++){
cin>>a;
fw.add(i,a);
}
int q,x,y;
for(int i=0;i<Q;i++){
cin>>q>>x>>y;
if(q){
cout<<fw.sum(x,y)<<endl;
}else{
fw.add(x,y);
}
}
return 0;
} | 1 |
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n,k,c[10],l[10],e[10000],d,a,b;
while(true){
cin>>n;
cin>>k;
if(n==0 && k==0){
break;
}
for(int i=0;i<n;i++){
cin>>c[i];
if(c[i]>=10){
l[i]=100;
}
else{
l[i]=10;
}
}
d=0;
if(k==2){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
b=0;
if(i!=j){
a=c[i]*l[j]+c[j];
for(int k=0;k<d;k++){
if(a==e[k]){
goto Exit1;
}
}
e[d]=a;
d++;
Exit1:
a=0;
}
}
}
}
if(k==3){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
for(int m=0;m<n;m++){
b=0;
if(i!=j && (j!=m && m!=i)){
a=c[i]*(l[j]*l[m])+c[j]*l[m]+c[m];
for(int k=0;k<d;k++){
if(a==e[k]){
goto Exit2;
}
}
e[d]=a;
d++;
Exit2:
a=0;
}
}
}
}
}
if(k==4){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
for(int m=0;m<n;m++){
for(int o=0;o<n;o++){
b=0;
if(((i!=j && o!=i) && (j!=m && m!=i)) && (o!=j && o!=m)){
a=c[i]*(l[j]*l[m]*l[o])+c[j]*(l[m]*l[o])+c[m]*l[o]+c[o];
for(int k=0;k<d;k++){
if(a==e[k]){
goto Exit3;
}
}
e[d]=a;
d++;
Exit3:
a=0;
}
}
}
}
}
}
std::cout<<d<<endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long // <-----!!!!!!!!!!!!!!!!!!!
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
int n, k;
set<string> st;
string a[10];
bool done[10];
void dfs(string s, int c) {
if (c == k) {
st.insert(s);
return;
}
rep(i, n) {
if (!done[i]) {
done[i] = true;
dfs(s + a[i], c + 1);
done[i] = false;
}
}
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
while (cin >> n >> k, n) {
rep(i, n) cin >> a[i];
st.clear();
fill(done, done + 10, false);
dfs("", 0);
cout << st.size() << endl;
}
} | 1 |
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
map<int, int> mp;
int main()
{
int n, k;
cin >> n >> k;
vector<int> x(n);
rep(i, n) cin >> x[i];
int lower, upper;
lower = 0;
upper = k - 1;
int ans = iINF, tmpans = iINF;
while (upper < n) {
tmpans = iINF;
if (x[lower] <= 0 && x[upper] <= 0) tmpans = abs(x[lower]);
else if (0 <= x[lower] && 0 <= x[upper]) tmpans = x[upper];
else {
tmpans = 2 * min(abs(x[lower]), abs(x[upper]));
tmpans += max(abs(x[lower]), abs(x[upper]));
}
if (tmpans < ans) ans = tmpans;
lower++;
upper++;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,k;cin>>n>>k;
vector<ll> x(n);rep(i,n)cin>>x[i];
ll ans = INF;
for(int i=0; i+k-1<n; i++){
ll l = x[i], r = x[i+k-1];
ll a;
if(r<0)a=-l;
else if(l<0)a=min(r-2*l, 2*r-l);
else a=r;
ans = min(ans, a);
}
cout<<ans<<endl;
return 0;
} | 1 |
/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 10000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL; // 2e18
const int inf = 0x3f3f3f3f; // 1061109567
const long double EPS = 1e-9;
//bitset<maxx/2>vis;
//bitset<maxx>pr;
//int mobi[maxx+10];
//vector<ll>prime;
//void sieve(){
// ll x=maxx/2, y=sqrt(maxx)/2;
// for(ll i=1;i<=y;i++){
// if(vis[i]==0){
// for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
// vis[j]=1;
// }
// }
// prime.push_back(2);
// for(ll i=3;i<maxx;i+=2)
// if(vis[i/2]==0)
// prime.push_back(i);
//}
//void generate_mobius()
//{
// for(int i=0;i<maxx;i++)mobi[i]=1;
// for(int i=2;i<maxx;i++){
// if(!pr[i]){
// mobi[i]*=-1;
// for(int j=i+i;j<maxx;j+=i){
// pr[j]=1;
// mobi[j]*=(j%(i*i)?-1:0);
// }
// }
// }
//}
//bool isprime(ll a)
//{
// if(a==1)return false;
// if(a==2)return true;
// if(a%2==0)return false;
// for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++)
// if(a%prime[i]==0)return false;
// return true;
//}
/*Used path compression technique*/
/*-------------------------------------*/
//ll finds(ll a)
//{
// vector<ll>vec;
// while(parent[a]>0){
// vec.pb(a);
// a=parent[a];
// }
// for(int i=0;i<vec.size();i++)parent[vec[i]]=a;
// return a;
//}
//void unions(ll a,ll b)
//{
// parent[a]+=parent[b];
// parent[b]=a;
//}
/*------------------------------*/
/* Calculate ( a*b ) %c */
inline ll mulmod(ll a, ll b, ll c) {
ll ret = 0 , cur = a % c ;
while(b) { if(b%2) ret=(ret+cur)%c; cur=(cur<<1)%c; b=b>>1; }
return ret%c;
}
//Calculate (b^p)%m || modular inverse: b^-1 = bigmod(b, m-2, m)
inline ll bigmod(ll b, ll p, ll m){
ll ret = 1, cur = b % m;
while(p) { if(p&1) ret=(ret*cur)%m; cur=(cur*cur)%m; p=p>>1; }
return ret;
}
inline ll modulo(ll a,ll b,ll c) { //Same as big mod, use for numbers over 1e10
ll ret = 1 , cur = a%c ;
while(b) { if(b%2) ret=mulmod(ret,cur,c); cur=mulmod(cur,cur,c); b=b>>1; }
return ret%c ;
}
inline ll power(ll b, ll p){
ll ret = 1, cur = b;
while(p) { if(p&1) ret=(ret*cur); cur=(cur*cur); p=p>>1; }
return ret;
}
ll lcm(ll a,ll b)
{
return (a/__gcd(a,b))*b;
}
ll gcd(ll a,ll b)
{
return __gcd(a,b);
}
ll arr[100];
void Dufaux()
{
ll n,k,sum=0;
cin>>n>>k;
for(int i=0;i<n;i++)cin>>arr[i];
sort(arr,arr+n,greater<ll>());
for(int i=0;i<k;i++)sum+=arr[i];
cout<<sum<<endl;
}
int main()
{
FastIO;
///sieve();
///generate_mobius();
int test=1;
while(test--){
Dufaux();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main()
{int N, K; cin >> N >> K;
int L[N]; for (int &l : L) cin >> l; sort(L, L + N);
cout << accumulate(L + N - K, L + N, 0);} | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MX = 1e10 + 10;;
unsigned long long fac[200001];
#include <math.h>
#define PI 3.14159265358979323846264338327950L
long long gcd(long long a, long long b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
long long lcm(long long a, long long b) {
return (a * b) / gcd(a, b);
}
long long digits(long long m) {
long long cnt = 0;
while (m) {
cnt++;
m /= 10;
}
return cnt;
}
unsigned long long power(unsigned long long x, unsigned long long y){
unsigned long long res = 1;
x = x % MOD;
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % MOD;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % MOD;
}
return res;
}
unsigned long long modInverse(unsigned long long n) {
return power(n, MOD - 2);
}
long long nCr(long long n, long long r) {
if (r > n) return 0;
return (fac[n] * modInverse(fac[r]) % MOD * modInverse(fac[n - r]) % MOD) % MOD;
}
long long bfs(vector<int> g, queue<int> q) {
return 1ll;
}
int main() {
int n, l;
cin >> n >> l;
vector<int> a(n);
long long sum = 0;
for (int i = 0; i < n; i++) {
a[i] = l + i;
sum += a[i];
}
int mn = 999999;
int pos = -1;
for (int i = 0; i < n; i++) {
if (abs(a[i]) < mn) {
mn = abs(a[i]);
pos = i;
}
}
sum -= a[pos];
cout << sum;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define pb push_back
#define bp __builtin_popcount
#define sz size()
#define ff first
#define ss second
#define vll vector<ll>
#define vbool vector<bool>
#define vpll vector<pair<ll,ll>>
#define pll pair<ll,ll>
#define vllv vector<vector<ll>>
#define setpri(x) cout<<setprecision(x)<<fixed;
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}
ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);
ll modinv(ll n,ll mod=MOD){ return pow1(n,mod-2,mod);}
bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
if(a.ff != b.ff)return a.ff < b.ff;
return a.ss > b.ss;
}
ll const N=(ll)3e2+11;
ll const LG=(ll)log2(N)+1;
void solve(){
ll i,j,k,l,n,m,x,y,z,r;
cin>>n>>l;
ll tt=0;
for(i=1;i<=n;i++){
tt+=l+i-1;
}
if(n==1){
cout<<0<<endl;
return;
}
ll ans=-100000;
for(i=1;i<=n;i++){
ll t1=tt-l+1-i;
if(abs(t1-tt)<abs(tt-ans)){
ans=t1;
}
}
cout<<ans<<endl;
}
int main(){
FS;
ll i,j,k,n,m,x,y,z,q;
q=1;
// cin>>q;
while(q--){
solve();
}
return 0;
}
ll pow1(ll n,ll m,ll mod){
if(m==0)return 1;
if(m%2==0)return pow1((n*n)%mod,m/2,mod);
return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}
ll pow2(ll n,ll k){
ll ans=1;
while(k>0){
if(k%2==1)ans=ans*n;
n=n*n;
k/=2;
}
return ans;
} | 1 |
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// std::cout << std::fixed << std::setprecision(15); //"for float-base
// problem"
string s, t;
int N;
cin >> N >> s >> t;
REP(i, N) {
if (s.substr(i, N - i) == t.substr(0, N - i)) {
cout << 2 * N - (N - i) << endl;
return 0;
}
}
cout << 2 * N << endl;
} | #include <stdio.h>
#include <algorithm>
int k, t;
int a[100];
int main() {
scanf("%d%d", &k, &t);
for (int i = 0; i < t; i++) {
scanf("%d", a + i);
}
std::sort(a, a + t);
k = k - a[t - 1];
k = a[t - 1] - k - 1;
if (k < 0)k = 0;
printf("%d\n", k);
} | 0 |
#include <iostream>
#include <set>
using namespace std;
int main() {
long long N, L[2]{};
cin >> N;
set<int> S;
while (cin >> N) {
if (!S.insert(N).second) {
S.erase(N);
if (N > L[0]) L[1] = L[0], L[0] = N;
else if (N > L[1]) L[1] = N;
}
}
cout << L[0] * L[1] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define pii pair<int, int>
const int mod = 1e9+7;
const int MAXN = 1e5+5;
const int N = 1e5+5;
int fac[N];
int spf[MAXN];
void pre(int p) {
fac[0] = 1;
for(int i=1; i<N; i++) {
fac[i] = (fac[i-1] * i) % p;
}
}
void sieve()
{
spf[1] = 1;
for (int i=2; i<MAXN; i++) spf[i] = i;
for (int i=4; i<MAXN; i+=2) spf[i] = 2;
for (int i=3; i*i<MAXN; i++)
{
if (spf[i] == i)
{
for (int j=i*i; j<MAXN; j+=i) if (spf[j]==j) spf[j] = i;
}
}
}
vector<int> getFactorization(int x)
{
vector<int> ret;
while (x != 1)
{
ret.push_back(spf[x]);
x = x / spf[x];
}
return ret;
}
unsigned long long power(unsigned long long x,
int y, int p)
{
unsigned long long res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
// Returns n^(-1) mod p
unsigned long long modInverse(unsigned long long n, int p)
{
return power(n, p - 2, p);
}
// Returns nCr % p using Fermat's little
// theorem.
unsigned long long nCr(unsigned long long n,
int r, int p)
{
// Base case
if (r == 0) return 1;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void solve(int TC) {
int n; cin >> n;
map<int, int> cnt;
for(int i=0; i<n; i++) {
int x; cin >> x;
cnt[x]++;
}
vector<int> a;
for(auto it : cnt) {
if(it.second >= 2) {
int times = it.second / 2;
for(int i=0; i<times; i++) {
a.push_back(it.first);
}
}
}
sort(a.rbegin(), a.rend());
if((int)a.size() < 2) {
cout << 0; return;
}
int ans = a[0]*a[1];
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(12);
int T = 1;
//cin >> T;
for(int i=1; i<=T; i++) {
solve(i);
}
return 0;
} | 1 |
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
int main(){
ll H, W, K;
cin >> H >> W >> K;
vll count1(W-1, 0); //count1.at(i)...i~i+1に線があるとき
vll count2(W, 0); //count2.at(i)...i番目の左右に線がないとき(i-1~i, i~i+1)
for(int tmp = 0; tmp < (1 << (W-1)); tmp++){
//1が隣あってないか
bool ok = true;
for(int i = 0; i < W-2; i++){
if((tmp >> i) & (tmp >> (i+1))){
ok = false;
break;
}
}
if(!ok) continue;
for(int i = 0; i < W-1; i++){
if((tmp >> i) & 1) count1.at(i)++;
}
for(int i = 0; i < W; i++){
bool flag = true;
if(i > 0){
if((tmp >> (i-1)) & 1) flag = false;
}
if(i < W-1){
if((tmp >> i) & 1) flag = false;
}
if(flag) count2.at(i)++;
}
}
vvll dp(H+2, vll(W, 0));
dp.at(1).at(0) = 1;
for(int i = 2; i < H+2; i++){
for(int j = 0; j < W; j++){
if(j > 0) dp.at(i).at(j) += dp.at(i-1).at(j-1) * count1.at(j-1) % MOD;
dp.at(i).at(j) %= MOD;
dp.at(i).at(j) += dp.at(i-1).at(j) * count2.at(j) % MOD;
dp.at(i).at(j) %= MOD;
if(j < W-1) dp.at(i).at(j) += dp.at(i-1).at(j+1) * count1.at(j) % MOD;
dp.at(i).at(j) %= MOD;
}
}
cout << dp.at(H+1).at(K-1) << endl;
} | #include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <list>
#include <numeric>
#include <stack>
#include <unordered_map>
#include <map>
#include <set>
using namespace std;
#define sz(a) int((a).size())
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'
#define watch(x) cout << #x << " : " << x << endl;
#define FastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
typedef vector<ii> vii;
const int N = int(2e5)+10;
const int K = 10005;
// const int MOD = int(1e9)+7;
const int INF = int(1e9)+5;
const ll INF64 = 1e18;
const ll MOD = 998244353;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
ll inv[N],fact[N],ifact[N];
//! Modular Exponentiation.
ll modpow (ll x,ll n) {
if (n == 0ll) return 1ll;
ll u = modpow(x,n/2);
u = mul(u,u,MOD);
if (n % 2 == 1) u = mul(u,x,MOD);
return u;
}
void pre () {
inv[1] = fact[0] = fact[1] = ifact[0] = ifact[1] = 1;
for (int i=2;i<N;i++) {
inv[i] = mul(MOD - MOD / i, inv[MOD % i], MOD);
fact[i] = mul(i * 1ll, fact[i - 1], MOD);
ifact[i] = mul(inv[i], ifact[i - 1], MOD);
}
return;
}
ll nCr (ll n,ll r) {
if (n >= 0 && r >= 0 && n >= r) {
return mul(fact[n],mul(ifact[r],ifact[n-r],MOD),MOD);
}
return 0;
}
void solve () {
pre();
ll n,m,k;cin>>n>>m>>k;
ll ans = 0;
// k1 are same as left.
for (int k1=0;k1<=k;k1++) {
// n-1Ck1 * m * (m-1) ^ (n-1-k1).
ll temp = nCr(n-1,k1);
temp = mul(temp,m,MOD);
temp = mul(temp,modpow(m-1,n-1-k1),MOD);
ans = add(ans,temp,MOD);
}
cout<<ans<<endl;
}
int main () {
FastIO
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int t;
// cin>>t;
t = 1;
while (t--) {
solve();
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;
#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)
// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
uint64_t temp;
while (m % n != 0){
temp = n;
n = m % n;
m = temp;
}
return n;
}
uint64_t lcm(uint64_t m, uint64_t n) {
return (m*n)/gcd(m,n);
}
// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
for(uint64_t i = 0;i <v.size(); i++){
v[i][0]=1;
v[i][i]=1;
}
for(uint64_t k = 1;k <v.size();k++){
for(uint64_t j = 1;j<k;j++){
v[k][j]=(v[k-1][j-1]+v[k-1][j]);
}
}
}
// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {
uint64_t prod = a * b;
return (prod / b != a);
}
//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
long i,sq;
if(a%2==0){ //偶数の場合
factors.push_back(2);
primeFactorization(a/2,factors); //2で割った値で再帰
return;
}
sq = sqrt(a);
for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
if(a%i==0){
factors.push_back(i);
primeFactorization(a/i,factors); //割れた値で再帰
return;
}
}
//偶数でも3以上√a以下の奇数の場合でも割り切れない場合
if(a!=1){ //aが1でないなら、a自身は素数
factors.push_back(a);
}
}
// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m
int64_t modinv(int64_t a, int64_t m) {
int64_t b = m, u = 1, v = 0;
while (b) {
int64_t t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
// 円周率
// M_PI
// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;
// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;
ll pCount(int x){
if(x==0) return 1;
return pCount(x-1)*2 + 1;
}
ll allCount(int x){
if(x==0) return 1;
return allCount(x-1)*2 + 3;
}
signed main() {
ull n,m;
cin >> n >> m;
ll ans = 1;
for(ll i=1;i*i<=m;i++){
if(m%i!=0)continue;
ll j = m/i;
if(i*n<=m) ans = max(ans,i);
if(j*n<=m) ans = max(ans,j);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v;
int x;
cin >> x;
v.push_back(x);
cin >> x;
v.push_back(x);
cin >> x;
v.push_back(x);
sort(v.begin(), v.end());
cout<<v[0] +v[1];
return 0;
}
| 0 |
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>>
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32; で小文字に
// cout << fixed << setprecision (20); 小数点以下20桁まで
//実行時間制約2秒では2×10^8回くらいまで計算できる
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,m;
cin>>n>>m;
vector<pair<ll,pair<ll,ll>>> p;
rep(i,n){
ll s,t,x;
cin>>s>>t>>x;
p.pb({s-x,{-1,x}});
p.pb({t-x,{0,x}});
}
rep(i,m){
ll d;
cin>>d;
p.pb({d,{1,i}});
}
sort(all(p));
vector<ll> ans(m);
multiset<ll> se;
for(auto w : p){
ll x=w.fi;
ll y=w.se.fi;
ll z=w.se.se;
if(y==-1) se.insert(z);
else if(y==0) se.erase(se.lower_bound(z));
else {
if(se.empty()) ans[z]=-1;
else ans[z]=*se.begin();
}
}
rep(i,m){
cout << ans[i] << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define vii vector<ii>
#define all(X) (X).begin(),(X).end()
#define xx first
#define yy second
#define FOR(i,l,r) for( int i = l-(l>r); i != r-(l>r); i += 1-2*(l>r) )
int main() {
int n,q; cin>>n>>q;
vector<pair<int,ii>> v;
FOR(i,0,n) {
int s,t,x; cin>>s>>t>>x;
v.pb({x,{s-x,t-1-x}});
}
sort(all(v));
set<ii> s;
FOR(i,0,q) {
int u; cin>>u;
s.insert({u,i});
}
int ans[q];
memset(ans,-1,sizeof(ans));
for( auto e : v ) {
if( !s.size() ) break;
auto i1 = s.lb({e.yy.xx,-1});
auto i2 = s.ub({e.yy.yy,n+5});
auto i = i1;
vii temp;
while( i != i2 ) {
temp.pb(*i);
i++;
}
for( auto ee : temp ) {
s.erase(ee);
ans[ee.yy] = e.xx;
}
}
for( auto e : ans ) cout<<e<<"\n";
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
//#define int long long
//signed main(){
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
vector<int> cnt(26,0);
for(int i = 0; i < s.size(); i++) {
cnt[s[i]-'a']++;
}
if(s.size()==26) {
int idx=25;
while(idx>0 && s[idx-1]>s[idx]) idx--;
if(idx==0) {
cout << "-1" << "\n";
return 0;
}
char e='z'+1;
for(int i = idx; i < s.size(); i++) if(s[idx-1]<s[i]) e=min(e,s[i]);
for(int i = 0; i < idx-1; i++) cout << s[i];
cout << e << "\n";
}
else{
cout << s;
int idx=0;
while(cnt[idx]!=0) idx++;
cout << char('a'+idx) << "\n";
}
return 0;
} | #include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793
int main(){
string S; cin >> S;
int N = S.size(); bool acan=true, bcan=true;
if(N%2==1){
cout << "No" << endl; return 0;
}
rep(i, N){
if(i%2==1 && S[i]!='h') acan=false;
if(i%2==0 && S[i]!='i') acan=false;
}
rep(i, N){
if(i%2==0 && S[i]!='h') bcan=false;
if(i%2==1 && S[i]!='i') bcan=false;
}
if(acan || bcan) cout << "Yes" << endl;
else cout << "No" << endl;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
int main() {
int k;
string s;
string kq;
cin >> k;
cin >> s;
int dodai = s.length();
if (k < 1 || k > 100)
return 0;
if (dodai < 1 || dodai > 100)
return 0;
for (int i = 0; i < k; ++i)
{
if (k > dodai)
{
cout << s;
return 0;
}
if (s[i] >= 'a' && s[i] <= 'z')
kq += s[i];
else
return 0;
}
if (k < dodai)
kq += "...";
cout << kq;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
//#define int long long
using ll = long long;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,n) for(ll i=0;i<=n;i++)
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int main(){
ios_base::sync_with_stdio(false);
ll k;
string s;
cin >> k >> s;
if(s.size()<=k){
cout << s << endl;
}else{
for(int i=0;i<k;i++){
cout << s[i];
}
cout << "..." << endl;
}
return 0;
}
| 1 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
const long long MOD = (long long)1e9 + 7;
int main(){
int n, m;
cin >> n >> m;
vector<long long> x(n), y(m);
for(int i = 0; i < n; i++){
cin >> x[i];
}
for(int i = 0; i < m; i++){
cin >> y[i];
}
long long a = 0, b = 0;
for(int i = 1; i < n; i++){
a += i * x[i] - (n - i) * x[i - 1];
if(a < 0){
a += MOD * (long long)((abs(a) + MOD - 1) / MOD);
}
a %= MOD;
}
for(int i = 1; i < m; i++){
b += i * y[i] - (m - i) * y[i - 1];
if(b < 0){
b += MOD * (long long)((abs(b) + MOD - 1) / MOD);
}
b %= MOD;
}
cout << (a * b) % MOD << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#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 inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<x<<endl
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
typedef vector<int> vi;
ll n,m,x[100001],y[100001];
ll xsum,ysum;
int main(void){
cin>>n>>m;
rep(i,n)cin>>x[i];
rep(i,m)cin>>y[i];
rep(i,n){xsum=(xsum+i*x[i]-(n-1-i)*x[i])%mod;d(xsum)}
rep(i,m){ysum=(ysum+i*y[i]-(m-1-i)*y[i])%mod;d(ysum)}
p((xsum*ysum)%mod);
return 0;
}
| 1 |
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};
vector<vector<int>> graph;
bool sort_sec(const pair<int,int> &a,const pair<int,int> &b){
if(a.second<b.second){
return true;
}
return false;
}
void swap(int *a,int *b){
int temp=*a;
*a=*b;
*b=temp;
}
int gcd(int a,int b){
if(a%b==0) return b;
return gcd(b,a%b);
}
int digit(int num){
int cnt=0;
while(num!=0){
cnt+=num%10;
num=num/10;
}
return cnt;
}
int main(void){
int N;
cin>>N;
long long x;
cin>>x;
vector<long long> a(N);
for(int i=0;i<N;i++){
cin>>a[i];
}
sort(a.begin(),a.end());
long long sum=0;
int ans=0;
for(int i=0;i<N;i++){
sum+=a[i];
if(sum<=x) ans++;
else break;
}
if(sum<x) ans--;
cout<<ans<<endl;
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 main() {
int N, K, ans = 1;
cin >> N >> K;
rep(i, N) {
if (ans < K) ans += ans;
else ans += K;
}
cout << ans << "\n";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int d, g;
cin >> d >> g;
vector<pair<int,int>>pc(d);
for (int i = 0; i < d; i++)cin >> pc.at(i).first >> pc.at(i).second;
int ans = 1e10;
for (int bit = 0; bit < (1 << d); bit++) {
vector<pair<int, int>>pcc = pc;
vector<int> l(0);
for (int i = 0; i < d; i++) if (bit & (1 << i))l.push_back(i);
int res = 0;
int point = 0;
for (int i = 0; i < l.size(); i++) {
point += pcc.at(l.at(i)).second;
res += pcc.at(l.at(i)).first;
point += pcc.at(l.at(i)).first * (l.at(i) + 1) * 100;
pcc.at(l.at(i)).first = 0;
}
int ct = d - 1;
while (true) {
if (ct == -1)break;
if (point >= g)break;
if (pcc.at(ct).first == 0) {
ct--;
}
else {
pcc.at(ct).first--;
res++;
point += (ct + 1) * 100;
}
}
ans = min(ans, res);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int 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 vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
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 d,g;
vin p,c;
bool check(int y){
bool ans=false;
vin order(d);
rep(i,0,d)order[i]=i;
do{
int x=y;
int rest=g;
rep(i,0,d){
int now=order[i];
if(x>=p[now]){
rest-=p[now]*(now+1)*100;
rest-=c[now];
x-=p[now];
}
else{
rest-=x*(now+1)*100;
x=0;
break;
}
}
if(rest<=0)ans=1;
}while(next_permutation(all(order)));
return ans;
}
int main(){cout<<fixed<<setprecision(20);
//二分探索かな?
//順列探索かな?
//O(10^6*log1000)*10
cin>>d>>g;
p.resize(d);c.resize(d);
rep(i,0,d)cin>>p[i]>>c[i];
int ng=0,ok=1000;
while(ok-ng>1){
int mid=(ok+ng)/2;
if(check(mid))ok=mid;
else ng=mid;
}
cout<<ok<<endl;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
int main(){
int n;
cin >> n;
int a[n];
double ave = 0;
rep(i,n) {
cin >> a[i];
ave += a[i];
}
ave /= n;
double d = 1e5;
int ans = 0;
rep(i,n){
if(d > abs(ave-a[i])){
ans = i;
d = abs(ave-a[i]);
}
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int dp[34];
int main(){
int N,x;
cin >> x;
dp[0] = 1;
for(int i = 0; i < 31; i++){
dp[i+1] += dp[i];
dp[i+2] += dp[i];
dp[i+3] += dp[i];
}
while(x != 0){
cout << dp[x]/3650 + 1 << endl;;
cin >> x;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 1e18
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N;
string S;
cin>>N>>S;
string mae,ushi;
mae = S.substr(0,N);
ushi = S.substr(N,N);
map<pair<string,string>,ll> mp;
//後ろ半分の文字列(反転させる)
for(int i=0;i<(1<<N);i++){
string a="",b="";
for(int j=0;j<N;j++){
if(i>>j & 1) a += ushi[j];
else b += ushi[j];
}
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
auto p = make_pair(a,b);
++mp[p];
}
ll res = 0;
for(int i=0;i<(1<<N);i++){
string a="",b="";
for(int j=0;j<N;j++){
if(i>>j & 1) a += mae[j];
else b += mae[j];
}
auto p = make_pair(a,b);
res += mp[p];
}
cout<<res<<endl;
}
| #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
const int MAXN = 18;
int n;
int LOG[1 << MAXN];
ll ans;
ll f[2][1 << MAXN][MAXN + 1];
ll g[2][1 << MAXN][MAXN + 1];
string S,s,t;
int popcount(int v)
{
return v ? popcount(v - (v & -v)) + 1 : 0;
}
int main()
{
cin >> n >> S;
LOG[0] = -1;
for (int i = 1;i < (1 << n);i++)
LOG[i] = LOG[i >> 1] + 1;
s = S.substr(0,n);
reverse(S.begin(),S.end());
t = S.substr(0,n);
f[0][0][0] = 1;
for (int j = 0;j <= n;j++)
{
memset(f[~j & 1],0,sizeof(f[~j & 1]));
memset(g[~j & 1],0,sizeof(g[~j & 1]));
for (int i = 0,I = 0;i < (1 << n);I = popcount(++i))
{
if (j > I)
continue;
for (int k = 0;k < n;k++)
{
if (f[j & 1][i][k])
{
for (int l = LOG[i] + 1;l < n;l++)
if (t[l] == s[I])
f[~j & 1][i | (1 << l)][k + (l == k)] += f[j & 1][i][k];
if (k == LOG[i] + 1)
{
for (int l = k + 1;l < n;l++)
if (t[l] == s[I])
g[j & 1][i | (1 << l)][k + (l == k)] += f[j & 1][i][k];
}
if (t[k] == s[I])
{
int K = k + 1;
while (K < n && (i >> K & 1))
K++;
int el = LOG[i] + 1 + (LOG[i] + 1 == k);
if (K > el)
g[j & 1][i | (1 << k)][el] += f[j & 1][i][k];
else
f[j & 1][i | (1 << k)][K] += f[j & 1][i][k];
}
}
if (g[j & 1][i][k])
{
for (int l = LOG[i] + 1;l < n;l++)
if (t[l] == s[I])
g[j & 1][i | (1 << l)][k] += g[j & 1][i][k];
if (t[k] == s[I])
{
int K = k + 1;
while (K < n && (i >> K & 1))
K++;
int el = LOG[i] + 1 + (LOG[i] + 1 == k);
if (K >= el)
f[~j & 1][i | (1 << k)][el] += g[j & 1][i][k];
else
g[~j & 1][i | (1 << k)][K] += g[j & 1][i][k];
}
}
}
}
ans += f[j & 1][(1 << n) - 1][n];
}
cout << ans << endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(false);
ll n;
cin >> n;
string res;
while (n>0){
int i = (n-1) % 26;
char c = 'a' + i;
res = c + res;
n = (n-1) / 26;
}cout << res;
return 0;
}
| #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
int main(){
INT(n);
vector<ll> vec(n),vec2(n);
int zero=0,minus=0;
ll sum=0;
rep(i,n){
in(vec[i]);
if(vec[i]==0)zero=1;
else if(vec[i]<0){
minus++;
}
sum+=abs(vec[i]);
vec2[i]=abs(vec[i]);
}
if(minus%2==0||zero==1){
out(sum);
}else{
sort(all(vec2));
out(sum-2*vec2[0]);
}
} | 0 |
#include <iostream>
#include <vector>
#include <cmath>
using ll = long long;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
using namespace std;
int main(){
ll n, m;
cin >> n >> m;
ll mx = m / n;
ll ans;
repr(i, mx+1){
if (m % i == 0){
ans = i;
break;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;
// 約数列挙
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(begin(ret), end(ret));
return (ret);
}
int main(){
ll n, m;
cin >> n >> m;
vector<ll> div = divisor(m);
ll ans = 1;
for(auto v : div){
ll k = m / v;
if (k >= n) ans = max(ans, v);
}
cout << ans << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;
int main(){
ll N;
cin >> N;
vector<ll> a(N), b(N), c(N), d(N);
vector<Pll> p(N), q(N);
rep(i,N){
cin >> a[i] >> b[i];
p[i] = Pll(a[i],b[i]);
}
rep(i,N){
cin >> c[i] >> d[i];
q[i] = Pll(c[i],d[i]);
}
sort(p.begin(),p.end());
sort(q.begin(),q.end());
vector<ll> memo(N);
ll ans = 0;
rep(i,N){
ll Mb = -1;
ll id = -1;
rep(j,N){
if(q[i].fi > p[j].fi && q[i].se > p[j].se && memo[j] == 0){
if(Mb < p[j].se){
Mb = p[j].se;
id = j;
}
}
}
if(Mb != -1){
memo[id] = 1;
ans++;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#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 pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
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> 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 outvvp(T v){rep(i,v.size())outvp(v[i]);}
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]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
vi level,memo;
vvi v;
ll n;
void bfs(ll s){
level=vi(n,inf);
queue<P> q;
q.push(P(s,0));
level[s]=0;
while(!q.empty()){
auto t=q.front();q.pop();
rep(i,n)if(v[t.fi][i]){
if(chmin(level[i],t.se+1))q.push(P(i,t.se+1));
}
}
}
ll dfs(ll i,ll t,ll f){
if(i==t)return f;
REP(j,memo[i],n){
memo[i]++;
if(v[i][j]==0||level[i]>=level[j])continue;
ll d=dfs(j,t,min(f,v[i][j]));
if(d>0){
v[i][j]-=d;
v[j][i]+=d;
return d;
}
}
return 0;
}
ll max_flow(ll s,ll t){
ll flow=0;
while(true){
bfs(s);
if(level[t]==inf)return flow;
memo=vi(n);
while(true){
ll f=dfs(s,t,inf);
if(f==0)break;
flow+=f;
}
}
return flow;
}
int main(){
cin>>n;
v=vvi(n*2+2,vi(n*2+2));
vp point(2*n);
rep(i,2*n)cin>>point[i].fi>>point[i].se;
rep(i,n)rep(j,n)if(point[i].fi<=point[j+n].fi&&point[i].se<=point[j+n].se){
v[i+1][j+n+1]++;
}
rep(i,n)v[0][i+1]++;
rep(i,n)v[i+n+1][n*2+1]++;
n=n*2+2;
outs(max_flow(0,n-1),-1);
} | 1 |
/* {{{ Shinobu kawaii */
/*
______ __ _ __
.' ____ \ [ | (_) [ |
| (___ \_| | |--. __ _ .--. .--. | |.--. __ _
_.____`. | .-. | [ | [ `.-. |/ .'`\ \| '/'`\ \[ | | |
| \____) | | | | | | | | | | || \__. || \__/ | | \_/ |,
\______.'[___]|__][___][___||__]'.__.'[__;.__.' '.__.'_/
*/
/* }}} */
#include <bits/stdc++.h>
using namespace std;
// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
/* cpp template {{{ */
/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X real()
#define Y imag()
/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)
/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';
/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T> void print(T x) {std::cout << x << '\n';}
template <typename T>
void print(std::vector<T>& v, std::string s = " ") {
REP(i, v.size()) {
if (i != 0) std::cout << s;
std::cout << v[i];
}
std::cout << '\n';
}
/* }}} */
int n, m;
void warshall_floyd(vvi& d)
{
REP(k, m) REP(i, m) REP(j, m) {
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
signed main()
{
while (cin >> n >> m, n || m) {
vvi dc, dt;
dc = dt = vvi(m, vi(m, INF));
REP(i, n) {
int a = in() - 1, b = in() - 1;
dc[a][b] = dc[b][a] = in();
dt[a][b] = dt[b][a] = in();
}
warshall_floyd(dc);
warshall_floyd(dt);
int k = in();
REP(i, k) {
int a = in() - 1, b = in() - 1, r = in();
print(r ? dt[a][b] : dc[a][b]);
}
}
return 0;
} | #include <cstdio>
#include <map>
using namespace std;
typedef pair<int, int> pii;
int c[101][101] = { { 0 } };
int t[101][101] = { { 0 } };
int n, m;
int calculate(int mat[101][101], int from, int to){
multimap<int, int> locations;
for(int i = 1; i <= m; i++){
if(mat[from][i] != 0){
locations.insert(pii(mat[from][i], i));
}
}
while(!locations.empty()){
multimap<int, int>::iterator it = locations.begin();
int d = (*it).first, f = (*it).second;
if(f == to){ break; }
for(int i = 1; i <= m; i++){
if(mat[f][i] != 0 && (d + mat[f][i] < mat[from][i] || mat[from][i] == 0)){
int dist = d + mat[f][i];
mat[from][i] = mat[i][from] = dist;
locations.insert(pii(dist, i));
}
}
locations.erase(it);
}
return mat[from][to];
}
int main(){
while(true){
scanf("%d%d", &n, &m);
if(n == 0 || m == 0){ break; }
for(int i = 0; i <= m; i++){
for(int j = 0; j <= m; j++){
c[i][j] = t[i][j] = 0;
}
}
for(int i = 0; i < n; i++){
int a, b, cost, time;
scanf("%d%d%d%d", &a, &b, &cost, &time);
if(c[a][b] == 0 || c[a][b] > cost){ c[a][b] = c[b][a] = cost; }
if(t[a][b] == 0 || t[a][b] > time){ t[a][b] = t[b][a] = time; }
}
int k;
scanf("%d", &k);
while(k--){
int p, q, r;
scanf("%d%d%d", &p, &q, &r);
printf("%d\n", calculate((r == 0) ? c : t, p, q));
}
}
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n; cin >> n;
int p = n + 5;
vector<ll> num(p, 0);
ll initial;
ll maximumValue = 0;
for (int i = 0; i < n; i++) {
ll d; cin >> d;
num[d]++;
maximumValue = max(maximumValue, d);
if (i == 0) initial = d;
}
if (initial != 0 || 2 <= num[0]) {
cout << 0 << endl;
return 0;
}
const ll mod = 998244353;
ll ans = 1;
for (int i = 2; i <= maximumValue; i++) {
int tmpCnt = num[i];
while (tmpCnt--) {
ans *= num[i - 1];
ans %= mod;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353;
ll Ep(int x, int y){
if(y == 1) return x;
ll r = Ep(x,y/2);
if(y%2 == 1) return r *r%MOD *x%MOD;
else return r *r%MOD;
}
int main(){
int n, x;
cin >> n;
cin >> x;
if(x != 0){
cout << 0 << endl;
return 0;
}
map<int, int> mp;
for(int i=1; i<n; ++i){
cin >> x;
if(x == 0){
cout << 0 << endl;
return 0;
}
++mp[x];
}
ll ans = 1;
for(auto p: mp){
if(p.first == 1) continue;
ans *= Ep(mp[p.first-1], p.second);
ans %= MOD;
}
cout << ans << endl;
} | 1 |
#include <bits/stdc++.h>
#include <ctime>
#define rep(i,a,b) for(int i =a;i<b;i++)
using namespace std;
typedef unsigned long long ll;
inline int cine() {int a; return scanf("%d", &a) ? a : 1e9;}
void solve() {
int train, bus, mine = 1e9, sum = 0 ;
rep(i, 0, 2) {
cin >> train;
mine = min(mine, train);
}
sum += mine;
mine = 1e9;
rep(i, 0, 2) {
cin >> bus;
mine = min(mine, bus);
}
sum += mine;
cout << sum;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("i.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
#ifndef ONLINE_JUDGE
cout << "\nTime Elapsed :" << 0.1 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
} | #include <bits/stdc++.h>
using namespace std;
inline void ci(void){
return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
cin >> first;
ci(rest...);
return;
}
inline void co(void){
cout << "\n";
return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
cout << first << " ";
co(rest...);
return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size())
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
// sqrt ルート, int 2*10^9, gcd 最大公約数
// __builtin_popcount bitの個数
int main() {
int A, B, C, D;
ci(A, B, C, D);
int a, b;
a = min(A, B);
b = min(C, D);
co(a + b);
}
| 1 |
#include<iostream>
#include<queue>
#include<limits>
// #include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#define ll long long
#define tc(t) while(t--)
#define V vector
#define Vp vector< pair<int,int> >
#define pb push_back
#define UM unordered_map
#define IT iterator
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define PQ priority_queue
#define _FI ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
char ar[140000];
vector<ll> SieveOfEratosthenes(ll n)
{
vector<ll> result;
bool prime[n+1];
memset(prime, true, sizeof(prime));
int count=1;
for (ll p=2; p*p<=n; p++)
{
if (prime[p] == true)
{
for (ll i=p*p; i<=n; i += p)
{
prime[i] = false;
}
count++;
}
}
for (ll p=2; p<=n; p++)
if (prime[p])
{
result.push_back(p);
}
return result;
}
vector<ll> Divisors (ll n)
{
vector<ll> res;
for(ll i=1;i<=sqrt(n);i++)
{
if(n%i==0)
{
if(n/i==i)
{
res.pb(i);
}
else
{
res.pb(i);
res.pb(n/i);
}
}
}
return res;
}
ll Div(ll n)
{
for(ll i=2;i<=sqrt(n);i++)
{
if(n%i==0)
return i;
}
return n;
}
int a[4][2]={ {1,0}, {1,-1}, {1,1}, {2,0} } ;
bool validPoint(int x,int y, int N)
{
return (x>=0 && x<N && y>=0 && y<N);
}
int main()
{
_FI
ll n;
cin>>n;
V<ll> arr(n);
map<ll,ll> mp;
forn(i,n)
{
cin>>arr[i];
mp[arr[i]]++;
}
if(mp.size()==n)
{
cout<<"YES";
}
else
{
cout<<"NO";
}
return 0;
}
| #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int n;
cin >> n;
vector<long long> A(n);
for(int i=0;i<n;i++) cin >> A.at(i);
vector<long long> sa(n+1,0);
for(int i=0;i<n;i++) sa.at(i+1) = sa.at(i) + A.at(i);
long long ans = 10000000000000000;
for(int i=1;i<n-1;i++){
long long left = sa.at(i+1);
long long right = sa.at(n) - sa.at(i+1);
int lsplit = min(int(upper_bound(sa.begin(),sa.end(),left/2) - sa.begin() - 2),i-1);
int rsplit = min(int(upper_bound(sa.begin(),sa.end(),right/2 + left) - sa.begin() - 2),n-2);
// cout << "rsplit = " << rsplit << endl;
long long lM = min(max(sa.at(lsplit + 1),sa.at(i+1) - sa.at(lsplit + 1)),max(sa.at(lsplit + 2), sa.at(i+1) - sa.at(lsplit + 2)));
long long rM = min(max(sa.at(rsplit + 1)-sa.at(i+1),sa.at(n)-sa.at(rsplit+1)) ,max(sa.at(rsplit+2)-sa.at(i+1),sa.at(n) - sa.at(rsplit+2)));
// cout << "rM = " << rM << endl;
long long M = max(lM,rM);
long long m = min(sa.at(i+1) - lM,sa.at(n) - sa.at(i+1) - rM);
// cout << i << ":" << M-m << " M = "<< M << " m = " << m << endl;
ans = min(ans, M-m);
}
cout << ans << endl;
}
| 0 |
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;
int n,s[10],t;
int main()
{
while(scanf("%d",&n),n)
{
rep(i,10)s[i]=0;
rep(i,n)scanf("%d",&t),s[t]++;
rep(i,10)
{
if(s[i]==0)putchar('-');
rep(j,s[i]+1)putchar(j==s[i]?'\n':'*');
}
}
return 0;
} | #include<iostream>
#include<iomanip>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int main(void) {
int n;
cin>>n;
REP(i, n) {
int out = 0;
int score = 0;
vector<bool> rui(3, false);
while(out < 3) {
string hoge;
cin>>hoge;
if(hoge == "HIT") {
if(rui[2]) {
++score;
}
for(int j = 1; j >= 0; --j) {
rui[j + 1] = rui[j];
}
rui[0] = true;
} else if (hoge == "OUT") {
++out;
} else if(hoge == "HOMERUN") {
score++;
REP(j, 3) {
if(rui[j]) ++score;
rui[j] = false;
}
}
}
cout<<score<<endl;
}
} | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
vector<P> cal(vector<P> &v,double a,double b){
vector<P> res;
for(int i=0;i<v.size();i++){
double l=v[i].real(),r=v[i].imag();
if(l<=a&&b<=r)res.push_back(P(l,a)),res.push_back(P(b,r));
else if(l<=a&&a<=r)res.push_back(P(l,a));
else if(l<=b&&b<=r)res.push_back(P(b,r));
else if(a>l||r>b)res.push_back(v[i]);
}
return res;
}
int main(){
int n;
cin>>n;
double x,y;
P p[100];
for(int i=0;i<n;i++)cin>>x>>y,p[i]=P(x,y);
for(int i=0;i<n;i++){
vector<P> v;
v.push_back(P(-M_PI,M_PI));
for(int j=0;j<n;j++){
if(i==j)continue;
P a=P(0,-1)*(p[j]-p[i]);
double d=arg(a);
if(d>0)v=cal(v,d,M_PI),v=cal(v,-M_PI,d-M_PI);
else v=cal(v,d,d+M_PI);
}
double ans=0;
for(int j=0;j<(int)v.size();j++)ans+=v[j].imag()-v[j].real();
cout<<ans/2/M_PI<<endl;
}
return 0;
} | /*First observation is that little numbers should be summed up to go to above 3
* any number above 3 is better multiplied
* also given a set of numbers to add, the best pairs to pick are least with most since we will multiply them next
* also if the number of numbers we are going to add is N
* then the numbers we will add are the first N numbers given that the array is sorted
* so we just bruteforce on N
*
*/
#include <bits/stdc++.h>
#include <complex>
using namespace std;
typedef long long int ll;
const double PI = acos(-1);
const int N = 2e6, MOD = 1e6 + 3, LOG = 21;
ll k, mvup, toAdd;
bool chn = false;
vector<ll> v;
int main() {
//freopen("input.txt", "r", stdin);
scanf("%lld", &k);
while (k % 50 != 0) {
k++;
mvup++;
}
ll N = 50;
ll base = N - 1;
ll needed = k / N;
printf("%lld\n", N);
for (int i = 0; i < N; i++) {
v.push_back(base + needed);
}
toAdd = mvup;
for (int i = 0; i < N; i++) {
if (mvup) {
v[i] -= N;
mvup--;
v[i] += (toAdd - 1);
} else {
v[i] += toAdd;
}
}
for (int i = 0; i < N; i++) {
printf("%lld ", v[i]);
}
return 0;
}
| 0 |
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main(){
string s;
cin >> s;
rep(i, (int)(s.length())-1) {
if ( s[i] == 'A' && s[i+1] == 'C' ) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MAX = 1000;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
//setprecision(15)
int main() {
ll N; cin >> N;
set<ll> st;
rep(i, N) {
ll tmp; cin >> tmp;
st.insert(tmp);
}
if (st.size() == N) cout << "YES" << endl;
else cout << "NO" << endl;
} | 0 |
#include <map>
#include <iostream>
using namespace std;
/** Problem0039 : Roman Figure **/
int main()
{
char num[110]; int now, old, ans;
map<char, int> list;
list.insert(map<char, int>::value_type('I', 1));
list.insert(map<char, int>::value_type('V', 5));
list.insert(map<char, int>::value_type('X', 10));
list.insert(map<char, int>::value_type('L', 50));
list.insert(map<char, int>::value_type('C', 100));
list.insert(map<char, int>::value_type('D', 500));
list.insert(map<char, int>::value_type('M', 1000));
while (cin >> num) {
ans = 0;
old = list[num[0]];
for (int i=1; i<110 && num[i]!='\0'; i++) {
now = list[num[i]];
if (old == 0) {
old = now;
} else if (old<now) {
ans += (now-old);
old = 0;
} else {
ans += old;
old = now;
}
}
ans += old;
cout << ans << endl;
}
return 0;
} | #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main(void){
int n;
//d[0] = 1patern d[1] = 1paten d[2] = 2patern
int dp[41] = {1, 1, 2};
for(int i = 3; i <= 31; i++){
dp[i] = dp[i-3] + dp[i-2] + dp[i-1];
}
while(cin >> n, n)
FIN(dp[n]/3650 + 1);
return 0;
} | 0 |
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
inline void chmax(int &x, int v) { if (x < v) x = v; }
int H, W;
int EX, EY;
char A[100][100];
int tate[100][100];
int yoko[100][100];
vector<vector<vector<vector<int> > > > dp;
inline int f_tate(int x, int l, int r) {
l = max(l, 0);
r = min(r, H-1);
if (x<0||x>=W||l>r) return 0;
return tate[x][r]-(l>0?tate[x][l-1]:0);
}
inline int f_yoko(int y, int l, int r) {
l = max(l, 0);
r = min(r, W-1);
if (y<0||y>=H||l>r) return 0;
return yoko[r][y]-(l>0?yoko[l-1][y]:0);
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> H >> W;
rep(i, H) rep(j, W) cin >> A[j][i];
rep(x, W) rep(y, H) if (A[x][y] == 'E') EX = x, EY = y;
rep(x, W) rep(y, H) tate[x][y] = yoko[x][y] = A[x][y] == 'o';
rep(x, W-1) rep(y, H) yoko[x+1][y] += yoko[x][y];
rep(x, W) rep(y, H-1) tate[x][y+1] += tate[x][y];
dp.resize(W+1);
rep(l, W+1) {
dp[l].resize(W+1-l);
rep(r, W+1-l) {
dp[l][r].resize(H+1);
rep(u, H+1) dp[l][r][u].resize(H+1-u, -INF);
}
}
dp[0][0][0][0] = 0;
rep(l, W) {
rep(r, W-l) {
rep(u, H) {
rep(d, H-u) {
if (dp[l][r][u][d] == -INF) continue;
chmax(dp[l+1][r][u][d], dp[l][r][u][d] + ((EX-(l+1)<r)?0:f_tate(EX-(l+1), max(EY-u, d), min(EY+d, H-1-u))));
chmax(dp[l][r+1][u][d], dp[l][r][u][d] + ((EX+(r+1)>=W-l)?0:f_tate(EX+(r+1), max(EY-u, d), min(EY+d, H-1-u))));
chmax(dp[l][r][u+1][d], dp[l][r][u][d] + ((EY-(u+1)<d)?0:f_yoko(EY-(u+1), max(EX-l, r), min(EX+r, W-1-l))));
chmax(dp[l][r][u][d+1], dp[l][r][u][d] + ((EY+(d+1)>=H-u)?0:f_yoko(EY+(d+1), max(EX-l, r), min(EX+r, W-1-l))));
}
}
}
}
int m = 0;
rep(l, W+1) rep(r, W+1-l) rep(u, H+1) rep(d, H+1-u) chmax(m, dp[l][r][u][d]);
cout << m << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N=110;
int h,w,px,py,f[N][N][N][N],col[N][N],row[N][N];
bool mp[N][N];
void Init()
{
scanf("%d%d",&h,&w);
for (int i=1;i<=h;++i)
for (int j=1;j<=w;++j)
{
char ch=getchar();
while (ch!='o' && ch!='.' && ch!='E') ch=getchar();
if (ch=='E') px=i,py=j;
if (ch=='o') mp[i][j]=1;
else mp[i][j]=0;
}
}
int Col(int r,int l,int x)
{
if (l>r) return 0;
return col[r][x]-col[l][x];
}
int Row(int r,int l,int x)
{
if (l>r) return 0;
return row[x][r]-row[x][l];
}
void Solve()
{
for (int i=1;i<=h;++i)
for (int j=1;j<=w;++j)
{
col[i][j]=col[i-1][j]+mp[i][j];
row[i][j]=row[i][j-1]+mp[i][j];
}
int ans=0;
for (int a=px;a>0;--a)
for (int b=px;b<=h;++b)
for (int c=py;c>0;--c)
for (int d=py;d<=w;++d) f[a][b][c][d]=-1e9;
f[px][px][py][py]=0;
for (int a=px;a>0;--a)
for (int b=px;b<=h;++b)
for (int c=py;c>0;--c)
for (int d=py;d<=w;++d)
{
if (a>1 && a-1>b-px)
f[a-1][b][c][d]=max(f[a-1][b][c][d],f[a][b][c][d]+Row(min(w-(py-c),d),max(c-1,d-py),a-1));
if (b<h && h-b>px-a)
f[a][b+1][c][d]=max(f[a][b+1][c][d],f[a][b][c][d]+Row(min(w-(py-c),d),max(c-1,d-py),b+1));
if (c>1 && c-1>d-py)
f[a][b][c-1][d]=max(f[a][b][c-1][d],f[a][b][c][d]+Col(min(h-(px-a),b),max(a-1,b-px),c-1));
if (d<w && w-d>py-c)
f[a][b][c][d+1]=max(f[a][b][c][d+1],f[a][b][c][d]+Col(min(h-(px-a),b),max(a-1,b-px),d+1));
ans=max(ans,f[a][b][c][d]);
}
printf("%d\n",ans);
}
int main()
{
Init();
Solve();
return 0;
} | 1 |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
int k,t;
cin>>k>>t;
if(t==1){
cout<<k-1<<endl;
return 0;
}
int vec[t];
for(int i=0;i<t;i++){
cin>>vec[i];
}
sort(vec,vec+t);
if(vec[t-1]<=(k+1)/2){
cout<<0<<endl;
return 0;
}
int ans=(vec[t-1]-(k+1)/2)*2;
if(k%2==0){
ans--;
}
cout<<ans<<endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
void setIO(string name = "c") {
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
int main() {
//setIO();
ll n, m; cin >> n >> m;
vector <ll> v (n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
ll ans = max(v[0], m) - m; v[0] -= max(v[0], m) - m;
for (int i = 0; i < n - 1; i++) {
ans += max(v[i] + v[i + 1], m) - m;
v[i + 1] -= max(v[i] + v[i + 1], m) - m;
}
cout << ans << "\n";
} | 0 |
#include <iostream>
#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 <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
if (a < b) return euclidean_gcd(b, a);
unsigned r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
ll ll_gcd(ll a, ll b) {
if (a < b) return ll_gcd(b, a);
ll r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
class UnionFind {
public:
vector <ll> par;
vector <ll> siz;
UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
for (ll i = 0; i < sz_; ++i) par[i] = i;
}
void init(ll sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL);
for (ll i = 0; i < sz_; ++i) par[i] = i;
}
ll root(ll x) {
while (par[x] != x) {
x = par[x] = par[par[x]];
}
return x;
}
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y) return false;
if (siz[x] < siz[y]) swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y) {
return root(x) == root(y);
}
ll size(ll x) {
return siz[root(x)];
}
};
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
long long modinv(long long a, long long mod) {
return modpow(a, mod - 2, mod);
}
vector<int> tpsort(vector<vector<int>>& G) {
int V = G.size();
vector<int> sorted_vertices;
queue<int> que;
vector<int> indegree(V);
for (int i = 0; i < V; i++) {
for (int j = 0; j < G[i].size(); j++) {
indegree[G[i][j]]++;
}
}
for (int i = 0; i < V; i++) {
if (indegree[i] == 0) {
que.push(i);
}
}
while (que.empty() == false) {
int v = que.front();
que.pop();
for (int i = 0; i < G[v].size(); i++) {
int u = G[v][i];
indegree[u] -= 1;
if (indegree[u] == 0) que.push(u);
}
sorted_vertices.push_back(v);
}
return sorted_vertices;
}
struct Point
{
double x;
double y;
};
struct LineSegment
{
Point start;
Point end;
};
double tenkyori(const LineSegment& line, const Point& point)
{
double x0 = point.x, y0 = point.y;
double x1 = line.start.x, y1 = line.start.y;
double x2 = line.end.x, y2 = line.end.y;
double a = x2 - x1;
double b = y2 - y1;
double a2 = a * a;
double b2 = b * b;
double r2 = a2 + b2;
double tt = -(a * (x1 - x0) + b * (y1 - y0));
if (tt < 0)
return sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
else if (tt > r2)
return sqrt((x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0));
double f1 = a * (y1 - y0) - b * (x1 - x0);
return sqrt((f1 * f1) / r2);
}
int main() {
ll m;
cin >> m;
ll dig = 0;
ll sum = 0;
for (int i = 0; i < m; i++) {
ll a, b;
cin >> a >> b;
dig += b;
sum += a * b;
}
cout << dig - 1 + (sum-1) / 9 << endl;
} | #include <iostream>
using namespace std;
static const int MAX = 101;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
int n, M[MAX][MAX];
int prim()
{
int u, mincost;
int d[MAX], p[MAX], color[MAX];
for(int i=0; i<MAX; i++)
{
color[i] = WHITE;
d[i] = INFTY;
p[i] = -1;
}
d[0] = 0;
while(1)
{
mincost = INFTY;
for(int i=0; i<n; i++)
{
if(color[i] != BLACK && d[i] < mincost)
{
mincost = d[i];
u = i;
}
}
if(mincost == INFTY)
break;
color[u] = BLACK;
for(int v=0; v<n; v++)
{
if(color[v] != BLACK && M[u][v] != -1)
{
if(M[u][v] < d[v])
{
d[v] = M[u][v];
p[v] = u;
color[v] = GRAY;
}
}
}
}
int sum = 0;
for(int i=0; i<n; i++)
{
if(p[i] != -1)
sum += M[i][p[i]];
}
return sum;
}
int main()
{
cin >> n;
int e;
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
cin >> e;
if(e == -1)
M[i][j] = INFTY;
else
M[i][j] = e;
}
}
cout << prim() << endl;
return 0;
} | 0 |
#include <iostream>
using namespace std;
int main(){
int n,a;
int max = -10000000,min = 10000000;
long sum=0;
cin >> n;
for(int i=0;i<n;++i){
cin >> a;
if(max<a){
max = a;
}
if(min>a){
min = a;
}
sum += a;
}
cout << min << " " << max << " " << sum << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define all(x) x.begin(), x.end()
#define watch(x) cout<<#x<<" : "<<x<<endl
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define testCases int tt;cin>>tt; while(tt--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef vector<string> vs;
int main() {
fastio;
int n;
cin >> n;
set<int> s;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
s.insert(temp);
}
if (s.size() == n) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;
int main(){
int n;
string a,b,c;
cin>>n>>a>>b>>c;
int ans=0;
rep(i,n){
if(a[i]==b[i]&&a[i]==c[i])continue;
if(a[i]==b[i]||a[i]==c[i]||b[i]==c[i])ans++;
else ans+=2;
}
cout<<ans<<endl;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int a, b, c;
cin >> a >> b >> c;
if (a==b && b!=c){
std::cout << "Yes" << std::endl;
}
else if (a==c && b!=c){
std::cout << "Yes" << std::endl;
}
else if (b==c && b!=a){
std::cout << "Yes" << std::endl;
}
else{std::cout << "No" << std::endl;}
} | 0 |
#include<iostream>
#include<climits>
using namespace std;
// 完成版。
int tree[(1 << 18)];
void Update(int s, int t, int m, int left = 0, int right = (1 << 17), int key = 0){
if(t < left || right <= s) return;
if(s <= left && right - 1 <= t){ tree[key] = max(tree[key], m); return; }
Update(s, t, m, left, (left + right) / 2, 2 * key + 1);
Update(s, t, m, (left + right) / 2, right, 2 * key + 2);
}
int Find(int i){
i += (1 << 17) - 1;
int m = tree[i];
while(i){
i = (i - 1) / 2;
m = max(tree[i], m);
};
return m;
}
int main(){
int i;
for(i = 0; i < (1 << 18); i++) tree[i] = 0;
int n, q;
int x[100000];
for(i = 0; i < 100000; i++) x[i] = INT_MAX;
int s, t, value, m;
m = 1;
cin >> n >> q;
int query;
while(q){
q--;
cin >> query;
if(query){
cin >> i;
cout << x[Find(i)] << endl;
}else{
cin >> s >> t >> value;
x[m] = value;
Update(s, t, m);
m++;
}
};
return 0;
}
| #include<stdio.h>
int x;
int d[11];
int i,j;
int main(){
while(scanf("%d,",&x)!=EOF){
d[0]=0;
d[1]=d[0]+x;
for(i=0;i<9;i++){
scanf("%d,",&x);
d[i+2]=d[i+1]+x;
}
int v1,v2;
scanf("%d,%d",&v1,&v2);
double p;
int ans;
p=(double)(d[10]*v1)/(v1+v2);
for(i=0;i<10;i++){
if(p>d[i]&&p<=d[i+1]){
ans=i;
break;
}
}
printf("%d\n",ans+1);
}
} | 0 |
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long INF=1e18;
long long mod=1e9+7;
//status unsolved
int main(){
int n;
cin>>n;
long long a[n+1];
rep2(i,n){
cin>>a[i];
}
a[0]=-1;
for(int i=1;i<=n;i++){
if(a[i]>a[i-1]+1){
cout<<"-1"<<endl;
return 0;
}
}
long long ans=0;
for(int i=2;i<=n;i++){
if(a[i-1]+1==a[i]){
ans++;
//cout<<"?";
}
else{
ans+=a[i];
//cout<<"!";
}
}
cout<<ans<<endl;
return 0;
}
/*
*/
| #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
const int MAX = 1000000;
//flagを用いたバブルソート
int bubbleSort(int A[], int N){
int sw = 0;
bool flag = 1;
for(int i = 0; flag; i++){
flag = 0;
for(int j = N - 1; j >= i + 1; j--){
if(A[j] < A[j - 1]){
//隣接要素を交換する
swap(A[j], A[j - 1]);
flag = 1;
sw++;
}
}
}
return sw;
}
int main(){
int A[100], N, sw;
cin >> N;
for(int i = 0;i < N; i++) cin >> A[i];
sw = bubbleSort(A, N);
for(int i = 0; i < N; i++){
if(i) cout << " ";
cout << A[i];
}
cout << endl;
cout << sw << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define PR(x) cout << (x) << "\n"
#define PS(x) cout << (x) << " "
const long long INF = numeric_limits<long long>::max();
int main() {
ll N;
cin >> N;
ll sum = 0;
for (ll i = 1; i <= N; ++i) {
if (i % 3 == 0) continue;
if (i % 5 == 0) continue;
sum += i;
}
PR(sum);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int main() {
string s;
cin >> s;
if(s[0] != 'A' || isupper(s[1]) || isupper(s[s.size() - 1])){
cout << "WA" << endl;
return 0;
}
bool isFoundC = false;
for(int i = 2; i < s.size() - 1; i++){
if(!isFoundC && s[i] == 'C') isFoundC = true;
else if(s[i] == 'C'){
cout << "WA" << endl;
return 0;
}else if(isupper(s[i])){
cout << "WA" << endl;
return 0;
}
}
cout << (isFoundC ? "AC" : "WA") << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a,b,c=0,d=0,e=0;
cin >> a >> b;
c += a+b;
d += a-b;
e += a*b;
cout << max(c,max(d,e)) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B;
cin >> A >> B;
int S = A + B;
int T = A - B;
int U = A * B;
if (S >= T && S >= U) {
cout << S << endl;
} else if (T >= S && T >= U) {
cout << T << endl;
} else {
cout << U << endl;
}
} | 1 |
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <cstdlib>
using namespace std;
vector<string> split(const string &str, char delim){
vector<string> res;
size_t current = 0, found;
while((found = str.find_first_of(delim, current)) != string::npos){
res.push_back(string(str, current, found - current));
current = found + 1;
}
res.push_back(string(str, current, str.size() - current));
return res;
}
int main()
{
string s;
while(cin >> s)
{
vector<string> _s = split(s,',');
int *values = new int[11];
double *v = new double[2];
for(int i=0;i<11;i++)
{
if(i == 0)
{
values[i] = 0;
}
else
{
values[i] = std::atoi(_s[i-1].c_str()) + values[i-1];
}
}
for(int i=0;i<2;i++)
{
v[i] = std::atoi(_s[i+10].c_str());
}
double temp = v[0] / (v[0]+v[1]);
temp *= values[10];
bool flag = true;
for(int i=0;i<10;i++)
{
if(values[i] <= temp && temp <= values[i+1] && flag)
{
cout << i+1 << endl;
flag = false;
}
}
}
return 0;
} | #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
cout << n / 3 << endl;
} | 0 |
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <math.h> // sqrt()
#include <iomanip>
#define rep(i , n) for (int i = 1; i <= (int)(n); i++)
#define repz(i , n) for (int i = 0; i < (int) n; i++)
#define repi(i , r, n) for (int i = r; i <= (int)(n); i++)
#define repd(i , r, n) for (int i = r; i >= (int)(n); i--)
using namespace std;
int main(){
int n;
cin >> n;
int64_t A[n];
int64_t B[n];
int64_t C[n];
repz( i , n) cin >> A[i];
repz( i , n) cin >> B[i];
repz( i , n) cin >> C[i];
sort(A, A + n);
sort(C, C + n);
int64_t ans = 0; int64_t a = 0; int64_t c = 0;
for ( int64_t i : B){
a = lower_bound(A, A + n, i ) - A ;
c = upper_bound(C, C + n , i) - C;
ans += a * (n - c);
}
cout << ans << endl;
} |
// Problem : C - Snuke Festival
// Contest : AtCoder - AtCoder Beginner Contest 077
// URL : https://atcoder.jp/contests/abc077/tasks/arc084_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()
using namespace std;
template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};
template<class T>
T abst(T a)
{return a<0?-a:a;}
template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}
void solve()
{
int n;cin>>n;
vi a(n),b(n),c(n);cin>>a>>b>>c;
sort(all(a));
sort(all(b));
sort(all(c));
int ans=0;
int suff[n];
for(int i=n-1;i>=0;i--)
{
int ind=upper_bound(all(c),b[i])-c.begin();
if(i==n-1)
{
suff[n-1]=n-ind;
}
else
{
suff[i]=n-ind;
suff[i]+=suff[i+1];
}
}
for(int i=0;i<n;i++)
{
int ind=upper_bound(all(b),a[i])-b.begin();
if(ind<n)
ans+=suff[ind];
}
cout<<ans;
}
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
solve();
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,0,-1,1,-1,-1,1,2,0,-2,0};
const int dy[]={0,1,-1,0,1,1,-1,-1,0,2,0,-2};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef pair<int,int> Pii;
typedef pair<int,Pii > P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
int main(){
int e;
while(scanf("%d",&e),e){
int ans = INF;
rep(y,1001){
rep(z,101){
int Y = y*y;
int Z = z*z*z;
if(Y+Z > e)continue;
ans = min(ans,e-Y-Z+y+z);
}
}
printf("%d\n",ans);
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)
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; }
//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x) cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する
class Solve {
public:
void input() {
}
void solve() {
input();
int e;
cin >> e;
if (e == 0) return;
int m = INF;
for (int y = 0; y * y <= e; ++y) {
for(int z = 0; z * z * z <= e; ++z){
int x = e - y * y - z * z * z;
if(x >= 0 && m > x + y + z) m = x + y + z;
}
}
cout << m << endl;
solve();
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
Solve().solve();
return 0;
}
| 1 |
// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define PI 3.14159265358979323846264338327950288
#define rep(i,n) for(int i=0;i<n;i++)
#define exf(x) for(auto&& tmp : x) { cout << tmp << endl; } // 拡張for
#define testP cout << "------------------ test ------------------" << endl; // 動作確認テスト
#define testX(x) cout << "testout : " << x << endl; // テストアウト
typedef long long ll;
using namespace std;
const int MOD{ int(1e9 + 7) }; // = 1000000007
const int inf{ 2100000000 }; // = 2100000000 (MAX:2147483647)
// ------------------ ベクター表示 ------------------ //
void printVec(vector<int>& vec) {
cout << "";
for (auto it = vec.begin(); it != vec.end(); it++) cout << *it << " ";
cout << endl;
}
// ------------------ ベクター合計 ------------------ //
int sumVec(vector<int> v) {
int sum = 0;
for (size_t i = 0; i < v.size(); i++) sum += v[i];
return sum;
}
// -------------------------------------------------- //
// ------------------ ここから本編 ------------------ //
// -------------------------------------------------- //
int main(void) {
int H, W;
cin >> H >> W;
queue<pair<int, int>> que;
pair<int, int> end_pair;
static char maze[1000][1000];
fill(maze[0], maze[1000], '-');
rep(y, H) {
rep(x, W) {
cin >> maze[y][x];
if (maze[y][x] == '#') {
que.push(make_pair(y, x));
end_pair = que.back();
}
}
}
// ----------
int dx[4] = { 1,0,-1,0 },
dy[4] = { 0,1,0,-1 };
int ans = 0;
while (!que.empty()) {
pair<int,int> tmp = que.front();
que.pop();
rep(i, 4) {
int nextY = tmp.first + dy[i],
nextX = tmp.second + dx[i];
if (nextY < 0 || nextY >= H || nextX < 0 || nextX >= W) continue;
if (maze[nextY][nextX] == '#') continue;
maze[nextY][nextX] = '#';
que.push(make_pair(nextY, nextX));
}
if (tmp == end_pair) {
ans++;
if (!que.empty()) end_pair = que.back();
}
}
cout << ans - 1 << endl;
return 0;
}
| #include "bits/stdc++.h"
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P =pair<int,int>;
int main(){
int h,w;
cin >> h >> w;
vector <vector <int>> m(h, vector <int> (w,3000));
queue <vector <int>> q;
int ans=0;
string s,s2;
vector <int> s3(3,0);
rep(i,h){
cin >> s;
rep(j,w){
s2=s[j];
if(s2=="#"){
s3[0]=i;
s3[1]=j;
q.push(s3);
m[i][j]=0;
}
}
}
int x,y,z;
vector <int> xyz,pu(3);
while(q.size()!=0){
xyz=q.front();
q.pop();
ans=max(ans,xyz[2]);
m[xyz[0]][xyz[1]]=xyz[2];
if(xyz[0]!=0){
if(m[xyz[0]-1][xyz[1]]>xyz[2]+1){
pu[0]=xyz[0]-1;
pu[1]=xyz[1];
pu[2]=xyz[2]+1;
q.push(pu);
m[xyz[0]-1][xyz[1]]=pu[2];
}
}
if(xyz[0]!=h-1){
if(m[xyz[0]+1][xyz[1]]>xyz[2]+1){
pu[0]=xyz[0]+1;
pu[1]=xyz[1];
pu[2]=xyz[2]+1;
q.push(pu);
m[xyz[0]+1][xyz[1]]=pu[2];
}
}
if(xyz[1]!=0){
if(m[xyz[0]][xyz[1]-1]>xyz[2]+1){
pu[0]=xyz[0];
pu[1]=xyz[1]-1;
pu[2]=xyz[2]+1;
q.push(pu);
m[xyz[0]][xyz[1]-1]=pu[2];
}
}
if(xyz[1]!=w-1){
if(m[xyz[0]][xyz[1]+1]>xyz[2]+1){
pu[0]=xyz[0];
pu[1]=xyz[1]+1;
pu[2]=xyz[2]+1;
q.push(pu);
m[xyz[0]][xyz[1]+1]=pu[2];
}
}
}
cout << ans << endl;
return 0;
} | 1 |
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>
#define f first
#define s second
#define mp make_pair
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)
using namespace std;
typedef unsigned int uint;
typedef long long ll;
const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};
int getInt(){
int ret = 0,c;
c = getchar();
while(!isdigit(c)) c = getchar();
while(isdigit(c)){
ret *= 10;
ret += c - '0';
c = getchar();
}
return ret;
}
int main(){
int n, m;
while((n = getInt()) + (m = getInt())){
vector<int> v(n);
int ans = 0;
REP(i,n) v[i] = getInt();
sort(v.rbegin(), v.rend());
REP(i,n) if(i % m != (m - 1))
ans += v[i];
print(ans);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;
#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int N,K;
cin>>N>>K;
vector<int>A(N);
for(int i=0;i<N;i++)cin>>A[i];
for(int i=0;i<K;i++){
vector<int>B(N,0);
for(int j=0;j<N;j++){
int l=max(0,j-A[j]);
int r=min(N,j+A[j]+1);
B[l]++;
if(r<N)B[r]--;
}
for(int i=0;i<N-1;i++)B[i+1]+=B[i];
A=B;
bool ok=true;
for(auto it:A)if(it!=N)ok=false;
if(ok)break;
}
for(auto it:A)cout<<it<<" ";
cout<<endl;
return 0;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 100
#define MAX_E 10000
#define INF 2000000001
struct edge{int from,to,cost;};
edge es[MAX_E]; //辺
int ds[MAX_V]; //最短距離
int V,E; //頂点数、辺数
int d[MAX_V][MAX_V]; //d[u][v]はe=(u,v)のコスト(存在しなければINF、d[i][i]は0)
void warshall_floyd(){
for(int k=0;k<V;k++)
for(int i=0;i<V;i++)
for(int j=0;j<V;j++){
if(d[i][k]!=INF&&d[k][j]!=INF)
d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}
}
bool find_negative_loop(){
memset(ds,0,sizeof(ds));
for(int i=0;i<V;i++){
for(int j=0;j<E;j++){
edge e=es[j];
if(ds[e.to]>ds[e.from]+e.cost){
ds[e.to]=ds[e.from]+e.cost;
if(i==V-1)return true;
}
}
}
return false;
}
int main(){
cin>>V>>E;
for(int i=0;i<V;i++)
for(int j=0;j<V;j++){
if(i==j)d[i][j]=0;
else d[i][j]=INF;
}
for(int i=0;i<E;i++){
cin>>es[i].from>>es[i].to>>es[i].cost;
d[es[i].from][es[i].to]=es[i].cost;
}
if(find_negative_loop())cout<<"NEGATIVE CYCLE"<<endl;
else {
warshall_floyd();
for(int i=0;i<V;i++){
for(int j=0;j<V;j++){
if(j)cout<<" ";
if(d[i][j]==INF)cout<<"INF";
else cout<<d[i][j];
}
cout<<endl;
}
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define int long long
const int mxn=2e5+3,du=1e9+7;
int m,n;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>m>>n;
map<int,int> mp;
multiset<int> s;
for (int i=1;i<=n;i++) mp[i]=i,s.insert(0);
for (int i=1;i<=m;i++)
{
int l,r;
cin>>l>>r;
auto it=mp.lower_bound(l);
int mx=0;
while(it!=mp.end()&&it->first<=r)
{
mx=max(mx,it->second);
int dis=(it->first)-(it->second);
s.erase(s.find(dis));
mp.erase(it++);
}
if (mx!=0&&r<n&&mp.find(r+1)==mp.end())
{
mp[r+1]=mx;
s.insert(r+1-mx);
}
// cout<<"DM";
if (s.size()) cout<<(*s.begin())+i<<"\n";
else cout<<-1<<"\n";
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
const int a[3] = {0, 1, 2};
const int b[3] = {1, 2, 0};
const int c[3] = {2, 0, 1};
int main() {
cin.tie(0)->sync_with_stdio(false);
int n;
cin >> n;
vector<vector<char> > s(3, vector<char>(n));
REP(i, 3) REP(j, n) cin >> s[i][j];
int cnt = 0;
REP(j, n) {
REP(i, 3)
if (s[a[i]][j] == s[b[i]][j] && s[b[i]][j] != s[c[i]][j])
cnt++;
if (s[0][j] != s[1][j] && s[0][j] != s[2][j] && s[1][j] != s[2][j])
cnt += 2;
}
cout << cnt << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
string a,b,c;
cin >> n >> a >> b >> c;
int cnt = 0;
for(int i = 0; i < n; i++){
if(a[i] == b[i] && b[i] != c[i]){
cnt++;
}else if(a[i] == c[i] && b[i] != c[i]){
cnt++;
}else if(c[i] == b[i] && a[i] != c[i]){
cnt++;
}else if(a[i] != b[i] && b[i] != c[i] && c[i] != a[i]){
cnt += 2;
}
}
cout << cnt << endl;
return 0;
} | 1 |
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main(){
int N;
cin >> N;
vector<queue<int>> Q(N + 1);
for (int i = 0; i < N; i++){
for (int j = 0; j < N - 1; j++){
int A;
cin >> A;
A--;
Q[i].push(A);
}
Q[i].push(N);
}
Q[N].push(N);
int ans = 0;
int cnt = N * (N - 1);
bool ok = true;
vector<int> upd;
for (int i = 0; i < N; i++){
upd.push_back(i);
}
while (cnt > 0){
ans++;
vector<int> upd2;
for (int i : upd){
if (Q[Q[i].front()].front() == i && Q[i].front() > i){
upd2.push_back(i);
upd2.push_back(Q[i].front());
}
}
for (int i : upd2){
Q[i].pop();
cnt--;
}
if (upd2.empty()){
ok = false;
break;
}
}
if (!ok){
cout << -1 << endl;
} else {
cout << ans << endl;
}
} | #include<iostream>
#include<vector>
using namespace std;
int main(){
int n;
cin>>n;
vector<vector<pair<int,int>>> v(n,vector<pair<int,int>>());
for(int i=0;i<n;i++){
int a;
cin>>a;
for(int j=0;j<a;j++){
int x,y;
cin>>x>>y;
x--;
v[i].push_back(make_pair(x,y));
}
}
int ans=0;
for(int i=0;i<(1<<n);i++){
int c=0;
vector<bool> f(n,false);
for(int j=0;j<n;j++){
if(i&(1<<j)){
f[j]=true;
c++;
}
}
bool ok=true;
for(int j=0;j<n;j++){
if(f[j]){
for(auto p : v[j]){
if(p.second==1 && !f[p.first]) ok=false;
if(p.second==0 && f[p.first]) ok=false;
}
}
}
if(ok) ans=max(ans,c);
}
cout<<ans<<endl;
}
| 0 |
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int V;
vector<int>G[10000],rG[10000],vs;
bool used[10000];
int cmp[10000];
void add_edge(int from,int to){
G[from].push_back(to);
rG[to].push_back(from);
}
void dfs(int v){
used[v]=true;
for(int i=0;i<G[v].size();i++){
if(!used[G[v][i]])dfs(G[v][i]);
}
vs.push_back(v);
}
void rdfs(int v,int k){
used[v]=true;
cmp[v]=k;
for(int i=0;i<rG[v].size();i++){
if(!used[rG[v][i]])rdfs(rG[v][i],k);
}
}
int scc(void){
fill(used,used+V,0);
vs.clear();
for(int v=0;v<V;v++)if(!used[v])dfs(v);
fill(used,used+V,0);
int k=0;
for(int i=vs.size()-1;i>=0;i--){
if(!used[vs[i]])rdfs(vs[i],k++);
}
return k;
}
int main(void){
int m,q,a,b;
cin >> V >> m;
for(int i=0;i<m;i++){
cin >> a >> b;
add_edge(a,b);
}
scc();
cin >> q;
for(int i=0;i<q;i++){
cin >> a >> b;
cout << (cmp[a]==cmp[b]) << endl;
}
return 0;
} | #include <cstdio>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
const int INF = 1000000000;
int main()
{
int n, m;
int d[512];
vector<int> f[512];
while (scanf("%d %d", &n, &m), n != 0){
for (int i = 1; i <= n; i++) f[i].clear();
for (int i = 0; i < m; i++){
int a, b;
scanf("%d %d", &a, &b);
f[a].push_back(b);
f[b].push_back(a);
}
fill(d + 1, d + n + 1, INF);
priority_queue<P, vector<P>, greater<P> > q;
q.push(P(0, 1));
d[1] = 0;
while (!q.empty()){
P p = q.top();
q.pop();
if (d[p.second] < p.first) continue;
for (int i = 0; i < f[p.second].size(); i++){
int v = f[p.second][i];
if (d[v] > d[p.second] + 1){
d[v] = d[p.second] + 1;
q.push(P(d[v], v));
}
}
}
int cnt = 0;
for (int i = 1; i <= n; i++){
cnt += (d[i] == 1 || d[i] == 2);
}
printf("%d\n", cnt);
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a,b;
cin >> a >> b;
int mn = max(-1000000,b-a+1);
int mx = min(1000000,b+a-1);
cout << mn;
for(int i = mn+1;i<mx+1;i++) cout << " " << i ;
} | #include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x,i##end=y;i<=i##end;++i)
#define _rep(i,x,y) for(int i=x,i##end=y;i>=i##end;--i)
#define N 4005
int n,k,c[N][N],pw[N];
const int mod=998244353;
inline void reduce(int&x){x-=mod,x+=x>>31&mod;}
inline int upd(int x){return reduce(x),x;}
inline void init(int n=4000){
pw[0]=c[0][0]=1;
rep(i,1,n){
c[i][0]=c[i][i]=1;
rep(j,1,i-1) c[i][j]=upd(c[i-1][j]+c[i-1][j-1]);
}
rep(i,1,n) pw[i]=upd(pw[i-1]<<1);
}
inline int solve(int A,int B,int C,int ret=0){
if(B<0) return 0;
rep(i,std::max(0,1-B),std::min(A,C))
(ret+=1ll*c[A][i]*pw[i]%mod*c[B+C-1][B+i-1]%mod)%=mod;
return ret;
}
int main(){
std::cin>>k>>n;
init();
rep(i,2,k<<1){
int l=std::max(i-k,1),r=std::min(i-1,k);
int now=r-l+1,ret=0;
if(now<0) now=0;
if(i&1) ret=solve(now>>1,k-now,n);
else
ret=upd(solve(now-1>>1,k-now,n)+solve(now-1>>1,k-now,n-1));
std::cout<<ret<<'\n';
}
return 0;
} | 0 |
/* HARD WORK FOREVER PAYS */
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define turbo(){ \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
}
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef unsigned long long int ull;
vector<ull> allPrimes;
void sieve(int n)
{
vector<bool> prime(n+1, true);
for (int p=2; p*p<=n; p++)
{
if (prime[p] == true)
{
for (int i=p*2; i<=n; i += p)
prime[i] = false;
}
}
for (int p=2; p<=n; p++)
if (prime[p])
allPrimes.push_back(p);
}
ull factorialDivisors(ull n)
{
sieve(n);
ull result = 1;
for (int i=0; i < allPrimes.size(); i++)
{
ull p = allPrimes[i];
ull exp = 0;
while (p <= n)
{
exp = exp + (n/p);
p = p*allPrimes[i];
}
result = result*(exp+1)%1000000007;
}
return result;
}
int main()
{
int n;
cin>>n;
cout << factorialDivisors(n)<<endl;
return 0;
} | #include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=4999999996000000001;
int main(){
int n;
cin>>n;
map<int,ll> mp;
for(int i=2;i<=n;i++){
int m=i;
for(int j=2;j*j<=m;j++){
while(m%j==0){
mp[j]++;
m/=j;
}
}
if(m>1) mp[m]++;
}
ll ans=1;
for(auto p:mp){
ans*=p.second+1;
ans%=MOD;
}
cout<<ans<<endl;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(void){
int a, b, c, d, in;
cin >> in;
a = in / 1000;
b = in % 1000 / 100;
c = in % 1000 % 100 / 10;
d = in % 1000 % 100 % 10;
vector<char> op(3);
if (a + b + c + d == 7) {
op[0] = '+';
op[1] = '+';
op[2] = '+';
} else if (a + b + c - d == 7) {
op[0] = '+';
op[1] = '+';
op[2] = '-';
} else if (a + b - c + d == 7) {
op[0] = '+';
op[1] = '-';
op[2] = '+';
} else if (a - b + c + d == 7) {
op[0] = '-';
op[1] = '+';
op[2] = '+';
} else if (a + b - c - d == 7) {
op[0] = '+';
op[1] = '-';
op[2] = '-';
} else if (a - b + c - d == 7) {
op[0] = '-';
op[1] = '+';
op[2] = '-';
} else if (a - b - c + d == 7) {
op[0] = '-';
op[1] = '-';
op[2] = '+';
} else if (a - b - c - d == 7) {
op[0] = '-';
op[1] = '-';
op[2] = '-';
}
cout << a << op[0] << b << op[1] << c << op[2] << d << "=7\n";
}
| #include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
LL n,i,maxi,mini=OO;
scanf("%lld",&n);
for(i=1;i*i<=n;++i){
if(n%i==0){
LL num1=i,num2=n/i,counter1=0,counter2=0;
while(num1){
num1/=10;
counter1++;
}
while(num2){
num2/=10;
counter2++;
}
maxi=max(counter1,counter2);
mini=min(mini,maxi);
}
}
printf("%lld",mini);
return 0;
}
| 0 |
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;
ll solve(ll d, string s){
ll ans = 0;
ll m = s.size();
vll t(18, 1);
for(int i=1;i<18;i++) t[i] = (t[i-1]*10);
//std::cout << s << '\n';
for(int i=0;i<(1<<(m/2));i++){
ll num = 0, cnt = 1;
//bitset<5> b(i);
//std::cout << b << '\n';
for(int j=0;j<m/2;j++){
ll l = m - 1 - j, r = j;
string tmp = to_string(num);
ll x = (tmp.size()<=j?0:tmp[tmp.size()-1-j] - '0');
ll y = (s.size()<=j?0:s[s.size()-1-j] - '0');
if((i>>j)&1){ //加算
ll z = (y - x + 10)%10, ad;
if(z==0){
ad = 0;
cnt *= 10-(j==0);
}else{
ll L = 10 - z;
ad = L * t[l] - L*t[r];
cnt *= (10 - L) - (j==0);
num += ad;
}
}else{ //減算
ll z = (y-x+10)%10, sb;
if(z==0){
sb = 0;
cnt *= 0;
}else{
ll L = z;
sb = L*t[l] - L*t[r];
cnt *= (10 - L) - (j==0);
num -= sb;
}
}
//std::cout << num << " " << cnt << '\n';
}
if(num==d) ans += cnt;
}
if(m%2) ans *= 10;
return ans;
}
int main(int argc, char const *argv[]) {
ll d;std::cin >> d;
string k = to_string(d);
ll ret = 0;
for(int i=0;i+k.size()<=18;i++){
string ad(i, '0');
ret += solve(d, ad + k);
}
std::cout << ret << '\n';
return 0;
}
| #include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
for(;b;b >>= 1,a = a * a % mod) if(b & 1)
ans = ans * a % mod;
return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int n, d;
ll pw[maxn], t;
std::unordered_map<ll, ll> map[100];
inline ll dfs(int high,int can,ll rem) {
if(high <= 0) return !rem * (high == 0 ? 10 : 1);
if(!can && map[high].count(rem)) return map[high][rem];
ll & ans = can ? t = 0 : map[high][rem];
for(int i = can;i < 10;++i) {
for(int j = 0;j < 10;++j) {
ll v = rem + (pw[high] - 1) / 9 * (j - i);
ans += v % 10 ? 0 : dfs(high - 2, 0, v / 10);
}
}
return ans;
}
int main() {
rep(i, 1, 20) map[i].rehash(1e5 + 7);
*pw = 1;
for(int i = 1;i < 19;++i) pw[i] = pw[i - 1] * 10;
cin >> d;
if(d % 9) {
cout << 0 << '\n';
return 0;
}
ll ans = 0;
for(n = 1;n < 19;++n) {
ans += dfs(n, 1, -d / 9);
}
cout << ans << '\n';
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int main(){
long long int n, m;
cin >> n >> m;
vector<int> d(n, 0);
vector<vector<int>> E(n);
for(int i=0;i<m;i++){
int a, b;
cin >> a >> b;
a--;b--;
E[a].emplace_back(b);
E[b].emplace_back(a);
}
vector<bool> visited(n, false);
function<void(int)> dfs = [&](int cur){
visited[cur] = true;
for(auto&& to:E[cur]){
if (!visited[to]){
d[to] = d[cur] + 1;
dfs(to);
}
}
};
dfs(0);
bool is_digraph = true;
for(int i=0;i<n;i++){
for(auto&& t:E[i]){
if(!((d[i]^d[t])&1)){
is_digraph = false;
}
}
}
// cerr << is_digraph << endl;
// for(auto&& r:d)cerr << r << " ";
// cerr << endl;
if(is_digraph){
long long int even = 0;
for(auto&& r:d)even += (r % 2 == 0);
cout << even * (n - even) - m << endl;
}else{
cout << n * (n - 1) / 2 - m << endl;
}
}
| #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount __builtin_popcount
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x))) //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x)) //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x)) //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
if (c >= '0' && c <= '9')
{
return c - '0';
}
return 0;
}
template <typename T>
T lcm(T x, T y)
{
T z = gcd(x, y);
return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
if (n < 2)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
double sqrtn = sqrt(n);
for (T i = 3; i < sqrtn + 1; i++)
{
if (n % i == 0)
{
return false;
}
i++;
}
return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));
Graph G;
//始点sからS回以内の移動でたどりつける町を探索
void bfs(vec &dist, ll s)
{
queue<ll> que;
dist[s] = 0;
que.push(s);
while (!que.empty())
{
ll v = que.front();
que.pop();
for (auto next_v : G[v])
{
if (dist[next_v] != -1)
continue;
dist[next_v] = dist[v] + 1;
que.push(next_v);
}
}
}
int main()
{
cout << fixed << setprecision(30);
ll N;
ll x, y;
cin >> N >> x >> y;
x--;
y--;
G.resize(N);
loop(i, N - 1)
{
ll a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
G[b].push_back(a);
}
if (G[x].size() == 1 && G[x][0] == y)
{
putout(0);
return 0;
}
vector<ll> distT(N, -1), distA(N, -1);
bfs(distT, x);
bfs(distA, y);
ll ans = 0;
loop(i, N)
{
if (distT[i] < distA[i])
ans = max(ans, distA[i] - 1);
}
putout(ans);
return 0;
}
| 0 |
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
using namespace std;
#define int long long
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE
//-----CODE------//
void DFS(int V,vector<vector<int> > &GRAPH,vector<int> & visited,vector<vector<char> > & mat,int & nB,int &nW,int WIDTH)
{
if(mat[V/WIDTH][V%WIDTH] == '.')nW++;
else nB++;
visited[V] = 1;
for (auto &&nV : GRAPH[V])
{
if(visited[nV] == 1)continue;
DFS(nV,GRAPH,visited,mat,nB,nW,WIDTH);
}
return;
}
//-----CODE------//
void solve(void)
{
int H,W; cin>>H; cin>>W;
vector<vector<char> > mat (H,vector<char>(W,0));
for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
cin>>mat[i][j];
}
}
int N = H*W;
vector<vector<int> > GRAPH (H*W);
for (int i = 0; i < H; i++)
{
for (int j = 0; j < W; j++)
{
if(i != 0)
{
if(mat[i][j] != mat[i-1][j])
{
int V = i*W + j;
int nV = (i-1)*W+j;
GRAPH[V].emplace_back(nV);
GRAPH[nV].emplace_back(V);
}
}
if(i != H - 1)
{
if(mat[i][j] != mat[i+1][j])
{
int V = i*W + j;
int nV = (i+1)*W+j;
GRAPH[V].emplace_back(nV);
GRAPH[nV].emplace_back(V);
}
}
if(j != 0)
{
if(mat[i][j] != mat[i][j-1])
{
int V = i*W + j;
int nV = (i)*W+j-1;
GRAPH[V].emplace_back(nV);
GRAPH[nV].emplace_back(V);
}
}
if(j != W -1)
{
if(mat[i][j] != mat[i][j+1])
{
int V = i*W + j;
int nV = (i)*W+j+1;
GRAPH[V].emplace_back(nV);
GRAPH[nV].emplace_back(V);
}
}
}
}
vector<int> visited (H*W,-1);
int ANS = 0;
for (int i = 0; i < H*W; i++)
{
int V = i;
int nB = 0;
int nW = 0;
DFS(V,GRAPH,visited,mat,nB,nW,W);
ANS += nB * nW;
}
cout<<ANS<<endl;
return;
}
int32_t main(int32_t argc, const char *argv[])
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout << std::fixed;
std::cout << std::setprecision(9);
solve();
return 0;
}
| #include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long LL;
typedef double T;
typedef pair<T,T> P;
double pi;
// difference
P operator-(const P& lhs, const P& rhs)
{
return P(lhs.first-rhs.first,lhs.second-rhs.second);
}
P operator+(const P& lhs, const P& rhs)
{
return P(lhs.first+rhs.first, lhs.second+rhs.second);
}
P full(0,1);
P one(1,1);
P f(P a, P b)
{
if(a==full){
return b;
}
if(a.first+0.5<b.first){
b=b-one;
}
if(b.first+0.5<a.first){
a=a-one;
}
P r=P(max(a.first,b.first),min(a.second,b.second));
if(r.first<0){
r=r+one;
}
return r;
}
P ps[100];
int main(){
pi=atan2(0,-1);
long long N;
scanf("%lld",&N);
for(int i = 0 ; i < N ; i++){
double x,y;
scanf("%lf",&x);
scanf("%lf",&y);
ps[i]=P(x,y);
}
for(int i=0;i<N;i++){
P r=full;
bool zero=false;
for(int j=0;j<N;j++){
if(i==j)continue;
auto v=ps[j]-ps[i];
auto c=atan2(v.second,v.first)/(2*pi);
P p(c-0.25,c+0.25);
while(p.first<0){
p=p+one;
}
r=f(r,p);
//cerr << i << ", " << j << ": " << p.first << ", " << p.second << ": " << r.first << ", " << r.second << ": " << v.first << ", " << v.second << ": " << c << endl;
//cerr << atan2(v.second,v.first) << ", " << pi << endl;
if(r.first>=r.second){
zero=true;
break;
}
}
if(zero){
cout << 0 << endl;
}
else{
cout << r.second-r.first << endl;
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define rep(i, n) rep2(i, 0, n)
using ll = long long;
using V = vector<int>;
char s[1000000];
ll t[3][1000001];
int main() {
int n, q;
scanf("%d%s%d", &n, s, &q);
V D, C;
rep(i, n) {
rep(j, 3) t[j][i+1] = t[j][i];
switch(s[i]){
case 'D':
++t[0][i+1];
D.push_back(i+1);
break;
case 'M':
++t[1][i+1];
break;
case 'C':
++t[2][i+1];
C.push_back(i);
break;
}
}
ll sa1 = 0, sc1 = 0;
for (auto &a : D) sa1 += t[1][a] * t[2][a];
for (auto &c : C) sc1 += t[1][c] * t[0][c];
rep(_, q) {
int k;
scanf("%d", &k);
ll ans = sa1 + sc1;
ll sa2 = 0, sc2 = 0;
for (auto &a : D) {
if (a+k-1 < n) ans -= t[1][a] * t[2][a+k-1];
else sa2 += t[1][a];
}
for (auto &c : C) {
if (c-k+1 > 0) ans -= t[1][c] * t[0][c-k+1];
else sc2 += t[1][c];
}
ans -= sa2 * t[2][n] + sc2 * t[0][0];
printf("%lld\n", ans);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
int N, Q;
string S;
cin >> N >> S >> Q;
vector<int> K(Q);
for (int i = 0; i < Q; i++) cin >> K[i];
vector<int> sum(N+1);
for (int k : K) {
ll D = 0, M = 0, ans = 0;
ll cntDM = 0;
for (int i = 0; i < S.size(); i++) {
if (S[i] == 'D') D++;
else if (S[i] == 'M') {
M++;
cntDM += D;
}
else if (S[i] == 'C') {
int l = max(i - k, 0), r = i + 1;
ans += cntDM;
}
if (i >= k - 1) {
if (S[i - (k - 1)] == 'D') {
D--;
cntDM -= M;
}
else if (S[i - (k - 1)] == 'M') M--;
}
}
cout << ans << '\n';
}
}
| 1 |
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n; cin >> n;
for (int i = 1; ; i++){
if (i * i == n) {
cout << i * i << endl;
break;
}
if (i * i > n) {
i--;
cout << i * i << endl;
break;
}
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a;
for(int i=0;i*i<=n;i++)
a=i*i;
cout<<a<<endl;
} | 1 |
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
fast;
ll T = 1, i, j;
//cin >> T;
while (T--) {
string s;
cin >> s;
bool flag = true;
ll cnt = 0;
for(i = 0; i < s.size() ; i += 2){
if(s[i] != 'h')
{
flag = false;
}
cnt++;
}
for(i = 1; i < s.size() ; i += 2){
if(s[i] != 'i'){
flag = false;
}
cnt--;
}
if(!flag || cnt != 0){
cout << "No";
}
else{
cout << "Yes";
}
}
return 0;
} | #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 all(v) v.begin(), v.end()
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
int main() {
string s;
bool hi = true;
cin >> s;
if(s.size() % 2 == 1)hi = false;
else {
for (int i = 0; i < s.size(); i += 2) {
if (s.substr(i, 2) != "hi") hi = false;
}
}
if (hi) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
string s;
void ans(int a, int64_t b) {
//cout << "a:" << a << " b:" << b << " num:" << int64_t(pow(26,a-1)) << endl;
if(a==1) s.push_back(96+b);
else {
int64_t num = pow(26,a-1);
if(b%num!=0) ans(a-1, b%num);
else ans(a-1, num);
if(b/num!=26 && b%num==0) s.push_back(96+b/num);
else if(b/num!=26) s.push_back(97+b/num);
else s.push_back('z');
}
}
int main() {
int64_t n;
cin >> n;
int digit = 0;
int64_t sum = 0;
for(int i=1;;i++) {
int64_t num = pow(26,i);
if((n-sum)/num==0) {
if((n-sum)%num==0) {
digit = i-1;
sum -= pow(26,i-1);
}
else digit = i;
}
if(digit!=0) break;
sum += num;
}
ans(digit, n-sum);
reverse(s.begin(), s.end());
cout << s << endl;
return 0;
} | #include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
int main(void){
ll n;
cin >> n;
char c[26+1]="abcdefghijklmnopqrstuvwxyz";
vector<char> v;
while(n){
v.push_back(c[(--n)%26]);
n/=26;
}
RREP(i,(int)v.size()-1)
cout << v[i];
cout << endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
vector<bool> dislike(10, false);
bool isOK(int p) {
while (p) {
int d = p % 10;
if (dislike[d]) return false;
p /= 10;
}
return true;
}
int main() {
int n, k;
cin >> n >> k;
rep(i, k) {
int d;
cin >> d;
dislike[d] = true;
}
int pay = n;
while (!isOK(pay)) pay++;
cout << pay << endl;
return 0;
} | #include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
if(a>8)
{
cout<<":(";
}
else if(b>8){
cout<<":(";
}
else
{cout<<"Yay!";
}}
| 0 |
#include<bits/stdc++.h>
int main(){
using namespace std;
unsigned long N, K;
cin >> N >> K;
unsigned long mx{0}, g{0};
for(unsigned long i{0}, A; i < N; ++i){
cin >> A;
mx = max(mx, A);
g = __gcd(g, A);
if(mx >= K && K % g == 0)return 0 & puts("POSSIBLE");
}
puts("IMPOSSIBLE");
return 0;
} | #include <iostream>
#include <numeric>
using namespace std;
const string YES = "POSSIBLE";
const string NO = "IMPOSSIBLE";
int main() {
int N, K, M{}, D{}, A;
cin >> N >> K;
while (cin >> A) {
M = max(M, A);
if (D) D = gcd(D, A);
else D = A;
}
cout << (K <= M && (M - K) % D == 0 ? YES : NO) << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
using ll = long long;
using P = pair<int, int>;
int main()
{
int n, m;
cin >> n >> m;
int maxL, minR;
maxL = -1e9;
minR = 1e9;
rep(i, m)
{
int l, r;
cin >> l >> r;
minR = min(minR, r);
maxL = max(maxL, l);
// printf("%d %d\n", minR, maxL);
}
cout << max(0, minR - maxL + 1) << endl;
return 0;
} | //Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll> pa;
typedef vector<ll> vc;
typedef vector<pa> vp;
typedef vector<vc> vvc;
int mpow(int base, int exp);
void ipgraph(ll n,ll m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================
vc g[N];
int main() {
FAST;
ll t, i, j, k, p, q, r, x, y, u, v, n, m;
cin>>n>>x>>t;
y=n/x;
if(n%x>0)
y++;
cout<<y*t;
return 0;
}
int mpow(int base, int exp) {
base %= mod;
int result = 1;
while (exp > 0) {
if (exp & 1) result = ((ll)result * base) % mod;
base = ((ll)base * base) % mod;
exp >>= 1;
}
return result;
}
void ipgraph(ll n, ll m){
int i, u, v;
while(m--){
cin>>u>>v;
g[u-1].pb(v-1);
g[v-1].pb(u-1);
}
}
void dfs(int u, int par){
for(int v:g[u]){
if (v == par) continue;
dfs(v, u);
}
} | 0 |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
if (y == 0)
{
return x;
}
else
{
return gcd(y, x % y);
}
}
const int MOD = 1000000007;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)
int main()
{
string s, t;
cin >> s >> t;
cout << t + s << endl;
return 0;
} | #include <stdio.h>
int main() {
char x[105], y[105];
scanf("%s %s", x, y);
printf("%s%s\n", y,x);
return 0;
} | 1 |
#include <iostream>
int main()
{
int64_t x;
std::cin >> x;
// 5と6を交互に出す
// どちらから始めてもいいので、最後を6にできる
const auto r = x % 11;
std::cout << x / 11 * 2 + (r + 5) / 6 << std::endl;
return 0;
}
| #include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数(任意精度)
typedef pair<int, int> P;
// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9)+7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
vector< pair<ll, ll> > p;
for (ll i = 2; i * i <= n; i++) {
if ((n % i) != 0) continue;
p.push_back(make_pair(i, 0));
while ((n % i) == 0) {
n /= i;
p[i].second += 1;
}
p.push_back(make_pair(n, 0));
}
if (n != 1) p.push_back(make_pair(n, 1));
return p;
}
// 組み合わせの整合性を保つ(後ほど解析する)
ll modinv(ll a) {
ll b = MOD, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= MOD;
if (u < 0) { u += MOD; }
return u;
}
// 順列
ll permutation(const ll n, const ll m) {
ll result = 1;
for (ll i = n; i > n - m; i--) { result = (result * i) % MOD; }
return result;
}
// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
if (x == 0) return 1;
ll res = repeat_square(n, x/2);
res = res * res % MOD;
if ((x % 2) == 1) res = res * n % MOD;
return res;
}
// 組み合わせ
ll combination(const ll n, const ll a) {
ll x = 1, y = 1;
for(ll i = 0; i < a; i++){
x = x * (n-i) % MOD;
y = y * (i+1) % MOD;
}
return x * repeat_square(y, MOD-2) % MOD;
}
int main() {
ll x;
cin >> x;
ll n = x / 11; // (5,6) or (6,5) のペア数でわる
ll m = x % 11; // 残りの数
ll result = n*2;
int min = 1000000;
rep(i, 2) { // 1, 6 始まりとそれ以外でパターンを分ける
int count = 0, temp = m;
bool flag = true;
while (temp > 0) {
if (i == 0) { // 1, 6 始まり
temp -= flag ? 5 : 6;
} else { // それ以外
temp -= flag ? 6 : 5;
}
count++;
flag = !flag;
}
if (min > count) min = count;
}
cout << (result + min) << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
const int N = 108;
int n;
int a[N], b[N];
int main() {
int i, mid;
scanf("%*d%d", &n);
for (i = 0; i < n; ++i) scanf("%d", a + i);
if (n == 1) return *a == 1 ? puts("1\n1\n1") : printf("%d\n2\n1 %d\n", *a, *a - 1), 0;
mid = std::partition(a, a + n, [] (const int x) -> bool {return x % 2;}) - a;
if (mid > 2) return puts("Impossible"), 0;
a[n] = *a;
for (i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? 10 : 32);
memcpy(b + 1, a + 1, n << 2), ++b[1], --b[n], n -= !b[n];
printf("%d\n", n);
for (i = 1; i <= n; ++i) printf("%d%c", b[i], i == n ? 10 : 32);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
ll x = 0; char ch = gc(); bool positive = 1;
for (; !isdigit(ch); ch = gc()) if (ch == '-') positive = 0;
for (; isdigit(ch); ch = gc()) x = x * 10 + ch - '0';
return positive ? x : -x;
}
inline void write(ll a){
if(a<0){
a=-a; putchar('-');
}
if(a>=10)write(a/10);
putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
return ((ull)rand()<<30^rand())<<4|rand()%4;
}
int n,m,a[105],tot;
vector<int> ans;
signed main(){
n=read(); m=read();
for(int i=1;i<=m;i++){a[i]=read(); if(a[i]&1)tot++;}
if(m==1){
if(a[1]==1)cout<<1<<endl<<1<<endl<<1<<endl; else
if(a[1]&1)cout<<a[1]<<endl<<2<<endl<<a[1]/2<<" "<<a[1]/2+1<<endl;
else if(a[1]==2)cout<<a[1]<<endl<<2<<endl<<1<<" "<<1<<endl;
else cout<<a[1]<<endl<<2<<endl<<a[1]/2-1<<" "<<a[1]/2+1<<endl;
return 0;
}
if(tot>2){
puts("Impossible"); return 0;
}
for(int i=2;i<m;i++)if(a[i]&1){
if(a[1]&1)swap(a[i],a[m]); else swap(a[1],a[i]);
}
for(int i=1;i<=m;i++)cout<<a[i]<<" "; puts("");
a[1]++; a[m]--;
for(int i=1;i<=m;i++)if(a[i])ans.push_back(a[i]);
cout<<ans.size()<<endl;
for(auto i:ans)cout<<i<<" ";
} | 1 |
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<ll> a(n);
ll s = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
s ^= a[i];
}
ll r = 0;
int i0 = 0;
for (int k = 60 - 1; k >= 0; k--) {
ll l = 1LL << k;
if (s & l) continue;
for (int i = i0; i < n; i++) {
if (a[i] & l) {
ll t = a[i];
for (int j = i + 1; j < n; j++) {
if (a[j] & l) {
a[j] ^= t;
}
}
swap(a[i0++], a[i]);
if (!(r & l)) r ^= t;
break;
}
}
}
r &= ~s;
r *= 2;
r += s;
cout << r << endl;
return 0;
} | #include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
typedef uint64_t ull;
typedef int64_t sll;
static const ull MOD = 1000000007LL;
int n;
int k;
int q;
ull a[200019];
ull umin (ull a, ull b) {
return (a < b) ? a : b;
}
ull umax (ull a, ull b) {
return (a > b) ? a : b;
}
ull solve () {
sll i, j, ki;
ull res = 0;
ull allxor = 0;
for (i = 0; i < n; i++) {
allxor ^= a[i];
}
for (i = 0; i < n; i++) {
a[i] &= ~allxor;
}
ull rank = 0;
for (i = 59; i >= 0; i--) {
for (j = rank; j < n; j++) {
if (a[j] & (1LL << i)) break;
}
if (j == n) {
continue;
}
if (j > rank) a[rank] ^= a[j];
for (j = rank + 1; j < n; j++) {
a[j] = umin(a[j], a[j] ^ a[rank]);
}
rank++;
}
ull x = 0;
for (i = 0; i < n; i++) {
x = umax(x, x ^ a[i]);
}
res = (x * 2) + allxor;
return res;
}
int main(void){
scanf("%d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
}
printf("%lld\n", solve());
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)
const int mxn = 2e5 + 5;
const ll inf = 1e18;
int n, v[mxn];
map <int, ll> dp[mxn];
int main() {
scanf("%d", &n);
rep(i, n) scanf("%d", &v[i]);
dp[0][0] = 0;
rep(i, n) {
for (int j = max(0, i / 2 - 5); j <= i / 2 + 5; ++ j) {
dp[i + 1][j] = dp[i].find(j) == dp[i].end() ? -inf : dp[i][j];
if (j) {
ll old = dp[max(0, i - 1)].find(j - 1) == dp[max(0, i - 1)].end() ? -inf : dp[max(0, i - 1)][j - 1];
dp[i + 1][j] = max(dp[i + 1][j], old + v[i]);
}
}
}
printf("%lld\n", dp[n][n / 2]);
return 0;
}
| #include <iostream>
#include <utility>
#include <vector>
#include <cstring>
using namespace std;
#define MAX 100
struct in {
int c;
int d;
pair<int, int> p;
};
int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };
int w, h, n;
pair<int, int> st, gl;
int map[MAX+2][MAX+2];//map[X][Y]
vector<in> info;
bool f;
bool dfs(int x, int y, int c) {
if (map[x][y] != c) return false;
map[x][y] = -1;
if (x==gl.first&&y==gl.second) return true;
for (int i=0; i<4; i++) {
if (x+dx[i]<0 || y+dy[i]<0 || x+dx[i]>=w+2 || y+dy[i]>=h+2) continue;
if (dfs(x+dx[i], y+dy[i], c)) return true;
}
return false;
}
int main() {
while (cin >> w >> h, w||h) {
cin >> st.first >> st.second >> gl.first >> gl.second >> n;
info.clear();
for (int i=0; i<n; i++) {
in t;
cin >> t.c >> t.d >> t.p.first >> t.p.second;
info.push_back(t);
}
memset(map, 0, sizeof(map));
for (int i=0; i<n; i++) {
int W=4, H=2;
if (info[i].d) { int t=W; W=H; H=t; }
for (int x=0; x<W; x++)
for (int y=0; y<H; y++)
map[info[i].p.first+x][info[i].p.second+y] = info[i].c;
}
cout << ((dfs(st.first, st.second, map[st.first][st.second])) ? "OK" : "NG") << endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点 << fixed << setprecision(0) <<
// sort降順 sort(ALL(),greater<int>());
// 円周率 M_PI
// 文字判定 isupper islower
// 文字変換
// 順列 do {} while(next_permutation(ALL(X)));
// 最大値 LLONG_MAX
// a内でx以上 auto iter = lower_bound(ALL(a), x);
// a内でxより大きい auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
int from; //出発点
int to; //到達点
int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
if(a < b) return Euclidean_gcd(b, a);
unsigned r;
while ((r=a%b)) {
a = b;
b = r;
}
return b;
}
int digit_sum(int n) {
int sum=n%10;
while(n!=0) {
n/=10;
sum+=n%10;
}
return sum;
}
vpll PrimeFactorization(ll n) {
vpll res;
for (ll i=2; i*i<=n; i++) {
if(n%i!=0) continue;
ll ex=0;
while(n%i==0) {
ex++;
n/=i;
}
res.push_back(pll(i,ex));
}
if(n!=1) res.push_back(pll(n,1));
return res;
}
int main() {
char s[100001];
cin >> s;
int n=strlen(s);
vi check(26,0);
REP(i,n) {
int x=s[i]-'a';
check[x]++;
}
int ans=-1;
REP(i,26) {
if(ans==-1&&check[i]==0) ans=i;
}
if(ans!=-1) {
char a='a'+ans;
cout << a << endl;
} else {
cout << "None" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
string s;
cin >> s;
char cbuff='a';
rep(i,26) {
cbuff='a'+i;
string::size_type pos=s.find(cbuff);
if (pos==string::npos) {
cout << cbuff << endl;
return 0;
}
}
cout << "None" << endl;
return 0;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MP make_pair
#define pb push_back
#define ff first
#define ss second
#define sz(x) x.size()
#define all(c) c.begin(),c.end()
#define int long long
#define fr(i,j,x) for(int i=j;i<x;i++)
#define rep(i,j,x) for(int i=j;i<=x;i++)
#define mem(x,val) memset(x,val,sizeof(x))
//#define endl '\n'
#define vi vector<int>
#define pii pair<int,int>
#define piii pair<int,pii>
const int mod=1e9+7;
const int N=1e5+10;
const int MAXN=2e6+10;
const int INF=1e18;
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
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 pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
int a[N];
string getbase(int x,int b){
string ans;
int d;
while(x){
d=x%b;
ans=char('0'+d)+ans;
x/=b;
}
return ans;
}
string L,R;
int d,dp[10010][2][2][101];
int rec(int ind,int tlo,int thi,int rem){
if(ind>=L.length()){
if(rem==0){
return 1;
}
return 0;
}
if(dp[ind][tlo][thi][rem]==-1){
int blo=0;
int bhi=9;
if(tlo){
blo=L[ind]-'0';
}
if(thi){
bhi=R[ind]-'0';
}
int ans=0;
for(int i=blo;i<=bhi;i++){
int ntlo=tlo;
int nthi=thi;
if(i>L[ind]-'0'){
ntlo=0;
}
if(i<R[ind]-'0'){
nthi=0;
}
ans+=rec(ind+1,ntlo,nthi,(rem+i)%d);
ans%=mod;
}
dp[ind][tlo][thi][rem]=ans;
}
return dp[ind][tlo][thi][rem];
}
void solve(){
string l,r;
l="1";
cin>>r>>d;
L=l;
R=r;
reverse(all(L));
reverse(all(R));
while(L.length()<R.length()){
L+='0';
}
while(L.length()>R.length()){
R+='0';
}
reverse(all(L));
reverse(all(R));
mem(dp,-1);
cout<<rec(0,1,1,0)<<endl;
}
int32_t main()
{
// #ifndef ONLINE_JUDGE
// freopen("inputf.in", "r", stdin);
// //freopen("outputf.in", "w", stdout);
// #endif
SPEED;
int T=1;
//cin>>T;
int t1=1;
while(true)
{
//cout<<"Case #"<<t1<<": ";
solve();
t1++;
if(t1>T)
break;
}
}
| #include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
#define ll long long
void add_self(ll& a, ll b) {
a += b;
if(a >= mod) {
a -= mod;
}
}
int main()
{
string k;
cin >> k;
int d;
cin >> d;
vector<vector<ll>> dp(d,vector<ll>(2));
int n = k.size();
dp[0][0] = 1;
for(int i = 0;i < n;i++)
{
auto new_dp = vector<vector<ll>> (d,vector<ll>(2));
for(int sum = 0;sum < d;sum++)
{
for(bool sm_already : {false,true})
{
for(int digit = 0;digit < 10;digit++)
{
if(digit > k[i]-'0' && !sm_already)
break;
add_self(new_dp[(sum+digit)%d][sm_already || (digit < k[i]-'0')],dp[sum][sm_already]);
}
}
}
dp = new_dp;
}
auto ans = (dp[0][true] + dp[0][false])%mod;
--ans;
if(ans == -1)
ans = mod-1;
cout << ans << endl;
return 0;
} | 1 |
#include <cstdio>
int a[100010],sum[2],n;
bool flag;
int gcd(int a,int b)
{
if (b==0) return a;
else return gcd(b,a%b);
}
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if (a[i]>1) sum[a[i]&1]++;
}
if (n==1)
{
if (a[1]&1) printf("Second\n");
else printf("First\n");
return 0;
}
flag=false;
while (1)
{
if (!sum[0]&&!sum[1])
{
if (!flag) printf("Second\n");
else printf("First\n");
return 0;
}
if (sum[0]&1)
{
if (!flag) printf("First\n");
else printf("Second\n");
return 0;
}
if (sum[1]>1||!sum[1])
{
if (!flag) printf("Second\n");
else printf("First\n");
return 0;
}
int GCD=-1;
for (int i=1;i<=n;i++)
if (a[i]>1)
{
if (a[i]&1)
{
a[i]--;break;
}
}
for (int i=1;i<=n;i++)
if (GCD==-1) GCD=a[i];
else GCD=gcd(a[i],GCD);
sum[0]=sum[1]=0;
for (int i=1;i<=n;i++)
{
a[i]/=GCD;
if (a[i]>1) sum[a[i]&1]++;
}
flag^=1;
}
return 0;
}
//all is 1: who faces even number of even number, lose./odd number of even number, win. | #include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
for(;b;b >>= 1,a = a * a % mod) if(b & 1)
ans = ans * a % mod;
return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int n, a[maxn];
inline bool get() {
int s = 0, one = 0;
rep(i, 1, n) s += a[i] % 2, one = one || a[i] == 1;
if(s != 1 || one) return n - s & 1;
int gcd = 0;
for(int i = 1;i <= n;++i) gcd = std::__gcd(gcd, a[i] -= a[i] % 2);
for(int i = 1;i <= n;++i) a[i] /= gcd;
return get() ^ 1;
}
int main() {
std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
rep(i, 1, n) cin >> a[i];
cout << (get() ? "First" : "Second") << '\n';
}
| 1 |
#include<stdio.h>
int main(){
int r,n,cnt=0;
scanf("%d",&n);
while(n>0){
r=n%10;
if(r==7){
printf("Yes");
cnt++;
break;
}
n=n/10;
}
if(cnt==0){
printf("No");
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
string h;
cin >> h;
if(h == "hi" || h == "hihi" || h == "hihihi" || h == "hihihihi" || h == "hihihihihi"){
cout << "Yes" << endl;
return 0;
}
cout << "No" << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;
int main(){
ll n;
cin >> n;
ll ans = mod;
for(ll i = 1; i*i <= n; i++){
if(n%i == 0){
ll a = to_string(n/i).size();
ll b = to_string(i).size();
ans = min(ans,max(a,b));
}
}
cout << ans << endl;
return 0;
} | /**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author Kein Yukiyoshi
*/
#include "bits/stdc++.h"
#define int long long
#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 FOR(i, a) for (auto &i : a)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
using namespace std;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI = acos(-1);
int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); } //always return positive num
int bpm(int a, int b) { //return x^y in order(log(y))
int res = 1;
for (a %= MOD; b; a = a * a % MOD, b >>= 1)
if (b & 1) res = res * a % MOD;
return res;
}
class CDigitsInMultiplication {
public:
static void solve(istream &cin, ostream &cout) {
int N;
cin >> N;
int ans = INF;
REP(i, 1, bpm(10, 5) + 1) {
if (N % i == 0) {
ans = min(ans, (int)max(log10(i) / 1 + 1, log10(N / i) / 1 + 1));
}
}
cout << ans << endl;
}
};
signed main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
cout<<fixed<<setprecision(15);
CDigitsInMultiplication solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define vt vector
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
const int maxn = 80, maxk = 1 << 14, init = 1 << 13;
bool dp[maxn][maxn][maxk];
int a[maxn][maxn];
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int t;
cin >> t;
a[i][j] = abs(t - a[i][j]);
}
}
dp[0][0][init - **a] = dp[0][0][init + **a] = true;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int &d = a[i][j];
for (int k = d; k < maxk - d; k++) {
bool &cur = dp[i][j][k];
if (i) {
auto &p = dp[i - 1][j];
if (p[k - d] || p[k + d]) cur = true;
}
if (j) {
auto &p = dp[i][j - 1];
if (p[k - d] || p[k + d]) cur = true;
}
}
}
}
int ans = 1 << 30;
for (int i = 0; i < maxk; i++) {
if (dp[n - 1][m - 1][i]) ans = min(ans, abs(i - init));
}
cout << ans;
}
| #include <cstdio>
typedef long long ll;
ll pos[100005], cnt[100005], ans;
void work(int l, int r, int s)
{
if (pos[r] < s)
ans += s - pos[l];
else if (pos[l] > s)
ans += pos[r] - s;
else
{
ans += pos[r] - pos[l];
if (cnt[l] >= cnt[r])
{
while (l < r && cnt[l] >= cnt[r])
cnt[l] += cnt[r--];
}
else
{
while (l < r && cnt[l] < cnt[r])
cnt[r] += cnt[l++];
}
work(l, r, s);
}
}
int main()
{
// freopen("AGC023-D.in", "r", stdin);
int n, s;
scanf("%d%d", &n, &s);
for (int i = 0; i < n; i++)
scanf("%lld%lld", pos + i, cnt + i);
work(0, n - 1, s);
printf("%lld\n", ans);
return 0;
}
| 0 |
#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef pair<int, int> P;
int main() {
int n; cin >> n;
map<int, int> odd, even;
for (int i = 1; i <= n; i++) {
int v; cin >> v;
if (i % 2) odd[v]++;
else even[v]++;
}
int o1 = 0, o2 = 0, odd_v;
for (auto ite = odd.begin(); ite != odd.end(); ite++) {
if (o1 < ite->second) {
o2 = o1;
o1 = ite->second;
odd_v = ite->first;
} else {
if (o2 < ite->second) o2 = ite->second;
}
}
int e1 = 0, e2 = 0, even_v;
for (auto ite = even.begin(); ite != even.end(); ite++) {
if (e1 < ite->second) {
e2 = e1;
e1 = ite->second;
even_v = ite->first;
} else {
if (e2 < ite->second) e2 = ite->second;
}
}
int ans;
if (odd_v == even_v) {
ans = min(n - o1 - e2, n - o2 - e1);
} else {
ans = n - o1 - e1;
}
cout << ans << endl;
} | #include <iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int MOD=998244353;
int adm(int x,int y){
return (x+y)%MOD;
}
int mim(int x,int y){
return (x-y+MOD)%MOD;
}
int t3m(int x){
int y=(x+x)%MOD;
return (x+y)%MOD;
}
//i番目まで使って和がjのものの個数
int dp[305][100000];
int dpx[305][100000];
int main(){
int N;
cin>>N;
int a[301];
int sum[301];
sum[0]=0;
rep1(i,N){
cin>>a[i];
sum[i]=sum[i-1]+a[i];
}
dp[0][0]=1;
rep(i,N){
rep(j,sum[i]+1){
dp[i+1][j]=adm(dp[i+1][j],dp[i][j]);
dp[i+1][j]=adm(dp[i+1][j],dp[i][j]);
dp[i+1][j+a[i+1]]=adm(dp[i+1][j+a[i+1]],dp[i][j]);
}
}
// rep(j,sum[N]+1)cout<<dp[N][j]<<" ";
// cout<<endl;
dpx[0][0]=1;
rep(i,N){
rep(j,sum[i]+1){
dpx[i+1][j]=adm(dpx[i+1][j],dpx[i][j]);
dpx[i+1][j+a[i+1]]=adm(dpx[i+1][j+a[i+1]],dpx[i][j]);
}
}
// rep(j,sum[N]+1)cout<<dpx[N][j]<<" ";
// cout<<endl;
int al=1;
rep(i,N){
al=t3m(al);
}
int ans=al;
int h=sum[N]/2;
if(sum[N]%2==1){
int ng=0;
for(int i=h+1;i<=sum[N];i++){
ng=adm(ng,dp[N][i]);
}
ng=t3m(ng);
ans=mim(ans,ng);
}
else{
int ng=0;
for(int i=h;i<=sum[N];i++){
ng=adm(ng,dp[N][i]);
}
ng=t3m(ng);
int cv=t3m(dpx[N][h]);
ans=adm(ans,cv);
ans=mim(ans,ng);
}
cout<<ans<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
int main() {
int n, h, w; cin >> n >> h >> w;
int a = n - h;
int b = n - w;
if(a < 0 || b < 0) {
cout << 0 << endl;
return 0;
}
a++;
b++;
cout << a * b << endl;
return 0;
}
| #include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
int n, h, w;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> h >> w;
int cnt = 0;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
if(i+h-1<=n && j+w-1<=n) cnt++;
cout << cnt;
return 0;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
char s[3];
cin>>s[0]>>s[1]>>s[2];
int max=0, locmax=0;
for(int i=0;i<3;i++){
if(s[i] == 'R'){
locmax++;
}
else{
locmax=0;
}
if(locmax>max){
max=locmax;
}
}
cout<<max;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5 , MOD = 1e9 + 7;
long long fact[N] , fact_inv[N];
int mul(long long a , long long b) {
return a * b % MOD;
}
long long power(long long a , long long b) {
if (!b) return 1;
long long r = power(a , b / 2);
r = mul(r , r);
if (b&1) return mul(r , a);
return r;
}
long long mod_inv(long long x) {
return power(x , MOD - 2);
}
long long nCr(long long n , long long r){
if (!n) return !r;
if(r>n) return 0;
return mul(fact[n] , mul(fact_inv[n - r] , fact_inv[r]));
}
void pre() {
fact[0] = fact_inv[0] = 1;
for(int i = 1 ; i < N ;i++) {
fact[i] = mul(fact[i - 1] , i);
fact_inv[i] = mod_inv(fact[i]);
}
}
int add (int a , int b) {
a += b;
while (a >= MOD) a -= MOD;
while (a < 0) a += MOD;
return a;
}
int main() {
ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
int n , m , k;
cin >> n >> m >> k;
pre();
int ans = 0;
for (int i = 1 ;i <= n ;i++) {
int ways = n - i + 1;
ways = mul(ways , mul(m , m - (i == 1)));
ways = mul(ways , nCr(n * 1ll * m - 2 , k - 2));
ans = add(ans , mul(ways , i - 1));
}
for (int i = 1 ;i <= m ;i++) {
int ways = m - i + 1;
ways = mul(ways , mul(n , n - (i == 1)));
ways = mul(ways , nCr(n * 1ll * m - 2 , k - 2));
ans = add(ans , mul(ways , i - 1));
}
cout << ans;
} | 0 |
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
const int INF = 1 << 24;
int main(void){
for(int n, m, s; s = 0, cin >> n >> m, n; cout << s << endl){
priority_queue<int> p;
rep(i, n){
int in; cin >> in;
p.push(in);
}
COUNT(i, n){
if(i % m) s += p.top();
p.pop();
}
}
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
int main(){
int n,m,x;
while(std::cin >> n >> m){
if(n == 0 && m == 0)
break;
int flag = 0;
int num = 0;
std::vector<int> v;
std::string line;
std::getline(std::cin, line);
if(std::getline(std::cin, line)){
std::istringstream ss(line);
while(ss >> x){
v.push_back(x);
}
}
sort(v.rbegin(),v.rend());
for(int y = 0;y < n;++y){
++flag;
if(flag != m){
num += v[y];
}
else
flag = 0;
}
std::cout << num << std::endl;
}
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
string a,b;
cin >> a >> b;
int len=0;
for(int i=0;i<n;i++){
bool ok=true;
for(int j=0;j<n-i;j++)
if(a.at(i+j)!=b.at(j))
ok=false;
if(ok)
len=max(n-i,len);
}
cout << n*2-len << endl;
return 0;
} | #include <iostream>
#include <cstring>
#include <cstdio>
#define Maxn 4010
#define Maxm 4010
using namespace std;
int read() {
int x = 0,f = 1;
char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while('0' <= c && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
int N,M,Q;
int mp[Maxn][Maxm],sum1[Maxn][Maxm],sum2[Maxn][Maxm];
int main() {
N = read(); M = read(); Q = read();
char ch;
for(int i = 1;i <= N; i++)
for(int j = 1;j <= M; j++) {
int x = i * 2 - 1,y = j * 2 - 1;
ch = getchar();
while(ch != '0' && ch != '1') ch = getchar();
if(ch == '1') mp[x][y] = 1;
}
for(int i = 1;i <= N; i++)
for(int j = 1;j <= M; j++) {
int x = i * 2 - 1,y = j * 2 - 1;
if(mp[x][y]) {
if(mp[x - 2][y]) mp[x - 1][y] = 2;
if(mp[x + 2][y]) mp[x + 1][y] = 2;
if(mp[x][y + 2]) mp[x][y + 1] = 2;
if(mp[x][y - 2]) mp[x][y - 1] = 2;
}
}
for(int i = 1;i < N * 2; i++)
for(int j = 1;j < M * 2; j++) {
if(mp[i][j] == 1) sum1[i][j] = sum1[i - 1][j] + sum1[i][j - 1] - sum1[i - 1][j - 1] + 1;
else sum1[i][j] = sum1[i - 1][j] + sum1[i][j - 1] - sum1[i - 1][j - 1];
if(mp[i][j] == 2) sum2[i][j] = sum2[i - 1][j] + sum2[i][j - 1] - sum2[i - 1][j - 1] + 1;
else sum2[i][j] = sum2[i - 1][j] + sum2[i][j - 1] - sum2[i - 1][j - 1];
}
int i_1,j_1,i_2,j_2,x_1,y_1,x_2,y_2;
for(int k = 1;k <= Q; k++) {
i_1 = read(); j_1 = read(); i_2 = read(); j_2 = read();
x_1 = i_1 * 2 - 1; y_1 = j_1 * 2 - 1;
x_2 = i_2 * 2 - 1; y_2 = j_2 * 2 - 1;
int ans1 = sum1[x_2][y_2] + sum1[x_1 - 1][y_1 - 1] - sum1[x_2][y_1 - 1] - sum1[x_1 - 1][y_2];
int ans2 = sum2[x_2][y_2] + sum2[x_1 - 1][y_1 - 1] - sum2[x_2][y_1 - 1] - sum2[x_1 - 1][y_2];
printf("%d\n",ans1 - ans2);
}
return 0;
} | 0 |
#include<map>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mp make_pair
using namespace std;
map<pair<int,int>,int> m;
struct dsu
{
int fa[200010],rank[200010];
void init(int n)
{
for(int i=1;i<=n;i++)
{
fa[i]=i;
}
}
int find(int x)
{
if(fa[x]==x)
{
return x;
}
return fa[x]=find(fa[x]);
}
void union_(int x,int y)
{
int fx=find(x);
int fy=find(y);
if(fx==fy)
{
return ;
}
if(rank[fx]<rank[fy])
{
fa[fx]=fy;
}
else
{
fa[fy]=fx;
if(rank[fx]==rank[fy])
{
rank[x]++;
}
}
}
int same(int x,int y)
{
return find(x)==find(y);
}
}a,b;
int main()
{
//give the fucking vjudge a flying fucking
int n,x,y;
scanf("%d%d%d",&n,&x,&y);
a.init(n);
b.init(n);
int from,to;
for(int i=1;i<=x;i++)
{
scanf("%d%d",&from,&to);
a.union_(from,to);
}
for(int i=1;i<=y;i++)
{
scanf("%d%d",&from,&to);
b.union_(from,to);
}
for(int i=1;i<=n;i++)
{
m[mp(a.find(i),b.find(i))]++;
}
for(int i=1;i<=n;i++)
{
printf("%d ",m[mp(a.find(i),b.find(i))]);
}
} | #include <iostream>
using namespace std;
void pri(string s,int a,int b){
cout << s.substr(a,b-a+1) << endl;
}
string rep(string s,int a, int b, string r){
for(int i=a; i<=b; i++){
s[i] = r[i-a];
}
return s;
}
string rev(string s, int a, int b){
string tmp = s;
for(int i=a; i<=b; i++){
s[i] = tmp[b+a-i];
}
return s;
}
int main(){
int n;
string s;
cin >> s >> n;
for(int i=0; i<n; i++){
string ope,tar; cin >> ope;
int a,b;
// cout << ope <<endl;
if(ope == "replace"){
cin >> a >> b >> tar;
s = rep(s,a,b,tar);
}
if(ope == "print"){
cin >> a >> b;
pri(s,a,b);
}
if(ope == "reverse"){
cin >> a >> b;
s = rev(s,a,b);
}
}
} | 0 |
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
char a[3][3];
char b[4][4];
string c[5];
int main(){
a[0][0] = 'a'; a[0][1] = 'a'; a[0][2] = 'c';
a[1][0] = 'b'; a[1][1] = '.'; a[1][2] = 'c';
a[2][0] = 'b'; a[2][1] = 'd'; a[2][2] = 'd';
b[0][0] = 'a'; b[0][1] = 'a'; b[0][2] = 'c'; b[0][3] = 'd';
b[1][0] = 'b'; b[1][1] = 'b'; b[1][2] = 'c'; b[1][3] = 'd';
b[2][0] = 'c'; b[2][1] = 'd'; b[2][2] = 'a'; b[2][3] = 'a';
b[3][0] = 'c'; b[3][1] = 'd'; b[3][2] = 'b'; b[3][3] = 'b';
c[0] = "a.eef";
c[1] = "ab..f";
c[2] = ".bggi";
c[3] = "cch.i";
c[4] = "ddhjj";
int n;
cin >> n;
if(n<=2) puts("-1");
else if(n == 7){
cout <<
"aa...bc" << endl <<
"....dbc" << endl <<
"eeffd.." << endl <<
".abbcc." << endl <<
".a..edd" << endl <<
"g...e.f" << endl <<
"g.hh..f" << endl;
}
else if(n == 11){
cout <<
"aa.......bc" << endl <<
"........dbc" << endl <<
"aabb....d.." << endl <<
"c...ddee..." << endl <<
"c......aabb" << endl <<
".cde......." << endl <<
".cde......." << endl <<
"....abc...." << endl <<
"....abc...." << endl <<
"..dd..ee..c" << endl <<
"....aa..bbc" << endl;
}
else if(n%3 == 0){
string ans[1005];
rep(i,n) rep(j,n) ans[i].pb('.');
rep(i,n/3){
int x = i*3, y = i*3;
rep(aa,3)rep(b,3){
ans[x+aa][y+b] = a[aa][b];
}
}
rep(i,n) cout << ans[i] << endl;
}
else{
string ans[1005];
rep(i,n) rep(j,n) ans[i].pb('.');
rep(aaa,n) rep(bbb,n){
if(4*aaa+5*bbb == n){
int cur = 0;
rep(i,aaa){
rep(aa,4)rep(bb,4) ans[cur+aa][cur+bb] = b[aa][bb];
cur += 4;
}
rep(i,bbb){
rep(aa,5)rep(bb,5) ans[cur+aa][cur+bb] = c[aa][bb];
cur += 5;
}
rep(i,n) cout << ans[i] << endl;return 0;
}
}
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int num;
int tmpCnt1,tmpCnt2;
int Max1 = 0, Max2 = 0;
string str1, str2;
cin >> num >> str1 >> str2;
if(str1 == str2){
cout << num;
return 0;
}
for(int i = 0; i < num; i++){
tmpCnt1 = 0;
if(str1.at(i) == str2.at(0)){
for(int j = 0; j < num - i; j++){
if(str1.at(i+j) == str2.at(j)) tmpCnt1++;
else break;
}
Max1 = max(Max1, tmpCnt1);
}
}
for(int i = 0; i < num; i++){
tmpCnt2 = 0;
if(str2.at(i) == str1.at(0)){
for(int j = 0; j < num - i; j++){
if(str2.at(i+j) == str1.at(j)) tmpCnt2++;
else break;
}
Max2 = max(Max2, tmpCnt2);
}
}
if(Max1 == 0 && Max2 == 0){
cout << num * 2;
}else if(Max1 >= Max2){
cout << num + (num - Max1);
}else{
cout << num + (num - Max2);
}
}
| 0 |
#include<cstdio>
long double sqrt(double);
int main(void){
long double d;
double x1,y1,x2,y2,D;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
D=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
sqrt(D);
d=sqrt(D);
printf("% 8.8Lf\n",d);
return 0;
}
long double sqrt(double a){
int i;
long double b=3;
for(i=0;i<256;i++){
b=(b/2)+(a/(2*b));
}
return b;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
int main()
{
double x1, y1, x2, y2;
fscanf(stdin, "%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
fprintf(stdout, "%.9f\n", hypot(x1 - x2, y1 - y2));
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
ll N, X;
cin >> N >> X;
vector<ll> A(N);
for (int i = 0; i < N; i++){
cin >> A.at(i);
}
sort(A.begin(), A.end());
ll ans = 0;
while (true){
if (X >= A.at(ans)){
X -= A.at(ans);
ans++;
if (ans == N){
if (X > 0){
ans--;
}
break;
}
}
else{
break;
}
}
cout << ans << endl;
} | #include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a) (a).begin(),(a).end()
#define REP(i,n) for(int i=0;i<(n);++i)
const double EPS = 1e-10;
const double PI = acos(-1.0);
#define dump(x) cerr << " (L" << __LINE__ << ") " << #x << " = " << (x) << endl;
#define dumpv(x) cerr << " (L" << __LINE__ << ") " << #x << " = "; REP(q,(x).size()) cerr << (x)[q] << " "; cerr << endl;
template<typename T1, typename T2>
ostream& operator<<(ostream& s, const pair<T1, T2>& d) {return s << "(" << d.first << "," << d.second << ")";}
int main() {
string s;
while (getline(cin, s)) {
string orig;
for (int i = 0; i <= 'z'-'a'; i++) {
orig = s;
for (int j = 0; j < orig.size(); j++) {
if (orig[j] >= 'a' && orig[j] <= 'z') {
orig[j] = 'a' + ((orig[j]-'a') + i) % ('z'-'a'+1);
}
}
if (orig.find("the") != string::npos ||
orig.find("this") != string::npos ||
orig.find("that") != string::npos) {
break;
}
}
cout << orig << endl;
}
} | 0 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n;i++)
using pii = pair<int,int>;
using piii = pair<pii,int>;
using ll = long long;
#define int ll
signed main(){
int v,e; cin>>v>>e;
vector<piii>edge;
rep(i,e){
int a,b,c; cin>>a>>b>>c;
edge.push_back(piii(pii(a,b),c));
}
vector<string>ans;
rep(s,v){
vector<int>d(v,LLONG_MAX/1000);
d[s]=0;
rep(i,v){
bool update=false;
rep(j,e){
int to,from,cost;
to=edge[j].first.second;
from=edge[j].first.first;
cost=edge[j].second;
if(d[from]==LLONG_MAX/1000)continue;
if(d[to]>d[from]+cost){
d[to]=d[from]+cost;
update=true;
}
}
if(i==v-1&&update==true) return puts("NEGATIVE CYCLE")*0;
}
string temp;
rep(i,v){
if(i)temp+=" ";
if(d[i]==LLONG_MAX/1000)temp+="INF";
else temp+=(to_string(d[i]));
}
ans.push_back(temp);
}
rep(i,v)cout<<ans[i]<<endl;
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;
int d[101][101];
int inf=INT_MAX;
int v;
int warshall_floyd(){
rep(k,v)rep(i,v)rep(j,v){
if(d[i][k]==inf||d[k][j]==inf)continue;
d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
}
}
int main(){
int e,r,s,t,ds;
cin>>v>>e;
rep(i,v)rep(j,v) d[i][j]=inf;
rep(i,v) d[i][i]=0;
rep(i,e){
cin>>s>>t>>ds;
d[s][t]=ds;
}
warshall_floyd();
rep(i,v){
if(d[i][i]<0){
cout<<"NEGATIVE CYCLE"<<endl;
break;
}
else if(i==v-1){
rep(j,v){
rep(k,v){
if(d[j][k]<inf) cout<<d[j][k];
else cout<<"INF";
if(k==v-1) cout<<endl;
else cout<<" ";
}
}
}
}
return 0;
} | 1 |
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
#define ref goto refrain
class dice{
public:
int o,u,s,e,n,w;//over,under,south,east,north,west
void change(char a);
};
void dice::change(char a){
int tem=o;
if(a=='S'){
o=n; n=u; u=s; s=tem;
}
else if(a=='E'){
o=w; w=u; u=e; e=tem;
}
else if(a=='N'){
o=s; s=u; u=n; n=tem;
}
else if(a=='W'){
o=e; e=u; u=w; w=tem;
}
else{
cout<<"Error!"<<endl;
exit(0);
}
}
int main(){
dice a;
cin>>a.o>>a.s>>a.e>>a.w>>a.n>>a.u;
char com[100];
cin>>com;
int m=strlen(com);
for(int i=0;i<m;i++){
a.change(com[i]);
}
cout<<a.o<<endl;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5+5, MOD = 998244353;
int n, m, k, p[N];
int mul(int x, int y) {
ll tmp = 1LL * x * y;
return tmp % MOD;
}
int add(int x, int y) {
ll tmp = 1LL*x + 1LL*y;
return tmp % MOD;
}
int pow(int x, int e) {
int res = 1;
for(; e; e>>=1) {
if(e&1) res = mul(res, x);
x = mul(x, x);
}
return res;
}
int inv(int x) {
return pow(x, MOD-2);
}
int C(int x, int y) {
int det = mul(p[x], p[y-x]);
return mul(p[y], inv(det));
}
void preprocess() {
p[0] = 1;
for(int i=1; i<N; i++)
p[i] = mul(p[i-1], i);
}
int main() {
preprocess();
cin >> n >> m >> k;
int ans = 0;
for(int t=n-k; t<=n; t++) {
int tmp = mul(m, pow(m-1, t-1));
tmp = mul(tmp, C(n-t, n-1));
ans = add(ans, tmp);
}
cout << ans;
} | 0 |
#include <bits/stdc++.h>
#define sz(c) int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;
int const MAXN=2.2e6;
int const MD=998244353;
int madd(int x,int y) {
if (x+y<MD) return x+y; else return x+y-MD;
}
int msub(int x,int y) {
if (x-y>=0) return x-y; else return x-y+MD;
}
int mmul(int x,int y) {
return int(ll(x)*y % MD);
}
int mpow(int x,int p) {
int res=1;
while (p>0) {
if (p%2) res=mmul(res,x);
x=mmul(x,x);
p/=2;
}
return res;
}
int minv(int x) {
return mpow(x,MD-2);
}
int mdiv(int x,int y) {
return mmul(x,mpow(y,MD-2));
}
struct mod_fact {
vector<int> f,rf;
mod_fact(int n):f(n),rf(n) {
f[0]=rf[0]=1;
rep(i,1,n) {
f[i]=mmul(f[i-1],i);
rf[i]=minv(f[i]);
}
}
} mfact(MAXN);
int comb(int n,int k) {
if (n<k) return 0;
return mmul(mfact.f[n],mmul(mfact.rf[n-k],mfact.rf[k]));
}
int distr(int n,int k) {
return comb(n+k-1,k-1);
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cout<<fixed<<setprecision(10);
int N,M;
cin>>N>>M;
int res=0;
rep(i,0,min(N,M)+1) if ((3*M-i)%2==0) {
int add=mmul(comb(N,i),distr((3*M-i)/2,N));
res=madd(res,add);
}
rep(i,0,min(N,M)+1) if ((M-i)%2==0) {
int sub=mmul(comb(N,i),distr((M-i)/2,N));
res=msub(res,mmul(sub,N));
}
rep(i,0,min(N,M)+1) if ((M-i)%2==0) {
int add=mmul(comb(N-1,i),distr((M-i)/2,N-1));
res=madd(res,mmul(add,N));
}
cout<<res<<'\n';
}
| #include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#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 in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'
const int MAXN = 2522222;
ll fact[2522222];
ll rfact[2522222];
ll mod_pow(ll x, ll p, ll M = MOD) {
ll a = 1;
while (p) {
if (p % 2)
a = a*x%M;
x = x*x%M;
p /= 2;
}
return a;
}
ll mod_inverse(ll a, ll M = MOD) {
return mod_pow(a, M - 2, M);
}
void set_fact(ll n, ll M = MOD) {
fact[0] = fact[1] = rfact[0] = rfact[1] = 1;
for (ll i = 2; i <= n; i++) {
fact[i] = i * fact[i - 1] % M;
rfact[i] = mod_inverse(fact[i], M);
}
}
//http://drken1215.hatenablog.com/entry/2018/06/08/210000
//nが大きくfactが計算できないときのほかの計算方法について書いてある
ll nCr(ll n, ll r, ll M = MOD) {
if (r > n) return 0;
ll ret = fact[n];
ret = (ret*rfact[r]) % M;
ret = (ret*rfact[n - r]) % M;
return ret;
}
ll nHr(ll n, ll r) {
return nCr(n+r-1, r);
}
ll guchoku(ll n, ll m) {
vll dp(n + 1, vl(3*m + 1));
dp[0][0] = 1;
rep (i, n) {
rep (j, 3*m + 1) {
for (int add = 0; add <= 2*m; add++) {
if (j + add > 3*m) break;
(dp[i + 1][j + add] += dp[i][j]) %= MOD;
}
}
}
return dp[n][3*m];
}
int main() {
ll n, m;
cin >> n >> m;
set_fact(2522221);
ll zen = nHr(3*m + 1, n - 1);
for (int x = 0; x < m; x++) {
ll sub = nHr(x + 1, n - 1);
if (3*m - 2*x > n) {
sub = 0;
}
else {
sub *= nCr(n, 3*m - 2*x);
sub %= MOD;
}
zen -= sub;
}
for (int x = 2*m + 1; x <= 3*m; x++) {
ll sub = n;
ll m2 = 3*m - x;
sub = sub * nHr(m2 + 1, (n - 1) - 1) % MOD;
(zen -= sub) %= MOD;
}
zen = (zen + MOD) % MOD;
cout << zen << endl;
//DEBUG(guchoku(n, m));
}
| 1 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
int main(void){
while(true){
int n;
cin >> n;
if(n == 0){ break; }
vector<pair<double, string> > moonlight;
string l;
int p, a, b, c, d, e, f, s, m;
for(int i = 0; i < n; i++){
cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
int income = f * m * s - p;
int time = a + b + c + (d + e) * m;
moonlight.push_back(make_pair(-income/(double)time, l));
}
sort(moonlight.begin(), moonlight.end());
for(int i = 0; i < n; i++){ cout << moonlight[i].second << endl; }
cout << "#" << endl;
}
return 0;
} | #include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;
struct Data{
long double x;
long double y;
};
int main(){
int N;
cin>>N;
vector<Data>data(N);
double countmax=1;
for(double i=0;i<=N-1;i++){
cin>>data[i].x>>data[i].y;
countmax*=i+1;
}
double x;
double x2;
double y;
double y2;
vector<double>P(N);
for(int i=0;i<=N-1;i++)P[i]=i+1;
double ave=0;
do{
for(int i=0;i<=N-2;i++){
x=data[P[i]-1].x;
x2=data[P[i+1]-1].x;
y=data[P[i]-1].y;
y2=data[P[i+1]-1].y;
ave+=sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2));
}
}while(next_permutation(P.begin(),P.end()));
ave/=countmax;
cout<< fixed << setprecision(15)<<ave;
return 0;
} | 0 |
#include <iostream>
using namespace std;
int main(void){
string s;
cin >> s;
cout << "2018/";
for (int i=0; i<s.size(); i++) {
if (i > 4) cout << s.at(i);
}
cout << endl;
}
| #include<iostream>
using namespace std;
int main()
{
int n;
int i;
cin >> n;
for(i=1;i<=n;i++){
if(i%3==0)
cout << ' ' << i;
else if(i%10==3)
cout << ' ' << i;
else if((i/10)%10==3)
cout << ' ' << i;
else if((i/100)%10==3)
cout << ' ' << i;
else if((i/1000)%10==3)
cout << ' ' << i;
}
cout << endl;
return 0;
} | 0 |
#include <iostream>
using namespace std;
int main()
{
string s;
cin>>s;
int sum=0;
int count=0;
for(int i=0;i<s.size();i++)
{
if(s[i]=='R')
sum++;
else
sum=0;
if(sum>count)
count=sum;
}
cout<<count<<endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REP(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define REP1(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Int = long long;
//INT_MAX = 2147483647;
//LLONG_MAX = 9223372036854775807;
//ULLONG_MAX = 18446744073709551615;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;
//少数点表示
//cout << std::fixed << std::setprecision(14) << 値
int main(){
cin.tie( 0 ); ios::sync_with_stdio( false );
string s;
cin >> s;
int cnt;
if(s[0]=='R' && s[1]=='R' && s[2]=='R') cnt = 3;
else if((s[0]=='R' && s[1]=='R' ) || (s[1]=='R' && s[2]=='R')) cnt = 2;
else if(s[0]=='R' || s[1]=='R' || s[2]=='R') cnt = 1;
else cnt = 0;
cout << cnt <<endl;
return 0;
} | 1 |
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
using ll = long long;
class Stream{
public:
Stream(){
}
//配列以外の入力を受け取る
void read(){
}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
cin >> first;
read(rest...);
}
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
for(size_t i = 0; i < v.size(); i++){
cout << v[i] << divider;
}
}
};
int main(){
Stream io;
string S;
io.read(S);
string ans = "AC";
if(S[0] != 'A') ans = "WA";
int c = 0;
for(int i = 1; i < S.size(); i++){
if(!(S[i] <= 'z' && S[i] >= 'a')){
if(i <= S.size() - 2 && i >= 2){
c++;
}
else ans = "WA";
}
}
if(c != 1) ans = "WA";
cout << ans;
return 0;
} | #include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
using namespace std;
using ll = long long;
typedef vector<int> vi;
int main(){
string s;
cin >> s;
bool OK_A = false;
bool OK_C = false;
bool OK_lower = true;
int cnum;
if(s[0] == 'A') OK_A = true;
rep(i, s.size()-1){
if(i != 1){
if(s[i] == 'C'){
cnum = i;
if(OK_C == false) OK_C = true;
else OK_C = false;
}
}
}
rep(i, s.size()){
if(i != 0 && i != cnum){
if(isupper(s[i])) OK_lower = false;
}
}
if(OK_A && OK_C && OK_lower) cout << "AC" << endl;
else cout << "WA" << endl;
return 0;
} | 1 |
#include<bits/stdc++.h>
int main(){
using namespace std;
constexpr unsigned long MOD = 1000000007;
auto f = [&MOD](auto& a, auto k){(a.second += (a.first += a.second * k) %= MOD) %= MOD; return a.first;};
unsigned long N;
cin >> N;
vector<pair<pair<unsigned long, unsigned long>, unsigned long>> tapi(1048576, {{1, 0}, 0});
unsigned long ans{0}, t{500000004}, a{0}, z{0};
for(unsigned long i = 1, A; i <= N; ++i){
cin >> A;
if(a ^= A){
ans += f(tapi[a].first, z - tapi[a].second);
tapi[a].second = z;
}else ++z, (t *= 2) %= MOD;
}
cout << (a ? tapi[a].first.first : (ans + t) % MOD) << endl;
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a)
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
if(!b) return 1;
int tmp=Pow(a*a%MOD,b>>1);
return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
const int maxn=100005;
//i_am_noob
int n,goal,a[10][2],cnt,x,ans=4e18;
bool flag;
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cin >> n >> goal;
rep(n) rep1(j,2) cin >> a[i][j];
rep(pow2(n)){
cnt=x=0;
rep1(j,n) if(i&pow2(j)){
x+=a[j][0];
cnt+=a[j][0]*(j+1)*100+a[j][1];
}
if(cnt>=goal){
ans=min(ans,x);
continue;
}
flag=false;
rep3(j,n-1,0) if((i&pow2(j))==0){
rep1(k,a[j][0]){
x++;
cnt+=(j+1)*100;
if(cnt>=goal){
ans=min(ans,x);
flag=true;
break;
}
}
if(flag) break;
}
}
print1(ans);
return 0;
}
| 0 |
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
int hour[3];
cin >> hour[0] >> hour[1] >> hour[2];
int ans = 1000;
for (int i = 0; i < 2; i++) {
for (int j = i + 1; j < 3; j++) {
ans = min(ans, hour[i] + hour[j]);
}
}
cout << ans << endl;
return 0;
} | /*
@uthor: Amit Kumar
user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
ll google_itr = 1;
#define google(x) cout<<"Case #"<<x<<":"
#define pi 3.14159265358979323846264338327950L
const ll mod = 1e9+7;
const ll inf = 1e18;
ll popcount(ll num){
num = num - ((num >> 1) & 0x55555555);
num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
vector<pair<ll,ll>> factor_arr;
void myfactor(ll num){
ll count = 0;
while (!(num % 2)) {
num >>= 1; count++;
}
if (count) factor_arr.push_back({2,count});
for (auto i = 3; i <= sqrt(num); i += 2) {
count = 0;
while (num % i == 0) {
count++;
num /= i;
}
if (count) factor_arr.push_back({i,count});
}
if (num > 2) factor_arr.push_back({num,1});
}
void virus(){
ll a,b,c;
cin>>a>>b>>c;
cout<<min({a+b,b+c,a+c});
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif*/
ll t=1;
//cin>>t;
while(t--){
auto start = high_resolution_clock::now();
virus();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<seconds>(stop - start);
//cout << "Time: "<<duration.count()<<endl;
//your code goes here
}
return 0;
} | 1 |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f(a, b) for (ll i = a; i <= b; i++)
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;
#define N 200005
const ll INF = 1000000000000000001;
const ll MOD = 1000000000;
//vector< vector<ll> > g(N);
//vector< pair<ll, pair< ll, ll > > > g(N);
//ll vis[N] = {0}, par[N] = {0}, child[N] = {0},cnt = 0;
void solve(){
ll n; cin >> n;
ll ans =0;
ll a[n] ;
f(0, n-1) cin >> a[i];
f(1, n-1){
if(a[i] < a[i-1]) ans += a[i-1]-a[i], a[i] += (a[i-1]-a[i]);
}
cout << ans << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
//ll t;cin >> t;for(ll index=1; index<=t; index++){
//cout << "Case #" << index << ": " ;
solve();
//}
return 0;
} | #include<bits/stdc++.h>
#define int long long int
#define mod 998244353
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output1.txt","w", stdout);
#endif
int n;
cin>>n;
int a[n];
for (int i = 0; i < n; ++i)
{
cin>>a[i];
}
int ans=0,s;
s=a[0];
for (int i = 1; i < n; ++i)
{
s=max(s,a[i]);
ans+=(s-a[i]);
}
cout<<ans;
#ifndef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
} | 1 |
#include <iostream>
#include <vector>
#include <set>
using namespace std;
// http://www.prefield.com/algorithm/misc/dice.html
enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
class dice {
public:
dice(int top,int front,int right,int left,int back,int bottom) {
id[TOP] = top; id[FRONT] = front; id[RIGHT] = right;
id[LEFT] = left; id[BACK] = back; id[BOTTOM] = bottom;
}
int& operator[] (FACE f) { return id[f]; }
const int& operator[] (FACE f) const { return id[f]; }
bool operator==(const dice &b) const {
const dice &a = *this;
return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
}
void roll_north() { roll(TOP, FRONT, BOTTOM, BACK); }
void roll_south() { roll(TOP, BACK, BOTTOM, FRONT); }
void roll_east() { roll(TOP, LEFT, BOTTOM, RIGHT); }
void roll_west() { roll(TOP, RIGHT, BOTTOM, LEFT); }
void roll_right() { roll(FRONT, LEFT, BACK, RIGHT); }
void roll_left() { roll(FRONT, RIGHT, BACK, LEFT); }
void all_rolls(set<long long> &s){
for (int k = 0; k < 6; (k&1?roll_east():roll_north()),++k)
for (int i = 0; i < 4; roll_right(), ++i)
s.insert(((long long)id[TOP]<<40) | ((long long)id[FRONT]<<32) | (id[RIGHT]<<24) | (id[LEFT]<<16) | (id[BACK]<<8) | (id[BOTTOM]<<0));
}
private:
void roll(FACE a, FACE b, FACE c, FACE d){
int tmp = id[a];
id[a] = id[b]; id[b] = id[c];
id[c] = id[d]; id[d] = tmp;
}
int id[6];
};
int main(){
int n,d[6];
cin>>n;
int i,j;
set<long long>s;
for(i=0;i<n;i++){
for(j=0;j<6;j++)cin>>d[j];
long long x=((long long)d[0]<<40) | ((long long)d[1]<<32) | (d[2]<<24) | (d[3]<<16) | (d[4]<<8) | (d[5]<<0);
if(s.find(x)!=s.end()){
cout<<"No"<<endl;
return 0;
}else{
dice di(d[0],d[1],d[2],d[3],d[4],d[5]);
di.all_rolls(s);
}
}
cout<<"Yes"<<endl;
} | #include <bits/stdc++.h>
using namespace std;
inline char shift(char c, int i) {
return char(((c + i) - 'a') % 26 + 'a');
}
int main() {
string str;
while (getline(cin, str)) {
int n;
for (int i = 0; i < 26; ++i) {
string target;
for (char c : str) {
if ('a' <= c && c <= 'z')
target += shift(c, i);
else
target += c;
}
for (string key : {"the", "this", "that"}) {
size_t pos = target.find(key);
if (pos != string::npos) {
n = i;
str = target;
goto found;
}
}
}
found:
cout << str << endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s; cin >> s;
map<char,vector<int>> dist;
for(int i=0; i< s.size(); i++){
dist[s.at(i)].push_back(i);
}
/*ここからアンバランス探しmapにはアルファベットと出現箇所が紐づけ
各アルファベットについて、隣り合ってたらok
*/
bool seikai = false;
for(auto& a: dist ){
if(a.second.size()>1){
for(int i=0; i< a.second.size() - 1; i++ ){
if((a.second[i+1] - a.second[i] ==1) ||
(a.second[i+1] - a.second[i]==2)){
cout << a.second[i] +1<< " " << a.second[i+1] +1;
seikai = true;
goto Finish;
}
}
}
}
Finish:
if(!seikai){cout << -1 << " " << -1;}
cout << endl;
}
| #include <iostream>
#include <string>
using namespace std;
int main(){
string s, strCopy;
while (getline(cin, s)) {
for(int j=0 ; j<26 ; j++){
for(int i=0 ; i<s.size() ; i++){
if(s[i]>='a' && s[i]<='z'){
s[i] = (s[i]=='z')? 'a' : s[i] + 1;
}
}
if( s.find( "the" ) != string::npos || s.find( "this" ) != string::npos || s.find( "that" ) != string::npos){
cout << s << endl;
}
}
}
return 0;
} | 0 |
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct node{
long long num,p;
}a[100010];
int s,n;
long long ans;
bool cmp(node a,node b)
{
return a.p<b.p;
}
int main()
{
scanf("%d%d",&n,&s);
for(int i=1;i<=n;i++)
scanf("%d%d",&a[i].p,&a[i].num);
sort(a+1,a+n+1,cmp);
int L=1,R=n;
int bef=-1;
while(a[L].p<=s && a[R].p>=s)
{
int now;
if(a[L].num>=a[R].num)
{
now=false;
a[L].num+=a[R].num;
}
else
{
now=true;
a[R].num+=a[L].num;
}
if(now!=bef)
{
ans+=a[R].p-a[L].p;
bef=now;
}
if(a[L].num>=a[R].num) R--;
else L++;
}
if(a[L].p<s) ans+=s-a[L].p;
else ans+=a[R].p-s;
printf("%lld",ans);
return 0;
} | //by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
char s[100000];
int it, len;
fastio() {it=len=0;}
inline char get()
{
if (it<len) return s[it++]; it=0;
len=fread(s, 1, 100000, stdin);
if (len==0) return EOF; else return s[it++];
}
bool notend()
{
char c=get();
while (c==' '||c=='\n') c=get();
if (it>0) it--;
return c!=EOF;
}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
ll r=0; bool ng=0; char c; c=_buff.get();
while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
if (c=='-') ng=1, c=_buff.get();
while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
if (x<0) putchar('-'), x=-x;
register short a[20]={}, sz=0;
while (x) a[sz++]=x%10, x/=10;
if(sz==0) putchar('0');
for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxn = 100111;
int n;
ll X[maxn], P[maxn], S;
struct movement
{
ll pos, ans;
movement move(ll x)
{
movement ret;
ret.ans = ans+abs(x-pos);
ret.pos = x;
return ret;
}
};
movement solve(int l, int r, ll dl, ll dr)
{
if (S<=X[l]) return movement({X[r], X[r]-S});
if (X[r]<=S) return movement({X[l], S-X[l]});
if (P[l]+dl<P[r]+dr)
{
return solve(l+1, r, 0, dl+dr+P[l]).move(X[l]);
}
else
{
return solve(l, r-1, dl+dr+P[r], 0).move(X[r]);
}
}
int main()
{
getii(n, S);
for (int i=1; i<=n; i++) getii(X[i], P[i]);
cout<<solve(1, n, 0, 0).ans<<endl;
return 0;
}
| 1 |
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
int main() {
int h, w;
cin >> h >> w;
int a, b;
cin >> a >> b;
int one = 1;
int zero = 0;
bool yes = true;
rep(i, h) {
if (i >= b && yes) {
swap(zero, one);
yes = false;
}
rep(j, w) {
if(j < a) cout << one;
else cout << zero;
}
cout << endl;
}
} | #include <stdio.h>
typedef long long ll;
int main(void) {
ll i, j, k, h, w, a, b;
scanf("%lld%lld%lld%lld", &h, &w, &a, &b);
for(i = 0; i < h; ++i) {
for(j = 0; j < w; ++j) printf("%d", (i < b) ^ (j < a));
printf("\n");
}
return 0;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define wi(t) int t;cin>>t;while(t--)
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
uniform_int_distribution<int> uid(0,lim-1);
return uid(rang);
}
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================
vi g[N];
int a[N];
void solve()
{
string s;
cin>>s;
string ans;
int diff=INT_MAX;
for(int i=0;i<3;i++)
ans+=s[i];
diff=min(diff,abs(stoi(ans)-753));
for(int i=3;i<s.length();i++)
{
ans.erase(ans.begin());
ans.pb(s[i]);
diff=min(diff,abs(stoi(ans)-753));
}
cout<<diff<<endl;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
srand(chrono::high_resolution_clock::now().time_since_epoch().count());
// wi(t)
{
solve();
}
return 0;
}
int mpow(int base, int exp) {
base %= mod;
int result = 1;
while (exp > 0) {
if (exp & 1) result = ((ll)result * base) % mod;
base = ((ll)base * base) % mod;
exp >>= 1;
}
return result;
}
void ipgraph(int n, int m){
int i, u, v;
while(m--){
cin>>u>>v;
u--, v--;
g[u].pb(v);
g[v].pb(u);
}
}
void dfs(int u, int par){
for(int v:g[u]){
if (v == par) continue;
dfs(v, u);
}
}
| #include<iostream>
#include<string>
using namespace std;
int main() {
string s;
cin >> s;
int mini = 10000;
for (int i = 0; i < s.length()-2; i++) {
int x = atoi(s.substr(i, 3).c_str());
mini = min(abs(x - 753), mini);
}
cout << mini << endl;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n;
cin >> n;
bool ok=false;
long long i=1;
while(!ok){
if(i*i>n){
cout << (i-1)*(i-1) << endl;
ok=true;
}
i++;
}
return 0;
}
| #include<iostream>
//#include<CastingInterop.h>
#include<string>
#include<array>
#include<math.h>
#include<sstream>
using namespace std;
int main()
{
int num1,num3;
cin >> num1;
num3 = sqrt(num1);
if (num3 % 10 != 0)
{
num3 = sqrt(num1);
cout << num3 * num3;
}
else
{
cout << num3 * num3;
}
} | 1 |
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;
int main()
{
string S, T;
cin >> S >> T;
cout << T + S << endl;
return 0;
}
| #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)
#define MP(a,b) make_pair(a,b)
ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);
template<typename T>
void debug(T& obj) {
debug(obj, true);
}
template<typename T>
void debug(T& obj, bool lnFlag) {
if (!debugFlag) return;
cout << obj;
if (lnFlag) cout << endl;
}
template<typename T>
void debug(vector<T>& obj) {
debug(obj, true);
}
template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
if (!debugFlag) return;
cout << "[";
rep(i, obj.size()) {
if (i != 0) cout << ",";
debug(obj[i], false);
}
cout << "]";
if (lnFlag) cout << endl;
}
template<typename T, typename U>
void debug(pair<T, U>& obj) {
debug(obj, true);
}
template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
if (!debugFlag) return;
cout << "(";
debug(obj.first, false);
cout << ",";
debug(obj.second, false);
cout << ")";
if (lnFlag) cout << endl;
}
void solve() {
string S,T;
cin >> S >> T;
cout << T << S;
}
int main(int argc, char* argv[]) {
if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
solve();
return 0;
} | 1 |
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a)
const int inf=1e18;
inline int in(){int x;scanf("%lld",&x);return x;}
#define x first
#define y second
int32_t main()
{
int n=in();
vector<vector<pair<int,int>>> g(n);
int u,v,w;
for(int i=1;i<n;i++)
{
u=in();v=in();w=in();
u--;v--;
g[u].push_back({v,w});
g[v].push_back({u,w});
}
int Q=in();int K=in();K--;
queue<int> q;
q.push(K);
vector<int> dis(n,inf);
dis[K]=0;
while(!q.empty())
{
u=q.front();
q.pop();
for(auto v:g[u])
{
if(dis[v.x]!=inf)continue;
dis[v.x]=min(dis[v.x],dis[u]+v.y);
q.push(v.x);
}
}
while(Q--)
{
u=in();v=in();
cout<<dis[u-1]+dis[v-1]<<"\n";
}
} | #include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T>
map<T, T> getPrimeFactor(T n) {
map<T, T> res;
for (T i = 2; i * i <= n; ++i) {
while (n % i == 0) {
res[i] ++;
n /= i;
}
}
if (n != 1) res[n] = 1;
return res;
}
template<typename T>
bool IsPrimeNumber(T num)
{
if (num <= 2) return true;
else if (num % 2 == 0) return false;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2)
{
if (num % i == 0)
{
return false;
}
}
return true;
}
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)
int main() {
ll N;
std::cin >> N;
vector<map<ll, ll>> dic(N+1);
rep(i, 1, N) {
ll a, b, c;
std::cin >> a >> b >> c;
dic[a][b] = c;
dic[b][a] = c;
}
ll Q, K;
std::cin >> Q >> K;
vll cost(N+1, 999999999999999);
cost[K] = 0;
vector<bool> isVisited(N + 1, false);
priority_queue<pair<ll, ll>> pq;
pq.push({ 0,K });
while (!pq.empty()) {
if (!isVisited[pq.top().second]) {
isVisited[pq.top().second] = true;
ll c = pq.top().first;
ll pos = pq.top().second;
pq.pop();
for (auto itr = dic[pos].begin(); itr != dic[pos].end(); itr++) {
if (c + itr->second < cost[itr->first]) {
cost[itr->first] = c + itr->second;
pq.push({ cost[itr->first],itr->first });
}
}
}
}
rep(i, 0, Q) {
ll x, y;
std::cin >> x >> y;
std::cout << cost[x] + cost[y] << endl;
}
return 0;
}
| 1 |