code_file1
stringlengths 80
4k
| code_file2
stringlengths 91
4k
| similar_or_different
int64 0
1
|
---|---|---|
#include <bits/stdc++.h>
using namespace std;
long long INF = 1e18;
int main(){
long long d, g;
cin >> d >> g;
vector<long long> p(d), c(d), score(d);
for(int i = 0; i < d; i++) {
cin >> p[i] >> c[i];
score[i] = (i + 1) * 100;
}
long long ans = INF;
for(int bit = 0; bit < (1 << d); bit++){
long long G = g;
long long res = 0;
vector<int> flag(d, 1);
for(int i = 0; i < d; i++){
if(bit & (1 << i)) {
G -= p[i]*score[i] + c[i];
flag[i] = 0;
res += p[i];
}
}
int t = -1;
for(int j = 0; j < d; j++){
if(flag[j] == 1) t = j;
}
if(G > 0 && G <= p[t] * score[t] + c[t]){
res += min(p[t], (G + score[t] - 1) / score[t]);
ans = min(res, ans);
}
else if(G <= 0) ans = min(res, ans);
}
cout << ans << endl;
}
| /**
* author: souzai32
* created: 01.08.2020 23:22:01
**/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
int n,m;
cin >> n >> m;
vector<tuple<int,int>> con(m);
int s,c;
rep(i,m){
cin >> s >> c;
con.at(i)=make_tuple(s,c);
}
sort(con.begin(),con.end());
vector<int> num(4,-1);
bool a=true;
int ans=0;
rep(i,m){
if(num.at(get<0>(con.at(i)))!=-1 && num.at(get<0>(con.at(i)))!=get<1>(con.at(i))) a=false;
if(get<0>(con.at(i))==1&&get<1>(con.at(i))==0&&n!=1) a=false;
num.at(get<0>(con.at(i)))=get<1>(con.at(i));
}
int t=1;
rep(i,n) t*=10;
if(a){
for(int i=1; i<=n; i++){
t/=10;
if(num.at(i)==-1){
if(i==1 && n!=1) num.at(i)=1;
else num.at(i)=0;
}
ans+=num.at(i)*t;
}
cout << ans << endl;
}
else cout << -1 << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3000000;
const int MOD = 998244353;
int fact[N];
int ifact[N];
int C(int n, int k) {
if (k < 0 || k > n) return 0;
return 1LL * fact[n] * ifact[k] % MOD * ifact[n-k] % MOD;
}
int M(int n, int k) {
return C(n + k - 1, k - 1);
}
int n, m;
int main() {
fact[0] = 1;
for (int i = 1; i < N; ++i) fact[i] = 1LL * fact[i-1] * i % MOD;
ifact[N-1] = 347057526;
for (int i = N-2; i >= 0; --i) ifact[i] = 1LL * ifact[i+1] * (i+1) % MOD;
scanf("%d %d", &n, &m);
long long ans = 0;
for (int odd = 0; odd <= m; ++odd) {
if (m*3 - odd & 1) continue;
int nn = m*3 - odd >> 1;
long long res1 = 1LL * M(nn, n) - 1LL * M(nn - m, n) * n % MOD;
long long res2 = 1LL * M(nn - m, n - 1) * n % MOD;
ans = ans + res1 * C(n, odd) % MOD + res2 * C(n-1, odd) % MOD;
}
ans %= MOD;
if (ans < 0) ans += MOD;
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif
namespace IO {
static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;
inline char myGetchar() {
static char buf[IN_BUF], *ps = buf, *pt = buf;
if (ps == pt) {
ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
}
return ps == pt ? EOF : *ps++;
}
template<typename T>
inline bool read(T &x) {
bool op = 0;
char ch = getchar();
x = 0;
for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
op ^= (ch == '-');
}
if (ch == EOF) {
return false;
}
for (; isdigit(ch); ch = getchar()) {
x = x * 10 + (ch ^ '0');
}
if (op) {
x = -x;
}
return true;
}
inline int readStr(char *s) {
int n = 0;
char ch = getchar();
for (; isspace(ch) && ch != EOF; ch = getchar())
;
for (; !isspace(ch) && ch != EOF; ch = getchar()) {
s[n++] = ch;
}
s[n] = '\0';
return n;
}
inline void myPutchar(char x) {
static char pbuf[OUT_BUF], *pp = pbuf;
struct _flusher {
~_flusher() {
fwrite(pbuf, 1, pp - pbuf, stdout);
}
};
static _flusher outputFlusher;
if (pp == pbuf + OUT_BUF) {
fwrite(pbuf, 1, OUT_BUF, stdout);
pp = pbuf;
}
*pp++ = x;
}
template<typename T>
inline void print_(T x) {
if (x == 0) {
putchar('0');
return;
}
static int num[40];
if (x < 0) {
putchar('-');
x = -x;
}
for (*num = 0; x; x /= 10) {
num[++*num] = x % 10;
}
while (*num){
putchar(num[*num] ^ '0');
--*num;
}
}
template<typename T>
inline void print(T x, char ch = '\n') {
print_(x);
putchar(ch);
}
inline void printStr_(const char *s, int n = -1) {
if (n == -1) {
n = strlen(s);
}
for (int i = 0; i < n; ++i) {
putchar(s[i]);
}
}
inline void printStr(const char *s, int n = -1, char ch = '\n') {
printStr_(s, n);
putchar(ch);
}
}
using namespace IO;
const int N = 2500005, P = 998244353;
int n, m;
int fac[N], inv[N];
int qpow(int a, int b) {
int s = 1;
for (; b; b >>= 1) {
if (b & 1) {
s = 1ll * s * a % P;
}
a = 1ll * a * a % P;
}
return s;
}
void init(int n) {
fac[0] = 1;
for (int i = 1; i <= n; ++i) {
fac[i] = 1ll * fac[i - 1] * i % P;
}
inv[n] = qpow(fac[n], P - 2);
for (int i = n; i; --i) {
inv[i - 1] = 1ll * inv[i] * i % P;
}
}
int C(int n, int m) {
if (m < 0 || m > n) {
return 0;
}
return 1ll * fac[n] * inv[m] % P * inv[n - m] % P;
}
int main() {
read(n), read(m);
init(n + 3 * m);
int ans = 0;
for (int i = m & 1; i <= n && i <= m; i += 2) {
int S = (3 * m - i) >> 1, s = 0;
for (int j = 0; j <= i && m * j <= S; ++j) {
for (int k = 0; k <= n - i && m * j + (m + 1) * k <= S; ++k) {
int t = 1ll * C(i, j) * C(n - i, k) % P * C(S - m * j - (m + 1) * k + n - 1, n - 1) % P;
if ((j + k) & 1) {
s = (s + P - t) % P;
} else {
s = (s + t) % P;
}
}
}
ans = (ans + 1ll * s * C(n, i)) % P;
}
print(ans);
}
| 1 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <string>
#include <map>
using namespace std;
long long A[100002] = {0};
long long S[100002] = {0};
map<long long, long long> m;
int main(int argc, char* argv[]){
int N;
long long M; //N 1.. 100000 M 2..1000000000
cin >> N >> M ;
A[0] = 0, S[0] = 0;
for(int i=1; i<=N; i++){
cin >> A[i];
S[i] = ( S[i-1]+A[i] ) % M;
if(m.count(S[i])==0){
m[S[i]] = 1;
}
else{
long long r = m[S[i]];
m[S[i]] = r+1;
}
}
unsigned long long ans = 0;
for(auto it=m.begin(); it!=m.end(); ++it){
long long k, v;
k = it->first;
v = it->second;
if(k==0){
ans = ans + v + (v*(v-1))/2; //重複OK
}
else{
ans = ans + (v*(v-1))/2;
}
}
printf("%llu\n", ans);
return 0;
} | #include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int N,M;
cin>>N>>M;
map<int,int> mp;
mp[0]=1;
int n=0;
while(N--){
int a;
cin>>a;
n=(n+a)%M;
mp[n]++;
}
int ans=0;
for(pair<int,int> p:mp)ans+=p.second*(p.second-1)/2;
cout<<ans<<endl;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;
int main() {
ll n;
cin >> n;
vec x(n),y(n);
for(ll i=0;i<n;i++) cin >> x[i] >> y[i];
for(ll i=0;i<n;i++) {
vector<double> d;
for(ll j=0;j<n;j++) {
if(i==j) continue;
d.push_back(atan2(y[j]-y[i],x[j]-x[i]));
}
sort(d.begin(),d.end());
double r=0;
ll k=d.size();
for(ll j=0;j<k;j++) {
d.push_back(d[j]+2*M_PI);
}
for(ll j=0;j<k;j++) {
r=max(r,M_PI-(d[j+k]-d[j+1]));
}
cout << fixed << setprecision(10) << r/(2*M_PI) << endl;
}
} | #include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
using Real = double;
using Point = complex< Real >;
const Real EPS = 1e-8, PI = acos(-1);
using Polygon = vector< Point >;
namespace std {
bool operator<(const Point &a, const Point &b) {
return a.real() != b.real() ? a.real() < b.real() : a.imag() < b.imag();
}
}
inline bool eq(Real a, Real b) { return fabs(b - a) < EPS; }
Real cross(const Point &a, const Point &b) {
return real(a) * imag(b) - imag(a) * real(b);
}
Real dot(const Point &a, const Point &b) {
return real(a) * real(b) + imag(a) * imag(b);
}
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C
// 点の回転方向
int ccw(const Point &a, Point b, Point c) {
b = b - a, c = c - a;
if(cross(b, c) > EPS) return +1; // "COUNTER_CLOCKWISE"
if(cross(b, c) < -EPS) return -1; // "CLOCKWISE"
if(dot(b, c) < 0) return +2; // "ONLINE_BACK"
if(norm(b) < norm(c)) return -2; // "ONLINE_FRONT"
return 0; // "ON_SEGMENT"
}
Point operator*(const Point &p, const Real &d) {
return Point(real(p) * d, imag(p) * d);
}
istream &operator>>(istream &is, Point &p) {
Real a, b;
is >> a >> b;
p = Point(a, b);
return is;
}
ostream &operator<<(ostream &os, Point &p) {
os << fixed << setprecision(10) << p.real() << " " << p.imag();
}
Polygon convex_hull(Polygon &p) {
int n = (int) p.size(), k = 0;
if(n <= 2) return p;
sort(p.begin(), p.end());
vector< Point > ch(2 * n);
for(int i = 0; i < n; ch[k++] = p[i++]) {
while(k >= 2 && cross(ch[k - 1] - ch[k - 2], p[i] - ch[k - 1]) < EPS) --k;
}
for(int i = n - 2, t = k + 1; i >= 0; ch[k++] = p[i--]) {
while(k >= t && cross(ch[k - 1] - ch[k - 2], p[i] - ch[k - 1]) < EPS) --k;
}
ch.resize(k - 1);
return ch;
}
int main(){
int n;
cin >> n;
Polygon v(n);
map<Point,int> ma;
for (int i = 0; i < n; i++) {
cin >> v[i];
ma[v[i]] = i;
}
auto p = convex_hull(v);
vector<double> ans(n,0.0);
if(p.size()==2){
for (int i = 0; i < p.size(); i++) {
ans[ma[p[i]]] = 1./2;
}
}
else{
for (int i = 0; i < p.size(); i++) {
Point a = p[(i+1)%p.size()] - p[i];
Point b = p[(i-1+p.size())%p.size()] - p[i];
double theta = acos(dot(a,b) / abs(a) / abs(b));
ans[ma[p[i]]] = (PI - theta) / 2 / PI;
}
}
for (int i = 0; i < n; i++) {
cout << setprecision(30) << ans[i] << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b) for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n) For(i, 0, n)
#define debug(x) cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line
int main()
{
string s;
cin >> s;
cout << s.substr(0,(s.size() - 8)) << endl;
}
| #include <stdio.h>
int main (){
long long int a;
long long int hasil=0;
scanf("%lld",&a);
for (int i=1 ; i<=a ; i++){
if (i%3==0 && i%5==0){
// puts("Fizzbuzz");
}
else if (i%3==0){
// puts ("Fizz");
}
else if (i%5==0){
// puts("Buzz");
}
else{
hasil=(hasil+i);
}
}
printf("%lld",hasil);
return 0;
} | 0 |
/*
DISCLAIMER: I don't expect this to AC first submit, but it'd be pretty great if it did...
-> I'm rusty af
*/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //gp_hash_table
#define all(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define sz(a) (int) a.size()
#define bitcount(a) __builtin_popcount(a)
#define bitcountll(a) __builtin_popcountll(a)
using namespace std;
// using namespace __gnu_pbds;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
void solve() {
const ll oo = 1e18;
int n; cin >> n;
vector<pii> a(n);
for(auto& p : a) cin >> p.first >> p.second;
sort(all(a), [](const pii& x, const pii& y) {
int l = x.first - y.second;
int r = y.first - x.second;
return l < r;
});
a.insert(a.begin(), {-1, -1});
vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, oo));
int ans = 0;
dp[0][0] = 0;
for(int i = 1; i <= n; ++i) {
dp[i][0] = 0;
for(int x = 1; x <= i; ++x) {
dp[i][x] = dp[i - 1][x];
if(dp[i - 1][x - 1] <= a[i].first) {
dp[i][x] = min(dp[i][x], dp[i - 1][x - 1] + a[i].second);
}
if(dp[i][x] < oo) {
ans = max(ans, x);
}
}
}
cout << ans << endl;
}
int main() {
// freopen("input.in", "r", stdin);
// freopen("input.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(20);
cout << fixed;
// int t; cin >> t; while(t--)
solve();
cout.flush();
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N=2e5+5;
int n;
LL a[90][40];
LL ans;
int main()
{
cin>>n;
while(n--)
{
string s;
cin>>s;
LL y=0;
int u=s.size();
for(int i=0;i<s.size();i++)
if(s[i]=='.') u=i;
if(u==s.size()) s+=".";
for(int i=s.size()-u;i<=9;i++) s+="0";
for(int i=0;i<s.size();i++)
if(s[i]!='.') y=y*10+s[i]-'0';
int z1=0,z2=0;
while(y%2==0) y/=2,z1++;
while(y%5==0) y/=5,z2++;
a[z1+36][z2+11]++;
}
for(int i=0;i<90;i++)
for(int j=0;j<40;j++)
for(int k=90-i;k<90;k++)
for(int l=40-j;l<40;l++)
ans+=a[i][j]*a[k][l];
for(int i=45;i<90;i++)
for(int j=20;j<40;j++)
ans-=a[i][j];
cout<<ans/2<<'\n';
return 0;
} | 0 |
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;
const int N = 100010, M = 1010;
int n;
int h[N], e[N], ne[N], idx;
int match[N];
bool st[N];
PII p[N];
void add(int a, int b)
{
e[idx] = b, ne[idx] = h[a], h[a] = idx ++ ;
}
bool find(int u)
{
for (int i = h[u]; ~i; i = ne[i])
{
int j = e[i];
if (!st[j])
{
st[j] = true;
if (match[j] == 0 || find(match[j]))
{
match[j] = u;
return true;
}
}
}
return false;
}
int main()
{
memset(h, -1, sizeof h);
scanf("%d", &n);
for (int i = 1; i <= n; i ++ ) scanf("%d%d", &p[i].F, &p[i].S);
for (int i = n + 1; i <= 2 * n; i ++ ) scanf("%d%d", &p[i].F, &p[i].S);
for (int i = 1; i <= n; i ++ )
for (int j = n + 1; j <= 2 * n; j ++ )
if (p[i].F < p[j].F && p[i].S < p[j].S)
add(i, j);
int res = 0;
for (int i = 1; i <= n; i ++ )
{
memset(st, 0, sizeof st);
if (find(i)) res ++ ;
}
printf("%d\n", res);
return 0;
} | #include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#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 mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);
int main() {
int M;
cin>>M;
ll d, c;
ll ans = 0;
ll sum = 0;
for(int i=0;i<M;++i) {
cin>>d>>c;
ans += c;
sum += d*c;
}
ans--;
if(sum%9==0) ans += sum/9-1;
else ans += sum/9;
cout<<ans<<endl;
}
| 0 |
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <set>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
set<int> s;
for (int i = 0; i < k; i++) {
int x;
cin >> x;
s.insert(x);
}
int a = n;
while (1) {
int c = a;
bool ok = 1;
while (c > 0) {
int di = c % 10;
if (s.count(di)) {
ok = 0;
break;
}
c /= 10;
}
if (ok) {
cout << a << endl;
break;
}
a++;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define 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 rall(x) x.rbegin(), x.rend()
#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 forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(int i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(int i=(a);i<(n);i++)cout<<(arr)[i]<<' ';
const ll inf = 1e18;
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;
ll n, k;
cin>>n>>k;
ll d;
map<ll, ll> m;
forn(i, 0, k){
cin>>d;
m[d]++;
}
ll ans;
forn(i, n, n+100000){
ll x = i, f = 1;
while(x){
if(m[x%10]>0){
f = 0;
break;
}
x/=10;
}
if(f == 1){
ans = i;
break;
}
}
cout<<ans<<endl;
} | 1 |
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cctype>
#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<bool>> VVB;
typedef pair<int,int> PII;
typedef pair<char,int> PCI;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
#define process first
#define movecnt second
int N, M;
VVB area;
vector<PCI> ms;
int posx, posy;
bool check () {
rep (i, area.size()) {
rep (j, area[i].size()) {
if (area[i][j]) return false;
}
}
return true;
}
void move (int movex, int movey, int cnt) {
rep (i, cnt) {
if (xyrange(posx, 0, 20, posy, 0, 20)) {
posx += movex;
posy += movey;
area[posy][posx] = false;
}
}
}
bool solve () {
posx = posy = 10;
area[posy][posx] = false;
for (auto &m : ms) {
switch (m.process) {
case 'N':
move(0, 1, m.movecnt);
break;
case 'S':
move(0, -1, m.movecnt);
break;
case 'E':
move(1, 0, m.movecnt);
break;
case 'W':
move(-1, 0, m.movecnt);
break;
}
}
return check();
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
while (cin >> N, N) {
area.clear();
area.resize(21, VB(21, false));
ms.clear();
rep (i, N) {
int x, y;
cin >> x >> y;
area[y][x] = true;
}
cin >> M;
rep (i, M) {
PCI m;
cin >> m.process >> m.movecnt;
ms.pb(m);
}
cout << (solve()? "Yes" : "No") << endl;
}
return 0;
} | #include <iostream>
using namespace std;
#define INF 10000000
// 0: cost , 1 :time
int d[2][101][101];
int main() {
int n, m, a, b, cost, time, k, p, q, r, i, j;
while ((cin >> n >> m) && n) {
for (i = 1; i <= m; i++) {
for (j = 1; j <= m; j++) {
d[0][i][j] = d[1][j][i] = INF;
}
}
for (i = 0; i < n; i++) {
cin >> a >> b >> cost >> time;
d[0][a][b] = d[0][b][a] = cost;
d[1][a][b] = d[1][b][a] = time;
}
for (k = 1; k <= m; k++) {
for (i = 1; i <= m; i++) {
for (j = 1; j <= m; j++) {
for (r = 0; r < 2; r++) {
if (d[r][i][j] > d[r][i][k] + d[r][k][j]) {
d[r][j][i] = d[r][i][j] = d[r][i][k] + d[r][k][j];
}
}
}
}
}
cin >> k;
while (k--) {
cin >> p >> q >> r;
cout << d[r][p][q] << endl;
}
}
return 0;
} | 0 |
// ALDS1_12_A.cpp
// Graph II - Minimum Spanning Tree
#include <iostream>
using namespace std;
const int maxN = 100;
const int INF = 2001;
int w[maxN][maxN];
int color[maxN];
int n;
static const int WHITE = 0;
static const int BLACK = 1;
int prim(int x)
{
int res = 0;
int cnt = 1;
color[x] = BLACK;
while (cnt++ != n) {
int minCost = INF;
int pos = 0; // ??°?????°?????????
for (int i = 0; i < n; i++) {
if (color[i] != BLACK) continue;
for (int j = 0; j < n; j++) {
if (color[j] != WHITE) continue;
if (w[i][j] < minCost) {
pos = j;
minCost = w[i][j];
}
}
}
res += minCost;
color[pos] = BLACK;
}
return res;
}
int main()
{
cin >> n;
int num;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> num;
if (num == -1) w[i][j] = INF;
else w[i][j] = num;
}
}
cout << prim(0) << endl;
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int P[10010];
void init(int N){
for (int i=0; i<N; i++) P[i] = i;
}
int root (int a){
if (P[a] == a) return a;
else {
P[a] = root(P[a]);
return P[a];
}
}
bool is_same_set(int a, int b){
return root(a) == root(b);
}
void unite(int a, int b){
P[root(a)] = root(b);
}
int main(){
int N;
cin >> N;
pair <int, int> edge[10010];
for (int i=0; i<N; i++){
for (int j=0; j<N; j++){
cin >> edge[i*N+j].first;
edge[i*N+j].second = i*N+j;
}
}
sort(edge, edge+N*N);
init(N);
int ans = 0;
int b = 0;
for (int k=0; k<N*N; k++){
while(edge[k].first < 0) k++;
int i = edge[k].second / N;
int j = edge[k].second % N;
if (is_same_set(i,j)){}
else{
unite(i,j);
ans += edge[k].first;
}
}
cout << ans << endl;
} | 1 |
#include "bits/stdc++.h"
using namespace std;
int main()
{
int n,ans,mn;
ans=1;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++)
{
cin>>a.at(i);
}
mn=a.at(0);
for(int i=1;i<n;i++)
{
if(mn>a.at(i))
ans++;
mn=min(mn,a.at(i));
}
cout<<ans<<endl;
} | #include <iostream>
#include <string>
using namespace std;
int main(void){
string str;
int n;
int i=0;
int ocnt=0, bcnt=0;
int score=0;
cin >> n;
while(i < n){
cin >> str;
if(str == "OUT"){
ocnt++;
}else if(str == "HIT"){
if(bcnt < 3){
bcnt++;
}else{
score++;
}
}else if(str == "HOMERUN"){
score += bcnt+1;
bcnt = 0;
}
if(ocnt == 3){
cout << score << endl;
ocnt = 0;
bcnt = 0;
score = 0;
i++;
}
}
} | 0 |
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i<n;i++)
#define cint(a) int a; cin >> a;
#define cstr(str) string str; cin >> str;
#define vv(Type, n,m,d)vector<vector<Type>> vv(n, vector<Type>(m, d));
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
int n, r; cin >> n >> r;
if (n >= 10) cout << r << endl;
else cout << r + 100 * (10 - n) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;
ll GCD(ll x,ll y){
if(y == 0) return x;
else return GCD(y,x%y);
}
ll LCM(ll a,ll b){
return a / GCD(a,b) * b;
}
const int MOD = 1000000007;
int main() {
int a,b; cin >> a >> b;
if(abs(a-b) <= 1){
cout << "Yay!";
}else{
cout << ":(";
}
}
| 0 |
# include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int inf = (int)1e9 + 7;
const int maxn = (int)6e5 + 7;
const int lmaxn = (int)6e6 + 7;
const ll linf = (ll)1e16 + 7;
const ld eps = ld(1e-11);
const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};
ll gcd(ll a, ll b){
while(b) a %= b, swap(a, b);
return a | b;
}
ll lcm(ll a, ll b){
return a * b / gcd(a, b);
}
string a;
bool ok(string x){
vector < ll > cnt(27, 0);
for(ll i : x)
cnt[i - 'a']++;
for(ll i : x){
if(cnt[i - 'a'] > (ll)x.size() / 2)
return 1;
}
return 0;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> a;
for(ll len = 2; len <= min((ll)a.size(), 5ll); ++len){
for(ll i = 0; i + len - 1 < (ll)a.size(); ++i){
if(ok(a.substr(i, len))){
cout << i + 1 << " " << i + len;
return 0;
}
}
}
cout << -1 << " " << -1;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))
//3111111111111111111111111111111
void solve(){
ins(morty);
int tmp = -1;
int tmp1 = -1;
FOR(i,0,morty.size()-1){
if(morty[i] == morty[i+1]){tmp = i+1;tmp1 = i+2;break;}
}
FOR(i,0,morty.size()-2){
if(morty[i] == morty[i+2]){tmp = i+1;tmp1 = i+3;break;}
}
out(tmp,tmp1);
}
int32_t main() {
oneforall
oneforall
oneforall
oneforall
oneforall
oneforall
oneforall
oneforall
oneforall
oneforall
oneforall
oneforall
oneforall
oneforall
solve();
return 0;
}
| 1 |
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 1987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
char s[2000][2002];
int v[2002][2002],ex[2002][2002],ey[2002][2002];
int main() {
int n,m,q;
scanf("%d%d%d",&n,&m,&q);
fup(i,0,n-1,1)scanf("%s",s[i]);
fup(i,0,n-1,1)
fup(j,0,m-1,1)
v[i+1][j+1]=v[i][j+1]+v[i+1][j]-v[i][j]+(s[i][j]=='1');
fup(i,0,n-2,1)
fup(j,0,m-1,1)
ex[i+1][j+1]=ex[i][j+1]+ex[i+1][j]-ex[i][j]+(s[i][j]=='1' && s[i+1][j]=='1');
fup(i,0,n-1,1)
fup(j,0,m-2,1)
ey[i+1][j+1]=ey[i][j+1]+ey[i+1][j]-ey[i][j]+(s[i][j]=='1' && s[i][j+1]=='1');
while(q--)
{
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
int t1=v[x2][y2]-v[x2][y1-1]-v[x1-1][y2]+v[x1-1][y1-1];
int t2=ex[x2-1][y2]-ex[x2-1][y1-1]-ex[x1-1][y2]+ex[x1-1][y1-1];
int t3=ey[x2][y2-1]-ey[x2][y1-1]-ey[x1-1][y2-1]+ey[x1-1][y1-1];
printf("%d\n",t1-t2-t3);
}
} | #include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define inver(a) power(a, mod - 2)
#define F(x, y) C(x - 1 + y, y)
using namespace std;
inline char nc()
{
return getchar();
static char buf[100000], *l = buf, *r = buf;
return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x)
{
x = 0; int f = 1, ch = nc();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
x *= f;
}
typedef long long ll;
const int mod = 998244353;
const int maxn = 2000050;
int n, m;
int fac[maxn];
int fac_inv[maxn];
inline int dec(int x) {return x < 0 ? x + mod : x;}
inline ll C(int x, int y)
{
return (ll)fac[x] * fac_inv[y] % mod * fac_inv[x - y] % mod;
}
ll power(ll x, ll y)
{
ll re = 1;
while(y)
{
if(y & 1) re = re * x % mod;
x = x * x % mod;
y >>= 1;
}
return re;
}
void init(int n)
{
fac[0] = 1;
for(int i = 1; i <= n; ++i)
{
fac[i] = (ll)fac[i - 1] * i % mod;
}
fac_inv[n] = inver(fac[n]);
for(int i = n; i >= 1; --i)
{
fac_inv[i - 1] = (ll)fac_inv[i] * i % mod;
}
}
int cal(int x, int y)
{
int re = F(n, x);
re = dec(re - y * F(n, x - m) % mod);
if(x > m) re = dec(re - (n - y) * F(n, x - m - 1) % mod);
return re;
}
int solve()
{
int an = 0;
for(int i = 0; i <= min(m, n); ++i)
{
if((3 * m - i) & 1) continue;
an = (an + cal((3 * m - i) >> 1, i) * C(n, i)) % mod;
}
return an;
}
int main()
{
read(n), read(m);
init(n + (m << 1));
printf("%d\n", solve());
return 0;
}
| 0 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll gcd(int a,int b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(int a,int b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll INFS=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
int main() {
int n;
cin>>n;
map<int,int> mp;
rep(i,n){
int a;
cin>>a;
mp[a]++;
}
if(mp.size()==n){
cout<<"YES"<<endl;
return 0;
}
cout<<"NO"<<endl;
} | #include <bits/stdc++.h>
#define N 1000020
#define ll long long
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return f?x:-x;
}
char s[N], t[N];
queue<int> q;
int main(int argc, char const *argv[]) {
int n = read();
scanf("%s", s + 1);
scanf("%s", t + 1);
if (!strcmp(s + 1, t + 1)) {
return puts("0"), 0;
}
int ans = 0;
for (int i = n, j = n; i; -- i) {
if (t[i] == t[i - 1]) continue;
j = min(j, i);
while (j && s[j] != t[i]) {
-- j;
}
if (!j) {
return puts("-1"), 0;
}
while (!q.empty() && q.front() >= i + q.size()) {
q.pop();
}
q.push(j);
if (i != j) {
ans = max(ans, (int) q.size());
}
}
printf("%d\n", ans + 1);
return 0;
}
/*
7
atcoder
aaaccce
*/ | 0 |
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef struct{
string name;
int p,abc,de,f,s,m;
int sum;
double KORITU; //sum(収入) / 時間(abc+de)+付加時間(de*(m-1)
}K;
int main(){
int n;
int A,B,C,D,E;
while(1){
cin >> n;
if(n==0)break;
K data[51];
K temp;
for(int i=0;i<n;i++){
cin >> data[i].name >> data[i].p >> A >> B >> C >> D >> E >> data[i].f >> data[i].s >> data[i].m;
data[i].abc=A+B+C;
data[i].de=D+E;
data[i].sum= data[i].f * data[i].s * data[i].m - data[i].p;
data[i].KORITU = (double)data[i].sum / (double)(data[i].abc+data[i].de + data[i].de*(data[i].m-1) );
}
for(int i=0;i<n-1;i++){
for(int j=n-1;j>i;j--){
if(data[j].KORITU > data[j-1].KORITU){
temp=data[j];
data[j]=data[j-1];
data[j-1]=temp;
}
}
}
for(int i=0;i<n-1;i++){
for(int j=n-1;j>i;j--){
if(data[j].KORITU==data[j-1].KORITU&& data[j].name < data[j-1].name){
temp=data[j];
data[j]=data[j-1];
data[j-1]=temp;
}
}
}
for(int i=0;i<n;i++){
cout << data[i].name << endl;
}
cout << "#" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);
template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
each(x,vec) is >> x;
return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
rep(i,vec.size()) {
if (i) os << " ";
os << vec[i];
}
return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
rep(i,vec.size()) {
if (i) os << endl;
os << vec[i];
}
return os;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, a, b;
while (cin >> n >> a >> b, n || a || b) {
vector<ll> s(n); cin >> s;
P ans(-linf, -linf);
rep(i, n-1) {
if (a <= i+1 && i+1 <= b) {
chmax(ans, P(s[i] - s[i+1], i+1));
}
}
cout << ans.second << endl;
}
} | 0 |
#include <cstdio>
#include <algorithm>
using namespace std;
const char *solve(){
int c[20] = {};
int a;
for(int i = 0; i < 5; ++i){
if(scanf("%d,", &a) == EOF){ return 0; }
++c[a];
}
c[14] = c[1];
int mc = 0, ms = 0, p = 0;
for(int i = 1; i < 14; ++i){
mc = max(mc, c[i]);
if(c[i] > 1){ ++p; }
int s = 0;
for(int j = 0; j < 5 && c[i + j]; ++j){
++s;
}
ms = max(ms, s);
}
if(mc == 4){ return "four card"; }
if(p > 1 && mc > 2){ return "full house"; }
if(ms > 4){ return "straight"; }
if(mc > 2){ return "three card"; }
if(p > 1){ return "two pair"; }
if(p){ return "one pair"; }
return "null";
}
int main(){
const char *ans;
while(ans = solve()){
puts(ans);
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
int main() {
int N; cin >> N;
vector<int> primes;
rep2(i, 2, 55555) {
bool flag = true;
rep(j, primes.size()) {
if (i%primes[j] == 0) {
flag = false;
break;
}
}
if (flag) primes.push_back(i);
}
vector<int> ans;
rep(i, primes.size()) {
if (primes[i]%5 == 1) ans.push_back(primes[i]);
}
rep(i, N) {
if (i) cout << " ";
cout << ans[i];
}
cout << 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++)
ll ans = 0;
bool cmp(const pair<ll,ll> &a, const pair<ll,ll> &b){
if(a.first==b.first)return a.second > b.second;
else return a.first < b.first;
}
int main()
{
ll n ;
cin >> n ;
vector<pair<ll,ll>> v(n);
ll rmin=0,lmax=0;
rep(i, n){
cin >> v[i].first >> v[i].second;
ans=max(ans,v[i].second-v[i].first+1);
if(v[rmin].second>v[i].second)rmin=i;
if(v[lmax].first <v[i].first)lmax=i;
}
ans+=max(0LL,v[rmin].second-v[lmax].first+1);
ll ss=v[rmin].second,t=v[lmax].first;
sort(v.begin(),v.end(),cmp);
multiset<ll> s;
rep(i,n)s.insert(v[i].second);
rep(i,n){
s.erase(s.find(v[i].second));
ans=max(ans,max(ss-v[i].first+1,0LL)+max(*s.begin()-t+1,0LL));
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
#include<tr1/unordered_map>
#define ri register int
using namespace std;
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> poly;
#define pb push_back
const int rlen=1<<18|1,inf=0x3f3f3f3f;
const ll Inf=1e18;
char buf[rlen],*ib=buf,*ob=buf;
#define gc() (((ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin)),ib==ob)?-1:*ib++)
inline int read() {
int ans=0;
bool f=1;
char ch=gc();
while(!isdigit(ch)) f^=ch=='-',ch=gc();
while(isdigit(ch)) ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
return f?ans:-ans;
}
inline ll readl() {
ll ans=0;
bool f=1;
char ch=gc();
while(!isdigit(ch)) f^=ch=='-',ch=gc();
while(isdigit(ch)) ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
return f?ans:-ans;
}
inline int Read(char*s) {
int tp=0;
char ch=gc();
while(!isdigit(ch)&&!isalpha(ch)) ch=gc();
while(isdigit(ch)||isalpha(ch)) s[++tp]=ch,ch=gc();
return tp;
}
namespace modular {
const int mod=1e9+7;
inline int add(int a,int b) { return a+b<mod?a+b:a+b-mod; }
inline int dec(int a,int b) { return a<b?a-b+mod:a-b; }
inline int mul(int a,int b) { return (ll)a*b%mod; }
inline void Add(int&a,int b) { a=a+b<mod?a+b:a+b-mod; }
inline void Dec(int&a,int b) { a=a<b?a-b+mod:a-b; }
inline void Mul(int&a,int b) { a=(ll)a*b%mod; }
inline int ksm(int a,int p) { int ret=1;for(;p;p>>=1,Mul(a,a)) (p&1)&&(Mul(ret,a),1);return ret; }
inline int Inv(int a) { return ksm(a,mod-2); }
inline int sqr(int a) { return mul(a,a); }
inline int cub(int a) { return (ll)a*a%mod*a%mod; }
}
using namespace modular;
template<typename T> inline void ckmax(T&a,T b) { a<b?a=b:0; }
template<typename T> inline void ckmin(T&a,T b) { a>b?a=b:0; }
template<typename T> inline T gcd(T a,T b) { T t;while(b)t=a,a=b,b=t-t/a*a;return a; }
template<typename T> inline T Abs(T x) { return x<0?-x:x; }
inline int rd() { return rand()|(rand()<<15); }
const int N=5e5+5;
int n,pre[N],suf[N];
pii a[N];
int main() {
#ifdef ldxcaicai
freopen("lx.in","r",stdin);
#endif
n=read();
for(ri i=1;i<=n;++i) a[i].fi=read(),a[i].se=read();
sort(a+1,a+n+1);
pre[0]=0x3f3f3f3f,suf[n]=0x3f3f3f3f;
for(ri i=1;i<n;++i) pre[i]=min(pre[i-1],a[i].se);
for(ri i=n-1;i;--i) suf[i]=min(suf[i+1],a[i].se);
int res=0;
for(ri mn,r1,r2,t,i=1;i<n;++i) {
r1=a[i].se,r2=min(max(suf[i+1],a[n].fi-1),a[n].se);
t=(r1-a[i].fi+1)+(r2-a[n].fi+1);
mn=pre[i-1];
ckmax(res,t-max(0,min(r1-max(a[i].fi-1,mn),r2-max(a[n].fi-1,mn))));
}
cout<<res;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n"
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pair<int, int>>
#define mems(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define forn(i, s, e) for (int i = s; i < (e); ++i)
#define FASTIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define FILEIO \
freopen("./input.txt", "r", stdin); \
freopen("./output.txt", "w", stdout);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) \
for ( \
auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
blockTime.second; \
debug("%s : %lld ms\n ", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
const int M = 1e9 + 7;
template <class T>
T ABS(const T &x) { return x > 0 ? x : -x; }
ll gcd(ll n1, ll n2) { return n2 == 0 ? ABS(n1) : gcd(n2, n1 % n2); }
ll lcm(ll n1, ll n2) { return n1 == 0 && n2 == 0 ? 0 : ABS(n1 * n2) / gcd(n1, n2); }
int main()
{
FASTIO
#ifdef LOCAL
FILEIO
#endif
int n, i;
cin >> n;
if (n % 111 == 0)
{
cout << n << endl;
return 0;
}
for (i = 1; i < 10; ++i)
{
if (n < i * 111)
{
break;
}
}
cout << i * 111 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
int a; cin>>a;
if(a<=111){
cout<<111<<endl;
}else if(a<=222){
cout<<222<<endl;
}else if(a<=333){
cout<<333<<endl;
}else if(a<=444){
cout<<444<<endl;
}else if(a<=555){
cout<<555<<endl;
}else if(a<=666){
cout<<666<<endl;
}else if(a<=777){
cout<<777<<endl;
}else if(a<=888){
cout<<888<<endl;
}else{
cout<<999<<endl;
}
}
| 1 |
/**
* @FileName a.cpp
* @Author kanpurin
* @Created 2020.08.20 03:18:30
**/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
class UnionFind {
private:
vector<int> par;
public:
UnionFind(int n) {
par.resize(n, -1);
}
int root(int x) {
if (par[x] < 0) return x;
return par[x] = root(par[x]);
}
bool unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry) return false;
if (size(rx) < size(ry)) swap(rx, ry);
par[rx] += par[ry];
par[ry] = rx;
return true;
}
bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
int size(int x) {
return -par[root(x)];
}
};
int main() {
int n;cin >> n;
vector<pair<int,int>> p(n),q(n);
for (int i = 0; i < n; i++) {
int a,b;cin >> a >> b;
p[i].first = a;
p[i].second = q[i].second = i;
q[i].first = b;
}
sort(p.begin(), p.end());
sort(q.begin(), q.end());
UnionFind uf(n);
typedef tuple<int,int,int> T;
priority_queue<T,vector<T>,greater<T>> pq;
for (int i = 0; i < n-1; i++) {
pq.push(make_tuple(p[i+1].first - p[i].first,p[i+1].second,p[i].second));
pq.push(make_tuple(q[i+1].first - q[i].first,q[i+1].second,q[i].second));
}
ll ans = 0;
while(!pq.empty()) {
auto t = pq.top();
pq.pop();
int x = get<1>(t);
int y = get<2>(t);
if (!uf.same(x,y)) {
ans += get<0>(t);
uf.unite(x,y);
}
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
using namespace std;
typedef pair<llint, llint> P;
llint n;
llint x[200005], y[200005], u[200005], v[200005];
char c[200005];
vector<P> vec[6][4000005];
llint calc(vector<P> &vec)
{
llint ret = inf, l = -inf;
for(int i = 0; i < vec.size(); i++){
if(vec[i].second == -1) l = vec[i].first;
else ret = min(ret, vec[i].first - l);
}
return ret;
}
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> x[i] >> y[i] >> c[i];
x[i] *= 10, y[i] *= 10;
u[i] = x[i] + y[i], v[i] = x[i] - y[i] + 2000002;
}
for(int i = 1; i <= n; i++){
if(c[i] == 'R') vec[0][y[i]].push_back(P(x[i], -1));
if(c[i] == 'L') vec[0][y[i]].push_back(P(x[i], 1));
if(c[i] == 'U') vec[1][x[i]].push_back(P(y[i], -1));
if(c[i] == 'D') vec[1][x[i]].push_back(P(y[i], 1));
if(c[i] == 'R') vec[2][u[i]].push_back(P(v[i], -1));
if(c[i] == 'U') vec[2][u[i]].push_back(P(v[i], 1));
if(c[i] == 'D') vec[3][u[i]].push_back(P(v[i], -1));
if(c[i] == 'L') vec[3][u[i]].push_back(P(v[i], 1));
if(c[i] == 'L') vec[4][v[i]].push_back(P(u[i], 1));
if(c[i] == 'U') vec[4][v[i]].push_back(P(u[i], -1));
if(c[i] == 'R') vec[5][v[i]].push_back(P(u[i], -1));
if(c[i] == 'D') vec[5][v[i]].push_back(P(u[i], 1));
}
llint ans = inf;
for(int i = 0; i < 6; i++){
for(int j = 0; j < 4000005; j++){
sort(vec[i][j].begin(), vec[i][j].end());
ans = min(ans, calc(vec[i][j]));
}
}
if(ans > inf/2) cout << "SAFE" << endl;
else cout << ans / 2 << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;
const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ")
{ if (!v.size()) puts(""); rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }
bool izryt(pair<pair<int, int>, string> a, pair<pair<int, int>, string> b) {
if (a.fs.fs * b.fs.sc == b.fs.fs * a.fs.sc) return a.sc < b.sc;
return a.fs.fs * b.fs.sc > b.fs.fs * a.fs.sc;
}
signed main() {
int n;
while (cin >> n, n) {
vector<pair<pair<int, int>, string>> v;
rep(i, n) {
string l;
cin >> l;
int p = in();
int u = 0, t = 0;
rep(i, 3) u += in();
rep(i, 2) t += in();
int f = in();
int s = in();
int m = in();
v.pb(mp(mp((f * m * s - p), (u + t * m)), l));
}
sort(all(v), izryt);
rep(i, n) {
cout << v[i].sc << endl;
}
cout << "#" << endl;
}
} | #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"
using namespace std;
const long long int MOD = 1000000007;
long long int power(long long int x, long long int n, long long int M) {
long long int tmp = 1;
if (n > 0) {
tmp = power(x, n / 2, M);
if (n % 2 == 0) tmp = (tmp*tmp) % M;
else tmp = (((tmp*tmp) % M)*x) % M;
}
return tmp;
}
long long int N, M, K, Q, W, H, L, R;
long long int ans;
int main() {
ios::sync_with_stdio(false);
cin >> N;
while (N) {
set<pair<long double, string> >s;
for (int i = 0; i < N; i++) {
string t;
long double p, a, b, c, d, e, f, n, m;
cin >> t >> p >> a >> b >> c >> d >> e >> f >> n >> m;
s.insert({ 1000-((f*n*m - p) / (a + b + c + d*m + e*m)) ,t });
}
for (auto i : s) {
cout << i.second << endl;
}
cout << "#\n";
cin >> N;
}
return 0;
} | 1 |
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>; using Vi = vector<long long int>;
using P = pair<int, int>; using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";};
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////
ll m;
map<ll,ll> ma;
Vi d,c;
bool ck(){
ll sum = 0;
rep(i,10){
sum += ma[i];
if(sum>=2)return true;
}
return false;
}
int main(){
cin.tie(0);ios::sync_with_stdio(false);
std::cout<<std::fixed<<std::setprecision(30);
cin>>m;
d.resize(m);
c.resize(m);
rep(i,m){
cin>>d[i]>>c[i];
ma[d[i]] += c[i];
}
ll ans = 0;
while(ck()){
rep(i,10){
ll sum = 0;
if(i==0){
if(ma[i]<2)continue;
ans += ma[i]-1;
ma[i] = 1;
}else{
while(ma[i]>1){
if(ma[i]*i<10){
sum = ma[i]*i;
ans += ma[i]-1;
ma[i] = 0;
ma[sum]++;
}else{
ll tmp = 10/i;
if(10%i==0){
tmp--;
}
tmp++;
ll ret = ma[i]/tmp;
ma[i]%=tmp;
sum = tmp*i;
sum = sum%10 + sum/10;
ans += tmp*ret;
ma[sum]+=ret;
}
}
}
}
rep(i,10){
if(ma[i]==0)continue;
repi(j,i+1,10){
if(ma[i]==0)continue;
if(ma[j]==0)continue;
ll sum = i+j;
ans++;
if(sum>=10)ans++;
sum = sum/10 + sum%10;
ma[i]--;
ma[j]--;
ma[sum]++;
}
}
}
print(ans);
return 0;
} | #include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define fastcin() ios_base::sync_with_stdio(false); cin.tie(0)
using namespace std;
typedef pair<int, int> ii;
int Ceil(int a, int b) { return (a + b - 1) / b; }
int m;
signed main()
{
int s = 0, dig = 0;
cin >> m;
for(int i = 1; i <= m; i++)
{
int d, c; cin >> d >> c;
dig += c;
s += c * d;
}
cout << (dig - 1) + Ceil(s-9, 9);
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
long long N, K;
double P[200000];
int main(){
cin >> N >> K;
for(long long i = 0; i < N; i++) {
double p;
cin >> p;
P[i] = (1.0 + p)/2.0;
}
double ans = 0;
double sum = 0;
for(long long i = 0; i < K; i++) {
sum += P[i];
}
ans = sum;
for(long long i = K; i < N; i++) {
sum += P[i];
sum -= P[i-K];
ans = max(ans, sum);
}
printf("%.10f\n", ans);
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll Mod = 1000000007;
bool exists(vector<ll>& vec,ll x)
{
auto pos = lower_bound(vec.begin(),vec.end(),x);
if(pos == vec.end())return false;
return *pos == x;
}
void solve(ll N, ll M, vector<ll> A, vector<ll> B)
{
ll ans = 1;
sort(A.begin(),A.end());
sort(B.begin(),B.end());
ll empty = 0;
ll numrow=0,numcol=0;
for(ll x = M*N;x>=1;--x)
{
if(exists(A,x))
{
if(exists(B,x))
{
empty += numcol + numrow;
numcol++;
numrow++;
}else
{
empty += numcol - 1;
ans *= numcol;
ans %= Mod;
numrow++;
}
}else
{
if(exists(B,x))
{
empty += numrow - 1;
ans *= numrow;
ans %= Mod;
numcol++;
}else
{
if(empty <= 0)
{
cout<<0<<endl;
return;
}
ans *= empty;
empty--;
ans %= Mod;
}
}
}
cout<<ans<<endl;
}
int main()
{
ll N;
cin >> N;
ll M;
cin >> M;
vector<ll> A(N);
for(int i = 0 ; i < N ; i++)
{
cin >> A[i];
}
vector<ll> B(M);
for(int i = 0 ; i < M ; i++)
{
cin >> B[i];
}
solve(N, M, move(A), move(B));
return 0;
}
| 0 |
#include <iostream>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
double x1,y1,x2,y2;
scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
printf("%4lf\n",sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
return 0;
} | #include <iostream>
#include <math.h>
using namespace std;
class point{
public:
double x, y;
int set();
};
int point::set()
{
cin >> x >> y;
return 0;
}
int main()
{
point P1, P2;
P1.set();
P2.set();
cout << fixed << sqrt((P1.x - P2.x)*(P1.x - P2.x) + (P1.y - P2.y)*(P1.y - P2.y)) << endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
#define reg register
#define pr std::pair<int, int>
#define fi first
#define se second
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
#define Rep(i, n) rep(i, 1, n)
#define Lep(i, n) lep(i, 1, n)
#define IRep(i, n) irep(i, n, 1)
#define ILep(i, n) ilep(i, n, 1)
typedef long long ll;
typedef long double ld;
namespace modular {
const int MOD = 1000000007;
inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
inline int mul(int x, int y) { return 1LL * x * y % MOD; }
inline int qpow(int x, int y) {
int ans = 1;
for (; y; y >>= 1, x = mul(x, x))
if (y & 1) ans = mul(ans, x);
return ans;
}
}; // namespace modular
namespace Base {
template <typename Tp>
inline Tp input() {
Tp x = 0, y = 1;
char c = getchar();
while ((c < '0' || '9' < c) && c != EOF) {
if (c == '-') y = -1;
c = getchar();
}
if (c == EOF) return 0;
while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
return x *= y;
}
template <typename Tp>
inline void read(Tp &x) {
x = input<Tp>();
}
template <typename Tp>
inline void chmax(Tp &x, Tp y) {
x < y ? x = y : 0;
}
template <typename Tp>
inline void chmin(Tp &x, Tp y) {
x > y ? x = y : 0;
}
}; // namespace Base
using namespace Base;
/*----------------------------------------------------------------------------*/
#define MAX_N 507
#define MAX_M 1000007
int pri[MAX_M], tot;
bool check[MAX_M];
void sieve() {
int MX = 1000000;
rep(i, 2, MX) {
if (!check[i]) pri[++tot] = i;
if (tot > 1000) break;
rep(j, 1, tot) {
if (i * pri[j] > MX) break;
check[i * pri[j]] = true;
if (i % pri[j] == 0) break;
}
}
}
int N;
ll ans[MAX_N * 2][MAX_N * 2], num1[MAX_N * 2], num2[MAX_N * 2];
void solve() {
if (N == 2) {
puts("4 7");
puts("23 10");
return;
}
int cur = 0;
Rep(i, N) if (i + 1 & 1) num1[1 - i + N] = pri[++cur];
rep(i, 2, N) if (i + 1 & 1) num1[i - 1 + N] = pri[++cur];
rep(i, 2, N + N) if (i & 1) num2[i] = pri[++cur];
// rep(i, 1, N * 2 - 1) printf("%d ", num1[i]);
// puts("");
rep(i, 0, N + 1) {
rep(j, 0, N + 1) if (i + j & 1) {
ans[i][j] =
std::max(1LL, num1[i - j + N]) * std::max(1LL, num2[i + j]);
}
}
Rep(i, N) {
Rep(j, N) if (!(i + j & 1)) {
ans[i][j] = ans[i - 1][j] * ans[i + 1][j] + 1;
}
}
Rep(i, N) {
Rep(j, N) {
if (ans[i][j] > 1e15) exit(1);
printf("%lld ", ans[i][j]);
}
puts("");
}
}
int main() {
sieve();
read(N);
solve();
return 0;
}
| #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int pds=998244353;
const int N=1000086;
int q1[N+5],q2[N+5];
int Pow(int a,int b)
{
int ans=1;
for(;b;b>>=1,a=1ll*a*a%pds)
if(b&1) ans=1ll*ans*a%pds;
return ans;
}
void Init()
{
q1[0]=1;
for(int i=1;i<=N;i++)
q1[i]=1ll*q1[i-1]*i%pds;
q2[N]=Pow(q1[N],pds-2);
for(int i=N-1;i>=0;i--)
q2[i]=1ll*q2[i+1]*(i+1)%pds;
}
int C(const int &n,const int &m){return 1ll*q1[n]*q2[m]%pds*q2[n-m]%pds;}
int invC(const int &n,const int &m){return 1ll*q2[n]*q1[m]%pds*q1[n-m]%pds;}
int main()
{
int n,m;Init();
cin>>n>>m;
int t=min(n,m),ans=0;
for(int i=1;i<=t;i++)
{
ans=(ans+1ll*C(2*i,i)*C(n+m-2*i,n-i))%pds;
}
ans=1ll*ans*invC(n+m,n)%pds*q2[2]%pds;
cout<<(ans+max(n,m))%pds;
return 0;
} | 0 |
//Heaplax
//别让自己后悔
#include<bits/stdc++.h>
#define N 2005
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
while(ch=getchar(),ch<33);
if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
while(ch=getchar(),ch>33)x=x*10+ch-48;
if(fs)x=-x;
}
using namespace std;
int n,m,q,v[N][N],xe[N][N],ye[N][N];
char s[N][N];
int main()
{
re(n),re(m),re(q);
for(int i=1;i<=n;++i)
scanf("%s",s[i]+1);
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
{
v[i][j]=s[i][j]-'0'+v[i-1][j];
xe[i][j]=(s[i][j]=='1'&&s[i-1][j]=='1')+xe[i-1][j];
ye[i][j]=(s[i][j]=='1'&&s[i][j-1]=='1')+ye[i][j-1];
}
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
{
v[i][j]+=v[i][j-1];
xe[i][j]+=xe[i][j-1];
ye[i][j]+=ye[i-1][j];
}
for(int a,b,c,d;q--;)
{
re(a),re(b),re(c),re(d);
int ans=v[c][d]+v[a-1][b-1]-v[a-1][d]-v[c][b-1];
ans-=xe[c][d]-xe[a][d]-xe[c][b-1]+xe[a][b-1];
ans-=ye[c][d]-ye[a-1][d]-ye[c][b]+ye[a-1][b];
printf("%d\n",ans);
}
}
| #include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
bool a[2001][2001];
int res[2001][2001],v2[2001][2001],v1[2001][2001];
int main(){
IOS
int n,m,q;
cin>>n>>m>>q;
for(int i=1;i<=n;i++){
int cnt=0;
string s;
cin>>s;
for(int j=0;j<m;j++){
a[i][j+1]=s[j]-'0';
if(a[i][j+1]==1){
cnt++;
}
res[i][j+1]=cnt;
}
}
for(int i=1;i<=n;i++){
int cnt=0;
for(int j=1;j<=m;j++){
if(a[i][j]==1&&a[i][j-1]==1){
cnt++;
}
v1[i][j]=cnt;
}
}
for(int i=1;i<=m;i++){
int cnt=0;
for(int j=1;j<=n;j++){
if(a[j][i]==1&&a[j-1][i]==1){
cnt++;
}
v2[j][i]=cnt;
}
}
for(int i=1;i<=q;i++){
int x1,y1,x2,y2,r=0,v=0;
cin>>x1>>y1>>x2>>y2;
for(int j=y1;j<=y2;j++){
r+=v2[x2][j]-v2[x1][j];
}
for(int j=x1;j<=x2;j++){
r+=v1[j][y2]-v1[j][y1];
}
for(int j=x1;j<=x2;j++){
v+=res[j][y2]-res[j][y1-1];
}
cout<<v-r<<endl;
}
return 0;
}
/*
*/ | 1 |
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, r) for (int i = (l); i < (r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <class T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <class T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;
// Union-Find
struct UnionFind {
vector<int> par;
UnionFind(int N) : par(N, -1) { }
int root(int x) {
if (par[x] < 0) return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry) return;
if (par[rx] > par[ry]) swap(rx, ry);
par[rx] += par[ry];
par[ry] = rx;
}
bool same(int x, int y) {
return root(x) == root(y);
}
int size(int x) {
return -par[root(x)];
}
};
// Main Code
int main() {
int n, m;
cin >> n >> m;
UnionFind uf(2 * n);
vector<int> cnt(n, 0);
rep(i, m) {
int a, b;
cin >> a >> b;
--a; --b;
uf.unite(a, b + n); uf.unite(a + n, b);
++cnt[a]; ++cnt[b];
}
vector<int> siz(2 * n, 0);
rep(i, n, 2 * n) ++siz[uf.root(i)];
ll ans = 0;
rep(i, n) {
ans += (siz[uf.root(i)] - cnt[i]);
if (uf.same(i, n + i)) --ans;
}
cout << ans / 2 << "\n";
return 0;
}
| #include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
const int N=2e5+10;
int n,m;
int col[N];
vector <int> g[N];
int cnt[4];
bool flag=0;
void dfs(int x,int c){
col[x]=c;cnt[c]++;
for(int i=0;i<g[x].size();i++){
if(!col[g[x][i]]) dfs(g[x][i],3-c);
if(col[g[x][i]]==col[x]) flag=1;
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1,x,y;i<=m;i++){
scanf("%d%d",&x,&y);
g[x].push_back(y);
g[y].push_back(x);
}
for(int i=1;i<=n;i++)
if(!col[i]) dfs(i,1);
if(flag) printf("%lld\n",(long long)n*(n-1)/2-m);
else {
printf("%lld\n",(long long)cnt[1]*cnt[2]-m);
}
return 0;
} | 1 |
#include <bits/stdc++.h>
#define int long long
#define mod 998244353
#define foi(i,n) for(int i = 0; i < n ; ++i)
#define pi pair<int,int>
#define pb push_back
#define debug cout << "here" << endl;
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
int dp[100000];
int findProfit(int mask,int arr[16][16]){
int answer =0 ;
vector<int> points;
int ctr =0 ;
while(mask){
if(mask&1) points.pb(ctr);
ctr++;
mask = mask>>1;
}
for(int i = 0 ;i < points.size();i++){
for(int j = i+1 ; j < points.size();j++) answer += arr[points[i]][points[j]];
}
//for(auto y : points ) cout << y << " ";
//cout << endl;
return answer;
}
void init(int n,int arr[16][16]){
dp[0] = 0;
for(int i = 1 ; i <= (((1)<<n)-1) ; i++){
int answer = findProfit(i,arr);
for(int j = i-1 ; j>=0 ; j--){
if((j|i) == i) answer = max(answer , dp[j] + dp[(i^j)]);
}
dp[i] = answer;
}
}
int32_t main(){
memset(dp,0,sizeof(dp));
int n;
cin >> n;
int arr[16][16];
foi(i,n){
foi(j,n) cin >> arr[i][j] ;
}
init(n,arr);
cout << dp[((1LL)<<n)-1];
}
| #include<bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<=b;++i)
typedef long long ll;
using namespace std;
void File(){
freopen("AGC10D.in","r",stdin);
freopen("AGC10D.out","w",stdout);
}
const int maxn=1e5+10;
int n;
ll a[maxn],sum;
bool dfs(bool now){
REP(i,1,n)if(a[i]%2==1)--a[i];
ll d=a[1];
REP(i,1,n)d=__gcd(a[i],d);
int cnt=0; sum=0;
bool flag=0;
REP(i,1,n){
a[i]/=d;
sum+=a[i];
if(a[i]%2==1)++cnt;
if(a[i]==1)flag=1;
}
if(sum%2==0)return now^1;
if(sum%2==1 && (cnt>=2 || flag))return now;
return dfs(now^1);
}
int main(){
//File();
scanf("%d",&n);
REP(i,1,n){
scanf("%lld",&a[i]);
sum+=a[i];
}
if(n%2!=sum%2)puts("First");
else if(n%2==0 && sum%2==0)puts("Second");
else{
int cnt=0;
REP(i,1,n){
if(a[i]%2==1)++cnt;
if(cnt>=2 || a[i]==1){
puts("Second");
return 0;
}
}
if(dfs(1))puts("First");
else puts("Second");
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;
bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }
int main(void) {
int n, t;
cin >> n >> t;
int ans = 0, tnow, tpush, tbfr;
cin >> tbfr;
for(int in=1;in<n;in++) {
cin >> tpush;
if(tpush-tbfr<=t) ans += tpush-tbfr;
else ans += t;
tbfr = tpush;
}
ans += t;
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#define local
#ifdef local
#include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
#include <boost/multiprecision/cpp_int.hpp>
#endif
#define p std::pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define pi std::pair<int, int>
#define stdabs std::abs
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
#define npm next_permutation
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
ll extgcd(ll a, ll b, ll& x, ll& y);
ll nCr(ll n, ll r);
void stat();
template <typename T> T fact(T num);
constexpr ll mod = 1000000000 + 7;
int main()
{
stat();
ll n, t;
cin >> n >> t;
ull ans = 0,curtime=0;
vec<ll> v(n);
rep(i, n) { cin >> v[i]; }
rep(i,n-1){
curtime+=v[i];
ans+=min(t,abs(v[i+1]-v[i]));
}
cout<<ans+t<<endl;
return 0;
}
ll extgcd(ll a, ll b, ll& x, ll& y)
{
if (b == 0) {
x = 1, y = 0;
return a;
}
ll d = extgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
std::vector<bool> is_prime(N + 1);
for (unsigned ll i = 0; i <= N; i++) {
is_prime[i] = true;
}
std::vector<unsigned ll> P;
for (unsigned ll i = 2; i <= N; i++) {
if (is_prime[i]) {
for (unsigned ll j = 2 * i; j <= N; j += i) {
is_prime[j] = false;
}
P.emplace_back(i);
}
}
return P;
}
void stat(){
#ifdef local
rep(i, 2){std::cout << "local enable" << std::endl;
}
#endif
#ifdef hacks
rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}
ll nCr(ll n, ll r)
{
ll num = 1;
for (ll i = 1; i <= r; i++) {
num = num * (n - i + 1) / i;
}
return num;
}
template <typename T> T fact(T num)
{
if (num == 1) { return 1; }
return num * fact(num - 1);
}
| 1 |
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#define re register
const int MAXN=2e5+10;
int n,K,s[MAXN],a[MAXN],timee;
char fin[10010],*p1=fin,*p2=fin;
char getc()
{
return p1==p2&&(p2=(p1=fin)+fread(fin,1,10000,stdin),p1==p2)?EOF:*p1++;
}
int read()
{
re int x=0;
re char ch=0;
while(ch<'0'||ch>'9') ch=getc();
while('0'<=ch&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getc();
return x;
}
inline void insert(int x,int w)
{
for(;x<=n;x+=x&-x) s[x]+=w;
}
inline int query(int x)
{
re int res=0;
for(;x;x-=x&-x) res+=s[x];
return res;
}
int main()
{
//freopen("t2.out","w",stdout);
n=read();
K=read();
for(re int i=1;i<=n;i++) a[i]=read();
while(K--)
{
re bool flag=1;
memset(s,0,(n+5)*sizeof(int));
for(re int i=1;i<=n;i++) insert(std::max(1,i-a[i]),1),insert(std::min(n,i+a[i])+1,-1);
for(re int i=1;i<=n;i++) a[i]=query(i),flag&=(a[i]==n);
if(flag) break;
}
for(re int i=1;i<=n;i++) printf("%d ",a[i]);
printf("\n");
return 0;
}
/*
5 1
1 0 0 1 0
*/ | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<n; i++)
int main() {
int N, K;
cin >> N >> K;
vector<int> v(N);
rep(i, N) {
cin >> v.at(i);
}
int a=0, b=0, c=0, x, y, z;
rep(i, min(K,50)) {
vector<int> vv(N+1);
rep(j, N) {
x = v.at(j);
vv.at(max(j-x, 0)) += 1;
vv.at(min(j+x+1,N)) -= 1;
}
v.at(0) = vv.at(0);
rep1(j, N) {
v.at(j) = v.at(j-1) + vv.at(j);
}
}
rep(i, N) {
cout << v.at(i) << " ";
}
}
| 1 |
#include"bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const long long INF10=1e10+1,ID_MAX=20;
const long mod=(1e9)+7;
const long long INF18=1e18+1;
struct edge{
int to;
long cost;
};
void sort2array(double *a,long *b,long n){
for(int i=0;i<n;i++){
b[i]=i;
}
sort(b,b+n,[a](long i,long j)->bool {return a[i]<a[j];} );
}
//bを何回足せばaを超えるか(O(a/b))
int wtover(int a,int b){
if(a%b>0)return (a/b)+1;
else return a/b;
}
int bi_e[ID_MAX]={0};
//2進数表示したときの最高桁(O(log n))
int bi_max(long n){
int m=0;
for(m;(1<<m)<=n;m++);m=m-1;
return m;
}
//bi_eに二進数表示したやつを代入(O(log^2 n))
void bi_exs(long n){
memset(bi_e,0,sizeof(bi_e));
if(n<(1<<ID_MAX)){
for(int i=0;n>0;n=(n>>1),i++)bi_e[i]=n&1;
}
}
//x^n mod m (nが負の時は0)(O(log n))
long myPow(long x, long n, long m){
if(n<0)return 0;
if(n == 0)
return 1;
if(n % 2 == 0)
return myPow(x * x % m, n / 2, m);
else
return x * myPow(x, n - 1, m) % m;
}
//m以下のn以下の分割数のmodの表生成(O(nm))d[i][j]=jのi分割
long long d[10001][10001];
void divNum(int n,int m,long long md=mod){
rep(j,n+1){
d[j][0]=1;
}
rep(j,m){
d[0][j+1]=0;
}
for(int j=1;j<=n;j++){
for(int k=1;k<=m;k++){
if(j>k)d[j][k]=d[j-1][k];
else d[j][k]=(d[j-1][k]+d[j][k-j])%md;
}
}
}
const int N_MAX=1e5+1,M_MAX=1e9+1;
int n,m;
vector<int> a;
long long div_res[N_MAX][100];
void divide(int s,int t){
div_res[0][0]=1;
rep(i,s){
rep(j,t+1){
rep(k,t-j+1){
div_res[i+1][j+k]=(div_res[i+1][j+k]+div_res[i][j])%mod;
}
}
}
}
int main(){
int i=0,maxa=0;
//入力
cin>>n>>m;
int mm=m,x=2,r;
for(int j=2;j<=ceil(sqrt(m));j++){
r=0;
while(mm%j==0){
mm=mm/j;
r++;
}
if(r!=0){
if(maxa<r)maxa=r;
a.push_back(r);
}
}
if(mm!=1)a.push_back(1);
//処理
long long res=1;
divide(n,maxa);
rep(i,a.size()){
res=(res*div_res[n][a.at(i)])%mod;
}
//出力
cout<<res<<endl;
} | #include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) {
if (a < b) { a = b; return true; } return false;
}
template<class T> inline bool chmin(T& a, T b) {
if (a > b) { a = b; return true; } return false;
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
map<ll,ll> insuu;
ll n;
const int MAX = 700000;
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;
}
void prime_factor(ll n){
ll k=n;
for(ll i=2;i*i<=n;i++){
while(k%i==0){
insuu[i]++;
k/=i;
}
}
if(k!=1) insuu[k]=1;
return ;
}
int main(){
COMinit();
ll m;
cin>>n>>m;prime_factor(m);
ll ans=1;
ll k=n-1;
for(auto p:insuu){
ans*=COM(p.S+k,k);
ans%=MOD;
}
COUT(ans);
} | 1 |
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
double cosine = dot(a, b) / (leng(a) * leng(b));
double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
double kaku = acos(cosine);
if (sine <= 0) {
kaku = 2 * Ma_PI - kaku;
}
return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
vector<int> ans;
double now_minnest = a[0].real();
int now_itr = 0;
REP(i, a.size()) {
if (now_minnest > a[i].real()) {
now_minnest = a[i].real();
now_itr = i;
}
}
ans.push_back(now_itr);
complex<double> ba(0, 1);
while (true) {
int now_go = 0;
double now_min = 0;
int starter = ans[ans.size() - 1];
for (int i = 0; i < a.size(); ++i) {
if (i != starter) {
double goa = angles(ba, a[i] - a[starter]);
if (goa > now_min) {
now_min = goa;
now_go = i;
}
}
}
if (now_go == ans[0]) break;
ans.push_back(now_go);
ba = complex<double>(a[now_go] - a[starter]);
}
return ans;
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
vector<tuple<long long, long long, long long, long long>> inputs;
long long required_costs[300000] = {};
long long winning_value[300000] = {};
long long n, x;
long long solve(long long now, long long border) {
long long cost = winning_value[now] - required_costs[now];
if (border < now) {
cost -= x * get<3>(inputs[border]);
cost += get<1>(inputs[border]) * get<3>(inputs[border]);
cost -= get<1>(inputs[border]) * get<2>(inputs[border]);
}
return cost;
}
int main() {
iostream::sync_with_stdio(false);
#define int long long
cin >> n >> x;
REP(i, n) {
long long a, b, c;
cin >> a >> b >> c;
inputs.push_back(make_tuple(c * (x - a) + b * a, a, b, c));
}
sort(inputs.begin(), inputs.end());
reverse(inputs.begin(), inputs.end());
long long costing = 0;
REP(i, n) {
costing += get<1>(inputs[i]) * get<2>(inputs[i]);
}
long long bobo = 0;
REP(i, n + 1) {
required_costs[i] = costing;
winning_value[i] = bobo;
if (i < n) {
costing -= get<1>(inputs[i]) * get<2>(inputs[i]);
bobo += get<3>(inputs[i]) * (x - get<1>(inputs[i]));
}
}
long long ans = LONG_INF;
for (int i = 0; i < n; ++i) {
long long bot = 0;
long long top = n;
while (top - bot > 1) {
long long mid = (top + bot) / 2;
if (solve(mid, i) <= 0) {
bot = mid;
}
else {
top = mid;
}
}
long long bobo = solve(bot, i);
bobo *= -1;
long long pre_ans = bot * x;
if (i < bot) {
pre_ans -= x;
}
long long now = x + 1;
now = (bobo + get<2>(inputs[i]) - 1) / get<2>(inputs[i]);
if (now >= 0 && now <= x) {
ans = min(ans, pre_ans + now);
}
bobo += (get<3>(inputs[i]) - get<2>(inputs[i])) * get<1>(inputs[i]);
now = (bobo + get<3>(inputs[i]) - 1) / get<3>(inputs[i]);
if (now >= 0 && now <= x) {
ans = min(ans, pre_ans + now);
}
}
ans = min(ans, x * n);
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int N, T;
int64_t DP[3010][3010]; // i番目、t分後の最大値
void init()
{
for (int i = 0; i < 3010; i++)
for (int j = 0; j < 3010; j++)
DP[i][j] = -1;
DP[0][0] = 0;
}
int64_t ans()
{
int64_t ans = 0;
for (int j = 0; j <= T; j++)
ans = max(DP[N][j], ans);
return ans;
}
int main()
{
cin >> N >> T;
vector<pair<int, int>> ab(N);
for (int i = 0; i < N; i++)
{
cin >> ab[i].first >> ab[i].second;
}
sort(ab.begin(), ab.end());
for (int i = 0; i < N; i++)
{
for (int t = 0; t <= T; t++)
{
if (DP[i][t] == -1)
continue;
DP[i + 1][t] = max(DP[i + 1][t], DP[i][t]);
if (t < T)
{
DP[i + 1][min(t + ab[i].first, T)] = max(DP[i + 1][min(t + ab[i].first, T)], DP[i][t] + ab[i].second);
}
}
}
cout << ans() << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
int n ;
cin >> n ;
string s , t ;
cin >> s >> t ;
deque<char> S , T ;
rep(i,n){
S.push_back(s.at(i)) ;
T.push_back(t.at(i));
}
if(s == t ) {
cout << s.size() <<endl ;
return 0 ;
}
int ans = 2 * n ;
rep(i,n){
S.pop_front();
T.pop_back();
if( S == T){
ans = S.size() + 2*(i+1) ;
cout << ans <<endl ;
return 0 ;
}
}
}
| // agc006_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif
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;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#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, index=0;
string S,T;
cin>>N>>S>>T;
rep (i, N) {
if (S.substr(N-1-i) == T.substr(0, i+1)) {
index = i+1;
}
}
cout<<2*N-index<<endl;
return 0;
}
| 1 |
#include <iostream>
#include <vector>
#include <algorithm>
int main(){
int n, m, p, sum;
while(std::cin >> n >> m){
std::vector<int> price_list = {};
if(n == 0 && m == 0){
break;
} else{
sum = 0;
for(int i = 0;i < n;++i){
std::cin >> p;
price_list.push_back(p);
sum += p;
}
std::sort(price_list.begin(), price_list.end(), std::greater<int>());
for(int i = 1;i <= n/m;++i){
sum -= price_list.at(i * m - 1);
}
std::cout << sum << std::endl;
}
}
return 0;
}
| #include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n,m,sum;
int p[1010];
while(cin >> n >> m,n!=0&&m!=0){
for(int i=0;i<n;i++){
cin >> p[i];
}
sort(p,p+n);
reverse(p,p+n);
sum = 0;
for(int i=0;i<n;i++){
if( (i+1)%m != 0) sum += p[i];
}
cout << sum << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int d, g;
cin >> d >> g;
vector <int> p(d);
vector <int> c(d);
for(int i = 0; i < d; ++i) cin >> p[i] >> c[i];
int ans = 1e9;
for(int mask = 0; mask < (1 << d); ++mask){
int point = 0, num = 0, rest_max = -1;
for(int i = 0; i < d; ++i){
if(mask >> i & 1){
point += 100 * (i + 1) * p[i] + c[i];
num += p[i];
}else{
rest_max = i;
}
}
if(point < g){
int p1 = 100 * (rest_max + 1);
int need = (g - point + p1 - 1)/p1;
if(need >= p[rest_max])continue;
num+= need;
}
ans = min(ans, num);
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n ,k;
cin>>n>>k;
cout.precision(15);
double p[n];
for(int i=0;i<n;i++)
{
cin>>p[i];
p[i] = (p[i] + 1)/2;
}
double curr =0, ans =0 ;
for(int i=0;i<k;i++)
{
curr += p[i];
}
ans =max( ans, curr);
for(int i = k ;i< n ;i++)
{
curr = curr - p[i - k] + p[i];
ans = max( ans , curr);
}
printf("%.12f" , ans);
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, p;
while (cin >> n >> p, n) {
int m = 0, q = p, st[50] = {};
while (1) {
if (p == 0) {
p += st[m];
st[m] = 0;
} else {
p--;
st[m]++;
if (p == 0 && st[m] == q) {
break;
}
}
m = (m + 1) % n;
}
cout << m << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;
#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
typedef long long ll;
typedef long double ld;
typedef pair<ll, int> P;
typedef tuple<int, int, int> T;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
template<typename T, typename U>
size_t operator()(const pair<T, U> &x) const {
size_t seed = hash<T>()(x.first);
return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
}
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);
int n;
string s;
int num[3][4010]; // 0->R, 1->G, 2->B
ll solve() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
num[j][i+1] = num[j][i];
}
switch(s[i]) {
case 'R': num[0][i+1]++; break;
case 'G': num[1][i+1]++; break;
case 'B': num[2][i+1]++; break;
}
}
ll res = 0;
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
if (s[i] == s[j]) continue;
if ((s[i] == 'R' && s[j] == 'G') || (s[j] == 'R' && s[i] == 'G')) {
res += num[2][n] - num[2][j];
if (j + j - i < n && s[j+j-i] == 'B') res--;
} else if ((s[i] == 'B' && s[j] == 'G') || (s[j] == 'B' && s[i] == 'G')) {
res += num[0][n] - num[0][j];
if (j + j - i < n && s[j+j-i] == 'R') res--;
} else {
res += num[1][n] - num[1][j];
if (j + j - i < n && s[j+j-i] == 'G') res--;
}
}
}
return res;
}
void input() {
cin >> n >> s;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
input();
cout << solve() << endl;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
int main(void){
int a[4];
for(int i=0;i<4;i++) cin>>a[i];
int e,f;
cin>>e>>f;
sort(a,a+4,greater<int>());
if(e<f){
cout<<a[0]+a[1]+a[2]+f<<endl;
}
else{
cout<<a[0]+a[1]+a[2]+e<<endl;
}
return 0;
}
| #include <iostream>
using namespace std;
int main ()
{
int a[100],b[100],a1,a2,a3,b1;
a1 = 0;
a2 = 0;
a3 = 0;
b1 = 0;
for (int i = 0; i < 4; i++)
{
cin >> a[i];
}
for (int j = 0; j < 2; j++)
{
cin >> b[j];
}
for (int i = 0; i < 4; i++)
{
if (a[i] >= a1)
{
a3 = 0;
a3 = a2;
a2 = 0;
a2 = a1;
a1 = 0;
a1 = a[i];
}
else if (a[i] >= a2)
{
a3 = 0;
a3 = a2;
a2 = 0;
a2 = a[i];
}
else if (a[i] >= a3)
{
a3 = 0;
a3 = a[i];
}
}
for (int j = 0; j < 2; j++)
{
if (b1 < b[j])
{
b1 = 0;
b1 = b[j];
}
}
cout << a1 + a2 + a3 + b1 << endl;
} | 1 |
#include<iostream>
#include<vector>
using namespace std;
vector<int> v[10000], rev[10000], order, group(10000, 0);
vector<bool> vis(10000);
void dfs(int x){
vis[x] = true;
for(int j : v[x]){
if(!vis[j]) dfs(j);
}
order.push_back(x);
}
void rdfs(int x, int k){
group[x] = k;
vis[x] = true;
for(int j : rev[x]){
if(!vis[j]) rdfs(j, k);
}
}
int main(){
int n, m;
cin >> n >> m;
while(m--){
int s, t;
cin >> s >> t;
v[s].push_back(t);
rev[t].push_back(s);
}
fill(vis.begin(),vis.end(),0);
for(int i = 0; i < n; i++){
if(!vis[i]) dfs(i);
}
fill(vis.begin(),vis.end(),0);
int k = 0;
for(int i = order.size()-1; i >= 0; i--){
if(!vis[order[i]]) rdfs(order[i], k++);
}
int q;
cin >> q;
while(q--){
int u, v;
cin >> u >> v;
cout << (group[u]==group[v]) << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
map<int ,bool> AC;
map<int ,int> WA;
cin >> n >> m;
for (int i = 0; i < m; i++){
int no;
string res;
cin >> no >> res;
if (res == "AC") {
AC[no] = 1;
} else {
if (!AC.count(no)) {
WA[no]++;
}
}
}
int ac, wa;
ac = wa = 0;
for(auto m: AC){
int p;
p = m.second;
ac += p;
}
for(auto m: WA){
if (AC[m.first] == 1) {
wa += m.second;
}
}
cout << ac << " " << wa << endl;
} | 0 |
#include <iostream>
using namespace std;
typedef long long ll;
const ll M=1000005,mod=998244353;
ll F[M];
void Init(){
F[0]=1;
for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}
ll Pow(ll n,ll p){
ll r=1;
for(;p>0;p>>=1){
if(p&1) r=(r*n)%mod;
n=(n*n)%mod;
}
return r;
}
ll Div(ll n,ll m){
return n*Pow(m,mod-2)%mod;
}
ll nCk(ll n,ll k){
return Div(F[n],F[n-k]*F[k]%mod);
}
int n,m;
int main(){
Init();
cin>>n>>m;
if(n>m) swap(n,m);
ll t=0;
for(int i=0;i<n;i++) (t+=nCk(2*i+1,i)*nCk(n+m-2*i-2,n-i-1))%=mod;
cout<<(m+Div(t,nCk(n+m,n)))%mod<<endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll mod = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
{ cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
if (a < b)swap(a, b);
if (b == 0) return a;
unsigned r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a * b / g;
}
bool prime(ll n) {
for (ll i = 2; i <= sqrt(n); i++) {
if (n%i == 0)return false;
}
return n != 1;
}
int pow(int x, int y, int mod){
int ret=1;
for(;y;y>>=1,x=1ll*x*x%mod){
if(y&1) ret=1ll*ret*x%mod;
}
return ret;
}
int n = 3010, maxn = 3000;
ll fac[3010], inv[3010];
void init(){
fac[0]=1;
REP(i, 1, maxn+1)fac[i]=1ll*fac[i-1]*i%mod;
inv[maxn]=pow(fac[maxn], mod-2, mod);
REPR(j,maxn-1,-1)inv[j]=1ll*inv[j+1]*(j+1)%mod;
}
int main() {
sonic();
map<char, string> mp;
R mp['a'] >> mp['b'] >> mp['c'];
char pre = 'a', nxt;
while(mp[pre]!=""){
nxt=mp[pre][0];
mp[pre]=mp[pre].substr(1, mp[pre].length());
pre=nxt;
}
pre-=32;
co(pre);
}
| 0 |
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
//////////////////////////////////////////////////
// Range Query - RMQ and RUQ with Lazy Segment Tree
// https://www.slideshare.net/iwiwi/ss-3578491
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_F&lang=jp
struct LazySegmentTree{
// for vertex n
// par (n-1)/2
// chi 2n+1,2n+2
// index i
// bottom vertex n+i-1
const int NONNUM = -1; //ありえない数字
int segn2; // imply actually vertex number
vector<ll> data,lazy;
LazySegmentTree(int n){
segn2=1;
while(segn2<n) segn2*=2; //必要分2^Mを取る
data.resize(segn2*2,INT_MAX);
lazy.resize(segn2*2,NONNUM);
}
//lazy_propagate -- lazy[v] = xはvの表す区間がxに変更されることを表す.
inline void eval(int k,int l,int r){
if (lazy[k] != NONNUM){ // lazy nonzero
data[k] = lazy[k]; // itself
if (r-l > 1){
lazy[2*k+1] = lazy[k];
lazy[2*k+2] = lazy[k];
}
lazy[k] = NONNUM;
}
}
ll query(int a,int b,int l=0,int r=-1,int k=0){
if(r<0) r=segn2; // when calling function at first
if (r <= a || b <= l) return INT_MAX; //disjoint
eval(k,l,r);
if (a <= l && r <= b) return data[k]; //include
ll vl = query(a,b,l,(l+r)/2,k*2+1);
ll vr = query(a,b,(l+r)/2,r,k*2+2);
return min(vl,vr);
}
void update(int a,int b ,ll x, int l = 0, int r=-1,int k = 0){
if(r==-1) r=segn2;
eval(k,l,r);
if (b <= l || r <= a) return;
if (a <= l && r <= b){
lazy[k] = x;
eval(k,l,r);
return;
}else{
//一部のみ含むとき,子ノードを計算してその結果をもらう
update(a,b,x,l,(l+r)/2,2*k+1);
update(a,b,x,(l+r)/2,r,2*k+2);
data[k] = min(data[2*k+1] , data[2*k+2]);
}
}
};
// 0-indexed
// sum [s,t) --> s,t+1
// update [s,t,x) --> s,t+1,x
int main(){
int N,q;
SCD2(N,q);
LazySegmentTree seg(N);
REP(i,q){
int d; SCD(d);
if (d==0){
int s,t,x;
SCD3(s,t,x);
seg.update(s,t+1,(ll)x);
}else{
int s,t; SCD(s);
PRINTLLD(seg.query(s,s+1));
}
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
int Q;
cin >> Q;
for (int q = 0; q < Q; q++) {
int k;
cin >> k;
long long cnt_D = 0, cnt_M = 0, cnt_DM = 0, cnt_DMC = 0;
for (int i = 0; i < n; i++) {
if (s.at(i) == 'D') cnt_D++;
else if (s.at(i) == 'M') {
cnt_M++;
cnt_DM += cnt_D;
}
else if (s.at(i) == 'C') cnt_DMC += cnt_DM;
if (k - 1 <= i) {
if (s.at(i - k + 1) == 'D') {
cnt_D--;
cnt_DM -= cnt_M;
}
else if (s.at(i - k + 1) == 'M') cnt_M--;
}
}
cout << cnt_DMC << endl;
}
} | 0 |
/**
* author: boutarou
* created: 10.06.2020 20:12:43
**/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const long long MOD = 1e9 + 7;
const long long INF = 3e18;
const double PI = 3.1415926535897932;
int n;
vector<P> a, b;
int ans = 0;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
rep(i, n) {
int x, y;
cin >> x >> y;
a.push_back({x, y});
}
rep(i, n) {
int x, y;
cin >> x >> y;
b.push_back({x, y});
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
rep(i, n) {
int now_x = b[i].first, now_y = b[i].second;
int ma_y = -1;
rep(j, n) {
if (a[j].first > now_x) break;
if (a[j].second < now_y) {
chmax(ma_y, a[j].second);
}
}
if (ma_y == -1) continue;
ans++;
rep(j, n) {
if (a[j].second == ma_y) {
a.erase(a.begin() + j);
}
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n,m;
cin >> n;
vector<string> s(n);
for(int i=0; i<n;i++){
cin >> s.at(i);
}
cin >> m;
vector<string> t(m);
for(int i=0; i<m; i++){
cin >> t.at(i);
}
int i;
int sum=1,ans=0;
vector<string> u;
for(i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(s.at(i) == s.at(j)){
sum++;
}
}
for(int l=0;l<m;l++){
if(s.at(i)==t.at(l)){
sum--;
}
}
if(ans<sum){
ans = sum;
//u=s.at(i);
}
sum=1;
}
cout << ans << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
vector< int64_t > divisor(int64_t n) {
vector< int64_t > ret;
for(int64_t i = 1; i * i <= n; i++) {
if(n % i == 0) {
ret.push_back(i);
if(i * i != n) ret.push_back(n / i);
}
}
return (ret);
}
int main(){
cin.tie(0); ios::sync_with_stdio(false);
int64_t n,a,b,c; cin>>n>>a>>b; if(n==3)cin>>c;
vector<int64_t> v;
for(auto t:divisor(a))if(!(b%t))v.push_back(t);
if(n==3)for(auto t:v)if(c%t)v.erase(find(v.begin(),v.end(),t));
sort(v.begin(),v.end());
for(auto t:v)cout<<t<<'\n';
}
| #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<int> yakusu(int d){
vector<int> res;
for(int i=1; i*i <= d; i++){
if(d % i == 0) {
res.push_back(i);
if(i*i != d) res.push_back(d / i);
}
}
sort(res.begin(), res.end());
return res;
}
int gcd(int a, int b){
if(b == 0) return a;
return gcd(b, a % b);
}
int gcd(int* a, int n){
if(n == 2) return gcd(a[0], a[1]);
int b[n-1];
for(int i=0; i<n-1; i++){
b[i] = gcd(a[i], a[i+1]);
}
return gcd(b, n-1);
}
int main(){
int n; cin >> n;
int a[n];
for(int i=0; i<n; i++) cin >> a[i];
int g = gcd(a, n);
for(const auto& x : yakusu(g)){
cout << x << endl;
}
return 0;
}
| 1 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
#define FOR(i,n) for(int i = 0; i < n; i++)
#define FORa(i,a,b) for(int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a,n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define UP(s) transform(s.begin(),s.end(),s.begin(),::toupper)
//-------------------------------------------------------//
int main() {
int x;
cin >> x;
cout << x/500*1000 + (x-x/500*500)/5*5 << endl;
return 0;
} | #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
using namespace std;
template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }
int main(){
int n;
cin >> n;
cout << n / 3 << '\n';
return 0;
} | 0 |
#include <vector>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int m = 1e9;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
m = min(__builtin_ctz(a), m);
}
cout << m << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> A(N), B(N);
for (int i = 0; i < N; i++) cin >> A.at(i);
int min_count = 0;
int x0 = A.at(0);
while (x0 % 2 == 0) {
min_count++;
x0 = x0 / 2;
}
for (int x : A) {
int count = 0;
while (x % 2 == 0) {
count++;
x = x / 2;
}
min_count = min (min_count, count);
}
cout << min_count << endl;
}
| 1 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
using P = complex<double>;
using lli = long long int;
using T = lli;
bool cmp_x(const P& p, const P& q)
{
if (p.real() != q.real())
return p.real() < q.real();
return p.imag() < q.imag();
}
T dot(P a, P b)
{
//内積
return (conj(a) * b).real();
}
T cross(P a, P b)
{
//det
return (conj(a) * b).imag();
}
vector<P> convex_hull(P* ps, int n)
{
sort(ps, ps + n, cmp_x);
int k = 0;
vector<P> qs(n * 2);
rep(i, n)
{
while (k > 1 && cross((qs[k - 1] - qs[k - 2]), (ps[i] - qs[k - 1])) <= 0)
k--;
qs[k++] = ps[i];
}
for (int i = n - 2, t = k; i >= 0; i--) {
while (k > t && cross((qs[k - 1] - qs[k - 2]), (ps[i] - qs[k - 1])) <= 0)
k--;
qs[k++] = ps[i];
}
qs.resize(k - 1);
return qs;
}
P x[100005];
int main()
{
int n;
cin >> n;
T a, b;
map<lli,map<lli,int>> idx;
map<lli,map<lli,int>> prev;
vector<P> Y;
rep(i, n)
{
cin >> a >> b;
x[i] = P(a, b);
Y.push_back(x[i]);
prev[a][b] = i;
}
vector<P> con = convex_hull(x, n);
if(n==2){
cout << 0.5 << "\n" << 0.5 << endl;
return 0;
}
int cnt = 0;
for(auto s:con)
{
idx[s.imag()][s.real()] = cnt++;
}
int k = con.size();
vector<double> ans ;
rep(i,n){
if(idx[Y[i].imag()].find(Y[i].real())==idx[Y[i].imag()].end()){
ans.push_back(0.0);
continue;
}
int id = idx[Y[i].imag()][Y[i].real()];
P l = con[(id-1+k)%k];
P c = Y[i];
P r = con[(id+1+k)%k];
using Pd = complex<double>;
Pd l_c = (l+c);l_c/=2.0;
Pd r_c = (r+c);r_c/=2.0;
double rad = M_PI - abs(arg((r_c - c) / (l_c - c)));
ans.push_back(rad);
}
double total = 0.0;
rep(i,n)total += ans[i];
rep(i,n){
printf("%.10f\n",ans[i]/total);
}
}
| #include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
using namespace std;
int g[100005];
int F(int x)
{
return g[x]==x?g[x]:g[x]=F(g[x]);
}
void U(int x,int y)
{
g[F(x)]=F(y);
}
int n;
pair <pair<int,int>,int> a[100005];
vector <pair<int,pair<int,int> > > v;
long long ans=0;
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d%d",&a[i].first.first,&a[i].first.second);
a[i].second=i;
g[i]=i;
}
sort(a,a+n);
for(int i=0;i<n-1;i++)
v.push_back(make_pair(a[i+1].first.first-a[i].first.first,
make_pair(a[i].second,a[i+1].second)));
for(int i=0;i<n;i++)
swap(a[i].first.first,a[i].first.second);
sort(a,a+n);
for(int i=0;i<n-1;i++)
v.push_back(make_pair(a[i+1].first.first-a[i].first.first,
make_pair(a[i].second,a[i+1].second)));
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++)
{
int k22=v[i].second.second;
int k21=v[i].second.first;
//cout<<v[i].first<<' '<<k21<<' '<<k22<<endl;
int aaa=F(k21),bbb=F(k22);
//cout<<k21<<':'<<aaa<<' '<<k22<<':'<<bbb<<endl;
if(aaa==bbb)
;
else
{
//cout<<aaa<<' '<<bbb<<endl;
U(k21,k22);
ans+=v[i].first;
//cout<<v[i].first<<endl;
}
}
cout<<ans;
return 0;
} | 0 |
#include<cstdio>
#define C(x,y) (fct[x]*ifct[y]%TT*ifct[(x)-(y)]%TT)
using namespace std;
const int maxn=2005,TT=1e9+7;
int n,K,m,F[maxn][maxn];
long long fct[maxn*maxn],ifct[maxn*maxn];
inline int read(){
int ret=0;bool f=0;char ch=getchar();
while(ch>'9'||ch<'0') f^=ch=='-',ch=getchar();
while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=getchar();
return f?-ret:ret;
}
inline long long pow(int x,int y){
long long ret=1,w=x;
while(1){
if(y&1) ret=ret*w%TT;
if(!(y>>=1)) return ret;
w=w*w%TT;
}
}
inline void add(int&x,int y){if((x+=y)>=TT) x-=TT;}
int main(){
n=read(),K=read();m=n*K;
if(K==1) return puts("1")&0;
for (int i=fct[0]=1;i<=m;i++) fct[i]=fct[i-1]*i%TT;
ifct[m]=pow(fct[m],TT-2);
for (int i=m;i;i--) ifct[i-1]=ifct[i]*i%TT;
F[0][0]=1;
for (int i=1;i<=n;i++)
for (int j=0;j<=i;j++){
if(j<i) add(F[i][j],F[i-1][j]);
if(j) add(F[i][j],C(m-i-(j-1)*(K-1)-1,K-2)*F[i][j-1]%TT);
}
printf("%lld\n",fct[n]*F[n][n]%TT);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD=1000000007;
int n,k;
LL fac[4000000],inv_fac[4000000],dp[2001];
void check_mod(LL &a) { if (a>=MOD) a%=MOD; }
int ksm(LL a, int b)
{
LL ret=1ll;
while (b) {
if (b&1) ret*=a;
check_mod(ret);
a*=a;
check_mod(a);
b>>=1;
}
return ret;
}
int main()
{
LL lt;
int t;
scanf("%d%d",&n,&k);
if (k==1) {
printf("1\n");
return 0;
}
fac[0]=1;
t=n*k;
for (int i = 1; i < t; ++i) {
fac[i]=1ll*i*fac[i - 1];
check_mod(fac[i]);
}
inv_fac[t-1]=ksm(fac[t-1],MOD-2);
for (int i=t-2;i;--i) {
inv_fac[i]=1ll*(i+1)*inv_fac[i+1];
check_mod(inv_fac[i]);
}
inv_fac[0]=1;
dp[0]=1;
t=-2;
for (int i=1;i<=n;++i) {
t+=k-1;
for (int j=0;j<=i;++j) {
++t;
lt=fac[t]*inv_fac[t-k+2];
check_mod(lt);
lt*=inv_fac[k-2];
check_mod(lt);
dp[j]*=lt;
if (j) dp[j]+=dp[j - 1];
check_mod(dp[j]);
}
t-=i+1;
}
printf("%lld\n",dp[n]*fac[n]%MOD);
return 0;
} | 1 |
#include <stdio.h>
int a[1000000];
long long int ans=0;
void mergesort(int l,int r){
if(l==r)return;
if(l==r-1){
if(a[r]<a[l]){
int temp;
temp=a[l];
a[l]=a[r];
a[r]=temp;
ans++;
}
return;
}
int mid=(l+r)/2,now=0,b[r-l+1];
mergesort(l,mid-1);
mergesort(mid,r);
for(int i=0;i<=r-l;i++){
if(a[l+i-now]<a[mid+now]){
b[i]=a[i+l-now];
if(i+l-now==mid-1){
for(i++;i<=r-l;i++)b[i]=a[i+l];
}
}
else{
ans+=mid-i+now-l;
b[i]=a[mid+now];
now++;
if(mid+now>r){
for(i++;i<=r-l;i++){
b[i]=a[i+l-now];
}
}
}
}
for(int i=0;i<=r-l;i++)a[i+l]=b[i];
}
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)scanf("%d",&a[i]);
mergesort(0,n-1);
printf("%lld\n",ans);
} | /* * * * * * * * * * * **
* *
* saurabh8522 *
* I will handle *
* IT. *
* *
* * * * * * * * * * * **/
#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a),0,sizeof((a)))
#define one(a) memset((a),1,sizeof((a)))
#define minus(a) memset((a),-1,sizeof((a)))
#define all(g) g.begin(),g.end()
#define ppb pop_back
using namespace std;
typedef long long int ll;
#define MOD 1000000007
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll numdigit(ll n){return floor(log10(n)) + 1;}
bool isPowerTwo (ll x) { return x && (!(x&(x-1))); }
const ll INF=1e16;
vector<ll>v(200005,-INF);
ll dp[200005][2][2];
bool vis[200005][2][2];
ll n;
ll find(ll pos,ll flag1,ll flag2){
// cout<<pos<<" "<<flag1<<" "<<flag2<<endl;
if(pos>=n) return 0ll;
ll &ans=dp[pos][flag1][flag2];
if(vis[pos][flag1][flag2]) return ans;
vis[pos][flag1][flag2]=1;
if(flag2==0){
if(pos==n-3){
if(flag1==0) return ans=max(v[pos],max(v[pos+1],v[pos+2]));
else return ans=max(v[pos+1],v[pos+2]);
}
if(flag1==0){
ll ans1=find(pos+2,0ll,1ll);
ll ans2=v[pos]+find(pos+2,0ll,0ll);
ll ans3=v[pos+1]+find(pos+2,1ll,0ll);
ans=max(ans1,max(ans2,ans3));
}
else{
ll ans1=find(pos+2,0ll,1ll);
ll ans2=v[pos+1]+find(pos+2,1ll,0ll);
ans=max(ans1,ans2);
}
}
else{
if(flag1==0){
ll ans1=v[pos]+find(pos+2,0ll,1ll);
ll ans2=v[pos+1]+find(pos+2,1ll,1ll);
ans=max(ans1,ans2);
}
else{
ans=v[pos+1]+find(pos+2,1ll,1ll);
}
}
// cout<<pos<<" "<<flag1<<" "<<flag2<<" "<<ans<<endl;
return ans;
}
int main(){
FastRead;
ll t=1;
while(t--){
cin>>n;
for(ll i=0;i<n;i++){
cin>>v[i];
}
for(ll i=0;i<n;i++){
vis[i][0][0]=vis[i][0][1]=0;
vis[i][1][0]=vis[i][1][1]=0;
}
if(n&1){
cout<<find(0,0ll,0ll)<<endl;
}
else{
cout<<find(0,0ll,1ll)<<endl;
}
}
} | 0 |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;
struct UnionFind {
vector< int > data;
UnionFind(int sz) {
data.assign(sz, -1);
}
bool unite(int x, int y) {
x = find(x), y = find(y);
if(x == y) return (false);
if(data[x] > data[y]) swap(x, y);
data[x] += data[y];
data[y] = x;
return (true);
}
int find(int k) {
if(data[k] < 0) return (k);
return (data[k] = find(data[k]));
}
int size(int k) {
return (-data[find(k)]);
}
};
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
ll n, m; cin >> n >> m;
UnionFind uf(2 * n);
rep (i, m) {
int a, b; cin >> a >> b; a--; b--;
uf.unite(2 * a, 2 * b + 1);
uf.unite(2 * b, 2 * a + 1);
}
if (uf.find(0) != uf.find(1)) {
ll x[2] = {};
rep (i, n) x[(uf.find(2 * i) != uf.find(0))]++;
eprintf("%lld %lld\n", x[0], x[1]);
cout << x[0] * x[1] - m << "\n";
} else {
cout << n * (n - 1) / 2 - m << "\n";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
int MX = 100005;
vector<int> parents(MX);
vector<int> in(MX);
vector<vector<int>> tree(MX,vector<int>());
int main() {
int n,m;
cin >> n >> m;
rep(i,n-1+m){
int a,b;
cin >> a >> b;
--a; --b;
tree.at(a).push_back(b);
in.at(b) ++;
}
int parent = 0;
rep(i,n){
if(in.at(i) == 0){
parent = i;
break;
}
}
parents.at(parent) = -1;
queue<int> q;
q.push(parent);
while(!q.empty()){
int now = q.front();
q.pop();
for(auto i:tree.at(now)){
in.at(i) --;
if(in.at(i) == 0){
parents.at(i) = now;
q.push(i);
}
}
}
rep(i,n) cout << parents.at(i)+1 << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second
using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD=1000000007;
int INF=100100100100100;
int a[100010];
signed main(){
int n;cin>>n;
ivec dp(n+1,INF);
rep(i,n)cin>>a[n-1-i];
rep(i,n){
*lower_bound(all(dp),a[i]+1)=a[i];
}
cout<<lower_bound(all(dp),INF)-dp.begin()<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,¬(a=b=0)*/
while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;
/*--------------------------------------------------------------------*/
signed main(){
int n;
cin>>n;
int a[17];
int x[17][17];
int y[17][17];
rep(i,n){
cin>>a[i];
rep(j,a[i]){
cin>>x[i][j]>>y[i][j];
}
}
int ans=0;
rep(bit,1<<n){
int shoujiki[17];
rep(i,n){
if(bit&(1<<i)) shoujiki[i]=1;
else shoujiki[i]=0;
}
int to[17][17];
int ok=1;
rep(i,n){
if(shoujiki[i]){
rep(j,a[i]){
if(y[i][j]){
if(shoujiki[x[i][j]-1]==0) ok=0;
}else{
if(shoujiki[x[i][j]-1]==1) ok=0;
}
}
}
}
if(ok){
int cnt=0;
rep(i,n){
if(shoujiki[i]==1) cnt++;
}
chmax(ans,cnt);
}
}
cout<<ans<<endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
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 gcd(int a,int b){return b?gcd(b,a%b):a;}
int main(){
ll n;
cin >> n;
string a, b, c;
cin >> a >> b >> c;
ll ans = 0;
rep(i,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]){
ans += 2;
}
else{
ans++;
}
}
print(ans);
} | #define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,b) for(ll i=(b)-1; i>=a; --i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define scanv(n,v) v.resize(n); rep(i,n){ cin>>v[i];}
#define MOD 1000000007ll
#define Yes(flag) cout<<((flag)? "Yes":"No");
#define YES(flag) cout<<((flag)? "YES":"NO");
#define be begin
#define pb push_back
#define fi first
#define se second
#define square(x) x*x
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
template<class T>T
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
//------------------------------------------------------
int eq(char a,char b,char c){
vector<char> k{a,b,c};
sort(ALL(k));
return distance(k.begin(),unique(ALL(k)))-1;
}
int n;
string a,b,c;
void input(){
cin>>n>>a>>b>>c;
}
void src(){
int ans=0;
rep(i,n){
ans+=eq(a[i],b[i],c[i]);
}
cout<<ans;
}
int main(int argc,char* argv[]){
ios::sync_with_stdio(false);
// ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
input();
src();
} | 1 |
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const ll MAXN = (ll)2e3+10;
const ll DIV = (ll)1e9+7;
int main(void) {
ll N;
cin>>N;
string S;
cin>>S;
vector<int> ar(2*N);
if (S[0]=='W' || S[2*N-1]=='W') {
cout<<0<<endl;
return 0;
}
ar[0] = 1;
ar[2*N-1] = -1;
rep(i,1,2*N) {
if (S[i] == S[i-1]) {
if (ar[i-1]==1) ar[i]=-1;
else ar[i]=1;
} else {
if (ar[i-1]==1) ar[i] = 1;
else ar[i] = -1;
}
}
// rep(i,0,2*N) cout<<ar[i]<<endl;
ll sum = 0;
rep(i,0,2*N) sum+=ar[i];
if (sum!=0) {
cout<<0<<endl;
return 0;
}
ll ans = 1;
ll tmp = 0;
for(int i = 2*N-1;i>=0;i--) {
if (ar[i]==-1) {
tmp++;
} else {
ans *= tmp;
ans = ans%DIV;
tmp--;
}
}
// cout<<ans<<endl;
rep(i,1,N+1) {
ans *= i;
ans = ans%DIV;
}
cout<<ans<<endl;
return 0;
} | #include <iostream>
#include <string>
using namespace std;
const int MOD = 1000000007;
int solve(const string& s){
const int N = s.size()/2;
long long res = 1;
int numS = 0, sumS = 0, inc = 0;
for(auto& c : s){
if(c == 'B'){
if(inc%2 == 0){
++inc;
++numS;
++sumS;
} else {
if(numS == 0) return 0;
--inc;
res = (res * numS) % MOD;
--numS;
}
} else {
if(inc%2 == 0){
if(numS == 0) return 0;
--inc;
res = (res * numS) % MOD;
--numS;
} else {
++inc;
++numS;
++sumS;
}
}
}
if(sumS != N) return 0;
for(int i=1;i<=N;i++) res = (res*i)%MOD;
return res;
}
int main(){
int N;
while(cin >> N){
string s; cin >> s;
cout << solve(s) << endl;
}
} | 1 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <limits>
using namespace std;
long long N;
map<long long, long long> mp;
int main(int argc, char* argv[]){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N ;
for(int i=0; i<N; i++){
long long a;
cin >> a;
if(mp.count(a)==0){
mp[a] = 1;
}
else{
mp[a]++;
}
}
vector<pair<long long, long long>> v;
for(auto itr = mp.begin(); itr != mp.end(); itr++){
long long k = itr->first;
long long u = itr->second;
v.push_back(make_pair(k, u));
}
sort(v.begin(), v.end());
int found = 0;
long long ans = 0;
for(int i=v.size()-1; i>=0; i--){
if(v[i].second < 2) continue;
if(v[i].second >=4){
if(found == 2){
ans = ans*(v[i].first);
}
else{
ans = (v[i].first)*(v[i].first);
}
found = 4;
break;
}
if(v[i].second == 2 || v[i].second == 3){
found += 2;
if(found == 4){
ans = ans * v[i].first;
break;
}
else{
ans = v[i].first;
}
}
}
if(found < 4) ans = 0;
printf("%lld\n", ans);
return 0;
} | #include <bits/stdc++.h>
#define nl '\n'
using namespace std;
typedef long long ll;
void solve() {
int N;
cin >> N;
int A[N];
for (int& i: A) cin >> i;
ll ans = 0;
const int mod = 1e9 + 7;
int suff[N] = {0};
suff[N - 1] = A[N - 1];
for (int i = N - 2; i >= 0; i--)
suff[i] = (A[i] + suff[i + 1]) % mod;
for (int i = 0; i < N - 1; i++) ans = (ans + (1ll * A[i] * suff[i + 1]) % mod) % mod;
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// int t;
// cin >> t;
// while (t--) {
solve();
// cout << nl;
// }
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int h,w;
cin >> h >> w;
int ans=(n-h+1)*(n-w+1);
cout << ans << endl;
return 0;
}
| #include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
string S; cin >> S;
int ans = 1000;
rep(i,S.size()-2) {
int t = int(S[i]-48) * 100 + int(S[i+1]-48) * 10 + int(S[i+2]-48);
ans = min(ans, abs(t - 753));
}
cout << ans << endl;
return 0;
} | 0 |
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#define MAX 10000
#define INFTY 1<<30 // 2^30
#define N 8
using namespace std;
typedef long long llong;
static const int NIL = -1;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int NOT_FREE = 0;
static const int FREE = 1;
static const int FIXED = 2;
bool X[N][N];
vector<pair<int, int> > ans;
void init()
{
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
X[i][j] = false;
}
bool can_pos(int x, int y)
{
for(int i = 0; i < ans.size(); i++)
{
int tx = ans[i].first;
int ty = ans[i].second;
if(x == tx) return false;
if(y == ty) return false;
if((x-tx)*(x-tx) == (y-ty)*(y-ty)) return false;
}
return true;
}
void printBoard()
{
for(int i = 0; i < ans.size(); i++)
X[ans[i].first][ans[i].second] = true;
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
cout << (X[i][j] ? "Q" : ".");
cout << endl;
}
}
bool recursive(int p)
{
for(; p < N * N; p++)
{
int i = p%N;
int j = p/N;
if(!(can_pos(i,j))) continue;
pair<int, int>tmp = make_pair(i, j);
ans.push_back(tmp);
if(!recursive((j+1)*N)) ans.pop_back();
}
if(ans.size() == N) return true;
return false;
}
int main()
{
init();
int k, r, c; cin >> k;
for(int i = 0; i < k; i++)
{
cin >> r >> c;
pair<int, int> tmp = make_pair(r, c);
ans.push_back(tmp);
}
if(recursive(0)) printBoard();
return 0;
} | #include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
const char Q = 'Q';
const char _ = '.';
char board[8][9] = {
"........",
"........",
"........",
"........",
"........",
"........",
"........",
"........",
};
int n;
bool pre_x[8], pre_y[8];
inline bool check(int x, int y) {
int p = x, q = y;
while (--p >= 0 && --q >= 0) { // upper left
if (board[q][p] == Q) return false;
}
p = x; q = y;
while (++p < 8 && --q >= 0) { // upper right
if (board[q][p] == Q) return false;
}
p = x; q = y;
while (++p < 8 && ++q < 8) { // lower right
if (board[q][p] == Q) return false;
}
p = x; q = y;
while (--p >= 0 && ++q < 8) { // lower left
if (board[q][p] == Q) return false;
}
return true;
}
bool solve(int row) {
if (row == 8)
return true;
if (pre_y[row] && solve(row + 1)) {
return true;
}
else {
for (int i = 0; i < 8; ++i) {
if (!pre_x[i] && check(i, row)) {
board[row][i] = Q;
pre_x[i] = true;
if (solve(row + 1)) {
return true;
}
else {
board[row][i] = _;
pre_x[i] = false;
}
}
}
}
return false;
}
int main(void) {
scanf("%d", &n);
for (int i = 0, x, y; i < n; ++i) {
scanf("%d %d", &y, &x);
board[y][x] = Q;
pre_y[y] = pre_x[x] = true;
}
solve(0);
for (int i = 0; i < 8; ++i) {
printf("%s\n", board[i]);
}
return 0;
} | 1 |
#include<algorithm>
#include<cstdio>
#define s(A) std::sort(A,A+10);
main(){
int Z[20],p;
for(int i=0;i<20;i++)
scanf("%d",&p),Z[i]=p;
s(Z);
s(Z+10);
printf("%d %d\n",Z[7]+Z[8]+Z[9],Z[17]+Z[18]+Z[19]);
} | #include <cstdio>
#include <algorithm>
#include <string>
#include <iostream>
#define inf 1001001001
using namespace std;
int n, c;
size_t s, t, dp[1001][1001];
string a, b;
int main() {
cin >> a >> b;
s = a.length(), t = b.length();
for (size_t i = 1; i <= s; ++i) dp[i][0] = i;
for (size_t i = 1; i <= t; ++i) dp[0][i] = i;
for (size_t i = 0; i < s; ++i) {
for (size_t j = 0; j < t; ++j) {
if (a[i]==b[j]) c = 0; else c = 1;
dp[i+1][j+1] = min(dp[i][j+1]+1, dp[i+1][j]+1);
dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]+c);
}
}
printf("%ld\n", dp[s][t]);
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
int main() {
int N, ans = 0;
string A, B, C;
cin >> N >> A >> B >> C;
for (int i = 0; i < N; i++){
set<char> T;
T.insert(A.at(i));
T.insert(B.at(i));
T.insert(C.at(i));
if (T.size() == 2){
ans++;
}
else if (T.size() == 3){
ans += 2;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int main(){
// 1. 入力情報.
int N;
char A[111], B[111], C[111];
scanf("%d %s %s %s", &N, A, B, C);
// 2. 操作回数を保存.
int ans = 0;
rep(i, N){
set<char> s;
s.insert(A[i]);
s.insert(B[i]);
s.insert(C[i]);
ans += s.size() - 1;
}
// 3. 出力.
printf("%d\n", ans);
return 0;
} | 1 |
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
int f=1;char k=getchar();x=0;
for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
for(;k>='0'&&k<='9';k=getchar()) x=x*10+k-'0';
x*=f;
}
template<class T>il _print(T x){
if(x>=10) _print(x/10);
putchar(x%10+'0');
}
template<class T>il print(T x){
if(x<0) putchar('-'),x=-x;
_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int k,int mod){
int res=1,bas=x;
while(k){
if(k&1) res=1ll*res*bas%mod;
bas=1ll*bas*bas%mod,k>>=1;
}
return res;
}
const int N = 2e5+5,mod = 1e9+7;
it add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
it mul(int x,int y){return 1ll*x*y%mod;}
il inc(int &x,int y){x=add(x,y);}
int n,m,k,ans,fac[N],ifac[N];
it C(int n,int m){return mul(mul(ifac[n-m],ifac[m]),fac[n]);}
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
read(n),read(m),read(k),fac[0]=1;
for(ri i=1;i<=n*m;++i) fac[i]=mul(fac[i-1],i);
ifac[n*m]=qpow(fac[n*m],mod-2,mod);
for(ri i=n*m-1;i>=0;--i) ifac[i]=mul(ifac[i+1],i+1);
for(ri i=1;i<=n-1;++i) inc(ans,mul(mul(mul(m,m),n-i),i));
for(ri i=1;i<=m-1;++i) inc(ans,mul(mul(mul(n,n),m-i),i));
print(mul(ans,C(n*m-2,k-2)));
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
struct Combination {
vector<long long> inv,finv,fac;
Combination(int n, int kmax) : inv(kmax+1),finv(kmax+1),fac(kmax){
if(kmax>=1){
inv.at(1)=1;
finv.at(1)=1;
fac.at(0) = n;
}
for(int i=2; i<=kmax; i++) inv.at(i) = MOD - inv.at(MOD%i) * (MOD/i) %MOD;
for(int i=2; i<=kmax; i++) finv.at(i) = finv.at(i-1) * inv.at(i) % MOD;
for(int i=1; i<kmax; i++) fac.at(i) = fac.at(i-1) * (n-i) % MOD;
}
int comb(int k) {return (k ? fac.at(k-1) * finv.at(k) % MOD : 1 );}
};
ll exgcd(ll a,ll b,ll &x,ll &y){
while(b){
ll t{a/b};
swap(a-=t*b, b);
swap(x-=t*y, y);
}
return a;
}
ll exgcd(ll a,ll b){
ll x{1},y{0};
return exgcd(a,b,x,y);
}
ll inverse(ll a,ll mod){
ll x{1},y{0};
exgcd(a,mod,x,y);
return (x%mod+mod)%mod;
}
int main(){
int n,m,k; cin>>n>>m>>k;
ll sum{};
Combination c(n*m-2,k-2);
for(ll i=0; i<n; i++){
for(ll j=0; j<m; j++){
sum += (i*(i+1)/2+(n-i)*(n-i-1)/2)*m;
sum %= MOD;
sum += (j*(j+1)/2+(m-j)*(m-j-1)/2)*n;
sum %= MOD;
}
}
sum *= c.comb(k-2);
sum %= MOD;
sum *= inverse(2,MOD);
sum %= MOD;
cout << sum << endl;
} | 1 |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
const int MAXN = 100000 + 1000;
int n;
int s[4][MAXN];
int id[MAXN], rev[MAXN];
int s1, s2, f1, f2;
bool vis[MAXN];
void no()
{
cout << "No" << endl;
exit(0);
}
void yes()
{
cout << "Yes" << endl;
exit(0);
}
int main()
{
ios::sync_with_stdio(false);
// freopen("1.in", "r", stdin);
// freopen("1.out", "w", stdout);
cin >> n;
for(int i = 1; i <= 3; i++)
for(int j = 1; j <= n; j++)
cin >> s[i][j];
for(int i = 1; i <= n; i++)
{
if(s[1][i] % 3 == 0 && s[3][i] + 1 == s[2][i] && s[2][i] + 1 == s[1][i])
id[i] = s[1][i] / 3, rev[i] = true;
else if(s[3][i] % 3 == 0 && s[1][i] + 1 == s[2][i] && s[2][i] + 1 == s[3][i])
id[i] = s[3][i] / 3, rev[i] = false;
else
no();
}
// for(int i = 1; i <= n; i++)
// cout << id[i] << endl;
for(int i = 1; i <= n; i++)
if(id[i] % 2 != i % 2)
no();
for(int i = 1; i <= n; i++)
(i & 1 ? f1 : f2) ^= rev[i];
for(int i = 1; i <= n; i++)
if(!vis[i])
{
int cur = i, cnt = 0;
do
{
vis[cur] = true;
cnt++;
cur = id[cur];
}
while(cur != i);
(i & 1 ? s1 : s2) ^= ((cnt - 1) & 1);
}
if((s1 ^ f2) || (s2 ^ f1))
no();
yes();
return 0;
}
| #include <iostream>
#include <cassert>
#include <cstring>
#include <vector>
using namespace std;
vector<vector<vector<double>>> dp;
int n;
double find(int i, int j, int k){
if(dp[i][j][k]!=-1) return dp[i][j][k];
dp[i][j][k] = 0.0;
if(i==0 && j==0 && k==0){
return dp[i][j][k];
}
dp[i][j][k] += n;
if(k){
dp[i][j][k] += k*find(i,j+1,k-1);
}
if(j){
dp[i][j][k] += j*find(i+1,j-1,k);
}
if(i){
dp[i][j][k] += i*find(i-1,j,k);
}
dp[i][j][k] /= 1.0*(i+j+k);
return dp[i][j][k];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
t = 1;
while(t--){
cin >> n;
dp = vector<vector<vector<double>>> (n+1,vector<vector<double>>(n+1,vector<double>(n+1,-1)));
vector<int> count(4,0);
for(int i=0 ; i<n ; i++){
int in;
cin >> in;
count[in]++;
}
cout.precision(16);
cout << find(count[1],count[2],count[3]) << "\n";
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#define int long long int
char arr[405][405];
bool vis[405][405];
int h, w;
int cb;
int cw;
bool f(int i, int j, int l, int m){
if(l<0 || l>=h || m<0 || m>=w){
return 0;
}
if(vis[l][m]==1){
return 0;
}
if(arr[i][j]==arr[l][m]){
return 0;
}
return 1;
}
void dfs(int i, int j){
vis[i][j]=1;
if(arr[i][j]=='#'){
cb++;
}
else{
cw++;
}
if(f(i, j, i+1, j)){
dfs(i+1, j);
}
if(f(i, j, i, j+1)){
dfs(i, j+1);
}
if(f(i, j, i-1, j)){
dfs(i-1, j);
}
if(f(i, j, i, j-1)){
dfs(i, j-1);
}
}
main() {
cin>>h>>w;
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
cin>>arr[i][j];
}
}
int ans=0;
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
if(vis[i][j]==0){
dfs(i, j);
ans+=(cb*cw);
cb=0;
cw=0;
}
}
}
cout<<ans;
return 0;
} | #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 h, w;
cin >> h >> w;
vector<string> mp(h);
rep(i, h) { cin >> mp[i]; }
UnionFind uf(h * w, mp);
rep(i, h) rep(j, w) rep(k, 4) {
ll y = i + dy[k];
ll x = j + dx[k];
bool cond = 0 <= x && x < w && 0 <= y && y < h;
if (!cond) continue;
if (mp[y][x] != mp[i][j]) {
uf.unite(x + y * w, j + i * w);
}
}
ll ans = 0;
rep(i, h * w) {
if(i == uf.find(i)){
ans += uf.get_bcnt(i) * uf.get_wcnt(i);
}
}
cout << ans << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int cnt[100005];
bool ac[100005];
char s[5];
int main() {
int n, m;
scanf("%d%d", &n, &m);
int pen = 0;
int res = 0;
for (int i = 0; i < m; i++) {
int x;
scanf("%d%s", &x, s);
if (s[0] == 'A') {
if (!ac[x]) {
res++;
pen += cnt[x];
}
ac[x] = 1;
}
else {
cnt[x]++;
}
}
printf("%d %d\n", res, pen);
}
| #include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;
const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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;}
int h, w;
vector<string> v(400);
class UnionFind
{
public:
vector<ll> par; // 各元の親を表す配列
vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)
vector<ll> siz_B;
// Constructor
UnionFind(ll sz_) : par(sz_), siz(sz_, 1), siz_B(sz_,0)
{
for (ll i = 0; i < sz_; ++i)
par[i] = i; // 初期では親は自分自身
}
void init(ll sz_)
{
par.resize(sz_);
siz.assign(sz_, 1);
siz_B.assign(sz_, 0);
for (ll i = 0; i < sz_; ++i){
par[i] = i;
if (v[i / w][i % w] == '#')
{
siz_B[i]=1;
}
}
}
// Member Function
// Find
ll root(ll x)
{ // 根の検索
while (par[x] != x)
{
x = par[x] = par[par[x]]; // x の親の親を x の親とする
}
return x;
}
// Union(Unite, Merge)
bool merge(ll x, ll y)
{
x = root(x);
y = root(y);
if (x == y)
return false;
// merge technique(データ構造をマージするテク.小を大にくっつける)
if (siz[x] < siz[y])
swap(x, y);
siz[x] += siz[y];
siz_B[x]+=siz_B[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y)
{ // 連結判定
return root(x) == root(y);
}
ll size(ll x)
{ // 素集合のサイズ
return siz[root(x)];
}
ll size_B(ll x){
return siz_B[root(x)];
}
};
int main()
{
cin >> h >> w;
REP(i,h){
cin >> v[i];
}
UnionFind uf(h * w);
uf.init(h*w);
REP(i,h){
REP(j,w){
if(j!=w-1&&v[i][j]!=v[i][j+1]){
uf.merge(i*w+j,i*w+j+1);
}
if(i!=h-1&&v[i][j]!=v[i+1][j]){
uf.merge(i*w+j,(i+1)*w+j);
}
}
}
set<ll> ne;
REP(i,h){
REP(j,w){
ne.insert(uf.root(i*w+j));
}
}
ll ans=0;
for(auto& k:ne){
ans+=(uf.size(k)-uf.size_B(k))*(uf.size_B(k));
}
cout << ans << endl;
}
| 0 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define V(a) a.begin(), a.end()
typedef vector<int> vi;
int main()
{
vi a[2], C;
for (auto &i : a) {
int n;
cin >> n;
i = vi(n);
for (int &j : i)
cin >> j;
sort(V(i));
}
set_intersection(V(a[0]), V(a[1]), inserter(C, C.end()));
cout << C.size() << endl;
}
| #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = 0 ; i < a ; i ++)
#define vi vector<int>
int main(void){
int s,t,r=0;
cin>>s;
vi sv(s);
rep(i,s)cin>>sv[i];
cin>>t;
vi tv(t);
rep(i,t){
cin>>tv[i];
rep(j,s){
if(sv[j] == tv[i]){
r++;
break;
}
}
}
cout<<r<<endl;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000; // n の最大値
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
int main() {
ll h,w,n;
cin>>h>>w>>n;
ll ans=0;
if(h>w){
if(n%h==0){
ans = n/h;}
else{
ans = n/h +1;}}
else{
if(n%w==0){
ans = n/w;}
else{
ans = n/w +1;}}
cout << ans << endl;}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n; cin >> n;
const ll p = 26;
string ans = "";
ll tmp = n;
while (true) {
tmp--;
ll mod = tmp % p;
string mod_s{ (char)('a' + mod) };
ans += mod_s;
if (tmp / p == 0) break;
tmp /= p;
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
return 0;
} | 0 |
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
struct UnionFind {
vector<int> data;
int sz;
UnionFind(int sz) : data(sz, -1), sz(sz) { }
bool unionSet(int x, int y) {
if ((x = root(x)) == (y = root(y))) return false;
if (data[x] > data[y]) swap(x, y);
data[x] += data[y]; data[y] = x; sz--;
return true;
}
bool findSet(int x, int y) { return root(x) == root(y); }
int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
int size(int x) { return -data[root(x)]; }
int size() { return sz; }
};
int main() {
int n, m; cin >> n >> m;
UnionFind uf(n * 2);
for (int i = 0; i < m; i++) {
int a, b; cin >> a >> b; a--, b--;
uf.unionSet(a, b + n);
uf.unionSet(a + n, b);
}
long long all = 0;
if (uf.findSet(0, n)) {
all = 1LL * n * (n - 1) / 2;
} else {
for (int i = 0; i < n; i++) all += uf.findSet(0, i);
all *= n - all;
}
cout << all - m << endl;
return 0;
}
| #include <iostream>
#include <vector>
#include <map>
using namespace std; using P=pair<int,int>; using ll=long long;
const int mx=1e5; vector<vector<int>> v(mx); vector<int> c(mx); int n; bool noco=false;
void dfs(int from, int to, int color) {
if (from == -1) for(int i=0;i<n;i++) c[i]=-1;
if (c[to] == 0 || c[to] == 1) {
if (c[to] != color) noco=true; return;
} else c[to]=color;
for(int next:v[to]) {
if (from == next) continue;
dfs(to, next, color^1);
}
}
int main() {
int m; cin>>n>>m;
for(int i=0;i<m;i++) {
int a,b; cin>>a>>b; a--; b--; v[a].push_back(b); v[b].push_back(a);
}
dfs(-1,0,0);
ll w=0,h=0,used=0;
for(int i=0;i<n;i++) {
if (c[i] == 0) w++;
if (c[i] == 1) h++;
}
if (noco) {
for(int i=0;i<n;i++) {
if (c[i] == -1) continue;
used+=v[i].size();
}
used/=2;
cout<<(w+h)*(w+h-1)/2-used<<endl;
} else {
for(int i=0;i<n;i++) {
if (c[i] == -1) continue;
for(int x:v[i]) {
if (c[i]^1 == c[x]) used++;
}
}
used/=2;
cout<<w*h-used<<endl;
}
} | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
double ans = 0;
int count = 0;
int N;
cin >> N;
vector<pair<int, int>> points;
for(int i=0;i<N;i++){
pair<int, int> p;
cin >> p.first;
cin >> p.second;
points.push_back(p);
}
sort(points.begin(), points.end());
do{
int sx = points[0].first;
int sy = points[0].second;
for(int i=1; i<N; i++){
ans += sqrt(pow((sx-points[i].first), 2) + pow((sy-points[i].second), 2));
sx = points[i].first;
sy = points[i].second;
}
count++;
}while(next_permutation(points.begin(), points.end()));
cout << setprecision(10) << (double)ans/count << endl;
return 0;
} | #include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long ll;
ll ans, fact[25];
int arr[25];
inline void chk(int len)
{
ll res = 9 - my_abs(arr[0]);
for (int i = 1; i <= len - 1 >> 1; i++)
res *= 10 - my_abs(arr[i]);
ans += res;
}
void dfs(int cur, int len, ll rem)
{
if (cur == len >> 1)
{
if (!rem)
{
arr[cur] = 0;
chk(len);
}
return;
}
ll diff = fact[len - cur - 1] - fact[cur];
ll r = ceil((double)rem / diff), l = floor((double)rem / diff);
if (-9 <= r && r <= 9)
{
arr[cur] = r;
dfs(cur + 1, len, rem - diff * r);
}
if (l != r && -9 <= l && l <= 9)
{
arr[cur] = l;
dfs(cur + 1, len, rem - diff * l);
}
}
int main()
{
// freopen("ARC075-F.in", "r", stdin);
ll d;
scanf("%lld", &d);
fact[0] = 1;
for (int i = 1; i <= 18; i++)
fact[i] = fact[i - 1] * 10;
for (int cnt = 1; cnt <= 18; cnt++)
{
memset(arr, 0, sizeof(arr));
dfs(0, cnt, d);
}
printf("%lld\n", ans);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;
#define fi first
#define se second
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);
void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}
int H, W;
char C[405][405];
bool visited[405][405];
int di[4] = {0, 1, 0, -1}, dj[4] = {1, 0, -1, 0};
ll ans = 0, b = 0, w = 0;
int Solve(int i, int j){
b = 0; w = 0;
if (C[i][j] == '.') w++;
else b++;
visited[i][j] = true;
queue <Pii> que; que.push({i, j});
while (!que.empty()){
Pii Q = que.front(); que.pop();
for (int k = 0; k < 4; k++){
int I = Q.fi + di[k], J = Q.se + dj[k];
if (0 <= I && I < H && 0 <= J && J < W){
if (visited[I][J]) continue;
if (C[I][J] == C[Q.fi][Q.se]) continue;
que.push({I, J});
visited[I][J] = true;
if (C[I][J] == '.') w++;
else b++;
}
}
}
ans += b * w;
return 0;
}
int main(){
cin >> H >> W;
for (int i = 0; i < H; i++){
for (int j = 0; j < W; j++){
cin >> C[i][j];
}
}
for (int i = 0; i < H; i++){
for (int j = 0; j < W; j++){
if (!visited[i][j]) Solve(i, j);
}
}
cout << ans << endl;
return 0;
}
| /*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/
//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int h,w;
string s[440];
bool vis[440][440]={false};
int typ[2];
int dx[4]={1,0,-1,0};
int dy[4]={0,-1,0,1};
void dfs(int i, int j)
{
vis[i][j]=true;
if(s[i][j]=='#')
++typ[0];
else
++typ[1];
for(int k=0;k<4;++k)
{
int x=i+dx[k];
int y=j+dy[k];
if(x>=0&&x<h&&y>=0&&y<w&&vis[x][y]==false&&s[i][j]!=s[x][y])
dfs(x,y);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli res=0ll;
cin>>h>>w;
for(int i=0;i<h;++i)
cin>>s[i];
for(int i=0;i<h;++i)
for(int j=0;j<w;++j)
{
if(vis[i][j])
continue;
if(s[i][j]=='.')
continue;
typ[0]=0;
typ[1]=0;
dfs(i,j);
res+=1ll*typ[0]*typ[1];
}
cout<<res<<endl;
} | 1 |
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char str[25];
cin>>str;
char rev[25];
for(int i=0;i<strlen(str);i++)
rev[i]=str[strlen(str)-i-1];
rev[strlen(str)]='\0';
cout<<rev<<endl;
} | #include<iostream>
#include<sstream>
using namespace std;
int main(){
string str;
cin >> str;
std::istringstream stream(str);
for(int i=str.length()-1; i>=0; i--){
stream >> str[i];
}
cout << str << endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define pii pair<int,int>
#define vvi vector<vector<int> >
#define vpi vector<pii>
#define F first
#define S second
#define pb push_back
#define INF 0x7fffffff
#define LINF 0x7fffffffffffffff
#define MOD 1000000007
#define mod 998244353
#define lowbit(x) x&(-x)
#define HS 173LL
using namespace std;
int read()
{
int x=0;
char ch=getchar();
while(!isdigit(ch))
ch=getchar();
while(isdigit(ch))
{
x=x*10+ch-'0';
ch=getchar();
}
return x;
}
int h,w;
map<int,int> mp;
multiset<int> st;
int main()
{
h=read(),w=read();
for(int i=1;i<=w;i++)
mp[i]=0;
for(int i=1;i<=w;i++)
st.insert(0);
for(int i=1;i<=h;i++)
{
int l=read(),r=read();
if(r!=w)
{
auto it=mp.upper_bound(r+1);
if(it!=mp.begin())
{
--it;
if(it->first!=r+1)
{
int v=it->second+r+1-it->first;
mp[r+1]=v;
st.insert(v);
}
}
}
auto it=mp.lower_bound(l);
while(it!=mp.end()&&it->first<=r)
{
st.erase(st.find(it->second));
it=mp.erase(it);
}
if(!st.empty())
cout<<*st.begin()+i<<endl;
else
cout<<-1<<endl;
}
return 0;
} | #include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
ll n,m,a[N],b[N];
struct SegT{
ll l,r,val,pd,pd2;
}dp[8*N];
void build_tree(ll l,ll r,ll x)
{
if(l>r)
{
return;
}
dp[x].l=l;
dp[x].r=r;
dp[x].val=0;
dp[x].pd=0;
dp[x].pd2=-1;
if(l==r)
{
return;
}
ll mid=(l+r)>>1,a=x<<1;
build_tree(l,mid,a);
build_tree(mid+1,r,a|1);
return;
}
void push_down(ll x)
{
ll a=x<<1;
dp[a].val+=dp[x].pd;
dp[a|1].val+=dp[x].pd;
dp[a].pd+=dp[x].pd;
dp[a|1].pd+=dp[x].pd;
dp[x].pd=0;
return;
}
void push_down2(ll x)
{
ll a=x<<1;
dp[a].val=dp[x].val;
dp[a|1].val=dp[a|1].l-dp[a].l+dp[x].val;
dp[a].pd2=dp[x].pd2;
dp[a|1].pd2=dp[x].pd2;
dp[a].pd=0;
dp[a|1].pd=0;
dp[x].pd=0;
dp[x].pd2=-1;
return;
}
void update(ll l,ll r,ll x)
{
if(l>r)
{
return;
}
ll tl=dp[x].l,tr=dp[x].r;
if(tl>r||tr<l)
{
return;
}
if(dp[x].pd2!=-1)
{
push_down2(x);
}
push_down(x);
if(l<=tl&&tr<=r)
{
dp[x].val++;
dp[x].pd++;
return;
}
ll mid=(tl+tr)>>1,a=x<<1;
if(mid>=l)
{
update(l,r,a);
}
if(mid<r)
{
update(l,r,a|1);
}
dp[x].val=min(dp[a].val,dp[a|1].val);
return;
}
ll query(ll l,ll r,ll x)
{
if(l<0||r<0||l>=m||r>=m)
{
return LINF;
}
ll tl=dp[x].l,tr=dp[x].r;
if(tl>r||tr<l)
{
return LINF;
}
if(dp[x].pd2!=-1)
{
push_down2(x);
}
push_down(x);
if(l<=tl&&tr<=r)
{
return dp[x].val;
}
ll mid=(tl+tr)>>1,a=x<<1,ret=LINF;
if(mid>=l)
{
ret=min(ret,query(l,r,a));
}
if(mid<r)
{
ret=min(ret,query(l,r,a|1));
}
dp[x].val=min(dp[a].val,dp[a|1].val);
return ret;
}
void update2(ll l,ll r,ll x,ll val)
{
if(l>r)
{
return;
}
ll tl=dp[x].l,tr=dp[x].r;
if(l<=tl&&tr<=r)
{
dp[x].val=val+tl-l+1;
dp[x].pd=0;
dp[x].pd2=l;
dp[x<<1].pd=0;
dp[(x<<1)|1].pd=0;
push_down2(x);
return;
}
if(dp[x].pd2!=-1)
{
push_down2(x);
}
push_down(x);
ll mid=(tl+tr)>>1,a=x<<1;
if(mid>=l)
{
update2(l,r,a,val);
}
if(mid<r)
{
update2(l,r,a|1,val);
}
dp[x].val=min(dp[a].val,dp[a|1].val);
return;
}
int main(){
ll i,j;
scanf("%lld%lld",&n,&m);
for(i=0;i<n;i++)
{
scanf("%lld%lld",&a[i],&b[i]);
a[i]--;
b[i]--;
}
build_tree(0,m-1,1);
for(i=1;i<=n;i++)
{
update(0,a[i-1]-1,1);
update(b[i-1]+1,m-1,1);
update2(a[i-1],b[i-1],1,query(a[i-1]-1,a[i-1]-1,1));
// for(j=0;j<m;j++)
// {
// query(j,j,1);
// }
j=dp[1].val;
if(j<INF)
{
printf("%lld\n",j);
}
else
{
puts("-1");
}
}
return 0;
} | 1 |
#include <iostream>
#include <string>
using namespace std;
int main(void){
string S;
cin >> S;
if(S.length() % 2 == 0){
for(int i=0;i<S.length();i=i+2){
if(S[i] == 'h' && S[i+1] == 'i'){
continue;
}
else{
cout << "No" << endl;
return 0;
}
}
}
else{
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10); 小数点以下10桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32; で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);
int main() {
string a;
cin >>a;
cout << (a=="hi" || a=="hihi" || a=="hihihi" ||
a=="hihihihi" || a=="hihihihihi"?"Yes":"No") << endl;
}
| 1 |
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(false);
int n, k; cin >> n >> k;
vector<int> a(n);
REP(i, n) cin >> a[i];
sort(a.begin(), a.end());
bool odd, even;
odd = even = true;
REP(i, n) {
if (a[i] % 2) even = false;
else odd = false;
}
bool allSame = true;
bool diffFlag = true;
int diff = INT_MAX;
REP(i, n - 1) {
if (abs(a[i] - a[i+1]))
diff = min(diff, abs(a[i] - a[i+1]));
}
REP(i, n - 1) {
if (a[i] != a[i+1])
allSame = false;
if (abs(a[i] - a[i+1]) % diff)
diffFlag = false;
}
if (k > *max_element(a.begin(), a.end())) {
cout << "IMPOSSIBLE" << '\n';
}
else if (find(a.begin(), a.end(), k) != a.end()) {
cout << "POSSIBLE" << '\n';
}
else if (allSame) {
cout << ((k == a[0]) ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
}
else if (diffFlag) {
cout << ((k % diff == 0) ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
}
else {
if (k % 2) {
bool ok = true;
if (even) ok = false;
if (k == 1 && (even || odd)) ok = false;
cout << ((ok) ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
}
else {
cout << "POSSIBLE" << '\n';
}
}
return 0;
}
| # include <iostream>
# include <vector>
# include <algorithm>
using namespace std;
# define ll long long
int fpb(int a, int b){
return (b == 0 ? a : fpb(b, a%b));
}
int main(){
int n, k;
cin >> n >> k;
int f = 0, largest = 0;
for(int i=0; i<n; i++){
int num;
cin >> num;
largest = max(largest, num);
f = fpb(f, num);
}
if (k <= largest && k % f == 0) cout << "POSSIBLE" << endl;
else cout << "IMPOSSIBLE" << endl;
return 0;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int sum = 1, a, b, i = 0; cin >> a >> b;
while(sum < b){
sum = sum - 1 + a;
i++;
}
cout << i << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B;
cin >> A >> B;
if ((B-1)%(A-1) == 0){
cout << (B-1)/(A-1) << endl;
}
else {
cout << (B-1)/(A-1) + 1 << endl;
}
} | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n, q;
string s;
cin >> n >> s >> q;
for (ll i = 0; i < q; i++)
{
ll k;
ll d, m, dm, dmc;
d = m = dm = dmc = 0;
scanf("%d", &k);
for (ll i = 0; i < n; i++)
{
if (i - k >= 0)
{
if (s[i - k] == 'D')
{
d--;
dm -= m;
}
if (s[i - k] == 'M')
m--;
}
if (s[i] == 'D')
d++;
if (s[i] == 'M')
{
m++;
dm += d;
}
if (s[i] == 'C')
dmc += dm;
}
cout << dmc << endl;
}
} | #define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using Int = long long;
//using namespace boost::multiprecision;
const double EPS = 1e-10;
long long const MOD = 998244353;
long long mod_pow(long long x, long long n) {
long long res = 1;
for (int i = 0;i < 60; i++) {
if (n >> i & 1) res = res * x % MOD;
x = x * x % MOD;
}
return res;
}
template<typename T>
T gcd(T a, T b) {
return b != 0 ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
return a * b / gcd(a, b);
}
void fastInput() {
cin.tie(0);
ios::sync_with_stdio(false);
}
const int MAXN = 1100010;
long long fact[MAXN], inv[MAXN];
void initComb() {
fact[0] = 1;
for (int i=1; i<MAXN; i++) {
fact[i] = (fact[i-1] * i) % MOD;
}
inv[MAXN - 1] = mod_pow(fact[MAXN - 1], MOD-2);
for (int i=MAXN - 2; i>=0; i--) {
inv[i] = (inv[i+1] * (i+1)) % MOD;
}
}
long long comb(int n, int r) {
if (n < r) return 0;
if (n < 0 || r < 0) return 0;
return fact[n] * inv[n-r] % MOD * inv[r] % MOD;
}
Int imos_D[1000005];
Int imos_C[1000005];
Int imos_M[1000005];
Int dp[1000005][5];
int main(void) {
int N; cin >> N;
string S; cin >> S;
int Q; cin >> Q;
for (int i = 0; i < N; i++) {
if (S[i] == 'D') imos_D[i+1] = 1;
else imos_D[i+1] = 0;
imos_D[i+1] += imos_D[i];
if (S[i] == 'C') imos_C[i+1] = 1;
else imos_C[i+1] = 0;
imos_C[i+1] += imos_C[i];
if (S[i] == 'M') imos_M[i+1] = 1;
else imos_M[i+1] = 0;
imos_M[i+1] += imos_M[i];
}
for (int i = 0; i < Q; i++) {
int K; cin >> K;
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int j = 0; j < N; j++) {
dp[j+1][0] = dp[j][0];
dp[j+1][1] = dp[j][1];
dp[j+1][2] = dp[j][2];
dp[j+1][3] = dp[j][3];
dp[j+1][4] = dp[j][4];
if (S[j] == 'D') {
dp[j+1][1] += dp[j][0];
}
if (S[j] == 'M') {
dp[j+1][2] += dp[j][1];
}
if (S[j] == 'C') {
dp[j+1][3] += dp[j][2];
}
if (S[j] == 'C') {
if (j+1-K >= 0) {
Int NumOfM = imos_M[j+1] - imos_M[j+1-K];
dp[j+1][4] += dp[j][2] - NumOfM * dp[j+1-K][1] - dp[j+1-K][2];
} else {
dp[j+1][4] += dp[j][2];
}
}
// cout << NumOfM << endl;
}
Int U = dp[N][3];
cout << dp[N][4] << endl;
}
} | 1 |
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define sor(a, l, r) sort(a + l, a + r + 1);
#define reve(a, l, r) reverse(a + l, a + r + 1)
using namespace std;
typedef long long LL;
const int N = 205;
const int MAXN = 100005;
template <typename T> inline void read(T &AKNOI) {
T x = 0, flag = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') flag = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
AKNOI = flag * x;
}
namespace ModCalculator {
const int MOD = 1e9 + 7;
inline void Inc(int &x, int y) {
x += y; if (x >= MOD) x -= MOD;
}
inline void Dec(int &x, int y) {
x -= y; if (x < 0) x += MOD;
}
inline int Add(int x, int y) {
Inc(x, y); return x;
}
inline int Sub(int x, int y) {
Dec(x, y); return x;
}
inline int Mul(int x, int y) {
return 1LL * x * y % MOD;
}
}
using namespace ModCalculator;
int n, X, a[N];
int dp[2][MAXN];
void init() {
read(n); read(X);
for (int i = 1; i <= n; ++i) {
read(a[i]);
}
sor(a, 1, n);
}
void solve() {
int pre = 0, cur = 1;
dp[pre][X] = 1;
int ans = 0;
for (int i = n; i >= 1; --i) {
mset(dp[cur], 0);
for (int j = 0; j <= X; ++j) {
Inc(dp[cur][j], Mul(dp[pre][j], i - 1));
Inc(dp[cur][j % a[i]], dp[pre][j]);
}
swap(pre, cur);
}
for (int i = 1; i <= X; ++i) {
Inc(ans, Mul(i, dp[pre][i]));
}
printf("%d\n", ans);
}
int main() {
init();
solve();
return 0;
}
| #include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n,x,s[205];
int dp[205][100005],tot[100005];
int main(){
scanf("%d %d",&n,&x);
for(int i=1;i<=n;i++) scanf("%d",&s[i]);
sort(s+1,s+n+1);
for(int i=0;i<=x;i++){
int l=1,r=n,p=0;
while(l<=r){
int mid=(l+r)/2;
if(s[mid]<=i) p=max(p,mid),l=mid+1;
else r=mid-1;
}
tot[i]=p;
}
dp[0][x]=1;
for(int i=1;i<=n;i++){
for(int j=0;j<=x;j++){
if(dp[i-1][j]==0) continue;
for(int k=1;k<=tot[j];k++) (dp[i][j%s[k]]+=dp[i-1][j])%=mod;
int p=n-tot[j];
if(i<=p) (dp[i][j]+=1ll*(p-i+1)*dp[i-1][j]%mod)%=mod;
}
}
int ans=0;
for(int i=0;i<=x;i++) (ans+=1ll*i*dp[n][i]%mod)%=mod;
printf("%d\n",ans);
return 0;
} | 1 |
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
char c=getchar();bool f=0;x=0;
while(!isdigit(c)) f|=c=='-',c=getchar();
while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
read(x);read(a...);
}
template<class t> inline void write(t x){
if(x<0) putchar('-'),write(-x);
else{if(x>9) write(x/10);putchar('0'+x%10);}
}
int ans,x,y;
signed main(){
read(x,y);
if(x==1) ans+=3e5;
if(x==2) ans+=2e5;
if(x==3) ans+=1e5;
if(y==1) ans+=3e5;
if(y==2) ans+=2e5;
if(y==3) ans+=1e5;
if(x==1&&y==1) ans+=4e5;
write(ans);
} | #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
struct set {
int h;
int w;
int diagonel;
} all[22500];
int suffix = 0;
void InsSort(int n)
{
int i, j, temp_dia, temp_h, temp_w;
for (i = 1; i < n; i++) {
temp_h = all[i].h;
temp_w = all[i].w;
temp_dia = all[i].diagonel;
for (j = i; j > 0; j--) {
if (all[j - 1].diagonel > temp_dia) {
all[j].h = all[j - 1].h;
all[j].w = all[j - 1].w;
all[j].diagonel = all[j - 1].diagonel;
}
else if (all[j - 1].diagonel == temp_dia) {
if (all[j - 1].h > temp_h) {
all[j].h = all[j - 1].h;
all[j].w = all[j - 1].w;
all[j].diagonel = all[j - 1].diagonel;
}
else {
break;
}
}
else {
break;
}
}
all[j].h = temp_h;
all[j].w = temp_w;
all[j].diagonel = temp_dia;
}
}
void search() {
for (int i = 1; i <= 150; i++) {
for (int j = 1; j <= 150; j++) {
if (i >= j) {
continue;
}
all[suffix].h = i;
all[suffix].w = j;
all[suffix].diagonel = (i * i) + (j * j);
suffix++;
}
}
}
int main() {
search();
InsSort(suffix);
//FILE *fp;
//fp = fopen("C:\\Users\\owata\\Desktop\\answer1.txt", "w");
while (1) {
int h, w, my;
scanf("%d %d", &h, &w);
if (h == 0 && w == 0) {
break;
}
my = (h * h) + (w * w);
for (int i = 0; i < suffix; i++) {
if (all[i].h == h && all[i].w == w) {
continue;
}
if (all[i].diagonel > my) {
printf("%d %d\n", all[i].h, all[i].w);
//fprintf(fp, "%d %d\n", all[i].h, all[i].w);
break;
}
else if (all[i].diagonel == my && h < all[i].h) {
printf("%d %d\n", all[i].h, all[i].w);
//fprintf(fp, "%d %d\n", all[i].h, all[i].w);
break;
}
}
}
//fclose(fp);
return 0;
} | 0 |
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 5000100;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);
//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
// ll a, b;
// cin >> a >> b;
// work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
return y ? gcd(y, x % y) : x;
}
ll lcm(ll x, ll y) {
if (x == 0 || y == 0)return 0;
return (x / gcd(x, y) * y);
}
//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX_N; 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;
}
ll dx[8] = { 0,0,-1,1 };
ll dy[8] = { -1,1,0,0 };
ll dp[101010];
//union-find木について
ll par[101010];
ll rank2[101010];
void init(ll n) {
rep(i, n) {
par[i] = i;
rank2[i] = 0;
}
}
ll find(ll x) {
if (par[x] == x) {
return x;
}
else {
return par[x] = find(par[x]);
}
}
void unite(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y)return;
if (rank2[x] < rank2[y]) {
par[x] = y;
}
else {
par[y] = x;
if (rank2[x] == rank2[y]) {
rank2[x]++;
}
}
}
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
bool graph[101][101];
bool visit[101010];
vector<ll> to[101010];
vector<ll>ball(101010, 1);
vector<bool>flag(101010);
//long longしか使わない
//素数は1より大きい
int main() {
ll x, y;
cin >> x >> y;
ll ans = 0;
if (y >= x) {
if (x >= 0) {
ans = y - x;
}
else if (y <= 0) {
ans = y - x;
}
else {
ll min2 = min(abs(x), abs(y));
ll max2 = max(abs(x), abs(y));
ans = max2 - min2 + 1;
}
}
else {
if (y >= 0) {
ans = x - y + 2;
if (y == 0) {
ans = abs(x) + 1;
}
}
else if (x <= 0) {
ans = x - y + 2;
if (x == 0) {
ans = abs(y) + 1;
}
}
else {
ll min2 = min(abs(x), abs(y));
ll max2 = max(abs(x), abs(y));
ans = max2 - min2 + 1;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-6;
const double PI = acos(-1.0);
const long INF=pow(2,31)-1;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
const long MOD=1e9+7;
const int MAX_N=1004;
int dp[MAX_N][MAX_N];
int main(){
string S1,S2;
cin>>S1>>S2;
CLR(dp);
FOR(i,1,MAX_N){
dp[0][i]=dp[i][0]=i;
}
REP(i,SZ(S1)){
REP(j,SZ(S2)){
int cost=(S1[i]==S2[j])?0:1;
dp[i+1][j+1]=min(min(dp[i][j+1]+1,dp[i+1][j]+1),dp[i][j]+cost);
}
}
cout<<dp[SZ(S1)][SZ(S2)]<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
int n=s.size();
bool judge=true;
if(n%2!=0){
judge=false;
}
for(int i=0;i<n;i+=2){
if(judge==false){
break;
}
if(s.at(i)!='h'||s.at(i+1)!='i'){
judge=false;
}
}
if(judge){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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 < 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 < table.size(); i++) {
for (int j = 0; j < 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;
}
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() {
string s;
cin >> s;
Yes(s=="hi"||s=="hihi"||s=="hihihi"||s=="hihihihi"||s=="hihihihihi");
} | 1 |
#include <iostream>
#include <vector>
using namespace std;
struct edge
{
int to, d;
};
vector<vector<edge>> g;
int b[100000];
int n, u, v;
int dfs(int v, int parent) {
int res = 0;
for (edge &ne : g[v]) {
if (ne.to == parent) continue;
ne.d = 1;
int now = dfs(ne.to, v) + 1;
res = max(res, now);
}
b[v] = res;
return res;
}
int main() {
cin >> n >> u >> v;
u--; v--;
g.assign(n, vector<edge>());
for (int i = 0; i < n-1; i++) {
int a, b;
cin >> a >> b;
a--; b--;
g[a].push_back({b, 0});
g[b].push_back({a, 0});
}
dfs(v, -1);
int dist = 0;
for (int i = u; i != v; ) {
for (edge e : g[i]) {
if (e.d == 0) {i = e.to; break;}
}
dist++;
}
int ans = 0;
while (dist > 2) {
for (edge e : g[u]) {
if (e.d == 0) {u = e.to; break;}
}
dist -= 2;
ans++;
}
ans += dist + b[u] - 1;
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
struct edge {int to, cost; };
typedef pair<int, int> P;
int V;
vector <edge> G[100010];
int d[100010];
void dijkstrra(int s){
priority_queue <P, vector<P>, greater<P> > que;
fill(d, d + V, 1000000000);
d[s] = 0;
que.push(P(0 , s));
while(!que.empty()){
P p = que.top(); que.pop();
int v = p.second;
if(d[v] < p.first) continue;
for(int i = 0; i < G[v].size(); i++){
edge e = G[v][i];
if(d[e.to] > d[v] + e.cost){
d[e.to] = d[v] + e.cost;
que.push(P(d[e.to], e.to));
}
}
}
}
int main(){
cin >> V;
int e, r; cin >> e >> r;
for(int i = 0; i < e; i++){
int s, t, d;
cin >> s >> t >> d;
G[s].push_back({t, d});
}
dijkstrra(r);
for(int i = 0; i < V; i++){
if(d[i] == 1000000000)
cout << "INF" << endl;
else
cout << d[i] << endl;
}
return 0;
} | 0 |
#include <cstdio>
#include <algorithm>
#define mod 998244353
#define maxn 200010
#define LL long long
using namespace std;
LL fact[maxn],inv[maxn],ans,t[maxn],p;
int n,m,k,nm;
LL quick_pow(LL a,LL b){//a^b
LL ans=1;
while(b){
if(b&1)ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans%mod;
}
void init(){
int i;
scanf("%d%d%d",&n,&m,&k);
nm=n,nm=max(nm,m),fact[0]=1;
for(i=1;i<=nm;i++)fact[i]=fact[i-1]*i%mod;//fact[i]代表i!
inv[nm]=quick_pow(fact[nm],mod-2);
for(i=nm-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;//inv[i]代表i!的乘法逆元
}
LL C(LL a,LL b){//组合数计算
return fact[a]*inv[a-b]%mod*inv[b]%mod;
}
int main(){
int i;
init();
ans=0,p=quick_pow(m-1,n-k-1);
for(i=n-k;i<=n;i++){
ans=(ans+m*p%mod*C(n-1,i-1)%mod)%mod;//C(n-1,i-1)隔板法
p=p*(m-1)%mod;
}
printf("%lld\n",ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define ff first
#define ss second
#define pb push_back
#define sz size()
#define mp make_pair
#ifndef ONLINE_JUDGE
#include "/home/asif/Codes/Library/debug.h"
#endif
/*--------------------------------------------------------------------*/
const int N = 2e5 + 5;
const int MOD = 998244353;
namespace nCr {
ll factorial[N], invFactorial[N];
ll ncr(ll n, ll r){
return (( (factorial[n] * invFactorial[r]) % MOD) * invFactorial[n - r]) % MOD;
}
void init(){
invFactorial[1] = 1;
for(int i = 2;i < N;i++)invFactorial[i] = MOD - (MOD / i) * invFactorial[MOD % i] % MOD;
factorial[0] = factorial[1] = invFactorial[0] = 1;
for(int i = 2; i < N; i++){
factorial[i] = (factorial[i - 1] * i) % MOD;
invFactorial[i] = (invFactorial[i - 1] * invFactorial[i]) % MOD;
}
}
}
ll bigmod(ll a, ll p){
if(p == 0) return 1LL;
ll ret = bigmod(a, p / 2);
ret *= ret;
ret %= MOD;
if(p & 1) ret = (ret * a) % MOD;
return ret;
}
int main() {
ll n, m, k;
cin >> n >> m >> k;
nCr::init();
ll ans = 0LL;
for(int i = 0; i <= k; i++){
ans += (((nCr::ncr(n - 1, i) * bigmod(m - 1, n - i - 1)) % MOD) * m) % MOD;
ans %= MOD;
}
cout << ans << endl;
return 0;
} | 1 |
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);
using namespace std;
struct INIT { INIT(){
cin.tie(0); ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
}}INIT;
signed main() {
int N;
cin >> N;
int keta = 0;
int sum = 0;
REP(i, N){
int a, b;
cin >> a >> b;
keta += b;
sum += a*b;
}
cout << (keta-1)+(sum-1)/9 << "\n";
return 0;
} | #pragma region Macros
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i)
#define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME
#define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__)
#define RREP2(i, n) for (int i = (n - 1); i >= 0; --i)
#define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i)
#define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME
#define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__)
#define IN(type, n) type n; cin >> n
#define INALL(type, v) REP(i, v.size()) { IN(type, _tmp); v.at(i) = _tmp; }
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl
#else
#define DEBUG(x)
#endif
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; }
#pragma endregion
int main() {
IN(int, N);
vector<ll> x(N);
vector<ll> y(N);
REP(i, N) {
IN(ll, tmp_x);
x.at(i) = tmp_x;
IN(ll, tmp_y);
y.at(i) = tmp_y;
}
cout << std::fixed << std::setprecision(6);
vector<vector<long double> > dist(N, vector<long double>(N, 0));
REP(i, N - 1) {
REP(j, i + 1, N) {
dist.at(i).at(j) = sqrtl((long double)(pow(x.at(i) - x.at(j), 2) + pow(y.at(i) - y.at(j), 2)));
dist.at(j).at(i) = dist.at(i).at(j);
}
}
vector<int> num;
REP(i, 0, N) {
num.push_back(i);
}
long double sum = 0;
do {
REP(i, N - 1) {
sum += dist.at(num.at(i)).at(num.at(i + 1));
}
} while (next_permutation(ALL(num)));
ll factorial = 1;
REP(i, 1, N + 1) {
factorial *= i;
}
long double ans = sum / (long double)factorial;
cout << ans << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;
const int MAX = 1001000;
char S[MAX];
char T[MAX];
int A[MAX];
int main()
{
//freopen("in.txt", "r", stdin);
//ios::sync_with_stdio(false); cin.tie(0);
int n;
scanf("%d", &n);
scanf("%s", S);
scanf("%s", T);
if ((string)(S) ==(string(T)))
{
cout<<0<<endl;
return 0;
}
FILL(A, -1);
int ind = n-1;
RFOR(i, n, 0)
{
while (ind > i) ind--;
while(ind >= 0 && S[ind] != T[i])
{
ind--;
}
if (ind == -1)
{
cout<<-1<<endl;
return 0;
}
if (A[ind] == -1) A[ind] = i;
}
vector<PII> a;
FOR (i, 0, n)
{
if (A[i] != -1) a.PB(MP(i, A[i]));
}
/*FOR (i, 0, SZ(a))
{
cout<<a[i].first<<' '<<a[i].second<<endl;
}
cout<<endl;*/
int res = 0;
ind = 0;
int ind2 = 0;
FOR (i, 0, SZ(a))
{
while(true)
{
if (ind2 == SZ(a)) break;
if (a[ind2].first <= a[i].second)
{
ind2++;
continue;
}
break;
}
while(true)
{
if (ind == SZ(a)) break;
if (a[ind].first - (ind - i - 1) <= a[i].second)
{
ind++;
continue;
}
break;
}
res = max(res, ind - i);
}
cout<<res<<endl;
}
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()
char S[1000010], T[1000010];
int N;
void solve(){
scanf("%d%s%s", &N, S+1, T+1);
if(!strcmp(S+1, T+1)){
printf("0");
return;
}
int que[1000010], *fr = que, *re = que, ans = 0;
for(int i=N, j=N;i>=1;i--)if(T[i] != T[i-1]){
j = min(i, j);
while(j > 0 && S[j] != T[i])--j;
if(j == 0){
printf("-1");
return;
}
while(re < fr && *re - (fr-re) >= i)re++;
if(i != j){
*fr++ = j;
ans = max(ans, (int)(fr - re));
}
}
printf("%d", ans + 1);
}
int main(){
int Tc = 1; //scanf("%d\n", &Tc);
for(int tc=1;tc<=Tc;tc++){
solve();
}
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,s,n) for(int i=s;i<n;++i)
#define FORR(i,s,n) for(int i=n-1;i>=s;--i)
#define ALL(c) (c).begin(),(c).end()
#define CLEAR(v) memset(v,0,sizeof(v))
#define MP(a,b) make_pair((a),(b))
#define ABS(a) ((a)>0?(a):-(a))
#define F first
#define S second
int main(int argc, char **argv) {
string s;
cin >> s;
bool f = true;
f &= (s[0] == 'A');
ll c = 0;
REP(i, s.length()) if (s[i] >= 'a' && s[i] <= 'z') ++c;
f &= (c == s.length() - 2);
if (f) FOR(i, 2, s.length()-1) if (s[i] == 'C') {
cout << "AC" << endl;
return 0;
}
cout << "WA" << endl;
return 0;
}
| #include <iostream>
#include <string>
using namespace std;
void solve(const string& s) {
for (int i = 0, j = 1; j < s.size(); ++i, ++j) {
if (s[i] == s[j]) {
cout << (i + 1) << " " << (j + 1) << "\n";
return;
}
}
for (int i = 0, j = 2; j < s.size(); ++i, ++j) {
if (s[i] == s[j]) {
cout << (i + 1) << " " << (j + 1) << "\n";
return;
}
}
cout << "-1 -1\n";
}
int main() {
string s;
cin >> s;
solve(s);
return 0;
}
| 0 |
#include<iostream>
using namespace std;
const int MAXN = 1005, INF = 2e9;
int d[MAXN][MAXN];
int main()
{
int n, m;
cin >> n >> m;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
d[i][j] = INF;
for(int i = 0; i < n; i++)
d[i][i] = 0;
for(int i = 0; i < m; i++)
{
int x, y, w;
cin >> x >> y >> w;
d[x][y] = w;
}
for(int k = 0; k < n; k++)
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if(d[i][k] < INF && d[k][j] < INF)
d[i][j] = min(1ll * d[i][j], 1ll * d[i][k] + d[k][j]);
for(int i = 0; i < n; i++)
if(d[i][i] < 0)
{
cout << "NEGATIVE CYCLE" << endl;
return 0;
}
for(int i = 0; i < n; i++, cout << endl)
for(int j = 0; j < n; j++)
{
if(d[i][j] == INF)
cout << "INF";
else
cout << d[i][j];
if(j < n - 1)
cout << ' ';
}
return 0;
} | #include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
const int N = 605;
inline int input() {
int x; char ch; while (!isdigit(ch = getchar()));
for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
return x;
}
inline void chkmin(int &x, int y) { x = x < y ? x : y; }
template <class T> T sqr(T x) { return x * x; }
int n, m, D1, D2;
int ansx[N * N], ansy[N * N], tot;
bool col[N][N];
void work(int D) {
int tmp = 0;
while(D % 4 == 0) D >>= 2, ++tmp;
if (D % 4 == 3) return void();
if (D % 4 == 1) {
for (int x = 0; x <= n; ++x)
for (int y = 0; y <= n; ++y)
if (((x >> tmp) + (y >> tmp)) & 1) col[x][y] = true;
}
if (D % 4 == 2) {
for (int x = 0; x <= n; ++x)
for (int y = 0; y <= n; ++y)
if ((x >> tmp) & 1) col[x][y] = true;
}
}
int main() {
#ifdef local
freopen("in", "r", stdin);
freopen("out", "w", stdout);
// freopen("log", "w", stderr);
#endif
ios::sync_with_stdio(false);
cin >> n >> D1 >> D2;
m = n, n = n * 2 - 1;
work(D1), work(D2);
for (int x = 0; x <= n; ++x)
for (int y = 0; y <= n; ++y) {
if (!col[x][y]) ansx[++tot] = x, ansy[tot] = y;
if (tot == m * m) goto Get;
}
Get:;
for (int i = 1; i <= tot; ++i)
printf("%d %d\n", ansx[i], ansy[i]);
return 0;
} | 0 |
#include<bits/stdc++.h>
#define ll long long
const ll mod=1e9+7;
using namespace std;
ll d[45][1<<17];
ll n,x,y,z;
int main()
{
scanf("%lld%lld%lld%lld",&n,&x,&y,&z);
ll ans=1;
for(ll i=1;i<=n;i++)
{
ans=1ll*ans*10;
ans%=mod;
}
ll s=(1<<x+y+z)-1;
ll u=(1<<x-1)|(1<<x+y-1)|(1<<x+y+z-1);
d[0][0]=1;
for(ll i=1;i<=n;i++)
{
for(ll j=0;j<=s;j++)
{
for(ll k=1;k<=10;k++)
{
ll t=(j<<k)|(1<<k-1);
t&=s;
if((t&u)!=u)
{
d[i][t]=(d[i][t]+d[i-1][j])%mod;
}
}
}
}
for(ll i=0;i<=s;i++)
{
ans=(ans-d[n][i]+mod)%mod;
}
cout<<ans%mod<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int mod=1e9+7;
const int INF=1001001001;
int dp[105][10];
int main() {
int H,W,K;
cin>>H>>W>>K;
dp[0][0]=1;
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
if(dp[i][j]==0){continue;}
for(int s=0;s<(1<<W-1);s++){
vector<int>t(W-1);
for(int k=0;k<W-1;k++){
if((s>>k)&1){t[k]=1;}
}
bool ok=true;
for(int k=0;k<W-2;k++){
if(t[k]==1&&t[k+1]==1){ok=false;}
}
if(ok){
if(j<W-1&&t[j]){(dp[i+1][j+1]+=dp[i][j])%=mod;}
else if(j>0&&t[j-1]){(dp[i+1][j-1]+=dp[i][j])%=mod;}
else{(dp[i+1][j]+=dp[i][j])%=mod;}
}
}
}
}
cout<<dp[H][K-1]<<endl;
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;
#define MAX 10000000
int main()
{
string s;
cin >> s;
if(s=="SUN"){
cout << 7 << endl;
}
else if(s=="MON"){
cout << 6 << endl;
}
else if(s=="TUE"){
cout << 5 << endl;
}
else if(s=="WED"){
cout << 4 << endl;
}
else if(s=="THU"){
cout << 3 << endl;
}
else if(s=="FRI"){
cout << 2 << endl;
}
else if(s=="SAT"){
cout << 1 << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
int A, B, C, D;
cin >> A >> B >> C >> D;
if ((A + B) > (C + D)) {
cout << "Left" <<endl;
}
if ((A + B) == (C + D)) {
cout << "Balanced" <<endl;
}
if ((A + B) < (C + D)) {
cout << "Right" <<endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define pdd pair<double, double>
#define f first
#define s second
#define MOD 1000000007
#define mkp make_pair
#define M_PI 3.14159265358979323846
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define LOR(i,l,r) for (ll i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)
#define LORD(i,r,l) for (ll i=r;i>=l;i--)
#define INF 1000000000
#define CL(x) memset(x,0,sizeof(x))
#define DEB(x) cout << #x << " : " << x << '\n'
#define ALL(x) x.begin(), x.end()
#define SZ(x) x.size()
#define UI(x) (int)(x-'A')
#define LI(x) (int)(x-'a')
typedef long long ll;
#define MXN 500005
int N,A[MXN];
map<pii,ll> DP;
//for x|x specially
ll psum[MXN];
map<int,ll> lsta;
map<int,int> lstp;
//===
ll Ans;
int xb;
ll modexp(ll x, ll y)
{
ll Pow = x%MOD, rtn = 1;
while(y)
{
if(y&1)rtn=(rtn*Pow)%MOD;
y>>=1;
Pow=(Pow*Pow)%MOD;
}
return rtn;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>N;
FOR(i,1,N)
{
cin>>A[i];
xb^=A[i];
}
int xf=0;
Ans=1;
FOR(i,1,N-1)
{
xf^=A[i];
xb^=A[i];
//0|0 case
psum[i]=psum[i-1]+( xf==0 && xb==0 );
ll za[4];
za[1]=DP[mkp(xb?xb:xf,1)];
za[2]=DP[mkp(xb?xb:xf,2)];
za[3]=DP[mkp(xb,3)];
//(even x)|x case
if( xf==0 && xb!=0 )
{
Ans=(Ans+za[2])%MOD;
DP[mkp(xb,1)]=(za[1]+za[2])%MOD;
}
//(odd x)|0 case
if( xf!=0 && xb==0 )
{
DP[mkp(xf,2)]=(za[1]+za[2]+1)%MOD;
}
//(odd x)|x case
if( xf==xb && xf )
{
if( lstp.find(xf)!=lstp.end() )
{
int lp = lstp[xf];
ll la = lsta[xf];
ll na = (la+za[3]*(psum[i-1]-psum[lp]))%MOD;
Ans=(Ans+na)%MOD;
lsta[xf]=na;
DP[mkp(xf,3)]=(za[3]+na)%MOD;
}
else
{
DP[mkp(xf,3)]=lsta[xf]=1;
Ans=(Ans+1)%MOD;
}
lstp[xf]=i;
}
}
if(psum[N-1])
{
ll Zans=modexp(2,psum[N-1]);
Ans=(Ans+Zans-1)%MOD;
}
cout<<Ans<<'\n';
return 0;
}
/*
3
1 2 3
5
0 0 0 0 0
*/
| #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=998244353;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
//---------------------------------------------------------------------------------------------------
int main(void){
// Your code here!
vector<int> d;
int n;cin >> n;
d.resize(n);
vector<int> v(n,0);
rep(i,n) {
cin >> d[i];
v[d[i]]++;
}
if (d[0] != 0) {
cout << 0 << endl;
return 0;
}
rep(i,n) {
if(i != 0 && d[i] ==0) {
cout << 0 << endl;
return 0;
}
}
ll ans = 1;
int ma = 0;
rep(i,n) chmax(ma,d[i]);
FOR(i,2,ma) {
ll ex = v[i-1];
rep(j,v[i]) {
ans *= ex;
ans %= MOD;
}
}
cout << ans << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;
#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back
int main()
{
ll N, M;
cin >> N >> M;
vec s(M), c(M);
REP(i,0,M) {
cin >> s[i] >> c[i];
--s[i];
}
ll d = 1;
bool f = true;
REP(i,0,N) d *= 10;
REP(i,N==1?0:d/10,d) {
string S = to_string(i);
f = true;
REP(j,0,M) {
if(!(s[j] < SZ(S) && S[s[j]]-'0' == c[j])) {
f = false;
break;
}
}
if(f) {
PR(i);
break;
}
}
if(!f) PR(-1);
return 0;
}
/*
*/ | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
void solve() {
int n, m;
cin >> n >> m;
vector<char> res(n, 0);
for (int i = 1; i <= m; i++) {
int s; char c;
cin >> s >> c;
s--;
if (res[s] == 0) res[s] = c;
else if (res[s] != c) {
cout << -1 << '\n';
return;
}
}
if (n > 1) {
if (res[0] == '0') {
cout << -1 << '\n';
return;
}
if (res[0] == 0) {
res[0] = '1';
}
}
for (auto &i : res) {
if (i == 0) cout << '0';
else cout << i;
}
cout << '\n';
}
signed main() {
#ifdef _DEBUG
// freopen("in" , "r", stdin );
// freopen("out", "w", stdout);
#endif
ios::sync_with_stdio(0); cin.tie(0);
int T = 1;
// cin >> T;
while (T--) solve();
}
| 1 |
#include <stdio.h>
int main(){
int m,a,b,x,y,r,g,i;
for(;scanf("%d%d%d%d",&m,&a,&b,&x)>3;){
for(g=0,i=1;i<m;i++){
scanf("%d",&y);
if(a<=i&&i<=b && x-y>=g)g=x-y,r=i;
x=y;
}
printf("%d\n",r);
}
return 0;
} | #include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int m, nmin, nmax;
while (cin >> m >> nmin >> nmax) {
if (m == 0 && nmin == 0 && nmax == 0) {
break;
}
vector<int> d(m);
for (int i = 0; i < m; i++) {
cin >> d[i];
}
int MAX = d[nmin-1]-d[nmin];
int maxn = nmin;
for (int i = nmin-1; i <= nmax-1; i++) {
int mm = d[i]-d[i+1];
if (mm >= MAX) {
MAX = mm;
maxn = i+1;
}
//cout << MAX << ' ' << maxn << endl;
}
cout << maxn << endl;
}
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
template<typename T>
struct Segtree {
int n;
T e;
vector<T> dat;
typedef function<T(T a, T b)> Func;
Func f;
Segtree(){}
Segtree(int n_input, Func f_input, T e_input){
initialize(n_input, f_input, e_input);
}
void initialize(int n_input, Func f_input, T e_input){
f = f_input;
e = e_input;
n = 1;
while(n < n_input) n <<= 1;
dat.resize(2*n-1, e);
}
void update(int k, T a){
k += n - 1;
dat[k] = a;
while(k > 0){
k = (k - 1)/2;
dat[k] = f(dat[2*k+1], dat[2*k+2]);
}
}
T get(int k){
return dat[k+n-1];
}
T between(int a, int b){
return query(a, b+1, 0, 0, n);
}
T query(int a, int b, int k, int l, int r){
if(r<=a || b<=l) return e;
if(a<=l && r<=b) return dat[k];
T vl = query(a, b, 2*k+1, l, (l+r)/2);
T vr = query(a, b, 2*k+2, (l+r)/2, r);
return f(vl, vr);
}
};
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
vector<int> par;
vector<int> sz;
UnionFind(int n=0){
if(n>0) initialize(n);
}
void initialize(int n){
par.resize(n);
sz.resize(n);
for(int i=0; i<n; i++){
par[i] = i;
sz[i] = 1;
}
}
int find(int x){
if(par[x] == x){
return x;
}else{
return par[x] = find(par[x]);
}
}
void unite(int x, int y){
x = find(x);
y = find(y);
if(x == y) return;
if(sz[x] < sz[y]){
par[x] = y;
sz[y] += sz[x];
}else{
par[y] = x;
sz[x] += sz[y];
}
}
bool same(int x, int y){
return find(x) == find(y);
}
};
int main(){
int N;
int64_t D, A[200000];
cin >> N >> D;
for(int i=0; i<N; i++) cin >> A[i];
typedef pair<int64_t, int> P;
const int64_t INF = 1e18;
const P INFP = {INF, 0};
Segtree<P> stL(N, [](P a, P b){ return min(a, b);}, INFP);
Segtree<P> stR(N, [](P a, P b){ return min(a, b);}, INFP);
vector<int> order;
for(int i=0; i<N; i++) order.push_back(i);
sort(order.begin(), order.end(), [&](int i, int j){ return A[i] < A[j];});
vector<vector<int64_t>> edges;
for(int i : order){
auto p = stL.between(0, i);
if(p != INFP){
int64_t cost = p.first + A[i] - (N-i)*D;
edges.push_back({cost, i, p.second});
}
p = stR.between(i, N-1);
if(p != INFP){
int64_t cost = p.first + A[i] - i*D;
edges.push_back({cost, i, p.second});
}
stL.update(i, {A[i] + (N-i)*D, i});
stR.update(i, {A[i] + i*D, i});
}
sort(edges.begin(), edges.end());
UnionFind uf(N);
int64_t ans = 0;
for(auto& e : edges){
if(!uf.same(e[1], e[2])){
uf.unite(e[1], e[2]);
ans += e[0];
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
int n, k;
scanf("%d%d", &n, &k);
vector<int> A(n);
for (int i = 0; i < n; ++i) scanf("%d", &A[i]);
for (int i = 0; i < k; ++i) {
vector<int> D(n + 1);
for (int j = 0; j < n; ++j) {
D[max(0, j - A[j])]++;
D[min(n, j + A[j] + 1)]--;
}
bool no = false;
for (int i = 0; i < n; ++i) {
if (i) A[i] = A[i - 1];
else A[i] = 0;
A[i] += D[i];
if (A[i] < n) no = true;
}
if (!no) break;
}
for (int i = 0; i < n; ++i) printf("%d ", A[i]);
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,L;
cin>>N>>L;
int A[N];
for(int i=0;i<N;i++){
A[i]=L+i;
}
int sum=0;
if(L>=0){
for(int i=1;i<N;i++){
sum+=A[i];
}
}else if(L<=-N){
for(int i=0;i<N-1;i++){
sum+=A[i];
}
}else{
for(int i=0;i<N;i++){
sum+=A[i];
}
}
cout<<sum<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
ll GCD(ll a, ll b) {
return a % b ? GCD(b, a % b): b;
}
vector<pair<ll, ll> > prime_factorize(ll n) {
vector<pair<ll,ll>> res;
for (ll a = 2; a * a <= n; ++a) {
if (n % a != 0) continue;
ll ex = 0; // 指数
// 割れる限り割り続ける
while (n % a == 0) {
++ex;
n /= a;
}
// その結果を push
res.push_back({a, ex});
}
// 最後に残った数について
if (n != 1) res.push_back({n, 1});
return res;
}
int main() {
ll A, B;
cin >> A >> B;
ll g = GCD(max(A, B), min(A,B));
vector<pair<ll,ll>> vec_f = prime_factorize(g);
cout << vec_f.size() + 1 << endl;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
int main(){
ll N;
cin >> N;
vector<double> A(N,0);
for(ll i=0;i<N;i++){
cin>>A[i]
;}
sort(A.begin(), A.end());
ll ans=0;
for(ll i=N-1;i>=1;i--){
for(ll j=0;j<=40;j++){
if(upper_bound(A.begin(), A.end()-(N-i), (1<<j)-A[i])!=lower_bound(A.begin(), A.end()-(N-i), (1<<j)-A[i]))
{*lower_bound(A.begin(), A.end()-(N-i), (1<<j)-A[i])-=0.0000001;ans++;break;}
}
;}
cout<<ans<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int N = 1e5+5;
int n, m, v, p, a[N], ans; i64 s[N];
int main()
{
scanf("%d%d%d%d", &n, &m, &v, &p), ans = p;
for(int i = 1; i <= n; ++i) scanf("%d", a+i);
sort(a+1, a+1+n, greater<int>());
for(int i = 1; i <= n; ++i) s[i] = s[i-1]+a[i];
for(int i = p+1; i <= n&&a[i]+m >= a[p]; ++i)
if((i64)m*v <= (p-1ll)*m+(n-i+1ll)*m+i64(i-p)*(a[i]+m)-(s[i-1]-s[p-1])) ++ans; else break;
printf("%d\n", ans);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,s,n) for(int i = s; i < (int)(n); i++)
int main() {
int k,x;
cin >> k >> x;
x = x-k+1;
rep(i,0,2*k-1){
cout << x+i;
if(i != 2*k-2) cout << " ";
else cout << "" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
#define MOD 1000000007
void solve() {
string s;
ll n, ans;
cin >> n >> s;
vi r, g;
for (int i = 0; i < n; ++i) {
if (s[i] == 'R')
r.push_back(i);
else if (s[i] == 'G')
g.push_back(i);
}
ans = (ll)r.size() * (ll)g.size() * (n - (ll)r.size() - (ll)g.size());
for (auto &i : r) {
for (auto &j : g) {
int k1 = 2 * i - j, k2 = 2 * j - i, k3 = (i + j) / 2;
if (k1 >= 0 && k1 < n && s[k1] == 'B')
--ans;
if (k2 >= 0 && k2 < n && s[k2] == 'B')
--ans;
if ((i + j) % 2 == 0 && s[k3] == 'B')
--ans;
}
}
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 123455, LG = 60;
ll n, m, k, A[N], P[N], R[LG][N];
int main()
{
scanf("%lld", &n);
for (int i = 0; i < n; i++)
scanf("%lld", &A[i]), P[i] = i;
scanf("%lld%lld", &m, &k);
for (int i = 0; i < m; i++)
{
int a;
scanf("%lld", &a);
swap(P[a], P[a - 1]);
}
for (int i = 0; i < n; i++)
R[0][i] = P[i];
for (int j = 1; j < LG; j++)
for (int i = 0; i < n; i++)
R[j][i] = R[j - 1][R[j - 1][i]];
printf("%lld\n", A[0]); ll nw = A[0];
for (int i = 1; i < n; i++)
{
int id = i;
for (int j = 0; j < LG; j++)
if ((k >> j) & 1LL)
id = R[j][id];
nw += A[id] - A[id - 1];
printf("%lld\n", nw);
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) (a).begin(), (a).end()
#define pw(x) (1ll<<(x))
#define lb(x) ((x) & -(x))
#define endl "\n"
#define FI(x) freopen(#x".in","r",stdin)
#define FO(x) freopen(#x".out","w",stdout)
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
//typedef uniform_int_distribution<ll> RR;
const int P = 1e9 + 7;
//ll rnd(ll l, ll r) { mt19937 gen(rand()); RR dis(l, r); return dis(gen); }
int add(int a, int b) {if((a += b) >= P) a -= P; return a < 0 ? a + P : a;}
int mul(int a, int b) {return 1ll * a * b % P;}
int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----
const int N = 1e5 + 7;
ll n, m, p[N], b[N], a[N], ans[N], now, vis[N], pp[N];
ll k;
int main(){
//FI(a);
ios::sync_with_stdio(0);
cin.tie(0);
//cout << setiosflags(ios::fixed);
//cout << setprecision(2);
cin >> n;
rep(i, 1, n+1) cin >> a[i];
per(i, 1, n+1) a[i] -= a[i-1];
// rep(i, 1, n+1) de(a[i]);
cin >> m >> k;
rep(i, 1, m+1) cin >> b[i];
rep(i, 1, n + 1) p[i] = i;
rep(i, 1, m + 1) swap(p[b[i]], p[b[i]+1]);
rep(i, 1, n+1) pp[p[i]] = i;
rep(i, 1, n+1) p[i] = pp[i];
// rep(i, 1, n+1) de(p[i]);
rep(i, 1, n+1) if (!vis[i]){
now = i;
vi tmp;
while (1) {
vis[now] = 1;
tmp.pb(now);
now = p[now];
if (now == i) break;
}
//de(sz(tmp));
rep(i, 0, sz(tmp)) {
int u = (i + k) % sz(tmp);
//de(tmp[u]);
ans[tmp[u]] = a[tmp[i]];
}
}
//rep(i, 1, n+1) de(ans[i]);
//de(a[1]);
rep(i, 1, n+1) ans[i] += ans[i-1], cout << ans[i] << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)
struct Problem {
UL S[2001][2001] = {};
UL J1[2001][2001] = {};
UL J2[2001][2001] = {};
void Query() {
UL y1, y2, x1, x2; cin >> y1 >> x1 >> y2>> x2;
y1--; x1--;
UL mass = S[x2][y2] + S[x1][y1] - S[x1][y2] - S[x2][y1];
UL J1s = J1[x2][y2] + J1[x1 + 1][y1] - J1[x1 + 1][y2] - J1[x2][y1];
UL J2s = J2[x2][y2] + J2[x1][y1 + 1] - J2[x1][y2] - J2[x2][y1 + 1];
cout << (mass - J1s - J2s) << endl;
}
void Solve() {
UL H, W; cin >> H >> W;
UL Q; cin >> Q;
rep(y, H) rep(x, W) {
char c; cin >> c;
S[x + 1][y + 1] = (c - '0');
}
rep(y, H) rep(x, W) if (S[x][y + 1] && S[x + 1][y + 1]) J1[x + 1][y + 1] = 1;
rep(y, H) rep(x, W) if (S[x + 1][y] && S[x + 1][y + 1]) J2[x + 1][y + 1] = 1;
rep(y, H) rep(x, W) S[x + 1][y + 1] += S[x][y + 1];
rep(y, H) rep(x, W) S[x + 1][y + 1] += S[x + 1][y];
rep(y, H) rep(x, W) J1[x + 1][y + 1] += J1[x][y + 1];
rep(y, H) rep(x, W) J1[x + 1][y + 1] += J1[x + 1][y];
rep(y, H) rep(x, W) J2[x + 1][y + 1] += J2[x][y + 1];
rep(y, H) rep(x, W) J2[x + 1][y + 1] += J2[x + 1][y];
rep(i, Q) Query();
}
Problem();
};
int main() {
unique_ptr<Problem> p(new Problem());
p->Solve();
return 0;
}
Problem::Problem() {
cout << fixed << setprecision(10);
} | #include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...)
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=2020;
int a[N][N],el[N][N],eu[N][N],p[N][N];
int32_t main(){
int n,m,q;
cin>>n>>m>>q;
for(int i=1;i<=n;++i){
string s;cin>>s;s="#"+s;
for(int j=1;j<=m;++j){
a[i][j]=s[j]-'0';
int pl=a[i][j]&a[i][j-1];
int pu=a[i][j]&a[i-1][j];
p[i][j]=p[i-1][j]+p[i][j-1]-p[i-1][j-1]+a[i][j];
el[i][j]=el[i-1][j]+el[i][j-1]-el[i-1][j-1]+pl;
eu[i][j]=eu[i-1][j]+eu[i][j-1]-eu[i-1][j-1]+pu;
}
}
while(q--){
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
int v=p[x2][y2]-p[x2][y1-1]-p[x1-1][y2]+p[x1-1][y1-1];
int e=el[x2][y2]-el[x2][y1]-el[x1-1][y2]+el[x1-1][y1]+
eu[x2][y2]-eu[x2][y1-1]-eu[x1][y2]+eu[x1][y1-1];
cout<<v-e<<'\n';
}
return 0;
} | 1 |
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323
template <class T>
inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
T GCD(T a, T b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
return (a * b) / GCD(a, b);
}
using namespace std;
//#inculude <bits/stdc++.h>
#define int long long
signed main() {
int n;
cin >> n;
repk(i, n, 1000) {
string s = to_string(i);
if (s[0] == s[1] && s[0] == s[2]) {
cout << s << endl;
return 0;
}
}
} | #include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
int R;
cin >> R;
double ans = (2 * R) * acos(-1.0);
cout << setprecision(20) << ans << endl;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
long long x;
cin>>x;
if(x/11==0){
if(x>6){
cout<<2<<endl;
}else{
cout<<1<<endl;
}
return 0;
}else{
if(x%11==0){
cout<<x/11*2<<endl;
}else if((x-x/11*11)>6){
cout<<x/11*2+2<<endl;
}else{
cout<<x/11*2+1<<endl;
}
}
return 0;
} | #include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
int main() {
long long x;
cin >> x;
long long ans = 0;
if (x % 11 == 0) {
ans = x / 11 * 2;
}
else if(x % 11 <= 6) {
ans = x / 11 * 2 + 1;
}
else {
ans = x / 11 * 2 + 2;
}
cout << ans << endl;
return 0;
} | 1 |
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
using pii=pair<int,int>;
using vs=vector<string>;
using vpii=vector<pii>;
using si=set<int>;
#define REP(i,a) for(int i=0;i<a;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rREP(i,a) for(int i=(a)-1;i>=0;i--)
#define rFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define out(S) cout<<(S)<<endl;
#define beginend(v) (v).begin(),(v).end()
#define IfOut(condition,text) if(condition){out(text);return 0;}
#define IfOutElse(condition,if_text,else_text) if(condition){out(if_text);return 0;}else{out(else_text);return 0;}
#define mod(s) ((s)%(ll)(1e9+7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a*modpow((ll)b,(ll)(1e9+5))))
#define pb(i) push_back(i)
#define fst first
#define snd second
#define Foreach(item,collection) for(auto item:collection)
#define INF 1e10
#define removeAll(vec,deleg) auto itr=remove_if(beginend(vec),deleg);vec.erase(itr,vec.end());
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
vector<ll> sieveOfEratosthenes(int max) {ll prime;double sqrtmax = sqrt(max);vector<ll> primeVec, searchVec;FOR(i, 2, max + 1) searchVec.push_back(i);do{prime = searchVec[0];primeVec.push_back(prime);auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });searchVec.erase(itr, searchVec.end());} while (prime < sqrtmax);primeVec.reserve(primeVec.size() + searchVec.size());primeVec.insert(primeVec.end(), beginend(searchVec));return primeVec;}
ll sum(vi v) {ll sum=0;Foreach(i,v){sum+=i;}return sum;}
#define ShowAll(v) Foreach(i,v) out(i);
int shouhi(int v,int x,int y){
double motone=(double)v*100.0/(100.0+x);
return motone*(100.0+y)/100.0;
}
int main(){
vi ans;
int m,nmin,nmax;
while (cin>>m>>nmin>>nmax,(m||nmin||nmax))
{
vi P(m);
REP(i,m)cin>>P[i];
int n=nmin-1,pmax=0;
FOR(i,nmin-1,nmax){
if(pmax<=P[i]-P[i+1]){
pmax=P[i]-P[i+1];
n=i;
}
}
ans.pb(n+1);
}
ShowAll(ans);
return 0;
} | #include <iostream>
using namespace std;
int main(void){
while(1){
int m, nmin, nmax;
cin >> m;
cin >> nmin;
cin >> nmax;
if(m == 0 && nmin == 0 && nmax == 0){ return 0; }
int P[m];
for(int i = 0 ; i < m ; i++){
cin >> P[i];
}
int ans = nmin;
int max = -1;
for(int i = nmin ; i <= nmax ; i++){
if(max >= P[i] - P[i - 1]){
max = P[i] - P[i - 1];
ans = i;
}
}
cout << ans << endl;
}
return 0;
} | 1 |
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
int n,m;
cin >> n >> m;
int l[m],r[m];
for(int i = 0; i < m; i++) {
cin >> l[i] >> r[i];
}
int ans = *max_element(l,l+m) - *min_element(r,r+m);
if(ans > 0) {
cout << 0 << endl;
}else {
cout << abs(ans)+1 << endl;
}
return 0;
} | #include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
int main()
{
int n,m;
cin >> n >> m;
int max = 0,min = 1e9;
vector<vector<int>> G(m,vector<int>(2));
for (int i = 0; i < m; i++)
{
for (int j = 0; j < 2; j++)
{
cin >> G[i][j];
}
if (max < G[i][0])
{
max = G[i][0];
}
if (min > G[i][1])
{
min = G[i][1];
}
}
if (max > min)
{
cout << "0" << endl;
}else{
cout << min-max+1 << endl;
}
} | 1 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;
int main(){
ll X, Y;
cin >> X >> Y;
ll cnt = LINF;
rep(i, 2) rep(j, 2){
ll x = X, y = Y;
ll tmp = 0;
if (i) x *= -1, tmp++;
if (j) y *= -1, tmp++;
if (x <= y) {
tmp += y - x;
cnt = min(cnt, tmp);
}
}
cout << cnt << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(){
long x,y;
cin >> x >> y;
if(x==y) cout << 0 << endl;
else if(y-x==1||y==-x) cout << 1 << endl;
else cout << min({abs(x-y),abs(x+y-1),abs(x+y+1),abs(x-y+2)})+2 << endl;
}
| 1 |
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
ll INF = 1LL << 60;
vector<vector<char>> vec;
vector<pair<int, int>> direct = {{1,0},{-1, 0}, {0,1}, {0, -1}};
vector<vector<int>> dist;
queue<pair<int, int>> que;
int H, W;
int
bfs()
{
while(!que.empty()){
int x = que.front().first;
int y = que.front().second;
que.pop();
rep(i, 0, 4){
int dx = x + direct[i].first;
int dy = y + direct[i].second;
if(dx < 0 || dx >= H || dy < 0 || dy >= W) continue;
if(vec[dx][dy] == '#') continue;
if(dist[dx][dy] == -1){
dist[dx][dy] = 1 + dist[x][y];
que.push({dx, dy});
}
}
}
int ans = 0;
rep(i, 0,H){
rep(k, 0, W){
ans = max(ans, dist[i][k]);
}
}
return ans;
}
int
main() {
cin >> H >> W;
vec.resize(H);
dist.resize(H, vector<int>(W, -1));
rep(i, 0, H){
rep(k, 0, W){
char c; cin >> c;
vec[i].push_back(c);
if(vec[i][k] == '#') dist[i][k] = 0, que.push({i, k});
}
}
int ans = bfs();
cout << ans << endl;
}
| #include <iostream>
#include <vector>
using namespace std;
int main(){
int n, t0;
cin >> n >> t0;
vector<int> t(n);
for(int i = 0; i < n; i++) cin >> t[i];
long long int ans = t0;
for(int i = 1; i < n; i++){
if(t[i]-t[i-1] >= t0) ans += t0;
else ans += t[i]-t[i-1];
}
cout << ans << endl;
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)
using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;
int main() {
int N,K;
cin >> N >> K;
if(N%K==0){
cout << 0 << endl;
}
else{
cout << 1 << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
int main() {
int N, K; cin >> N >> K;
cout << (N + K - 1) / K - N / K << endl;
return 0;
} | 1 |
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 600000
int main() {
int n, k;
scanf("%d", &n);
printf("%d\n", n*n*n);
return 0;
}
| #include<iostream>
using namespace std;
int main(){
int a,b;
cin>>a;
for(int i=3;i<=a;i++){
b=0;
if(i%3==0 || i%10==3){
cout<<" "<<i;
b=1;
}
if(i>=30 && b==0){
for(int j=i;j>=9;){
j=j/10;
if(j%10==3){
cout<<" "<<i;
break;
}
}
}
}
cout<<endl;
} | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.