code_file1
stringlengths 80
4k
| code_file2
stringlengths 91
4k
| similar_or_different
int64 0
1
|
---|---|---|
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
LL A[1010][1010];
int n,Color[1010][1010];
int N,P[101010],T1[1010*1010],T2[1010*1010],n1,n2;
bool f[101010],vis[1010][1010];
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
void Pre(){
for (int i=2;i<=100000;i++){
if (!f[i]) P[++N]=i;
for (int j=i+i;j<=100000;j+=i) f[j]=1;
}
}
void Dfs(int x,int y,int c){
Color[x][y]=c; vis[x][y]=1;
for (int k=0;k<4;k++){
int x1=x+dx[k],y1=y+dy[k];
if (x1>=1&&x1<=n&&y1>=1&&y1<=n&&!vis[x1][y1])
Dfs(x1,y1,1-c);
}
}
void _Num(){
for (int i=1;i<=n;i++) for (int j=1;j<=n;j++)
if (Color[i][j])
T1[++n1]=i+j,T2[++n2]=i-j;
sort(T1+1,T1+n1+1); sort(T2+1,T2+n2+1);
n1=unique(T1+1,T1+n1+1)-T1-1;
n2=unique(T2+1,T2+n2+1)-T2-1;
for (int i=1;i<=n;i++) for (int j=1;j<=n;j++)
if (Color[i][j]){
int p1=lower_bound(T1+1,T1+n1+1,i+j)-T1;
int p2=lower_bound(T2+1,T2+n2+1,i-j)-T2;
A[i][j]=(LL)P[p1]*(LL)P[n1+p2];
}
}
LL gcd(LL a,LL b){
if (!b) return a;
return gcd(b,a%b);
}
LL Lcm(LL a,LL b){
LL g=gcd(a,b);
return (a/g)*b;
}
int main(){
scanf("%d",&n);
if (n==2){
printf("4 7\n23 10"); return 0;
}
Pre(); Dfs(1,1,1); _Num();
for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (!Color[i][j]){
LL g=1;
for (int k=0;k<4;k++){
int x1=i+dx[k],y1=j+dy[k];
if (x1>=1&&x1<=n&&y1>=1&&y1<=n)
g=Lcm(g,A[x1][y1]);
}
A[i][j]=g+1;
}
for (int i=1;i<=n;i++){
for (int j=1;j<=n;j++) printf("%lld ",A[i][j]);
printf("\n");
}
} | #include<bits/stdc++.h>
using namespace std;
long long a[1100],na,n;
bool p(int x){for (int i=2;i<x;i++)if (x%i==0)return 0;return 1;}
int main(){
for (int i=2;i<=8000;i++)if (p(i))a[++na]=i;
cin>>n;
for (int i=1;i<=n;i++){
for (int j=1;j<=n;j++)
if ((i+j)%2==0)cout<<a[(i+j)/2]*a[(i-j+n)/2+n+1]<<' ';
else cout<<a[(i+j)/2]*a[(i-j+n+1)/2+n+1]*a[(i+j+1)/2]*a[(i-j+n-1)/2+n+1]+1<<' ';
cout<<endl;
}
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10;
int s[maxn], t[maxn];
int a[maxn], b[maxn];
int fail[maxn];
int n, m;
void getfail()
{
memset(fail, 0, sizeof(fail));
int len = n;
int j = 0, k = fail[0] = -1;
while (j < len)
{
while (k != -1 && t[j] != t[k])
k = fail[k];
fail[++j] = ++k;
}
}
int kmp()
{
int i = 0, j = 0;
int ret = 0;
while (i < n * 2)
{
while (j != -1 && s[i] != t[j])
j = fail[j];
i++, j++;
if (j == m)
{
//printf("debug: i: %d j: %d\n", i, j);
if (i < 2 * n)
printf("%d %d\n", i - j, a[(i - j)] ^ b[0]);
ret++, j = fail[j];
}
}
return ret;
}
int main()
{
scanf("%d", &n);
m = n;
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
for (int i = 0; i < n; i++)
scanf("%d", &b[i]);
for (int i = 0; i < n; i++)
s[i] = a[i] ^ a[(i + 1) % n], t[i] = b[i] ^ b[(i + 1) % n];
for (int i = n; i < 2 * n; i++)
s[i] = s[i - n];
/* for (int i = 0; i < 2 * n; i++)
cout << s[i] << " ";
cout << endl;
for (int i = 0; i < n; i++)
cout << t[i] << " ";
cout << endl; */
getfail();
kmp();
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
struct Compress {
vector<T> xs;
Compress(const vector<T>& vs) : xs(vs) {
sort(xs.begin(), xs.end());
xs.erase(unique(xs.begin(), xs.end()), xs.end());
}
int compress(const T& x) {
return lower_bound(xs.begin(), xs.end(), x) - xs.begin();
}
T decompress(int i) {
return xs[i];
}
};
vector<int> suffix_array(vector<int>& s) {
int n = s.size();
Compress<int> comp(s);
vector<int> t(n);
for (int i = 0; i < n; i++) t[i] = comp.compress(s[i]);
vector<int> p(n), c(n), cnt(n);
for (int i = 0; i < n; i++) cnt[t[i]]++;
for (int i = 1; i < n; i++) cnt[i] += cnt[i-1];
for (int i = 0; i < n; i++) p[--cnt[t[i]]] = i;
int cl = 0;
for (int i = 1; i < n; i++) {
if (s[p[i]] != s[p[i-1]]) cl++;
c[p[i]] = cl;
}
vector<int> pn(n), cn(n);
for (int h = 0; (1 << h) < n; h++) {
for (int i = 0; i < n; i++) {
pn[i] = p[i] - (1 << h);
if (pn[i] < 0) pn[i] += n;
}
fill(cnt.begin(), cnt.end(), 0);
for (int i = 0; i < n; i++) cnt[c[pn[i]]]++;
for (int i = 1; i < n; i++) cnt[i] += cnt[i-1];
for (int i = n - 1; i >= 0; i--) {
cnt[c[pn[i]]]--;
p[cnt[c[pn[i]]]] = pn[i];
}
cn[p[0]] = 0;
cl = 0;
for (int i = 1; i < n; i++) {
pair<int, int> cur(c[p[i]], c[(p[i] + (1 << h)) % n]);
pair<int, int> prev(c[p[i-1]], c[(p[i-1] + (1 << h)) % n]);
if (cur != prev) cl++;
cn[p[i]] = cl;
}
swap(c, cn);
}
return p;
}
int bin_search(vector<int>& a, vector<int>& b, vector<int>& sa, bool lower) {
int n = a.size();
int lb = -1, ub = n;
while (ub - lb > 1) {
int m = (lb + ub) / 2;
bool flag = false;
for (int i = 0; i < n; i++) {
int j = (sa[m] + i) % n;
if (a[i] < b[j]) {
ub = m;
flag = true;
break;
}
if (a[i] > b[j]) {
lb = m;
flag = true;
break;
}
}
if (!flag) {
if (lower) ub = m;
else lb = m;
}
}
return ub;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vector<int> a(N), b(N);
for (int i = 0; i < N; i++) cin >> a[i];
for (int i = 0; i < N; i++) cin >> b[i];
vector<int> c(N), d(N);
for (int i = 0; i < N; i++) {
c[i] = a[i] ^ a[(i+1) % N];
d[i] = b[i] ^ b[(i+1) % N];
}
auto sa = suffix_array(d);
int lb = bin_search(c, d, sa, true);
int ub = bin_search(c, d, sa, false);
vector<pair<int, int>> ans;
for (int i = lb; i < ub; i++) {
int k = (N - sa[i]) % N;
int x = a[k] ^ b[0];
ans.push_back({k, x});
}
sort(ans.begin(), ans.end());
for (auto& p : ans) cout << p.first << " " << p.second << "\n";
} | 1 |
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;
const int inf = (int)1e9;
ll gcd(ll a, ll b) {
if (b > a) {
ll tmp = b;
b = a;
a = tmp;
}
if (a%b == 0)return b;
else return gcd(b, a%b);
}
ll dp[110][10];
ll fib[1010];
int main(void){
int H,W,K;
cin>>H>>W>>K;
dp[0][1]=1;
fib[0]=1;
fib[1]=1;
for(int i=2;i<1010;i++){
fib[i] = (fib[i-1]+fib[i-2])%N;
}
for(int i=1;i<=H;i++){
for(int j=1;j<=W;j++){
if(j==1){
dp[i][j] = (dp[i-1][j]*fib[W-1])%N;
if(W-j>=0){
ll t = (dp[i-1][j+1]*fib[W-j-1])%N;
dp[i][j] = (dp[i][j]+t)%N;
}
}
else{
if(j==W){
dp[i][j] = (dp[i-1][j]*fib[j-1])%N;
if(j-2>=0){
ll t = (dp[i-1][j-1]*fib[j-2])%N;
dp[i][j] = (dp[i][j]+t)%N;
}
}
else{
ll t1 = (fib[j-2]*fib[W-j])%N;
ll t2 = (fib[j-1]*fib[W-j-1])%N;
ll t3 = (fib[j-1]*fib[W-j])%N;
t1 = (dp[i-1][j-1]*t1)%N;
t2 = (dp[i-1][j+1]*t2)%N;
t3 = (dp[i-1][j]*t3)%N;
dp[i][j] = ((t1+t2)%N+t3)%N;
}
}
}
}
/*for(int i=1;i<=H;i++){
for(int j=1;j<=W;j++){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
cout<<dp[H][K]<<endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll A[222222];
ll N;
cin >> N;
ll i;
for(i=0;i<=N-1;i++)
cin >> A[i];
ll sum[222222] = {0}; //sum[i]=A[i]までの和
sum[0] = A[0];
for(i=1;i<=N-1;i++){
sum[i] = (sum[i-1] + A[i]) % 1000000007;
}
ll ans = 0;
for(i=0;i<=N-2;i++)
ans = (ans + A[i] * (sum[N-1] - sum[i])) % 1000000007;
if(ans < 0) ans += 1000000007;
cout << ans << endl;
} | 0 |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
const int N=1e6+10;
int n,q[N],ans;char s[N],t[N];
int main(){
scanf("%d%s%s",&n,s+1,t+1);
int flag=0;
rep(i,1,n) if(s[i]^t[i]){flag=1;break;}
if(!flag) return puts("0"),0;
int i=n,j=n,l=1,r=0;
while(i){
while(i>1&&t[i]==t[i-1]) --i;
//printf("%d %d\n",i,j);
while(j&&(s[j]!=t[i]||j>i)) --j;
if(!j) return puts("-1"),0;
while(l<=r&&q[l]-(r-l+1)>=i) ++l;
if(i!=j) q[++r]=j;
ans=max(ans,r-l+2);--i;
}
printf("%d\n",ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()
const int maxn = 1e6 + 100, maxc = 256;
const ll inf = 2e18, mod = 1e9 + 7;
int n, pos[maxc], R[maxn], dest[maxn], par[maxn], fen[maxn * 2];
char s[maxn], t[maxn];
vector<int> vec[maxc];
void update(int x, int val)
{
for (int ind = x + 1; ind < maxn * 2; ind += (ind & -ind))
fen[ind] += val;
}
int query(int x)
{
int res = 0;
for (int ind = x + 1; ind; ind -= (ind & -ind))
res += fen[ind];
return res;
}
bool check(int H)
{
memset(fen, 0, sizeof(fen));
update(n, -H);
update(0, H);
int cut = 0;
for (int i = n - 1; i >= 0; i--)
{
if (query(cut + i) == 0)
return false;
if (!i || t[i] != t[i - 1])
{
if (query(cut + i) < H)
cut++;
else
{
update(cut + i, -H);
update(cut + i + 1, H);
}
update(par[i] + cut, -1);
update(i + cut, 1);
}
}
return true;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
for (int i = 0; i < maxc; i++)
pos[i] = -mod;
cin >> n >> s >> t;
if (strcmp(s, t) == 0)
{
cout << 0 << endl;
return 0;
}
int ind = 0;
for (int i = 0; i < n; i++)
if (t[i] != t[i - 1])
{
for (int j = ind; j < i; j++)
R[j] = i - 1;
ind = i;
}
for (int i = ind; i < n; i++)
R[i] = n - 1;
for (int i = 0; i < n; i++)
vec[s[i]].pb(i);
ind = n;
for (int i = n - 1; i >= 0; i--)
{
while (ind - 1 > i)
{
ind--;
//cerr << "ERASE " << t[ind] << endl;
vec[s[ind]].popb();
}
if (!i || t[i] != t[i - 1])
{
if (vec[t[i]].empty())
{
//cerr << '#' << i << ' ' << t[i] << ' ' << ind << endl;
cout << -1 << endl;
return 0;
}
par[i] = vec[t[i]].back();
for (int j = vec[t[i]].back(); j < ind; j++)
vec[s[j]].popb();
ind = par[i];
}
}
for (int i = 0; i < n; i++)
if (!i || t[i] != t[i - 1])
for (int j = i; j <= R[i]; j++)
par[j] = par[i];
//for (int i = 0; i < n; i++)
// cerr << '_' << par[i];
//cerr << endl;
for (int i = 0; i < n; i++)
if ((i && par[i] < par[i - 1]) || par[i] > i)
{
//cerr << "QUIT " << i << ' ' << par[i] << endl;
cout << -1 << endl;
return 0;
}
/*while (true)
{
int x;
cin >> x;
cerr << '#' << check(x) << endl;
}*/
int l = 0, r = n + 100, mid;
while (r - l > 1)
{
mid = (l + r) / 2;
if (check(mid))
r = mid;
else
l = mid;
}
cout << r << endl;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000; // n の最大値
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 a,b,n;
cin>>a>>b>>n;
for(ll i=0; i<n; i++){
if(i%2==0){
a/=2;
b+=a;}
else{
b/=2;
a+=b;}}
cout << a << " " << b << endl;} | #include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
ll n,m,d;cin>>n>>m>>d;if(d)d=2*(n-d);else d=n;
printf("%.20f",(double)(m-1)*d/(double)(n*n));cout<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
double expected_value(int n) {
return (double)((1 + n) * n / 2) / (double)n;
}
int main() {
int n, k;
cin >> n >> k;
vector<double> ps(n + 1);
vector<double> comsum(n + 1, 0);
int p;
rep(i, n) {
cin >> p;
ps[i + 1] = expected_value(p);
comsum[i + 1] = comsum[i] + ps[i + 1];
}
double mm = 0;
for (int i = k; i <= n; i++) {
mm = max(comsum[i] - comsum[i - k], mm);
}
printf("%.6f\n", mm);
return 0;
}
|
/**
* author : Sudipta Banik Trisha
* created : September 10, 2020 5:11 PM
* Problem Name : D - Dice in Line
* Problem Limit : 2000 ms , 1024 MB
* Problem Url : https://atcoder.jp/contests/abc154/tasks/abc154_d
* @genarated by : ai-virtual-assistant
**/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
ll n,k;
cin >> n >> k;
vector<ll>v(n);
for(ll i=0; i<n; i++){
cin >> v[i];
v[i] = 1 + v[i];
}
for(ll i=1; i<n; i++){
v[i] = v[i-1] + v[i];
}
long double mxprob = (long double)v[k-1];
for(int i=k; i<n; i++) {
mxprob = max(mxprob , (long double)(v[i] - v[i-k]));
}
mxprob = mxprob / (long double)2.0;
cout << fixed << setprecision(12) << mxprob << endl;
return 0 ;
}
| 1 |
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#define MAXN 1000010
using namespace std;
int n;
char s1[MAXN],s2[MAXN];
vector<int> S[30];
int p[MAXN];
struct Queue{
deque<int> Q;
int d;
void push_back(int x){ Q.push_back(x-d); }
void push_front(int x){ Q.push_front(x-d); }
int back(){ return Q.back()+d; }
void pop_back(){ Q.pop_back(); }
void pop_front(){ Q.pop_front(); }
bool empty(){ return Q.empty(); }
int size(){ return Q.size(); }
}Q;
int main(){
#ifdef DEBUG
freopen("F.in","r",stdin);
#endif
scanf("%d",&n);
scanf("%s%s",s1+1,s2+1);
n=strlen(s1+1);
for(int i=1;i<=n;i++) S[s1[i]-'a'].push_back(i);
int ans=0;
p[n+1]=n+1;
for(int i=n;i>=1;i--){
if(s2[i]==s2[i+1] && i>=p[i+1]){
p[i]=p[i+1];
}else{
while(!S[s2[i]-'a'].empty() && S[s2[i]-'a'].back()>=p[i+1])
S[s2[i]-'a'].pop_back();
if(S[s2[i]-'a'].empty()){
puts("-1");
return 0;
}
p[i]=S[s2[i]-'a'].back();
if(i>=p[i+1]){
Q.d--;
Q.push_front(p[i+1]-1);
while(Q.back()>=i) Q.pop_back();
Q.push_back(i);
}else{
while(!Q.empty()) Q.pop_back();
if(p[i]<i) Q.push_back(i);
}
ans=max(ans,(int)Q.size());
}
}
printf("%d\n",ans);
}
| #include <cstdio>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> Q;
int n, m;
Q g[100000];
int p[10000];
int r[10000];
void init(){
rep(i, n){
p[i] = i;
r[i] = 0;
}
}
int find(int i){
return p[i] == i ? i : p[i] = find(p[i]);
}
bool same(int i, int j){
return find(i) == find(j);
}
void unite(int i, int j){
int a = find(i);
int b = find(j);
if(a == b){
return;
}
if(r[a] > r[b]){
p[b] = a;
}
else{
p[a] = b;
if(r[a] == r[b]){
++r[b];
}
}
}
int main(){
scanf("%d%d", &n, &m);
rep(i, m){
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
g[i] = Q(c, P(a, b));
}
sort(g, g + m);
init();
int ans = 0;
rep(i, m){
int a = g[i].second.first;
int b = g[i].second.second;
int c = g[i].first;
if(!same(a, b)){
unite(a, b);
ans += c;
}
}
printf("%d\n", ans);
return 0;
} | 0 |
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
template <typename T>
struct RollingHash
{
int size;
int n;
ll factor = 1;
ll b = 0;
ll mod = 0;
ll hash = 0;
vector<T> list;
int num = 0;
int head = 0;
void init(int _n, ll _b = (ll)1e8 + 7, ll _mod = (ll)1e9 + 7)
{
n = _n;
b = _b;
list.reserve(n);
mod = _mod;
auto temp = 1ll;
for (auto i = 0; i < n; ++i)
{
factor = temp;
temp = temp * b % mod;
}
}
void add(ll val)
{
if ((int)list.size() >= n)
{
hash = (((hash - list[head] * factor) % mod) + mod) % mod;
list[head] = val;
head = (head + 1) % n;
}
else
{
list.push_back(val);
}
hash = hash * b % mod;
hash = (hash + val) % mod;
}
ll getHash() { return hash; }
};
ll calcHash(vector<ll>& list, ll factor, ll mod)
{
auto hash = 0ll;
for (auto i = 0; i < (int)list.size(); ++i)
{
hash = hash * factor % mod;
hash = (hash + list[i]) % mod;
}
return hash;
}
int main()
{
int N;
cin >> N;
vector<ll> a(N);
vector<ll> b(N);
for (auto i = 0; i < N; ++i)
{
ll temp;
cin >> temp;
a[i] = temp;
a.push_back(temp);
}
for (auto& temp : b)
{
cin >> temp;
}
vector<ll> x;
for (auto i = 0; i < N; ++i)
{
x.push_back(b[0] ^ a[i]);
}
auto bitNum = 31;
auto mod = (ll)1e9 + 7;
vector<ll> rollingHashFactor = { (ll)1e8 + 7 };
vector<vector<vector<RollingHash<ll>>>> hashA
(bitNum, vector<vector<RollingHash<ll>>>(2, vector<RollingHash<ll>>((int)rollingHashFactor.size())));
vector<vector<RollingHash<ll>>> hashB
(bitNum, vector<RollingHash<ll>>((int)rollingHashFactor.size()));
for (auto i = 0; i < bitNum; ++i)
{
for (auto k = 0; k < N; ++k)
{
auto val = (b[k] >> i) & 1;
for (auto l = 0; l < (int)rollingHashFactor.size(); ++l)
{
if (k == 0)
{
hashB[i][l].init(N, rollingHashFactor[l], mod);
}
hashB[i][l].add(val);
}
}
}
vector<ll> factor;
for (auto i = 0; i < (int)rollingHashFactor.size(); ++i)
{
auto temp = 1ll;
for (auto j = 0; j < bitNum; ++j)
{
temp = temp * rollingHashFactor[i] % mod;
}
factor.push_back(temp);
}
vector<ll> correct;
for (auto i = 0; i < (int)rollingHashFactor.size(); ++i)
{
vector<ll> list;
for (auto j = 0; j < bitNum; ++j)
{
list.push_back(hashB[j][i].getHash());
}
correct.push_back(calcHash(list, factor[i], mod));
}
for (auto i = 0; i < bitNum; ++i)
{
for (auto j = 0; j < 2; ++j)
{
for (auto k = 0; k < N; ++k)
{
auto val = ((a[k] >> i) ^ j) & 1;
for (auto l = 0; l < (int)rollingHashFactor.size(); ++l)
{
if (k == 0)
{
hashA[i][j][l].init(N, rollingHashFactor[l]);
}
hashA[i][j][l].add(val);
}
}
}
}
vector<pair<int, ll>> ans;
for (auto k = 0; k < N; ++k)
{
vector<vector<ll>> list((int)rollingHashFactor.size());
for (auto i = 0; i < bitNum; ++i)
{
int j = (x[k] >> i) & 1;
for (auto l = 0; l < (int)rollingHashFactor.size(); ++l)
{
list[l].push_back(hashA[i][j][l].getHash());
}
}
auto match = true;
for (auto i = 0; i < (int)rollingHashFactor.size(); ++i)
{
auto hash = calcHash(list[i], factor[i], mod);
if (hash != correct[i])
{
match = false;
}
}
if (match != false)
{
ans.push_back({ k, x[k] });
}
for (auto i = 0; i < bitNum; ++i)
{
for (auto j = 0; j < 2; ++j)
{
auto val = ((a[k + N] >> i) ^ j) & 1;
for (auto l = 0; l < (int)rollingHashFactor.size(); ++l)
{
hashA[i][j][l].add(val);
}
}
}
}
for (auto& pair : ans)
{
cout << pair.first << " " << pair.second << endl;
}
return 0;
} | #include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;
int main(void)
{
int h, w;
int d_max=80*80;
while(scanf("%d%d", &h, &w)==2)
{
vvi a(h), b(h), c(h);
for(int y=0;y<h;y++)
{
a[y].resize(w);
for(int x=0;x<w;x++) scanf("%d", &a[y][x]);
}
for(int y=0;y<h;y++)
{
b[y].resize(w);
for(int x=0;x<w;x++) scanf("%d", &b[y][x]);
}
for(int y=0;y<h;y++)
{
c[y].resize(w);
for(int x=0;x<w;x++) c[y][x]=abs(a[y][x]-b[y][x]);
}
vector<vector<vector<bool> > > dp(h);
for(int y=0;y<h;y++)
{
dp[y].resize(w);
for(int x=0;x<w;x++)
{
dp[y][x].assign(d_max+1, false);
}
}
dp[0][0][c[0][0]]=true;
for(int y=0;y<h;y++)
{
for(int x=0;x<w;x++)
{
for(int i=0;i<=d_max;i++)
{
if(dp[y][x][i]==false) continue;
if(y+1<h)
{
int nbp=i+c[y+1][x];
int nbn=abs(i-c[y+1][x]);
dp[y+1][x][nbn]=true;
if(nbp<=d_max) dp[y+1][x][nbp]=true;
}
if(x+1<w)
{
int nbp=i+c[y][x+1];
int nbn=abs(i-c[y][x+1]);
dp[y][x+1][nbn]=true;
if(nbp<=d_max) dp[y][x+1][nbp]=true;
}
}
}
}
int ans=0;
for(ans=0;ans<=d_max && dp[h-1][w-1][ans]==false;ans++)
{
}
if(0)
{
for(int y=0;y<h;y++)
{
for(int x=0;x<w;x++)
{
printf("%d ", c[y][x]);
}
printf("\n");
}
for(int y=0;y<h;y++)
{
for(int x=0;x<w;x++)
{
printf(" [");
for(int i=0;i<=d_max;i++) if(dp[y][x][i]) printf(" %d", i);
printf(" ]");
}
printf("\n");
}
}
printf("%d\n", ans);
}
return 0;
}
| 0 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
long long N, M, V, P; cin >> N >> M >> V >> P;
vector<long long> A(N);
for(auto& t : A) cin >> t;
sort(A.begin(), A.end());
int L = -1, R = N-1;
while(R-L > 1){
int mid = (L+R)/2;
long long thr = A[mid] + M;
int gr = 0;
long long add = M;
for(int j=N-1;j>=0;j--){
if(j == mid) continue;
if(A[j] > thr){
gr++;
add += M;
} else {
if(gr+1 < P && A[j]+M > thr){
gr++;
add += M;
} else {
add += min(M, thr-A[j]);
}
}
}
if(gr < P && add >= M*V) R = mid;
else L = mid;
}
cout << N-R << endl;
} | //Author:xht37
#include <bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double
#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair
#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)
#define vi vector <int>
#define pb push_back
#define pq priority_queue
#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
using namespace std;
namespace io {
const int SI = 1 << 21 | 1;
char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
int f, t;
#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
inline void flush() {
fwrite(OB, 1, OS - OB, stdout), OS = OB;
}
inline void pc(char x) {
*OS++ = x;
if (OS == OT) flush();
}
template <class I>
inline void rd(I &x) {
for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
x *= f;
}
template <class I>
inline void rd(I &x, I &y) {
rd(x), rd(y);
}
template <class I>
inline void rd(I &x, I &y, I &z) {
rd(x), rd(y), rd(z);
}
template <class I>
inline void rda(I *a, int n) {
for (int i = 1; i <= n; i++) rd(a[i]);
}
inline void rdc(char &c) {
for (c = gc(); c < 33 || c > 126; c = gc());
}
inline void rds(char *s, int &n) {
for (c = gc(); c < 33 || c > 126; c = gc());
for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
s[n+1] = '\0';
}
inline void rds(string &s) {
for (c = gc(); c < 33 || c > 126; c = gc());
for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
}
template <class I>
inline void print(I x, char k = '\n') {
if (!x) pc('0');
if (x < 0) pc('-'), x = -x;
while (x) ch[++t] = x % 10 + '0', x /= 10;
while (t) pc(ch[t--]);
pc(k);
}
template <class I>
inline void print(I x, I y) {
print(x, ' '), print(y);
}
template <class I>
inline void print(I x, I y, I z) {
print(x, ' '), print(y, ' '), print(z);
}
template <class I>
inline void printa(I *a, int n) {
for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
}
inline void printc(char c) {
pc(c);
}
inline void prints(char *s, int n) {
for (int i = 1; i <= n; i++) pc(s[i]);
pc('\n');
}
inline void prints(string s) {
int n = s.length();
while (t < n) pc(s[t++]);
pc('\n'), t = 0;
}
struct Flush {
~Flush() {
flush();
}
} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;
namespace shai {
const int n = 1e6 + 7;
int p[n], v[n], phi[n], miu[n];
inline void init(int n) {
v[1] = phi[1] = miu[1] = 1;
for (int i = 2; i <= n; i++) {
if (!v[i]) p[++p[0]] = v[i] = i, phi[i] = i - 1, miu[i] = -1;
for (int j = 1; j <= p[0] && i * p[j] <= n && p[j] <= v[i]; j++)
v[i*p[j]] = p[j],
phi[i*p[j]] = phi[i] * (p[j] - 1 + (p[j] == v[i])),
miu[i*p[j]] = p[j] == v[i] ? 0 : -miu[i];
}
}
}
using shai::p;
const int N = 507;
int n, a[N], b[N];
int main() {
shai::init(1e4);
rd(n);
for (int i = 1; i <= n; i++) a[i] = p[i&1?i/2+1:n*2-i/2+1];
for (int i = 1; i <= n; i++) b[i] = p[(i&1?n-i/2:n+i/2)+(n&1)];
a[0] = a[n+1] = b[0] = b[n+1] = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
print((i ^ j) & 1 ? 1ll * a[(i+j)/2] * a[(i+j)/2+1] * b[(n+i-j+(n&1))/2] * b[(n+i-j+(n&1))/2+1] + 1 : 1ll * a[(i+j)/2] * b[(n+i-j+(n&1))/2], " \n"[j==n]);
return 0;
} | 0 |
#include<bits/stdc++.h>
#include<math.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define MOD 1000000007LL
#define ROD 1000000000
#define INF 12345678
#define MIN(a,b) (a>b?b:a)
using namespace std;
#include<bits/stdc++.h>
#include<math.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define ll long long
#define mp make_pair
#define piii pair<pair<ll,ll>,pair <ll,ll>>
#define pii pair <ll,ll>
#define fi first
#define se second
ll ch(ll);
ll n,cr[100005],tot,x;
piii br[100005];
int main()
{
cin>>n>>x;
rep(i,0,n)
{
cin>>br[i].fi.se>>br[i].se.fi>>br[i].se.se;
br[i].fi.fi=(br[i].se.se)*(x-br[i].fi.se)+br[i].fi.se*br[i].se.fi;
tot+=br[i].fi.se*br[i].se.fi;
}
//cout<<tot<<"\n";
sort(br,br+n,greater <piii> ());
rep(i,0,n)
{
cr[i]=br[i].fi.fi;
if(i-1>=0)
cr[i]+=cr[i-1];
}
cr[n]=cr[n-1];
// rep(i,0,n+1)
// cout<<cr[i]<<" ";
// rep(i,0,n)
// cout<<br[i].fi.se<<" "<<br[i].se.fi<<" "<<br[i].se.se<<" "<<cr[i]<<"\n";
ch(2497);
ll low=0,high=n*x,mid,ans;
while(low<=high)
{
mid=(low+high)/2;
if(ch(mid))
{
ans=mid;
high=mid-1;
}
else
low=mid+1;
}
//cout<<ch(400)<<" ";
cout<<ans;
}
ll ch(ll mid)
{
ll q=mid/x,r=mid-x*q;
if(mid==n*x)
return 1;
//cout<<r<<" ";
rep(i,0,n)
{
ll temp=0;
if(i<q)
{
if(q>=0)
temp+=cr[q]-br[i].fi.fi;
//temp+=(r>br[i].fi.se?r*br[i].se.se:r*br[i].se.fi);
temp+=(r>br[i].fi.se?(r-br[i].fi.se)*br[i].se.se+br[i].fi.se*br[i].se.fi:r*br[i].se.fi);
}
else
{
if(q-1>=0)
temp+=cr[q-1];
temp+=(r>br[i].fi.se?(r-br[i].fi.se)*br[i].se.se+br[i].fi.se*br[i].se.fi:r*br[i].se.fi);
//cout<<"HERE"<<br[i].fi.se<<" "<<r<<" "<<r-br[i].fi.se<<" "<<br[i].se.se<<" ";
}
// ll qw=r>br[i].fi.se?(r-br[i].fi.se)*br[i].se.se+br[i].fi.se*br[i].se.fi:r*br[i].se.fi;
// cout<<mid<<" "<<tot<<" "<<qw<<" "<<r<<" "<<" "<<temp<<"\n";
if(temp>=tot)
return 1;
}
return 0;
} | #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
template<typename T>
struct BIT{
//1-index
//0-indexで取ると無限ループする
private:
V<T> arr;
int n;
public:
BIT(int siz){
n=siz;
arr.assign(n+1,0);
}
//一点更新 aにvを加える
void add(T a,T v){
//x+=(x&-x) 初項a,それ以降a<=2^Nが列挙
for(T x=a;x<=n;x+=(x&-x)){
arr[x]+=v;
}
}
T sum(T a){
// 1からaまでの区間和
T ret=0;
for(T x=a;x>0;x-=(x&-x))ret+=arr[x];
return ret;
}
T get(T x){//x番目に大きい数 // 区間和がw以上となる最小のindを返す
if(x<=0) return 0;
T N=1;
while(N*2<=n)N*=2;
T v=0;
for(T i=N;i>0;i/=2){
if(v+i<=n&&arr[v+i]<x){
x-=arr[v+i];
v+=i;
}
}
return v+1;
}
T query(int l,int r){
return sum(r)-sum(l);
}
};
int main(){
int n,q;
cin>>n>>q;
BIT<ll> bit(n+5);
ll a;
for(int i=0;i<n;i++){
cin>>a;
bit.add(i+1,a);
}
ll t,l,r;
while(q--){
cin>>t>>l>>r;
if(t){
cout<<bit.query(l,r)<<"\n";
}else{
bit.add(l+1,r);
}
}
} | 0 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
uint N;
long long x;
cin >> N >> x;
vector<long long> a(N, 0);
long long sum = 0;
for (auto &c: a) {
cin >> c;
sum += c;
}
if (sum < x) {
cout << a.size() - 1 << endl;
}
else if (sum == x) {
cout << a.size() << endl;
}
// sum > x
else {
sort(a.begin(), a.end());
int numHappy = 0;
for (size_t i=0; i<a.size(); ++i) {
x -= a[i];
if (x >= 0) ++numHappy;
else break;
}
cout << numHappy << endl;
}
}
| #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
ios_base :: sync_with_stdio(0);
cin.tie(0);
int n, x;
cin >> n >> x;
vector<int> a;
int i, count = 0;
for(i=0; i<n; i++){
int p;
cin >> p;
a.push_back(p);
}
sort(a.begin(), a.end());
for(i=0; i<n; i++){
if(a[i]>x){
x = 0;
break;
}
else{
count++;
x = x-a[i];
}
}
if(x) count = count - 1;
cout << count << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000009;
const double pi = acos(-1);
int dist_sum(int N) {
int ans = 0;
while(N > 0) {
ans += N%10;
N /= 10;
}
return ans;
}
int main() {
int N; cin >> N;
cout << (N%dist_sum(N) == 0 ? "Yes" : "No") << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main (){
int N,K,sum,s;
cin>>N;
K=1;
sum=0;
for (int i=0;i<8;i++){
for(int j=0;j<i;j++){
K*=10;
}
s=(N-N%K)%(K*10)/K;
sum+=s;
K=1;
}
int m;
m=N%sum;
if (m==0){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}
| 1 |
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
unsigned long long a;
double b;
cin>> a >>b;
unsigned long long c = 1000*b;
unsigned long long d = a*c;
unsigned long long e = d/1000;
cout<< e <<endl;
} | #include <bits/stdc++.h>
using namespace std;
int main (){
int A, B;
cin >> A >> B;
int ans = A*B;
cout << ans << endl;
}
| 1 |
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
typedef vector <int> VI;
typedef set <int> SI;
int get_digit( int n )
{
int count = 0;
while ( n >= 10 )
{
n /= 10;
count++;
}
return count + 1;
}
int ten_pow( int n )
{
int answer = 1;
for ( int i = 0; i < n; i++ ) answer *= 10;
return answer;
}
int main( void )
{
int n, k;
while ( cin >> n >> k && n && k )
{
VI cards(n);
for ( int i = 0; i < n; i++ ) cin >> cards[i];
sort( cards.begin(), cards.end() );
SI h;
for ( int i = 0; i < 1<<n; i++ )
{
int cnt = 0;
for ( int j = 0; j < n; j++ )
{
if ( i & 1 << j ) cnt++;
}
if ( cnt != k ) continue;
VI C;
for ( int j = 0; j < n; j++ )
{
if ( i & 1 << j ) C.push_back( cards[j] );
}
do {
int m = 0;
for ( VI::iterator it = C.begin(); it != C.end(); it++ )
{
if ( m == 0 ) m += *it;
else
{
m *= ten_pow( get_digit( *it ) );
m += *it;
}
}
h.insert( m );
} while ( next_permutation( C.begin(), C.end() ) );
}
cout << h.size() << endl;
}
return 0;
} | #include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
int n, k;
string str[10];
int main(){
while(scanf("%d", &n),n){
set<string> s;
scanf("%d", &k);
rep(i,n) cin >> str[i];
if(k == 2){
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i == j) continue;
s.insert(str[i]+str[j]);
}
}
} else if(k == 3){
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(j == i) continue;
for(int u = 0; u < n; u++){
if(u == i || u == j) continue;
s.insert(str[i]+str[j]+str[u]);
}
}
}
} else{
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i == j) continue;
for(int u = 0; u < n; u++){
if(u == i || u == j) continue;
for(int v = 0; v < n; v++){
if(v == i || v == j || v == u) continue;
s.insert(str[i]+str[j]+str[u]+str[v]);
}
}
}
}
}
cout << s.size() << endl;
}
} | 1 |
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
for(int T = 0; T < t ; T++){
ll n, x;
cin >> n >> x;
ll a[n], ans = 0;
for(int i = 0; i < n; i++)
cin >> a[i];
if(a[0] > x){
ans += a[0] - x;
a[0] = x;
}
for(int i = 1; i < n; i++){
if(a[i] + a[i - 1] > x){
ans += a[i] + a[i -1] - x;
a[i] = x - a[i - 1];
}
}
std::cout << ans << std::endl;
}
return 0;
} | #include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)
using namespace std;
using ll = long long;
using VI = std::vector<int>;
using VI2D = std::vector<vector<int>>;
using VLL = std::vector<long long>;
using VLL2D = std::vector<vector<long long>>;
constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);
constexpr int dx[] = {-1, 0, 1, 0};
constexpr int dy[] = {0, -1, 0, 1};
template <typename T>
constexpr int sign(T x) {
return x < 0 ? -1 : x > 0 ? 1 : 0;
}
template <>
constexpr int sign(double x) {
return x < -EPS ? -1 : x > EPS ? 1 : 0;
}
template <typename T, typename U>
constexpr void chmax(T& m, U x) {
m = max(m, x);
}
template <typename T, typename U>
constexpr void chmin(T& m, U x) {
m = min(m, x);
}
template <typename T>
constexpr T square(T x) {
return x * x;
}
int main() {
int n, x;
cin >> n >> x;
VI a(n);
REP(i, n) { cin >> a[i]; }
ll result = 0;
REP(i, n - 1) {
if(a[i] + a[i + 1] > x) {
int d = a[i] + a[i + 1] - x;
if(a[i + 1] < d) {
a[i] -= d - a[i + 1];
a[i + 1] = 0;
} else {
a[i + 1] -= d;
}
result += d;
}
}
cout << result << endl;
return 0;
}
| 1 |
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (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 FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
void solve(int m, int nmi, int nma) {
VI P(m);
REP(i, m) cin >> P[i];
RSORT(P);
P.EB(0);
PII ans = MP(abs(P[nmi] - P[nmi - 1]), nmi);
FOR(i, nmi, nma) {
int dif = abs(P[i] - P[i + 1]);
if (dif >= ans.first) {
ans = MP(dif, i + 1);
}
}
cout << ans.second << endl;
}
signed main(void) {
int n, m, p, a, b, c, x, y, z, q;
string s;
while (cin >> m >> a >> b, m) {
solve(m, a, b);
//return 0;
}
} | #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char convNext(char ch) {
if('a' <= ch && ch <= 'y') return ch+1;
if(ch=='z')return 'a';
return ch;
}
int main() {
char str[90];
while(true) {
if(!fgets(str, 90, stdin))break;
for(int i = 0; i < 26; i++) {
if(strstr(str,"this") || strstr(str,"that") || strstr(str,"the"))break;
for(int j = 0; str[j]; j++) {
str[j]=convNext(str[j]);
}
}
fputs(str, stdout);
}
return 0;
} | 0 |
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
const LL mod=1e9+7;
LL f[1010][1010],n,a,b,c,d,C[1010][1010],inv[1010][1010],fac[1010],finv[1010];
void pre()
{
inv[0][1]=inv[1][1]=1;fac[0]=fac[1]=1;
for(LL i=2;i<=1000;i++) inv[i][1]=(mod-mod/i)*inv[mod%i][1]%mod,fac[i]=fac[i-1]*i%mod;
for(LL i=2;i<=1000;i++) inv[i][1]=inv[i-1][1]*inv[i][1]%mod;
for(LL i=1;i<=1000;i++)
for(LL j=2;j<=1000;j++) inv[i][j]=inv[i][1]*inv[i][j-1]%mod;
for(LL i=1;i<=1000;i++)
for(LL j=1;j<=i;j++) C[i][j]=fac[i]*inv[i-j][1]%mod;
}
LL get(LL x,LL y,LL i) {return C[x][i*y]*inv[y][i]%mod*inv[i][1]%mod;}
LL dfs(LL x,LL y)
{
if(f[x][y]!=-1) return f[x][y];
if(x==0) return 1;
if(y<a) return 0;
f[x][y]=0;
for(LL i=c;i<=d;i++)
{
LL num=i*y;
if(num<=x) (f[x][y]+=dfs(x-num,y-1)*get(x,y,i)%mod)%=mod;
else break;
}
(f[x][y]+=dfs(x,y-1))%=mod;
return f[x][y];
}
int main()
{
pre();
scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&c,&d);
memset(f,-1,sizeof(f));
printf("%lld",dfs(n,b));
} | #include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const ll MOD=998244353;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
int N,M,K;
const int MAXN=2e5+10;
ll factor[MAXN];
void init()
{
factor[0]=1;
for(int u=1;u<MAXN;u++){
factor[u]=(factor[u-1]*u)%MOD;
}
}
ll C(ll n,ll k)
{
return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;
}
void solve()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>N>>M>>K;
init();
ll ans=0;
for(int u=0;u<=K;u++){
ans=(ans+M*C(N-1,u)%MOD*qpow(M-1,N-1-u)%MOD)%MOD;
}
cout<<ans;
}
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
solve();
} | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<bool> digit(10, false);
bool check(int N) {
bool res = true;
while(N > 0) {
int x = N % 10;
if (digit[x]) {
res = false;
break;
}
N /= 10;
}
return res;
}
int main() {
int N, K;
cin >> N >> K;
for (int i = 0; i < K; i++) {
int x;
cin >> x;
digit[x] = true;
}
while(true) {
if (check(N)) {
cout << N << endl;
return 0;
}
N++;
}
} | #include <algorithm>
#include <iostream>
#include <vector>
#define rep(S, L) for (int i = S; i < L; ++i)
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> ng_d;
int dd;
vector<int> d;
for (int i = 0; i < k; ++i) {
cin >> dd;
ng_d.push_back(dd);
}
for (int i = 0; i < 10; ++i) {
bool ng = false;
for (int j = 0; j < ng_d.size(); ++j) {
if (ng_d[j] == i) {
ng = true;
break;
}
}
if (!ng) {
d.push_back(i);
}
}
sort(d.begin(), d.end());
int ans = d[0];
bool ok = false;
for (int i1 = 0; i1 < d.size(); ++i1) {
int tmp1 = d[i1];
if (tmp1 >= n) {
ans = tmp1;
goto end;
}
}
for (int i1 = 0; i1 < d.size(); ++i1) {
int tmp1 = d[i1];
for (int i2 = 0; i2 < d.size(); ++i2) {
int tmp2 = tmp1 * 10 + d[i2];
if (tmp2 >= n) {
ans = tmp2;
goto end;
}
}
}
for (int i1 = 0; i1 < d.size(); ++i1) {
int tmp1 = d[i1];
for (int i2 = 0; i2 < d.size(); ++i2) {
int tmp2 = tmp1 * 10 + d[i2];
for (int i3 = 0; i3 < d.size(); ++i3) {
int tmp3 = tmp2 * 10 + d[i3];
if (tmp3 >= n) {
ans = tmp3;
goto end;
}
}
}
}
for (int i1 = 0; i1 < d.size(); ++i1) {
int tmp1 = d[i1];
for (int i2 = 0; i2 < d.size(); ++i2) {
int tmp2 = tmp1 * 10 + d[i2];
for (int i3 = 0; i3 < d.size(); ++i3) {
int tmp3 = tmp2 * 10 + d[i3];
for (int i4 = 0; i4 < d.size(); ++i4) {
int tmp4 = tmp3 * 10 + d[i4];
if (tmp4 >= n) {
ans = tmp4;
goto end;
}
}
}
}
}
for (int i1 = 0; i1 < d.size(); ++i1) {
int tmp1 = d[i1];
for (int i2 = 0; i2 < d.size(); ++i2) {
int tmp2 = tmp1 * 10 + d[i2];
for (int i3 = 0; i3 < d.size(); ++i3) {
int tmp3 = tmp2 * 10 + d[i3];
for (int i4 = 0; i4 < d.size(); ++i4) {
int tmp4 = tmp3 * 10 + d[i4];
for (int i5 = 0; i5 < d.size(); ++i5) {
int tmp5 = tmp4 * 10 + d[i5];
if (tmp5 >= n) {
ans = tmp5;
goto end;
}
}
}
}
}
}
end:
cout << ans << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int H, W;
bool check(int i, int j, int dx, int dy, vector<vector<int>> &field) {
int x = i + dx;
int y = j + dy;
return (x >= 0 && x < H && y >= 0 && y < W && (field[x][y] == -1));
}
int main() {
cin >> H >> W;
vector<vector<int>> field(H, vector<int>(W));
int white = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
char c; cin >> c;
if (c == '.') {
field[i][j] = -1;
white++;
}
else field[i][j] = -2;
}
}
vector<int> dx = {-1, 1, 0, 0};
vector<int> dy = {0, 0, -1, 1};
field[0][0] = 0;
queue<pii> que;
que.push({0, 0});
while (!que.empty()) {
int i = que.front().first;
int j = que.front().second;
que.pop();
if (i == (H - 1) && j == (W - 1)) {
cout << white - field[H-1][W-1] - 1 << endl;
return 0;
}
for (int k = 0; k < 4; k++) {
if (check(i, j, dx[k], dy[k], field)) {
que.push({i + dx[k], j + dy[k]});
field[i + dx[k]][j + dy[k]] = field[i][j] + 1;
}
}
}
cout << -1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef vector<bool> vbool;
typedef vector<int> vint;
#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep_rev(i, n) for (int i = n-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <class T, class S> inline bool chmax(T &a, S b) {
if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
if(a > b) {a = b;return 1;} return 0;
}
template <class T>
void line(vector<T> &x){for (auto&& xi : x) cin >> xi;}
inline void IN(void){ return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return;}
#define INT(...) int __VA_ARGS__; IN (__VA_ARGS__)
#define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)
template <class T> void UNIQUE(vector<T> &x) {
sort(all(x)); x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(T first, T end){
for (auto i = first; i < end - 1; i++) cout << *i << " ";
cout << *(end-1) << endl;
}
template<class... T>
void debug_print(T... args){
vector<lint> tmp = initializer_list<lint>{args...};
print_vec(all(tmp));
}
template<class T>
void print(T a){ cout << a << endl;}
vector<string> Yes = {"No", "Yes"};
vector<string> YES = {"NO", "YES"};
int ord(char x){ return (int)(x - 'a');}
char chr(lint x){ return (char)(x + (lint)('a'));}
lint mod = 1e9+7;
// lint mod =
lint sum(vlint a){lint ret = 0; for(auto&& v:a) ret += v; return ret;}
lint vmini(vlint a, lint &index){
lint ret = LLONG_MAX;
rep(i, Size(a)){ if (chmin(ret, a[i])) index = i;}
return ret;
}
lint vmaxi(vlint a, lint &index){
lint ret = -LLONG_MAX;
rep(i, Size(a)){ if (chmax(ret, a[i])) index = i;}
return ret;
}
lint vmin(vlint a){
lint ret = LLONG_MAX; for (auto && v : a) chmin(ret, v); return ret;
}
lint vmax(vlint a){
lint ret = -LLONG_MAX; for (auto && v : a) chmax(ret, v); return ret;
}
vlint base_3(int k){
vlint ret; while (k > 0){ ret.pb(k % 3); k /= 3;} reverse(all(ret)); return ret;
}
map<lint, lint> trial_division(lint n){
map<lint, lint> factor;
lint tmp = (lint)(sqrt(n)) + 1;
for (lint i = 2; i < tmp; ++i){
while (n % i == 0){
n /= i;
factor[i] ++;
}
}
if(n != 1) factor[n] ++;
return factor;
}
lint dist(lint x1, lint y1, lint x2, lint y2){
return (x1-x2) * (x1-x2) + (y1-y2) * (y1 - y2);
}
int main(){
INT(h, w);
char o;
vector<vint> grid(h+2, vint(w+2, 0));
int cnt = 0;
rep1(i, h+1){
rep1(j, w+1){
cin >> o;
if (o == '.'){
grid[i][j] = 1;
cnt ++;
}
}
}
queue<pair<int, int>> q;
q.push({1, 1});
vector<vint> dist(h+2, vint(w+2, -1));
dist[1][1] = 0;
int y, x, ny, nx;
vint dx = {-1, 0, 0, 1};
vint dy = {0, -1, 1, 0};
while (!q.empty()){
y = q.front().first;
x = q.front().second; q.pop();
rep(i, 4){
ny = y + dy[i];
nx = x + dx[i];
if (dist[ny][nx] != -1 || grid[ny][nx] == 0){
continue;
}
q.push({ny, nx});
dist[ny][nx] = dist[y][x] + 1;
}
}
if (dist[h][w] == -1){
print(-1);
}
else{
print(cnt - dist[h][w]-1);
}
}
| 1 |
#include <iostream>
using namespace std;
int main(){
int n;
cin >> n;
int i=1;
while(i*i<=n) i++;
cout << (i-1)*(i-1) << "\n";
return 0;
}
| #include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;
int main() {
int n;
cin >> n;
n = pow(n, 0.5);
cout << n * n << endl;
}
| 1 |
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<LL,LL> P;
int read()
{
int x=0,flag=1; char c=getchar();
while((c>'9' || c<'0') && c!='-') c=getchar();
if(c=='-') flag=0,c=getchar();
while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
return flag?x:-x;
}
const int maxn=1e6+5,v=5e5,N=1e6;
struct node {int x,y,dir;} a[maxn];
VI x[maxn],y[maxn],p[maxn],q[maxn];
int n,ans=1e9;
char s[10];
bool cmp1(int i,int j) {return a[i].x==a[j].x?a[i].y<a[j].y:a[i].x<a[j].x;}
bool cmp2(int i,int j) {return a[i].y==a[j].y?a[i].x<a[j].x:a[i].y<a[j].y;}
int main()
{
n=read();
REP(i,1,n)
{
a[i].x=read();
a[i].y=read();
scanf("%s",s);
a[i].dir=s[0];
}
sort(a+1,a+n+1,[&](node a,node b){return a.x==b.x?a.y<b.y:a.x<b.x;});
REP(i,2,n) if(a[i].x==a[i-1].x && a[i].y==a[i-1].y) return puts("0"),0;
REP(i,1,n)
{
x[a[i].x+v].pb(i);
y[a[i].y+v].pb(i);
p[a[i].y-a[i].x+v].pb(i);
q[a[i].y+a[i].x+v].pb(i);
}
REP(i,1,N)
{
sort(x[i].begin(),x[i].end(),cmp1);
sort(y[i].begin(),y[i].end(),cmp2);
sort(p[i].begin(),p[i].end(),cmp1);
sort(q[i].begin(),q[i].end(),cmp1);
}
REP(i,1,N) if(x[i].size()>1)
{
int yy=-1;
REP(j,0,x[i].size()-1)
{
int id=x[i][j];
if(yy>=0 && a[id].dir=='D') ans=min(ans,abs(a[id].y-yy)*5);
if(a[id].dir=='U') yy=a[id].y;
}
}
REP(i,1,N) if(y[i].size()>1)
{
int xx=-1;
REP(j,0,y[i].size()-1)
{
int id=y[i][j];
if(xx>=0 && a[id].dir=='L') ans=min(ans,abs(a[id].x-xx)*5);
if(a[id].dir=='R') xx=a[id].x;
}
}
REP(i,1,N) if(p[i].size()>1)
{
int xx1=-1,xx2=-1;
REP(j,0,p[i].size()-1)
{
int id=p[i][j];
if(xx1>=0 && a[id].dir=='L') ans=min(ans,abs(a[id].x-xx1)*10);
if(xx2>=0 && a[id].dir=='D') ans=min(ans,abs(a[id].x-xx2)*10);
if(a[id].dir=='U') xx1=a[id].x;
if(a[id].dir=='R') xx2=a[id].x;
}
}
REP(i,1,N) if(q[i].size()>1)
{
int xx1=-1,xx2=-1;
REP(j,0,q[i].size()-1)
{
int id=q[i][j];
if(xx1>=0 && a[id].dir=='U') ans=min(ans,abs(a[id].x-xx1)*10);
if(xx2>=0 && a[id].dir=='L') ans=min(ans,abs(a[id].x-xx2)*10);
if(a[id].dir=='R') xx1=a[id].x;
if(a[id].dir=='D') xx2=a[id].x;
}
}
if(ans>=(1e9)-1) puts("SAFE");
else printf("%d\n",ans);
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll llINF = 1LL << 60;
const int iINF = 1e8;
//collision time
int colltime(vector<P> yu){
int res = iINF;
sort(yu.begin(),yu.end());
rep(i,yu.size()-1){
if( yu[i].second == 0 && yu[i+1].second != 0 ){
chmin(res, (yu[i+1].first - yu[i].first));
}
}
return res;
}
int min_colltime(map<int,vector<P>>& UD){
int res = iINF;
for(auto udi : UD) chmin(res,colltime(udi.second));
return res;
}
//---main---------------------------------------------
int main(){
//main
int N;
cin >> N;
vector<int> X(N),Y(N),U(N);
char c;
rep(i,N){
cin >> X[i] >> Y[i] >> c;
if(c=='U') U[i] = 0;
if(c=='R') U[i] = 1;
if(c=='D') U[i] = 2;
if(c=='L') U[i] = 3;
}
int ans = iINF;
rep(d,4){
//同じx座標でU,Dのものをまとめる
map<int,vector<P>> UD;
rep(i,N) if(U[i]==0 || U[i]==2) UD[X[i]].emplace_back(Y[i],U[i]);
chmin(ans, min_colltime(UD)*5);
//同じ直線上でU,Rのものをまとめる
map<int,vector<P>> UR;
rep(i,N) if(U[i]==0 || U[i]==1) UR[X[i]+Y[i]].emplace_back(Y[i],U[i]);
chmin(ans, min_colltime(UR)*10);
//rotate
int xi;
rep(i,N){
xi = X[i];
X[i] = Y[i];
Y[i] = -xi;
U[i] = (U[i]+1)%4;
}
}
if(ans == iINF) cout << "SAFE" << endl;
else cout << ans << endl;
return 0;
} | 1 |
#include<stdio.h>
int main(){
int n,c[101][2][7],z,Z,x;
scanf("%d",&n);
for(int i=0;i<n;i++){
for(int t=0;t<6;t++){
scanf("%d",&c[i][1][t]);
c[i][0][t]=t;
}
}
for(int p=0;p<n-1;p++){
for(int s=p+1;s<n;s++){
///????????????????????????///
for(int i=0;i<6;i++){
///??????c[s][1][i]?????????///
for(int t=0;i!=c[s][0][0];t++){
if(t==4) break;
z=c[s][0][0];
Z=c[s][1][0];
c[s][0][0]=c[s][0][4];
c[s][1][0]=c[s][1][4];
c[s][0][4]=c[s][0][5];
c[s][1][4]=c[s][1][5];
c[s][0][5]=c[s][0][1];
c[s][1][5]=c[s][1][1];
c[s][0][1]=z;
c[s][1][1]=Z;
}
if(i!=c[s][0][0]){
for(int t=0;i!=c[s][0][0];t++){
if(t==4) break;
z=c[s][0][0];
Z=c[s][1][0];
c[s][0][0]=c[s][0][2];
c[s][1][0]=c[s][1][2];
c[s][0][2]=c[s][0][5];
c[s][1][2]=c[s][1][5];
c[s][0][5]=c[s][0][3];
c[s][1][5]=c[s][1][3];
c[s][0][3]=z;
c[s][1][3]=Z;
}
}
///a[]??¨????????????????????´??¢?????????///
for(int t=0;t<4;t++){
x=0;
for(int t=0;t<6;t++){
if(c[p][1][t]!=c[s][1][t]){
x++;
}
}
//printf("%d\n",x);
if(x==0) break;
Z=c[s][1][1];
c[s][1][1]=c[s][1][3];
c[s][1][3]=c[s][1][4];
c[s][1][4]=c[s][1][2];
c[s][1][2]=Z;
}
if(x==0) break;
}
if(x==0) break;
}
if(x==0) break;
}
if(x==0){
printf("No\n");
}
else printf("Yes\n");
return 0;
} | #include<iostream>
#include<cctype>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cctype>
#include<cstring>
#include<utility>
const int inf=0x7fffffff;
typedef long long int ll;
using namespace std;
const int N=100+5;
char s[100+10];
char ans[][10]={
"No\n",
"Yes\n"
};
struct DICE{
int u,s,e,w,n,d;
DICE (int u=0,int s=0,int e=0,int w=0,int n=0,int d=0):u(u),s(s),e(e),w(w),n(n),d(d){}
DICE fW(){
DICE tmp;
tmp.s=this->s;
tmp.n=this->n;
tmp.e=this->d;
tmp.w=this->u;
tmp.u=this->e;
tmp.d=this->w;
return tmp;
}
DICE fS(){
DICE tmp;
tmp.s=this->u;
tmp.n=this->d;
tmp.e=this->e;
tmp.w=this->w;
tmp.d=this->s;
tmp.u=this->n;
return tmp;
}
DICE fE(){
DICE tmp;
tmp.s=this->s;
tmp.n=this->n;
tmp.e=this->u;
tmp.w=this->d;
tmp.d=this->e;
tmp.u=this->w;
return tmp;
}
DICE fN(){
DICE tmp;
tmp.s=this->d;
tmp.n=this->u;
tmp.e=this->e;
tmp.w=this->w;
tmp.d=this->n;
tmp.u=this->s;
return tmp;
}
int right(int t,int f){
if(t==this->u)
{
if(f==this->s)return this->e;
else if(f==this->e)return this->n;
else if(f==this->n)return this->w;
else if(f==this->w)return this->s;
else return -1;
}
else if(t==this->s){
DICE tmp=(*this).fN();
return tmp.right(t,f);
}
else if(t==this->e){
DICE tmp=(*this).fW();
return tmp.right(t,f);
}
else if(t==this->n){
DICE tmp=(*this).fS();
return tmp.right(t,f);
}
else if(t==this->w){
DICE tmp=(*this).fE();
return tmp.right(t,f);
}
else if(t==this->d){
DICE tmp=(*this).fE().fE();
return tmp.right(t,f);
}
else return -1;
}
};
DICE A[N];
bool check(DICE x,DICE y){
int ax[]={
x.s,x.e,x.n,x.w
};
int ay[]={
y.s,y.e,y.n,y.w
};
if(x.u==y.u){
if(x.d==y.d){
int cnt=0;
while(cnt<=4){
while(ax[cnt]!=ay[0]&&cnt<=4)
cnt++;
int i=0;
while(ax[(i+cnt)%4]==ay[i]&&i<=4)
i++;
if(i==4)return 1;
cnt++;
}
}
}
return 0;
}
bool sovle(DICE x,DICE y){
if(check(x,y))return 1;
if(check(x.fE(),y))return 1;
if(check(x.fW(),y))return 1;
if(check(x.fN(),y))return 1;
if(check(x.fS(),y))return 1;
if(check(x.fS().fS(),y))return 1;
return 0;
}
int main()
{
//#ifdef DEBUG
// freopen("in", "r", stdin);
//// freopen("out", "w", stdout);
//#endif
int n;scanf("%d", &n);
int t=0;
int a[6];
bool flag=1;
for(int i=0;i<6;i++){
scanf("%d", &a[i]);
}
A[0]=DICE(a[0],a[1],a[2],a[3],a[4],a[5]);
t++;
while(t<n){
for(int i=0;i<6;i++){
scanf("%d", &a[i]);
}
A[t]=DICE (a[0],a[1],a[2],a[3],a[4],a[5]);
for(int i=0;i<t;i++)
{
if(sovle(A[i],A[t])){flag=0;
// cout<<i<<' '<<t<<endl;
}
}
t++;
}
printf("%s", ans[flag]);
// printf("%s", ans[solve(dice,dice2)]);
// DICE I
// scanf("%s", s);
// int len=strlen(s);
// for(int i=0;i<len;i++){
// switch(s[i]){
// case'S':dice=dice.fS();break;
// case'E':dice=dice.fE();break;
// case'W':dice=dice.fW();break;
// case'N':dice=dice.fN();break;
// }
// }
// printf("%d\n", dice.u);
//
return 0;
}
//aoj1_11_a.cc
//AC | 1 |
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define FOE(x, a) for(auto x : a)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FOD(i, a, b) for(int i = a; i >= b; i--)
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
const int N = 2e5 + 10;
const ll INF = 1e18;
struct segmentTree{
ll d[N * 4], lazy[N * 4];
void doLazy(int id, int l, int r){
d[id] += lazy[id];
if (l < r){
lazy[id << 1] += lazy[id];
lazy[id << 1 | 1] += lazy[id];
}
lazy[id] = 0;
}
void update(int id, int l, int r, int u, int v, ll val){
doLazy(id, l, r);
if (v < l || r < u)
return;
if (u <= l && r <= v){
lazy[id] += val;
doLazy(id, l, r);
return;
}
int mid = (l + r) >> 1;
update(id << 1, l, mid, u, v, val);
update(id << 1 | 1, mid + 1, r, u, v, val);
d[id] = min(d[id << 1], d[id << 1 | 1]);
}
ll getMin(int id, int l, int r, int u, int v){
doLazy(id, l, r);
if (v < l || r < u)
return INF;
if (u <= l && r <= v)
return d[id];
int mid = (l + r) >> 1;
return min(getMin(id << 1, l, mid, u, v), getMin(id << 1 | 1, mid + 1, r, u, v));
}
} ST[2];
int n, q, a, b;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q >> a >> b;
FOR(i, 1, n){
ST[0].update(1, 1, n, i, i, abs(b - i) - i);
ST[1].update(1, 1, n, i, i, abs(b - i) + i);
}
while (q--){
int x;
cin >> x;
ll cur = ST[0].getMin(1, 1, n, a, a) + a;
ll minVal = min(ST[0].getMin(1, 1, n, 1, x) + x, ST[1].getMin(1, 1, n, x, n) - x);
minVal = min(minVal, cur + abs(x - a));
ST[0].update(1, 1, n, a, a, minVal - cur);
ST[1].update(1, 1, n, a, a, minVal - cur);
if (a > 1){
ST[0].update(1, 1, n, 1, a - 1, abs(x - a));
ST[1].update(1, 1, n, 1, a - 1, abs(x - a));
}
if (a < n){
ST[0].update(1, 1, n, a + 1, n, abs(x - a));
ST[1].update(1, 1, n, a + 1, n, abs(x - a));
}
a = x;
}
ll ans = INF;
FOR(i, 1, n)
ans = min(ans, ST[0].getMin(1, 1, n, i, i) + i);
cout << ans;
return 0;
}
| //
// main.cpp
//
#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int main() {
struct Test {
ll b;
ll l;
ll u;
};
ll N, X;
vector<Test> tests;
cin >> N >> X;
for (int i = 0; i < N; i++) {
int bi, li, ui;
cin >> bi >> li >> ui;
tests.push_back({bi, li, ui});
}
auto full_score = [X](Test test) {
return (X - test.b) * test.u - (0 - test.b) * test.l;
};
sort(tests.begin(), tests.end(), [&full_score](Test lhs, Test rhs) {
return full_score(lhs) > full_score(rhs);
});
vector<ll> full_score_sum;
{
ll sum = 0;
full_score_sum.push_back(sum);
for (Test test : tests) {
sum += full_score(test);
full_score_sum.push_back(sum);
}
}
ll zero_score = 0;
for (Test test : tests) {
zero_score += (0 - test.b) * test.l;
}
ll lower = -1;
ll upper = N * X;
while (lower + 1 < upper) {
ll time = (lower + upper) / 2;
ll full_cnt = time / X;
ll residue = time % X;
ll score_max = numeric_limits<ll>::min();
if (residue == 0) {
ll score = 0;
score = full_score_sum[full_cnt];
score_max = max(score_max, score);
} else {
for (int i = 0; i < tests.size(); i++) {
ll score = 0;
if (residue < tests[i].b) {
score = (residue - tests[i].b) * tests[i].l
- (0 - tests[i].b) * tests[i].l;
} else {
score = (residue - tests[i].b) * tests[i].u
- (0 - tests[i].b) * tests[i].l;
}
if (i >= full_cnt) {
score += full_score_sum[full_cnt];
} else {
score += full_score_sum[i];
score += full_score_sum[full_cnt + 1] - full_score_sum[i + 1];
}
score_max = max(score_max, score);
}
}
if (score_max + zero_score >= 0) {
upper = time;
} else {
lower = time;
}
}
cout << upper << endl;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;
typedef priority_queue< int, vector< int >, greater< int > > minHeap;
#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bug(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
int Set(int N,int pos)
{
return N=N | (1<<pos);
}
int reset(int N,int pos)
{
return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
return (bool)(N & (1<<pos));
}
inline int addmod(lli x,lli y)
{
return (x%mod + y%mod)%mod;
}
inline int submod(lli x,lli y)
{
return (x%mod - y%mod + mod)%mod;
}
inline int mulmod(lli x,lli y)
{
return (x%mod * y%mod)%mod;
}
inline int nextSubMask(int i, int mask)
{
return (i-1)&mask; /// returns next submask
}
template<typename T>
void we_r_done(T mssg)
{
cout<<mssg;
exit(0);
}
int main()
{
///freopen("output.txt","w",stdout);
// freopen("input.txt","r",stdin);
FastIO;
string s;
while(cin>>s){
int n = s.size();
lli ans = 1 + n*1LL*(n-1)/2;
vector<int>cnt(30,0);
for(int i=0; i<n; i++){
cnt[s[i]-'a']++;
}
for(int i=0; i<26; i++) ans -= cnt[i]*1LL*(cnt[i]-1)/2;
cout<<ans<<endl;
}
return 0;
}
///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?
///sort(atoz(v), [](const data x, const data y){return (x.a==y.a?x.b>y.b : x.a<y.a);});
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll x;
cin >> x;
if(x%11==0) cout << 2*x/11;
else if(x%11<=6) cout << (x/11)*2+1;
else cout << (x/11)*2+2;
cout << endl;
} | 0 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int main() {
int N;
cin >> N;
if (N == 1)
cout << "Hello World" << endl;
else {
int A, B;
cin >> A >> B;
cout << A + B << endl;
}
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int const NMAX = 100;
char v[1 + NMAX][1 + NMAX];
int main() {
int n, m;
cin >> n >> m;
cout << max(n * m, max(n - m, n + m));
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n) for (int i = 1; i <= (n); i++)
typedef long long ll;
int main() {
ll N, m = LONG_LONG_MAX;
cin >> N;
rep(i, 5) {
ll x;
cin >> x;
m = min(m, x);
}
ll ans = 4 + (ll)ceil(N * 1.0 / m);
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, e, n) for (int i = e; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const ll inf=1000000000007;
int main() {
ll n,a,b,c,d,e;
cin >> n >> a >> b >> c >> d >> e;
ll mn= min(min(min(a,b),c),min(d,e));
ll ans = (n-0.5)/mn +5;
cout << ans << endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> b(n);
for (int i = 0; i < n; i++) {
cin >> b[i];
}
vector<int> c(n);
for (int i = 0; i < n; i++) {
cin >> c[i];
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
sort(c.begin(), c.end());
long long ans = 0;
for (int i = 0; i < n; i++) {
auto low = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
auto up = c.end() - upper_bound(c.begin(), c.end(), b[i]);
ans += low * up;
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n; cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
double average = (double)accumulate(a.begin(), a.end(), 0)/n;
int ans = 0;
double minv=100100100;
rep(i, n) {
if (abs(average-(double)a[i])< minv) {
ans = i;
minv = abs(average-(double)a[i]);
}
}
cout << ans << endl;
//cout << a[ans] << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N;
//1 <= N <= 10^10なので
//1回のfor文すら回せない
//N = A * B なので√Nまで探索すればok
int findDigit(ll x, ll y)
{
ll s, t;
s = log10(x) + 1;
t = log10(y) + 1;
return max(s, t);
}
int main()
{
cin >> N;
ll s = sqrt(N);
ll res = N;
for (int i = 1; i <= s; i++)
{
if (N % i == 0)
{
int F = findDigit(i, N / i);
if (F < res)
res = F;
}
}
cout << res << endl;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(){
string S;
cin >> S;
reverse(S.begin(), S.end());
int N = S.length();
const long long INF = 1e18;
vector<long long> dp(2,INF);
dp[0] = 0;
for(auto c : S){
vector<long long> dp_(2,INF);
for(int i = 0; i < 2; ++i){
int d = c-'0'+i;
dp_[1] = min(dp_[1],dp[i]+10-d);
dp_[d/10] = min(dp_[d/10],dp[i]+d%10);
}
swap(dp,dp_);
}
++dp[1];
cout << min(dp[0],dp[1]) << endl;
}
| 0 |
// ABC162-D RGB Triplets
#include <bits/stdc++.h>
using namespace std;
signed main() {
int n, a, b, pos1, pos2;
long long dp[3][4000] = {}, ans = 0;
string s;
cin >> n;
cin >> s;
ans = 0;
for(int i=0 ;i<n ;i++ ) {
if(s[i] == 'R') {
dp[0][i] = 1;
}
else if(s[i] == 'B') {
dp[1][i] = 1;
}
else {
dp[2][i] = 1;
}
if(i > 0) {
for(int j=0 ;j<3 ;j++ ) {
dp[j][i] += dp[j][i-1];
}
}
}
for(int i=1 ;i<n-1 ;i++ ) {
if(s[i] == 'R') {
a = 1;
b = 2;
}
else if(s[i] == 'B') {
a = 0;
b = 2;
}
else {
a = 0;
b = 1;
}
ans += dp[a][i-1] * (dp[b][n-1] - dp[b][i]) + dp[b][i-1] * (dp[a][n-1] - dp[a][i]);
pos1 = i-1;
pos2 = i+1;
while(pos1 >= 0 && pos2 <= n-1) {
if(s[pos1] != s[i] && s[i] != s[pos2] && s[pos1] != s[pos2]) {
ans --;
}
pos1 --;
pos2 ++;
}
}
cout << ans << endl;
return (0);
} | #include<iostream>
#include<string>
using namespace std;
int main()
{
char s[5000];
long long n,i,j,k,total=0,red[5000]={0},green[5000]={0},blue[5000]={0},r=0,g=0,b=0,x,y;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>s[i];
}
for(i=1;i<=n;i++)
{
if(s[i]=='R')
{
r++;
red[i]=red[i-1]+1;
blue[i]=blue[i-1];
green[i]=green[i-1];
}
else if(s[i]=='G')
{
g++;
green[i]=green[i-1]+1;
red[i]=red[i-1];
blue[i]=blue[i-1];
}
else if(s[i]=='B')
{
b++;
blue[i]=blue[i-1]+1;
red[i]=red[i-1];
green[i]=green[i-1];
}
}
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&&s[j]=='R'))
{
x=b-blue[j];
y=(j-i)+j;
if(s[y]=='B'&&x>0&&y<=n)
{
x--;
}
if(x>0)
{
total=total+x;
}
}
else if((s[i]=='R'&&s[j]=='B')||(s[i]=='B'&&s[j]=='R'))
{
x=g-green[j];
y=(j-i)+j;
if(s[y]=='G'&&x>0&&y<=n)
{
x--;
}
if(x>0)
{
total=total+x;
}
}
else if((s[i]=='B'&&s[j]=='G')||(s[i]=='G'&&s[j]=='B'))
{
x=r-red[j];
y=(j-i)+j;
if(s[y]=='R'&&x>0&&y<=n)
{
x--;
}
if(x>0)
{
total=total+x;
}
}
}
}
cout<<total<<endl;
return 0;
} | 1 |
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
vector<pll> prime_factorize(ll N) {
vector<pll> res;
for (ll a = 2; a * a <= N; ++a) {
if (N % a != 0) continue;
ll ex = 0;
while (N % a == 0) {
++ex;
N /= a;
}
res.push_back({a, ex});
}
if (N != 1) res.push_back({N, 1});
return res;
}
const int MAX = 210000;
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;
}
int main() {
ll n, m;
COMinit();
cin >> n >> m;
vector<pll> vc = prime_factorize(m);
ll ans = 1;
for(int i=0; i<vc.size(); i++){
ll num = COM(vc[i].second + n - 1, n-1);
//cout << "num:" << num << " vc[i]:" << vc[i].first << " " << vc[i].second << ln;
ans = (ans * num)% MOD;
}
cout << ans % MOD << ln;
} | #include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << (x) << endl
using namespace std;
const int N = 305;
const long long mod = 998244353ll;
int n, K, num[N], pre[N], cnt = 0;
char str[N];
long long f[N][N << 1], g[N][N << 1], tmp[N][N << 1];
int main () {
scanf("%s%d", str, &K), n = strlen(str);
int pos = -1;
for (int i = 0; str[i]; i++) {
if (str[i] == '0') {
num[++cnt] = i - pos - 1;
pos = i;
}
}
num[++cnt] = n - 1 - pos;
pre[0] = 0;
for (int i = 1; i <= cnt; i++) pre[i] = pre[i - 1] + num[i];
for (int i = 0; i <= pre[cnt]; i++) {
for (int j = 0; j <= (pre[cnt] << 1); j++) f[i][j] = 0ll;
}
f[0][0] = 1ll;
for (int i = 1; i <= cnt; i++) {
for (int j = 0; j <= (pre[cnt] << 1); j++) {
tmp[0][j] = f[0][j];
for (int k = 1; k <= pre[cnt]; k++) tmp[k][j] = (tmp[k - 1][j] + f[k][j]) % mod;
}
for (int j = 0; j <= pre[cnt]; j++) {
for (int k = 0; k <= (pre[cnt] << 1); k++) {
g[j][k] = 0ll;
if (j >= pre[i]) {
g[j][k] = j > num[i] ? tmp[j - num[i] - 1][k] : 0ll;
for (int l = 0; l <= min(num[i], j); l++) {
if (k + l >= num[i]) g[j][k] = (g[j][k] + f[j - l][k + l - num[i]]) % mod;
}
}
}
}
for (int j = 0; j <= pre[cnt]; j++) {
for (int k = 0; k <= (pre[cnt] << 1); k++) f[j][k] = g[j][k];
}
}
long long ans = 0ll;
for (int i = 0; i <= min(pre[cnt] << 1, K); i++) ans = (ans + f[pre[cnt]][i]) % mod;
printf("%lld\n", ans);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
// container util
#define all(x) (x).begin(), (x).end()
// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};
// conversion
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
inline ll toLL(string s) {
ll v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
VLL a(n);
rep(i, n) cin >> a[i];
int mcnt = 0;
VLL absA;
ll ans = 0;
rep(i, n) {
absA.push_back(abs(a[i]));
ans += abs(a[i]);
if(a[i] < 0)
mcnt++;
}
sort(all(absA));
// rep(i, n) cout << absA[i] << " ";
// cout << endl;
// cout << ans << " " << absA[0] << endl;
if(mcnt % 2) {
cout << ans - 2LL * absA[0] << endl;
} else {
cout << ans << endl;
}
return 0;
}
| #ifdef _WIN32
#include "XOR.h"
#endif
#include <stdio.h>
#include <iostream>
#include <vector>
#include <array>
constexpr int64_t MOD = 1'000'000'007;
constexpr int64_t help = 1;
#define ll long long int
#define o(X) ll bits##X = 0
#define ok(X) bits##X += !!(d & (help << X))
#define oke(X) ans += (bits##X * (n - bits##X) % MOD) *((help << X) % MOD); ans %= MOD;
//ll p = (help << b) % MOD;
//ans += (bits[b] * (n - bits[b]) % MOD) * p;
//ans %= MOD;
char buf[1 << 17], *bp = buf, *bend = buf;
char gc() {
if (bp == bend) {
int x = fread_unlocked(buf, 1, sizeof buf, stdin);
bend = buf + x;
bp = buf;
}
return *bp++;
}
void fastscan(ll &n) {
char c;
n = 0;
c = gc();
for (; '0' <= c && c <= '9'; c = gc())
n = 10 * n + c - '0';
}
#ifdef _WIN32
namespace XOR
{
#endif
int main() {
ll n;
fastscan(n);
o(0);
o(1);
o(2);
o(3);
o(4);
o(5);
o(6);
o(7);
o(8);
o(9);
o(10);
o(11);
o(12);
o(13);
o(14);
o(15);
o(16);
o(17);
o(18);
o(19);
o(20);
o(21);
o(22);
o(23);
o(24);
o(25);
o(26);
o(27);
o(28);
o(29);
o(30);
o(31);
o(32);
o(33);
o(34);
o(35);
o(36);
o(37);
o(38);
o(39);
o(40);
o(41);
o(42);
o(43);
o(44);
o(45);
o(46);
o(47);
o(48);
o(49);
o(50);
o(51);
o(52);
o(53);
o(54);
o(55);
o(56);
o(57);
o(58);
o(59);
o(60);
o(61);
o(62);
std::array<ll, 62> bits{};
for (ll i = 0; i < n; i++) {
ll d;
fastscan(d);
ok(0);
ok(1);
ok(2);
ok(3);
ok(4);
ok(5);
ok(6);
ok(7);
ok(8);
ok(9);
ok(10);
ok(11);
ok(12);
ok(13);
ok(14);
ok(15);
ok(16);
ok(17);
ok(18);
ok(19);
ok(20);
ok(21);
ok(22);
ok(23);
ok(24);
ok(25);
ok(26);
ok(27);
ok(28);
ok(29);
ok(30);
ok(31);
ok(32);
ok(33);
ok(34);
ok(35);
ok(36);
ok(37);
ok(38);
ok(39);
ok(40);
ok(41);
ok(42);
ok(43);
ok(44);
ok(45);
ok(46);
ok(47);
ok(48);
ok(49);
ok(50);
ok(51);
ok(52);
ok(53);
ok(54);
ok(55);
ok(56);
ok(57);
ok(58);
ok(59);
ok(60);
ok(61);
ok(62);
}
ll ans = 0;
oke(0);
oke(1);
oke(2);
oke(3);
oke(4);
oke(5);
oke(6);
oke(7);
oke(8);
oke(9);
oke(10);
oke(11);
oke(12);
oke(13);
oke(14);
oke(15);
oke(16);
oke(17);
oke(18);
oke(19);
oke(20);
oke(21);
oke(22);
oke(23);
oke(24);
oke(25);
oke(26);
oke(27);
oke(28);
oke(29);
oke(30);
oke(31);
oke(32);
oke(33);
oke(34);
oke(35);
oke(36);
oke(37);
oke(38);
oke(39);
oke(40);
oke(41);
oke(42);
oke(43);
oke(44);
oke(45);
oke(46);
oke(47);
oke(48);
oke(49);
oke(50);
oke(51);
oke(52);
oke(53);
oke(54);
oke(55);
oke(56);
oke(57);
oke(58);
oke(59);
oke(60);
oke(61);
oke(62);
//for (ll b = 0; b < 62; b++) {
// ll p = (help << b) % MOD;
// ans += (bits[b] * (n - bits[b]) % MOD) * p;
// ans %= MOD;
//}
std::cout << ans;
return 0;
}
#ifdef _WIN32
}
#endif
| 0 |
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int H, W;
vector<string> fi;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
cin >> H >> W;
fi.resize(H);
for (int i = 0; i < H; ++i) cin >> fi[i];
// 多点をスタートとして扱う
vector<vector<int> > dist(H, vector<int>(W, -1));
using pint = pair<int,int>;
queue<pint> que;
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
if (fi[i][j] == '#') {
dist[i][j] = 0;
que.push(pint(i, j));
}
}
}
// BFS
while (!que.empty()) {
auto cur = que.front();
que.pop();
for (int dir = 0; dir < 4; ++dir) {
int nx = cur.first + dx[dir];
int ny = cur.second + dy[dir];
if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
if (dist[nx][ny] == -1) {
dist[nx][ny] = dist[cur.first][cur.second] + 1;
que.push(pint(nx, ny));
}
}
}
int res = 0;
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
res = max(res, dist[i][j]);
}
}
cout << res << endl;
} | #include<bits/stdc++.h>
using namespace std;
int H, W, x, y, ans = 0, flag = 0;
queue<int> Qx, Qx_next; queue<int> Qy, Qy_next;
bool can_go(int x, int y){
return (1 <= x && x <= H && 1 <= y && y<= W);
}
void f(vector<vector<int>>& A, int x, int y){
if(can_go(x,y)){
if(A[x][y] == 1){
flag = 1;
A[x][y] = -1;
Qx_next.push(x);
Qy_next.push(y);
}
}
}
void visit(vector<vector<int>>& A, int x, int y){
f(A, x-1, y);
f(A, x+1, y);
f(A, x, y-1);
f(A, x, y+1);
}
int main(){
cin >> H >> W;
vector<vector<int>> A(H+1, vector<int>(W+1, 1));
char buf;
for(int i = 1; i <= H; ++i){
for(int j = 1; j <= W; ++j){
cin >> buf;
if(buf == '#'){
A[i][j] = -1; //黒色ならfalse, 白色ならtrue
Qx.push(i);
Qy.push(j);
}
}
}
while(!Qx.empty()){
x = Qx.front();
y = Qy.front();
Qx.pop();
Qy.pop();
visit(A, x, y);
if(Qx.empty()){
while(!Qx_next.empty()){
Qx.push(Qx_next.front()); Qx_next.pop();
Qy.push(Qy_next.front()); Qy_next.pop();
}
if(flag == 1)++ans;
flag = 0;
}
}
cout << ans << endl;
return 0;
} | 1 |
/*
* src.cpp
*
* Created on: 2016/08/04
* Author: joi
*/
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
const int MAX_N=1e4;
int n;
int p[3];
char out[MAX_N+5];
int main(){
do{
cin>>n;
if (n){
REP(i,n){
int ave=0;
bool f=false;
REP(j,3){
cin>>p[j];
ave+=p[j];
if (p[j]==100){
f=true;
}
}
if (f){
out[i]='A';
}else if (p[0]+p[1]>=180){
out[i]='A';
}else if (ave>=80*3){
out[i]='A';
}else if (ave>=70*3){
out[i]='B';
}else if (ave>=50*3 && (p[0]>=80 || p[1]>=80)){
out[i]='B';
}else{
out[i]='C';
}
}
REP(i,n){
cout<<out[i]<<endl;
}
}
}while (n);
return 0;
} | #include <stdio.h>
void grade(int students)
{
while(students != 0) {
for(int i = 0; i < students; ++i) {
int math, english, japanese;
scanf("%d %d %d", &math, &english, &japanese);
int mean = (math + english + japanese) / 3;
if ((math == 100) || (english == 100) || (japanese == 100)) {
printf("A\n");
} else {
if (((math + english) / 2 >= 90) || mean >= 80) {
printf("A\n");
} else if ((mean >= 70) || ((mean >= 50) && ((math >= 80) || (english >= 80)))) {
printf("B\n");
} else {
printf("C\n");
}
}
}
scanf("%d", &students);
}
}
int main(void)
{
int students;
scanf("%d", &students);
grade(students);
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
vector<ll> z_algorithmll(const vector<ll> &s)
{
vector<ll> prefix(s.size());
for (int i = 1, j = 0; i < s.size(); i++)
{
if (i + prefix[i - j] < j + prefix[j])
{
prefix[i] = prefix[i - j];
}
else
{
int k = max(0LL, j + prefix[j] - i);
while (i + k < s.size() && s[k] == s[i + k])
++k;
prefix[i] = k;
j = i;
}
}
prefix[0] = (int)s.size();
return prefix;
}
int main()
{
ll n ;
cin >> n ;
vector<ll> a(n);
rep(i, n){
cin >> a[i];
}
vector<ll> b(n);
rep(i, n){
cin >> b[i];
}
vector<vector<ll>> v,vv;
rep(j,30){
vector<ll> a1;
vector<ll> a2;
vector<ll> bb;
rep(i,n){
if(a[i]>>j & 1LL){a1.push_back(1);a2.push_back(0);}
else {a1.push_back(0);a2.push_back(1);}
if(b[i]>>j & 1LL)bb.push_back(1);
else bb.push_back(0);
}
auto r=bb; r.push_back(-1);
r.insert(r.end(), a1.begin(), a1.end());
r.insert(r.end(), a1.begin(), a1.end());
v.push_back(z_algorithmll(r));
r=bb; r.push_back(-1);
r.insert(r.end(), a2.begin(), a2.end());
r.insert(r.end(), a2.begin(), a2.end());
vv.push_back(z_algorithmll(r));
}
rep(i,n){
bool ok=1;
ll ans=0;
rep(j,30){
if(v[j][i+n+1]!=n&&vv[j][i+n+1]!=n){
ok=0;
break;
}
if(vv[j][i+n+1]==n)ans+=1LL<<j;
}
if(ok)cout << i << ' ' << ans <<endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
if (b < a)
{
a = b;
return true;
}
return false;
}
//ll mod = 1000000007;
ll mod = 998244353;
signed main()
{
int n;
cin >> n;
vector<ll> a(n);
bool is_minus_even = true;
bool is_zero_exist = false;
rep(i, n)
{
cin >> a[i];
if (a[i] < 0)
{
is_minus_even = !is_minus_even;
}
if (a[i] == 0)
{
is_zero_exist = true;
}
}
ll ans = 0;
if (is_minus_even == true || (!is_minus_even && is_zero_exist))
{
rep(i, n)
{
ans += abs(a[i]);
}
}
else
{
rep(i, n)
{
a[i] = abs(a[i]);
}
sort(all(a));
ans = accumulate(a.begin() + 1, a.end(), 0LL) - a[0];
}
cout << ans << endl;
return 0;
} | 0 |
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
ll x=0,f=1;char c=getchar();
while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
if (c=='-') f=-1,c=getchar();
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x*f;
}
const int N = 1<<20|3, mod = 1e9+7;
int n,maxn,a[N],pre[N],s[N],s2[N],f[N];
poly v[N];
inline int Mod(int x){
return x>=mod?x-mod:x;
}
int main(){
n=read(),pre[0]=1;
For(i,1,n){
a[i]=read(),a[i]=a[i-1]^a[i],v[a[i]].pb(i);
pre[i]=pre[i-1]+(a[i]==0);
}
int ans=0;
if (a[n]==0){
int x=1;
For(i,1,pre[n]-2) x=x*2%mod;
ans=Mod(ans+x);
}
FOR(i,1,1<<20) if (!v[i].empty()){
f[0]=1,s[0]=1,s2[0]=pre[v[i][0]];
FOR(j,1,siz(v[i])){
f[j]=(1ll*s[j-1]*pre[v[i][j]]+mod-s2[j-1]+1)%mod;
s[j]=Mod(s[j-1]+f[j]),s2[j]=(s2[j-1]+1ll*f[j]*pre[v[i][j]])%mod;
}
if (a[n]==0) ans=Mod(ans+s[siz(v[i])-1]);
else if (a[n]==i) ans=Mod(ans+f[siz(v[i])-1]);
}
printf("%d\n",ans);
} | #include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>
#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;
ll mod_pow(ll x,int n){
return n? n&1? x*mod_pow(x,n-1)%MOD:mod_pow(x*x%MOD,n/2):1;
}
int N;
ll dp[(1<<20)+10],dpsum[(1<<20)+10],dpsum2[(1<<20)+10];
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin>>N;
vint A(N);
repeat(i,N)cin>>A[i];
int c=0;
int xorsum=0;
repeat(i,N){
c++;
int j=i+1;
xorsum=A[i];
while(j<N&&xorsum!=0){
dp[xorsum] = (1+dpsum[xorsum]*c-dpsum2[xorsum]+MOD)%MOD;
dpsum[xorsum] = (dpsum[xorsum]+dp[xorsum])%MOD;
dpsum2[xorsum] = (dpsum2[xorsum]+dp[xorsum]*c)%MOD;
xorsum ^= A[j];
j++;
}
i=j-1;
}
ll ans = 0;
if(xorsum){
ans = (1+dpsum[xorsum]*c-dpsum2[xorsum]+MOD)%MOD;
}else{
ans = mod_pow(2,c-1);
repeat(i,1<<20){
ans = (ans+dpsum[i])%MOD;
}
}
cout<<ans<<endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;
int main() {
int n;cin >>n;
n-=2;
cout <<n*180<<endl;
return 0;
}
| #include <bits/stdc++.h> // ver1.8
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000 // 9.0 * 10^18
#define MOD 1000000007 // 10^9 + 7
#define PAI 3.14159265358979
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;} // 最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;} // 最小公倍数lcm
signed main() {
cout << fixed << setprecision(14);
int n,k;
cin>>n>>k;
cout << 180*(n-2)<< endl;
return 0;
}
| 1 |
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int arr[100005];
int n,k,x;
int gcd(int a,int b){
if(b==0) return a;
return gcd(b,a%b);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>k;
bool u=false;
for(int i=1;i<=n;i++){
cin>>arr[i];
if(i==1) x=arr[1];
else x=gcd(x,arr[i]);
if(arr[i]==k){
cout<<"POSSIBLE"<<endl;
return 0;
}
if(arr[i]>k) u=true;
}
if(!u){
cout<<"IMPOSSIBLE"<<endl;
return 0;
}
if(k%x==0){
cout<<"POSSIBLE"<<endl;
}
else cout<<"IMPOSSIBLE"<<endl;
} | #include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
cin.tie(NULL);
ios::sync_with_stdio(false);
int a[10];
int k,b;
for(int i=0;i<5;i++){
cin>>a[i];
}
cin>>k;
sort(a,a+5);
b=a[4]-a[0];
if(k<b){
cout<<":("<<"\n";
}
else{
cout<<"Yay!"<<"\n";
}
return 0;
} | 0 |
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for (int i=(n)-1;i>=0;i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define REPS(i,f,n) for (int i=(f)-1;i>=(n);i--)
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
int n;
int field[21][21];
void hantei(void){
/*
rep(i, 21){
rep(j, 21){
printf("%d", field[i][j]);
}
printf("\n");
}
*/
int sum = 0;
rep(i, 21) rep(j, 21) sum += field[i][j];
//printf("summm %d\n", sum);
if (sum == 0) printf("Yes\n");
else printf("No\n");
return;
}
void slove(int n){
int x = 10, y = 10; //?????¨???????????????????????°
rep(i, 21) rep(j, 21) field[i][j] = 0;
rep(i, n){
int pointx, pointy;
cin >> pointx >> pointy;
field[pointy][pointx] = 1;//????????????????????¨??????????????????
}
int meireikaisu;
cin >> meireikaisu;
rep(i, meireikaisu){
string meirei;
int kyori;
cin >> meirei >> kyori;
if (meirei[0] == 'N'){
reps(j, 1, kyori + 1){
if (field[y + j][x] == 1) field[y + j][x]--;//??¨??£????????????
}
y += kyori;
}else if(meirei[0] == 'E'){
reps(j, 1, kyori + 1){
if (field[y][x + j] == 1) field[y][x + j]--;
}
x += kyori;
}else if(meirei[0] == 'S'){
reps(j, 1, kyori + 1){
if (field[y - j][x] == 1) field[y - j][x]--;
}
y -= kyori;
}else if(meirei[0] == 'W'){
reps(j, 1, kyori + 1){
if (field[y][x - j] == 1) field[y][x - j]--;
}
x -= kyori;
}
}
hantei();
}
int main(void){
rep(i, 1000){
cin >> n;
if (n == 0) break;
slove(n);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int main(){
int N,x,y,M,l;
char d;
map<char,int> D;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
D['E']=0; D['W']=1; D['N']=2; D['S']=3;
while(cin>>N,N){
bool a[21][21]={};
rep(i,N){
cin>>x>>y;
a[x][y]=true;
}
x=y=10;
cin>>M;
rep(i,M){
cin>>d>>l;
while(l--){
if(a[x+=dx[D[d]]][y+=dy[D[d]]]){
a[x][y]=false;
N--;
}
}
}
cout<<(N?"No":"Yes")<<endl;
}
return 0;
} | 1 |
/**
* author: yuya1234
* created: 25.06.2020 13:29:29
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
ll n,x,tmp;
vector<ll> v;
cin>>n>>x;
REP(i,n)
{
cin>>tmp;
v.push_back(tmp);
}
SORT(v);
ll cnt=0;
REP(i,n)
{
if((x>=v[i] && i!=n-1) || x==v[i])
{
x-=v[i];
cnt++;
}
}
cout<<cnt<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
long int n,x;
cin >> n >> x;
vector<long int> a(n);
long int sum=0;
int i;
for(i=0; i<n; i++){
cin >> a.at(i);
sum+=a.at(i);
}
sort(a.begin(),a.end());
if(x>sum) cout << n-1 << endl;
else if(x==sum) cout << n << endl;
else{
for(i=0; i<n; i++){
sum-=a.at(n-1-i);
if(x>=sum) break;
}
cout << n-1-i << endl;
}
} | 1 |
#include <math.h>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
long sum;
cin >> sum;
cout << int(pow(sum, 3)) << endl;
} | #include <iostream>
using namespace std;
int main(void){
int x,y;
x=y=0;
cin>>x;
y=x*x*x;
cout<<y<<endl;
return 0;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
ll dp[2][2][100];
ll mod=1e9+7;ll d;
ll mo(ll x)
{
if(x>=0)
return(x%d);
else
return(x%d+d)%d;
}
int main()
{
flash
string s;
cin>>s;ll n=s.size();ll a[n];
for(ll i=0;i<n;i++)
{
a[i]=s[i]-'0';
}
cin>>d;
dp[1][0][0] = 1;dp[1][1][0] = 1;
for(ll i = n-1; i >=0 ; i--) {
for(ll state = 0; state < 2 ; state++) {
for(ll sum = 0; sum < d; sum++) {
if(state) {
for(ll x = 0; x <= a[i] ; x++) {
dp[0][1][sum] += (x== a[i]) ? dp[1][1][mo(sum-x)]%mod:dp[1][0][mo(sum-x)]%mod;
}
}
else {
for(ll x = 0; x < 10 ; x++) {
dp[0][0][sum] += dp[1][0][mo(sum-x)]%mod;
}
}
}
}
if(i!=0)
{
for(ll sum=0;sum<d;sum++)
{
dp[1][1][sum]=dp[0][1][sum];
dp[1][0][sum]=dp[0][0][sum];
dp[0][1][sum]=0;
dp[0][0][sum]=0;
}
}
}
dp[0][1][0]--;
dp[0][1][0]=dp[0][1][0]%mod;
cout<<dp[0][1][0]<<endl;
} | #include<iostream>
#include<string>
using namespace std;
int alignment(string s,string t){
int a[1001][1001];
int n=s.size();
int m=t.size();
a[0][0]=0;
for(int i=0;i<n;i++){
a[i+1][0]=a[i][0]+1;
}
for(int i=0;i<m;i++){
a[0][i+1]=a[0][i]+1;
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(s[i]==t[j]){
a[i+1][j+1]=min(a[i][j],min(a[i+1][j]+1,a[i][j+1]+1));
}else{
a[i+1][j+1]=min(a[i][j]+1,min(a[i+1][j]+1,a[i][j+1]+1));
}
}
}
return a[n][m];
}
int main(void){
string s;
string t;
cin >> s >> t;
cout << alignment(s,t) <<endl;
}
| 0 |
#include <stdio.h>
int main(void) {
int n, i, po[2] = {0}, ca[2];
while(scanf("%d", &n)){
if(!n)break;
po[0] = 0;
po[1] = 0;
for(i = 0; n > i; i++){
scanf("%d%d", &ca[0], &ca[1]);
if(ca[0] > ca[1]) po[0] += ca[0]+ca[1];
else if(ca[0] < ca[1]) po[1] += ca[0]+ca[1];
else{ po[0] += ca[0]; po[1] += ca[1];}
}
printf("%d %d\n",po[0],po[1]);
}
return 0;
} | #pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
ll dp[2][3];
dp[0][0] = 0;
dp[0][1] = -1e18;
dp[0][2] = -1e18;
dp[1][0] = -1e18;
dp[1][1] = -1e18;
dp[1][2] = -1e18;
int n = N / 2;
if (N % 2) {
rep(i, n) {
int a, b;
cin >> a >> b;
chmax(dp[1][1], dp[0][0]);
dp[0][0] += a;
dp[0][2] += a;
chmax(dp[0][2], dp[1][1]);
dp[1][1] += b;
}
int a;
cin >> a;
chmax(dp[1][1], dp[0][0]);
dp[0][2] += a;
printf("%lld\n", max(dp[0][2], dp[1][1]));
}
else {
rep(i, n) {
int a, b;
cin >> a >> b;
chmax(dp[1][1], dp[0][0]);
dp[0][0] += a;
dp[1][1] += b;
}
printf("%lld\n", max(dp[1][1], dp[0][0]));
}
Would you please return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
int cnt=0;
string s;
cin>>s;
int m =0;
for(int i =0 ;i<3;i++)
{
if(s[i]=='R')m++;
else
{
cnt = max(m,cnt);
m =0;
}
}
cnt = max(m,cnt);
cout<<cnt;
return 0;
}
| #include<bits/stdc++.h>
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define N 4e7
#define nl "\n"
#define f first
#define s second
#define pi acos(-1.0)
#define MOD 1000000007
#define pb push_back
#define vector<int> VI;
#define vector<long long> VII;
typedef long long ll;
typedef double db;
using namespace std;
int main()
{
io;
//freopen("in.txt" , "r" , stdin);
//freopen("out.txt" , "w" , stdout);
///Let the showdown begin
string str;
int cnt;
cin >> str;
if(str[0] =='R' && str[1] == 'R' && str[2] == 'R')
cnt = 3;
else if((str[0] =='R' && str[1] == 'R' && str[2] == 'S') || (str[0] =='S' && str[1] == 'R' && str[2] == 'R'))
cnt = 2;
else if((str[0] =='S' && str[1] == 'S' && str[2] == 'S'))
cnt = 0;
else
cnt = 1;
cout << cnt << nl;
///Happily DONE
return 0;
}
| 1 |
#include <iostream>
using namespace std;
const int MAX = 500;
int main() {
int n, m, Q;
cin >> n >> m >> Q;
int S[MAX+1][MAX+1] = {};
for (int i = 0; i < m; i++) {
int l, r;
cin >> l >> r;
S[l][r]++;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
S[i][j] += S[i][j-1];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
S[i][j] += S[i-1][j];
}
}
auto sum_rect = [&](int x0, int y0, int x1, int y1) {
return S[x1][y1] - S[x0-1][y1] - S[x1][y0-1] + S[x0-1][y0-1];
};
for (int query = 0; query < Q; query++) {
int p, q;
cin >> p >> q;
int ans = sum_rect(p, p, q, q);
cout << ans << endl;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int main(){
int n,m,q;cin>>n>>m>>q;
vvi g(n);
rep(i,m){
int l,r;
cin>>l>>r;
l--;r--;
g[l].PB(r);
}
rep(i,n){
sort(all(g[i]));
}
rep(i,q){
int P,Q;
cin>>P>>Q;
P--;Q--;
int cnt=0;
for(int j=P;j<=Q;++j){
cnt+=upper_bound(all(g[j]),Q)-g[j].begin();
}
cout<<cnt<<endl;
}
}
| 1 |
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif
void d_err() {
cerr << endl;
}
template <typename H, typename... T>
void d_err(H h, T... t) {
cerr << h << " ";
d_err(t...);
}
template <typename T>
void print(T x) {
cout << x << endl;
}
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;
ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;
void chmax(ll& a, ll b) {
if (a < b) a = b;
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
ll N;
cin >> N;
vll A(N);
REP(i, N) cin >> A[i];
vector<vll> dp(N, vll(3, -INF));
dp[0][0] = 0;
dp[0][1] = 0;
dp[0][2] = A[0];
REP(i, N - 1) {
auto &nxt = dp[i+1], &cur = dp[i];
if (N & 1) {
if (i & 1) {
chmax(nxt[0], cur[1]);
chmax(nxt[0], cur[2]);
chmax(nxt[1], cur[0] + A[i+1]);
chmax(nxt[2], cur[2] + A[i+1]);
} else {
chmax(nxt[0], cur[0]);
chmax(nxt[0], cur[1]);
chmax(nxt[1], cur[0] + A[i+1]);
chmax(nxt[2], cur[2]);
}
} else {
if (i & 1) {
chmax(nxt[0], cur[0]);
chmax(nxt[0], cur[2]);
chmax(nxt[2], cur[0] + A[i+1]);
} else {
chmax(nxt[0], cur[2]);
chmax(nxt[2], cur[0] + A[i+1]);
}
}
}
if (N&1) print(max(dp[N-1][0], dp[N-1][1]));
else print(max(dp[N-1][0], dp[N-1][2]));
}
| #include <iostream>
#include <vector>
#include <limits>
#include <algorithm>
struct RangeUpdateQuery{
int n, now;
std::vector<int> dat, time;
void init(int n_){
n = 1;
now = 0;
while(n < n_) n *= 2;
dat.resize(2 * n - 1, std::numeric_limits<int>::max());
time.resize(2 * n - 1, 0);
}
void update(int a, int b, int k, int l, int r, int x){
if(r <= a || b <= l) return;
if(a <= l && r <= b){
dat[k] = x;
time[k] = now;
}
else{
update(a, b, k * 2 + 1, l, (l + r) / 2, x);
update(a, b, k * 2 + 2, (l + r) / 2, r, x);
}
}
void update(int a, int b, int x){
now++;
update(a, b, 0, 0, n, x);
}
int query(int k){
k += n - 1;
int res = dat[k], recent = time[k];
while(k > 0) {
k = (k - 1) / 2;
if(recent < time[k]){
recent = time[k];
res = dat[k];
}
}
return res;
}
};
using namespace std;
int main(){
int n, q;
cin >> n >> q;
RangeUpdateQuery ruq;
ruq.init(n);
while(q--){
int com;
cin >> com;
if(com){
int i;
cin >> i;
cout << ruq.query(i) << "\n";
}else{
int s, t, x;
cin >> s >> t >> x;
ruq.update(s, t + 1, x);
}
}
}
| 0 |
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int stage[12][12] = {{0}};
int n;
int j = 0;
int x = 0,y = 0,xx = 0;
for(;;){
cin >> n;
if(n == 0)break;
for(int i = 0;i < n; i++){
for(j = 0;j < n; j++){
cin >> stage[i][j];
x += stage[i][j];
if(j == n-1){
stage[i][n] = x;
xx += stage[i][n];
x = 0;
}
}
}
for(int i = 0;i < n; i++){
for(j = 0;j < n; j++){
y += stage[j][i];
if(j == n-1){
stage[n][i] = y;
y = 0;
}
}
}
stage[n][n] = xx;
for(int i = 0;i <= n; i++){
for(int j = 0;j <= n; j++){
printf("%5d",stage[i][j]);
}
printf("\n");
}
x = 0,y = 0,xx = 0;
}
return 0;
} | #include<stdio.h>
#include<string.h>
#define SIZE 1002
int main(){
int i,j;
int na,nb,nc,n;
int a[SIZE],b[SIZE],c[SIZE],d[SIZE];
int data[SIZE];
while(1){
scanf("%d %d %d",&na,&nb,&nc);
if(na==0 && nb==0 && nc==0)break;
scanf("%d",&n);
for(i=1;i<=na+nb+nc;i++)data[i]=2;
for(i=0;i<n;i++){
scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
if(d[i]==1){
data[a[i]]=data[b[i]]=data[c[i]]=1;
}
}
for(i=0;i<n;i++){
if(d[i]==0){
if(data[a[i]]==1 && data[b[i]]==1)data[c[i]]=0;
else if(data[a[i]]==1 && data[c[i]]==1)data[b[i]]=0;
else if(data[b[i]]==1 && data[c[i]]==1)data[a[i]]=0;
}
}
for(i=1;i<=na+nb+nc;i++){
printf("%d\n",data[i]);
}
}
return 0;
} | 0 |
// A - Rated for Me
#include <bits/stdc++.h>
using namespace std;
int main(){
int r; cin>>r;
string ans = "ARC";
if(r < 1200) ans = "ABC";
if(2800 <= r) ans = "AGC";
cout<< ans <<endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
template<typename T> bool chmax(T &a, T b) {if(a <= b){a = b; return true;}return false;}
template<typename T> bool chmin(T &a, T b) {if(a >= b){a = b; return true;}return false;}
#define ABC 001
#define ARC 010
#define AGC 100
int main(void){
int r;
cin >> r;
int frag = AGC;
if(r < 1200){
frag |= ABC;
frag |= ARC;
}else if( r < 2800){
frag |= ARC;
}
if(frag & ABC)cout << "ABC" << endl;
else if(frag & ARC)cout << "ARC" << endl;
else cout << "AGC" << endl;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, a, b, c, d, e;
cin >> n >> a >> b >> c >> d >> e;
ll ans = 0;
chmax(ans, (n+a-1)/a+4);
chmax(ans, (n+b-1)/b+4);
chmax(ans, (n+c-1)/c+4);
chmax(ans, (n+d-1)/d+4);
chmax(ans, (n+e-1)/e+4);
cout << ans << endk;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;
template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }
constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
void solve() {
int m;
cin >> m;
ll res = 0, sum = 0;
for (int i=0; i<m; ++i) {
ll d, c;
cin >> d >> c;
res += c;
sum += d * c;
}
cout << res - 1 + (sum - 1) / 9 << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
solve();
return 0;
}
| 0 |
#include <iostream>
#include <string>
using namespace std;
int map[21][21];
void search(int a[][21], string d, int i, int *x, int *y) {
if (d == "N") {
for (int j = 1; j <= i; j++) a[*y + j][*x] = 2;
*y += i;
} else if (d == "S") {
for (int j = 1; j <= i; j++) a[*y - j][*x] = 2;
*y -= i;
} else if (d == "E") {
for (int j = 1; j <= i; j++) a[*y][*x + j] = 2;
*x += i;
} else if (d == "W") {
for (int j = 1; j <= i; j++) a[*y][*x - j] = 2;
*x -= i;
}
}
int judge (int a[][21]) {
for (int i = 0; i < 21; i++) {
for (int j = 0; j < 21; j++) {
if (a[i][j] == 1) return 0;
}
}
return 1;
}
void print (int a[][21]) {
for (int i = 20; i >= 0; i--) {
for (int j = 0; j < 21; j++) {
cout << a[i][j] << " ";
}
cout << "\n";
}
}
int main(void) {
int N, x, y, M, i, nowx, nowy;
string d;
cin.tie(0);
//ios::sync_with_stdio(false);
while (cin >> N, N) {
nowx = nowy = 10;
for (int k = 0; k < 21; k++) {
for (int l = 0; l < 21; l++) {
map[k][l] = 0;
}
}
//print(map);
for (int j = 0; j < N; j++) {
cin >> x >> y;
map[y][x] = 1;
}
map[nowy][nowx] = 2;
//print(map);
cin >> M;
for (int k = 0; k < M; k++) {
cin >> d >> i;
search(map, d, i, &nowx, &nowy);
//print(map);
}
cout << (judge(map) == 1 ? "Yes" : "No") << "\n";
}
return 0;
} | #include <iostream>
using namespace std;
int main()
{
int a,b,c; int CASE[1000][3];
while(1)
{
cin >> a >> b >> c ; int total=a+b+c;
if(a==0 && b==0 && c==0) break;
int N,i,j,k,r; int pnt=0;
cin >> N ;
int* test=new int[total]; for(int n=0;n<total;n++) test[n]=2;
for(int n=0;n<N;n++)
{
cin >> i >> j >> k >> r ;
if(r==1) test[i-1]=test[j-1]=test[k-1]=1;
else CASE[pnt][0]=i-1,CASE[pnt][1]=j-1,CASE[pnt++][2]=k-1;
}
for(int n=0;n<pnt;n++)
{
if(test[CASE[n][0]]==1 && test[CASE[n][1]]==1 && test[CASE[n][2]]==2) test[CASE[n][2]]=0;
if(test[CASE[n][0]]==1 && test[CASE[n][2]]==1 && test[CASE[n][1]]==2) test[CASE[n][1]]=0;
if(test[CASE[n][1]]==1 && test[CASE[n][2]]==1 && test[CASE[n][0]]==2) test[CASE[n][0]]=0;
}
for(int n=0;n<total;n++)
cout << test[n] << '\n' ;
}
} | 0 |
#include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'
using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;
static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;
const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};
vector<LL> Div(LL n) {
vector<LL> ret;
for(LL i = 1; i * i <= n; ++i) {
if(n % i == 0) {
ret.pb(i);
if(i * i != n) ret.pb(n / i);
}
}
sort(all(ret));
return ret;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vector<int> v(N);
for(int i = 0; i < N; ++i) {
cin >> v[i];
}
sort(all(v));
LL a, b;
a = 0, b = 0;
for(int i = 0; i < N - 1; ++i) {
if(v[i] == v[i + 1]) {
b = a;
a = v[i];
i++;
}
}
cout << a * b << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
int main() {
int n;
cin >> n;
map<ll, int, greater<ll>> m;
rep(i, n) {
ll a;
cin >> a;
m[a]++;
}
int cnt = 0;
ll ans = 0;
for (auto e : m) {
if (e.second >= 4 && cnt == 0) {
ans = e.first * e.first;
cnt += 2;
break;
} else if (e.second >= 2) {
if (cnt == 0)
ans = e.first, cnt++;
else if (cnt == 1) {
ans *= e.first, cnt++;
break;
}
}
}
if (cnt == 1) ans = 0;
cout << ans << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;
int a = h1 * 60 + m1, b = h2 * 60 + m2;
int ans = b - a;
if (ans < 0) ans += 24 * 60;
ans -= k;
cout << ans << "\n";
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll h1,m1,h2,m2,k;
cin>>h1>>m1>>h2>>m2>>k;
ll t=((h2-h1)*60)-m1+m2;
ll d=t-k;
if(d<=0){
cout<<"0"<<"\n";
}
else{
cout<<d<<"\n";
}
return 0;
} | 1 |
#include <iostream>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
int n;
int a[305];
ll dp[305][90005];
ll dp2[305][90005];
ll p(ll a, ll x) {
ll res = 1;
while(x > 0) {
if(x & 1) res = res * a % mod;
a = a * a % mod;
x >>= 1;
}
return res;
}
int main() {
cin >> n;
int sum = 0;
int maxa = 0;
for(int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
maxa = max(maxa,a[i]);
}
dp[0][0] = 1;
for(int i = 0; i < n; i++) {
for(int j = 0; j <= i * maxa; j++) {
if(dp[i][j] == 0) continue;
dp[i+1][j] = (dp[i+1][j] + dp[i][j] * 2) % mod;
dp[i+1][j+a[i]] = (dp[i+1][j+a[i]] + dp[i][j]) % mod;
}
}
dp2[0][0] = 1;
for(int i = 0; i < n; i++) {
for(int j = 0; j <= i * maxa; j++) {
if(dp2[i][j] == 0) continue;
dp2[i+1][j] = (dp2[i+1][j] + dp2[i][j]) % mod;
dp2[i+1][j+a[i]] = (dp2[i+1][j+a[i]] + dp2[i][j]) % mod;
}
}
ll ans = p(3,n);
for(int i = 0; i <= n * maxa; i++) {
if(i >= sum - i) {
ans = (ans + mod - dp[n][i] * 3 % mod) % mod;
}
if(i == sum - i) {
ans = (ans + dp2[n][i] * 3 % mod) % mod;
}
}
if(ans < 0 ) cout << ans + mod << endl;
else
cout << ans << endl;
}
| #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define MOD 998244353
using namespace std;
typedef long long ll;
template <typename Tp> inline void getint(Tp &num){
register int ch, neg = 0;
while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
num = ch & 15;
while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
if(neg) num = -num;
}
inline int fastpow(int bas, int ex){
register int res = 1;
for(; ex; ex >>= 1, bas = bas * (ll)bas % MOD) if(ex & 1) res = res * (ll)bas % MOD;
return res;
}
inline int kazu(int a, const int &b) {return (a += b) >= MOD ? a - MOD : a;}
inline int hiku(int a, const int &b) {return (a -= b) < 0 ? a + MOD : a;}
int N, sum = 0, f[90005], g[90005];
int main(){
getint(N), f[0] = g[0] = 1;
for(register int i = 1, a; i <= N; i++){
getint(a), sum += a;
for(register int j = sum; j >= 0; j--){
f[j] = f[j] * 2LL % MOD;
if(j >= a) f[j] = kazu(f[j], f[j - a]), g[j] = kazu(g[j], g[j - a]);
}
}
int ans = fastpow(3, N);
for(register int i = sum + 1 >> 1; i <= sum; i++) ans = hiku(ans, f[i] * 3LL % MOD);
if(!(sum & 1)) ans = kazu(ans, g[sum >> 1] * 3LL % MOD);
return printf("%d\n", ans), 0;
} | 1 |
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
#include<cmath>
using namespace std;
double len(int x1,int x2, int y1,int y2){
double res;
double x=x1-x2;
double y=y1-y2;
res=pow(x*x+y*y,0.5);
return res;
}
int main(){
int n;
cin>>n;
int x[n],y[n];
double ans=0;
for(int i=0;i<n;i++)cin>>x[i]>>y[i];
for(int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
ans+=len(x[i],x[j],y[i],y[j])*2.0/n;
}
}
cout<<fixed<<setprecision(12)<<ans<<endl;
return 0;
} | #include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 1e5 + 5;
int x[8], y[8];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int N;
cin >> N;
double sum = 0;
int cnt = 0;
for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
vector<int> v(N);
iota(all(v), 0);
do {
double cur = 0;
for (int i = 1; i < N; i++) {
int dx = x[v[i]]-x[v[i-1]], dy = y[v[i]]-y[v[i-1]];
cur += sqrt(dx*dx+dy*dy);
}
sum += cur;
cnt++;
} while (next_permutation(all(v)));
cout << fixed << setprecision(7) << sum / cnt << '\n';
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
int N,M,Q,m;
const int maxn=600000+5;
int siz;
int C[maxn],a[maxn],ret[maxn];
struct node{
int l,r,id;
bool operator<(const node& other)const{
return other.r > r;
}
}x[maxn],y[maxn];
void add(int x,int v){
for(int i=x;i<=m;i+=i&-i) C[i]+=v;
}
int sum(int x){
int ret=0;
for(int i=x;i;i-=i&-i) ret+=C[i];
return ret;
}
int main(){
cin>>N>>M>>Q;
for(int i=0;i<M;i++){
cin>>x[i].l>>x[i].r;
a[siz++]=x[i].l;
a[siz++]=x[i].r;
}
for(int i=0;i<Q;i++){
cin>>y[i].l>>y[i].r;
y[i].id=i;
a[siz++]=y[i].l;
a[siz++]=y[i].r;
}
sort(a,a+siz);
m=unique(a,a+siz)-a;
for(int i=0;i<M;i++){
x[i].l=lower_bound(a,a+m,x[i].l)-a+1;
x[i].r=lower_bound(a,a+m,x[i].r)-a+1;
}
for(int i=0;i<Q;i++){
y[i].l=lower_bound(a,a+m,y[i].l)-a+1;
y[i].r=lower_bound(a,a+m,y[i].r)-a+1;
}
sort(x,x+M);
sort(y,y+Q);
int j=0;
for(int i=0;i<Q;i++){
while(j<M&&x[j].r<=y[i].r) add(x[j++].l,1);
ret[y[i].id]=j-sum(y[i].l-1);
}
for(int i=0;i<Q;i++) cout<<ret[i]<<endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
int main() {
int n, m, q;
cin >> n >> m >> q;
vector<vector<int>> cnt(n+1, vector<int>(n+1, 0));
rep(i, m){
int l, r;
cin >> l >> r;
cnt[l][r]++;
}
rep(i, n)rep(j, n){
cnt[i+1][j+1] += cnt[i][j+1] + cnt[i+1][j] - cnt[i][j];
}
rep(i, q){
int p, q;
cin >> p >> q;
int ans = cnt[q][q] - cnt[q][p-1] - cnt[p-1][q] + cnt[p-1][p-1];
cout << ans << endl;
}
} | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,char> Q;
ll N;
vector<Q> v;
vector<vector<P>> V,H;
set<P> S;
vector<vector<ll>> LU,LD,RU,RD;
int main(){
cin >> N;
V.resize(200010);
H.resize(200010);
LU.resize(400010);
LD.resize(400010);
RU.resize(400010);
RD.resize(400010);
ll offset = 200000;
for(int i=0;i<N;i++){
ll x,y;
char u;
cin >> x >> y >> u;
v.push_back({{x,y},u});
}
for(auto &e : v){
ll x = e.first.first;
ll y = e.first.second;
if(S.find({x,y}) != S.end()){
cout << 0 << endl;
return 0;
}
S.insert({x,y});
}
for(auto &e : v){
ll x = e.first.first;
ll y = e.first.second;
if(e.second == 'U'){
V[x].push_back({y,0});
RU[x+y].push_back(x);
LU[x-y+offset].push_back(x);
}
if(e.second == 'D'){
V[x].push_back({y,1});
LD[x+y].push_back(x);
RD[x-y+offset].push_back(x);
}
if(e.second == 'R'){
H[y].push_back({x,0});
}
if(e.second == 'L'){
H[y].push_back({x,1});
}
}
ll ans = 1e18;
for(int i=0;i<=200000;i++) sort(V[i].begin(),V[i].end());
for(int i=0;i<=200000;i++) sort(H[i].begin(),H[i].end());
for(int i=0;i<=200000;i++){
ll tmp = -1;
for(auto &e : V[i]){
ll x = e.first;
ll d = e.second;
if(d == 0) tmp = x;
else{
if(tmp == -1) continue;
ans = min(ans, (x-tmp) * 5);
}
}
}
for(int i=0;i<=200000;i++){
ll tmp = -1;
for(auto &e : H[i]){
ll y = e.first;
ll d = e.second;
if(d == 0) tmp = y;
else{
if(tmp == -1) continue;
ans = min(ans, (y-tmp) * 5);
}
}
}
for(int i=0;i<=400000;i++) sort(LU[i].begin(),LU[i].end());
for(int i=0;i<=400000;i++) sort(LD[i].begin(),LD[i].end());
for(int i=0;i<=400000;i++) sort(RU[i].begin(),RU[i].end());
for(int i=0;i<=400000;i++) sort(RD[i].begin(),RD[i].end());
for(auto &e : v){
ll x = e.first.first;
ll y = e.first.second;
if(e.second == 'U'){
continue;
}
if(e.second == 'D'){
continue;
}
if(e.second == 'R'){
auto itr_d = upper_bound(RD[x-y+offset].begin(),RD[x-y+offset].end(),x);
if(itr_d != RD[x-y+offset].end()) ans = min(ans,((*itr_d) - x)*10);
auto itr_u = upper_bound(RU[x+y].begin(),RU[x+y].end(),x);
if(itr_u != RU[x+y].end()) ans = min(ans,((*itr_u) - x)*10);
}
if(e.second == 'L'){
auto itr_d = upper_bound(LD[x+y].begin(),LD[x+y].end(),x);
if(itr_d != LD[x+y].begin() && LD[x+y].size() != 0) ans = min(ans,(x - *(itr_d-1))*10);
auto itr_u = upper_bound(LU[x-y+offset].begin(),LU[x-y+offset].end(),x);
if(itr_u != LU[x-y+offset].begin() && LU[x-y+offset].size() != 0) ans = min(ans,(x - *(itr_u-1))*10);
}
}
if(ans == 1e18) cout << "SAFE" << endl;
else cout << ans << endl;
return 0;
} | #include<cstdio>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const static int MOD = 1e9+7;
int main(){
int N;
scanf("%d\n", &N);
bool is_black[2*N];
for (int i = 0; i < 2*N; ++i){
char tmp;
scanf("%c", &tmp);
is_black[i] = tmp == 'B';
}
bool is_left_end[2*N];
if(!is_black[0]){
printf("0\n");
return 0;
}
is_left_end[0] = true;
int n_right_end = 0;
ull ans = 1;
for (int i = 1; i < 2*N; ++i){
is_left_end[i] = (is_black[i] ^ is_black[i-1]) ? is_left_end[i-1] : !is_left_end[i-1];
if(!is_left_end[i]){
//これを含めてこれより左側にある左端の数はi-n_right_end、右端の数はn_right_end+1
if(i - n_right_end < n_right_end + 1){
printf("0\n");
return 0;
}
(ans *= i - n_right_end*2) %= MOD;
n_right_end++;
}
}
if(n_right_end != N){
printf("0\n");
return 0;
}
for (int i = 2; i <= N; ++i) (ans *= i) %= MOD;
printf("%llu\n", ans);
return 0;
} | 0 |
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
LL p = 1000000007ll;
int main(void)
{
int n;
cin >> n;
vector<int> a(n);
for(auto &x: a) cin >> x;
vector<vector<int> > cnt0(1<<20);
int zeros = 0;
int part = 0;
for(auto x:a) {
part ^= x;
if(part) cnt0[part].push_back(zeros);
else ++zeros;
}
if(part) {
LL pre = 0;
LL j = 1;
LL k = 0;
for(auto c:cnt0[part]) {
LL tmp = c-pre;
j += k*tmp;
j %= p;
k += j;
k %= p;
pre = c;
}
cout << j << endl;
return 0;
} else {
LL answer = 1;
REP(i,zeros-1) {
answer *= 2;
answer %= p;
}
FOR(i,1,1<<20) {
LL pre = 0;
LL j = 1;
LL k = 0;
for(auto c:cnt0[i]) {
LL tmp = c-pre;
j += k*tmp;
j %= p;
k += j;
k %= p;
pre = c;
}
answer += k;
answer %= p;
}
cout << answer << endl;
return 0;
}
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 550000;
const int MOD = 1e9 + 7;
int a[N], sum[N], cnt[N];
vector<int> pos[1 << 21];
int chk[1 << 21];
inline int modExp(int a, int n, int mod) {
int ret = 1;
while (n) {
if (n & 1) ret = (long long)ret * a % mod;
a = (long long)a * a % mod;
n >>= 1;
}
return ret;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n; cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i], sum[i] = sum[i - 1] ^ a[i], cnt[i] = cnt[i - 1] + (sum[i] == 0);
for (int i = 1; i <= n; i++) pos[sum[i]].push_back(i);
if (sum[n] == 0) {
int ans = 0;
for (int i = 1; i <= n; i++) if (sum[i] && !chk[sum[i]]) {
chk[sum[i]] = 1;
int cnt0 = 1, cntg = 0;
for (int j = pos[sum[i]].size() - 1; j >= 0; j--) {
(cntg += cnt0) >= MOD && (cntg -= MOD);
if (j) (cnt0 += (long long)cntg * (cnt[pos[sum[i]][j]] - cnt[pos[sum[i]][j - 1]]) % MOD) >= MOD && (cnt0 -= MOD);
}
(ans += cntg) >= MOD && (ans -= MOD);
}
(ans += modExp(2, cnt[n] - 1, MOD)) >= MOD && (ans -= MOD);
cout << ans << "\n";
return 0;
} else {
int cnt0 = 1, cntg = 0;
for (int j = 0; j < pos[sum[n]].size(); j++) {
(cntg += cnt0) >= MOD && (cntg -= MOD);
if (j + 1 < pos[sum[n]].size()) (cnt0 += (long long)cntg * (cnt[pos[sum[n]][j + 1]] - cnt[pos[sum[n]][j]]) % MOD) >= MOD && (cnt0 -= MOD);
}
cout << cnt0 << "\n";
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
// Grid Repainting 2
int h, w; cin >> h >> w;
vector<string> s(h);
rep(i,h) cin >> s.at(i);
vector<int> di = {1, 0, -1, 0};
vector<int> dj = {0, 1, 0, -1};
rep(i,h) {
rep(j,w) {
if (s.at(i).at(j) == '#') {
int cnt = 0;
rep(k,4) {
int ni = i + di[k];
int nj = j + dj[k];
if (0 <= ni && ni < h && 0 <= nj && nj < w) {
if (s.at(ni).at(nj) == '.') cnt++;
}
}
if (cnt == 4) {
cout << "No" << endl;
return 0;
}
}
}
}
cout << "Yes" << endl;
return 0;
} | #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
int main(){
string s;
cin>>s;
if(s=="zyxwvutsrqponmlkjihgfedcba"){
out(-1);
return 0;
}
if(s.length()<26){
cout<<s;
char c='a';
rep(i,26){
if(count(all(s),c)==0){
cout<<c<<endl;
return 0;
}
c++;
}
}else if(s.length()==26){
int n=25,d=0;
while(1){
s[n]++;
if(s[n]>'z'){
s[n-1]++;
s.erase(s.begin()+n);
n--;
}
if(s[n]>='a'&&s[n]<='z'&&count(all(s),s[n])==1)break;
}
cout<<s<<endl;
}
} | 0 |
#include <stdio.h>
#include <math.h>
#define MAXINPUT 100
int main(void){
int h[MAXINPUT],w[MAXINPUT];
int ansh[MAXINPUT]={},answ[MAXINPUT]={};
int i=0,j=0;
int ans=0;
int num=0;
int k;
while(i<MAXINPUT){
scanf("%d %d",&h[i],&w[i]);
if(h[i]==0 && w[i]==0)break;
i++;
num++;
}
for(i=0;i<num;i++,ans=0){
ans=h[i]*h[i]+w[i]*w[i];
for(;(ansh[i]==0||answ[i]==0);){
for(j=1;k==0;j++){
double temp=ans-(j*j);
double tempa=0;
if(temp<=0){
k=1;
break;
}
temp=sqrt(temp);
temp=modf(temp,&tempa);
if(temp==0 && tempa<=150 && j<tempa){
if(tempa*tempa+j*j==h[i]*h[i]+w[i]*w[i] && j<=h[i]){
continue;
}
ansh[i]=j;
answ[i]=(int)tempa;
printf("%d %d\n",ansh[i],answ[i]);
break;
}
}
ans++;
k=0;
}
}
return 0;
} | #include "bits/stdc++.h"
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#ifdef Debug
#define dump(x) cerr << #x << " = " << (x) << endl
#else
#define dump(x)
#endif
int main(){
int h,w;
while(cin>>h>>w){
if(h==0 && w==0)break;
int a=9999,b=9999;
for(int i=1;i<=150;i++){
for(int j=i+1;j<=150;j++){
if(h*h+w*w<i*i+j*j || (h*h+w*w==i*i+j*j && h<i )){
if(i*i+j*j<a*a+b*b || ( i*i+j*j==a*a+b*b && i<a )){
a=i;b=j;
}
}
}
}
cout<<a<<" "<<b<<endl;
}
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
bool IsPrime(long long n){
if(n == 1) return false;
for(long long i = 2; i * i < n; i++){
if(n%i == 0) return false;
}
return true;
}
vector<pair<long long, long long>> PrimeFactorize(long long n){
vector<pair<long long, long long>> res;
long long a = 0;
for(long long i = 2; i * i <= n; i++){
a = 0;
if(n%i == 0){
if(IsPrime(i)){
while(n % i == 0){
n /= i;
a++;
}
res.push_back(make_pair(i, a));
}
}
}
if(n!= 1) res.push_back(make_pair(n, 1));
return res;
}
int NumOfDivisor(long long n){
vector<pair<long long, long long>> res;
res = PrimeFactorize(n);
int num = 1;
for(int i = 0; i < res.size(); i++){
num *= (1 + res[i].second);
}
return num;
}
int main(){
const int mod = 1e9 + 7;
int n;
const int max_n = 1e3;
cin >> n;
long long ans = 1;
long long ex[max_n + 2] = {};
for(int i = 1; i <= n; i++){
vector<pair<long long, long long>> res;
res = PrimeFactorize(i);
for(int j = 0; j < res.size(); j++){
ex[res[j].first - 1] += res[j].second;
}
}
for(int i = 0; i < n; i++){
ans *= (ex[i] + 1);
ans %= mod;
}
cout << ans << endl;
return 0;
} | /*
ID: anonymo14
TASK: wormhole
LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;
#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back
#define REP(i,a,b) for(int i=a; i<=b; i++)
#define MOD 1000000007
void solve(int test_case) {//211
ll n;
cin>>n;
vector<bool> prime(n+1,1);
REP(i,2,n) {
if(prime[i])for(int j=i+i;j<=n;j+=i)prime[j]=0;
}
ll ans = 1;
for(ll i=2;i<=n;i++) {
if(prime[i]) {
ll now = i,cnt=0;
while(now<=n){cnt=cnt+(n/now);now*=i;}
ans = (ans*(cnt+1))%1000000007;
}
}
//if(n!=1)ans = (ans*2)%1000000007;
cout<<ans;
}//1, 2, 4, 8, 12, 30, 60, 96
int main() {
////// FILE BASED IO////
//freopen("wormhole.in", "r", stdin);
//freopen("wormhole.out", "w", stdout);
///////////////
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin>>t;
REP(i,1,t) {
solve(i);
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
//#define MOD 1000000007
#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef long long ll;
typedef pair<ll,ll> PP;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false
bool comp(pair<pair<int,int>,string> G,pair<pair<int,int>,string> H){
int Ga=G.first.first;
int Gb=G.first.second;
int Ha=H.first.first;
int Hb=H.first.second;
if(Ga-Gb>=0 && Ha-Hb<0)return true;
if(Ga-Gb<0 && Ha-Hb>=0)return false;
if(Ga-Gb>=0 && Ha-Hb>=0){
return Gb<Hb;
}else{
return Ga>Ha;
}
}
signed main(void){
int N;
string S;
vector<pair<pair<int,int>,string>> V;
cin >> N;
REP(i,N){
cin >> S;
int a=0,b=0;
REP(j,S.size()){
if(S[j]=='('){
a++;
}else{
b++;
}
}
V.push_back({{a,b},S});
}
sort(V.begin(),V.end(),comp);
//REP(i,N){cout << V[i].second << endl;}
int now=0;
bool ok = true;
REP(i,N){
string S = V[i].second;
REP(j,S.size()){
if(S[j]=='('){
now++;
}else{
now--;
}
if(now<0)ok=false;
}
}
if(now!=0)ok = false;
cout << (ok?"Yes":"No") << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod = 998244353;
struct node{
int l,r;
};
const int N = 1e6+7;
string s[N];
int n;
vector<node>a;
vector<node>b;
bool cmp(node x,node y)
{
return x.r<y.r;
}
bool cmp1(node x,node y){
return x.l<y.l;
}
int main()
{
cin >> n;
for(int i = 1;i<=n;++i)
{
cin >>s[i];
int len =s[i].length();
int l = 0,r = 0;
for(int j = 0;j<len;++j)
{
if(s[i][j]=='(')++l;
else if(l)--l;
else ++r;
}
if(l>=r) a.push_back({l,r});
else b.push_back({l,r});
}
sort(a.begin(),a.end(),cmp);
sort(b.begin(),b.end(),cmp1);
int sum = 0,ok = 0;
for(int i = 0;i<a.size();++i)
{
sum-=a[i].r;
if(sum<0)
{
ok = 1;
break;
}
sum+=a[i].l;
}
int sum1 = 0;
for(int i = 0;i<b.size();++i)
{
sum1-=b[i].l;
if(sum1<0)
{
ok = 1;
break;
}
sum1+=b[i].r;
}
if(ok)
puts("No");
else
{
if(sum==sum1)
puts("Yes");
else
puts("No");
}
return 0;
}
| 1 |
#include <iostream>
using namespace std;
long long int get_digit(long long int l){
long long int digit = 0;
while(l != 0){
l /= 10;
digit++;
}
return digit;
}
int main(void){
// Your code here!
long long int n;
cin >> n;
long long int j;
long long int x,y,z;
long long int ans = 20000000000000;
for(long long int i=1; i*i <= n;i++){//iは0からエラー
if(n%i == 0){
j = n/i;
x = get_digit(i);
y = get_digit(j);
z = max(x,y);
if(z < ans){
ans = z;
}
}
}
cout << ans << endl;
}
| // -*- mode:c++; coding:utf-8; indent-tabs-mode:nil; -*-
// ALDS1_4-A: Linear Search
#include <cstdio>
static int linear_search(const int as[], const int target) {
int i = 0;
while (as[i] != target) {
++i;
}
return i;
}
int main(void) {
int n;
std::scanf("%d", &n);
int ss[n+1]; // n+1(sentinel)
for (auto i = 0; i < n; ++i) {
std::scanf("%d", &ss[i]);
}
int q;
std::scanf("%d", &q);
int c = 0;
for (auto i = 0; i < q; ++i) {
int t;
std::scanf("%d", &t);
ss[n] = t; // sentinel
auto j = linear_search(ss, t);
if (j != n) ++c;
}
std::printf("%d\n", c);
return 0;
}
// end | 0 |
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef unsigned long long ll;
typedef unsigned int ui;
const ll mod = (ll)(1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll bit[1 << 17][2]; int n;
void add(int id,int a, ll w) {
for (int i = a; i <= n + 1; i += i & -i)bit[i][id] += w;
}
ll sum(int id,int a) {
ll ret = 0;
for (int i = a; i > 0; i -= i & -i)ret += bit[i][id];
return ret;
}
int a[1 << 17][3];
P b[1 << 17];
int main() {
cin >> n;
rep(i, 3) {
rep(j, n) {
cin >> a[j][i]; a[j][i]--;
}
}
bool f = true;
rep(i, n) {
int key = a[i][0]/3;
rep1(j, 2) {
if (key != a[i][j] / 3)f = false;
}
if (a[i][1] == a[i][0] + 1 && a[i][2] == a[i][0] + 2) {
b[key] = { i+1,0 };
}
else if (a[i][1] == a[i][0] - 1 && a[i][2] == a[i][0] - 2) {
b[key] = { i+1,1 };
}
else f = false;
if (i % 2 != key % 2)f = false;
//cout << key << endl;
}
if (!f) {
cout << "No" << endl;
}
else {
ll cnt[2] = {};
rep(i, n) {
int k = i % 2;
cnt[k ^ 1] += b[i].second;
cnt[k] += (b[i].first-1)/2 - sum(k,b[i].first);
add(k,b[i].first,1);
//cout << cnt << endl;
}
//cout << cnt[0] << " " << cnt[1] << endl;
if (cnt[0]% 2==0&&cnt[1]%2==0)cout << "Yes" << endl;
else cout << "No" << endl;
//cout << cnt << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
double ev[305][305][305], p[305][305][305];
int main()
{
int n;
cin>>n;
vector<int> cnt(4,0);
for(int i=0; i<n; i++)
{
int x;
cin>>x;
cnt[x]++;
}
p[cnt[1]][cnt[2]][cnt[3]] = 1;
for(int c=n; c >= 0; c--)
{
for(int b=n; b >= 0; b--)
{
for(int a=n; a >= 0; a--)
{
if(a==0 && b==0 && c==0)
continue;
if(a+b+c > n)
continue;
double p_waste = (double)(n - (a+b+c))/n;
double ev_waste = (double)p_waste/(1 - p_waste);
//debug() << imie(a) imie(b) imie(c) imie(ev_waste);
ev[a][b][c] += ev_waste*p[a][b][c];
if(a != 0)
{
double p_go = (double)a/(a+b+c);
p[a-1][b][c] += p[a][b][c]*p_go;
ev[a-1][b][c] += ev[a][b][c]*p_go;
}
if(b != 0)
{
double p_go = (double)b/(a+b+c);
p[a+1][b-1][c] += p[a][b][c]*p_go;
ev[a+1][b-1][c] += ev[a][b][c]*p_go;
}
if(c != 0)
{
double p_go = (double)c/(a+b+c);
p[a][b+1][c-1] += p[a][b][c]*p_go;
ev[a][b+1][c-1] += ev[a][b][c]*p_go;
}
}
}
}
cout<<fixed<<setprecision(10)<<ev[0][0][0] + cnt[1] + 2*cnt[2] + 3*cnt[3]<<endl;
}
| 0 |
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;
int main(){
string S;
cin >> S;
sort(S.begin(), S.end());
char ans = 'a';
rep(i, S.size()){
if(S[i] == ans){
ans++;
}else if(S[i] > ans){
break;
}
}
if(ans > 'z'){
cout << "None" << endl;
}else{
cout << ans << endl;
}
return 0;
} | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++)
#define REP(i,n) for(int i = 0;i < (n) ; i++)
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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;}
/*----------------------------------------------------------------*/
const int MOD = 998244353;
// const int MOD = 1000000007;
/*----------------------------------------------------------------*/
signed main(){
string s;
cin >> s;
int cnt[26] = {};
for(auto c:s)cnt[c-'a']++;
rep(i,26){
if(cnt[i] == 0){
cout << (char)('a'+i) << endl;
return 0;
}
}
cout << "None" << endl;
return 0;
}
/*----------------------------------------------------------------*/
// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://abc071.contest.atcoder.jp/tasks/abc071_b | 1 |
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 303
const int mod=998244353;
inline int read(){
int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-')f=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
x=(x<<1)+(x<<3)+c-'0';
c=getchar();
}
return x*f;
}
int n,m,gu,dp[N][N][N],a[N],ans,sum[N],s1[N][N],s2[N<<1][N<<1];
char s[N];
int main(){
scanf("%s",s+1);
n=strlen(s+1),m=read();
s[++n]='0';
m=min(n,m);
for(int i=1;i<=n;++i){
if(s[i]=='0')++gu;
else ++a[gu+1];
}
for(int i=1;i<=gu;++i){
sum[i]=a[i]+sum[i-1];
}
dp[0][0][0]=1;
for(int i=1;i<=gu;++i){
for(int k=0;k<=m;++k){
s1[0][k]=dp[i-1][0][k];
for(int j=1;j<=n-gu;++j){
s1[j][k]=(s1[j-1][k]+dp[i-1][j][k])%mod;
}
}
for(int k=sum[i]-a[i];k<=n-gu+min(n-gu,m)-a[i];++k){
s2[k][0]=dp[i-1][0][k]%mod;
for(int p=1;p<=k;++p){
s2[k][p]=(s2[k][p-1]+dp[i-1][p][k-p])%mod;
}
}
for(int j=sum[i];j<=n-gu;++j){
int lim=min(j,n-sum[i-1]-gu);
if(lim>a[i]){
for(int k=0;k<=min(j,m);++k){
dp[i][j][k]=1LL*(s1[j-(a[i]+1)][k]-s1[j-lim-1][k]+mod)%mod;
}
}
for(int k=0;k<=min(j,m);++k){
dp[i][j][k]=(dp[i][j][k]+s2[j+k-a[i]][j-max(0,a[i]-k)]-s2[j+k-a[i]][j-a[i]-1])%mod;
dp[i][j][k]=(dp[i][j][k]<0?dp[i][j][k]+mod:dp[i][j][k]);
}
}
}
for(int k=0;k<=m;++k){
ans=(ans+dp[gu][n-gu][k])%mod;
}
cout<<ans<<endl;
return 0;
}
| // FUCKED UP FUCKED UP FUCKED UP FUCKED UP FUCKED UP
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn=3e2+10, maxm=5e4+10, lg=21, mod=998244353, inf=1e18;
string s;
ll k,n,cnt,a[maxn],d[maxn],dp[maxn][maxn][maxn];
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>s>>k;
for(char c:s) (c=='0' ? cnt++:a[n++]=cnt);
k=min(k,n);
for(int i=0;i<n;i++) d[a[i]]++;
dp[cnt+1][0][0]=1;
for(int i=cnt+1;i;i--)for(int j=0;j<=k;j++)for(int k=0;k<=n;k++)if(dp[i][j][k])for(int t=0;t<=d[i-1]+k;t++) (dp[i-1][j+max(0ll,d[i-1]-t)][d[i-1]+k-t]+=dp[i][j][k])%=mod;
ll ans=0;
for(int i=0;i<=k;i++) ans+=dp[0][i][0];
cout<<ans%mod;
return 0;
}
| 1 |
#include <stdio.h>
int main(){
int a, b, c, d;
int K;
scanf("%d %d %d %d %d", &a, &b, &c, &d, &K);
int diff1 = c - a;
int diff2 = d - b;
int min = (diff1 * 60) + diff2;
printf("%d", min - K);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define mod 998244353
#define floop(i,a,b) for (int i=(a);i<(b);i++)
#define rloop(i,a,b) for (int i=(a);i>=(b);i--)
#define floopeq(i,a,b) for (int i=(a);i<(b);i++)
#define pa pair<int,int>
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x, ll y, ll p)
{
ll res = 1;x = x % p;if (x == 0)return 0;while (y > 0)
{if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res;
}
void dfs(int i,int j,int n,int m,vector<vector<char>>a,vector<vector<bool>>&vis)
{
vis[i][j]=1;
if(i<(n-1) && vis[i+1][j]==0 && (a[i+1][j]!='#'))
{
dfs(i+1,j,n,m,a,vis);
}
if(i>0 && vis[i-1][j]==0 &&(a[i-1][j]!='#'))
{
dfs(i-1,j,n,m,a,vis);
}
if(j<(m-1) && vis[i][j+1]==0 && (a[i][j+1]!='#'))
{
dfs(i,j+1,n,m,a,vis);
}
if(j>0 && vis[i][j-1]==0 && ((a[i][j-1]!='#')))
{
dfs(i,j-1,n,m,a,vis);
}
}
void solve()
{
int h1,m1,h2,m2,k;
cin>>h1>>m1>>h2>>m2>>k;
int al = (60*(h2-h1)) + (m2-m1);
cout<<al-k<<endl;
}
int main()
{
int t;
t=1;
while(t--){
solve();
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int na, nb, nt;
cin >> na >> nb >> nt;
vector<int> a(na), b(nb);
for (int i = 0; i < na; i++) {
cin >> a[i];
}
for (int i = 0; i < nb; i++) {
cin >> b[i];
}
int ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
for (int i = 0; i < nt; i++) {
int x, y, c;
cin >> x >> y >> c;
x--; y--;
ans = min(ans, a[x] + b[y] - c);
}
cout << ans << '\n';
}
| #include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;
// 插入此處
LL a[100005];
int main() {
LL n, m, v, p;
cin >> n >> m >> v >> p;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n, [](LL x, LL y) { return x > y; });
// for (int i = 0; i < n; i++) {
// printf("%lld ", a[i]);
// }
// puts("");
LL ans;
LL agg = 0;
for (ans = p; ans < n; ans++) {
// 前後都還夠塞
LL les = n - ans;
LL re = v - (p - 1) - les;
agg += a[ans - 1];
if (re <= 0) {
if (a[p - 1] <= a[ans] + m) {
continue;
} else {
break;
}
} else {
// 要開始塞中間了
LL space = (ans - p + 1) * (a[ans] + m) - agg;
LL vote = re * m;
// printf("ans = %lld, re = %lld, space = %lld, vote = %lld\n", ans, re, space, vote);
if (a[p - 1] <= a[ans] + m && space >= vote) {
continue;
} else {
break;
}
}
}
cout << ans << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
tree<int, null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> void re(T& x) { cin >> x; }
template<typename T>
void remdup(vector<T>& v) {
sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "/home/o_o/MyCodes/pr.h"
#else
#define trace(...)
#endif
#define MOD 1000000007
void solve(){
int cnt = 1 ;
int n , x , t ;
re(n,x,t);
while(cnt*x<n) cnt++;
cout << cnt * t << endl;
}
signed main() {
unsyncIO();
int tt =1 ;
// cin >> tt;
rep(i,0,tt) solve();
#ifdef np
cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
long long s,ans;
int n,a[200003];
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+1+n);
for(int i=2;i<=n;i++)
{
s=(s+a[i-1])%1000000007;
ans=(ans+s*a[i])%1000000007;
}
cout<<ans<<endl;
return 0;
}
| 0 |
#include <stack>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <numeric>
using namespace std;
using ll = long long;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define input(...) __VA_ARGS__; in(__VA_ARGS__)
#if __has_include("debugger.cpp")
#include "debugger.cpp"
#else
void print() {
std::cout << std::endl;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
cout << head;
if (sizeof...(tail) > 0) cout << " ";
print(std::forward<Tail>(tail)...);
}
# endif
void in() { }
template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
cin >> head;
in(std::forward<Tail>(tail)...);
}
int main() {
string input(s);
stack<char> p;
REP(i, s.size()) {
if (s[i] == 'T' && !p.empty() && p.top() == 'S') {
p.pop();
} else {
p.push(s[i]);
}
}
print(p.size());
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define all(v) v.begin(),v.end()
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl
void Suhaib_Sawalha (){
string s , w;
cin >> s >> w;
cout << w + s;
}
int main(){
In_The_Name_Of_Allah_The_Merciful /* بسم الله الرحمن الرحيم */
#ifndef ONLINE_JUDGE
freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<'\n')
Suhaib_Sawalha();
Alhamdulillah /* الحمد لله */
} | 0 |
#include <iostream>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
int main() {
int n, k;
cin >> n >> k;
int p[n];
rep(i,n) cin >> p[i], p[i]++;
int s = 0, m = 0;
rep(i,n) {
s = s + p[i] - (i >= k ? p[i-k] : 0);
m = max(m, s);
}
cout << fixed << setprecision(1) << (double)m / 2 << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
double expected_value(int n) {
return (double)((1 + n) * n / 2) / (double)n;
}
int main() {
int n, k;
cin >> n >> k;
vector<double> ps(n + 1);
vector<double> comsum(n + 1, 0);
int p;
rep(i, n) {
cin >> p;
ps[i + 1] = expected_value(p);
comsum[i + 1] = comsum[i] + ps[i + 1];
}
double mm = 0;
for (int i = k; i <= n; i++) {
mm = max(comsum[i] - comsum[i - k], mm);
}
printf("%.6f\n", mm);
return 0;
}
| 1 |
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define MAX 1000001
ll prime[MAX];
#define mod 1000000007
ll rec(vector<vector<ll> >& dp,vector<ll>& arr,int n,int i,int k,int w)
{
ll ans=0;
if(i>=n)
return 0;
if(dp[i][k]!=-1)
return dp[i][k];
if(k!=0)
ans=max(rec(dp,arr,n,i+1,w,w),arr[i]+rec(dp,arr,n,i+1,k-1,w));
else
ans=max(rec(dp,arr,n,i+1,k,w),rec(dp,arr,n,i+1,w,w));
return dp[i][k]=ans;
}
ll t[400008];
void build(vector<ll>& a, int v, int tl, int tr) {
if (tl == tr) {
t[v] = a[tl];
} else {
int tm = (tl + tr) / 2;
build(a, v*2, tl, tm);
build(a, v*2+1, tm+1, tr);
t[v] = max(t[v*2] ,t[v*2+1]);
}
}
ll maxi(int v, int tl, int tr, int l, int r) {
if (l > r)
return 0;
if (l == tl && r == tr) {
return t[v];
}
int tm = (tl + tr) / 2;
return max(maxi(v*2, tl, tm, l, min(r, tm)) ,maxi(v*2+1, tm+1, tr, max(l, tm+1), r));
}
void update(int v, int tl, int tr, int pos, ll new_val) {
if (tl == tr) {
t[v] = new_val;
} else {
int tm = (tl + tr) / 2;
if (pos <= tm)
update(v*2, tl, tm, pos, new_val);
else
update(v*2+1, tm+1, tr, pos, new_val);
t[v] = max(t[v*2] ,t[v*2+1]);
}
}
int main() {
int a;
cin>>a;
cout<<a+a*a+a*a*a;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
int ans = a + a*a + a*a*a;
cout << ans << endl;
} | 1 |
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
using namespace std;
int main()
{
int n;
string str;
cin >> n;
cin.get();
for(int i=0;i<n;++i)
{
int loc;
getline(cin, str);
loc = str.find("Hoshino",0);
while(loc!=string::npos)
{
str[loc+6] = 'a';
loc = str.find("Hoshino",0);
}
cout << str << endl;
}
} | #include<bits/stdc++.h>
using namespace std ;
main(){
int n ;
string s ;
char c[] = {'H','o','s','h','i','n','o'} ;
cin >> n ;
for( int k=0 ; k<=n ; k++ ){
getline( cin , s ) ;
for( int i=0 ; i<s.size() ; i++ ){
int cnt = 0 ;
if( s[i] == 'H' ){
for( int j=0 ; j<s.size() && j<7 ; j++ ){
if( s[i+j] == c[j] ) cnt++ ;
else break ;
}
if( cnt==7 ) s[i+6] = 'a' ;
}
}
if( k ) cout << s << endl ;
}
} | 1 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
void solve()
{
ll a,b,c;
cin>>a>>b>>c;
cout<<a+b+c-max({a,b,c});
return;
}
int main()
{
fast;
ll q;
q=1;
// cin>>q;
while(q--)
solve();
return 0;
}
| #include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
int a[5],i,j;
for(i=0;i<3;i++){
cin >> a[i];
}
int ans=(1<<29);
for(i=0;i<3;i++){
for(j=i+1;j<3;j++){
ans=min(ans,a[i]+a[j]);
}
}
cout << ans << endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};
const ll MXN=100000;
vl G[MXN];
vvl d(2,vl(MXN,INF));
void dfs(ll x,ll v,ll z){
d[x][v]=z;
rep(i,G[v].size()){
if(d[x][G[v][i]]==INF){
dfs(x,G[v][i],z+1);
}
}
}
int main() {
ll N,u,v;
cin >> N >> u >> v;
u--;v--;
rep(i,N-1){
ll a,b;
cin >> a >> b;
a--;b--;
G[a].pb(b);
G[b].pb(a);
}
dfs(0,u,0);
dfs(1,v,0);
ll D=0;
rep(i,N){
if(d[0][i]<d[1][i]){
D=max(D,d[1][i]);
}
}
cout << D-1 << endl;
} | #include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p;
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
vector<int> V[110000];
int color[110000];
//二部グラフならtrueを返す
bool dfs(int x,int c){
color[x]=c;
for(int i=0;i<V[x].size();i++){
//隣接している頂点が同じ色ならfalse
if(color[V[x][i]]==c) return false;
//隣接している頂点がまだ塗られていないなら-cで塗る
if(color[V[x][i]]==0 && !dfs(V[x][i],-c)) return false;
}
return true;
}
int main(){
ll N,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);
}
if(dfs(0,1)){
ll count=0;
for(int i=0;i<N;i++){
if(color[i]==1) count++;
}
cout<<count*(N-count)-M<<endl;
}else{
cout<<N*(N-1)/2-M<<endl;
}
}
| 0 |
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
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; }
ll N;
//dp
vector<vector<vector<double>>> table;
double dp(ll i,ll j,ll k){
//cout<<i<<" "<<j<<" "<<k<<endl;
if(i==0&&j==0&&k==0) return 0;
if(table.at(i).at(j).at(k)>-1) return table.at(i).at(j).at(k);
table.at(i).at(j).at(k)=0;
if(i>0) table.at(i).at(j).at(k)+=dp(i-1,j,k)*i/N;
if(j>0) table.at(i).at(j).at(k)+=dp(i+1,j-1,k)*j/N;
if(k>0) table.at(i).at(j).at(k)+=dp(i,j+1,k-1)*k/N;
table.at(i).at(j).at(k)+=1;
return table.at(i).at(j).at(k)/=(double)(i+j+k)/N;
}
int main()
{
cin>>N;
vector<ll> vec(4,0); rep(i,N) {ll a; cin>>a; vec.at(a)++;}
//dp
table=vector<vector<vector<double>>>(N+1,vector<vector<double>>(N+1,vector<double>(N+1,-1)));
cout<<fixed<<setprecision(15)<<dp(vec.at(1),vec.at(2),vec.at(3))<<endl;
/*
rep(i,2) {
if(i!=0) cout<<" ";
cout<<table.at(0).at(0).at(i);
}
cout<<fixed<<setprecision(15)<<endl;
*/
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int D;
int d[22];
long long ans;
bool analyze(int ndig) {
int tmp = D;
for (int i = ndig; i >= 1; --i) {
d[i] = tmp % 10; tmp /= 10;
}
return tmp == 0;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> D;
for (int ndig = 2; ndig <= 20; ++ndig) {
bool odd = ndig % 2;
if (!analyze(ndig)) continue;
long long cur = 1; // current answer
// d[1], d[2], ..., d[ndig]
bool lef = 0 /* -> */, rig = 0 /* <- */;
for (int dig = 1; dig <= ndig / 2; ++dig) {
bool nlef = 0, nrig = 0;
bool LEF = 0, RIG = 0;
// opposite: ndig + 1 - dig
int npair = 0;
for (int i = 0; i <= 9; ++i) {
for (int j = 0; j <= 9; ++j) {
// check for validity
if (dig == 1) {
if (j == 0) continue;
if (i < j) continue;
}
// I - J ~ [d[dig] + 1, d[dig]]
// J - I = d[n + 1 - dig] || 10 + J - I = d[n + 1 - dig]
int I = i, J = j;
if (lef) I += 10; if (rig) --J;
if (I - j == d[dig]) nlef = 0;
else if (I - j == d[dig] + 1) nlef = 1;
else continue;
if (J - i == d[ndig + 1 - dig]) nrig = 0;
else if (10 + J - i == d[ndig + 1 - dig]) nrig = 1;
else continue;
// now valid
++npair;
LEF = nlef;
RIG = nrig;
}
}
cur *= npair;
lef = LEF;
rig = RIG;
}
if (!odd && lef != rig) continue;
else if (odd) {
int cnt = 0;
for (int i = 0; i <= 9; ++i) {
int I = i;
if (lef) I += 10;
if (rig) I--;
if (I - i == d[(ndig + 1) / 2]) ++cnt;
}
cur *= cnt;
}
ans += cur;
}
cout << ans << endl;
} | 0 |
#include <iostream>
#include <string>
#include <algorithm>
int main(void)
{
std::string str1;
std::string str2;
std::cin >> str1 >> str2;
int l1 = str1.size();
int l2 = str2.size();
int A[l1 + 1][l2 + 1] = {};
for (int i = 0; i <= l1; i++)
{
for (int j = 0; j <= l2; j++)
{
if (i == 0)
{
A[i][j] = j;
}
else if (j == 0)
{
A[i][j] = i;
}
else
{
A[i][j] = std::min(A[i - 1][j] + 1, A[i][j - 1] + 1);
if (str1[i - 1] == str2[j - 1])
{
A[i][j] = std::min(A[i - 1][j - 1], A[i][j]);
}
else
{
A[i][j] = std::min(A[i - 1][j - 1] + 1, A[i][j]);
}
}
//std::cout << A[i][j] << " ";
}
//std::cout << "\n";
}
std::cout << A[l1][l2] << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount
#define INF INT_MAX/3
#define BV_SIZE 64ULL // 64bit
#define MAX_BV_NUM 100 // m <= 100*64 = 6400
unsigned long long Peq[MAX_BV_NUM][0x100];
int levenshteinDistance(string a,string b) {
int m=a.size(),n=b.size();
int num_of_bv = (m + BV_SIZE -1) / BV_SIZE;
for (int i = 0; i < m; i++) {
Peq[i / BV_SIZE][a[i]] |= 1ULL << ((unsigned long long)i % BV_SIZE);
}
// calc
int score = m;
unsigned long long Pv[MAX_BV_NUM], Mv[MAX_BV_NUM], Ph[MAX_BV_NUM], Mh[MAX_BV_NUM], Xv[MAX_BV_NUM], Xh[MAX_BV_NUM], Eq[MAX_BV_NUM], Xt[MAX_BV_NUM], Xa[MAX_BV_NUM];
unsigned long long top = 1ULL << (((unsigned long long)m - 1ULL) % BV_SIZE);
for(int i = 0; i < num_of_bv; i++) {
Pv[i] = ~0ULL; Mv[i] = 0ULL;
}
Pv[num_of_bv - 1] &= ((top << 1ULL) - 1ULL);
//cout << static_cast<bitset<64> >(Pv[num_of_bv - 1]) << endl;
for (int j = 0; j < n; j++) {
for(int i = 0; i < num_of_bv; i++){
Eq[i] = Peq[i][b[j]];
Xv[i] = Eq[i] | Mv[i];
Xt[i] = Eq[i] & Pv[i];
}
unsigned long long carry = 0ULL;
for(int i = 0; i < num_of_bv; i++){
Xa[i] = Xt[i] + Pv[i] + carry;
if(Xt[i] == ~0ULL && carry == 1ULL){
carry = 1ULL;
}else{
unsigned long long cXt = Xt[i] + carry;
carry = (((cXt & Pv[i]) | ((cXt | Pv[i]) & ( ~ (cXt + Pv[i]) ))) >> 63ULL) & 1ULL;
}
}
for(int i = 0; i < num_of_bv; i++){
Xh[i] = (Xa[i] ^ Pv[i]) | Eq[i];
}
for(int i = 0; i < num_of_bv; i++){
Ph[i] = Mv[i] | ( ~ (Xh[i] | Pv[i]) );
Mh[i] = Pv[i] & Xh[i];
}
if((Ph[num_of_bv - 1] & top) != 0ULL)score++;
else if((Mh[num_of_bv - 1] & top) != 0ULL)score--;
unsigned long long Ph_carry = 1ULL;
unsigned long long Mh_carry = 0ULL;
/*
for(int i = num_of_bv - 1; i >= 0; i--){
for(int k = 63; k >= 0; k--){
if((Ph[i] >> k) & 1ULL)cout<<1;
else cout<<0;
}
}
cout<<endl;
*/
for(int i = 0; i < num_of_bv; i++){
unsigned long long nxt_Ph_carry = (Ph[i] >> 63ULL) & 1ULL;
Ph[i] = (Ph[i] << 1ULL) | Ph_carry;
Ph_carry = nxt_Ph_carry;
}
/*
for(int i = num_of_bv -1; i >= 0; i--){
for(int k = 63; k >= 0; k--){
if((Ph[i] >> k) & 1ULL)cout<<1;
else cout<<0;
}
}
cout<<endl;
cout<<endl;
*/
for(int i = 0; i < num_of_bv; i++){
unsigned long long nxt_Mh_carry = (Mh[i] >> 63ULL) & 1ULL;
Pv[i] = ((Mh[i] << 1ULL) | Mh_carry ) | ( ~ (Xv[i] | Ph[i]) );
Mh_carry = nxt_Mh_carry;
}
for(int i = 0; i < num_of_bv; i++){
Mv[i] = Ph[i] & Xv[i];
}
}
return score;
}
int main(){
string a,b;
cin>>a>>b;
cout<<levenshteinDistance(a,b)<<endl;
return 0;
} | 1 |
#include <iostream>
#include <vector>
#include <algorithm>
long long solve(int n, const std::vector<long long> & a, const std::vector<long long> & b, const std::vector<long long> & c) {
long long res { 0LL };
for (int i = 0; i < n; ++i) {
const long long m { b[i] };
const long long an { std::distance(a.begin(), std::lower_bound(a.begin(), a.end(), m)) };
const long long cn { std::distance(c.begin(), std::upper_bound(c.begin(), c.end(), m)) };
res += (an * (n - cn));
}
return res;
}
int main(int argc, const char * argv[]) {
int n;
std::cin >> n;
std::vector<long long> a;
for (int i = 0; i < n; ++i) {
long long ai;
std::cin >> ai;
a.push_back(ai);
}
std::sort(a.begin(), a.end());
std::vector<long long> b;
for (int i = 0; i < n; ++i) {
long long bi;
std::cin >> bi;
b.push_back(bi);
}
std::sort(b.begin(), b.end());
std::vector<long long> c;
for (int i = 0; i < n; ++i) {
long long ci;
std::cin >> ci;
c.push_back(ci);
}
std::sort(c.begin(), c.end());
std::cout << solve(n, a, b, c) << std::endl;
return 0;
}
| #include <algorithm>
#include <iostream> //標準入出力
#include <fstream> //ファイルでの入出力
#include <vector>
#include <set>
#include <functional>
#include <string>
#include <utility> //pair
#include <cmath> //sqrt
#include <iomanip> //setprecision
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define MAX 1000000
#define pair(a) pair<a,a>
ll binary_search(vector<ll>& s,ll key){
auto isOK = [&](ll index){
if(s[index] > key) return true;
else return false;
};
ll ng=-1,ok=s.size();
while(abs(ok-ng) > 1){
ll mid = (ok+ng)/2;
if(isOK(mid)) ok = mid;
else ng = mid;
};
return ok;
}
void _main(){
ll n; cin >> n;
vector<ll> a(n),b(n),c(n);
rep(i,n) cin >> a[i];
rep(i,n) cin >> b[i];
rep(i,n) cin >> c[i];
sort(ALL(a));
sort(ALL(b));
sort(ALL(c));
vector<ll> atob(n),btoc(n);
ll out = 0;
rep(i,n) atob[i] = binary_search(b,a[i]);
rep(i,n) btoc[i] = binary_search(c,b[i]);
rep(i,n){
for (ll j = atob[i]; j < n; j++)
{
out += (n-btoc[j]);
}
}
cout << out << endl;
return;
}
int main() {
cout << fixed << setprecision(10);
_main();
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);}
}
const int N=1e5+5;
int n,m,p,a[N],b[N],ans=1e9;
signed main(){
read(n,m,p);
for(int i=1;i<=n;i++) read(a[i]);
for(int i=1;i<=m;i++) read(b[i]);
ans=*min_element(a+1,a+1+n)+*min_element(b+1,b+1+n);
while(p--){
int x,y,z;
read(x,y,z);
ans=min(ans,a[x]+b[y]-z);
}
write(ans);
} | #include<bits/stdc++.h>
#define N 10
using namespace std;
typedef long long ll;
int n,k,a[N];
set<ll> s;
int check(){
int perm[N];
for(int i=0;i<n;i++)perm[i]=i;
do{
ll num=0;
for(int i=0;i<k;i++){
if(!(a[perm[i]]/10))num=num*10+a[perm[i]];
else num=num*100+a[perm[i]];
}
s.insert(num);
}while(next_permutation(perm,perm+n));
return s.size();
}
int main(){
while(1){
cin>>n>>k;
if(!n&&!k)break;
for(int i=0;i<n;i++)
cin>>a[i];
cout<<check()<<endl;
s.clear();
}
return 0;
} | 0 |
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef int_fast64_t ll;
template<int N, typename T, T M>
struct ModFact {
T fact[N+1];
constexpr ModFact() : fact() {
fact[0] = 1;
for (int i=0; i<N; ++i)
fact[i+1] = (fact[i]*(i+1))%M;
}
};
ModFact<100000, ll, MOD> fact;
ll N, M, ans = 1;
int tmp, cnt = 0;
constexpr ll th = 1LL<<45;
char S[200000];
int main() {
scanf("%lld\n", &N);
M = N << 1;
fread_unlocked(S, 1, M, stdin);
for(size_t i = 0; i < M;) {
tmp = (S[i++]=='B') + cnt;
if(tmp&1) cnt++;
else {
ans *= cnt;
if(ans > th) ans %= MOD;
if(--cnt < 0) break;
}
}
ans = cnt == 0 ? ((ans % MOD) * fact.fact[N]) % MOD : 0;
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S;
cin >> N >> S;
if(S[0] == 'W' || S[2 * N - 1] == 'W') {
cout << 0 << endl;
return 0;
}
vector<bool> f(2 * N);
f[0] = true;
for(int i=1; i<2*N; ++i) {
if(S[i - 1] != S[i]) f[i] = f[i - 1];
else f[i] = !f[i - 1];
}
if(count(begin(f), end(f), true) != N) {
cout << 0 << endl;
return 0;
}
long long MOD = 1000000007;
long long res = 1;
for(int i=1; i<=N; ++i) res = (res * i) % MOD;
int cnt = 0;
for(int i=0; i<2*N; ++i) {
if(f[i]) {
++cnt;
} else {
res = (res * cnt) % MOD;
--cnt;
}
}
cout << res << endl;
} | 1 |
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
using namespace std;
int main(){
int n;
while(cin>>n,n){
map<long double,set<string> > ans;
for(int i=0;i<n;i++){
string name;
long double p,a,b,c,d,e,f,s,m;
cin>>name>>p>>a>>b>>c>>d>>e>>f>>s>>m;
ans[((f*s*m)-p)/(a+b+c+m*(d+e))].insert(name);
}
for(auto it=ans.rbegin();it!=ans.rend();it++){
set<string> ss =it->second;
for(auto it2=ss.begin();it2!=ss.end();it2++) cout<<(*it2)<<endl;
}
cout<<"#"<<endl;
}
return 0;
} | #include<iostream>
using namespace std ;
int s[31] = {} ;
int ans[31] = {} ;
void cal(){
s[1] = 1 ;
s[2] = 2 ;
s[3] = 4 ;
for( int i=4 ; i<=30 ; i++ ){
s[i] = s[i-1] + s[i-2] + s[i-3] ;
}
for( int i=1 ; i<=30 ; i++ ){
ans[i] = s[i] / 3650 ;
if( s[i] % 3650 > 0 ) ans[i]++ ;
}
}
int main(){
cal() ;
int n ;
while( cin >> n , n ){
cout << ans[n] << endl ;
}
return 0 ;
} | 0 |
#include <stdio.h>
#include <algorithm>
int n;
int a[100010];
int b[100010];
int c[100010];
long long psum_b[100010];
long long ans;
long long find_bc(int st,int ed,int x){
int mid = (st+ed)/2;
if(ed-st<=1){
if(x<c[st]) return n-st;
if(x>=c[ed]) return n-ed-1;
return n-ed;
}
if(c[mid]<=x) return find_bc(mid,ed,x);
return find_bc(st,mid,x);
}
long long find_ab(int st,int ed,int x){
int mid = (st+ed)/2;
if(ed-st<=1){
if(x<b[st]) return psum_b[st];
if(x>=b[ed]) return psum_b[ed+1];
return psum_b[ed];
}
if(b[mid]<=x) return find_ab(mid,ed,x);
return find_ab(st,mid,x);
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
std::sort(a,a+n);
for(int i=0;i<n;i++){
scanf("%d",&b[i]);
}
std::sort(b,b+n);
for(int i=0;i<n;i++){
scanf("%d",&c[i]);
}
std::sort(c,c+n);
for(int i=n-1;i>=0;i--){
psum_b[i]=psum_b[i+1]+find_bc(0,n-1,b[i]);
}
for(int i=0;i<n;i++){
ans+=find_ab(0,n-1,a[i]);
}
printf("%lld\n",ans);
} | #include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
int N;
int A[3][100001];
LL dp[3][100001] = {};
int main() {
scanf("%d", &N);
rep(j, 3) { rep(i, N) scanf("%d", &A[j][i]); A[j][N] = 1000000001; }
rep(j, 3) sort(A[j], A[j] + N);
rep(i, N + 1) dp[0][i] = i;
rep(j, 2) {
int p = 0;
rep(i, N) {
while (A[j][p] < A[j + 1][i]) p++;
dp[j + 1][i + 1] += dp[j + 1][i] + dp[j][p];
}
}
printf("%lld\n", dp[2][N]);
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll INF = 1e18;
int main(){
int N;
cin >> N;
vector<ll> a(N);
ll sum =0;
for(int i=0;i<N;i++){
cin >> a[i];
sum += a[i];
}
ll m = INF;
for(int i=0;i<N;i++){
m = min(m,abs(sum- N*a[i]));
}
for(int i=0;i<N;i++){
if(abs(sum-N*a[i]) == m){
cout << i << endl;
break;
}
}
return 0;
} | #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
using namespace std;
int main(){
int n,sum=0,mi_idx;
double avg,mi=1e9;
cin >> n;
vector<int> d(n,0);
for(int i=0;i<n;i++){
cin >> d[i];
sum+=d[i];
}
avg=(double)sum/(double)n;
for(int i=n-1;i>=0;i--){
if(mi>=(avg-d[i])*(avg-d[i])){
mi_idx=i;
}
mi=min(mi,(avg-d[i])*(avg-d[i]));
}
cout << mi_idx << endl;
return 0;
}
| 1 |
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int w,h,m[21][21],sx,sy,gx,gy,dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int f(int w,int h,int m[][21],int x,int y,int t){
if(t==10)return 99;
int res=99;
rep(i,4){
int cx=x,cy=y,d=0;
while(1){
cx+=dx[i];cy+=dy[i];
if(cx<0||cx>=w||cy<0||cy>=h)break;
if(m[cy][cx]==3){res=min(res,t+1);break;}
if(m[cy][cx]==1){
if(!d)break;
int m2[21][21];
rep(j,h)rep(k,w)m2[j][k]=m[j][k];
m2[cy][cx]=0;
res=min(res,f(w,h,m2,cx-dx[i],cy-dy[i],t+1));
break;
}
d++;
}
}
return res;
}
int main(){
while(cin>>w>>h&&w){
rep(i,h)rep(j,w){
cin>>m[i][j];
if(m[i][j]==2){sx=j,sy=i;}
if(m[i][j]==3){gx=j,gy=i;}
}
int ans=f(w,h,m,sx,sy,0);
cout<<(ans<99?ans:-1)<<endl;
}
} | #include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
using i64 = int64_t;
const i64 MOD = 1e9+7;
const i64 INF = 1e18+7;
struct UnionFind{
int n;
vector<int> par;
UnionFind(int n) : n(n), par(n, -1){}
int Find(int x){return par[x] < 0 ? x : Find(par[x]);}
bool Unite(int x, int y){
x = Find(x), y = Find(y);
if(x == y)
return false;
if(par[x] > par[y])
swap(x, y);
par[x] += par[y];
par[y] = x;
return true;
}
};
template<typename T>
struct Segtree{
const int n;
const T op;
vector<T> elm;
function<T(T, T)> f;
Segtree(int n, T init, function<T(T, T)> f, T op = T()) :
n(n),
op(op),
f(f),
elm(2 * n, init)
{
}
void set(int x, T val){
x += n;
elm[x] = val;
while(x >>= 1)
elm[x] = f(elm[2 * x], elm[2 * x + 1]);
}
void update(int x, T val){
x += n;
elm[x] = f(val, elm[x]);
while(x >>= 1)
elm[x] = f(elm[2 * x], elm[2 * x + 1]);
}
T get(int x, int y) const{
T val = op;
for(x += n, y += n - 1; x <= y; x >>= 1, y >>= 1){
if(x & 1)
val = f(val, elm[x++]);
if(!(y & 1))
val = f(val, elm[y--]);
}
return val;
}
};
signed main(){
int n, d;
cin >> n >> d;
vector<int> v(n);
for(auto& x : v)
cin >> x;
auto f = [](pair<i64,int> x, pair<i64,int> y){
return min(x, y);
};
Segtree<pair<i64,int>> seg_a(n, pair<i64,int>(), f, pair<i64,int>(INF, 0));
Segtree<pair<i64,int>> seg_b(n, pair<i64,int>(), f, pair<i64,int>(INF, 0));
auto s = [&](int i){
seg_a.set(i, make_pair(v[i] + i64(1) * d * i, i));
seg_b.set(i, make_pair(v[i] + i64(1) * d * (n - i - 1), i));
};
auto t = [&](int i){
seg_a.set(i, make_pair(INF, i));
seg_b.set(i, make_pair(INF, i));
};
for(int i = 0; i < n; ++i)
s(i);
UnionFind u(n);
i64 ans = 0;
while(u.par[u.Find(0)] != -n){
// 子ノードの一覧
vector<vector<int>> ch(n);
// 接合するノード
vector<pair<i64, int>> nex(n, make_pair(INF, 0));
for(int i = 0; i < n; ++i)
ch[u.Find(i)].push_back(i);
for(int i = 0; i < n; ++i){
if(ch[i].empty())
continue;
for(auto& x : ch[i])
t(x);
pair<i64,int> val(INF, 0);
for(auto& x : ch[i]){
auto p_a = seg_a.get(x + 1, n);
p_a.first -= i64(1) * d * x;
p_a.first += v[x];
val = f(val, p_a);
auto p_b = seg_b.get(0, x);
p_b.first -= i64(1) * d * (n - 1 - x);
p_b.first += v[x];
val = f(val, p_b);
}
for(auto& x : ch[i])
s(x);
nex[i] = val;
}
for(int i = 0; i < n; ++i){
if(nex[i].first != INF && u.Unite(i, nex[i].second))
ans += nex[i].first;
}
}
cout << ans << endl;
}
| 0 |
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
void printDP(vvi &dp){
for(auto v: dp){
for(auto x: v){
cout << x << " ";
}
cout << endl;
}
cout << endl;
}
void inc(bitset<15> &a){
a = a.to_ullong() +1;
}
int main() {
int n;
cin >> n;
vector<vector<pair<int,int>>> testimonies(n);
vvi dp(n,vi(n,-1));
for(int i = 0 ; i < n ; i ++ ){
int q;
cin >> q;
vector<pair<int,int>> xy(q);
for(int j = 0 ; j < q;j++){
int f,s;
cin >> f>> s;
f--;
xy[j] = {f,s};
dp[f][i] = s;
}
testimonies[i] = xy;
}
// printDP(dp);
bitset<15> bp;
int maxScore = 0;
while (bp.count() < n){
inc(bp);
bool isValid = true;
for(int i = 0 ; i <n;i++ ){
isValid = true;
if(bp[i]){
for(int j = 0 ; j < n ; j++){
if(dp[i][j] == 0 && bp[j]){
isValid = false;
break;
}
}
}else{
for(int j = 0 ; j < n ; j++){
if(dp[i][j] == 1 && bp[j]){
isValid = false;
break;
}
}
}
if(!isValid){
break;
}
}
if(isValid){
maxScore = max(maxScore,(int)bp.count());
}
}
cout << maxScore;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int counter(int bits) {
if (bits == 0) return 0;
return counter(bits >> 1) + (bits & 1);
}
int main(int argc, char const *argv[]) {
int n;
cin >> n;
vector<int> a(n+1);
vector<vector<int> > x(n+1, vector<int>(n+1));
vector<vector<int> > y(n+1, vector<int>(n+1));
for (size_t i = 1; i <= n; i++) {
cin >> a[i];
for (size_t j = 1; j <= a[i]; j++) {
cin >> x[i][j] >> y[i][j];
}
}
int ans = 0;
for (int bits = 1; bits < (1<<n); bits++) {
bool can = true;
for (int i = 1; i <= n; i++) {
if (bits & 1<<(i-1)) {
for (size_t j = 1; j <= a[i]; j++) {
if (((bits >> (x[i][j]-1)) & 1) ^ y[i][j]) can = false;
}
}
}
if (can) ans = max(ans, counter(bits));
}
cout << ans << endl;
return 0;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
const int N_MAX=31;
int dp[N_MAX];
int rec(int n){
int res;
if(n<0)return 0;
if(n==0)return 1;
if(dp[n]>=0){
return dp[n];
}else{
res=rec(n-1)+rec(n-2)+rec(n-3);
}
return dp[n]=res;
}
int main(){
int n;
while(cin>>n){
memset(dp,-1,sizeof(dp));
if(n==0)break;
cout<<ceil(rec(n)/3650.0)<<endl;
}
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int a, b, ans = 0;
cin >> a >> b;
while(a <= b){
if(a / 10000 == a % 10 &&(a / 1000 - (a / 10000) * 10) == (a % 100 - a % 10) / 10){
ans++;
}
a++;
}
cout << ans;
} | 0 |
#include<bits/stdc++.h>
#define mo 998244353
#define pi 3.1415926535898
#define eps 1e-9
using namespace std;
long long read(){
long long xx=0,flagg=1;
char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')
ch=getchar();
if(ch=='-'){
flagg=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
xx=xx*10+ch-'0';
ch=getchar();
}
return xx*flagg;
}
void pus(long long xx,long long flagg){
if(xx<0){
putchar('-');
xx=-xx;
}
if(xx>=10)
pus(xx/10,0);
putchar(xx%10+'0');
if(flagg==1)
putchar(' ');
if(flagg==2)
putchar('\n');
return;
}
long long n,i,j,r[1000005],top,x[1000005],y[1000005];
long long head,tail,sum,max1,zhan[1000005];
char s[1000005],t[1000005];
int main(){
n=read();
scanf("%s%s",s+1,t+1);
for(i=1;i<=n;i++)
if(s[i]!=t[i])
break;
if(i==n+1){
pus(0,2);
return 0;
}
j=n;
for(i=n;i>=1;i--){
if(i<j)
j=i;
while(j!=0&&t[i]!=s[j])
j--;
if(j==0){
pus(-1,2);
return 0;
}
if(r[j]==0)
r[j]=i;
}
for(i=1;i<=n;i++)
if(r[i]!=0){
top++;
x[top]=i;
y[top]=r[i];
}
head=1;
for(i=top;i>=1;i--){
while(head<=tail&&y[i]<zhan[head]-sum)
head++;
tail++;
sum++;
zhan[tail]=x[i]+sum;
max1=max(max1,tail-head+1);
}
pus(max1,2);
return 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 998244353
#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
ll modpow(ll a, ll n, ll m)
{
if(n == 0) return 1;
ll t = modpow(a, n >> 1, m);
t = t * t % m;
if(n & 1) t = t * a % m;
return t;
}
int main()
{
ll N;
cin >> N;
vec D(N);
REP(i,0,N) cin >> D[i];
vec A(N, 0);
if(D[0] != 0) PR(0);
else {
ll m = 0;
REP(i,0,N) {
++A[D[i]];
m = MAX(m,D[i]);
}
if(A[0] > 1) PR(0);
else {
ll cnt = 1;
REP(i,1,m+1) {
cnt = (cnt * modpow(A[i-1], A[i], MOD)) % MOD;
}
PR(cnt);
}
}
return 0;
}
/*
*/ | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)
const ll MOD = 1000000007;
const ll INF = (ll) 1e15;
ll calc(ll &m, ll p) {
ll ret = 1;
m += p;
if (m >= 10) {
ret++;
m = (m / 10) + (m % 10);
}
return ret;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll M;
cin >> M;
ll ans = 0;
vector<ll> v(M);
REP(i, M) {
ll d, c;
cin >> d >> c;
vector<ll> u;
while (c > 1) {
if (c % 2 == 1)
u.push_back(d);
c /= 2;
ans += c;
d = d + d;
if (d >= 10) {
d = (d / 10) + (d % 10);
ans += c;
}
}
u.push_back(d);
ll n = u[0];
REP(j, u.size() - 1) {
ans += calc(n, u[j + 1]);
}
v[i] = n;
}
ll m = v[0];
REP(i, M - 1) {
ans += calc(m, v[i + 1]);
}
cout << ans << endl;
return 0;
} | #include <iostream>
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
ll s=0, t=0;
for(int i=0; i<n; i++) {
ll x,y;
cin >> x >> y;
s += x*y;
t += y;
}
ll k=s%9;
if(k==0) k=9;
cout << t-1+(s-k)/9 << endl;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
map<char, int> mp;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int main(){
// cin.tie(0);
// ios::sync_with_stdio(false);
mp['N'] = 0;
mp['S'] = 1;
mp['E'] = 2;
mp['W'] = 3;
while(1){
cin >> n;
if(n == 0) return 0;
int a[25][25] = {{}};
for(int i=0; i<n; ++i){
int x, y;
cin >> x >> y;
a[x][y] = 1;
}
int m;
cin >> m;
int p = 10, q = 10;
int tmp = 0;
if(a[p][q] == 1) ++tmp;
for(int i=0; i<m; ++i){
char c;
int d;
cin >> c >> d;
for(int j=0; j<d; ++j){
p += dx[mp.at(c)];
q += dy[mp.at(c)];
if(a[p][q] == 1){
++tmp;
a[p][q] = 0;
}
}
}
cout << (tmp == n ? "Yes\n" : "No\n");
}
}
| //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
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 vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
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 EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int mapgem[21][21];
VI wque;
vector<char> que;
VI gemx;
VI gemy;
string search(){
//N y+ S y-
//E x+ W x-
int rx = 10;
int ry = 10;
int dx = 0;
int dy = 0;
int qsize = wque.size();
mapgem[rx][ry]=0;
REP(i,qsize){
dx = 0;
dy = 0;
if(que[i] == 'N'){dy++;}
else if(que[i] == 'S'){dy--;}
else if(que[i] == 'E'){dx++;}
else if(que[i] == 'W'){dx--;}
REP(j,wque[i]){
rx += dx;
ry += dy;
mapgem[rx][ry] = 0;
}
}
REP(i,gemx.size()){
if(mapgem[gemx[i]][gemy[i]]==1){return "No";}
}
return "Yes";
}
int main(){
int endlchk =8101919;
int N;
int M;
char d;
int l;
int mx,my;
while(true){
if(endlchk != 8101919){cout << endl;}
endlchk = 0;
cin >> N;
if(N==0){break;}
REP(i,20){
REP(j,20){
mapgem[i][j]=0;
}
}
REP(i,N){
cin >> mx >> my;
mapgem[mx][my] = 1;
gemx.push_back(mx);
gemy.push_back(my);
}
cin >> M;
REP(i,M){
cin >> d >> l;
que.push_back(d);
wque.push_back(l);
}
cout << search();
que.clear();
wque.clear();
gemx.clear();
gemy.clear();
}
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if(n % 111 == 0) {
cout << n << endl;
return 0;
}
else {
cout << 111 * ((n / 111)+1) << endl;
}
} | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
string s;
string ans="";
cin >>s;
for(int i=0;i<s.size()-8;i++){
ans+=s[i];
}
cout<<ans<<endl;
} | 0 |
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
cout << a;
return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
for (auto &a : vec) {
cout << a;
if (&a != &vec.back()) {
cout << " ";
}
}
return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
for (auto &v : vv) {
for (auto &a : v) {
cout << a;
if (&a != &v.back()) {
cout << " ";
}
}
if (&v != &vv.back()) {
cout << "\n";
}
}
return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
bool f = print_(head);
if (sizeof...(tail) != 0) {
cout << (f ? " " : "\n");
}
print(forward<Tail>(tail)...);
}
#pragma endregion
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int n, m, q;
cin >> n >> m >> q;
vs s(n);
rep(i, n){
cin >> s[i];
}
vvi v(n+1, vi(m+1, 0));
vvi ev(n, vi(m+1, 0));
vvi eh(n+1, vi(m, 0));
rep(i, n)rep(j, m){
v[i+1][j+1] = s[i][j]-'0';
}
rep(i, n+1)rep(j, m){
v[i][j+1] += v[i][j];
}
rep(i, n)rep(j, m+1){
v[i+1][j] += v[i][j];
}
rep(i, n-1)rep(j, m){
ev[i+1][j+1] = (s[i][j] == '1' && s[i+1][j] == '1');
}
rep(i, n)rep(j, m){
ev[i][j+1] += ev[i][j];
}
rep(i, n-1)rep(j, m+1){
ev[i+1][j] += ev[i][j];
}
rep(i, n)rep(j, m-1){
eh[i+1][j+1] = (s[i][j] == '1' && s[i][j+1] == '1');
}
rep(i, n+1)rep(j, m-1){
eh[i][j+1] += eh[i][j];
}
rep(i, n)rep(j, m){
eh[i+1][j] += eh[i][j];
}
while(q--){
int a, b, c, d;
cin >> a >> b >> c >> d;
int ans = v[c][d]-v[a-1][d]-v[c][b-1]+v[a-1][b-1];
ans -= ev[c-1][d]-ev[a-1][d]-ev[c-1][b-1]+ev[a-1][b-1];
ans -= eh[c][d-1]-eh[a-1][d-1]-eh[c][b-1]+eh[a-1][b-1];
print(ans);
}
}
| #include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
if(a.first==b.first)
{
if(a.second<=b.second)
return true;
else
return false;
}
if(a.first>b.first)
return true;
else return false;
}
long long int gcd(long long int bdda,long long int chota)
{
if(chota==0)
return bdda;
return gcd(chota,bdda%chota);
}
void solve()
{
int A, B, M;
cin >> A >> B >> M;
vector<int> a(A);
vector<int> b(B);
for (int i = 0; i < A; i++)cin >> a[i];
for (int i = 0; i < B; i++)cin >> b[i];
int minA = *min_element(a.begin(), a.end());
int minB = *min_element(b.begin(), b.end());
int ans = minA+minB;
for (int i = 0; i < M; i++) {
int x, y, c;
cin >> x >> y >> c; x--; y--;
ans = min(ans, a[x] + b[y] - c);
}
cout << ans << endl;
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
t=1;
//cin>>t;
while(t--)
{
solve();
}
}
| 0 |
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
#define fs first
#define sc second
const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
return count(s.cbegin(), s.cend(), c);
}
// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
return (a + b - 1) / b;
}
// 桁和
template<typename T>
T digsum(T n) {
T res = 0;
while(n > 0) {
res += n%10;
n /= 10;
}
return res;
}
// 回文判定
bool kai (string s) {
string t{s};
reverse(begin(t), end(t));
return s == t;
}
using pint = pair<int, int>;
using pll = pair<ll, ll>;
int main(void)
{
cout.tie(0);
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int n;
cin >> n;
print(180 * (n - 2));
}
| #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++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main() {
int n; cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
sort(all(a)); reverse(all(a));
map<ll, ll> m;
rep(i, n) m[a[i]]++;
ll ans = 0;
rep(i, n) {
if (!m[a[i]]) continue;
m[a[i]]--;
ll p = 1;
while (p <= a[i]) p *= 2;
if (m[p - a[i]]) {
m[p - a[i]]--;
ans++;
}
}
cout << ans << endl;
}
| 0 |
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
template <class T>
inline bool chmin(T &a, T b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <class T>inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<long long, long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
int main() {
ll x; cin >> x;
ll ans = x/11*2;
ll rest = x%11;
if(rest >= 7) ans += 2;
else if(rest > 0) ans++;
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int a, x, y;
cin >> a;
x = a;
// ここにプログラムを追記
while (x > 0) {
y += x % 10;
x /= 10;
}
if ((a % y) == 0) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
}
| 0 |
#include <iostream>
using namespace std;
int order[4000];
bool search(int);
class Member {
public:
Member() {sum = 0;}
void add(long price, long num) {
sum += (long long int)price*num;
}
bool milion()
{
if (sum >= 1000000) return true;
else return false;
}
private:
long long int sum;
int id;
};
bool search(int num)
{
for (int i=0; i<4000; i++)
if (order[i] == num ) return true;
return false;
}
int main()
{
int n, idx, memNum;
long price, num;
bool nothing;
ios::sync_with_stdio();
while (1) {
Member *member = new Member[4000];
memNum=0;
nothing =true;
for (int i=0; i<4000; i++) order[i] = -1;
if (cin >> n, !n) break;
for (int i=0; i<n; i++) {
scanf("%d %ld %ld", &idx, &price, &num);
member[idx].add(price, num);
if (!search(idx)) order[memNum++] = idx;
}
for (int i=0; i<4000 && order[i] > 0; i++)
if (member[order[i]].milion()) { cout << order[i] << endl; nothing = false; }
if (nothing) cout << "NA" << endl;
}
} | #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int findNum(vector<pair<int, long long> > comm, int num) {
for(int i=0; i<comm.size(); i++) {
if(comm[i].first == num) {
return i;
}
}
return comm.size();
}
int main() {
int n;
cin>>n;
while(n != 0) {
int m = n;
vector<pair<int, long long> > comm;
while(m--) {
int num;
long long price, unit;
cin>>num>>price>>unit;
int dataNum = findNum(comm, num);
if(dataNum == comm.size()) {
comm.push_back(make_pair(num, price*unit));
}
else {
comm[dataNum].second += price*unit;
}
}
bool flag = true;
for(int i=0; i<comm.size(); i++) {
if(comm[i].second >= 1000000) {
cout<<comm[i].first<<endl;
flag = false;
}
}
if(flag == true) {
cout<<"NA"<<endl;
}
cin>>n;
}
} | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define INF 1000000009
#define MAX_V 500000
struct edge {
int to;
int cost;
edge(int to,int cost):to(to),cost(cost){}
};
int V;
vector<edge> G[MAX_V];
int d[MAX_V];
void dijkstra(int s) {
priority_queue<P, vector<P>, greater<P> > que;
fill(d, d+V, INF);
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));
}
}
}
}
map<P,int> zip(vector<P> v){
sort(all(v));
map<P,int> res;
int vsz=v.size();
rep(i,vsz){
res[v[i]]=i;
}
return res;
}
int main(){
int n,m;cin>>n>>m;
V=500000;
int p[m],q[m],c[m];
rep(i,m){
cin>>p[i]>>q[i]>>c[i];
--p[i];--q[i];--c[i];
}
vector<P> tozip;
rep(i,m){
tozip.push_back(P(p[i],c[i]));
tozip.push_back(P(q[i],c[i]));
}
rep(i,n){
tozip.push_back(P(i,-1));
}
auto index=zip(tozip);
rep(i,m){
G[index[P(p[i],c[i])]].push_back(edge(index[P(q[i],c[i])],0));
G[index[P(q[i],c[i])]].push_back(edge(index[P(p[i],c[i])],0));
G[index[P(p[i],c[i])]].push_back(edge(index[P(p[i],-1)],1));
G[index[P(q[i],c[i])]].push_back(edge(index[P(q[i],-1)],1));
G[index[P(p[i],-1)]].push_back(edge(index[P(p[i],c[i])],1));
G[index[P(q[i],-1)]].push_back(edge(index[P(q[i],c[i])],1));
}
dijkstra(0);
cout<<(d[index[P(n-1,-1)]]==INF?-1:d[index[P(n-1,-1)]]/2)<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXV = 100;
const ll INF = (1LL<<60);
int V, E;
ll adjMat[MAXV][MAXV];
int main(){
scanf("%d%d",&V,&E);
for (int i = 0; i < V; i++)
for(int j = 0; j < V; j++)
adjMat[i][j] = INF;
for (int i = 0, s, t, d; i < E; i++) {
scanf("%d%d%d",&s,&t,&d);
adjMat[s][t] = d;
}
for (int k = 0; k < V; k++)
for (int i = 0; i < V; i++)
for (int j = 0;j < V; j++)
if (adjMat[i][k] != INF && adjMat[k][j] != INF)
adjMat[i][j] = min(adjMat[i][j],adjMat[i][k]+adjMat[k][j]);
for (int i = 0; i < V; i++) {
if (adjMat[i][i] < 0) {
printf("NEGATIVE CYCLE\n");
return 0;
}
}
for (int i = 0; i < V; i++){
for (int j = 0; j < V; j++){
if (j)
printf(" ");
if (i == j)
printf("0");
else if (adjMat[i][j] >= INF)
printf("INF");
else
printf("%lld",adjMat[i][j]);
}
printf("\n");
}
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
int gcd(int x,int y){
if(x%y==0) return y;
else return gcd(y,x%y);
}
int main(){
int n,i,k,a,G,MAX;scanf("%d%d",&n,&k);
scanf("%d",&G);MAX = G;
if(n == 1){
printf((k==G) ? "POSSIBLE\n":"IMPOSSIBLE\n");
return 0;
}
for(i=1;i<n;i++){
scanf("%d",&a);
G = gcd(G,a);
MAX = max(MAX,a);
}
printf((k<=MAX && k%G==0) ? "POSSIBLE\n":"IMPOSSIBLE\n");
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define MOD 1000000007
#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))
template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
cout << "(" << m.first << ", " << m.second << ")";
return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
ll c = 0;
cout << "{ ";
iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
cout << "}";
return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
cout << "{ ";
rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
cout << "}";
return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
ll c = 0;
cout << "{ ";
iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
cout << "}";
return s;
}
int main(void) {
ll N, K;
vector<ll> A;
cin >> N >> K;
A.resize(N);
rep(i, N) cin >> A[i];
if(N == 1) {
if(A[0] == K) cout << "POSSIBLE" << endl;
else cout << "IMPOSSIBLE" << endl;
} else {
ll mini;
ll prev;
sort(A.begin(), A.end());
mini = A[1] - A.front();
prev = A.front();
while(mini != prev) {
ll temp;
temp = mini;
mini = abs(prev - mini);
prev = temp;
if(mini == 0) {
mini = prev;
break;
}
}
iter(a, A) {
if(a >= K && (a - K) % mini == 0) {
cout << "POSSIBLE" << endl;
return 0;
}
}
cout << "IMPOSSIBLE" << endl;
}
return 0;
}
| 1 |
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
using namespace std;
int main()
{
int R;
cin >> R;
if (R < 1200) {
cout << "ABC" << endl;
}
else if (R < 2800) {
cout << "ARC" << endl;
}
else {
cout << "AGC" << endl;
}
}
| #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(20);
int N; cin >> N;
cout << (N-2)*180 << endl;
} | 0 |
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <memory.h>
#include <queue>
using namespace std;
#define N 303
int dp[N][N][N];
char s[N];
void solve() {
scanf(" %s",s+1);
int n = strlen(s+1);
int k;scanf("%d",&k);
for(int cc = k;cc>=0;--cc) {
for(int i=1;i<=n;++i) {
for(int j=n;j>=i+1;--j) {
dp[cc][i+1][j] = max(dp[cc][i+1][j], dp[cc][i][j]);
dp[cc][i][j-1] = max(dp[cc][i][j-1],dp[cc][i][j]);
if(s[i]==s[j]) {
dp[cc][i+1][j-1] = max(dp[cc][i+1][j-1], dp[cc][i][j]+1);
} else if(cc>0){
dp[cc-1][i+1][j-1] = max(dp[cc-1][i+1][j-1], dp[cc][i][j]+1);
}
}
}
}
int ret = 0;
for(int i=1;i<=n;++i) {
for(int cc=0;cc<=k;++cc) {
ret = max(ret, dp[cc][i][i-1]*2);
ret = max(ret, dp[cc][i+1][i]*2);
ret = max(ret,1 + dp[cc][i][i]*2);
}
}
printf("%d\n", ret);
}
int main() {
//freopen("input.txt","r",stdin);
solve();
return 0;
}
| #include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("in.in");ofstream coutt("out.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), is_sorted(),
signed main(){
FASTER;
int n;cin>>n;
cout<<180*(n-2);
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
if(y == 0) return x;
else return GCD(y,x%y);
}
int main() {
int n;
cin >> n;
cout << n / 3 << endl;
}
| #include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
int a;
cin>>a;
a += (a*a) + (a*a*a);
cout<<a;
cout<<endl;
return 0;
} | 0 |
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
int N;
cin>>N;
int A[200000],B[200000];
for(int i=0;i<N;i++) cin>>A[i];
for(int i=0;i<N;i++) cin>>B[i];
sort(B,B+N,greater<int>());
vector<int> same;
for(int i=0;i<N;i++){
if(A[i]==B[i]) same.push_back(i);
}
int j=0;
int judge=0;
for(int i=0;i<same.size();i++){
while(A[same[i]]==B[same[i]]){
if(j==N){
judge++; break;
}
if(A[j]!=B[same[i]]&&B[j]!=B[same[i]]) swap(B[same[i]],B[j]);
j++;
}
if(judge==1) break;
}
if(judge==0){
cout<<"Yes"<<endl;
for(int i=0;i<N-1;i++) cout<<B[i]<<' ';
cout<<B[N-1]<<endl;
}
else cout<<"No"<<endl;
return 0;
} | #include <iostream>
#include <string>
#include <queue>
using namespace std;
class Player{
private:
int base;
public:
Player(int i){
base=1;
}
void SetBase(int a){
this->base =a;
}
int GetBase(){
return this->base;
}
};
class Baseball{
private:
int score;
int out;
queue<Player> que;
public:
Baseball(){
score = out=0;
}
void add_hit(int num){
Player one(1);
this->que.push(one);
int length=this->que.size();
for(int i= 0;i<length;i++){
Player tmp = this->que.front();
this->que.pop();
int tmp_base=tmp.GetBase();
if((tmp_base+num)>4){
score++;
}else{
tmp.SetBase(tmp_base+num);
this->que.push(tmp);
}
}
}
void add_out(){
this->out++;
}
void add_score(){
this->score++;
}
int GetOut(){
return this->out;
}
int GetScore(){
return this->score;
}
void show_score(){
cout<<this->score<<endl;
}
};
int main(void){
int time;
cin >> time;
for(int i=0;i<time;i++){
Baseball baseball;
while(baseball.GetOut()!=3){
string judge;
cin>>judge;
if(judge == "HIT"){
baseball.add_hit(1);
}else if(judge=="OUT"){
baseball.add_out();
}else if(judge=="HOMERUN"){
baseball.add_hit(4);
}
}
cout<<baseball.GetScore()<<endl;
}
return 0;
}
| 0 |
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
void* p=malloc(size);\
esp_new=(lint)p+size-1;\
void * stack_extend_memory_ = malloc(size);\
void * stack_extend_origin_memory_;\
char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
*stack_extend_dummy_memory_ = 0;\
asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI = 3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
if (lhs > rhs) {
lhs = rhs;
return 1;
}
return 0;
}
inline lint gcd(lint a, lint b) {
while (b) {
lint c = a;
a = b; b = c % b;
}
return a;
}
inline lint lcm(lint a, lint b) {
return a / gcd(a, b) * b;
}
bool isprime(lint n) {
if (n == 1)return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0)return false;
}
return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
T res(1),now(a);
while(b){
if(b&1)res*=now;
b>>=1;
now*=now;
}
return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
rep(i, (int)vec.size() - 1)std::cout << vec[i] << " ";
if(!vec.empty())std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
T rprev = r;
rprev--;
for (T i = l; i != rprev; i++) {
std::cout << *i << " ";
}
std::cout << *rprev << std::endl;
}
int m;
int main(){
lint sum=0,digits=0;
std::cin>>m;
rep(i,m){
lint d,c;
std::cin>>d>>c;
sum+=d*c;
digits+=c;
}
std::cout<<digits-1+(sum-1)/9<<std::endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i{ 0 }; i < n; ++i)
using namespace std;
int main() {
int d, g;
cin >> d >> g;
vector<int> ps(d);
vector<int> cs(d);
rep(i, d) cin >> ps[i] >> cs[i];
// for(auto p :cs) cout <<p;
int min_cnt{ INT_MAX };
rep(i, 1 << d) {
int cnt{ 0 };
int score{ 0 };
rep(j, d) if (i >> j & 1) {
score += ps.at(j) * 100 * (j + 1) + cs.at(j);
cnt += ps.at(j);
}
// cout << "i: " << i << "cnt: " << cnt << "score: " << score << endl;
for (int j = d - 1; j >= 0; j--) {
if (score >= g) continue;
if (i >> j & 1) continue;
int q = min((int)((g - score) / ((j + 1) * 100)), ps.at(j));
score += q * 100 * (j + 1);
cnt += q;
// cout << "q: " << q << "cnt: " << cnt << "score: " << score << endl;
}
// cout << "i: " << i << "cnt: " << cnt << "score: " << score << endl;
if (score >= g) min_cnt = min(min_cnt, cnt);
}
cout << min_cnt << endl;
}
| 0 |
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;
int main() {
fastIO;
string s;
cin >> s;
for (size_t i = 0; i < s.size() - 1; i++) {
if (s.at(i) == 'A' && s.at(i + 1) == 'C') {
cout << "Yes\n";
return 0;
}
}
cout << "No\n";
} | #include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector>
#include <string.h>
#include <iomanip>
#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define INF 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());//昇順ソート
#define usort(a) sort(a.rbegin(),a.rend());//降順ソート
using namespace::std;
int jo(ll int a, ll int b){//累乗
ll int num=1;
rep(i,0,b) num=num*a;
return num;
}
char tobig(char s){//char大文字化
return (s-0x20);
}
char tolow(char s){//char小文字化
return (s+0x20);
}
int ctoi(char a){//char->int
if('0'<=a&&a<='9') return (a-'0');
return -1;
}
int gcd(ll int a,ll int b) {//最大公約数
if(a<b) return gcd(b,a);
int c;
while ((c=a%b)) {
a=b;
b=c;
}
return b;
}
int lcm(ll int a,ll int b){//最小公倍数
return (a*b)/gcd(a,b);
}
int main(){
int N;
cin>>N;
cout<<(N-2)*180;
}
// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));
//cout<<fixed<<setprecision(n); //小数点n桁まで表示
// vector<pair<int,int>> data(N); //2つのデータを格納、.first/.secondで参照
// pairのソートはfirst優先の昇順
| 0 |