code_file1
stringlengths 80
4k
| code_file2
stringlengths 91
4k
| similar_or_different
int64 0
1
|
---|---|---|
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long long int LL;
#define st first
#define nd second
#define pb push_back
#define PLL pair <LL, LL>
#define PII pair <int, int>
const int N = 507;
const int MX = 1e9 + 7;
const LL INF = 1e18 + 9LL;
int n;
LL tab[N][N];
vector <int> primes;
LL nwd(LL a, LL b){
if(b == 0)
return a;
return nwd(b, a%b);
}
LL get(LL a, LL b, LL c, LL d){
LL ret = a / nwd(a, b) * b;
ret = ret / nwd(ret, c) * c;
ret = ret / nwd(ret, d) * d;
return ret;
}
bool ok(int a){
for(int i = 2; i * i <= a; ++i)
if(a%i == 0)
return false;
return true;
}
int main(){
scanf("%d", &n);
if(n == 2){
puts("2 3\n5 4");
return 0;
}
for(int i = 2; primes.size() < n + n; ++i)
if(ok(i))
primes.push_back(i);
for(int i = 0; i <= n + 1; ++i)
for(int j = 0; j <= n + 1; ++j)
tab[i][j] = 1;
int sx = n - 1 + (n & 1), sy = 1;
for(int i = 1; i <= n - 1 + (n & 1); ++i){
int cx = sx, cy = sy;
while(cx <= n && cy <= n){
tab[cx][cy] *= primes.back();
++cx, ++cy;
}
if(sx > 2)
sx -= 2;
else{
if(sy == 1 && sx == 2)
sx = 1, sy++;
else
sy += 2;
}
primes.pop_back();
}
sx = 1, sy = 1;
for(int i = 1; i <= n; ++i){
int cx = sx, cy = sy;
while(cx <= n && cy >= 1){
tab[cx][cy] *= primes.back();
++cx, --cy;
}
if(sy + 1 < n)
sy += 2;
else{
if(sx == 1 && sy + 1 == n)
sy = n, ++sx;
else
sx += 2;
}
primes.pop_back();
}
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
if((i + j) & 1)
tab[i][j] = get(tab[i - 1][j], tab[i][j - 1], tab[i + 1][j], tab[i][j + 1]) + 1;
printf("%lld ", tab[i][j]);
}
puts("");
}
return 0;
} | #include "bits/stdc++.h"
using namespace std;
#define int long long int
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define se second
#define fi first
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> matrix;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
inline int add(int x, int y) { x += y; if (x >= mod) x -= mod; return x;}
inline int sub(int x, int y) { x -= y; if (x < 0) x += mod; return x;}
inline int mul(int x, int y) { return ((x % mod) * (y % mod)) % mod;}
inline int power(int a, int b) {
int x = 1;
while (b) {
if (b & 1) x = mul(x, a);
a = mul(a, a);
b >>= 1;
}
return x;
}
inline int inv(int a) { return power(a, mod - 2);}
const int N = 5005;
int n, dp[N][N];
pii a[N];
bool cmp(pii one, pii two) {
return (one.fi + one.se < two.fi + two.se);
}
#undef int
int main() {
#define int long long int
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
clock_t start = clock();
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].fi >> a[i].se;
}
sort(a + 1, a + n + 1, cmp);
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
dp[i][j] = inf;
}
}
dp[1][1] = a[1].se;
int ans = 1;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if (dp[i - 1][j - 1] > a[i].fi) dp[i][j] = dp[i - 1][j];
else {
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1] + a[i].se);
ans = max(ans, j);
}
}
}
cout << ans << endl;
clock_t end = clock();
cerr << "Time: " << (double)(end - start) / CLOCKS_PER_SEC << " seconds" << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define MAX_N 100000
int main(){
ll n;
cin >> n;
cout << 50 << endl;
ll b = n / 50;
int a = n % 50;
ll flag = 0;
REP(i,50){
if(i<a){
flag = 1;
}else{
flag = 0;
}
cout << i + (b + flag) * 51 - n << ' ';
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
typedef long long ll;
const ll MAXN = 2e6 + 10, inf = 1e18, mod = 1e9 + 7;
struct pair_hash {
template <class T1, class T2>
std::size_t operator () (const std::pair<T1,T2> &p) const {
auto h1 = std::hash<T1>{}(p.first);
auto h2 = std::hash<T2>{}(p.second);
return h1 ^ h2;
}
};
ll pw(ll te, ll tee) {
if (tee == 0) return 1;
ll res = pw(te, tee / 2);
return (tee % 2 ? te * res * res : res * res);
}
ll k, a[60];
void Read_input() {
cin >> k;
if (k == 0) {
cout << 4 << endl;
cout << 3 << " " << 3 << " " << 3 << " " << 3;
exit(0);
}
}
void Solve() {
for (ll i = 1; i <= 50; i++) a[i] = i - 1;
ll t = (k - 1) / 50;
k %= 50;
for (ll i = 1; i <= 50; i++) a[i] += t;
if (k == 0)
for (ll i = 1; i <= 50; i++) a[i]++;
else {
for (ll i = 1; i <= k; i++) {
sort(a + 1, a + 51);
a[1] += 50;
for (ll j = 2; j <= 50; j++) a[j]--;
}
}
cout << 50 << endl;
cout << a[1];
for (ll i = 2; i <= 50; i++) cout << " " << a[i];
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
Read_input(), Solve();
return 0;
} | 1 |
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;
const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;
#define _GLIBCXX_DEBUG
#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end())
void Add(ll &a, ll b){
a=(a+b)%mod;
return;
}
void Pro(ll &a, ll b){
a=(a*b)%mod;
return;
}
ll H,W;
vector<P> d;
vec ans;
void init(){
cin>>H>>W;
rep(i,H){
ll x,y; cin>>x>>y;
x--; y--;
d.pb(mp(x,y));
ans.pb(-1);
}
}
void Solve(){
set<P> x;
multiset<ll> y;
rep(i,W) {
P f=mp(i,i);
x.insert(f);
y.insert(0);
}
rep(i,H){
ll Biggest=-INF;
for(auto itr=x.lower_bound(mp(d[i].first,-INF));itr!=x.end();){
ll R=(*itr).first, L=(*itr).second;
// cout<<i<<':'<<R<<' '<<L<<endl;
if(R>d[i].second+1) break;
Biggest=max(Biggest,L);
auto itr1=y.lower_bound(R-L);
y.erase(itr1);
itr=x.erase(itr);
}
if(Biggest!=-INF) if(d[i].second!=W-1) {x.insert(mp(d[i].second+1,Biggest)); y.insert(d[i].second+1-Biggest);}
if(y.size()) ans[i]=*(y.begin());
else break;
}
rep(i,H) if(ans[i]>=0) ans[i]+=(i+1);
}
int main(){
init();
Solve();
rep(i,H) cout<<ans[i]<<endl;
}
| #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;
vector<vector<ll>> G(100007, vector<ll>(0));
void dfs(ll x,vl &d,ll dist){
d[x]=dist;
for(auto p: G[x]){
if(d[p]==INF)dfs(p,d,dist+1);
}
}
signed main(void){
cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
ll N;
cin >> N;
ll u;
cin >> u;u--;
ll v;
cin >> v;v--;
vector<ll> A(N-1,0);
vector<ll> B(N-1,0);
for(ll i=0;i<N-1;++i){
cin>>A[i]>>B[i];
A[i]--;B[i]--;
G[A[i]].emplace_back(B[i]);
G[B[i]].emplace_back(A[i]);
}
vector<ll> du(N,INF);
vector<ll> dv(N,INF);
dfs(u,du,0);
dfs(v,dv,0);
ll mark;
ll ou=-INF;
for(ll i=0;i<N;++i){
if(du[i]<dv[i]&&chmax(ou,dv[i]))mark=i;
}
ll nige=du[mark];
ll ans=nige;
ll S=ou-nige;//Sは1以上
if(S==1)ans+=0;
else if(S==2)ans++;
else {
ans+=((S-2)/2)*2;
S-=((S-2)/2)*2;
if(S==3)ans+=2;
else ans++;
}
prt(ans)
return 0;
}
| 0 |
#include <iostream>
int main(void)
{
int n;
std::cin >> n;
for(int i = 1; i <= n; i++) {
int x = i;
if(x % 3 == 0) {
std::cout << " " << i;
continue;
}
do {
if(x % 10 == 3) {
std::cout << " " << i;
break;
} else {
x /= 10;
}
}while(x);
}
std::cout << std::endl;
return 0;
} | #include <iostream>
using namespace std;
void check_num(int *i, int *x, int *n, int *flag);
void include3(int *i, int *x, int *n, int *flag);
void end_check_num(int *i, int *x, int *n, int *flag);
void call(int n){
int i = 1;
int x = 0;
int END_FLAG = 0;
check_num(&i, &x, &n, &END_FLAG);
}
int main(void){
int n;
cin >> n;
call(n);
return 0;
}
void check_num(int *i, int *x, int *n, int *flag){
*x = *i;
if( *x % 3 == 0 ){
cout << " " << *i;
end_check_num(i, x, n, flag);
}
else include3(i, x, n, flag);
}
void include3(int *i, int *x, int *n, int *flag){
if( *flag == 0 ){
if( *x % 10 == 3 ){
cout << " " << *i;
end_check_num(i, x, n, flag);
}
else{
(*x) /= 10;
if(*x) include3(i, x, n, flag);
else end_check_num(i, x, n, flag);
}
}
}
void end_check_num(int *i, int *x, int *n, int *flag){
if( ++(*i) <= *n ) check_num(i, x, n, flag);
else{
cout << endl;
*flag = 1;
}
} | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a,b,c,d;
cin >> a >> b >> c >> d ;
int L=a+b,R=c+d;
if (L==R){
cout << "Balanced" << endl;
}else
cout << (L<R ? "Right" :"Left") << endl;
}
| #pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
T x; \
cin >> x;
#define AIN(T, a, n) \
vector<T> a(n); \
FOR(i, a) \
cin >> i;
#define A2IN(T1, a, T2, b, n) \
vector<T1> a(n); \
vector<T2> b(n); \
REP(i, n) \
cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
SORT(a); \
reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a) \
cout << #a << " = {"; \
JOUT(ALL(a), ", ", cout) << "}" << endl;
template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
if (s != e)
{
os << *s;
++s;
}
while (s != e)
{
os << sep << *s;
++s;
}
return os;
}
ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
if (cond)
{
os << yes << endl;
}
else
{
os << no << endl;
}
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
os << '(' << p.first << ", " << p.second << ')';
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
os << '[';
JOUT(ALL(v), ", ", os) << ']';
return os;
}
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template
int main()
{
IN(ll, n);
IN(ll, m);
IN(ll, d);
double ans = (1.0 + (d != 0)) * (m - 1) * (n - d) / (n * n);
FOUT(ans);
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(false);
int x, y;
cin >> x >> y;
int f = 300000;
int s = 200000;
int t = 100000;
int ans = 0;
if (x == 1) ans += f;
else if (x == 2) ans += s;
else if (x == 3) ans += t;
if (y == 1) ans += f;
else if (y == 2) ans += s;
else if (y == 3) ans += t;
if (x == 1 && y == 1) ans += 400000;
cout << ans << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long ans, n;
int main() {
string s;
cin >> n >> s;
for (int i = 0; i < (1 << n); i++) {
string lr, lb;
for (int j = 0; j < n; j++) {
if (i & (1 << j))
lr += s[j];
else
lb += s[j];
}
//cerr << lr << " " << lb << "\n";
long long dp[40][20];
memset(dp, 0, sizeof dp);
dp[n * 2][0] = 1;
for (int j = n * 2 - 1; j >= n; j--) {
for (int k = 0; k <= (int)lr.size(); k++) {
dp[j][k] += (k > 0) * dp[j + 1][k - 1] * (s[j] == lr[k - 1]);
dp[j][k] += dp[j + 1][k] * (s[j] == lb[(n * 2 - j) - k - 1]);
}
}
ans += dp[n][(int)lr.size()];
}
cout << ans;
return 0;
} | 0 |
#include "bits/stdc++.h"
using namespace std;
template<typename Itr>
auto partition2(const Itr first, const Itr last){
auto i=first;
for(auto j=first; j!=last; ++j){
if(*j<=*last){
iter_swap(i, j);
++i;
}
}
iter_swap(i, last);
return i;
}
int32_t main(){
size_t n; cin>>n;
vector<uint32_t> a(n); for(auto&& e:a) cin>>e;
const auto last=--end(a);
auto mid=partition2(begin(a), last);
for(auto i=begin(a); i!=mid; ++i) cout<<*i<<' ';
cout<<'['<<*mid<<"] ";
for(auto i=next(mid); i!=last; ++i) cout<<*i<<' ';
cout<<*last<<'\n';
}
| #include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <list>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
int Partition(int a[], int p, int r) {
int x = a[r];
int i = p-1;
for(int j = p; j < r; j++) {
if(a[j] <= x) {
i++;
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
int temp = a[i+1];
a[i+1] = x;
a[r] = temp;
return i+1;
}
int main() {
int n;
cin >> n;
int a[n];
for( int i = 0; i < n; i++) cin >> a[i];
int b = Partition(a, 0, n-1);
for( int i = 0; i < n; i++) {
if(i == b) {
if( i ) cout << " [" <<a[i] << "]";
else cout << "[" << a[i] << "]";
} else if( i ) cout << " " <<a[i];
else cout << a[i];
}
cout << endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
const int ofs = 12800;
int H, W;
int A[82][82], B[82][82];
bool dp[82][82][25610];
signed main() {
cin.tie(0); ios::sync_with_stdio(false);
cin >> H >> W;
rep(i, H) rep(j, W) cin >> A[i][j];
rep(i, H) rep(j, W) cin >> B[i][j];
dp[0][0][A[0][0]-B[0][0]+ofs] = true;
dp[0][0][B[0][0]-A[0][0]+ofs] = true;
rep(i, H) rep(j, W) {
if (i>0) rep(k, 25610) {
if (!dp[i-1][j][k]) continue;
int nk = k+A[i][j]-B[i][j];
if (0<=nk && nk<25610) dp[i][j][nk] = true;
nk = k+B[i][j]-A[i][j];
if (0<=nk && nk<25610) dp[i][j][nk] = true;
}
if (j>0) rep(k, 25610) {
if (!dp[i][j-1][k]) continue;
int nk = k+A[i][j]-B[i][j];
if (0<=nk && nk<25610) dp[i][j][nk] = true;
nk = k+B[i][j]-A[i][j];
if (0<=nk && nk<25610) dp[i][j][nk] = true;
}
}
int ans = 1000000;
rep(i, 25610) if (dp[H-1][W-1][i]) ans = min(ans, abs(i-ofs));
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
using G=vector<vector<int>>;
bool dp[6410][20000];
int abs(int x,int y){
if(x>=y) return x-y;
else return y-x;
}
int main(){
int h,w;
cin >> h >> w;
vector<int> a(h*w), b(h*w);
rp(i,h*w) cin >> a[i];
rp(i,h*w) cin >> b[i];
rp(i,6410){
rp(j,20000) dp[i][j]=false;
}
int m=0;
rp(i,h*w) m=max(m,abs(a[i],b[i]));
dp[0][abs(a[0],b[0])]=true;
for(int i=1; i<h*w; i++){
int dif=abs(a[i],b[i]);
if(i%w){
for(int k=0; k<=(h+w)*m;k++){
if(dp[i-1][k]){
dp[i][abs(k,dif)]=true;
if(k+dif<=(h+w)*m*2) dp[i][k+dif]=true;
}
}
}
if(i>=w){
for(int k=0; k<=(h+w)*m;k++){
if(dp[i-w][k]){
dp[i][abs(k,dif)]=true;
if(k+dif<=(h+w)*m*2) dp[i][k+dif]=true;
}
}
}
}
int ans;
int c=0;
while(1){
if(dp[h*w-1][c]){
ans=c;
break;
}
c++;
}
cout << ans << endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める
int main()
{
int h, w;
cin >> h >> w;
vector<vector<char>> s(h, vector<char>(w));
rep(i,h) rep(j, w) cin >> s[i][j];
rep(i,h)rep(j,w){
if(s[i][j] == '#' && i != 0 && j != 0 && i != h-1 && j != w-1){
if(s[i+1][j] != '#' && s[i-1][j] != '#' && s[i][j-1] != '#' && s[i][j+1] != '#'){
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
return 0;
} | #include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int N,K,mx=0,gc=0;
cin>>N>>K;
vector<int> A(N);
for(int &i:A){
cin>>i;
mx=max(mx,i),gc=__gcd(gc,i);
}
if(K<=mx && K%gc==0)puts("POSSIBLE");
else puts("IMPOSSIBLE");
} | 0 |
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin()) // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << endl
#define RETURN(x) \
cout << x << endl; \
return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << endl
#define init() \
cin.tie(0); \
ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v) \
cerr << "[debugV] " << #v << ":"; \
rep(i, v.size()) cerr << " " << v[i]; \
cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
return to_string(x).size();
}
ll gcd(ll x, ll y) {
return y ? gcd(y, x % y) : x;
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
vector<P> factorize(ll n) {
vector<P> result;
for (ll i = 2; i * i <= n; ++i) {
if (n % i == 0) {
result.pb({i, 0});
while (n % i == 0) {
n /= i;
result.back().second++;
}
}
}
if (n != 1) {
result.pb({n, 1});
}
return result;
}
vll divisor(ll n) {
vll ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n) ret.push_back(n / i);
}
}
SORT(ret);
return (ret);
}
signed main() {
init();
ll N, T;
cin >> N >> T;
ll T_MAX = 6003;
vll dp(T_MAX);
vector<P> food(N);
rep(i, N) cin >> food[i].first >> food[i].second;
SORT(food);
rep(i, N) {
ll a = food[i].first;
ll b = food[i].second;
vll t = dp;
rep(j, T) {
ll nj = j + a;
t[nj] = max(t[nj], dp[j] + b);
}
dp = t;
}
ll ans = 0;
rep(j, T_MAX) {
ans = max(ans, dp[j]);
}
COUT(ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ar array
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
cin >> x;
}
void read(double& d) {
string t;
read(t);
d=stod(t);
}
void read(long double& d) {
string t;
read(t);
d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
read(h);
read(t...);
}
template<class A> void read(vt<A>& x) {
EACH(a, x)
read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
EACH(a, x)
read(a);
}
string to_string(char c) {
return string(1, c);
}
string to_string(bool b) {
return b?"true":"false";
}
string to_string(const char* s) {
return string(s);
}
string to_string(string s) {
return s;
}
string to_string(vt<bool> v) {
string res;
FOR(sz(v))
res+=char('0'+v[i]);
return res;
}
template<size_t S> string to_string(bitset<S> b) {
string res;
FOR(S)
res+=char('0'+b[i]);
return res;
}
template<class T> string to_string(T v) {
bool f=1;
string res;
EACH(x, v) {
if(!f)
res+=' ';
f=0;
res+=to_string(x);
}
return res;
}
template<class A> void write(A x) {
cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) {
write(h);
write(t...);
}
void print() {
write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) {
write(h);
if(sizeof...(t))
write(' ');
print(t...);
}
void DBG() {
cerr << "]" << endl;
}
template<class H, class... T> void DBG(H h, T... t) {
cerr << to_string(h);
if(sizeof...(t))
cerr << ", ";
DBG(t...);
}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
template<class T> void offset(ll o, T& x) {
x+=o;
}
template<class T> void offset(ll o, vt<T>& x) {
EACH(a, x)
offset(o, a);
}
template<class T, size_t S> void offset(ll o, ar<T, S>& x) {
EACH(a, x)
offset(o, a);
}
mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) {
return uniform_int_distribution<ll>(a, b)(mt_rng);
}
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
ll mod=1e9+7;
const int N=1e6+5;
const ld PI=2*acos(0.0);
ll modpow(ll a, ll b){
ll res=1; a%=mod;
while(b){
if(b&1){ res=(res*a)%mod;}
a=(a*a)%mod;
b>>=1;
}
return res;
}
#define lcm(a,b) ((a)*(b))/(__gcd(a,b))
bool compare(array<int,2> a,array<int,2> b){
return a[0]<b[0];
}
void solve() {
int n,t; read(n,t);
vt<array<int,2> > td(n+1);
FOR(i,1,n+1) read(td[i][0],td[i][1]);
sort(++td.begin(),td.end(),compare);
int siz=(*--td.end())[0]+t+5;
vt<int> dp(siz,0);
vt<int> pre(siz,0);
FOR(i,1,n+1){
FOR(j,1,siz){
if(j-td[i][0]<0||j-td[i][0]>=t) { dp[j]=pre[j];}
else{ dp[j]=max(pre[j],pre[j-td[i][0]]+td[i][1]);}
}
FOR(j,1,siz){ pre[j]=dp[j]; dp[j]=0; }
//dbg(i,pre);
}
print(*max_element(all(pre)));
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
solve();
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
int main(){
int a,b,c;
cin>>a>>b>>c;
if((a-b == 0)+(a-c == 0)+(b-c == 0)==1){
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}
} | #include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define MOD 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define M 1e6+9
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}
ll n,k,a,b,c,d,x,y,z,m,l;
ll ans;
vecl arr(N);
ll dp[509][509];
ll pre[N];
void test_case() {
set<int> st;
rep(i,3) {
int x;
cin>>x;
st.insert(x);
}
if(st.size() == 2) {
yes;
} else {
no;
}
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout<<fixed<<setprecision(20);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int t = 1;
// cin >> t;
while(t--)
{
test_case();
}
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
/* 変数名を被らせない
デバッグコードを取り除く */
#define ANSWER(x) cout<<x<<endl
#define debug(x) cout<<#x<<": "<<x
const int MAX_INT = 1000000;
int dp[31];
int n;
int solve(int a);
int main(){
while(1){
memset(dp,-1,sizeof(dp));
cin >> n;
if(n==0)break;
cout << (solve(n)/10-1)/365+1 << endl;
}
}
int solve(int a){
if(dp[a] != -1)return dp[a];
else{
if(a == 0)return 1;
else if(a < 0)return 0;
else return dp[a] = solve(a-1)+solve(a-2)+solve(a-3);
}
} | #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;
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int n;
while (cin >> n, n) {
V a(n);
rep(i, n) cin >> a[i];
int ans = -1e9;
rep(i, n) {
int t = 0;
rep2(j, i, n) {
t += a[j];
ans = max(ans, t);
}
}
cout << ans << endl;
}
} | 0 |
/*
@uthor: Varun Mishra
"varun21999" -> Codechef, Codeforce, Hackerrank, Hackerearth;
*/
//#include<boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define ull unsigned int
#define ld long double
#define pb push_back
#define pa pair<int,int>
#define ppa pair<pair<int,int>,int>
#define pap pair<int,pair<int,int>>
#define v1d vector<int>
#define v2d vector<vector<int> >
#define vpa vector<pair<int,int>>
#define M 1000000007
#define MN LLONG_MIN
#define MX LLONG_MAX
#define ff first
#define ss second
#define endl "\n"
#define v1s vector<string>
#define all(v) v.begin(),v.end()
#define S(v) sort(v.begin(),v.end())
#define RS(v) sort(v.rbegin(),v.rend())
#define R(v) reverse(v.begin(),v.end())
#define mxpq(T) priority_queue <T>
#define mnpq(T) priority_queue<T,vector<T>,greater<T>>
#define T int tc;cin>>tc;while(tc--)
#define p2d(v) for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v) for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v) for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define forIloop(i,n) for(auto i=0;i<n;i++);
#define forDloop(i,n) for(auto i=n-1;i>=0;i--);
#define qqq 400005
#define isEven(n) (!n & 1);
const int MOD = 1e9 + 7;
// bool isEven(int n){
// return (!(n & 1));
// }
// int popcount(int num){
// num = num - ((num >> 1) & 0x55555555);
// num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
// return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
// }
// int powerOfTwo(int n){
// return 1 << n;
// }
// int arr[1000001];
// bool temet = false;
void codeforce2(){
int a[3]; cin>>a[0]>>a[1]>>a[2];
swap(a[0], a[1]);
swap(a[0], a[2]);
cout << a[0] << " " << a[1] << " " << a[2] << endl;
return;
}
int32_t main(){
cout<<fixed<<setprecision(16);
cin.sync_with_stdio(false);
cin.tie(0);cout.tie(0);
/*#ifndef _DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
//auto start = high_resolution_clock::now();
// Lucario();
//codeforceContest();
//hackerEarth();
//codeChef();
// T{
// codeforce2();
// }
codeforce2();
/* auto stop = high_resolution_clock::now();
auto duration = duration_cast<seconds>(stop - start);
cout << "Time: "<<duration.count()<<endl;*/
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n,m,d;
cin>>n>>m>>d;
cout << fixed << setprecision(8);
double ans=1.000000*(n-d)/n*(m-1)/n;
if(d!=0)ans*=2;
cout<<ans<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------
void MAIN() {
int n; cin >> n;
int mi = n;
for (int i = 1; i <= 5; i++) {
int t; cin >> t;
mi = min(mi, t);
}
cout << (n + mi - 1) / mi + 4 << '\n';
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int T = 1;
// cin >> T;
while (T--) MAIN();
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
lint fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (lint i = 2; i < MAX; i++)
{
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long COM(lint n, lint k)
{
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
lint primary(lint num)
{
if (num < 2) return 0;
else if (num == 2) return 1;
else if (num % 2 == 0) return 0;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2)
{
if (num % i == 0)
{
return 0;
}
}
return 1;
}
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;
}
lint lcm(lint a,lint b){
return a/__gcd(a,b)*b;
}
lint gcd(lint a,lint b){
return __gcd(a,b);
}
int main(){
lint n,a,b,c,d,e;
cin>>n>>a>>b>>c>>d>>e;
lint x=min({a,b,c,d,e});
lint ans=(n+x-1)/x;
ans+=4;
cout<<ans<<endl;
}
| 1 |
#include <stdio.h>
int main(){
int l, r, ll, rr, minn;
scanf("%d%d", &l, &r);
ll = l % 2019;
rr = r % 2019;
minn = 2019;
if(r - l > 2019) rr += 2019;
for (int i=ll;i<rr;i++){
for (int j=ll+i-ll+1;j<rr+1;j++){
if(minn > i * j % 2019){
minn = i * j % 2019;
}
}
}
printf("%d\n", minn);
return 0;
}
| #include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };
int main(void) {
int l, r, i, j, ans;
scanf("%d%d", &l, &r);
if (r - l >= 2019 || l % 2019 > r % 2019)
{
printf("0\n");
return (0);
}
ans = 2019;
i = l % 2019;
while (i < r % 2019)
{
j = i + 1;
while (j <= r % 2019)
{
if (ans > i * j % 2019)
ans = i * j % 2019;
j++;
}
i++;
}
printf("%d\n", ans);
return 0;
} | 1 |
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream> // cout, endl, cin
#include <iomanip>
#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 <math.h>
using namespace std;
int main() {
vector<long long> num(3);
long long K;
for (int i = 0; i < 3; i++) {
cin >> num.at(i);
}
sort(num.begin(), num.end());
cin >> K;
for (int i = 0; i < K; i++) {
num.back() *= 2;
}
long long ans;
ans = num.at(0) + num.at(1) + num.at(2);
cout << ans << endl;
} | #include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define int long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
const int maxn=500010;
const int N=1<<20;
const int mod=1e9+7;
int n;
int a[maxn],f[maxn];
int flg[maxn];//1-i中异或和不为0的个数
int d1[N];//
int d0[N];//
int pre[N];//上一个异或和为i的数
signed main(){
cin>>n;
for(int i=0;i<(1<<20);i++)d0[i]=1;
for(int i=0;i<n;i++)cin>>a[i],f[i]=(i>0?(f[i-1]^a[i]):a[i]);
for(int i=0;i<n;i++){
if(f[i]){
int b=f[i];//当前的异或和
d0[b]=(d0[b]+(flg[i]-flg[pre[b]])*d1[b])%mod;
d1[b]=(d0[b]+d1[b])%mod;
pre[b]=i;
}else{
flg[i]++;
if(d1[0])d1[0]=(d1[0]*2)%mod;
else d1[0]++;
}
flg[i+1]=flg[i];
}
int ans=0;
if(f[n-1]==0){
for(int i=0;i<(1<<20);i++)ans=(ans+d1[i])%mod;
}else{
ans=d0[f[n-1]];
}
cout<<ans<<endl;
return 0;
}
| 0 |
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
cin.tie(0);
ios::ios_base::sync_with_stdio(false);
int n, q;
cin >> n;
vector<int>S(n);
for (int i = 0; i < n; ++i)cin >> S[i];
sort(S.begin(), S.end());
cin >> q;
vector<int>T(q);
for (int i = 0; i < q; ++i)cin >> T[i];
sort(T.begin(), T.end());
int ans = 0;
for (int i = 0; i < q; ++i) {
if(binary_search(S.begin(), S.end(), T[i]))++ans;
}cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
string char_to_string(char val) {
return string(1, val);
}
int char_to_int(char val) {
return val - '0';
}
int main() {
int N; cin >> N;
string A, B, C; cin >> A >> B >> C;
int cnt = 0;
REP(i, N) {
if(A[i] == B[i] && B[i] == C[i]) {
}
else if(A[i] == B[i]) {
cnt++;
}
else if(A[i] == C[i]) {
cnt++;
}
else if(C[i] == B[i]) {
cnt++;
} else {
cnt = cnt + 2;
}
}
cout << cnt << endl;
} | 0 |
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
using namespace std;
void func()
{
double D,T,S;
cin >> D>>T>>S;
if(D/S <= T)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
int main() {
// while(1)
func();
return 0;
}
| #include <iostream>
#include <regex>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
int A, B;
string S;
cin >> A >> B >> S;
regex rx(R"([0-9]{)" + to_string(A) + R"(}-[0-9]{)" + to_string(B) + R"(})");
if (regex_match(S, rx)) {
printf("Yes\n");
} else {
printf("No\n");
}
} | 0 |
#include <bits/stdc++.h>
#define mov(x) (1<<(x))
using namespace std;
template <typename T> void cmin(T &x, const T &y)
{
if(y < x) x = y;
}
template <typename T> void cmax(T &x, const T &y)
{
if(y > x) x = y;
}
template <typename T> void read(T &x)
{
x = 0; char c = getchar(); bool f = 0;
while(!isdigit(c) && c!='-') c = getchar();
if(c == '-') f = 1, c = getchar();
while(isdigit(c)) x = x*10+c-'0', c = getchar();
if(f) x = -x;
}
int n, m, sum;
int grp[mov(15)];
int w[15][15];
int f[mov(15)][15];
int main()
{
read(n), read(m);
memset(w, 0x9f, sizeof(w));
for(int i=1; i<=m; i++)
{
int a, b, c;
read(a), read(b), read(c);
w[a-1][b-1] = c;
w[b-1][a-1] = c;
sum += c;
}
memset(f, 0x9f, sizeof(f));
for(int s=1; s<mov(n); s++)
for(int i=0; i<n; i++)
if(s & mov(i))
for(int j=i+1; j<n; j++)
if(s & mov(j))
if(w[i][j] > 0)
grp[s] += w[i][j];
for(int s=1; s<mov(n); s++)
if(s & 1)
f[s][0] = grp[s];
for(int s=1; s<mov(n); s++)
for(int i=0; i<n; i++)
if((mov(i)&s) && (s&1))
{
int u = ((~s)&(mov(n)-1));
for(int t=u; t; t=((t-1)&u))
for(int j=0; j<n; j++)
if(mov(j) & t)
if(w[i][j] > 0)
cmax(f[s|t][j], f[s][i] + w[i][j] + grp[t]);
}
printf("%d\n", sum-f[mov(n)-1][n-1]);
return 0;
}
| #include <iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll sum[200010];
int bin_s(int l,int r) {
ll g=(sum[l]+sum[r])/2;
int ok=l,ng=r;
while(ok+1<ng){
int mid=(ok+ng)/2;
if (sum[mid]<=g)ok=mid;
else ng=mid;
}
if(g-sum[ok]<sum[ng]-g)return ok;
else return ng;
}
int main() {
int N;cin>>N;
for(int i=0;i<N;++i){
ll A; cin>>A;
sum[i+1]=sum[i]+A;
}
ll ans=1e15;
for(int i=2;i+2<=N;++i){
int form=bin_s(0,i),latt=bin_s(i,N);
ll mn=min(sum[form],sum[i]-sum[form]),mx=max(sum[form],sum[i]-sum[form]);
mn=min(mn,min(sum[latt]-sum[i],sum[N]-sum[latt]));
mx=max(mx,max(sum[latt]-sum[i],sum[N]-sum[latt]));
ans=min(ans,mx-mn);
}
cout<<ans<<endl;
return 0;
} | 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;
} | #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int n;
vector<vector<int>> a(3);
ll solve () {
ll ans = 0;
rep (j, n) {
int tmp = a[1][j];
ll comb = lower_bound(a[0].begin(), a[0].end(), tmp) - a[0].begin();
comb *= a[2].end() - upper_bound(a[2].begin(), a[2].end(), tmp);
ans += comb;
}
return ans;
}
int main() {
while (cin >> n) {
rep (i, 3) {
a[i].resize(n);
rep (j, n) cin >> a[i][j];
sort(a[i].begin(), a[i].end());
}
cout << solve() << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int n;
cin >> n;
vector<ll> takahashi(n);
ll sum = 0;
for(int i = 0; i < n; i++){
ll a, b;
cin >> a >> b;
takahashi[i] = a+b;
sum-=b;
}
sort(takahashi.begin(), takahashi.end(), greater<long long>());
for(int i = 0; i < n; i++){
if(i%2 == 0){
sum += takahashi[i];
}
}
cout << sum;
}
| #include<iostream>
#include<math.h>
#include<algorithm>
#include<tuple>
using namespace std;
#define fr(i,n) for(int i=0;i<n;i++)
typedef double db;
typedef tuple<bool,db> bod;
db Pi = 3.14159265358979;
db st(db t){
t+=4*Pi;
while(t>=0) t-=2*Pi;
t+=2*Pi;
return t;
}
bod J(db a,db b){
if(a<=Pi){
return make_tuple(!(a<=b && b<a+Pi),a+Pi-b);
}
else{
return make_tuple(!(a<=b || b<a-Pi),st(a+Pi-b));
}
}
int main(){
int n,q,r;
bool f;
db x[100],y[100],m[100][100],M;
cin >> n;
if(n==2){
cout<<0.5<<endl<<0.5<<endl;
return 0;
}
fr(i,n) cin>>x[i]>>y[i];
fr(i,n){
fr(j,n){
if(i != j){
m[i][j]=st(atan2(x[j]-x[i],y[j]-y[i]));
}
}
fr(j,n){
if(i==j) continue;
f=0;
M=2*Pi;
fr(k,n){
if(k==i || k==j) continue;
// cout<<i<<" "<<j<<" "<<k<<" "<<m[i][j]<<" "<<m[i][k]<<endl;
bod G=J(m[i][j],m[i][k]);
if(M>get<1>(G)){
r=k;
M=get<1>(G);
}
if(get<0>(G)){
f=1;
break;
}
}
if(!f){
q=j;
break;
}
}
if(f) cout<<0.0<<endl;
else cout<<M/(2*Pi)<<endl;
}
} | 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>;
vector<P> tell[15];
int main() {
int n;
cin >> n;
rep(i,n) {
int a;
cin >> a;
rep(j,a) {
int x, y;
cin >> x >> y;
x--;
tell[i].emplace_back(x,y);
}
}
int ans = 0;
rep(is,1<<n) {
int cnt = __builtin_popcount(is);
bool ok = true;
rep(i,n) {
if (!(is>>i&1)) continue;
for (auto p : tell[i]) {
int x = p.first, y = p.second;
if (!(int(is>>x&1) == y)) ok = false;
}
}
if (ok) ans = max(ans, cnt);
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <array>
using namespace std;
class EightQueen
{
public:
vector<vector<int>> bd;
EightQueen(){}
EightQueen( int n ) : bd(n, vector<int>(n)) {}
int solve();
bool dfs( int r );
bool conflict( int r, int c );
};
bool EightQueen::conflict( int r, int c )
{
for ( auto i = 0; i < 8; ++i )
for ( auto j = 0; j < 8; ++j )
{
if ( bd[i][j] == 0 ) continue;
if ( i == r ) return false;
if ( j == c ) return false;
if ( r - c == i - j ) return false;
if ( r + c == i + j ) return false;
}
return true;
}
bool EightQueen::dfs( int r )
{
if ( r == 8 ) return true;
for ( auto c = 0; c < 8; ++c )
{
if ( bd[r][c] == 2 )
{
if ( dfs( r + 1 ) ) return true;
}
else
{
if ( conflict( r, c ) )
{
bd[r][c] = 1;
if ( dfs( r + 1 ) ) return true;
bd[r][c] = 0;
}
}
}
return false;
}
int EightQueen::solve()
{
dfs( 0 );
for ( auto r = 0; r < 8; ++r )
{
for ( auto c = 0; c < 8; ++c )
{
if ( bd[r][c] )
cout << "Q";
else
cout << ".";
}
cout << endl;
}
return 0;
}
int main()
{
int n;
cin >> n;
EightQueen eq( 8 );
for ( auto i = 0; i < n; ++i )
{
int r, c;
cin >> r >> c;
eq.bd[r][c] = 2;
}
eq.solve();
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, p;
int peb[55];
void solve() {
int c = 0;
int p_ = p;
while (1) {
if (p_ == 0) {
p_ += peb[c];
peb[c] = 0;
c++;
} else {
peb[c]++;
if (peb[c] == p) break;
p_--;
c++;
}
c %= n;
}
cout << c << endl;
}
int main() {
while (1) {
cin >> n >> p; if (n == 0 && p == 0) break;
memset(peb, 0, sizeof(peb));
solve();
}
return 0;
} | #include <iostream>
int main(void){
while(1){
int stonNum[51] = {0};
int p, n;
std::cin >> n >> p;
int first = p;
if(n == 0 && p == 0) return 0;
int i=0;
while(1){
bool flag = true;
if(p > 0){
stonNum[i]++;
p--;
if(stonNum[i] == first){
std::cout << i << std::endl;
break;
}
}else{
p += stonNum[i];
stonNum[i] = 0;
}
if(i == n-1) i = 0;
else i++;
}
}
} | 1 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
cin.tie(0);
ios::sync_with_stdio(0);
int n,y;cin>>n>>y;
int sy=y-n*1000;
int n1=-1,n5=-1,n10=-1;
for(int i=0;i<=n;i++)
{
int bsy=sy-i*4000;
if(bsy<0)break;
if(bsy%9000==0)
{
if(bsy/9000+i<=n)
{
n10=bsy/9000;
n5=i;
n1=n-n10-n5;
break;
}
}
}
cout<<n10<<" "<<n5<<" "<<n1<<"\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
int64_t Y;
cin >> Y;
int a = -1;
int b = -1;
int c = -1;
for(int i = 0; i <= N; i++){
for(int j = 0; j + i <= N; j++){
int k = (N - i -j);
int sum = 10000 * i + 5000 * j + 1000 * k;
if(sum == Y){
a = i;
b = j;
c = k;
}
}
}
cout << a << " " << b << " " << c << endl;
} | 1 |
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
distance(v.begin(), upper_bound(v.begin(), v.end(), x))
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;
ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
const ll INF = 1LL << 50;
struct UnionFind {
vll par;
vll wcnt;
vll bcnt;
ll cnt;
UnionFind(ll N, vector<string>& mp) : par(N), wcnt(N, 0), bcnt(N, 0), cnt(N) {
for (ll i = 0; i < N; i++) {
par[i] = i;
ll w = (ll)mp[0].size();
if (mp[i / w][i % w] == '.')
wcnt[i] = 1;
else
bcnt[i] = 1;
}
}
ll find(ll x) { return par[x] == x ? x : par[x] = find(par[x]); }
bool same(ll x, ll y) { return find(x) == find(y); }
ll get_wcnt(ll x) { return wcnt[find(x)]; }
ll get_bcnt(ll x) { return bcnt[find(x)]; }
void unite(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y) return;
ll sizex = wcnt[x] + bcnt[x];
ll sizey = wcnt[y] + bcnt[y];
if (sizex < sizey) swap(x, y);
par[y] = x;
wcnt[x] += wcnt[y];
bcnt[x] += bcnt[y];
cnt--;
}
ll count() const { return cnt; }
};
int main() {
ll x, y;
cin >> x >> y;
ll ans = 0;
if (x == 1)
ans += 300000;
else if (x == 2)
ans += 200000;
else if (x == 3)
ans += 100000;
if (y == 1)
ans += 300000;
else if (y == 2)
ans += 200000;
else if (y == 3)
ans += 100000;
if (x == 1 && y == 1) ans += 400000;
cout << ans << endl;
return 0;
}
| #include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n, M[MAX][MAX];
int prim() {
int d[MAX],
p[MAX] = { -1 },
color[MAX] = {};//WHITE
fill(d, d + MAX, INF);
d[0] = 0;
while (true) {
int u, minv = INF;
for (int i = 0; i < n; i++) {
if (color[i] != BLACK&&d[i] < minv) {
minv = d[i];
u = i;
}
}
if (minv == INF) { break; }
color[u] = BLACK;
for (int v = 0; v < n; v++) {
if (color[v] != BLACK&&M[u][v] != INF) {
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;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int a; cin >> a;
M[i][j] = (a == -1) ? INF : a;
}
}
cout << prim() << endl;
return 0;
} | 0 |
#include <stdio.h>
int main(int argc, char const *argv[]) {
int i, n;
scanf("%d", &n);
for (i = 3; i <= n; i++) {
if (i % 3 == 0) {
printf(" %d", i);
} else {
int temp = i;
do {
if (temp % 10 == 3) {
printf(" %d", i);
break;
}
temp /= 10;
} while (temp > 0);
}
}
puts("");
return 0;
} | #include<iostream>
using namespace std;
int i = 1, x, n;
void checknum();
void include3();
void endchecknum();
int main() {
cin >> n;
checknum();
return 0;
}
void checknum() {
x = i;
if (x % 3 == 0) {
cout << " " << i;
endchecknum();
} else {
include3();
}
}
void include3() {
if (x % 10 == 3) {
cout << " " << i;
endchecknum();
} else {
x /= 10;
if (x) {
include3();
} else {
endchecknum();
}
}
}
void endchecknum() {
if (++i <= n) {
checknum();
} else {
cout << endl;
return;
}
} | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define asd cout << "ok" << endl;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(it, m) for(auto it = m.begin(); it!= m.end(); it++)
const int MOD = 1e9 + 7;
const ll INF = 1e19;
const ld PI = acos((ld)-1);
const int MX = 2e5 +5;
const char nl = '\n';
int main(){
string s; cin >> s;
int ok1 = 0, ok2 = 0, ok3 = 0;
if(s[0] == 'A')
ok1= 1;
int cnt = 0;
for(int i =2; i < s.size()-1; i++)
{
if(s[i] == 'C')
cnt++;
}
if(cnt == 1)
ok2 = 1;
if(s[1] < 'a' || s[1] > 'z')
{
cout << "WA" <<nl;
return 0;
}
if(s[s.size() -1] < 'a' || s[s.size()-1] > 'z')
{
cout << "WA" <<nl;
return 0;
}
for(int i = 1; i < s.size(); i++)
{
if(s[i] >= 'a' && s[i] <= 'z' || s[i] == 'C')
ok3 = 1;
}
if(ok1 && ok2 && ok3)
cout << "AC" << nl;
else
cout << "WA" << nl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, n;
cin >> N;
n = N;
for (int i = 0; i < 9; i++) {
int x;
x += n % 10;
n /= 10;
if (i == 8){
if ( N % x == 0){
cout << "Yes" << endl;}
else{
cout << "No" << endl;}
}
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
const double PI = acos(-1);
int n;
pair<int, int> p[maxn];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d %d", &p[i].first, &p[i].second);
}
for (int i = 1; i <= n; i++) {
vector<double> V;
for (int j = 1; j <= n; j++) if (i ^ j) {
V.push_back(atan2(p[j].second - p[i].second, p[j].first - p[i].first));
}
sort(V.begin(), V.end());
double ans = max(0.0, PI - (V.back() - V[0]));
for (int i = 0; i + 1 < V.size(); i++) {
ans = max(ans, (V[i + 1] - V[i]) - PI);
}
printf("%.10f\n", ans / PI / 2);
}
return 0;
} | #include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;
typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;
typedef pair<double, int> Pdi;
template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);
double pi = 3.141592653589793238;
signed main(){
int N; cin >> N;
vector<double> x(N), y(N);
REP(i, N) cin >> x[i] >> y[i];
vector<double> ans(N, 0.0);
int n = 1000000;
REP(i, n){
double theta = 2.0 * pi * (double)i / (double)(n);
double maxv = -1.0 * INF, v;
int maxi;
REP(j, N){
v = x[j] * cos(theta) + y[j] * sin(theta);
if(v > maxv){
maxv = v;
maxi = j;
}
}
ans[maxi] += 1.0 / (double)n;
}
REP(i, N) cout << ans[i] << endl;
return 0;
}
template<typename T>
void readvec(vector<T> &a){
REP(i, a.size()){
cin >> a[i];
}
}
void readindex(vector<int> &a){
REP(i, a.size()){
cin >> a[i];
a[i]--;
}
} | 1 |
#include <bits/stdc++.h>
#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(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
int main() {
int a, b, c; cin >> a >> b >> c;
if (a > b) swap(a,b);
if (a < c && c < b) cout << "Yes" << endl;
else cout << "No" << endl;
} | #include <stdio.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
char s[a+b+2];
scanf("%s", s);
for(int i=0; i<a; i++){
if(s[i]<48 || s[i]>57){
printf("No\n");
return 0;
}
}
if (s[a]!=45){
printf("No\n");
return 0;
}
for(int i=a+1; i<=(a+b); i++){
if(s[i]<48 || s[i]>57){
printf("No\n");
return 0;
}
}
printf("Yes\n");
return 0;
} | 0 |
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
const int N = 3e5 + 1;
int n, m, k;
long long int A[N], B[N], cs[N], sum;
int main(){
ll H , W , N ;
cin >> H >> W >> N ;
if(N % max(H , W ) == 0) cout << N / max(H , W ) << endl;
else cout << ( N / max(H , W ) ) + 1 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
#define MOD 1000000007
int main(){
ll h, w, k;
cin >> h >> w >> k;
ll dp[110][10] = {};
dp[0][0] = 1;
rep(i, h)rep(j, w)rep(k,(1<<(w-1))){
bool isok = true;
rep(l, w-2)if(k & (1<<l) && k & (1<<(l+1))){
isok = false;
break;
}
if(isok){
if(j > 0 && (1<<(j-1) & k)){
dp[i+1][j-1] += dp[i][j];
dp[i+1][j-1] %= MOD;
}
else if(j < w-1 && (1<<j) & k){
dp[i+1][j+1] += dp[i][j];
dp[i+1][j+1] %= MOD;
}
else {
dp[i+1][j] += dp[i][j];
dp[i+1][j] %= MOD;
}
}
}
cout << dp[h][k-1] << endl;
} | 0 |
#include <bits/stdc++.h>
#include <gmpxx.h>
#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; return(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;
ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;
ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;
double ave = 0.0;
ll mod_pow(ll base, ll power) {
if (power == 0) return 1;
if (power == 1) return base % MOD;
if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}
ll mod_fact(ll number) {
ll ret = 1;
ll count = 1;
while (count <= number) {
ret *= (count % MOD);
ret %= MOD;
count++;
}
return ret % MOD;
}
ll gcd(ll a, ll b) {
if (a < b) {
return gcd(b, a);
}
ll c = a % b;
while (c != 0) {
a = b;
b = c;
c = a % b;
}
return b;
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
cin >> s;
if (s.size() % 2 != 0) {
END("No")
}
REP(i, 0, s.size()) {
if (i % 2 == 0) {
if (s.at(i) != 'h') {
END("No")
}
} else {
if (s.at(i) != 'i') {
END("No")
}
}
}
MSG("Yes")
}
| #include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int sum = 0;
sum = (n - 2) * 180;
cout << sum;
return 0;
}
| 0 |
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;
int N, K, a[100001], d[100001], c[100001];
vector<int> G[100001];
void dfs(int u) {
for (int v : G[u]) {
dfs(v);
d[u] = max(d[v]+1, d[u]);
c[u] += c[v];
}
if (u > 1 && a[u] > 1 && d[u] == K-1) {
d[u] = -1;
++c[u];
}
}
int main() {
if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> N >> K;
for (int u = 1; u <= N; ++u) {
cin >> a[u];
if (u > 1) G[a[u]].push_back(u);
}
dfs(1);
cout << (a[1] > 1) + c[1];
} | #include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
int main() {
ios::sync_with_stdio(false);
int a[3], k, b = 0;
for (int i = 0 ; i < 3 ; i++) cin >> a[i];
cin >> k;
sort(a, a + 3);
b = a[2];
for (int i = 0 ; i < k ; i++) b *= 2;
cout << a[0] + a[1] + b;
} | 0 |
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>
using namespace std;
typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;
const double PI=3.14159265358979323846;
#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))
#define rep(i, N) for(int i = 0; i < N; ++i)
#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL
#define IN(l, r, x) ((l) <= (x) && (x) < (r))
template< typename T >
map<T, int> prime_factorization(T x)
{
map<T, int> ret;
for (T i = 2; i * i <= x; ++i)
{
while (x % i == 0)
{
++ret[i];
x /= i;
}
}
if (x != 1) ++ret[x];
return ret;
}
s64 mypow(s64 x, s64 n)
{
s64 ret = 1;
while (n)
{
if (n & 1) ret = (ret * x) % MOD;
x = (x * x) % MOD;
n >>= 1;
}
return ret;
}
const int max_n = 100100;
s64 fac[max_n + 1];
s64 finv[max_n + 1];
void init(int n)
{
fac[0] = fac[1] = 1;
for (s64 i = 2; i <= n; ++i)
{
fac[i] = fac[i - 1] * i % MOD;
}
finv[n] = mypow(fac[n], MOD - 2);
for (s64 i = n - 1; i >= 0; --i)
{
finv[i] = finv[i + 1] * (i + 1) % MOD;
}
}
s64 comb(int n, int r)
{
if (n < r || n < 0 || r < 0) return 0;
return fac[n] * finv[r] % MOD * finv[n - r] % MOD;
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
auto pfac = prime_factorization(m);
init(max_n);
s64 ans = 1;
for (auto& item : pfac)
{
int num = item.second;
ans *= comb(n + num - 1, num);
ans %= MOD;
}
cout << ans << "\n";
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 n, y;
cin >> n >> y;
for (int i = 0; i <= n; ++i) {
for (int j = 0; i + j <= n; ++j) {
int k = n - i - j;
if (10000 * i + 5000 * j + 1000 * k == y) {
printf("%d %d %d\n", i, j, k);
return 0;
}
}
}
printf("-1 -1 -1\n");
return 0;
} | 0 |
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
double x1,y1,x2,y2;
cin >> x1 >> y1 >> x2 >> y2;
cout.precision(9);
cout.setf(ios::fixed);
cout << sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) << endl;
return 0;
} | #include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main() {
string str;
while (getline(cin, str)) {
for (int i = 0; i < 26; i++) {
for (auto &itr : str) if (isalpha(itr)) itr = (itr - 'a' + 1) % 26 + 'a';
if (str.find("the") != -1) { cout << str << endl; break; }
if (str.find("this") != -1) { cout << str << endl; break; }
if (str.find("that") != -1) { cout << str << endl; break; }
}
}
return 0;
}
| 0 |
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
int main(void) {
int64_t N, X;
cin >> N >> X;
vector<int64_t> A(N);
rep(i, N) cin >> A[i];
int64_t answer = 0;
for(int i = 1; i < N; ++i) {
if(X < (A[i-1] + A[i])) {
int64_t diff = (A[i] + A[i-1]) - X;
A[i] -= min(A[i], diff);
answer += diff;
}
}
cout << answer << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
if(v.size() >= 200) {
return "Too big container";
}
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep(i,n) for (int i = 0; i < n; ++i)
#define per(i,n) for (int i = n - 1; i >= 0; --i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
#define reps(i,s,n) for (int i = s; i < n; ++i)
#define all(c) begin(c),end(c)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef long double ld;
typedef pair<int,int> PINT;
typedef pair<ll,ll> PLL;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
#define print(a) cout << a << endl;
const int INFI = (1 << 30) - 1;
const long long INFLL = (1LL << 62) - 1;
template<typename T> void printv(vector<T>&v) {
int n = v.size() - 1;
rep(i, n) cout << v[i] << " ";
cout << v.back() << endl;
}
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
double deg2rad(double deg) { return deg * M_PI / 180; }
double rad2deg(double rad) { return rad * 180 / M_PI; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, X; cin >> N >> X;
ll ans = 0;
ll left; cin >> left;
rep(i, N - 1) {
ll a; cin >> a;
ll over = (left + a) - X;
if(over > 0) {
ans += over;
if(over > a) {
left = 0;
} else {
left = a - over;
}
} else {
left = a;
}
}
print(ans);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define MOD 1000000007LL
#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))
template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
cout << "(" << m.first << ", " << m.second << ")";
return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
ll c = 0;
cout << "{ ";
iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
cout << "}";
return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
cout << "{ ";
rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
cout << "}";
return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
ll c = 0;
cout << "{ ";
iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
cout << "}";
return s;
}
int main(void) {
ll prev = 0;
vector<ll> A(5);
ll k;
rep(i, 5) cin >> A[i];
cin >> k;
rep(i, 4) {
rep2(j, i + 1, 5) {
if(A[j] - A[i] > k) {
cout << ":(" << endl;
return 0;
}
}
}
cout << "Yay!" << endl;
return 0;
}
| #include <cmath>
#include <iostream>
using namespace std;
int main() {
int N, L;
cin >> N >> L;
int opt = (1 << 30), sum = 0;
for (int i = 0; i < N; ++i) {
int p = L + i;
if (abs(opt) > abs(p)) {
opt = p;
}
sum += p;
}
cout << sum - opt << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a,b,n,i=0;
cin >> a >> b;
n = 1;
while(b>n){
n += a - 1;
i++;
}
cout << i << endl;
} | #define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;
int main(){
int n;
string s;
cin>>n>>s;
vector<int> A(n),B(n);
rep(i,n){
if(i==0){
if(s[0]=='W') A[0]=1;
else A[0]=0;
}
else if(s[i]=='W') A[i]=A[i-1]+1;
else A[i]=A[i-1];
}
for(int i=n-1;i>=0;i--){
if(i==n-1){
if(s[n-1]=='E') B[n-1]=1;
else B[n-1]=0;
}
else if(s[i]=='E') B[i]=B[i+1]+1;
else B[i]=B[i+1];
}
int mi=INF;
rep(i,n){
mi=min(mi,A[i]+B[i]);
}
cout<<mi-1<<endl;
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
lli n, m;
int main(void){
cin >> n >> m;
vector<bool> ac(n+1);
vector<lli> wa(n+1);
rep(i, m){
int p;
string s;
cin >> p >> s;
if(s == "AC") ac[p] = true;
else{
if(!ac[p]) wa[p]++;
}
}
lli sumac = 0, sumwa = 0;
rep(i, n+1){
if(ac[i]){
sumac++;
sumwa+=wa[i];
}
}
cout << sumac << " " << sumwa << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
inline int gi()
{
char c = getchar();
while(c < '0' || c > '9') c = getchar();
int sum = 0;
while('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
return sum;
}
typedef long long ll;
const int maxn = 100005;
int n, s, x[maxn];
ll ans, p[maxn];
int main()
{
n = gi(); s = gi();
for (int i = 1; i <= n; ++i) x[i] = gi(), p[i] = gi();
int l = 1, r = n, d = p[1] >= p[n];
while (1) {
if (x[l] >= s) {ans += x[r] - s; break;}
if (x[r] <= s) {ans += s - x[l]; break;}
if (p[l] >= p[r]) {
if (d != 0) {ans += x[r] - x[l]; d ^= 1;}
p[l] += p[r--];
} else {
if (d != 1) {ans += x[r] - x[l]; d ^= 1;}
p[r] += p[l++];
}
}
printf("%lld\n", ans);
return 0;
}
| 0 |
#include <bits/stdc++.h>
template <class T>
T root(std::vector<T>& v, T x) {
return v[x] - x ? (v[x] = root(v, v[x])) : x;
}
template <class T>
bool same(std::vector<T>& v, T x, T y) { return root(v, x) == root(v, y); }
template <class T>
void unite(std::vector<T>& v, T x, T y) {
x = root(v, x);
y = root(v, y);
if (x != y) v[x] = y;
}
int main() {
long long n, m;
std::cin >> n >> m;
std::vector<int> p(n);
std::vector<std::deque<int>> g(n);
for (int i = 0; i < n; i++) p[i] = i;
for (int i = 0; i < m; i++) {
int a, b;
std::cin >> a >> b; a--; b--;
unite(p, a, b);
g[a].push_back(b);
g[b].push_back(a);
}
std::map<int, std::deque<int>> sub;
for (int i = 0; i < n; i++) {
sub[root(p, p[i])].push_back(i);
}
long long a = 0, b = 0, c = 0;
std::vector<bool> done(n, false), color(n);
for (auto& s : sub) {
auto v = s.second;
if (v.size() == 1) {
b++;
continue;
}
std::deque<int> q;
q.push_back(v[0]);
color[v[0]] = true;
bool odd = false;
while (!q.empty()) {
auto curr = q.front();
done[curr] = true;
for (auto to : g[curr]) {
if (done[to] && color[to] == color[curr]) {
odd = true;
// break;
} else if (!done[to]) {
q.push_back(to);
color[to] = !color[curr];
}
}
q.pop_front();
// if (odd) break;
}
if (odd) a++;
else c++;
}
// std::cout << a << " " << b << " " << c << std::endl;
std::cout << (a * a + 2 * a * c + 2 * c * c + 2 * n * b - b * b) << std::endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<30;
template<class T> inline bool chmax(T &a, T b)
{
if(a < b)
{
a = b;
return true;
}
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int H, W;
cin >> H >> W;
vector<int> A(H), B(H);
for(int i=0; i<H; i++)
{
cin >> A[i] >> B[i];
A[i]--;
B[i]--;
}
map<int, int> path;
multiset<int> dist;
for(int i=0; i<W; i++)
{
path[i] = i;
dist.insert(0);
}
for(int i=0; i<H; i++)
{
int idx = -1;
for(auto itr = path.lower_bound(A[i]); itr != path.end() && itr->first <= B[i] + 1; itr = path.erase(itr))
{
chmax(idx, itr->second);
auto ditr = dist.find(itr->first - itr->second);
dist.erase(ditr);
}
if(idx != -1 && B[i] + 1 < W)
{
path[B[i] + 1] = idx;
dist.insert(B[i] + 1 - idx);
}
if(dist.size() == 0)
{
cout << "-1\n";
}
else
{
cout << *dist.begin() + i + 1 << '\n';
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<"\t\n"[x_i==n-1]
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;
const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);
int main() {
ll n, m; cin >> n >> m;
vl a(n), b(m); ina(a,n); ina(b,m);
sort(all(a)); sort(all(b));
rep(i,n-1) if (a[i]==a[i+1]) { puts("0"); return 0; }
rep(i,m-1) if (b[i]==b[i+1]) { puts("0"); return 0; }
ll ans = 1;
for (ll now = n*m; now > 0; now--) {
auto ita = lower_bound(all(a), now);
auto itb = lower_bound(all(b), now);
int st = (*ita == now) + (*itb == now);
if (st == 0) {
ans *= (a.end() - ita)*(b.end() - itb) - (n*m - now);
}
if (st == 1 && *ita == now) {
ans *= (b.end() - itb);
}
if (st == 1 && *itb == now) {
ans *= (a.end() - ita);
}
ans %= MOD;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
int main(){FIN
ll n,m;cin>>n>>m;
vll a(n);
REP(i,n) cin>>a[i];
vll rui(n+1,0);
ll sum=0;
REP(i,n){
sum += a[i];
rui[i+1] = sum % m;
}
map<ll,ll> mp;
REP(i,n+1) mp[rui[i]]++;
ll ans=0;
for(auto p:mp){
// cout<<p.second<<endl;
ans += p.second * (p.second-1) /2;
}
cout<<ans<<endl;
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
bool Cmp(pii a,pii b){
if(a.first>b.first){
return true;
}else{
return false;
}
}
int main(){
int n;
cin>>n;
vector<pii>team;
for(int j=0;j<n;j++) team.push_back(pii(0,j));
for(int i=0;i<(n*(n-1))/2;i++){
int ta,tb,sa,sb;
cin>>ta>>tb>>sa>>sb;
if(sa>sb){
team[--ta].first+=3;
}else if(sa<sb){
team[--tb].first+=3;
}else{
team[--ta].first++;
team[--tb].first++;
}
}
sort(team.begin(),team.end(),Cmp);
//for(pii a : team)cout <<"score :" << a.first << " team num: " <<a.second << endl;
//cout << endl;
int ans[n];
for(int i=0;i<team.size();i++){
int cnt=0;
while(team[i].first==team[i-1-cnt].first)cnt++;
ans[team[i].second]=i+1-cnt;
}
for(int i=0;i<n;i++){
cout << ans[i] << endl;
}
return 0;
} | //https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/1/GRL_1_A
#include <bits/stdc++.h>
using namespace std;
template<class Weight>
struct WeightedGraph {
struct Edge {
int to;
int weight;
};
int n;
vector<vector<Edge> > adj, rdj;
explicit WeightedGraph(int n) : n(n), adj(n), rdj(n) {
}
void addEdge(int u, int v, Weight w) {
adj[u].push_back({v, w});
rdj[v].push_back({u, w}); // can be omitted for the standard dijkstra
}
};
template<class Weight>
struct ShortestPath {
WeightedGraph<Weight> g;
explicit ShortestPath(WeightedGraph<Weight> g) : g(g), dist(g.n), prev(g.n) {
}
vector<Weight> dist;
vector<int> prev;
void solve(int s) {
prev.assign(g.n, -1);
dist.assign(g.n, -1);
dist[s] = 0;
using Node = pair<Weight, int>;
priority_queue<Node, vector<Node>, greater<> > que;
que.push({0, s});
while (!que.empty()) {
auto d = que.top().first;
auto u = que.top().second;
que.pop();
if (dist[u] < d) continue;
for (auto e: g.adj[u]) {
auto v = e.to;
auto w = e.weight;
if (dist[v] >= 0 && dist[v] <= dist[u] + w) continue;
dist[v] = dist[u] + w;
prev[v] = u;
que.push({dist[v], v});
}
}
}
int solve(int s, int t) {
if (s == t) return dist[s] = 0;
fill(dist.begin(), dist.end(), -1);
dist[s] = 0;
vector<Weight> drev(g.n, -1);
drev[t] = 0;
using Node = pair<Weight, int>;
priority_queue<Node, vector<Node>, greater<> > qs, qt;
qs.push({0, s});
qt.push({0, t});
int mu = -1;
while (!qs.empty() && !qt.empty()) {
if (mu >= 0 && qs.top().first + qt.top().first >= mu) break;
if (qs.top().first <= qt.top().first) {
auto d = qs.top().first;
auto u = qs.top().second;
qs.pop();
if (dist[u] > d) continue;
for (auto e: g.adj[u]) {
auto v = e.to;
auto w = e.weight;
if (dist[v] >= 0 && dist[v] <= dist[u] + w) continue;
dist[v] = dist[u] + w;
qs.push({dist[v], v});
if (drev[v] >= 0) {
auto nu = dist[v] + drev[v];
if (mu < 0 || mu > nu) mu = nu;
}
}
} else {
auto d = qt.top().first;
auto u = qt.top().second;
qt.pop();
if (drev[u] > d) continue;
for (auto e: g.rdj[u]) {
auto v = e.to;
auto w = e.weight;
if (drev[v] >= 0 && drev[v] <= drev[u] + w) continue;
drev[v] = drev[u] + w;
qt.push({drev[v], v});
if (dist[v] >= 0) {
auto nu = dist[v] + drev[v];
if (mu < 0 || mu > nu) mu = nu;
}
}
}
}
return mu;
}
};
int main() {
int V, E, r;
cin >> V >> E >> r;
WeightedGraph<int> g(V);
for (int i = 0; i < E; ++i) {
int s, t, c;
cin >> s >> t >> c;
g.addEdge(s, t, c);
}
ShortestPath<int> solver(g);
solver.solve(r);
for (int i = 0; i < V; ++i) {
if (solver.dist[i] != -1) {
cout << solver.dist[i] << endl;
} else {
cout << "INF" << endl;
}
}
return 0;
}
/*
* Dijkstra
*/
| 0 |
#include <bits/stdc++.h>
using namespace std;
void Sum(int data[3],int K){
data[2] *= 2;
if(K == 1){
int sum = 0;
for(int i=0;i<3;i++) sum += data[i];
cout << sum << endl;
}
else{
Sum(data,K-1);
}
}
int main(void){
int data[3];
int K;
for(int i=0;i<3;i++) cin >> data[i];
cin >> K;
sort(data,data+3);
Sum(data,K);
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";
ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}
int main(){
fast;
#ifndef ONLINE_JUDGE
freopen("input1.txt","r",stdin);
freopen("output1.txt","w",stdout);
#endif
long double n, m, x;
cin>>n>>m>>x;
cout<<(ll)ceil(x/max(n, m));
} | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
vector<int> A(N);
for(int i=0; i<N; i++) cin >> A.at(i);
set<int> B;
bool flg = true;
for(int i=0; i<N; i++){
if(B.find(A.at(i)) == B.end()) B.insert(A.at(i));
else{
flg = false;
break;
}
}
if(flg) cout << "YES" << endl;
else cout << "NO" << endl;
} | #define LOCAL
#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define LLINF 100000000000000005LL
#define INF (int)1e9+1
// Copied from Gennady-Korotkevich's template
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string)s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}\n";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto& x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}\n";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
template <typename A, typename B, typename C, typename D, typename E>
string to_string(tuple<A, B, C, D, E> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + "," + to_string(get<4>(p)) + ")";
}
void debug_out() {
cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "\n[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// End of Gennady-Korotkevich's template
using llong = long long;
using PII = pair<int, int>;
int n;
vector<vector<vector<double>>> dp;
double dfs(int one, int two, int three) {
double& ret = dp[one][two][three];
int cnt = one + two + three;
if (cnt == 0) return 0;
if (ret != -1) return ret;
ret = 0;
if (one >= 1) ret += dfs(one - 1, two, three) * one / (cnt);
if (two >= 1) ret += dfs(one + 1, two - 1, three) * two / (cnt);
if (three >= 1) ret += dfs(one, two + 1, three - 1) * three / (cnt);
ret += (double)n / (cnt);
return ret;
}
int main() {
IOS;
cin >> n;
dp = vector<vector<vector<double>>>(n + 1, vector<vector<double>>(n + 1, vector<double>(n + 1, -1)));
int one = 0, two = 0, three = 0;
for (int i = 0; i < n; i++) {
int a; cin >> a;
if (a == 1) one++;
else if (a == 2) two++;
else three++;
}
cout << fixed << setprecision(15);
cout << dfs(one, two, three);
} | 0 |
#include <cstdio>
#include <algorithm>
using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using usize = std::size_t;
i32 a[200000];
auto main() -> i32 {
i32 n, k;
scanf("%d%d", &n, &k);
for (i32 i = 0; i < n; i += 1) {
scanf("%d", a + i);
}
i32 b[200001];
for (i32 step = 0; step < std::min(64, k); step += 1) {
std::fill(b, b + n + 1, 0);
for (i32 i = 0; i < n; i += 1) {
b[std::max(0, i - a[i])] += 1;
b[std::min(n, i + a[i] + 1)] -= 1;
}
a[0] = b[0];
for (i32 i = 1; i < n; i += 1) {
b[i] += b[i - 1];
a[i] = b[i];
}
}
for (i32 i = 0; i < n; i += 1) {
printf("%d%c", a[i], i == n - 1 ? '\n' : ' ');
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<ll, ll> P;
const int mod = 1000000007; //出力は (ans % mod + mod) % mod (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60; // INF = 11
int main()
{
int n,k; cin >> n >> k;
int a[n];
rep(i,n) cin >> a[i];
int tmp[n];
for(int t = 0; t < k; t++){
rep(i,n) tmp[i] = 0;
rep(i,n){
if(i - a[i] < 0){
tmp[0]++;
}else{
tmp[i-a[i]]++;
}
if(i + 1 + a[i] < n){
tmp[i+1+a[i]]--;
}
}
a[0] = tmp[0];
rep(i,n-1){
a[i+1] = a[i] + tmp[i+1];
}
bool f = true;
rep(i,n) if(a[i] != n) f = false;
if(f) break;
}
rep(i,n) cout << a[i] << ' ';
} | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long n,m,x=0,ans=0;
cin >> n >> m;
map<long,long> aaa;
aaa[0]=1;
for(long i=0;i<n;i++) {
long a;
cin >> a;
x+=a;
x=x%m;
aaa[x]++;
ans+=aaa[x]-1;
}
cout << ans << endl;
} | #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
using namespace std;
const int maxN = 2007;
template<class T> inline T rd() {
bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}
int n, m;
char s[maxN][maxN];
int a[maxN], b[maxN], c[maxN];
int mat[maxN][maxN];
int stack[maxN], Top, ans = 0;
int main() {
n = ri(), m = ri();
rep (i, 1, n) scanf("%s", s[i]+1);
For (i, 1, n) {
rep (j, 1, m) a[j] = s[i][j] == '.' ? 1 : 0;
rep (j, 1, m) b[j] = s[i+1][j] == '.' ? 1 : 0;
rep (k, 0, 1) {
rep (j, 1, m) b[j] ^= k;
per (j, m, 1) c[j] = (a[j] == b[j]) ? 1 + c[j+1] : 0;
rep (j, 1, m) mat[i][j] = max(mat[i][j], c[j]);
}
}
rep (j, 1, m) {
Top = 0;
For (i, 1, n) {
for (; Top && mat[stack[Top]][j] >= mat[i][j]; --Top) {
ans = max(ans, mat[stack[Top]][j] * (i - stack[Top-1]));
}
stack[++Top] = i;
}
for (; Top; --Top) {
ans = max(ans, mat[stack[Top]][j] * (n - stack[Top-1]));
}
}
printf("%d\n", max(ans, m));
return 0;
}
| 0 |
#include<iostream>
using namespace std;
int n,A,B;
int main(){
while(true){
cin>>n;
if(n==0)break;
for(int i=0;i<n;i++){
int a,b;
cin>>a>>b;
if(a>b)A=A+a+b;
else if(a<b)B=B+a+b;
else A=A+a,B=B+b;
}
cout<<A<<" "<<B<<endl;
A=0,B=0;
}
return 0;
} |
#include <iostream>
using namespace std;
int main()
{
int n, a, b, count = 0, pointX = 0, pointY = 0;
cin >> n;
do {
cin >> a >> b;
if (a > b) {
pointX += (a + b);
}
else if (a < b) {
pointY += (a + b);
}
else {
pointX += a;
pointY += b;
}
count++;
if (count == n) {
cout << pointX << " " << pointY << endl;
pointX = pointY = count = 0;
cin >> n;
}
} while (n != 0);
return 0;
} | 1 |
#include <iostream>
#include <vector>
//#define rep(i,n) for(int i = 0; i , (n); ++i)
using ll = long long;
using namespace std;
int sum(int n) {
if (n == 0) {
return 0;
}
int s = sum(n - 1);
return s + n;
}
int main() {
int N, W;
cin >> N >> W;
vector<vector<char>>A(N, vector<char>(W));
for (int i = 0;i < N;i++) {
for (int j = 0;j < W;j++) {
cin >> A.at(i).at(j);
}
}
bool hantei = true;
for (int i = 0;i < N;i++) {
for (int j = 0;j < W;j++){
if (j>0&&j<(W-1)&&i>0&&i<(N-1)&&A.at(i).at(j) == '#'&&A.at(i + 1).at(j) == '.' && A.at(i - 1).at(j) == '.' &&
A.at(i).at(j + 1) == '.' && A.at(i).at(j - 1) == '.') {
hantei=false;
break;
}
}
if (hantei == false) {
break;
}
}
if (hantei) {
cout << "Yes";
}
else {
cout << "No";
}
}
| #include <bits/stdc++.h>
using namespace std;
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;} //最大公約数
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;} //最小公倍数
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;} //コンビネーション
int nHr(int a,int b){return nCr(a+b-1,b);} // 重複組み合わせ
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;} //階乗
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;} // a~bまでの階乗
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;} //数字の各位の和
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;} // b進数の各位の和?
int sankaku(int x){return ((1+x)*x)/2;} //三角数 xまでの和
//以下long long ver
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llnHr(long long a,long long b){return llnCr(a+b-1,b);}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long lldsum(long long x){long long r=0;while(x){r+=(x%10);x/=10;}return r;}
long long lldsumb(long long x,long long b){long long r=0;while(x){r+=(x%b);x/=b;}return r;}
long long llsankaku(long long x){return ((1+x)*x)/2;}
//double
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) ; for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
bool is_prime (int x){
if (x<=1) return false ;
for (int i=2 ; i*i<=x ; i++){
if (x%i==0) return false ;
}
return true;
}
string alpha = "abcdefghijklmnopqrstuvwxyz" ;
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
bool chmin (int a,int b){
if ( a > b ){
a = b;
return true ;
}
return false ;
}
bool chmax (int a,int b){
if ( a < b ){
a = b;
return true ;
}
return false ;
}
#define SORT(c) sort((c).begin(),(c).end());
#define ANS(ans) cout<<(ans)<<endl;
string split (string s , ll n , char x){
// n文字目は前の文字列
string a ,b,c,d;
a = s;
b = s;
if ( x == 'f'){
return c = a.erase(n) ;
}else if ( x == 'l'){
return d = b.substr(n) ;
}
}
/*CODE START HERE*/
int main() {
int h, w;
cin >> h >> w;
bool ans = true ;
string board[50];
for (int i = 0; i < h; ++i) cin >> board[i];
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (board[i][j] == '.') continue;
int num = 0;
for (int d = 0; d < 4; ++d) {
const int ni = i + dy[d];
const int nj = j + dx[d];
if(ni<0 || h<=ni)continue;
if(nj<0 || w<=nj)continue;
if (board[ni][nj] == '#') num++;
}
if ( num == 0){
ANS("No");
return 0 ;
}
}
}
ANS("Yes") ;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int64_t n;
cin>>n;
vector<int> L(2*n);
for(int i=0;i<2*n;i++){
cin>>L.at(i);
}
sort(L.begin(),L.end());
int64_t sum=0;
for(int i=0;i<2*n;i++){
if(i%2==1)
sum+=min(L.at(i),L.at(i-1));
}
cout<<sum<<endl;
return 0;
} | //BadWaper gg
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define N 220
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
char ch=getchar();
ll s=0,w=1;
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
return s*w;
}
int a[N];
int n;
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
n=read()<<1;
for(register int i=1;i<=n;i++)a[i]=read();
sort(a+1,a+n+1);int ans=0;
for(register int i=1;i<=n;i+=2)ans+=a[i];
printf("%d\n",ans);
return 0;
}
| 1 |
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
static const long long INF = 100000000000000;
bool warshall_floyd(vector<vector<long long> > &graph);
int main() {
int v,e;
scanf ("%d %d",&v,&e);
vector<vector<long long> > g (v, vector<long long>(v,INF));
int s,t,d;
for(int i=0;i<e;i++){
scanf ("%d %d %d",&s,&t,&d);
g[s][t]=d;
}
bool x;
x=warshall_floyd(g);
if(x==true){
for(int i=0;i<v;i++){
if(g[i][0]>=INF){
printf("INF");
}
else{
printf("%lld",g[i][0]);
}
for(int j=1;j<v;j++){
if(g[i][j]>=INF){
printf(" INF");
}
else{
printf(" %lld",g[i][j]);
}
}
printf("\n");
}
}
else{
printf("NEGATIVE CYCLE\n");
}
}
// graph は隣接行列形式!
// 戻り値は負閉路検出結果で、負閉路があれば false 、なければ true
bool warshall_floyd(vector<vector<long long> > &graph) {
int V = graph.size();
// 自分までの距離は 0 としておく。後で使う。
for (int i = 0; i < V; i++) { graph[i][i] = 0; }
// 本体
for (int k = 0; k < V; k++) {
for (int i = 0; i < V; i++) {
for (int j = 0; j < V; j++) {
// 右辺に INF を含むときは計算しないようにする。
// 重みが負になる辺があると INF - 1 とかになってしまい、
// INF と区別がつかなくなる。
if (graph[i][k] < INF && graph[k][j] < INF){
graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
}
}
}
}
// 負閉路検出をやる
for (int i = 0; i < V; i++) {
if (graph[i][i] < 0) {
// これ、もし負閉路がなければ最初に入れた 0 が残っているはず。
// そうでないということは、負閉路があって、そこを経由して自分自身に戻ってきたということ。
return false;
}
}
return true;
}
|
// D - Make Them Even
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;
struct Cell {
int y;
int x;
int c;
};
struct Move {
int y1;
int x1;
int y2;
int x2;
};
int field[500][500];
Cell cells[500 * 500];
int main() {
int H, W;
cin >> H >> W;
for (int i=0; i<H; i++) {
for (int j=0; j<W; j++) {
cin >> field[i][j];
}
}
int k = 0;
for (int i=0; i<H; i++) {
if (i % 2 == 0) {
for (int j=0; j<W; j++) {
cells[k] = {i, j, field[i][j]};
k++;
}
} else {
for (int j=W-1; j>=0; j--) {
cells[k] = {i, j, field[i][j]};
k++;
}
}
}
int N = 0;
vector<Move> ans;
for (int i=0; i<H*W-1; i++) {
if (cells[i].c % 2 == 1) {
ans.push_back(Move{cells[i].y, cells[i].x, cells[i+1].y, cells[i+1].x});
cells[i+1].c++;
N++;
}
}
cout << N << endl;
for (Move a : ans) {
cout << a.y1 + 1 << " " << a.x1 + 1 << " " << a.y2 + 1 << " " << a.x2 + 1 << endl;
}
return 0;
} | 0 |
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a,b,c,d,n,maxi=0,f=0,mini=INF,sum=0;
string str;
cin>>str;
if(str.length()==2&&str[0]==str[1]) {
cout<<1<<" "<<2<<endl;
return 0;
}
rep(i,str.length()-2){
if(str[i]==str[i+1]){
cout<<i+1<<" "<<i+3<<endl;
return 0;
}if(str[i]==str[i+2]){
cout<<i+1<<" "<<i+3<<endl;
return 0;
}
}
if(str[str.length()-2]==str[str.length()-1]) {
cout<<str.length()-2<<" "<<str.length()<<endl;
return 0;
}
cout<<-1<<" "<<-1<<endl;
}
| #include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
if (a < b)
{
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return 1;
}
return 0;
}
struct io
{
io()
{
ios::sync_with_stdio(false);
cin.tie(0);
}
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
string replaceOtherStr(std::string &replacedStr, std::string from, std::string to) {
const ll pos = replacedStr.find(from);
const ll len = from.length();
if (pos == (ll)std::string::npos || from.empty()) {
return replacedStr;
}
return replacedStr.replace(pos, len, to);
}
signed main() {
string s;
cin >> s;
stack<char> stk;
rep(i, (ll)s.length()) {
if (stk.empty()) {
stk.push(s[i]);
} else {
if (stk.top() == 'S' && s[i] == 'T') {
stk.pop();
} else {
stk.push(s[i]);
}
}
}
mes(stk.size());
re0;
} | 0 |
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 2e5 + 5;
typedef long long ll;
using namespace std;
int n, A, B, x[N];
ll ans;
template < typename T >
inline T read()
{
T x = 0, w = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * w;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("cpp.in", "r", stdin);
#endif
n = read <int> (), A = read <int> (), B = read <int> ();
for(int i = 1; i <= n; i++) x[i] = read <int> ();
for(int i = 1; i < n; i++) ans += min(1ll * B, 1ll * A * (x[i + 1] - x[i]));
printf("%lld\n", ans);
return 0;
}
| #include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define vi vector <int>
#define vii vector <int>::iterator
#define vd vector <double>
#define vdd vector <double>::iterator
#define vs vector <string>
#define vss vector <string>::iterator
#define vc vector <char>
#define vcc vector <char>::iterator
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
#define SORT(x) sort(x.begin(),x.end())
#define fill(x,y) memset(x, y, sizeof(x))
#define PI 2*acos(0.0)
#define fio ios::sync_with_stdio(false);cin.tie(0)
using namespace std;
int main(){
ll a;
cin >> a;
cout << a*(1+(a*(a+1))) << endl;
} | 0 |
#include<iostream>
using namespace std;
#include<stdio.h>
int f_r(int d,int x){
x=x+d;
if(x>=600)return 0;
return d*x*x+f_r(d,x);
}
int main(){
int d;
int s;
while((scanf("%d",&d))!=EOF){
s=f_r(d,0);
printf("%d\n",s);
}
return 0;
} | #include "bits/stdc++.h"
#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())
using namespace std;
using LL = long long int;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;
const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;
const int dy[] = { 0, 1, 0, -1 };
const int dx[] = { 1, 0, -1, 0 };
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
LL d;
while (cin >> d) {
LL ans = 0;
for (LL i = 1; i * d <= 600 - d; i++) {
ans += i * d * i * d * d;
}
cout << ans << endl;
}
return 0;
} | 1 |
#include <stdio.h>
int main() {
int n, i, num[2], result[2] = { 0,0 };
while (scanf("%d", &n)) {
if (n == 0) break;
result[0] = 0;
result[1] = 0;
for (i = 0; i < n; i++) {
scanf("%d %d", &num[0], &num[1]);
if (num[0] > num[1]) result[0] += num[0] + num[1];
else if (num[0] < num[1]) result[1] += num[0] + num[1];
else result[0] += num[0], result[1] += num[1];
}
printf("%d %d\n", result[0], result[1]);
}
return 0;
} | #include<iostream>
using namespace std;
int main(){
int a;
int uma;
int ushi;
int b;
int c;
int i;
while (true){
cin >> a;
if (a == 0){ break; }
else{
while (true){
if (i<a){
cin >> b;
cin >> c;
if (b>c){
uma = uma + b + c;
}
else if (b == c){
uma = uma + b;
ushi = ushi + c;
}
else{
ushi = ushi + b + c;
}
i = i + 1;
}if (i == a){ break; }
}
cout << uma << " " << ushi << endl;
uma = 0;
ushi = 0;
i = 0;
}
}
} | 1 |
#include <bits/stdc++.h>
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007
using namespace std;
typedef long long ll;
const int match[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
int main()
{
int N, M;
cin >> N >> M;
int A[M];
REP(i, M)
{
cin >> A[i];
A[i]--;
}
vector<array<int, 9>> dp(N + 1, {0});
bool isMake[N + 1] = {false};
isMake[0] = true;
for (int i = 1; i <= N; ++i)
{
vector<array<int, 9>> candidate;
REP(j, M)
{
if (i - match[A[j]] >= 0)
{
if (isMake[i - match[A[j]]])
{
array<int, 9> current = dp[i - match[A[j]]];
current[A[j]]++;
candidate.push_back(current);
isMake[i] = true;
}
}
}
if (isMake[i])
{
array<int, 9> maxArray = {0};
int countMaxSet = 0;
for (auto iter = candidate.begin(); iter != candidate.end(); ++iter)
{
int count = 0;
REP(j, 9) count += (*iter)[j];
if (count != countMaxSet)
{
if (count > countMaxSet)
{
countMaxSet = count;
maxArray = *iter;
}
}
else
{
for (int j = 8; j >= 0; --j)
{
if (maxArray[j] > (*iter)[j])
{
break;
}
else if (maxArray[j] < (*iter)[j])
{
maxArray = *iter;
break;
}
}
}
}
dp[i] = maxArray;
}
}
for(int i = 8; i >= 0; --i) REP(j, dp[N][i]) cout << i + 1;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const ll mod = 1e9+7;
int main(){
int n, m;
cin >> n >> m;
int a[n], b[m];
vector<ll> va(n*m+1,0), vb(n*m+1,0);
rep(i,n) {
cin >> a[i];
va[a[i]]++;
}
rep(i,m) {
cin >> b[i];
vb[b[i]]++;
}
vector<ll> num(n*m+1,0);
rep(i,n) {
rep(j,m) num[min(a[i],b[j])]++;
}
ll ans = 1, s = 0;
for(int i = n*m; i >= 1; i--) {
if(va[i] >= 2 || vb[i] >= 2) {
ans = 0;
} else if (va[i] == 1 && vb[i] == 1){
ans *= 1;
} else if(va[i] == 1 || vb[i] == 1) {
(ans *= num[i]) %= mod;
} else {
(ans *= num[i] + s) %= mod;
}
s += num[i] - 1;
}
cout << ans << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int d,t,s;
cin >> d >> t >> s;
if (s*t>=d) cout << "Yes" << endl;
else cout << "No " << endl;
} | #include <iostream>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <vector>
using namespace std;
//const char a[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
const int maxN=50;
int dp[maxN+1][maxN+1][maxN*maxN+1];
void solver() {
string a,b,c;
cin>>a>>b>>c;
char n = a[0];
a.erase(0,1);
while(1){
if(n == 'a'){
if(a.size() == 0){
cout<<"A"<<endl;
return; }
n = a[0];
a.erase(0,1);
}else if(n == 'b'){
if(b.size() == 0){
cout<<"B"<<endl;
return;
}
n = b[0];
b.erase(0,1);
}
else if(n == 'c'){
if(c.size() == 0){
cout<<"C"<<endl;
return;
}
n = c[0];
c.erase(0,1);
}
}
return;
}
int main() {
int n=1;
//cin>>n;
while(n--)
{
solver();
}
}
| 0 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef pair<int, int> P;
class UnionFind {
public:
vector<int> Parent;
UnionFind(int N) {
Parent = vector<int>(N, -1);
}
int root(int A) {
if(Parent[A] < 0) return A;
return Parent[A] = root(Parent[A]);
}
int size(int A) {
return -Parent[root(A)];
}
bool connect(int A, int B) {
A = root(A);
B = root(B);
if(A==B) {
return false;
}
if(size(A) < size(B)) swap(A, B);
Parent[A] += Parent[B];
Parent[B] = A;
return true;
}
};
int main() {
int N, K, L; cin >> N >> K >> L;
UnionFind Uni(N);
UnionFind U(N);
map<P, int> m;
for(int i = 0; i < K; ++i) {
int p, q; cin >> p >> q;
p--, q--;
Uni.connect(p, q);
}
for(int i = 0; i < L; ++i) {
int r, s; cin >> r >> s;
r--, s--;
U.connect(r, s);
}
for(int i = 0; i < N; ++i) {
try {
int cnt = m.at({Uni.root(i), U.root(i)});
m.erase({Uni.root(i), U.root(i)});
m.insert({{Uni.root(i), U.root(i)}, cnt+1});
} catch(std::out_of_range&) {
m.insert({{Uni.root(i), U.root(i)}, 1});
}
}
for(int i = 0; i < N; ++i) {
try {
cout << m.at({Uni.root(i), U.root(i)});
} catch(std::out_of_range&) {
cout << 0;
}
if(i != N-1) cout << " ";
}
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)
using namespace std;
typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;
template <typename T>
inline T gi()
{
T f = 1, x = 0; char c = getchar();
while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return f * x;
}
const int INF = 0x3f3f3f3f, N = 200003, M = N << 2;
int n, k, l;
int tot, head[N], headc[N], ver[M], nxt[M];
int in1[N], cnt1, in2[N], cnt2;
bool vis1[N], vis2[N];
map <PII, int> p;
inline void add(int h[], int u, int v)
{
ver[++tot] = v, nxt[tot] = h[u], h[u] = tot;
}
void dfs1(int u, int id)
{
in1[u] = id;
vis1[u] = true;
for (int i = head[u]; i; i = nxt[i])
{
int v = ver[i];
if (!vis1[v]) dfs1(v, id);
}
}
void dfs2(int u, int id)
{
in2[u] = id;
vis2[u] = true;
for (int i = headc[u]; i; i = nxt[i])
{
int v = ver[i];
if (!vis2[v]) dfs2(v, id);
}
}
int main()
{
//File("");
n = gi <int> (), k = gi <int> (), l = gi <int> ();
for (int i = 1; i <= k; i+=1)
{
int u = gi <int> (), v = gi <int> ();
add(head, u, v), add(head, v, u);
}
for (int i = 1; i <= l; i+=1)
{
int u = gi <int> (), v = gi <int> ();
add(headc, u, v), add(headc, v, u);
}
for (int i = 1; i <= n; i+=1)
if (!vis1[i]) dfs1(i, ++cnt1);
for (int i = 1; i <= n; i+=1)
if (!vis2[i]) dfs2(i, ++cnt2);
for (int i = 1; i <= n; i+=1) ++p[make_pair(in1[i], in2[i])];
for (int i = 1; i <= n; i+=1)
printf("%d ", p[make_pair(in1[i], in2[i])]);
return 0;
}
| 1 |
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define YOU using
#define DONT namespace
#define SAY std
YOU DONT SAY;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)
#define pb push_back
#define F first
#define S second
const int OO = 1e9;
const ll INF = 1e18;
const int irand(int lo,int hi){
return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}
const ll lrand(ll lo,ll hi){
return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}
#define getc getchar
template<typename T>
T getnum(){
int sign = 1;
T ret = 0;
char c;
do{
c = getc();
}while(c == ' ' || c == '\n');
if(c == '-')sign = -1;
else ret = c-'0';
while(1){
c = getc();
if(c < '0' || c > '9')break;
ret = 10*ret + c-'0';
}
return sign * ret;
}
inline void ini(int& x){
x = getnum<int>();
}
inline void scani(int& x){
scanf("%d",&x);
}
//end of macro
const ll MOD = 1e9 + 7;
inline ll addmod(ll a, ll b){
if(a+b<MOD)return a+b;
return a+b-MOD;
}
inline ll mulmod(ll a, ll b){
return (a*b)%MOD;
}
inline ll expmod(ll a, ll e){
ll ret = 1;
while(e){
if(e&1)ret = mulmod(ret, a);
a = mulmod(a, a);
e >>= 1;
}
return ret;
}
inline ll divmod(ll a, ll b){
return mulmod(a, expmod(b, MOD-2));
}
int n,x,y,z;
int tmask;
int m1, m2, m3;
int memo[40][1<<16][2];
int dp(int now, int mask, bool ok){
if(now == n)return ok;
int& ret = memo[now][mask][ok];
if(ret != -1)return ret;
ret = 0;
int nmask = mask<<1|1;
REP(i,1,10){
bool nok = ok;
if((nmask & m1) && (nmask & m2) && (nmask & m3)){
nok = true;
}
ret = addmod(ret, dp(now+1, nmask & tmask, nok));
nmask <<= 1;
}
// if(ret > 0){
// printf("%d %d %d = %d\n",now,mask,ok,ret);
// }
return ret;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define endl '\n'
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(10);
cin>>n>>x>>y>>z;
tmask = (1 << (x + y + z - 1)) - 1;
m1 = 1<<(z-1);
m2 = 1<<(y+z-1);
m3 = 1<<(x+y+z-1);
memset(memo, -1, sizeof memo);
cout << dp(0, 0, false) << endl;
return 0;
}
| // IOI 2021
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
////////////////////////////////////////////////////////////////////
const int N = 2e5 + 5;
int F[N], I[N];
int P(int a, int b) {
int res = 1;
for (; b; b >>= 1, a = 1LL * a * a % MOD) if (b & 1) res = 1LL * res * a % MOD;
return res;
}
int C(int n, int r) { return r > n ? 0 : 1LL * I[r] * I[n - r] % MOD * F[n] % MOD; }
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
F[0] = 1;
for (int i = 1; i < N; i++) F[i] = 1LL * F[i - 1] * i % MOD;
I[N - 1] = P(F[N - 1], MOD - 2);
for (int i = N - 2; i >= 0; i--) I[i] = 1LL * I[i + 1] * (i + 1) % MOD;
int n, m, k; cin >> n >> m >> k;
int ans = 0;
for (int i = 1; i <= n; i++) ans = (ans + 1LL * i * (n - i) % MOD * m % MOD * m % MOD) % MOD;
for (int i = 1; i <= m; i++) ans = (ans + 1LL * i * (m - i) % MOD * n % MOD * n % MOD) % MOD;
cout << 1LL * ans * C(n * m - 2, k - 2) % MOD << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる => (a + b - 1) / b
vi vx={-1,0,1,0};
vi vy={0,1,0,-1};
using pi = pair<int,int>;
signed main(){
int a,b; cin>>a>>b;
vvi v(a,vi(b));
queue<pi> q;
rep(i,0,a){
rep(j,0,b){
char c; cin>>c;
if(c=='#'){
v[i][j]=1;
q.push(make_pair(i,j));
}
else v[i][j]=0;
}
}
while(!q.empty()){
pi p=q.front(); q.pop();
int k,l; tie(k,l)=p;
bool ok=false;
rep(i,0,4){
k+=vx[i]; l+=vy[i];
if(k>=0 && k<a){
if(l>=0 && l<b){
if(v[k][l]==1)ok=true;
}
}
k-=vx[i]; l-=vy[i];
}
if(!ok){
cout<<"No"<<endl;
return 0;
}
}
cout<<"Yes"<<endl;
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
int main(){
int i,j;
int h,w;
cin >> h >> w;
vector<vector<char>> v(h+2,vector<char>(w+2,'.'));
for(i=1;i<=h;i++){
for(j=1;j<=w;j++){
cin >> v[i][j];
}
}
for(i=1;i<=h;i++){
for(j=1;j<=w;j++){
if(v[i][j]=='#'){
if(v[i][j+1]!='#'&&v[i][j-1]!='#'&&v[i+1][j]!='#'&&v[i-1][j]!='#'){
cout << "No" << "\n";
return 0;
}
}
}
}
cout << "Yes" << "\n";
return 0;
}
| 1 |
#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 unsigned 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()
{
int n, r;
cin >> n >> r;
if(n>=10){
cout << r << endl;
}else{
cout << r + 1000 - 100 * n << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
int main() {
int n, r;
cin >> n >> r;
int rate;
if (n > 10) {
rate = r;
} else {
rate = r + (100 * (10 - n));
}
cout << rate << endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i < (int)(b); ++i)
#define endl "\n"
typedef long long ll;
const double pi=3.14159265358979323846;
int ctoi(const char c) {
if ('0' <= c && c <= '9') return (c - '0');
return -1;
}
vector<int> input(int n) {
vector<int> vec(n);
for (int i = 0; i < n; i++) {
cin >> vec.at(i);
}
return vec;
}
void output(vector<int> vec) {
for (int i = 0; i < int(vec.size()); i++) {
cout << vec[i] << " ";
}
return;
}
vector<vector<int>> input(int n, int m) {
vector<vector<int>> table(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> table. at(i).at(j);
}
}
return table;
}
void output(vector<vector<int>> table) {
for (int i = 0; i < int(table.size()); i++) {
for (int j = 0; j < int(table.at(0).size()); j++) {
cout << table.at(i).at(j) << " ";
}
cout << endl;
}
}
long long perm(int n, int r) {
if (n < r) {
cout << "error" << endl;
return 0;
}
long long perm = 1;
for (int i = n; i > n - r; i--) {
perm *= i;
}
return perm;
}
long long comb(int n, int r) {
if (n < r) {
cout << "error" << endl;
return 0;
}
long long comb = perm(n,r);
for (int i = r; i > 0; i--) {
comb /= i;
}
return comb;
}
long long homo(int n, int r) {
return comb(n + r - 1, n - 1);
}
long long fact(int n) {
long long fact = 1;
for (int i = n; i > 0; i--) {
fact *= i;
}
return fact;
}
int gcd(int a, int b){
if (a % b == 0){
return(b);
}else{
return(gcd(b, a % b));
}
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
bool isprime(int n){
if (n < 2) return false;
else if (n == 2) return true;
else if (n % 2 == 0) return false;
for (int i = 3; i <= sqrt(n); i += 2){
if (n % i == 0){
return false;
}
}
return true;
}
vector<long long> divisors(long long N) {
vector<long long> res;
for (long long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
// 重複しないならば i の相方である N/i も push
if (N/i != i) res.push_back(N/i);
}
}
// 小さい順に並び替える
sort(res.begin(), res.end());
return res;
/*long long N;
cin >> N;
vector<long long> res = divisors(N);
for (int i = 0; i < res.size(); ++i) {
cout << res[i] << " ";
}
cout << endl;*/
}
vector<pair<long long, long long> > prime_factorize(long long N) {
vector<pair<long long, long long> > res;
for (long long a = 2; a * a <= N; ++a) {
if (N % a != 0) continue;
long long ex = 0;
while (N % a == 0) {
++ex;
N /= a;
}
res.push_back({a, ex});
}
if (N != 1) res.push_back({N, 1});
return res;
}
void Yes(bool f) {
if (f) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
}
void YES(bool f) {
if (f) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
int main() {
int n,cnt=0;
cin >> n;
string a,b,c;
cin >> a >> b >> c;
rep(i,0,n){
if(a[i]==b[i]&&b[i]==c[i]){
continue;
}else if(a[i]!=b[i]&&b[i]!=c[i]&&c[i]!=a[i]){
cnt+=2;
}else{
cnt++;
}
}
cout << cnt << endl;
} | #include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
ll mi = 1e9, sum = 0;
vector<ll> a(n);
int cnt = 0;
bool zero = false;
rep(i,n){
cin >> a[i];
if(a[i] < 0){
++cnt;
chmin(mi, -a[i]);
sum -= a[i];
}
else if(a[i] == 0) zero = true;
else{
chmin(mi, a[i]);
sum += a[i];
}
}
ll ans = sum;
if(!zero && (cnt%2 == 1)) ans -= 2 * mi;
cout << ans << endl;
return 0;
} | 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[100];
char y[100];
scanf("%s%s\n", &x,&y);
printf("%s%s\n", y, x);
return 0;
}
| 1 |
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include<iomanip>
#include<utility>
using namespace std;
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
#define S 21
llfor;
const ll mod=1000000007;
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/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;}
/*n乗*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)*fact(n-r)/fact(r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=1,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*行列のコピー*/void matcpy(ll a[S][S],ll b[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)b[i][j]=a[i][j];/*(aをbに)*/i=t;}
/*行列のリセット*/void matrst(ll a[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)a[i][j]=0;i=t;}
/*行列の2乗*/void matpow(ll a[S][S]){ll ans[S][S];matrst(ans);ll t=i,k;rep(i,0,S)rep(j,0,S)rep(k,0,S)ans[i][j]+=a[i][k]*a[k][j];matcpy(ans,a);i=t;}
/*行列の乗算*/void matmul(ll a[S][S],ll b[S][S], ll as[S][S]){ll t=i,k;matrst(as);rep(i,0,S)rep(j,0,S)rep(k,0,S)as[i][j]+=a[i][k]*b[k][j];i=t;}
//ll ans=0;
////////////////////////////////////////////////////////////
int main(){
ll n;cin>>n;
bool a[n+10];
rep(i,1,n+1)sc(a[i]);
ll box[n+10]={0},c,sum=0;
rrp(i,n+1,1){
c=0;
for(j=2;j*i<=n;j++)c+=box[j*i];
if(c%2!=a[i]){
box[i]=1;
sum++;
}
}
pr(sum);
rep(i,1,n+1){
if(box[i]!=0)cout<<i<<" ";
}
pnn;
return 0;}
| #include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 100000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;
int A[5*100000 + 10];
int S[5*100000 + 10];
vi idx[(1LL<<20)+10];
//idx[i]:S中の,iの存在するindexのリスト
int zero[5*100000 + 10];
//zero[i]:S中のi番目までに,いくつ0があるか
int dp[5*100000+10];
//dp[i]:i番目まで見たときの場合の数
signed main(void) {
int N;
cin>>N;
S[0]=0;
zero[0]=0;
REP(i,1,N) {
cin>>A[i];
S[i] = S[i-1]^A[i];
if (S[i] == 0) zero[i] = zero[i-1]+1;
else zero[i] = zero[i-1];
idx[S[i]].pb(i);
// cerr<<S[i]<<"\t";
}
// cerr<<endl;
// REP(i,1,N) cerr<<zero[i]<<"\t";
// cerr<<endl;
if (S[N] == 0) {
//Sの右端が0のケース
int ans = 0;
REP(d,1,1LL<<20) {
// REP(d,1,8) {
//まず,dがSのなかにいくつあるのか確認
int dnum = idx[d].size();
if (dnum==0) continue;
//0,d,0,...,d,0だから,必要なdp配列の数はdnum*2+1;
dp[0]=1; //スタート→1通り
int from_zero=1;
int from_d=0;
REP(i,1,dnum*2) {
if (i==dnum*2) { //ラス1→絶対右端で止まらないといけないので1通り
dp[i] = from_d;
} else if (i%2==0) { //iが偶数→現在地はd
//まず,行き先候補の0の数を計算
int znum = (zero[idx[d][i/2]]-zero[idx[d][i/2-1]]) % mod;
dp[i] = znum * from_d % mod;
from_zero += dp[i];
from_zero %= mod;
} else { //iが奇数→現在地は0
dp[i] = from_zero;
from_d += dp[i];
from_d %= mod;
}
// cerr<<dp[i]<<"\t";
}
// cerr<<endl;
// cerr<<"d="<<d<<"の時:"<<dp[dnum*2]<<endl;
ans += dp[dnum*2];
ans %= mod;
}
//d=0でpartitionする場合→2^(0の総数-1)通り
int pow2 = 1;
REP(j,1,zero[N]-1) {
pow2 *= 2;
pow2 %= mod;
}
cout << (ans + pow2) % mod << endl;
} else { //Sの右端が0でない→それをdとしてやるだけ
int d=S[N];
//まず,dがSのなかにいくつあるのか確認
int dnum = idx[d].size();
//0,d,0,...,0,dだから,必要なdp配列の数はdnum*2;
dp[0]=1; //スタート→1通り
int from_zero=1;
int from_d=0;
REP(i,1,dnum*2-1) {
if (i%2==0) { //iが偶数→現在地はd
//まず,行き先候補の0の数を計算
int znum = (zero[idx[d][i/2]]-zero[idx[d][i/2-1]]) % mod;
dp[i] = (znum * from_d) % mod;
from_zero += dp[i];
from_zero %= mod;
} else { //iが奇数→現在地は0
dp[i] = from_zero;
from_d += dp[i];
from_d %= mod;
}
// cerr<<dp[i]<<"\t";
}
// cerr<<endl;
// cerr<<"d="<<d<<"の時:"<<dp[dnum*2]<<endl;
cout << dp[dnum*2-1] % mod << endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()
ll modPow(ll a, ll n) {
if (n == 0) return 1; // 0乗にも対応する場合
if (n == 1) return a % MOD;
if (n % 2 == 1) return (a * modPow(a, n - 1)) % MOD;
ll t = modPow(a, n / 2);
return (t * t) % MOD;
}
ll modComb(ll n,ll a){
ll x=1,y=1;
rep(i,a){
x*=n-i;
x%=MOD;
y*=i+1;
y%=MOD;
}
y=modPow(y,MOD-2);
return (x*y)%MOD;
}
int main(){
ll N,M,K,ans=0,x;
cin >> N >> M >> K;
x=modComb(N*M-2,K-2);
rep(i,N){
ll k;
k=i*(N-i);
k%=MOD;
k*=M;
k%=MOD;
k*=M;
k%=MOD;
k*=x;
k%=MOD;
ans+=k;
ans%=MOD;
}
rep(i,M){
ll k;
k=i*(M-i);
k%=MOD;
k*=N;
k%=MOD;
k*=N;
k%=MOD;
k*=x;
k%=MOD;
ans+=k;
ans%=MOD;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
int main(){
int N; cin >> N;
int h,w; cin >> h >> w;
int r = (N-h+1) * (N-w+1);
cout << r << "\n";
} | 0 |
#include <stdio.h>
#define ICES 10
int main(){
int num[ICES];
int n, tmp;
while (scanf("%d",&n), n!=0){
for (int i=0; i<ICES; i++) num[i]=0;
for (int i=0; i<n; i++){
scanf("%d", &tmp);
num[tmp]++;
}
for (int i=0; i<ICES; i++){
if (num[i]==0){
printf("-\n");
} else {
for (int j=0; j<num[i]; j++){
printf("*");
}
printf("\n");
}
}
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef set<int> si;
typedef set<ll> sll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
const double pi = acos(-1.0);
const long long INF = 2e18;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define in insert
#define endl "\n"
#define sqr(a) ((a) * (a))
#define jor(a) !(a&1)// jor means EVEN number
#define bjor(a) (a&1)// bjor means ODD number
#define all(a) a.begin(), a.end()
#define mem(arr, b) memset(arr, b, sizeof(arr)) //memset only for -1 and 0
//fill(a, a+n, 5) //fill for any value
#define for0(i,b) for(int i=0;i<(b);i++)
#define for1(i,b) for(int i=1;i<=(b);i++)
#define forab(i,a,b) for(int i=(a);i<=(b);i++)
#define forba(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fileRead freopen("input.txt", "r", stdin);
#define fileWrite freopen("output.txt", "w", stdout);
void print(int a[], int n){ // for testing or debugging
for(int i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl;
}
//-------------------------------------------------------------------\\
int main()
{
IOS;
//fileRead
int tc = 1;
//cin>>tc;
while(tc--)
{
int n; cin>>n;
cout<<n+sqr(n)+sqr(n)*n;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;
const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
//使う前にCOMinit
//最大に注意!!!!!!!!!!!!!!!
int main() {
ll n,m,k;
cin>>n>>m>>k;
ll ans1=0;
rep(i,n){
ll num1=n-i;
ans1+=num1*i*m*m;
ans1%=MOD;
}
rep(i,m){
ll num2=m-i;
ans1+=num2*i*n*n;
ans1%=MOD;
}
COMinit();
if(n*m==2)cout<<ans1<<endl;
else{
ll ans=ans1*COM(n*m-2,k-2);
ans%=MOD;
cout<<ans<<endl;
}
return 0;
} | #include <bits/stdc++.h>
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(box) box.begin(), box.end()
using namespace std;
using P = pair<int,int>;
using ll = long long;
const long long INF = LLONG_MAX/3;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct UnionFind{
std::vector<int> par,siz;
void init(int n){
par.resize(n);
for(int i=0;i<n;i++)par[i]=i;
siz.resize(n,1);
}
UnionFind(int n){
init(n);
}
int root(int n){
if(par[n]==n)return n;
else return par[n]=root(par[n]);
}
bool issame(int x,int y){
return (root(x)==root(y));
}
bool marge(int a,int b){
if(issame(a,b))return false;
else{
a=root(a),b=root(b);
if(siz[a]<siz[b])swap(a,b);
siz[a]+=siz[b];
par[a]=par[b];
return true;
}
}
int size(int n){
return siz[root(n)];
}
};
long long gcd(long long a,long long b){
if(b==0)return a;
return gcd(b,a%b);
}
long long lcm(long long i,long long j){
return i*(j/gcd(i,j));
}
const int MOD=1e9+7;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
if(COMinited==false){
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
COMinited=true;
}
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
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);
}
signed main(){
int n,m,k;
cin>>n>>m>>k;
int cn=0;
int cnt=0;
for(int i=2;i<=n;i++)cnt+=i-1;
cn+=cnt;
for(int i=2;i<=n;i++){
cnt-=n-i+1;
cnt+=i-1;
cn+=cnt;
}
cn/=2;
int ans=0;
ans+=(((m*m)%MOD*cn)%MOD*COM(n*m-2,k-2))%MOD;
int cm=0;
cnt=0;
for(int i=2;i<=m;i++)cnt+=i-1;
cm+=cnt;
for(int i=2;i<=m;i++){
cnt-=m-i+1;
cnt+=i-1;
cm+=cnt;
}
cm/=2;
ans+=(((n*n)%MOD*cm)%MOD*COM(n*m-2,k-2))%MOD;
cout<<ans%MOD<<endl;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int N, Q;
cin >> N >> Q;
vector<vector<int>> vec(N,vector<int>(3));
for(int i=0; i<N; i++){
for(int j=0; j<3; j++){
cin >> vec.at(i).at(j);
}
}
vector<int> query(Q+2,-1e9);
for(int i=1; i<=Q; i++){
cin >> query.at(i);
}
query.at(Q+1) = 1e9+10;
vector<vector<int>> in(Q+2,vector<int>(0));
vector<vector<int>> out(Q+2,vector<int>(0));
vector<int>::iterator pos;
int idx;
for(int i=0; i<N; i++){
int s = vec.at(i).at(0);
int e = vec.at(i).at(1);
int p = vec.at(i).at(2);
pos = lower_bound(query.begin(),query.end(),s-p);
idx = distance(query.begin(),pos);
in.at(idx).push_back(p);
pos = lower_bound(query.begin(),query.end(),e-p);
idx = distance(query.begin(),pos);
out.at(idx).push_back(p);
}
map<int,int> mp;
mp[1e9+10] = 1;
for(int i=0; i<Q+1; i++){
for(int j=0; j<in.at(i).size(); j++){
if(mp.count(in.at(i).at(j))){
mp[in.at(i).at(j)]++;
}
else{
mp[in.at(i).at(j)] = 1;
}
}
for(int j=0; j<out.at(i).size(); j++){
mp[out.at(i).at(j)]--;
if(mp[out.at(i).at(j)] == 0){
mp.erase(out.at(i).at(j));
}
}
if(i != 0){
int x = mp.begin()->first;
if(x == 1e9+10){
cout << -1 << endl;
}
else{
cout << x << endl;
}
}
}
} | #include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);
int main() {
int N, Q;
cin>>N>>Q;
vector<pair<ll, ll> > sarr(N), tarr(N);
multiset<ll> xset;
ll S, T, X;
for(int i=0;i<N;++i){
cin>>S>>T>>X;
sarr[i] = mp(S-X, X);
tarr[i] = mp(T-X, X);
}
sort(sarr.begin(), sarr.end());
sort(tarr.begin(), tarr.end());
ll D[Q];
for(int i=0;i<Q;++i){
cin>>D[i];
}
ll ans[Q];
int sindex = 0, tindex = 0;
for(int i=0;i<Q;++i){
while(sindex<N && sarr[sindex].fi<=D[i]){
xset.insert(sarr[sindex].se);
sindex++;
}
while(tindex<N && tarr[tindex].fi<=D[i]){
xset.erase(xset.find(tarr[tindex].se));
tindex++;
}
if(sindex==tindex) ans[i] = -1;
else ans[i] = *xset.begin();
}
for(int i=0;i<Q;++i){
cout<<ans[i]<<endl;
}
}
| 1 |
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define int long long
#define ll long long
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
#ifdef int
constexpr int INF = LLONG_MAX / 10;
#else
constexpr int INF = INT_MAX / 10;
#endif
constexpr double eps = 1e-9;
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
if (lhs > rhs) {
lhs = rhs;
return 1;
}
return 0;
}
using namespace std;
inline ll gcd(ll a, ll b) {
while (b) {
ll c = a;
a = b; b = c % b;
}
return a;
}
inline ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
bool isprime(ll n) {
if (n == 1)return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0)return false;
}
return true;
}
ll mypow(ll a, ll b) {
if (!b)return 1;
if (b & 1)return mypow(a, b - 1) * a;
int memo = mypow(a, b >> 1);
return memo * memo;
}
int n, m, a[110];
signed main() {
cin >> n >> m;
int oddcount = 0;
rep(i, m) {
cin >> a[i];
if (a[i] & 1)oddcount++;
}
if (m == 1) {
if (a[0] == 1) {
cout << 1 << endl << 1 << endl << 1 << endl;
return 0;
}
cout << a[0] << endl;
cout << 2 << endl;
cout << a[0] - 1 << " " << 1 << endl;
return 0;
}
if (oddcount >= 3) {
puts("Impossible");
return 0;
}
if (oddcount == 2 && (n & 1)) {
puts("Impossible");
return 0;
}
REP(i, m - 1) {
if (a[i] & 1) {
if (a[0] & 1) {
swap(a[i], a[m - 1]);
break;
}
swap(a[0], a[i]);
}
}
rep(i, m - 1)cout << a[i] << " ";
cout << a[m - 1] << endl;
if (a[0] != 1) {
cout << m << endl;
cout << a[0] - 1 << " ";
}
else cout << m - 1 << endl;
REP(i, m - 2)cout << a[i] << " ";
cout << a[m - 1] + 1 << endl;
return 0;
} | #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;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
int main() {
int N,M,Q;
cin >> N >> M >> Q;
vector<int> L(M), R(M);
for(int i = 0; i < M; i++) {
cin >> L[i] >> R[i];
L[i]--, R[i]--;
}
vector<vector<int>> train(N, vector<int>(N, 0));
vector<vector<int>> train_cum(N+1, vector<int>(N+1, 0));
for(int i = 0; i < M; i++) {
train[L[i]][R[i]] += 1;
}
for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++) {
train_cum[i+1][j+1] = train_cum[i][j+1] + train_cum[i+1][j] - train_cum[i][j] + train[i][j];
}
}
int p, q;
vector<int> answer;
for(int k = 0; k < Q; k++) {
cin >> p >> q;
answer.push_back(train_cum[q][q] - train_cum[p-1][q] - train_cum[q][p-1] + train_cum[p-1][p-1]);
}
for(auto i : answer) {
cout << i << endl;
}
return 0;
} | #include <iostream>
#include <vector>
#include <queue>
#define INF 50000000000
struct vertex{
std::vector<int> edge_to;
std::vector<int> edge_cost;
bool done;
long long int mincost;
};
std::vector<vertex> G(100000);
void shortest_path(int v);
int V,E;
int r;
int main(void){
std::cin>>V>>E>>r;
for(int i=0;i<E;i++){
int from,to,cost;
std::cin>>from>>to>>cost;
G[from].edge_to.push_back(to);
G[from].edge_cost.push_back(cost);
// G[to].edge_to.push_back(from);
// G[to].edge_cost.push_back(cost);
}
shortest_path(r);
for(int i=0;i<V;i++){
if(G[i].mincost!=INF){
std::cout<<G[i].mincost<<std::endl;
}else {
std::cout<<"INF"<<std::endl;
}
}
return 0;
}
void shortest_path(int v){
for(int i=0;i<V;i++){
G[i].mincost=INF;
}
G[v].mincost=0;
while(1){
bool update=false;
for(int i=0;i<V;i++){
for(int j=0;j<G[i].edge_to.size();j++){
if(G[ G[i].edge_to[j] ].mincost>G[i].mincost+G[i].edge_cost[j]){
G[ G[i].edge_to[j] ].mincost=G[i].mincost+G[i].edge_cost[j];
update=true;
}
}
}
if(!update){
break;
}
}
} | 0 |
#include<iostream>
using namespace std;
class Dice {
public:
int *num;
Dice(int *n) {
num = n;
}
int top() {
return num[0];
}
void move(char c) {
int n[6];
for (int i = 0; i < 6; i++) {
n[i] = num[i];
}
if (c == 'N') {
num[0] = n[1];
num[1] = n[5];
num[4] = n[0];
num[5] = n[4];
} else if (c == 'S') {
num[0] = n[4];
num[1] = n[0];
num[4] = n[5];
num[5] = n[1];
} else if (c == 'W') {
num[0] = n[2];
num[2] = n[5];
num[3] = n[0];
num[5] = n[3];
} else {
num[0] = n[3];
num[2] = n[0];
num[3] = n[5];
num[5] = n[2];
}
}
};
int main() {
int num[6];
string c;
for (int i = 0; i < 6; i++) {
cin >> num[i];
}
cin >> c;
Dice d(num);
for (int i = 0; i < c.size(); i++) {
d.move(c[i]);
}
cout << d.top() << endl;
} | #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
using LLONG = long long;
const LLONG MOD = 1000000007;
int main()
{
int H, W; cin >> H >> W;
vector<char> cs(H * W);
REP(i, H) REP(j, W) cin >> cs[i * W + j];
const int INF = 1e9;
vector<int> dists(H * W, INF);
vector<int> parents(H * W, -1);
dists[0] = 0;
deque<int> Q{ 0 };
while (!Q.empty())
{
int v = Q.front(); Q.pop_front();
int r = v / W, c = v % W;
vector<int> neighbors;
if (r > 0 && cs[v - W] == '.') neighbors.push_back(v - W);
if (r < H - 1 && cs[v + W] == '.') neighbors.push_back(v + W);
if (c > 0 && cs[v - 1] == '.') neighbors.push_back(v - 1);
if (c < W - 1 && cs[v + 1] == '.') neighbors.push_back(v + 1);
for (const int n : neighbors)
{
if (dists[n] > dists[v] + 1)
{
dists[n] = dists[v] + 1;
parents[n] = v;
Q.push_back(n);
}
}
}
if (dists[H * W - 1] == INF)
{
cout << -1 << endl;
}
else
{
vector<int> path;
for (int v = H * W - 1; v != -1; v = parents[v])
{
path.push_back(v);
}
int ans = H * W;
for (const char ch : cs)
{
if (ch == '#') --ans;
}
cout << ans - path.size() << endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif
void init() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
}
const int N = 1e5+23;
vector<int> g[N], ans;
bool bio[N];
int parent[N];
void dfs(int u) {
bio[u] = true;
for (int v: g[u]) {
if (bio[v]) continue;
dfs(v);
}
ans.push_back(u);
}
void solve() {
int n, m; scanf("%d%d", &n, &m);
for (int u, v, i = 0; i < n-1+m; ++i) {
scanf("%d%d", &u, &v);
g[u].push_back(v);
}
for (int i = 1; i <= n; ++i) {
if (bio[i]) continue;
dfs(i);
}
for (int u: ans)
for (int v: g[u])
if (!parent[v])
parent[v] = u;
for (int i = 1; i <= n; ++i) printf("%d\n", parent[i]);
}
int main() {
init();
int t = 1; //scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll N,M;
cin >> N >> M;
vector<ll> A(N+M-1),B(N+M-1),G[N],in_cnt(N,0);
vector<bool> is_root(N,true);
for(int i=0;i<N+M-1;i++){
cin >> A[i] >> B[i];
A[i]--,B[i]--;
G[A[i]].push_back(B[i]);
is_root[B[i]] = false;
in_cnt[B[i]]++;
}
int root;
for(int i=0;i<N-1;i++){
if(is_root[i]) root = i;
}
vector<ll> pa(N,-1);
queue<ll> q;
q.push(root);
while(q.size()){
ll from = q.front();
q.pop();
for(auto to:G[from]){
pa[to] = from;
in_cnt[to]--;
if(in_cnt[to] == 0){
q.push(to);
}
}
}
pa[root] = -1;
for(auto x:pa){
cout << x+1 << "\n";
}
}
| 1 |
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX>>2
#define MAX 1000000
#define mod 1000000007
#define pb push_back
#define f(i,a,n,x) for ((i)=(a);(i)<(n);(i)+=(x))
#define fd(i,a,n,x) for ((i)=(a);(i)>=(n);(i)-=(x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
using namespace std;
void read(vt<ll> &a,ll n){ll i,temp;f(i,0,n,1){cin>>temp;a.pb(temp);}}
void solve(){
ll k,i,j;
string n,m="0";
vt<ll> dislike;
cin>>n>>k;
m=m+n;
read(dislike,k);
fd(i,m.length()-1,1,1)
while(find(dislike.begin(),dislike.end(),m[i]-'0')!=dislike.end()){
j=i;
if (m[j]!='9'){
m[j]=((m[j]-'0'+1)%10)+'0';
f(j,j+1,m.length(),1)
m[j]='0';
i=m.length()-1;
}
else{
while(m[j]=='9'){
m[j]='0';
j--;
}
m[j]=((m[j]-'0'+1)%10)+'0';
i=m.length()-1;
}
}
if (m[0]!='0'){
while(find(dislike.begin(),dislike.end(),m[0]-'0')!=dislike.end()){
m[0]=((m[0]-'0'+1)%10)+'0';
}
f(j,1,m.length(),1)
m[j]='0';
fd(i,m.length()-1,1,1)
while(find(dislike.begin(),dislike.end(),m[i]-'0')!=dislike.end()){
j=i;
if (m[j]!='9'){
m[j]=((m[j]-'0'+1)%10)+'0';
f(j,j+1,m.length(),1)
m[j]='0';
i=m.length()-1;
}
else{
while(m[j]=='9'){
m[j]='0';
j--;
}
m[j]=((m[j]-'0'+1)%10)+'0';
i=m.length()-1;
}
}
}
if (m[0]!='0')
cout<<m<<endl;
else
cout<<m.substr(1)<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t=1;
//cin>>t;
while(t--)
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main() {
int h, w;
cin >> h >> w;
vector<string> g(h);
vector<vector<bool>> seen(h, vector<bool>(w));
for(int i=0;i<h;i++) cin >> g[i];
long long ans = 0;
long long black = 0, white = 0;
for(int i=0;i<h;i++) {
for(int j=0;j<w;j++) {
if(seen[i][j]) continue;
queue<P> que;
que.emplace(make_pair(i, j));
while(!que.empty()) {
P p = que.front();que.pop();
if(seen[p.first][p.second]) continue;
seen[p.first][p.second] = true;
char c = g[p.first][p.second];
if(c == '.') white++;
else black++;
if(p.first != 0 && !seen[p.first-1][p.second] && g[p.first-1][p.second] != c) que.emplace(make_pair(p.first-1, p.second));
if(p.first != h-1 && !seen[p.first+1][p.second] && g[p.first+1][p.second] != c) que.emplace(make_pair(p.first+1, p.second));
if(p.second != 0 && !seen[p.first][p.second-1] && g[p.first][p.second-1] != c) que.emplace(make_pair(p.first, p.second-1));
if(p.second != w-1 && !seen[p.first][p.second+1] && g[p.first][p.second+1] != c) que.emplace(make_pair(p.first, p.second+1));
}
ans += black * white;
black = white = 0;
}
}
cout << ans << endl;
}
| 0 |
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <memory.h>
#include <cmath>
#include <array>
using namespace std;
void re(int& x);
template<class T, class... Ts> void re(T& t, Ts&... ts);
void pr(long long x);
void pr(const char *x);
void ps();
template<class T, class... Ts> void ps(const T& t, const Ts&... ts);
#ifdef FFDBG
#else
#define dbg(x...) dsfdsfsdfasd
#endif
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
int n, x;
long long tgt = 0;
struct ex {
int l, r, b;
} exam[110000];
long long score(const ex& a, long long h) {
long long sc = a.l * 1ll * min(h, (ll)a.b);
sc += a.r * 1ll * max(0LL, h-a.b);
return sc;
}
bool check(long long hrs) {
int full = hrs / x;
int rem = hrs % x;
long long sc = 0;
rep(i,0,full) sc += score(exam[i], x);
long long best = sc;
rep(i,full,n) best = max(best, sc + score(exam[i], rem));
if (full < n) {
sc += score(exam[full], x);
rep(i,0,full) best = max(best, sc - score(exam[i], x) + score(exam[i],rem));
}
return best >= tgt;
}
void solve()
{
re(n,x);
rep(i,0,n) re(exam[i].b, exam[i].l, exam[i].r);
rep(i,0,n) tgt += exam[i].l * 1ll * exam[i].b;
sort(exam, exam+n, [](const ex& a, const ex& b) {
return score(a,x) > score(b,x);
});
long long st = 0, ed = n*1ll*x;
while (st < ed) {
long long md = (st+ed)/2;
if (check(md)) ed = md;
else st = md+1;
}
ps(st);
}
int main() {
solve();
}
void re(int& x) { scanf("%d", &x); }
template<class T, class... Ts> void re(T& t, Ts&... ts) {
re(t); re(ts...);
}
void pr(long long x) { printf("%lld", x); }
void pr(const char *x) { printf("%s", x); }
void ps() { pr("\n"); }
template<class T, class... Ts> void ps(const T& t, const Ts&... ts) {
pr(t); if (sizeof...(ts)) pr(" "); ps(ts...);
}
| // Program Name: Minimum Spanning Tree
// Written by: by_sknight
// Date: 2019/4/27
#include <bits/stdc++.h>
using namespace std;
#define MAX 105
#define INFTY INT_MAX
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n, G[MAX][MAX];
int prim() {
int d[MAX], p[MAX], color[MAX];
int u, minv;
for (int i = 0; i < n; i++) {
d[i] = INFTY;
p[i] = -1;
color[i] = WHITE;
}
d[0] = 0;
while (1) {
u = -1;
minv = INFTY;
for (int i = 0; i < n; i++) {
if (color[i] != BLACK && d[i] < minv) {
minv = d[i];
u = i;
}
}
if (u == -1)
break;
color[u] = BLACK;
for (int v = 0; v < n; v++) {
if (color[v] != BLACK && G[u][v] < d[v]) {
d[v] = G[u][v];
p[v] = u;
color[v] = GRAY;
}
}
}
int sum = 0;
for (int i = 0; i < n; i++) {
if (p[i] != -1) {
sum += d[i];
}
}
return sum;
}
int main(void) {
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int k;
cin >> k;
G[i][j] = (k == -1 ? INFTY : k);
}
}
int sum = prim();
cout << sum << endl;
}
| 0 |
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0,h,w;
string str;
cin>>n>>h>>w;
a=n-h+1;
b=n-w+1;
cout<<a*b<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B;
cin >> A >> B;
cout << max(max(A+B,A-B),A*B) << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
#include <fstream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define ll unsigned long long
const ll MOD = 1000000000000000000;
int main() {
//入力
int k;
string s;
cin >> k >> s;
//処理
string ans = s;
if (s.size() > k) {
ans = s.substr(0, k) + "...";
}
//出力
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
//#define INF 1e18
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX]; //n!, 1/n!, 1/n
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(ll n, ll k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
map<ll,ll> prime_factor(ll n){
map<ll,ll> res;
for(ll i=2;i*i<=n;i++){
while(n%i==0){
++res[i];
n /= i;
}
}
if(n!=1) res[n] = 1;
return res;
}
int main(){
ll n,m;
cin >> n >> m;
COMinit();
ll ans=1;
map<ll,ll> M = prime_factor(m);
for(auto p : M){
ll k = p.second;
ans *= COM(n+k-1,k);
ans %= MOD;
}
cout << ans << endl;
return 0;
}
| 0 |
#include <iostream>
#include <string>
#include <set>
using namespace std;
void input(int& N, set<int>& R_INDEX, set<int>& G_INDEX, set<int>& B_INDEX)
{
char c;
for (int i= 0; i < N; i++){
cin >> c;
switch(c){
case 'R':
R_INDEX.insert(i);
break;
case 'G':
G_INDEX.insert(i);
break;
case 'B':
B_INDEX.insert(i);
break;
}
}
}
long long int findsetnum(set<int>& R_INDEX, set<int>& G_INDEX, set<int>& B_INDEX)
{
long long int sum = 0;
int a, b, c;
set<int>::iterator R_iter, G_iter;
for (R_iter = R_INDEX.begin(); R_iter != R_INDEX.end(); R_iter++)
for (G_iter = G_INDEX.begin(); G_iter != G_INDEX.end(); G_iter++){
a = (B_INDEX.find(2 * (*G_iter) - *R_iter) == B_INDEX.end())? 0 : 1;
b = (B_INDEX.find(2 * (*R_iter) - *G_iter) == B_INDEX.end())? 0 : 1;
c = (B_INDEX.find((*G_iter + *R_iter) / 2) == B_INDEX.end() || (*G_iter + *R_iter) % 2 != 0)? 0 : 1;
sum += (B_INDEX.size() - a - b - c);
}
return sum;
}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
set<int> R_INDEX, G_INDEX, B_INDEX;
input(N, R_INDEX, G_INDEX, B_INDEX);
cout << findsetnum(R_INDEX, G_INDEX, B_INDEX) << '\n';
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
int main() {
fast_io;
long long n,r,g,b;
cin>>n;
string s;
cin>>s;
r=0;
g=0;
b=0;
for(int i=0;i<n;i++) {
if(s[i]=='R')r++;
else if (s[i]=='G')g++;
else if (s[i]=='B')b++;
}
int count =0;
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
int k=2*j-i;
if(i>=j||k>=n||k<=j) continue;
if(s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k]) count++;
}
}
cout<<r*g*b-count<<endl;
}
| 1 |
#include<iostream>
#include<string>
using namespace std;
int main()
{
char s[5000];
long long n,i,j,k,total=0,red[5000]={0},green[5000]={0},blue[5000]={0},r=0,g=0,b=0,x,y;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>s[i];
if(s[i]=='R')
{
r++;
red[i]=red[i-1]+1;
blue[i]=blue[i-1];
green[i]=green[i-1];
}
else if(s[i]=='G')
{
g++;
green[i]=green[i-1]+1;
red[i]=red[i-1];
blue[i]=blue[i-1];
}
else if(s[i]=='B')
{
b++;
blue[i]=blue[i-1]+1;
red[i]=red[i-1];
green[i]=green[i-1];
}
}
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&&s[j]=='R'))
{
x=b-blue[j];
y=(j-i)+j;
if(s[y]=='B'&&x>0&&y<=n)
{
x--;
}
total+=x;
}
else if((s[i]=='R'&&s[j]=='B')||(s[i]=='B'&&s[j]=='R'))
{
x=g-green[j];
y=(j-i)+j;
if(s[y]=='G'&&x>0&&y<=n)
{
x--;
}
total+=x;
}
else if((s[i]=='B'&&s[j]=='G')||(s[i]=='G'&&s[j]=='B'))
{
x=r-red[j];
y=(j-i)+j;
if(s[y]=='R'&&x>0&&y<=n)
{
x--;
}
total+=x;
}
}
}
cout<<total<<endl;
return 0;
} | #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
string s;
cin >> s;
int b = 0;
for(auto c : s) if(c == 'B') ++b;
long long ans = 0;
for(int i = 0; i < n; ++i){
if(s[i] != 'R') continue;
for(int j = 0; j < n; ++j){
if(s[j] != 'G') continue;
ans += b;
int x = i, y = j;
if(x > y) swap(x, y);
int d = y - x;
if(d % 2 == 0 && s[x + d / 2] == 'B') --ans;
if(x - d >= 0 && s[x - d] == 'B') --ans;
if(y + d < n && s[y + d] == 'B') --ans;
}
}
cout << ans << endl;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
int a,b,s,i,x;
s=100;
x=0;
for(i=0;i<4;i++){
cin>>a;
if(s>a) s=a;
x=x+a;
}
x=x-s;
s=100;
for(i=0;i<2;i++){
cin>>b;
if(s>b) s=b;
x=x+b;
}
x=x-s;
cout<<x<<endl;
return 0;
}
| #include<iostream>
#include<string>
#include<stdio.h>
#include <algorithm>
#include <set>
#include<math.h>
#include<vector>
using namespace std;
int main(){
int N,M,X,Y;cin >> N >> M >> X >> Y;
int x[100]={};
int y[100]={};
int flag = 1;
for(int i = 0;i < N;i++)cin >> x[i];
for(int i = 0;i < M;i++)cin >> y[i];
for(int i = X+1;i <= Y;i++){
flag = 1;
for(int j=0;j < N;j++){
if(x[j] >= i){
flag = 0;
continue;
}
}
if(flag==0)continue;
for(int j = 0;j < M;j++){
if(y[j] < i){
flag = 0;
continue;
}
}
if(flag == 1)break;
}
if(flag == 1)cout << "No War" << endl;
else cout << "War" << endl;
} | 0 |
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (1) {
int cx = 10,cy = 10;
int v[21][21];
REP(i, 21) {
REP(j, 21) {
v[i][j] = 0;
}
}
int n, m,cnt=0;
cin >> n;
if (!n) break;
REP(i, n) {
int x, y;
cin >> x >> y;
v[x][y] = 1;
}
cin >> m;
REP(i, m) {
char d;
int L;
cin >> d >> L;
int dx, dy;
if (d == 'N') {
dx = 0;dy = 1;
}
else if (d == 'E') {
dx = 1;dy = 0;
}
else if(d=='W'){
dx = -1;dy = 0;
}
else {
dx = 0;dy = -1;
}
FOR(j,1, L+1) {
if (v[cx + j*dx][cy + j*dy] == 1) {
cnt++;
v[cx + j*dx][cy + j*dy] = 0;
}
}
cx += L*dx;cy += L*dy;
}
if (cnt == n) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define ull unsigned long long
#define ul unsigned long
#define ll long long
#define pb push_back
#define sodayoda_C ios_base::sync_with_stdio(false);cin.tie(NULL);
#define f(i,a,b) for(int i = a;i<b;i++)
#define fb(i,a,b) for(int i = a;i>b;i--)
#define endl "\n"
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define mp make_pair
//memset(name,'',size)
//reverse(s,begin(),s.end())
using namespace std;
int fact(int n){
if(n == 0) return 1;
return n*fact(n-1);
}
int main(){
sodayoda_C;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
//cin>>t;
t = 1;
while(t--){
int n;
cin>>n;
double x[n],y[n];
f(i,0,n) cin>>x[i]>>y[i];
double ans = 0;
f(i,0,n){
f(j,0,n){
if(j!=i){
ans+= (1/(double)n)*sqrt(pow(x[i]-x[j],2) + pow(y[i]-y[j],2));
}
}
}
printf("%.7f",ans);
}
return 0;
}
| 0 |
#include<bits/stdc++.h>
#define LL long long
#define RG register
using namespace std;
template<class T> inline void read(T &x) {
x = 0; RG char c = getchar(); bool f = 0;
while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-') c = getchar(), f = 1;
while (c >= '0' && c <= '9') x = x*10+c-48, c = getchar();
x = f ? -x : x;
return ;
}
template<class T> inline void write(T x) {
if (!x) {putchar(48);return ;}
if (x < 0) x = -x, putchar('-');
int len = -1, z[20]; while (x > 0) z[++len] = x%10, x /= 10;
for (RG int i = len; i >= 0; i--) putchar(z[i]+48);return ;
}
const int N = 200010, Mod = 1e9 + 7;
int fac[N], ifac[N], H, W, A, B;
int fpow(int a, int b) {
int res = 1;
for (; b; b >>= 1, a = 1ll * a * a % Mod)
if (b & 1) res = 1ll * res * a % Mod;
return res;
}
int C(int n, int m) {
if (n < m) return 0;
return 1ll * fac[n] * ifac[m] % Mod * ifac[n - m] % Mod;
}
int calc(int n, int m) {
return C(n + m - 2, n - 1);
}
int main() {
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
read(H), read(W), read(A), read(B);
fac[0] = 1;
for (int i = 1; i <= 200000; i++)
fac[i] = 1ll * fac[i - 1] * i % Mod;
ifac[200000] = fpow(fac[200000], Mod - 2);
for (int i = 200000; i >= 1; i--)
ifac[i - 1] = 1ll * ifac[i] * i % Mod;
int ans = 0;
for (int i = B + 1; i <= W; i++)
(ans += 1ll * calc(H - A, i) * calc(A, W - i + 1) % Mod) %= Mod;
printf("%d\n", ans);
return 0;
}
| //---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
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 int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
const long long MAX = 1001000;
const long long MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long com(long long n, long long k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll h,w,a,b;
cin>>h>>w>>a>>b;
COMinit();
ll ans=0;
for(int i=b+1;i<=w;i++){
ll cur=com(h-1-a-1+i,h-a-1)*com(a-1+w-i,a-1);
cur=cur%MOD;
ans+=cur;
ans=ans%MOD;
}
cout<<ans<<endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
tree<int, null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T>
void remdup(vector<T>& v) {
sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif
#define MOD 1000000007
void solve(){
string s ;
cin >> s ;
bool ok = 0 ;;
trav(i,s)if(i-'0' == 7) ok = 1;
if(ok) cout << "Yes\n";
else cout << "No\n";
}
signed main() {
unsyncIO();
int tt =1 ;
// cin >> tt;
rep(i,0,tt) solve();
#ifdef np
cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
| #include<stdio.h>
int main() {
int N,B;
scanf("%d",&N);
while(N!=0)
{
B=N%10;
if(B==7) {
printf("Yes");
break;
}
N=N/10;
}
if(B!=7)
printf("No");
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
const ll mod = 1e9 + 7;
ll powMod(ll a, ll k)
{
ll ret = 1;
while(k)
{
if(k & 1) ret = ret * a % mod;
a = a * a % mod; k >>= 1;
}
return ret;
}
ll inv(ll a) { return powMod(a, mod - 2);}
ll C(int n, int m)
{
ll a = 1, b = 1;
for(int i = 1; i <= m; ++i)
{
a = a * i % mod;
b = b * (n - i + 1) % mod;
}
return b * inv(a) % mod;
}
int main()
{
ll n, m, k;
cin >> n >> m >> k;
ll ans = C(n * m - 2, k - 2);
ll A = n * n % mod * C(m + 1, 3) % mod;
ll B = m * m % mod * C(n + 1, 3) % mod;
ans = ans * (A + B) % mod;
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll pl(ll a, ll b) {
a %= mod, b %= mod;
return (a+b) % mod;
}
ll mu(ll a, ll b) {
a %= mod, b %= mod;
return (a*b) % mod;
}
ll pow_mod(ll a, ll b) {
if (b == 0) return 1;
a %= mod;
ll k = pow_mod(a, b/2);
k = mu(k, k);
if (b & 1) k = mu(k, a);
return k;
}
ll di(ll a, ll b) {
a %= mod;
return mu(a, pow_mod(b, mod-2));
}
ll nCk(ll n, ll k) {
ll res = 1;
for (int a = n, b = k; b > 0; a--, b--) {
res = mu(res, a);
res = di(res, b);
}
return res;
}
int main () {
ll A[2], K;
cin >> A[0] >> A[1] >> K;
ll ans = 0;
for (int k = 0; k < 2; k++) {
ll p = A[0], q = A[1];
for (int i = 1; i <= q-1; i++) {
ans += mu(mu(mu(p, p), q-i), i);
}
swap(A[0], A[1]);
}
ans = di(ans, nCk(A[0]*A[1], 2));
ans = mu(ans, nCk(A[0]*A[1], K));
ans = mu(ans, nCk(K, 2));
cout << ans << endl;
} | 1 |
//
// main.cpp
// D
//
// Created by 曾憲揚 on 2020/8/21.
// Copyright © 2020 曾憲揚. All rights reserved.
//
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e3+5;
int main(int argc, const char * argv[]) {
int n; cin>>n;
string s; cin>>s;
int r=0, g=0, b=0;
for(int i=0; i<n; i++){
if(s[i]=='R') r++;
else if(s[i]=='G') g++;
else if(s[i]=='B') b++;
}
long long ans = 1LL*r*g*b;
for(int i=0; i<n; i++){
for(int j=i+1; j<n; j++){
if(s[i] == s[j]) continue;
int k = j+(j-i);
if(k>=n) break;
if(s[k] != s[i] && s[k] != s[j]) ans--;
}
}
cout<<ans<<endl;
return 0;
}
| #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
bool is_palindrome(string str){
string rstr = str;
reverse(str.begin(), str.end());
return rstr == str;
}
int main(){
int A, B, ans = 0;
cin >> A >> B;
for (int i = A; i <= B; i++){
if (is_palindrome(to_string(i))) ans++;
}
printf("%d\n", ans);
}
| 0 |
#include<iostream>
int main(void){
int n;
std::cin >> n;
int seq[n];
for (int i =0; i <n; i++){
std::cin >> seq[i];
}
for (int i = 0; i < n; i ++){
if (i < n-1) std::cout << seq[(n-1) - i] << " ";
else std::cout << seq[ (n-1)-i] << std::endl;
}
return 0;
} | #include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int main(){
double i, j, k, l;
cin >> i >> j >> k >> l;
cout << fixed << setprecision(8);
cout << (double)sqrt(pow(i - k, 2.0) + pow(j - l, 2.0)) << endl;
} | 0 |
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
class BIT {
std::vector<LL> bit;
LL size;
public:
BIT() { }
BIT(LL sz) { init(sz); }
void init(LL sz) {
bit = std::vector<LL>((size = sz) + 1);
}
LL sum(LL i) {
LL s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(LL i, LL x) {
while (i <= size) {
bit[i] += x;
i += i & -i;
}
}
};
int main() {
LL N, Q, a, t, x, y;
cin >> N >> Q;
BIT bit(N);
for (LL i = 1; i <= N; ++i) {
cin >> a;
bit.add(i, a);
}
for (LL i = 0; i < Q; ++i) {
cin >> t >> x >> y;
if (t == 0) {
bit.add(x + 1, y);
} else {
cout << (bit.sum(y) - bit.sum(x)) << endl;
}
}
return 0;
}
| #include <bits/stdc++.h>
#include <atcoder/fenwicktree>
using namespace std;
using namespace atcoder;
int main(){
int N, Q;
cin >> N >> Q;
fenwick_tree<long long> a(N);
for (int i = 0; i < N; i++){
int x;
cin >> x;
a.add(i, x);
}
for (int i = 0; i < Q; i++){
int t;
cin >> t;
if (t == 0){
int p, x;
cin >> p >> x;
a.add(p, x);
}
if (t == 1){
int l, r;
cin >> l >> r;
cout << a.sum(l, r) << endl;
}
}
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
int main() {
int n;
cin >> n;
queue<int> que;
rep(i, n) {
int p;
cin >> p;
if(i == 0) que.push(p);
else {
if(que.back() > p) que.push(p);
}
}
cout << que.size() << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define vt vector
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
using ll = long long;
using pii = pair<int, int>;
void solve() {
int n;
cin >> n;
int mn = n + 1, ans = 0;
while (n--) {
int x;
cin >> x;
if (x < mn) mn = x, ans++;
}
cout << ans;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int tcs = 1;
for (int tc = 1; tc <= tcs; tc++) {
// cout << "Case " << tc << ": ";
solve();
}
}
| 1 |
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
long long n;
cin >> n;
string name = "";
while (1) {
n--;
name += (n % 26 + 'a');
n /= 26;
if (n == 0) break;
}
reverse(name.begin(), name.end());
cout << name;
}
| #include<stdio.h>
#define ll long long
int main()
{
ll n, j = 0;
char str[255];
scanf("%lld", &n);
while(n != 0){
--n;
str[j++] = n % 26 + 'a';
n /= 26;
}
for(int i = j - 1; i >= 0; i--){
printf("%c", str[i]);
}
} | 1 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
double sum = 0;
cin >> n;
vector<int> x(n);
vector<int> y(n);
for (int i = 0; i < n; i++)
{
cin >> x[i] >> y[i];
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
sum += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
}
}
cout << fixed;
cout << setprecision(7) << sum / n << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
int main(){
ll N;
cin >> N;
vector<ll> A(N), B(N), S(N);
rep(i, 0, N){
cin >> A[i] >> B[i];
S[i] = A[i] + B[i];
}
sort(S.begin(), S.end(), greater<ll>());
ll taka = 0;
rep(i, 0, N){
if(i % 2 == 0) taka += S[i];
}
ll ans = taka - accumulate(B.begin(), B.end(), 0LL);
cout << ans << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long N; cin >> N;
string ans="";
while(N){
N--;
int r=N%26;
N=N/26;
ans+='a'+r;
}
reverse(ans.begin(),ans.end());
cout << ans << endl;
}
| #include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
string S, T;
cin >> S >> T;
cout << T + S << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll INF = 1LL << 60; //MAX 9223372036854775807
//https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_D
//区間加算 区間和クエリ
//演算の定義
auto query = [](ll x, ll y) { return x+y; };
//単位元
const ll unit = 0;
struct LazySegTree
{
private:
ll n;
vector<ll> node,lazy;
public:
LazySegTree(vector<ll> v)
{
node.resize((1LL << 64 - __builtin_clzll(v.size())) * 2 - 1, unit);
lazy.resize((1LL << 64 - __builtin_clzll(v.size())) * 2 - 1,-1);
n = 1LL << 64 - __builtin_clzll(v.size());
for (ll i = 0; i < v.size(); i++)
node[i + n - 1] = v[i]; //最下段から構築
for (ll i = n - 2; i >= 0; i--)
node[i] = query(node[2 * i + 1], node[2 * i + 2]);
}
// k 番目のノードについて遅延評価を行う
void eval(int k, int l, int r){
// 遅延配列が空でない場合、自ノード及び子ノードへの
// 値の伝播が起こる
if (lazy[k] != -1){
node[k] = lazy[k];
// 最下段かどうかのチェックをしよう
// 子ノードは親ノードの 1/2 の範囲であるため、
// 伝播させるときは半分にする
if (r - l > 1){
lazy[2 * k + 1] = lazy[k] / 2;
lazy[2 * k + 2] = lazy[k] / 2;
}
// 伝播が終わったので、自ノードの遅延配列を空にする
lazy[k] = -1;
}
}
void update(int a, int b, ll x, int k = 0, int l = 0, int r = -1){
if (r < 0)
r = n;
// k 番目のノードに対して遅延評価を行う
eval(k, l, r);
// 範囲外なら何もしない
if (b <= l || r <= a)
return;
// 完全に被覆しているならば、遅延配列に値を入れた後に評価
if (a <= l && r <= b){
lazy[k]= (r - l) * x;
eval(k, l, r);
}
// そうでないならば、子ノードの値を再帰的に計算して、
// 計算済みの値をもらってくる
else{
update(a, b, x, 2 * k + 1, l, (l + r) / 2);
update(a, b, x, 2 * k + 2, (l + r) / 2, r);
node[k] = node[2 * k + 1] + node[2 * k + 2];
}
}
// 要求区間 [a, b) 中の要素の和を答える k := 自分がいるノードのインデックス 対象区間は [l, r) にあたる
ll get(ll a, ll b, ll k = 0, ll l = 0, ll r = -1)
{
// 最初に呼び出されたときの対象区間は [0, n)
if (r < 0)
r = n;
// 要求区間と対象区間が交わらない -> 適当に返す
if (r <= a || b <= l)
return unit;
// 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う
// 関数が呼び出されたら評価!
eval(k, l, r);
if (a <= l && r <= b)
return node[k];
// 要求区間が対象区間の一部を被覆 -> 子について探索を行う
// 左側の子を vl ・ 右側の子を vr としている
// 新しい対象区間は、現在の対象区間を半分に割ったもの
ll vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
ll vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
return query(vl, vr);
}
};
int main()
{
ll n , q ;
cin >> n >> q ;
vector<ll> t(n,(1LL<<31)-1);
LazySegTree s(t);
vector<ll> ans;
rep(i,q){
ll a ;
cin >> a ;
if(!a){
ll b , c , d ;
cin >> b >> c >> d ;
s.update(b, c+1, d);
}
else {
ll b ;
cin >> b ;
ans.push_back(s.get(b, b+1));
}
}
rep(i,ans.size())cout<<ans[i]<<"\n";
return 0;
}
| #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
using namespace std;
#define REP(i,n) for (int i = 0; i < n; i++)
int main() {
int N;
vector<int> s(123),t;
scanf("%d", &N);
REP(i, N *(N - 1) / 2) {
int A, B, C, D;
scanf("%d %d %d %d", &A, &B, &C, &D);
s[A-1] += (C > D) ? 3 : 0;
s[B-1] += (C < D) ? 3 : 0;
if (C == D) {
s[A-1]++;
s[B-1]++;
}
}
t = s;
sort(t.begin(), t.begin() + N);
REP(i, N) {
printf("%d\n", N - distance(t.begin(), upper_bound(t.begin(), t.begin() + N, s[i])) + 1);
}
return 0;
} | 0 |
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;
//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;
//??¨????????????????????????
//n??\????????£??´??°????´???°???????????°???????????????is_prime[]???????´?
void eratos(int n, bool is_prime[]) {
fill(is_prime, is_prime + n + 1, true);
is_prime[0] = is_prime[1] = false;
for (int i = 2; i*i <= n; i++)
if (is_prime[i]) {
int j = i + i;
while (j <= n) {
is_prime[j] = false;
j = j + i;
}
}
}
signed main() {
bool is_prime[10010] = {};
eratos(10010, is_prime);
for (int n; cin >> n&&n;) {
rrep(i, 0, n + 1) {
if (is_prime[i] && is_prime[i - 2]) {
cout << i - 2 << " " << i << endl; break;
}
}
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define int long long
void read(int &x) {
x=0;int f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}
void print(int x) {
if(x<0) putchar('-'),x=-x;
if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}
#define lf double
#define ll long long
#define pii pair<int,int >
#define vec vector<int >
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define data asd09123jdf02i3h
#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)
const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;
int sta[maxn],top,a[maxn],n;
signed main() {
read(n);
for(int i=1;i<=n;i++) read(a[i]);
int ans=0,lst=n+1;
for(int i=n;i;i--) {
int x=a[lst]-(lst-i);
if(a[i]==x) continue;
if(a[i]<x||a[i]>=i) return puts("-1"),0;
ans+=a[i],lst=i;
}
write(ans);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
for(int i=1;i<s.size();i++){
if(1<i && s[i-2]==s[i]){
cout << i-1 << " " << i+1 << endl;
return 0;
}
if(s[i-1]==s[i]){
cout << i << " " << i+1 << endl;
return 0;
}
}
cout << -1 << " " << -1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
int main(void)
{
IOS
string S; cin >> S;
OUT(S.substr(0,S.size()-8))
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
double K=0;
vector<int> X(N),Y(N);
for(int i=0;i<N;i++){
cin >> X.at(i) >> Y.at(i);
}
for(int i=0;i<N-1;i++){
for(int j=i+1;j<N;j++){
int X2=X.at(i)-X.at(j);
int Y2=Y.at(i)-Y.at(j);
K+=sqrt(X2*X2+Y2*Y2);
}
}
cout << fixed << setprecision(10) << 2*K/N << endl;
}
| #include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair <int,int> pi;
typedef pair <int,pi> pii;
struct point{
point(int x, int y, int ind){
this->x=x;
this->y=y;
this->ind=ind;
}
int x,y;
int ind;
};
int getdist(int i,int j, vector <pi> &a){
return min(abs(a[i].fi-a[j].fi),abs(a[i].se-a[j].se));
}
int par[100005],Size[100005];
int root(int i)
{
while (par[i] != i)
{
par[i] = par[par[i]];
i = par[i];
}
return i;
}
void wunion(int A, int B)
{
int root_A = root(A);
int root_B = root(B);
if (Size[root_A] < Size[root_B])
{
par[root_A] = par[root_B];
Size[root_B] += Size[root_A];
}
else
{
par[root_B] = par[root_A];
Size[root_A] += Size[root_B];
}
}
bool Find(int A, int B)
{
if (root(A) == root(B)) //if A and B have same root,means they are connected.
return true;
else
return false;
}
int main(){
int n;
cin >> n;
vector <pi> a(n);
vector <point> st;
for(int i=0;i<n;i++){
cin >> a[i].fi >> a[i].se;
st.emplace_back(a[i].fi,a[i].se,i);
}
sort(st.begin(),st.end(),[](const point &l,const point &r){
return l.x<r.x;
});
set <pii> e;
for(int i=1;i<n;i++){
e.insert({getdist(st[i].ind,st[i-1].ind,a),{st[i].ind,st[i-1].ind}});
e.insert({getdist(st[i].ind,st[i-1].ind,a),{st[i-1].ind,st[i].ind}});
}
sort(st.begin(),st.end(),[](const point &l,const point &r){
return l.y<r.y;
});
for(int i=1;i<n;i++){
e.insert({getdist(st[i].ind,st[i-1].ind,a),{st[i].ind,st[i-1].ind}});
e.insert({getdist(st[i].ind,st[i-1].ind,a),{st[i-1].ind,st[i].ind}});
}
for(int i=0;i<n;i++){
par[i]=i;
Size[i]=1;
}
long long ans=0;
for(auto x:e){
int i=x.se.fi, j =x.se.se;
if(!Find(i,j)){
wunion(i,j);
ans+=x.fi;
}
}
cout << ans << endl;
return 0;
} | 0 |
#include<iostream>
#include<algorithm>
using namespace std;
int main (void)
{
string s;
cin>>s;
if(s=="SUN")cout<<"7"<<endl;
if(s=="MON")cout<<"6"<<endl;
if(s=="TUE")cout<<"5"<<endl;
if(s=="WED")cout<<"4"<<endl;
if(s=="THU")cout<<"3"<<endl;
if(s=="FRI")cout<<"2"<<endl;
if(s=="SAT")cout<<"1"<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl
void Suhaib_Sawalha (){
vector <string> v = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
string s;
cin >> s;
cout << v.end() - find(v.begin(),v.end(),s);
}
int main(){
In_The_Name_Of_Allah_The_Merciful /* بسم الله الرحمن الرحيم */
#ifndef ONLINE_JUDGE
freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<'\n')
Suhaib_Sawalha();
Alhamdulillah /* الحمد لله */
} | 1 |
#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, char *argv[])
{
int w, h, diag, i, j;
while (cin >> w >> h, w | h) {
diag = w * w + h * h;
i = 0;
while (1) {
i++;
j = sqrt(diag - i * i);
if (i >= j) {
diag++;
i = 0;
continue;
} else {
if ((diag == w * w + h * h && i <= w) || j * j != diag - i * i)
continue;
cout << i << ' ' << j << endl;
break;
}
}
}
return 0;
} | #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"
using namespace std;
const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;
long long int N, M, K, H, W, L, R;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
vector<pair<int, pair<int,int>>>v;
for (int i = 1; i <= 150; i++) {
for (int j = i + 1; j <= 150; j++) {
v.push_back({ i*i + j*j ,{i,j} });
}
}
sort(v.begin(), v.end());
cin >> H >> W;
while (H) {
bool flag = false;
for (auto i : v) {
if (flag) {
cout << i.second.first << " " << i.second.second << endl;
break;
}
if (i.second.first == H&&i.second.second == W) {
flag = true;
}
}
cin >> H >> W;
}
return 0;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+10;
struct node{
int pos,num;
bool operator<(const node& a)const{
return num<a.num;
}
};
struct node1{
int pos,num;
bool operator<(const node1& a)const{
return pos<a.pos;
}
};
char s[maxn];
bool vis[maxn]={0};
node p[maxn]={0},p1[maxn]={0};
node1 p2[maxn]={0};
ll ans[maxn]={0};
ll sum[maxn]={0};
int k[100];
int main()
{
int n;
scanf("%d %s",&n,s+1);
int q;
scanf("%d",&q);
for(int i=1;i<=q;i++){
scanf("%d",&k[i]);
}
int num=0;
int now1=0,now2=0;
for(int i=1;i<=n;i++){
if(s[i]=='M')num++;
else if(s[i]=='D'){
p1[++now1].pos=i;
p1[now1].num=num;
}
else if(s[i]=='C'){
p[++now2].pos=i;
p[now2].num=num;
p2[now2].pos=i;
p2[now2].num=num;
}
}
for(int i=1;i<=now2;i++){
sum[i]=sum[i-1]+p[i].num;
}
for(int j=1;j<=q;j++)
{
ll sum1=0;
for(int i=1;i<=now1;i++){
node aa;
node1 bb;
aa.num=p1[i].num+1;
bb.pos=p1[i].pos+k[j];
int x=lower_bound(p+1,p+now2+1,aa)-p;
int y=lower_bound(p2+1,p2+now2+1,bb)-p2;
y--;
if(x==now2+1)continue;
sum1+=sum[y]-sum[x-1]-p1[i].num*1ll*(y-x+1);
}
ans[j]=sum1;
}
for(int i=1;i<=q;i++){
printf("%lld\n",ans[i]);
}
} | #include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int INF=1e9;
const long double eps=1e-9;
const double Pi=acos(-1.0);
const int maxn=1e2+10;
struct node{
int x,y,id;
}a[maxn];
inline bool cmp(const node &lhs,const node &rhs){
return lhs.x==rhs.x?lhs.y>rhs.y:lhs.x<rhs.x;
}
inline bool Cmp(const node &lhs,const node &rhs){
return lhs.id<rhs.id;
}
int stk[maxn],ans[maxn],vis[maxn];
double Ans[maxn],slp[maxn];
inline int read(){
int x=0,flag=1;
char ch=getchar();
while(!isdigit(ch) && ch!='-')ch=getchar();
if(ch=='-')flag=-1,ch=getchar();
while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return x*flag;
}
inline double Slope(int idx,int idy){
if(a[idx].x==a[idy].x)return -INF;
return (a[idx].y-a[idy].y)*1.0/(a[idx].x-a[idy].x);
}
inline double arcle(int idx,int idy){
if(a[idx].x==a[idy].x){
if(a[idx].y>a[idy].y)return 0;
else return Pi;
}
if(a[idx].y==a[idy].y){
if(a[idx].x<a[idy].x)return Pi/2;
else return 3*Pi/2;
}
double slope=-1.0/Slope(idx,idy),arc=atan(slope);
if(arc<0)arc+=Pi;
if(a[idx].x<a[idy].x)return arc;
else return arc+Pi;
}
int main(){
int i,j,k,m,n,pos;
n=read();
for(i=1;i<=n;i++){
a[i].x=read();a[i].y=read();a[i].id=i;
}
sort(a+1,a+n+1,cmp);
stk[1]=1;stk[2]=2;int top=2;
for(i=3;i<=n;i++){
while(top>1 && Slope(stk[top],stk[top-1])>=Slope(i,stk[top]))top--;
stk[++top]=i;
}
for(i=1;i<top;i++)ans[i]=a[stk[i]].id,vis[a[stk[i]].id]=1;pos=top;
vis[a[1].id]=0;
reverse(a+1,a+n+1);
stk[1]=1;stk[2]=2;top=2;
for(i=3;i<=n;i++){
if(vis[a[i].id])continue;
while(top>1 && Slope(stk[top],stk[top-1])>=Slope(i,stk[top]))top--;
stk[++top]=i;
}
for(i=pos;i<pos+top-1;i++)ans[i]=a[stk[i-pos+1]].id;pos=pos+top-2;
sort(a+1,a+n+1,Cmp);
ans[0]=ans[pos];ans[pos+1]=ans[1];
for(i=0;i<=pos;i++)slp[i]=arcle(ans[i+1],ans[i]);
for(i=1;i<=pos;i++)Ans[ans[i]]=slp[i]-slp[i-1];
for(i=1;i<=n;i++){
if(Ans[i]<0)Ans[i]+=2*Pi;
printf("%.15lf\n",Ans[i]/(2*Pi));
}
return 0;
}
| 0 |
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;
ll max(ll a, ll b) {
if (a > b) { return a; }
return b;
}
ll min(ll a, ll b) {
if (a > b) { return b; }
return a;
}
ll gcd(ll a, ll b) {
if (b == 0) { return a; }
if (a < b) { return gcd(b, a); }
return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
return a * b / gcd(a, b);
}
///////////////////////////
ll p(ll n) {
if (n == 0) { return 1; }
return 2 * p(n - 1);
}
int main() {
ll N;
cin >> N;
vector<ll> A(N + 1);
repn(i, N) cin >> A[i];
sort(++A.begin(), A.end(), greater<ll>());
vector<vector<ll>> d(N + 1,vector<ll>(60));
vector<ll> count1(60);
repn(i, N) {
ll t = A[i];
rep(j,60){
d[i][59-j] = t%2;
count1[59-j]+= d[i][59-j];
t /= 2;
}
}
repn(i, N) {
rep(j, 60) {
if (count1[j] % 2 == 1) { d[i][j] = 0; }
}
}
/*
repn(i, N) {
rep(j, 60) {
cout << d[i][j];
}
cout << endl;
}
*/
repn(i, N) {
ll K=-1;
rep(j,60){
if (d[i][j] == 1) { K = j; break; }
}
//cout << i << K << endl;
if (K == -1) { continue; }
repn(l, N) {
if (l == i) { continue; }
if (d[l][K] == 1) {
for (int j = K; j < 60; j++) {
d[l][j] = (d[i][j] + d[l][j]) % 2;
}
}
}
/*
repn(i, N) {
rep(j, 60) {
cout << d[i][j];
}
cout << endl;
}
*/
}
vector<ll> sum(60, 0);
repn(i, N) {
rep(j, 60) {
sum[j]+=d[i][j];
}
}
//rep(j, 60) { cout << count1[j] << endl; }
ll ans=0;
rep(j, 60) {
ans += (count1[j]%2+2*(sum[j]%2)) * p(59-j);
}
cout << ans;
system("PAUSE");
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MN = 100100;
const int A = 60;
ll w[MN];
ll fr[A];
int main() {
ll n;
cin >> n;
for(int i=0;i<n;i++) {
cin >> w[i];
for(int j=0;j<A;j++) {
if(w[i]&(1LL<<j)) {
fr[j]++;
}
}
}
ll res = 0;
ll tot = 0;
ll ms = 0;
int st = 0;
for(int b=A-1;b>=0;b--) {
if(fr[b]&1) {
tot += 1LL<<b;
continue;
}
ms |= 1LL<<b;
ll ma = -1,mi = -1;
for(int i=st;i<n;i++) {
if((w[i]&(1LL<<b)) && w[i] > ma) {
ma = w[i];
mi = i;
}
}
if(mi >= 0) {
swap(w[mi],w[st]);
mi = st;
for(int i=0;i<n;i++) {
if((w[i]&(1LL<<b)) && (i != mi)) {
w[i] ^= ma;
}
}
st++;
}
}
for(int i=0;i<n;i++) {
res ^= w[i];
}
tot += (res&ms)*2;
cout << tot << '\n';
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;
int main() {
ll a,b,m;
cin>>a>>b>>m;
ll A[a];ll B[b];ll Maxa=MOD,Maxb=MOD;
rep(i,a){
cin>>A[i];
Maxa=min(Maxa,A[i]);
}
rep(i,b){
cin>>B[i];
Maxb=min(Maxb,B[i]);
}
ll ans=Maxa+Maxb;
rep(i,m){
ll x,y,c;
cin>>x>>y>>c;
ans=min(ans,A[x-1]+B[y-1]-c);
}
cout<<ans;
}
| #include <bits/stdc++.h>
using namespace std;
int main(){
int A,B,M;
cin >> A >> B >> M;
vector<int> a(A);
vector<int> b(B);
for(int i=0;i<A;i++){
cin >> a[i];
}
for(int i=0;i<B;i++){
cin >> b[i];
}
vector<vector<int>> ju(M,vector<int>(3));
for(int i=0;i<M;i++){
for(int j=0;j<3;j++){
cin >> ju[i][j];
}
}
int c=200000;
for(int i=0;i<M;i++){
c=min(c,a[ju[i][0]-1]+b[ju[i][1]-1]-ju[i][2]);
}
sort (a.begin(),a.end());
sort (b.begin(),b.end());
c=min(c,a[0]+b[0]);
cout << c << endl;
}
| 1 |
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;
ll dp[41][1<<16][2];
int main(int argc, char* argv[])
{
int n,x,y,z;
scanf("%d%d%d%d", &n, &x, &y, &z);
int s=(1<<(x+y+z))+(1<<(y+z))+(1<<z);
int s2=s/2;
dp[0][0][0]=1;
int i,j,p,k;
for(i=0; i<n; i++) {
for(j=0; j<(1<<16); j++) {
for(p=0; p<2; p++) {
if(dp[i][j][p]) {
for(k=1; k<=10; k++) {
ll tmp=((ll)((j<<1)+1)<<(k-1));
int flag=p;
if(flag==0 && (tmp&s2)==s2) {
flag=1;
}
int j2=tmp%(1<<16);
dp[i+1][j2][flag]=(dp[i+1][j2][flag]+dp[i][j][p])%MOD;
}
}
}
}
}
ll ans=0;
for(j=0; j<(1<<16); j++) {
ans=(ans+dp[n][j][1])%MOD;
}
printf("%lld\n", ans);
return 0;
}
| #include<iostream>
#include<cstdio>
#include<cstring>
#define N 100010
#define mod 1000000007
#define ll long long
using namespace std;
ll fac[N],inv[N],f[N];
ll ksm(ll a,ll b=mod-2)
{
ll ans=1;
for(;b;b>>=1)
{
if(b&1) ans=ans*a%mod;
a=a*a%mod;
}
return ans;
}
int main()
{
int n,l,r,lt,rt;
scanf("%d%d%d%d%d",&n,&l,&r,<,&rt);
fac[0]=1;
for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
inv[n]=ksm(fac[n]);
for(int i=n-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
f[0]=1;
for(int i=l;i<=r;i++)
for(int j=min(i*rt,n);j>=i*lt;j--)
{
ll u=ksm(inv[i],lt);
int v=j-i*lt;
for(int k=lt;k<=rt;k++)
{
f[j]=(f[j]+fac[j]*u%mod*inv[v]%mod*inv[k]%mod*f[v])%mod;
v-=i,u=u*inv[i]%mod;
if(v<0) break;
}
}
printf("%d\n",f[n]);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using ll = long long;
using P = pair<ll,ll>;
using graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int col[100005];
graph g;
bool color(int x){
bool ok = true;
for(auto nx:g[x]){
if(col[nx]!=-1) {
if(col[nx]==col[x]) ok = false;
else continue;
}
else {
col[nx] = 1-col[x];
if(!color(nx)) ok = false;
}
}
return ok;
}
int main() {
ll N,M;
cin>>N>>M;
g.resize(N);
rep(i,100005) col[i] = -1;
col[0]=0;
rep(i,M){
int x,y;
cin>>x>>y;
x--;
y--;
g[x].push_back(y);
g[y].push_back(x);
}
bool can = color(0);
if(!can) cout<<N*(N-1)/2-M<<endl;
else{
ll cnt0 = 0,cnt1 = 0;
rep(i,N) {
if(col[i]==0) cnt0++;
if(col[i]==1) cnt1++;
}
cout<<cnt0*cnt1-M<<endl;
}
} | #include <bits/stdc++.h>
//#include <ext/numeric>
using namespace std;
//using namespace __gnu_cxx;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
// freopen("fence.out", "w", stdout);
#endif
int n;
cin >> n;
vector<int> arr(n);
for (int &x : arr)
cin >> x;
int l;
cin >> l;
int log = ceil(log2(n));
vector<vector<int>> par(n, vector<int>(log + 1));
auto build = [&]() {
int j = n - 1;
for (int i = n - 1; ~i; --i) {
while (arr[j] - arr[i] > l)
--j;
par[i][0] = j;
}
};
build();
for (int v = n - 1; ~v; --v) {
for (int p = 1; p <= log; ++p)
par[v][p] = par[par[v][p - 1]][p - 1];
}
int q;
cin >> q;
while(q--) {
int u, v;
cin >> u >> v;
--u, --v;
if (u > v)
swap(u, v);
int ans = 0;
for (int p = log; ~p; --p) {
if (par[u][p] < v) {
ans += (1 << p);
u = par[u][p];
}
}
cout << ans + 1 << '\n';
}
return 0;
} | 0 |
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on
template<typename A, typename B>
bool cemax(A &a, const B &b) {
return a <= b ? (a = b, true) : false;
}
void solve() {
int m, mi, ma;
while (cin >> m >> mi >> ma, m) {
mi--, ma--;
vi p(m);
rep(i, m) cin >> p[i];
int c = 0, r = 0;
for (int i = mi; i <= ma; i++) {
if (cemax(c, p[i] - p[i + 1])) r = i;
}
cout << r + 1 << endl;
}
} | #include<iostream>
using namespace std;
int main() {
while (1) {
int m, nmin, nmax;
cin >> m >> nmin >> nmax;
if (m == 0) break;
int ans = 0;
int tmp;
cin >> tmp;
int maxgap = 0;
for (int i = 1; i < m; ++i) {
int s;
cin >> s;
if (maxgap <= tmp - s && i >= nmin && i <= nmax) {
maxgap = tmp - s;
ans = i;
}
tmp = s;
}
cout << ans << endl;
}
} | 1 |