code_file1
stringlengths 80
4k
| code_file2
stringlengths 91
4k
| similar_or_different
int64 0
1
|
---|---|---|
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
int n, a[330], dp[300*303], d2[300*303], ans = 1, sum;
int expo(int b, int e) {
if(e == 0) return 1;
if(e & 1) return 1ll * b * expo(1LL * b * b % MOD, e >> 1) % MOD;
return expo(1LL * b * b % MOD, e >> 1);
}
int inv_mod(int x) { return expo(x, MOD - 2); }
int main() {
scanf("%d", &n);
dp[0] = d2[0] = 1;
for(int i = 0; i < n; i++) {
scanf("%d", &a[i]);
sum += a[i];
ans = 3LL * ans % MOD;
for(int v = n * 300; v >= 0; v--) {
dp[v] = (2LL * dp[v] % MOD + (v >= a[i] ? dp[v - a[i]] : 0)) % MOD;
d2[v] = (d2[v] % MOD + (v >= a[i] ? d2[v - a[i]] : 0)) % MOD;
}
}
for(int i = sum; 2*i >= sum; i--)
ans = (ans - 3LL * dp[i] % MOD + MOD) % MOD;
if(sum % 2 == 0) ans = (ans + 3LL * d2[sum/2] % MOD) % MOD;
printf("%d\n", ans);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define MOD 998244353
template<typename ty1,typename ty2>
inline int add(ty1 x, ty2 y) {
if(y>=MOD)y%=MOD;
if(x>=MOD)x%=MOD;
x += y; return x < MOD ? x : x - MOD;
}
template<typename ty1,typename ty2>
inline void addto(ty1 &x, ty2 y) {
if(y>=MOD)y%=MOD;
if(x>=MOD)x%=MOD;
x += y; if (x >= MOD) x -= MOD;
}
template<typename ty1,typename ty2>
inline int sub(ty1 x, ty2 y) {
if(y>=MOD)y%=MOD;
if(x>=MOD)x%=MOD;
x -= y; return x < 0 ? x + MOD : x;
}
template<typename ty1,typename ty2>
inline void subto(ty1 &x, ty2 y) {
if(y>=MOD)y%=MOD;
if(x>=MOD)x%=MOD;
x -= y; if (x < 0) x += MOD;
}
template<typename ty1,typename ty2>
inline int mul(ty1 x, ty2 y) {
if(y>=MOD)y%=MOD;
if(x>=MOD)x%=MOD;
return 1ll * x * y % MOD;
}
template<typename ty1,typename ty2>
void multo(ty1 &x, ty2 y) {
if(y>=MOD)y%=MOD;
if(x>=MOD)x%=MOD;
x=1ll * x * y % MOD;
}
long long int ppow(long long int i, long long int j){
long long int res = 1LL;
while (j){
if ((j & 1LL)){
res *= i;
if (res >= MOD){
res %= MOD;
}
}
j >>= 1;
i *= i;
if (i >= MOD){
i %= MOD;
}
}
return res;
}
class Combination{
public:
vector<long long int> k;
vector<long long int> r;
void resize(int N){
k.resize(N + 2);
r.resize(N + 2);
k[0] = 1;
for (int i = 1; i < N+2; i++){
k[i] = k[i - 1];
k[i] *= i;
if (k[i] >= MOD)k[i] %= MOD;
}
long long int al = k[k.size() - 1];
long long int iv = ppow(k[k.size() - 1],MOD-2);
r[k.size() - 1] = iv;
for (int i = (int)(r.size()) - 2; i >= 0; i--){
r[i] = r[i + 1] * (i + 1);
if (r[i] >= MOD){
r[i] %= MOD;
}
}
}
long long int C(int a, int b){
if (a < b)return 0;
long long int up = k[a];
long long int dw = r[b] * r[a - b];
dw %= MOD;
up *= dw;
up %= MOD;
return up;
}
long long int H(int a, int b){
return C(a + b - 1, b);
}
long long int catalan_number(int n){
return (C(2 * n, n) + MOD - C(2 * n, n - 1)) % MOD;
}
};
Combination C;
#define MAX 302
int n;
vector<int> v;
int dp[MAX][MAX*MAX][4];
int im[MAX];
int main(){
cin>>n;
for(int i=0;i<n;i++){
int a;
scanf("%d",&a);
v.push_back(a);
}
//v[0]<=v[1]<=v[2]
//v[0]+v[1]>v[2]
for(int i=0;i<n;i++){
im[i]+=v[i];
if(i)im[i]+=im[i-1];
}
dp[0][0][0]=1;
for(int i=0;i<n;i++){
for(int j=0;j<=300*i;j++){
for(int k=0;k<4;k++){
if(dp[i][j][k]==0)continue;
//choose
addto(dp[i+1][j+v[i]][k],dp[i][j][k]);
//discard
addto(dp[i+1][j][k|1],dp[i][j][k]);
addto(dp[i+1][j][k|2],dp[i][j][k]);
}
}
}
int ans=0;
int overall=0;
for(int j=(im[n-1]+1)/2;j<=300*n;j++){
addto(ans,mul(3,dp[n][j][3]));
}
for(int j=1;j<=300*n;j++){
addto(overall,dp[n][j][3]);
}
subto(overall,ans);
printf("%d\n",overall);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << min(a, b) + min(c, d) << endl;
return 0;
} | #include<stdio.h>
int main()
{
long long int a,ans;
long double b,s;
scanf("%lld %Lf",&a,&b);
s=a*b;
ans=s;
printf("%lld",ans);
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(void){
ios::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vector<int> p(n+1);
cin >> p[0] >> p[1];
for(int i = 0; i < n-2; i++){
int a, b; cin >> a >> b;
p[i+2] = b;
}
{
int a, b; cin >> a >> b;
p[n] = b;
}
int dp[101][101];
memset(dp, 0, sizeof(dp));
n = p.size() - 1;
for(int l = 2; l <= n; l++){
for(int i = 1; i <= n-l+1; i++){
int j = i+l-1;
dp[i][j] = INT_MAX/10;
for(int k = i; k < j; k++){
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j]);
}
}
}
cout << dp[1][n] << endl;
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
if (a < b) return euclidean_gcd(b, a);
unsigned r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
ll ll_gcd(ll a, ll b) {
if (a < b) return ll_gcd(b, a);
ll r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
class UnionFind {
public:
vector <ll> par;
vector <ll> siz;
UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
for (ll i = 0; i < sz_; ++i) par[i] = i;
}
void init(ll sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL);
for (ll i = 0; i < sz_; ++i) par[i] = i;
}
ll root(ll x) {
while (par[x] != x) {
x = par[x] = par[par[x]];
}
return x;
}
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y) return false;
if (siz[x] < siz[y]) swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y) {
return root(x) == root(y);
}
ll size(ll x) {
return siz[root(x)];
}
};
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
long long modinv(long long a, long long mod) {
return modpow(a, mod - 2, mod);
}
vector<int> tpsort(vector<vector<int>>& G) {
int V = G.size();
vector<int> sorted_vertices;
queue<int> que;
vector<int> indegree(V);
for (int i = 0; i < V; i++) {
for (int j = 0; j < G[i].size(); j++) {
indegree[G[i][j]]++;
}
}
for (int i = 0; i < V; i++) {
if (indegree[i] == 0) {
que.push(i);
}
}
while (que.empty() == false) {
int v = que.front();
que.pop();
for (int i = 0; i < G[v].size(); i++) {
int u = G[v][i];
indegree[u] -= 1;
if (indegree[u] == 0) que.push(u);
}
sorted_vertices.push_back(v);
}
return sorted_vertices;
}
struct Point
{
double x;
double y;
};
struct LineSegment
{
Point start;
Point end;
};
double tenkyori(const LineSegment& line, const Point& point)
{
double x0 = point.x, y0 = point.y;
double x1 = line.start.x, y1 = line.start.y;
double x2 = line.end.x, y2 = line.end.y;
double a = x2 - x1;
double b = y2 - y1;
double a2 = a * a;
double b2 = b * b;
double r2 = a2 + b2;
double tt = -(a * (x1 - x0) + b * (y1 - y0));
if (tt < 0)
return sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
else if (tt > r2)
return sqrt((x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0));
double f1 = a * (y1 - y0) - b * (x1 - x0);
return sqrt((f1 * f1) / r2);
}
int main() {
ll m;
cin >> m;
ll dig = 0;
ll sum = 0;
for (int i = 0; i < m; i++) {
ll a, b;
cin >> a >> b;
dig += b;
sum += a * b;
}
cout << dig - 1 + (sum-1) / 9 << endl;
} | 0 |
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
//using Graph = vector<vector<int>>;
typedef long long ll;
using Graph = vector<vector<pair<ll,ll>>>;
const int mod =1e+9+7;
const int dy[4]={0,1,0,-1};
const int dx[4]={1,0,-1,0};
const ll INF=1e10;
int main(){
ll n; cin>>n;
Graph G(n);
rep(i,n-1){
ll a,b,c;
cin>>a>>b>>c;
a--;b--;
G[a].push_back(make_pair(b,c));
G[b].push_back(make_pair(a,c));
}
ll q,k; cin>>q>>k;
k--;
vector<ll>dist(n,0);
queue<ll>que;
vector<bool>seen(n,false);
que.push(k);
while(!que.empty()){
ll v=que.front();que.pop();
seen[v]=true;
for(auto nv:G[v]){
if(seen[nv.first]==true)continue;
dist[nv.first]=dist[v]+nv.second;
que.push(nv.first);
}
}
vector<ll>x(q),y(q);
rep(i,q){
cin>>x[i]>>y[i];
x[i]--;y[i]--;
}
rep(i,q){
cout<<dist[x[i]]+dist[y[i]]<<endl;
}
/*rep(i,n){
cout<<dist[i]<<" ";
}
cout<<endl;*/
}
| #include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;
int main(){
int distance[10], v1, v2;
char garbage;
while(cin >> distance[0]){
cin >> garbage;
double lineLength = distance[0];
range(i,1,10){
cin >> distance[i] >> garbage;
lineLength+= distance[i];
}
cin >> v1 >> garbage >> v2;
double sum_v = v1 + v2;
double time = lineLength / sum_v;
double pass_location = v1 * time;
rep(i,10){
pass_location-= static_cast<double>(distance[i]);
if(pass_location <= 0){
cout << i + 1 << endl;
break;
}
}
}
} | 0 |
#include <iostream>
#include <vector>
#include <set>
#include <string>
using namespace std;
void solve()
{
int n, k;
while (cin >> n >> k, n || k)
{
vector<string> card(n);
for (int i = 0; i < n; ++i)
{
cin >> card[i];
}
set<string> S;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n; ++j)
{
if (k == 2)
{
if (i != j)
{
S.insert(card[i] + card[j]);
S.insert(card[j] + card[i]);
}
}
else
{
if (k == 3)
{
for (int a = 0; a < n; ++a)
{
if (i != j && j != a && i != a)
{
S.insert(card[i] + card[j] + card[a]);
S.insert(card[i] + card[a] + card[j]);
S.insert(card[j] + card[i] + card[a]);
S.insert(card[j] + card[a] + card[i]);
S.insert(card[a] + card[i] + card[j]);
S.insert(card[a] + card[j] + card[i]);
}
}
}
else
{
for (int a = 0; a < n; ++a)
{
for (int b = 0; b < n; ++b)
{
if (i != j && i != a && i != b &&
j != a && j != b &&
a != b)
{
S.insert(card[i] + card[j] + card[a] + card[b]);
S.insert(card[i] + card[j] + card[b] + card[a]);
S.insert(card[i] + card[a] + card[b] + card[j]);
S.insert(card[i] + card[a] + card[j] + card[b]);
S.insert(card[i] + card[b] + card[a] + card[j]);
S.insert(card[i] + card[b] + card[j] + card[a]);
S.insert(card[j] + card[i] + card[a] + card[b]);
S.insert(card[j] + card[i] + card[b] + card[a]);
S.insert(card[j] + card[a] + card[b] + card[i]);
S.insert(card[j] + card[a] + card[i] + card[b]);
S.insert(card[j] + card[b] + card[a] + card[i]);
S.insert(card[j] + card[b] + card[i] + card[a]);
S.insert(card[a] + card[i] + card[b] + card[j]);
S.insert(card[a] + card[i] + card[j] + card[b]);
S.insert(card[a] + card[j] + card[b] + card[i]);
S.insert(card[a] + card[j] + card[i] + card[b]);
S.insert(card[a] + card[b] + card[i] + card[j]);
S.insert(card[a] + card[b] + card[j] + card[i]);
S.insert(card[b] + card[i] + card[a] + card[j]);
S.insert(card[b] + card[i] + card[j] + card[a]);
S.insert(card[b] + card[a] + card[i] + card[j]);
S.insert(card[b] + card[a] + card[j] + card[i]);
S.insert(card[b] + card[j] + card[a] + card[i]);
S.insert(card[b] + card[j] + card[i] + card[a]);
}
}
}
}
}
}
}
cout << S.size() << endl;
}
}
int main()
{
solve();
return(0);
} | #include<cstdio>
#include<algorithm>
using namespace std;
int main(){
int n,m;
while(scanf("%d%d",&n,&m),n,m){
int yasai[1024]={0};
for(int i = 0;i < n; i++){
scanf("%d",&yasai[i]);
}
sort(yasai,yasai+n);
for(int i = n;i >= 0; i-=m){
yasai[i] = 0;
}
int ans=0;
for(int i = 0;i < n; i++){
ans += yasai[i];
}
printf("%d\n",ans);
}
return 0;
} | 0 |
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
int n;
string result;
vector<int> a;
vector<int>::reverse_iterator begin,end;
cin >> n;
for (int c = 0; c < n; c++) {
int t;
cin >> t;
a.push_back(t);
}
begin = a.rbegin();
end = a.rend();
for (;begin != end; begin++) {
result += to_string(*begin) + " ";
}
result.erase(result.size() - 1);
cout << result << endl;
} | #include<iostream>
using namespace std;
int main()
{
int n,j,i,s;
cin>>n;
int * a=new int[n];
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;(n/2)>i;i++)
{
s=a[i];
a[i]=a[n-1-i];
a[n-1-i]=s;
}
for(i=0;i<n;i++){
cout<<a[i];
if(i!=n-1)
cout<<" ";
}
cout<<endl;
delete[] a;
return 0;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
if(a.first != b.first){
return a.first < b.first;
}else{
return a.second < b.second;
}
}
bool In_map(ll y,ll x,ll h,ll w){
if(y<0 || x<0 || y>=h || x>=w){
return 0;
}else{
return 1;
}
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
int main() {
vector<queue<ll>>que(3);
vector<string>S(3);
rep(i,3){
char c;
cin>>S[i];
rep(j,S[i].size()){
que[i].push(S[i][j]-'a');
}
// cout<<que[i].size()<<endl;
}
ll now=que[0].front();
que[0].pop();
while(1){
//cout<<now<<" "<<que[now].size()<<endl;
if(que[now].empty()){
cout<<(char)(now+'A')<<endl;
return 0;
}else{
//cout<<now<<endl;
ll tmp;
tmp=que[now].front();
que[now].pop();
now=tmp;
}
}
return 0;
} | #include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#define M 2100000
using namespace std;
int main(void)
{
int i,j,n,k,m,a[3001],b[3001],cost[3001],time[3001],kk,pp,bre;
int p,q,r;
int kin[101][101],zi[101][101];
int flg[10001],leng[10001],min;
int kaku,skin,szi;
while(1) {
scanf("%d %d",&n,&m);
if(n==0 && m==0) break;
for(i=1;i<=n;i++) scanf("%d %d %d %d",&a[i],&b[i],&cost[i],&time[i]);
//??£??\???????????? ??????
for(i=1;i<=m;i++) {
for(j=1;j<=m;j++) {
kin[i][j]=M;
}
}
for(i=1;i<=m;i++) kin[i][i]=0;
for(i=1;i<=n;i++) kin[a[i]][b[i]]=cost[i];
for(i=1;i<=n;i++) kin[b[i]][a[i]]=cost[i];
//??£??\???????????????
for(i=1;i<=m;i++) {
for(j=1;j<=m;j++) {
zi[i][j]=M;
}
}
for(i=1;i<=m;i++) zi[i][i]=0;
for(i=1;i<=n;i++) zi[a[i]][b[i]]=time[i];
for(i=1;i<=n;i++) zi[b[i]][a[i]]=time[i];
scanf("%d",&k);
for(i=1;i<=k;i++) {
scanf("%d %d ",&p,&q);
scanf("%d",&r);
for(j=1;j<=m;j++) {
leng[j]=M;
flg[j]=0;
}
leng[p]=0;
if(r==0) {
for(j=1;j<=m;j++) {
min=M;
for(kk=1;kk<=m;kk++) {
if(flg[kk]==0 && leng[kk]<min) {
kaku=kk;
min=leng[kk];
}
}
flg[kaku]=1;
for(kk=1;kk<=m;kk++) {
if((leng[kaku]+kin[kaku][kk])<leng[kk]) leng[kk]=leng[kaku]+kin[kaku][kk];
}
}
printf("%d\n",leng[q]);
}
else {
for(j=1;j<=m;j++) {
min=M;
for(kk=1;kk<=m;kk++) {
if(flg[kk]==0 && leng[kk]<min) {
kaku=kk;
min=leng[kk];
}
}
flg[kaku]=1;
for(kk=1;kk<=m;kk++) {
if((leng[kaku]+zi[kaku][kk])<leng[kk]) leng[kk]=leng[kaku]+zi[kaku][kk];
}
}
printf("%d\n",leng[q]);
}
}
/*
//cost
printf("??????\n");
printf(" ");
for(i=1;i<=m;i++) printf("%7d ",i);
printf("\n");
printf("\n");
for(i=1;i<=m;i++) {
printf("%7d ",i);
for(j=1;j<=m;j++) {
printf("%7d ",kin[i][j]);
}
printf("\n");
}
printf("\n");
printf("\n");
//time
printf("??????\n");
printf(" ");
for(i=1;i<=m;i++) printf("%7d ",i);
printf("\n");
printf("\n");
for(i=1;i<=m;i++) {
printf("%7d ",i);
for(j=1;j<=m;j++) {
printf("%7d ",zi[i][j]);
}
printf("\n");
}
printf("\n");*/
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
~printer(){cerr<<endl;}
Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
Rics(string x){cerr<<x;return *this;}
Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
Gene c >Rics(rge<c> x){
*this,"["; for(auto it = x.b; it != x.e; ++it)
*this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) {
return uniform_int_distribution<int>(l, r) (rng);
}
int main() {
// freopen("in.txt", "r", stdin);
ios::sync_with_stdio(0);
cin.tie(0);
long long x, y;
cin >> x >> y;
long long ans = 1e18;
for(int mask = 0; mask < 4; mask++) {
long long cur = x;
long long moves = 0;
for(int k = 0; k < 2; k++) {
if((mask >> k) & 1) {
cur = -cur;
moves++;
}
if(k == 0) {
if(cur < y) ans = min(ans, moves + abs(y - cur));
if(cur < -y) moves += (-y-cur), cur = -y;
}
if(k == 1) {
if(cur == y) {
ans = min(ans, moves);
}
}
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
ll x,y;
cin >> x >> y;
ll ans = 999999999999;
if (y - x >= 0) {
ans = min(ans,y-x);
}
if ((-y) - x >= 0) {
ans = min(ans,(-y)-x+1);
}
if (y - (-x) >= 0) {
ans = min(ans,y-(-x)+1);
}
if ((-y) - (-x) >= 0) {
ans = min(ans,(-y) - (-x)+2);
}
cout << ans << endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
int main(void)
{
ll a,b,m,ans;
cin>>a>>b>>m;
vector<ll> A(a),B(b);
rep(i,a) cin>>A[i];
rep(i,b) cin>>B[i];
ll minia=*min_element(all(A)),minib=*min_element(all(B));
ans=minia+minib;
rep(i,m){
ll x,y,c;
cin>>x>>y>>c;
ans = min(ans, A[x-1]+B[y-1]-c);
}
cout<<ans<<endl;
return 0;
} | #include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
void solve();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
#define ini(...) \
int __VA_ARGS__; \
in(__VA_ARGS__)
#define inl(...) \
ll __VA_ARGS__; \
in(__VA_ARGS__)
#define ins(...) \
string __VA_ARGS__; \
in(__VA_ARGS__);
void in() {}
template <typename T, class... U>
void in(T& t, U&... u) {
cin >> t;
in(u...);
}
void out() {
cout << endl;
}
template <typename T, class... U>
void out(const T& t, const U&... u) {
cout << t;
if (sizeof...(u))
cout << " ";
out(u...);
}
#define rep(i, n) for (long long i = 0; i < n; i++)
void solve();
#ifndef ONLINE_JUDGE
#include "./lib.hpp"
#endif
void solve() {
inl(N, A, B);
vll X(N);
rep(i, N) cin >> X[i];
ll ret = 0;
rep(i, N - 1)
ret += min(A * (X[i + 1] - X[i]), B);
out(ret);
}
| 0 |
#include "bits/stdc++.h"
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P =pair<int,int>;
int main(){
int n;
cin >> n;
string s,sf,sl;
vector <int> m(n,0);
cout << 0 << endl;
cin >> s;
if(s=="Vacant"){
exit(0);
}
else{
/*if(s=="Male"){
m[0]=1;
}
else{
m[0]=-1;
}*/
sf=s;
cout << n-1 << endl;
cin >> s;
if(s=="Vacant"){
exit(0);
}
else{
/*if(s=="Male"){
m[n-1]=1;
}
else{
m[n-1]=-1;
}*/
sl=s;
int mi,r,l;
r=n-1;
l=0;
while(r-l!=1){
mi=(r+l)/2;
cout << mi << endl;
cin >> s;
if(s=="Vacant"){
exit(0);
//break;
}
else{
if(s==sf){
if((mi-l)%2==0){
l=mi;
}
else{
r=mi+1;
}
}
else{
if((mi-l)%2==0){
r=mi;
}
else{
l=mi-1;
}
}
}
}
}
}
return 0;
} | #include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=210, Mod=1e9+7;
inline int read()
{
int s=0, w=1; ri char ch=getchar();
while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
return s*w;
}
int n,res;
map<int,int> Q;
signed main()
{
n=read();
for(ri int i=2;i<=n;i++)
{
int x=i;
for(ri int j=2;j*j<=x;j++)
{
if(x%j) continue;
while(x%j==0) Q[j]++, x/=j;
}
if(x>1) Q[x]++;
}
res=1;
for(ri map<int,int>::iterator s=Q.begin();s!=Q.end();s++)
res=res*(s->second+1)%Mod;
printf("%lld\n",res);
return 0;
} | 0 |
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
void solve() {
int N, M;
cin >> N >> M;
vector<vector<int>> to(N+1);
vector<vector<int>> from(N+1);
vector<bool> visited(N+1);
vector<int> parent(N+1);
for (int i = 0; i < N-1+M; i++) {
int a, b; cin >> a >> b;
to[b].push_back(a);
from[a].push_back(b);
}
int root = 1;
while (!to[root].empty()) {
root++;
}
visited[root] = true;
parent[root] = 0;
queue<int> q;
q.push(root);
while (!q.empty()) {
int x = q.front(); q.pop();
visited[x] = true;
for (int dist : from[x]) {
bool ok = true;
for (int y : to[dist]) {
if (!visited[y]) {
ok = false;
break;
}
}
if (ok) {
q.push(dist);
parent[dist] = x;
}
}
}
for (int i = 1; i <= N; i++) {
cout << parent[i] << endl;
}
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
| #include <cmath>
#include <cstdio>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
#include <stdio.h>
#include <functional>
#include <chrono>
using namespace std;
#define rep(i,s,n) for(ll i=s;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MAX_INF = 9223372036854775807;
constexpr ll MOD = (1e9 + 7);
//constexpr ll MOD = (998244353);
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
template<class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
return move(ans);
}
template<class T>
vector<T> vt(T init, ll n) {
vector<T> ans = vector<T>(n, init);
return move(ans);
}
template<class T>
T maxVec(vector<T>& v) {
T ans = -INF;
rep(i, 0, v.size()) {
ans = max(ans, v[i]);
}
return ans;
}
// 素数判定
bool judge(ll n) {
for (ll i = 2; i * i <= n; i++) if (n %= i)return false;
return true;
}
template <class C>
void print(const C & c, std::ostream & os = std::cout)
{
std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, ", "));
os << std::endl;
}
/*
ll count(ll n,ll r) {
ll ans = 0,check = 1;
rep(i,0, r) {
if ((n & check) > 0) {
ans++;
}
check = check << 1;
}
return ans;
}
*/
bool sortreverse(ll a, ll b) {
return a > b;
}
ll kiriage(ll a, ll b) {
if (a % b == 0)return a / b;
return a / b + 1;
}
ll n, m, x, y, t, q, s,k,h,w;
bool topologicalSort(vector<vector<long long>>& graph, vector<long long>& ans) {
vector<unordered_set<long long>> inGraph(graph.size());
vector<long long> node,check(graph.size(),0);
rep(i, 0, graph.size()) {
rep(j, 0, graph.at(i).size()) {
inGraph.at(graph.at(i).at(j)).insert(i);
}
}
rep(i, 0, graph.size()) {
if (inGraph.at(i).size() == 0)node.push_back(i);
}
while (! node.empty()) {
long long v = node.back();
node.pop_back();
ans.push_back(v);
rep(i, 0, graph.at(v).size()) {
inGraph.at(graph.at(v).at(i)).erase(v);
if (inGraph.at(graph.at(v).at(i)).size() == 0) {
node.push_back(graph.at(v).at(i));
}
}
check.at(v) = 1;
}
for (long long v : check) {
if (v == 0)return false;
}
return true;
}
int main() {
cin >> n >> m;
vvl graph(n);
rep(i, 0, n + m - 1) {
cin >> x >> y;
graph.at(x - 1).push_back(y - 1);
}
vl result;
topologicalSort(graph, result);
vl num(n);
rep(i, 0, n) {
num[result[i]] = i;
}
vvl in(n);
rep(i, 0, n) {
for (ll v : graph[i]) {
in[v].push_back(i);
}
}
rep(i, 0, n) {
ll oya = -1, c = -1;
rep(j, 0, in[i].size()) {
if (c < num[in[i][j]]) {
oya = in[i][j];
c = num[in[i][j]];
}
}
printf("%lld\n", oya + 1);
}
} | 1 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>
using namespace std;
static void inputArray(int A[], int num) {
for (int i = 0; i < num; i++) {
cin >> A[i];
}
}
static vector<int> L(100000 + 1);
static vector<int> R(100000 + 1);
static uint64_t inversions = 0;
static inline void merge(int A[], int left, int mid, int right) {
int n1 = mid - left;
int n2 = right - mid;
L.assign(&A[left], &A[left + n1]);
R.assign(&A[mid], &A[mid + n2]);
L[n1] = R[n2] = INT32_MAX;
for (int i = 0, j = 0, k = left; k < right; k++) {
if (L[i] <= R[j]) {
A[k] = L[i];
i++;
} else {
A[k] = R[j];
j++;
inversions += n1 - i;
}
}
}
static inline void mergeSort(int A[], int left, int right) {
if (left + 1 < right) {
int mid = (left + right) / 2;
mergeSort(A, left, mid);
mergeSort(A, mid, right);
merge(A, left, mid, right);
}
}
static vector<int> A(200000);
int main() {
int n;
cin >> n;
inputArray(&A[0], n);
mergeSort(&A[0], 0, n);
cout << inversions << endl;
return 0;
}
| #include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
const int INF = 1001001001;
int main(void){
ll n, k;
cin >> n >> k;
vector<ll> v(n);
REP(i, n) cin >> v[i];
ll ans = -INF;
ll r = min(n, k);
FORe(a, 0, r){
for(ll b = 0; a+b <= r; b++){
vector<ll> p;
ll now = 0;
REP(i, a) p.emplace_back(v[i]), now += v[i];
REP(i, b) p.emplace_back(v[n-i-1]), now += v[n-i-1];
sort(ALL(p));
ll c = min(k-a-b, (ll)p.size());
REP(i, c){
if(p[i] < 0) now -= p[i];
}
chmax(ans, now);
}
}
cout << ans << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_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())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
return is >> p.FF >> p.SS;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const LL MOD = 1e9+7;
struct Edge{
int to, cost;
Edge(int t, int c = 0): to(t), cost(c)
{}
bool operator>(const Edge& rhs) const{
return cost > rhs.cost;
}
bool operator<(const Edge& rhs) const{
return cost < rhs.cost;
}
};
using Graph = vector< vector<Edge> >;
// ????????°???????????¨???
void add_edge(Graph& graph, int u, int v, int cost = 0){
graph[u].push_back(Edge(v,cost));
graph[v].push_back(Edge(u,cost));
}
int prim(const Graph& G){
const int V = G.size();
int res = 0;
vector<bool> visited(V, false);
priority_queue<Edge, vector<Edge>, greater<Edge> > pq;
pq.push(Edge(0,0));
for(int i=0;i<V;++i){
Edge edge = pq.top(); pq.pop();
int v = edge.to;
if(visited[v]){
--i;
continue;
}
visited[v] = true;
res += edge.cost;
for(const auto& e:G[v]){
pq.push(e);
}
}
return res;
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(false);
int V, E; cin >> V >> E;
Graph G(V);
REP(i,E){
int a, b, c; cin >> a >> b >> c;
add_edge(G, a, b, c);
}
cout << prim(G) << endl;
return 0;
} | #include<iostream>
#include<queue>
#include<utility>
#include<vector>
using namespace std;
int V,E,R,S[500010],T[500010],D[500010];
int C[100010];
int const inf=10000*100000+100;
typedef pair<int,int>P;
priority_queue<P,vector<P>,greater<P> > Q;
struct list{
int d,t;
};
vector<list> edges[500010];
int main(){
cin>>V>>E>>R;
for(int i=0;i<E;++i){
cin>>S[i]>>T[i]>>D[i];
list L;
L.d=D[i];
L.t=T[i];
edges[S[i]].push_back(L);
}
for(int j=0;j<V;++j){
if(j==R){
C[j]=0;
}
else C[j]=inf;
}
Q.push(P(0,R));
while(!Q.empty()){
P n=Q.top();
Q.pop();
int m1=n.first;//distance
int m2=n.second;//To...
if(C[m2]<m1)continue;
for(int i=0;i<edges[m2].size();++i){
list L=edges[m2][i];
if(C[L.t]>C[m2]+L.d){
C[L.t]=C[m2]+L.d;
Q.push(P(C[L.t],L.t));
}
}
}
for(int i=0;i<V;++i){
if(C[i]==inf)cout<<"INF"<<endl;
else cout<<C[i]<<endl;
}
} | 0 |
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MOD 1000000007
#define MOD2 998244353
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<=b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define T int
#define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
auto clk=clock();
ll mexp(ll a, ll b, ll m){
ll ans=1;
a%=m;
while(b){
if(b&1) ans=ans*a%m;
b>>=1;
a=a*a%m;
}
return ans;
}
const int N = 100005;
ll X[N];
int main(){
IOS
srand(chrono::high_resolution_clock::now().time_since_epoch().count());
ll n, a, b;
cin >> n >> a >> b;
FOR(i,1,n){
cin >> X[i];
}
ll ans = 0;
FOR(i,2,n){
ans += min((X[i] - X[i-1]) * a, b);
}
cout << ans;
cerr<<endl<<endl<<"Time: "<<fixed<<setprecision(12)<<(long double)(clock()-clk)/CLOCKS_PER_SEC<<" ms"<<endl<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define all(x) (x).begin(),(x).end() // 昇順ソート
#define rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
int main(){
int a, b, c;
cin >> a >> b >> c;
swap(a, b);
swap(a, c);
printf("%d %d %d\n", a, b, c);
return 0;
} | 0 |
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;
//red:0 blue:1
signed main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
ll n;
string s;
cin>>n>>s;
vector<string>red(1<<n,""),blue(1<<n,"");
map<pair<string,string>,ll>mp;
for(int i=0;i<(1<<n);++i){//前半分全列挙
for(int j=0;j<n;++j){
if(i>>j&1){
red[i]+=string{s[n-1-j]};
}
else blue[i]+=string{s[n-1-j]};
}
//前半分について逆から読んだ赤、青と、後ろ半分についての青、赤が一致しているか調べる
string ope="",ope2="";
for(int j=0;j<n;++j){
if(i>>j&1){
ope+=string{s[n+j]};
}
else ope2+=string{s[n+j]};
}
mp[make_pair(ope,ope2)]++;
}
ll ans=0;
for(int i=0;i<(1<<n);++i){
ll x=mp[make_pair(blue[i],red[i])];
ans+=x;
}
cout<<ans<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
int main() {
int n, k;
cin >> n >> k;
vector<int> d(k,0);
rep(i,k) cin >> d[i];
while(1){
bool flag = false;
rep(i,k){
string s = to_string(n);
rep(j,s.size()) {
if ((int)s[j] - (int)'0' == d[i]) {
n++;
flag = true;
break;
}
}
if (flag) break;
}
if (!flag) {
cout << n << endl;
return 0;
}
}
} | 0 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define per(i,n) for(int i=(n)-1; i>=0; i--)
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
const int MOD = 1000000007;
int main(){
int H,W,A,B; cin>>H>>W>>A>>B;
rep(i,H){
rep(j,W){
cout << (((i<B)^(j<A))?1:0);
}
cout << endl;
}
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
using namespace std;
#define for0(a, c) for (int(a) = 0; (a) < (c); (a)++)
#define forA(a, b, c) for (int(a) = (b); (a) <= (c); (a)++)
#define forD(a, b, c) for (int(a) = (b); (a) >= (c); (a)--)
#define deb(x) cout<< #x << "=" << x <<endl
#define all(a) a.begin(),a.end()
#define re(x) cin>>x
#define readarr(a,n) for0(i,n) cin>>a[i]
#define mod 1000000007
#define INF 1000000000000000003
#define ff first
#define ss second
#define pb push_back
#define pob pop_back
#define mp make_pair
#define endl "\n"
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef unordered_map<int, int> mii;
typedef unordered_map<char, int> mci;
typedef unordered_set<int> usi;
int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;}
bool isPrime(int N){ for(int i=2;i*i<=N;++i){if(N%i==0) return false;}return true;}
void solve(){
int x,y,z;
re(x),re(y),re(z);
swap(x,y);
swap(x,z);
cout<<x<<" "<<y<<" "<<z;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
} | 0 |
#include <iostream>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int a, b, c;
cin >> a >> c >> b;
if ((a >= b && b >= c) || (a <= b && b <= c)) cout << "Yes\n";
else cout << "No\n";
return 0;
}
| #include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
// ===============================================================
using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
// ===============================================================
ll gcd(ll a, ll b) //最大公約数
{
if (a % b == 0)
{
return(b);
}
else
{
return(gcd(b, a % b));
}
}
ll lcm(ll a, ll b) //最小公倍数
{
return a * b / gcd(a, b);
}
ll box(double a) //doubleの切り捨て
{
ll b = a;
return b;
}
ll fff(double a) //doubleの四捨五入
{
ll b = a + 0.5;
return b;
}
ll sum(ll n) { //整数sまでの合計
if (n == 0) {
return 0;
}
int s = sum(n - 1);
return s + n;
}
bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
if (num < 2) return false;
else if (num == 2) return true;
else if (num % 2 == 0) return false;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2)
{
if (num % i == 0)
{
return false;
}
}
// 素数である
return true;
}
// ===============================================================
int main() {
ll a, b, c;
cin >> a >> b >> c;
vl e{ a + b,b + c,a + c };
sort(e.begin(), e.end());
cout << e[0];
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define mod 998244353
#define sz(v) (int)(v).size()
#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
ll add(ll a,ll b)
{
a%=M;
b%=M;
ll p = (a+b)%M;
return (p+M)%M;
}
ll mul(ll a,ll b)
{
a%=M;
b%=M;
ll p = (a*b)%M;
return (p+M)%M;
}
vector<ll> adj[100010];
ll dp1[100010],dp2[100010];
void dfs1(ll i,ll par)
{
ll j;
for(j=0;j<sz(adj[i]);j++)
{
ll x = adj[i][j];
if(x==par)
continue;
dp1[x] = dp1[i]+1;
dfs1(x,i);
}
return ;
}
void dfs2(ll i,ll par)
{
ll j;
for(j=0;j<sz(adj[i]);j++)
{
ll x = adj[i][j];
if(x==par)
continue;
dp2[x] = dp2[i]+1;
dfs2(x,i);
}
return ;
}
int main()
{
fastio;
ll i,j,n,a,b;
cin>>n>>a>>b;
for(i=0;i<n-1;i++)
{
ll u,v;
cin>>u>>v;
adj[u].pb(v);
adj[v].pb(u);
}
dp1[a]=0;
dfs1(a,0);
dp2[b]=0;
dfs2(b,0);
ll ma=-1e9,mi=1e9;
for(i=1;i<=n;i++)
{
if(dp1[i]==dp2[i])
mi=min(mi,dp1[i]);
if((dp2[i]>dp1[i])&&(dp2[i]>2))
{
// if((dp1[i]+dp2[i])%2)
// ma=max(dp2[i]-1,ma);
// else
ma=max(ma,dp2[i]-1);
}
// cout<<dp1[i]<<" "<<dp2[i]<<endl;
// cout<<ma<<endl;
}
if(mi!=1e9)
ma=max(ma,mi);
if(ma==-1e9)
ma=0;
cout<<ma<<endl;
return 0;
}
| #include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int mx = 100005;
int dtime = 0;
int n, m, par[mx], low[mx], start[mx];
vector<int> adj[mx], child[mx];
bool vis[mx];
set<int> art;
void dfs(int n, int p = -1) {
//printf("DFS %d from %d\n", n, p);
vis[n] = true;
par[n] = p;
child[p].pb(n);
start[n] = dtime++;
low[n] = start[n];
for (int h : adj[n]) {
if (!vis[h]) {
dfs(h, n);
// printf("Low[%d] = min(%d, %d) = %d\n", n, low[n], low[h], min(low[n], low[h]));
low[n] = min(low[h], low[n]);
if ((n == 0 && child[0].size() > 1) || (n != 0 && low[h] >= start[n])) {
art.insert(n);
}
} else if (h != p) {
low[n] = min(low[n], start[h]);
}
}
}
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v; cin >> u >> v;
adj[u].pb(v); adj[v].pb(u);
}
dfs(0);
for (int h : art) cout << h << endl;
}
| 0 |
#include<bits/stdc++.h>
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 Would
#define you
#define please
inline int getint_mae() {
char C = getchar_unlocked();
int A = C - '0';
while (isdigit(C = getchar())) A = A * 10 + C - '0';
return A;
}
const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
return *ci++;
}
inline int getint() {
int A = 0;
if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
return A;
}
const int dm = 1 << 21;
char dn[dm], *di = dn, dt;
inline void putint(int X) {
if (X == 0) {
*di++ = '0';
*di++ = '\n';
return;
}
int keta = 0;
char C[10];
while (X) {
*(C + keta) = '0' + X % 10;
X /= 10;
keta++;
}
for (int i = keta - 1; i >= 0; i--) *di++ = (*(C + i));
*di++ = '\n';
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N = getint_mae(), M = getint_mae(), Q = getint_mae();
char S[2001][2002];
rep(i, N + 1) S[i][0] = '0';
rep(i, M + 1) S[0][i] = '0';
rep1(i, N) fread_unlocked(S[i] + 1, 1, M + 1, stdin);
int B[2001][2001], C[2001][2001], D[2001][2001];
rep(i, N) {
rep(j, M) {
B[i + 1][j + 1] = B[i + 1][j] + B[i][j + 1] - B[i][j] + S[i + 1][j + 1] - '0';
C[i + 1][j + 1] = C[i + 1][j] + C[i][j + 1] - C[i][j] + ((S[i][j + 1] - '0') & (S[i + 1][j + 1] - '0'));
D[i + 1][j + 1] = D[i + 1][j] + D[i][j + 1] - D[i][j] + ((S[i + 1][j] - '0') & (S[i + 1][j + 1] - '0'));
}
}
rep(q, Q) {
int a = getint(), b = getint(), c = getint(), d = getint();
int kotae = B[c][d] - B[c][b - 1] - B[a - 1][d] + B[a - 1][b - 1] - C[c][d] + C[c][b - 1] + C[a][d] - C[a][b - 1] - D[c][d] + D[c][b] + D[a - 1][d] - D[a - 1][b];
putint(kotae);
}
fwrite_unlocked(dn, di - dn, 1, stdout);
Would you please return 0;
} | #include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<string, string> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
string s;
cin >> n >> s;
int m = 2*n;
string s1 = "", s2 = "";
rep(i,n) s1 += s[i];
rep(i,n) s2 += s[i+n];
ll ans = 0;
map<P, ll> mp;
rep(i,1<<n){
string sw = "", sv = "";
rep(j,n){
if(i>>j & 1) sw += s1[j];
else sv += s1[j];
}
reverse(sv.begin(), sv.end());
++mp[P(sw, sv)];
}
rep(i,1<<n){
string su = "", st = "";
rep(j,n){
if(i>>j & 1) su += s2[j];
else st += s2[j];
}
reverse(st.begin(), st.end());
ans += mp[P(st, su)];
}
cout << ans << endl;
return 0;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
template <typename T>
inline void readin(T &x) {
x = 0;
T fh = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
x *= fh;
}
inline void d_read(double &x) {
x = 0.0;
int fh = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
if (ch == '.') {
double num = 1.0;
ch = getchar();
for (; isdigit(ch); ch = getchar()) x = x + (num /= 10) * (ch ^ 48);
}
x *= fh;
}
template <typename T>
inline void wt(T x) {
if (x > 9) wt(x / 10);
putchar(x % 10 + 48);
}
template <typename T>
inline void writeln(T x, char c) {
if (x < 0) {
putchar('-');
x = -x;
}
wt(x);
putchar(c);
}
const int N = 2e5 + 5;
int a[N << 2], t[N << 2], tg[N << 2];
inline void up(int p) {
a[p] = min(a[p << 1], a[p << 1 | 1]);
t[p] = min(t[p << 1], t[p << 1 | 1]);
}
inline void work(int p, int l, int r, int k) {
a[p] = k;
t[p] = k + l;
tg[p] = k;
}
inline void build(int p, int l, int r) {
tg[p] = -1e9;
if (l == r) {
a[p] = -l;
t[p] = a[p] + l;
}
else {
int mid = l + r >> 1;
build(p << 1, l, mid);
build(p << 1 | 1, mid + 1, r);
up(p);
}
}
inline void down(int p, int l, int r) {
if (tg[p] != -1e9) {
int mid = l + r >> 1;
a[p << 1] = a[p << 1 | 1] = tg[p];
tg[p << 1] = tg[p << 1 | 1] = tg[p];
t[p << 1] = tg[p] + l;
t[p << 1 | 1] = tg[p] + mid + 1;
tg[p] = -1e9;
}
}
int sum;
inline void ask(int p, int l, int r, int pos) {
if (l == pos && pos == r) {
sum = a[p];
}
else {
down(p, l, r);
int mid = l + r >> 1;
if (pos <= mid) ask(p << 1, l, mid, pos);
else ask(p << 1 | 1, mid + 1, r, pos);
}
}
inline void modify(int p, int l, int r, int ql, int qr, int k) {
if (l >= ql && r <= qr) {
a[p] = k;
t[p] = a[p] + l;
tg[p] = k;
}
else {
down(p, l, r);
int mid = l + r >> 1;
if (ql <= mid) modify(p << 1, l, mid, ql, qr, k);
if (mid < qr) modify(p << 1 | 1, mid + 1, r, ql, qr, k);
up(p);
}
}
int n, m;
int main() {
readin(n); readin(m);
int x, y;
build(1, 1, m);
for (int i = 1; i <= n; i ++) {
readin(x); readin(y);
sum = 1e8;
if (x > 1) ask(1, 1, m, x - 1);
modify(1, 1, m, x, y, sum);
if (t[1] + i >= 1e8) puts("-1");
else writeln(t[1] + i, '\n');
}
return 0;
} | //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>
#include <climits>
#include <queue>
using namespace std;
//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);
int f(int n){
int x, y, z;
int ans = n;
for(int y=0;y*y<=n;++y){
for(int z=0;z*z*z<=n;++z){
if(y*y+z*z*z > n) break;
ans = min(ans, y+z+(n-y*y-z*z*z));
}
}
return ans;
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(false);
while(true){
int N; cin >> N; if(!N) break;
cout << f(N) << endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
const int MOD = 1e9 + 7;
const int INF = 9e18;
signed main(){
int N;
cin >> N;
multiset<int> A;
for (int i = 0; i < N; i++) {
int temp;
cin >> temp;
A.insert(temp);
}
int ans = 0;
while (!A.empty()) {
int base, key;
{
auto itr = A.end();
--itr;
base = *itr;
int count = 0;
int k = base;
while (k > 0) {
k /= 2;
++count;
}
key = (1<<count) - base;
A.erase(itr);
}
auto itr = A.find(key);
if (itr != A.end()) {
A.erase(itr);
++ans;
}
}
cout << ans << endl;
} | #define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;
//typedef modint998244353 mint;
const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9 + 5;
int main() {
int n;
cin >> n;
map<int, int> m;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
m[a]++;
}
int cnt = 0;
for (auto it = m.rbegin(); it != m.rend(); it++) {
ll p2 = 1;
ll num = it->first;
while (p2 <= num) {
p2 *= 2;
}
//cout << num << endl;
auto it1 = m.find(p2 - num);
if (it1 != m.end()) {
if (it1->first == num) {
cnt += it->second / 2;
}
else {
int c = min(it1->second, it->second);
it1->second -= c;
cnt += c;
if (it1->second == 0) {
m.erase(it1);
}
}
}
}
cout << cnt << endl;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;
double equal(double a, double b) {
return fabs(a - b) < DBL_EPSILON;
}
std::istream &operator>>(std::istream &in, set<string> &o) {
string a;
in >> a;
o.insert(a);
return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
ll a;
in >> a;
o.push(a);
return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;
int main() {
int n;
cin >> n;
vector<double> v(n);
rep(i, n) cin >> v[i];
double ave = accumulate(v.begin(), v.end(), 0.0) / n;
rep(i, n) v[i] = abs(v[i] - ave);
double target = *min_element(v.begin(), v.end());
int f = distance(v.begin(), find(v.begin(), v.end(), target));
cout << f << endl;
}
| #include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define int long long
const int N = 1e6;
int n;
int a[N], s;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i], s += a[i];
int ans = 0;
for (int i = 0; i < n; i++)
{
if (abs(a[i] * n - s) < abs(a[ans] * n - s)) ans = i;
}
cout << ans;
}
| 1 |
#include<iostream>
#include<algorithm>
#include<vector>
#define all(c) (c).begin(),(c).end()
using namespace std;
int mergecount(vector<int> &a) {
int count=0,n=a.size();
if (n>1){
vector<int>b(a.begin(),a.begin()+n/2);
vector<int>c(a.begin()+n/2,a.end());
count+=mergecount(b);
count+=mergecount(c);
for (int i=0,j=0,k=0;i<n;i++)
if (k == c.size())a[i]=b[j++];
else if (j == b.size())a[i]=c[k++];
else if (b[j]<=c[k])a[i]=b[j++];
else a[i]=c[k++],count+=n/2-j;
}
return count;
}
int main(void){
int n;
cin >> n;
vector<int>v(n);
for(int i=0;i<n;i++)cin >> v[i];
int cnt=mergecount(v);
sort(all(v));
for(int i=0;i<n;i++)cout << v[i] << (i<n-1?" ":"\n");
cout << cnt << endl;
return 0;
} | #include <iostream>
#include <iomanip>
#include <math.h>
#include <fstream>
#include <string>
#include <time.h>
#include <ctime>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cstdlib>
using namespace std;
void trace(int A[],int N){
for(int i=0;i<N;i++){
if(i>0)cout << ' ';
cout << A[i];
}
cout << endl;
}
void bubbleSort(int A[],int N){
bool flag=1;
int count=0;
while(flag){
flag=0;
for(int j=N-1;j>0;j--){
if(A[j]<A[j-1]){
int tmp;
tmp = A[j];
A[j] = A[j-1];
A[j-1] = tmp;
flag = 1;
count++;
}
}
}
trace(A,N);
cout << count;
cout << endl;
}
int main(){
int N;
int A[100];
cin >> N;
for(int i=0;i<N;i++){
cin >> A[i];
}
bubbleSort(A,N);
return 0;
} | 1 |
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
const int mx=1000010;
const ll mod=1e9+7;
int main(){
ll n,m,d;
cin >> n >> m >> d;
ld ans = 2 * (n-d) * (m-1);
ans /= n;
ans /= n;
if(d==0) ans/=2;
cout << fixed << setprecision(10) << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
long long COM(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 h,w,k;
cin>>h>>w>>k;
COMinit();
ll ans=0;
ll H=(h-1)*h*(h+1)/6%inf*w%inf*w%inf;
H*=COM(h*w-2,k-2);
H%=inf;
ll W=(w-1)*w*(w+1)/6%inf*h%inf*h%inf;
W*=COM(h*w-2,k-2);
W%=inf;
ans+=H+W;
ans%=inf;
cout <<ans;
// 計算例
// cout << COM(100000, 50000) << endl;
// your code goes here
return 0;
} | 0 |
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
ll gcd(ll a,ll b){
if(b == 0) return a;
return gcd(b , a % b);
}
const ll MOD = 1000000007;
const ll MAX = 2000001;
ll mod(ll a){
return a % MOD;
}
ll lcm(ll a,ll b){
return (a*b)/gcd(a,b);
}
ll fac[MAX], finv[MAX], inv[MAX];
void nCrprep() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll 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;
}
}
ll nCr(ll n, ll r){
if (n < r) return 0;
if (n < 0 || r < 0) return 0;
return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}
ll nCrcheep(ll n,ll r){
if(r == 0) return 1;
else if(r == 1) return n;
else return nCrcheep(n-1,r-1)*n/r;
}
vector<pair<ll,ll>> prime_factorize(ll n){
vector<pair<ll,ll>> res;
for(ll i=2; i*i <= n; i++){
if(n % i != 0) continue;
ll ex = 0;
while(n % i == 0){
ex++;
n /= i;
}
res.push_back({i,ex});
}
if(n != 1) res.push_back({n,1});
return res;
}
int main(){
ll sx,sy,tx,ty; cin >> sx >> sy >> tx >> ty;
ll dx = tx - sx; ll dy = ty - sy;
cout << string(dx,'R') << string(dy,'U') << string(dx,'L') <<
string(dy,'D') << 'D' << string(dx+1,'R') <<
string(dy+1,'U') << 'L' << 'U' << string(dx+1,'L') <<
string(dy+1,'D') << 'R' << endl;
}
| #include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll mod = 1000000007;
ll fact[200010];
ll power(ll x, ll y, ll p)
{
ll res = 1;
x = x % p;
while (y > 0)
{
if (y & 1)
res = (res*x) % p;
y = y>>1;
x = (x*x) % p;
}
return res;
}
ll modInverse(ll n, ll p)
{
return power(n, p-2, p);
}
void init(){
fact[0] = 1;
for(int i=1;i<=200005; i++){
fact[i] = (fact[i-1]*i)%mod;
}
}
ll sol(ll r, ll d){
ll ans = fact[r+d];
ans = (ans*modInverse(fact[r],mod))%mod;
ans = (ans*modInverse(fact[d],mod))%mod;
return ans;
}
int main() {
init();
int h,w,a,b;
cin>>h>>w>>a>>b;
ll ans = 0;
ll t;
for(int i=0; i<h-a; i++){
t = 1;
t = (t*sol(i,b-1))%mod;
t = (t*sol(w-b-1,h-i-1))%mod;
// cout<<i<<":"<<b<<" "<<w-b-1<<":"<<h-i-1<<'\n';
ans = (ans + t)%mod;
}
cout<<ans;
return 0;
}
| 0 |
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 200010;
int n, ans;
int read()
{
int x = 0, w = 1;
char ch = 0;
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + (ch - '0');
ch = getchar();
}
return x * w;
}
inline void write(int x)
{
static int sta[35];
int top = 0;
do {
sta[top++] = x % 10, x /= 10;
} while (x);
while (top) putchar(sta[-- top] + 48);
}
signed main()
{
n = read();
ans = (n - 2) * 180;
write(ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
signed main()
{
cin.tie( 0 ); ios::sync_with_stdio( false );
ll n; cin>>n;
cout<<180*(n-2)<<endl;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<string> S;
int black = 0;
int white = 0;
int INF = 1001001001;
int main() {
int H, W;
cin >> H >> W;
for(int i = 0; i < H; ++i) {
string s;
cin >> s;
S.push_back(s);
}
for(int i = 0; i < H; ++i) {
for(int j = 0; j < W; ++j) {
if(S[i][j] == '#') ++black;
else ++white;
}
}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int dist[100][100];
queue<pair<int, int>> Q;
Q.push(make_pair(0, 0));
for(int i = 0; i < 100; ++i) {
for(int j = 0; j < 100; ++j) {
dist[i][j] = INF;
}
}
dist[0][0] = 0;
while(Q.size()) {
auto q = Q.front(); Q.pop();
if(q.first == W -1 && q.second == H -1) break;
for(int i = 0; i < 4; ++i) {
int nx = q.first + dx[i];
int ny = q.second + dy[i];
if(0 <= nx && nx < W && 0 <= ny && ny < H && S[ny][nx] != '#' && dist[nx][ny] == INF) {
Q.push(make_pair(nx, ny));
dist[nx][ny] = dist[q.first][q.second] + 1;
}
}
}
int g = dist[W-1][H-1];
if(g == INF) {
cout << -1 << endl;
return 0;
}
cout << white - g -1 << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
using i64 = int64_t;
int main(){
int n;
cin >> n;
string s;
cin >> s;
int q;
cin >> q;
vector<int> query;
for(int i=0;i<q;++i){
int k;
cin >> k;
query.push_back(k);
}
vector<int> cumsum_c(n+1, 0), cumsum_m(n+1, 0);
vector<pair<int, int>> idx_c;
vector<pair<char, int>> idx_dc;
for(int i=0;i<n;++i){
cumsum_c[i+1] = cumsum_c[i];
cumsum_m[i+1] = cumsum_m[i];
if(s[i] == 'D'){
idx_dc.emplace_back('D', i);
}else if(s[i] == 'M'){
cumsum_m[i+1]++;
}else if(s[i] == 'C'){
cumsum_c[i+1]++;
idx_c.emplace_back(i, (int)idx_dc.size());
idx_dc.emplace_back('C', i);
}
}
for(auto k: query){
i64 ans = 0, num_c = 0, num_d = 0;
vector<int> imos(idx_dc.size());
for(int i=0;i<idx_dc.size();++i){
if(idx_dc[i].first == 'D'){
if(i > 0){
ans += num_c * (cumsum_m[idx_dc[i].second]-cumsum_m[idx_dc[i-1].second+1]);
}
int valid = -1, invalid = (int)idx_c.size();
while(invalid-valid > 1){
int mid = (valid + invalid) / 2;
if(idx_c[mid].first < idx_dc[i].second + k)valid = mid;
else invalid = mid;
}
if(valid < 0)continue;
i64 c = cumsum_c[idx_c[valid].first+1] - cumsum_c[idx_dc[i].second];
//cerr << c << endl;
c = max(c, (i64)0);
num_c += c;
num_d++;
imos[idx_c[valid].second]++;
//cerr << num_c << endl;
}else{
if(i == 0)continue;
ans += num_c * (cumsum_m[idx_dc[i].second]-cumsum_m[idx_dc[i-1].second+1]);
num_c -= num_d;
num_d -= imos[i];
}
//cerr << ans << endl;
}
cout << ans << endl;
}
return 0;
} | 0 |
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int data[100];
int main(){
int n;
scanf("%d",&n);
for(int i = 0; i < n * (n - 1) / 2; i++){
int b[4];
for(int k=0;k<4;k++) scanf("%d",&b[k]);
if(b[2]>b[3]) data[b[0]-1]+=3;
if(b[2]<b[3]) data[b[1]-1]+=3;
if(b[2]==b[3]){ data[b[0]-1]++; data[b[1]-1]++; }
}
for(int i=0;i<n;i++){
int res=1;
for(int j=0;j<n;j++){
if(data[i]<data[j]) res++;
}
printf("%d\n",res);
}
} | #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
int n;
cin>>n;
vector<int>in(n);
rep(i,n*(n-1)/2){
int a,b,c,d;
cin>>a>>b>>c>>d;
a--;b--;
if(c==d){in[a]++;in[b]++;}
else if(c>d)in[a]+=3;
else in[b]+=3;
}
//rep(i,n)cout<<in[i]<<endl;
int num=1;
vector<int>out(n);
while(1){
int maxi=-1;
rep(i,n)if(!out[i])maxi=max(maxi,in[i]);
if(maxi==-1)break;
int co=0;
rep(i,n)if(maxi==in[i]){co++;out[i]=num;in[i]=-2;}
num+=co;
}
rep(i,n)cout<<out[i]<<endl;
} | 1 |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[309][309][309],A[309],S[309][309][309];
ll mod = 998244353;
void admod(ll &x, ll y){
x = (x +y) % mod;
}
main(){
string s;
ll k;
cin >> s >> k;
ll n = s.size();
if(k > n) k = n;
vector<ll> A;
ll o = 0;
for(ll i = 0; i < n; i++){
if(s[i] == '1') o++;
else A.push_back(o), o =0;
}
A.push_back(o);
ll m = A.size();
reverse(A.begin(),A.end());
dp[0][0][0] = 1;
for(ll i = 0; i <= m; i++){
for(ll s = 0; s <= k; s++)
for(ll j = k; j >=0; j--)
admod(S[i][s][j], S[i][s][j+1]);
for(ll car = 0; car <= k; car ++){
for(ll pl = 0; car + pl <= k; pl++){
admod(dp[i][car][pl], S[i][car+pl][car]);
if(i < m){
admod(S[i+1][car+pl][car] , dp[i][car][pl]);
for(ll j = 1; j <= A[i]; j++)
admod(dp[i+1][car + j][pl], dp[i][car][pl]);
}
}
}
}
ll ans = 0;
for(ll i = 0; i <= k; i++)
admod(ans, dp[m][0][i] );
cout<<ans<<endl;
}
| #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void){
int a, b, h = 100, w = 100;
string s[100];
char wht = '.', blk = '#';
cin >> a >> b;
if(a > b){
int t = a;
a = b;
b = t;
wht = '#';
blk = '.';
}
for(int i=0;i<h;i++){
s[i] = string(w, wht);
}
for(int i=1;i<h&&b>0;i+=4){
for(int j=1;j<w&&b>0;j+=4){
for(int k=-1;k<=1;k++){
for(int l=-1;l<=1;l++){
s[i+k][j+l] = blk;
}
}
b--;
}
}
a--;
for(int i=1;i<h&&a>0;i+=4){
for(int j=1;j<w&&a>0;j+=4){
s[i][j] = wht;
a--;
}
}
cout << h << " " << w << endl;
for(int i=0;i<h;i++){
cout << s[i] << endl;
}
}
| 0 |
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;
const int SIZE=17;
const ll MOD=1e9+7;
void add(ll &lhs,ll rhs){
lhs=(lhs+rhs)%MOD;
}
int main(){
int n;
cin>>n;
int xyz[3];
for(int i=0;i<3;i++) cin>>xyz[i];
vector<vector<ll>> dp(n+1,vector<ll>(1<<SIZE));
dp[0][(1<<SIZE)-1]=1;
vector<int> isAccept(1<<SIZE);
for(int bit=0;bit<(1<<SIZE);bit++){
int st=0;
int buf=0;
for(int i=0;i<SIZE;i++){
buf++;
if(!((bit>>i)&1) && xyz[st]==buf){
st++;
buf=0;
if(st==3){
isAccept[bit]=true;
break;
}
}
}
}
vector<ll> pow10(n);
pow10[0]=1;
for(int i=0;i+1<n;i++) pow10[i+1]=pow10[i]*10%MOD;
ll res=0;
int mask=(1<<SIZE)-1;
for(int i=0;i<n;i++){
for(int bit=0;bit<(1<<SIZE);bit++){
if(dp[i][bit]==0) continue;
for(int v=1;v<=7;v++){
int nex=(bit<<v)+(1<<(v-1))-1;
nex&=mask;
add(dp[i+1][nex],dp[i][bit]);
}
add(dp[i+1][mask],3*dp[i][bit]);
}
for(int bit=0;bit<(1<<SIZE);bit++){
if(isAccept[bit]){
ll r=pow10[n-1-i];
res+=r*dp[i+1][bit];
res%=MOD;
dp[i+1][bit]=0;
}
}
}
cout<<res<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int n,x,y,z,mx,ji;
const long long mod=1e9+7;
long long ans,dp[45][1000010];
int main()
{
scanf("%d%d%d%d",&n,&x,&y,&z);
ans=1;
for(int i=1;i<=n;++i)
ans=ans*10%mod;
mx=(1<<(x+y+z))-1;
ji=(1<<(x+y+z-1));
ji|=(1<<(y+z-1));
ji|=(1<<(z-1));
dp[0][0]=1;
for(int i=1;i<=n;++i)
{
for(int j=0;j<=mx;++j)
{
if(dp[i-1][j]==0)
continue;
for(int k=1;k<=10;++k)
{
int cur=(j<<k)|(1<<(k-1));
cur&=mx;//只取后(x+y+z)位
if((cur&ji)==ji)
continue;
dp[i][cur]=(dp[i][cur]+dp[i-1][j])%mod;
}
}
}
for(int i=0;i<=mx;++i)
ans=(ans-dp[n][i]+mod)%mod;
printf("%lld\n",ans);
return 0;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
bool compare(pair<int, int> a, pair<int, int> b) {
if(a.first != b.first){
return a.first < b.first;
}else{
return a.second < b.second;
}
}
// 入力
int main() {
ll N;
cin >>N;
vector<ll> A(N);
rep(i,N){
cin >> A[i];
}
ll ans=0;
vector<ll> cnt(61);
rep(i,61){
rep(j,N){
if((A[j]>>i)&1){
cnt[i]++;
}
}
}
rep(i,61){
ll ml = cnt[i]*(N-cnt[i]);
rep(j,i){
ml = (ml*2)%mod;
}
ans = (ans+ml)%mod;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
const int MOD=1000*1000*1000+7,N=300005;
using namespace std;
typedef long long ll;
ll f[N];
ll h,w,a,b;
ll P(ll a,ll b){
ll ans=1;
while(b){
if(b%2)ans=(ans*a)%MOD;
a=(a*a)%MOD;
b/=2;
}
return ans;
}
ll WAYS(ll n,ll k){
ll cnt=f[n];
cnt=(cnt*P(f[k],MOD-2))%MOD;
cnt=(cnt*P(f[n-k],MOD-2))%MOD;
return cnt;
}
int main()
{f[0]=1;
for(int i=1;i<N;i++)f[i]=(f[i-1]*i)%MOD;
cin>>h>>w>>a>>b;
ll ans=0;
for(int i=b;i<w;i++){
ll c=h-a;
ll v1=WAYS(c+i-1,c-1);
ll v2=WAYS(a+w-i-2,a-1);
ans=(ans+v1*v2)%MOD;
}
cout<<ans<<'\n';
return 0;
}
| 0 |
#include<bits/stdc++.h>
#define MOD 1000000007
#define mp make_pair
#define ll long long
#define pb push_back
#define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug cout<<"Debugging.."<<endl
using namespace std;
int main()
{
faster;
ll int n;
cin>>n;
int a=pow(n,2);
int b=pow(n,3);
cout<<a+b+n;
}
| #include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
using ll = long long;
using ull = unsigned long long;
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 ll mod = 1e9+7;
void chmod(ll &M){
if(M >= mod) M %= mod;
else if(M < 0){
M += (abs(M)/mod + 1)*mod;
M %= mod;
}
}
ll modpow(ll x, ll n){
if(n==0) return 1;
ll res=modpow(x, n/2);
if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
if (b == 0) return a;
else return GCD(b, a % b);
}
using namespace std;
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
int main()
{
int a;
cin >> a;
cout << a + a*a + a*a*a << endl;
}
| 1 |
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
using namespace std;
const int maxn = 100005;
int a[maxn], n;
inline int gcd(int a, int b) {
return !b ? a : gcd(b, a % b);
}
int solve() {
int flag1 = 0, cnt1 = 0, cnt0 = 0;
rep (i, 1, n)
if (a[i] & 1) {
flag1 |= (a[i] == 1);
cnt1++;
}
else cnt0++;
if (cnt0 & 1) return 1;
if (cnt1 != 1) return 0;
if (flag1) return cnt0 & 1;
rep (i, 1, n)
if (a[i] & 1) a[i]--;
int g = a[1];
rep (i, 2, n)
g = gcd(g, a[i]);
rep (i, 1, n)
a[i] /= g;
return solve() ^ 1;
}
int main() {
scanf("%d", &n);
rep (i, 1, n) scanf("%d", &a[i]);
puts(solve() ? "First" : "Second");
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
void addWordCount(const vector<string>& cards, map<string, int>& wordCount);
void subWordCount(const vector<string>& cards, map<string, int>& wordCount);
int getMaxValue(const map<string, int>& wordCount);
int main() {
int numOfBlueCard = 0;
cin >> numOfBlueCard;
vector<string> blueCards;
for (int i = 0; i < numOfBlueCard; ++i) {
string blueCard;
cin >> blueCard;
blueCards.push_back(blueCard);
}
int numOfRedCard = 0;
cin >> numOfRedCard;
vector<string> redCards;
for (int i = 0; i < numOfRedCard; ++i) {
string redCard;
cin >> redCard;
redCards.push_back(redCard);
}
map<string, int> wordCount;
addWordCount(blueCards, wordCount);
subWordCount(redCards, wordCount);
auto maxValueWord = std::max_element(wordCount.begin(), wordCount.end(),
[](const pair<string, int>& p1, const pair<string, int>& p2) {
return p1.second < p2.second; });
int maxValue = 0;
if(maxValueWord->second >= 0) {
maxValue = maxValueWord->second;
}
cout << maxValue << endl;
}
void addWordCount(const vector<string>& cards, map<string, int>& wordCount) {
for (string card : cards) {
++wordCount[card];
}
}
void subWordCount(const vector<string>& cards, map<string, int>& wordCount) {
for (string card : cards) {
--wordCount[card];
}
}
int getMaxValue(const map<string, int>& wordCount) {
int maxValue = 0;
for (auto word : wordCount) {
if (word.second > maxValue) maxValue = word.second;
}
return maxValue;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n); (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define rev(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c) for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define mp make_pair
#define pb push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }
#define INF 1000000000
#define MOD 1000000007
#define EPS 1E-12
int dx;
int main()
{
while(cin >> dx){
int res = 0;
for(int d=dx; d<600; d+=dx) res += dx * d * d;
cout << res << endl;
}
return 0;
} | #include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int f(int);
int integral(int);
int main(void) {
int a, b;
while(cin >> a >> b) {
cout << integral(a) << endl;
cout << integral(b) << endl;
}
return 0;
}
int integral(int d){
int n = 600 / d;
int sum = 0;
for (int i = 1; i < n; i++) {
sum = sum + f(d * i) * d;
}
return sum;
}
int f(int a) {
return a * a;
} | 1 |
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
vector<char> init(){
vector<char> data;
for(int c='a'; c<='z'; ++c) data.push_back(c);
for(int c='A'; c<='Z'; ++c) data.push_back(c);
return data;
}
char solve(const char& c, int& x, const vector<char>& data){
for(int i=0; i<data.size(); ++i){
if(data[i] == c){
int j = i-x;
if(j < 0) j += data.size();
return data[j];
}
}
}
int main(){
int n;
string s;
vector<char> s_name = init();
while(1){
cin >> n;
if(!n) break;
vector<int> data(n, 0);
for(int i=0; i<n; ++i) cin >> data[i];
cin >> s;
for(int i=0, j=0; i<s.size(); ++i){
cout << solve(s[i], data[j], s_name);
++j;
if(j == data.size()) j=0;
}
cout << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
struct RUQ{
ll size;
ll *tree;
vi history;
RUQ(ll sz){
ll logsize; for(logsize=0;(1ll<<logsize)<=sz;logsize++);
size=(1ll<<logsize);
tree=new ll[size*2-1]; REP(i, size*2-1) tree[i]=0;
}
void update(ll s,ll t,ll x){
ll id=history.size();
updatesub(s,t,0,size,0,id);
history.push_back(x);
}
void updatesub(ll s,ll t,ll l,ll r,ll k,ll id){
if(r<=s||t<=l||l>=r) return;
if(l+1==r) {tree[k]=id; return;}
if(s<=l&&r<=t) {tree[k]=id; return;}
ll mid=(l+r+1)/2;
updatesub(s,t,l,mid,k*2+1,id);
updatesub(s,t,mid,r,k*2+2,id);
}
ll find(ll i){
ll k=size+i-1;
ll recent=tree[k];
while(k>0){
k=(k-1)/2;
recent=max(recent,tree[k]);
}
return history[recent];
}
};
int main(){
ll n,q; cin>>n>>q;
RUQ ruq(n);
ruq.update(0,n,(1ll<<31)-1);
REP(i,q){
ll com;cin>>com;
if(com==0) {ll s,t,x; cin>>s>>t>>x; ruq.update(s,t+1,x);}
else {ll i; cin>>i; cout<<ruq.find(i)<<endl;}
}
} | 0 |
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
long long h,w,n;
cin>>h>>w>>n;
if(h>w){
cout<<ceil((double)n/h)<<endl;
}else{
cout<<ceil((double)n/w)<<endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main(){
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
string s;
int dx = x2 - x1;
int dy = y2 - y1;
for(int i=0; i<dy; ++i) s += 'U';
for(int i=0; i<dx; ++i) s += 'R';
for(int i=0; i<dy; ++i) s += 'D';
for(int i=0; i<dx+1; ++i) s += 'L';
for(int i=0; i<dy+1; ++i) s += 'U';
for(int i=0; i<dx+1; ++i) s += 'R';
s += "DR";
for(int i=0; i<dy+1; ++i) s += 'D';
for(int i=0; i<dx+1; ++i) s += 'L';
s += 'U';
cout << s << endl;
} | 0 |
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
int main(){
/*??£???????????????????????????
int a[2];
cin >> a[1] >> a[2];
cout << "[+] " << a[1] + a[2] << endl;
cout << "[-] " << a[1] - a[2] << endl;
cout << "[*] " << a[1] * a[2] << endl;
cout << "[/] " << a[1] / a[2] << endl;
*/
int a;
while(cin >> a){
if(a == 0){break;}
int ans[10] = {0,0,0,0,0,0,0,0,0,0};
string ans2[10] = {"","","","","","","","","",""};
int p;
for(int i = 1;a >= i;i++){
cin >> p;ans[p]++;
}
for(int i = 0;9 >= i;i++){
if(ans[i] == 0){
ans2[i] = "-";
}else{
for(int ii = 1;ans[i] >= ii;ii++){
ans2[i] += "*";
}
}
cout << ans2[i] << endl;
}
}
} | #include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;
using namespace std;
typedef long long ll;
template <typename T>
struct bit{
int n;
vector<T> data;
bit(int n_){
n = 1;
while(n < n_) n *= 2;
data = vector<T>(n+1);
for(int i = 0; i <= n; i++) data[i] = 0;
}
T sum(int i){
T ret = 0;
while(i > 0){
ret += data[i];
i -= i&-i;
}
return ret;
}
void add(int i, T x){
while(i <= n){
data[i] += x;
i += i&-i;
}
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
int N, Q; cin >> N >> Q;
bit<ll> bt(N);
for(int i = 1; i <= N; i++){
ll a; cin >> a;
bt.add(i, a);
}
for(int i = 0; i < Q; i++){
int t; cin >> t;
if(t == 0){
int p; ll x; cin >> p >> x; p++;
bt.add(p, x);
}else{
int l, r; cin >> l >> r; r;
cout << bt.sum(r)-bt.sum(l) << endl;
}
}
} | 0 |
#include "bits/stdc++.h"
using namespace std;
set<int>S;
bool f(int n) {
while (n >0) {
int num = n % 10;
n /= 10;
if (S.count(num) == 1) {
return false;
}
}
return true;
}
int main() {
int N, K;
cin >> N >> K;
for (int i = 0;i<K;++i) {
int num;
cin >> num;
S.insert(num);
}
while (true) {
if (f(N)) {
break;
}
N++;
}
cout << N <<endl;
return 0;
} | #include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
distance(v.begin(), upper_bound(v.begin(), v.end(), x))
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;
ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
/* Macros reg. ends here */
const ll INF = 1LL << 50;
int main() {
// ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
ll n, k;
cin >> n >> k;
unordered_map<char, ll> ngl;
rep(i, k){
char d;
cin >> d;
ngl[d]++;
}
repLRE(i, n, 99999){
string str = to_string(i);
bool ok = true;
for(char c : str){
if(ngl.count(c)) {
ok = false;
break;
}
}
if(ok){
cout << i << endl;
return 0;
}
}
return 0;
}
| 1 |
#include <iostream>
using namespace std;
int main()
{
int m, d;
while (1){
cin >> m >> d;
if (m == 0){
break;
}
if (m == 2){
d += 31;
}
if (m == 3){
d += 60;
}
if (m == 4){
d += 91;
}
if (m == 5){
d += 121;
}
if (m == 6){
d += 152;
}
if (m == 7){
d += 182;
}
if (m == 8){
d += 213;
}
if (m == 9){
d += 244;
}
if (m == 10){
d += 274;
}
if (m == 11){
d += 305;
}
if (m == 12){
d += 335;
}
if (d % 7 == 0){
cout << "Wednesday";
}
else if (d % 7 == 1){
cout << "Thursday";
}
else if (d % 7 == 2){
cout << "Friday";
}
else if (d % 7 == 3){
cout << "Saturday";
}
else if (d % 7 == 4){
cout << "Sunday";
}
else if (d % 7 == 5){
cout << "Monday";
}
else {
cout << "Tuesday";
}
cout << endl;
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
int main() {
int n;
cin >> n;
cout << 0 << endl;
string s;
cin >> s;
if (s == "Vacant") return 0;
vector<string> v(n);
v[0] = s;
int l = 0;
int r = n;
int p = (l+r)/2;
cout << p << endl;
while (cin >> s, s != "Vacant") {
v[p] = s;
int x = p - l - 1;
int y = r - p - 1;
if ((v[l] == s && x % 2 == 0) || (v[l] != s && x % 2 == 1)) {
r = p;
p = (l+r)/2;
} else {
l = p;
p = (l+r)/2;
}
cout << p << endl;
}
} | 0 |
#include <iostream>
#include <cstring>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
using namespace std;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
string fld[12];
void dfs(int x,int y){
fld[x][y]='0';
rep(i,4){
int sx=x+dx[i],sy=y+dy[i];
if(sx>=0&&sx<12&&sy>=0&&sy<12)if(fld[sx][sy]=='1')dfs(sx,sy);
}
}
int main(){
while(cin>>fld[0]){
int ans=0;
FOR(i,1,12)cin>>fld[i];
rep(i,12)rep(j,12){
if(fld[j][i]=='1'){
ans++;
dfs(j,i);
}
}
cout<<ans<<endl;
}
} | #define _CRT_SECURE_NO_WARNINGS
#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
using namespace std;
queue<int> q;
list<int> l;
int *map = new int[12 * 12 * 20];
static int count;
void loop(int i){
map[i] = 0;
if (i / 12 > 0) {
if (map[i - 12] == 1) {
loop(i - 12);
}
}
if (i / 12 < 11) {
if (map[i + 12] == 1) {
loop(i + 12);
}
}
if (i % 12 > 0) {
if (map[i - 1] == 1) {
loop(i - 1);
}
}
if (i % 12 < 11) {
if (map[i + 1] == 1) {
loop(i + 1);
}
}
}
int main(int argc, char **argv)
{
int count = 0;
string str;
while (cin >> str) {
for (int j = 0; j < 12; j++) {
map[j] = str[j] - '0';
}
for (int i = 1; i < 12 && cin >> str; i++) {
for (int j = 0; j < 12; j++) {
map[i * 12 + j] = str[j] - '0';
}
}
count = 0;
for (int i = 0; i < 12 * 12; i++) {
if (map[i] == 1) {
loop(i);
count++;
}
}
cout << count << endl;
}
return 0;
} | 1 |
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
const ll INF = 1e18;
int main() {
int N, ans = 0;
cin >> N;
vector<int> A(N);
map<int, int> mp;
rep(i, N) {
cin >> A[i];
mp[A[i]]++;
}
sort(A.begin(), A.end());
for (int i = N - 1; i >= 0; i--) {
if (mp[A[i]] == 0) continue;
mp[A[i]]--;
int b = 1;
while (b <= A[i]) b += b;
int j = lower_bound(A.begin(), A.end(), b - A[i]) - A.begin();
if (A[j] != b - A[i]) continue;
if (mp[A[j]] == 0) continue;
mp[A[j]]--;
ans++;
}
cout << ans << "\n";
} | #include <bits/stdc++.h>
// #define int long long
#define Matrix vector<vector<int> >
// #define Matrix vector<vector<int> >
#define double long double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define td(v) v.begin(),v.end()
#define tdr(v) v.rbegin(),v.rend()
#define endl "\n"
#define Matrix vector<vector<int> >
using namespace std;
const int MOD = 1e9+7;
const long long INF = 5e18;
const double pi = acos(-1.0);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
inline long long mod(long long n, long long m){
long long ret = n%m;
if(ret < 0) ret += m;
return ret;
}
double rad(double x){
return x*pi/180.0;
}
bool isleft(pair<int,int> a, pair<int,int> b, pair<int,int> c){
int det = (b.first-a.first)*(c.second-a.second) - (c.first-a.first)*(b.second-a.second);
if(det>=0) return true;
if(det<0) return false;
return false;
}
int exp(int a, int b){
int result = 1;
while (b > 0){
if (b & 1)
result = mod(result*a,MOD);
b >>= 1;
a = mod(a*a,MOD);
}
return result;
}
double memo[321][321][321];
int vet[321];
int n;
double dp(int t, int d, int u){
if(t+d+u==0) return 0;
double &x = memo[t][d][u];
if(x!=-1) return x;
x = 0;
if(t>0)
x+=t*dp(t-1,d+1,u);
if(d>0)
x+=d*dp(t,d-1,u+1);
if(u>0){
x+=u*dp(t,d,u-1);
}
x/=(t+d+u)*1.0;
x+=n*1.0/(t+d+u);
return x;
}
void solve(){
cin>>n;
int q[4] = {0,0,0};
for(int i=0;i<n;i++){
cin>>vet[i];
q[vet[i]]++;
}
for(int i=0;i<321;i++)
for(int j=0;j<321;j++)
for(int k=0;k<321;k++)
memo[i][j][k]=-1;
cout<<fixed<<setprecision(13);
cout<<dp(q[3],q[2],q[1])<<endl;
}
signed main(){
fastio;
int t=1;
// cin>>t;
while(t--)
solve();
}
| 0 |
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxn = 300111;
char s[maxn];
int n;
int dp[maxn][3][3];
void upd(int &x, int v) {x=(x+v)%mod;}
int main()
{
scanf("%s", s);
n = strlen(s);
dp[0][0][0] = 1;
for (int i=0; i<n; i++)
{
for (int x=0; x<3; x++)
{
for (int y=0; y<3; y++)
{
int cur = dp[i][x][y];
if (!cur) continue;
for (int t=0; t<2; t++)
{
if (s[i]!='?'&&s[i]-'0'!=t) continue;
int nx, ny;
if (x==2) nx=2, ny=0;
else
{
if (t==0) nx=x, ny=y+1==3?1:y+1;
else
{
if (y==0) nx=x+1, ny=0;
else nx=x, ny=y-1;
}
}
upd(dp[i+1][nx][ny], cur);
}
}
}
}
int ans = 0;
upd(ans, dp[n][2][0]);
upd(ans, dp[n][1][0]);
upd(ans, dp[n][0][0]);
cout<<ans<<endl;
return 0;
}
| #include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>
// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>
typedef long long LL;
//typedef long double LD;
using namespace std;
#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
int main() {
int n;
cin >> n;
vector<LL> a(n);
for(int i=0; i<n; i++){
cin >> a[i];
}
LL ans=1;
vector<LL> rgb(3, 0);
for(int i=0; i<n; i++){
LL tmp=0;
for(int j=0; j<3; j++){
if(a[i]==rgb[j]){
tmp++;
}
}
ans=(ans*tmp)%MOD;
for(int j=0; j<3; j++){
if(a[i]==rgb[j]){
rgb[j]++;
break;
}
}
}
//for(int i=0; i<3; i++){
// cout << rgb[i] << endl;
//}
cout << ans << endl;
return 0;
} | 0 |
#include <iostream>
#include <string>
typedef long long ll;
std::string alphabet = "abcdefghijklmnopqrstuvwxyz";
ll N;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
std::cin >> N;
std::string ans = "";
while (N) {
N--;
ans = alphabet[N % 26] + ans;
N /= 26;
}
std::cout << ans << "\n";
return 0;
}
| #include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long ll;
bool g(ll a,ll b){
return a>b;
}
int main(){
string S;
cin>>S;
set<char> s;
if(S.length()<26){
for(ll i=0;i<S.length();++i){
s.insert(S[i]);
}
cout<<S;
for(ll i=0;i<26;++i){
if(s.count('a'+i)==0){
cout<<char('a'+i);
break;
}
}
}else{
// string p=S;
// next_permutation(p.begin(),p.end());
// cout<<S<<endl;
// cout<<p<<endl;
s.insert(S[S.length()-1]);
for(ll i=S.length()-2;i>=0;--i){
s.insert(S[i]);
if(S[i]<S[i+1]){
S[i]= *s.upper_bound(S[i]);
S=S.substr(0,i+1);
cout<<S;
return 0;
}
}
cout<<-1;
}
} | 0 |
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
using namespace std;
int main() {
double x1, y1, x2, y2, num, ans = 0, dou = 1, xx;
cin >> x1 >> y1 >> x2 >> y2;
num = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);
while (dou < num) {
dou *= 10;
}
xx = dou;
for (int i = 0; i < 100; i++) {
for (int j = 0; j < i; j++) {
dou *= 0.1;
}
if (dou < 0.000001)break;
for (int j = 0; j < 10; j++) {
ans += dou;
//cout << ans << " " << j << " " << dou << endl;
if (ans*ans > num) {
ans -= dou;
break;
}
}
dou = xx;
}
printf("%f\n", ans);
//cout << ans;
return 0;
} | #include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
using namespace std;
int main() {
double x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
printf("%.7f \n", sqrt(pow((x2-x1), (double)2) + pow((y2-y1), (double)2)));
} | 1 |
#include <cstdio>
int n, sum, p[3];
bool f;
int main(){
while(scanf("%d", &n) != EOF){
if(n == 0) break;
for(int i = 0; i < n; i++){
f = false;
scanf("%d %d %d", &p[0], &p[1], &p[2]);
sum = p[0] + p[1] + p[2];
for(int j = 0; j < 3; j++)
if(p[j] == 100){
printf("A\n");
f = true;
break;
}
if(f) continue;
if(p[0] + p[1] >= 180){
printf("A\n");
continue;
}
if(sum >= 240){
printf("A\n");
continue;
}
if(sum >= 210){
printf("B\n");
continue;
}
if(sum >= 150 && (p[0] >= 80 || p[1] >= 80)){
printf("B\n");
continue;
}
printf("C\n");
}
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int n;
string str;
cin >> n;
for(int i=0;i<n;i++){
int out = 0;
int a[4] = {};
while(out != 3){
cin >> str;
if(str == "OUT") out++;
else if(str == "HOMERUN"){
a[3] += a[0]+a[1]+a[2]+1;
a[0] = a[1] = a[2] = 0;
}
else if(str == "HIT"){
a[3] += a[2];
a[2] = 0;
a[2] = a[1];
a[1] = 0;
a[1] = a[0];
a[0] = 1;
}
}
cout << a[3] << endl;
}
return (0);
} | 0 |
#include<iostream>
using namespace std;
int main(){
int n = 1;
while(1){
cin >> n;
if (n == 0){
break;
}
int apoint = 0;int bpoint = 0;
int i = 1;
for(i = 1;i <= n;i++){
int a = 0;int b = 0;
cin >> a >> b;
if(a == b){
apoint = apoint + a;
bpoint = bpoint + b;
}
else if(a > b){
apoint = apoint + a + b;
}
else{
bpoint = bpoint + a + b;
}
}
cout << apoint << " " << bpoint << endl;
}
return 0;
} |
#include <iostream>
using namespace std;
int main()
{
int n, a, b, count = 0, pointX = 0, pointY = 0;
cin >> n;
do {
cin >> a >> b;
if (a > b) {
pointX += (a + b);
}
else if (a < b) {
pointY += (a + b);
}
else {
pointX += a;
pointY += b;
}
count++;
if (count == n) {
cout << pointX << " " << pointY << endl;
pointX = pointY = count = 0;
cin >> n;
}
} while (n != 0);
return 0;
} | 1 |
#include <iostream>
#include <cstdio>
using namespace std;
int n, m;
int main() {
int i, d;
cin >> n >> m;
for(i=1, d=m; d>0; i++, d-=2) printf("%d %d\n", i, i+d);
for(i=m+2, d=m-1; d>0; i++, d-=2) printf("%d %d\n", i, i+d);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a, b, c) for(int a = b; a >= c; --a)
#define fi first
#define se second
#define pb push_back
#define SZ(a) ((int)a.size())
#define int long long
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
const int N = 5e5 + 100;
const int mod = 998244353;
const int Maxn = 1e5;
const int oo = 1e18;
const double PI = ((double)2.00 * (double)asin(1));
struct query {
int lef, rig, x;
} q[N];
int n, m, k;
int dp[N], g[N], a[N], lst[N];
vector<ii> even, odd, tmp;
int add(int x, int y) { return (x + y + 2 * mod) % mod; }
int mul(int x, int y) { return (x * y) % mod; }
int pw(int x, int y) {
int res = 1;
while(y) {
if(y % 2) res = mul(res, x);
x = mul(x, x);
y >>= 1;
}
return res;
}
int solve() {
memset(dp, 0, sizeof dp);
for(auto v: odd) {
a[v.fi] ++, a[v.se + 1] -= 1;
}
FOR(i, 1, n) a[i] += a[i - 1];
FOR(i, 1, n) {
a[i] = min(a[i], 1ll);
//cout << a[i] << ' ';
} //cout << '\n';
sort(tmp.begin(), tmp.end());
for(auto v: tmp) {
while(SZ(even) > 0 && even.back().se >= v.se) even.pop_back();
even.pb(v);
}
if(!SZ(even)) {
int res = 1;
FOR(i, 1, n) if(!a[i]) res = mul(res, 2);
return res;
}
//for(auto v: even) cout << v.fi << ' ' << v.se << '\n'; cout << '\n';
int pos = 0, pos1 = 0;
FOR(i, 1, n) {
while(pos < SZ(even) && even[pos].se < i) pos += 1;
if(pos > 0) lst[i] = even[pos - 1].fi;
else lst[i] = 0;
}
dp[0] = g[0] = 1;
FOR(i, 1, n) {
if(a[i]) {
g[i] = g[i - 1];
dp[i] = 0;
} else {
// set a[i] = 0
if(lst[i] == 0) dp[i] = g[i - 1];
else dp[i] = add(g[i - 1], -g[lst[i] - 1]);
g[i] = add(dp[i], g[i - 1]);
}
//cout << dp[i] << ' ';
} //cout << '\n';
int res = 0;
FOR(i, 1, n) if(even.back().fi <= i)
res = add(res, dp[i]);
return res;
}
signed main() {
#ifdef TEST
freopen("test.inp", "r", stdin);
//freopen("athletic.in", "r", stdin);
//freopen("athletic.out", "w", stdout);
#endif //TEST
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
int even = m / 2, odd = (m + 1) / 2;
FOR(i, 1, odd) cout << i << ' ' << 2 * odd - i + 1 << '\n';
FOR(i, 1, even) cout << 2 * odd + i << ' ' << 2 * odd + 2 * even + 1 - i + 1 << '\n';
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using tiii = tuple<int,int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV 998244353
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-10;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
/* Coding space */
ll dp[301][100000] = {};
ll dp2[301][100000] = {};
int main(){
int n; cin >> n;
ll sum = 0;
vt<ll> in(n); rep(i,n) cin >> in[i], sum += in[i];
ll ans = pow(3,n,DIV);
dp[0][0] = dp2[0][0] = 1;
rep(i,n){
rep(j,100000){
dp[i+1][j+in[i]] += dp[i][j];
dp[i+1][j] += dp[i][j]*2;
dp[i+1][j] %= DIV;
dp[i+1][j+in[i]] %= DIV;
dp2[i+1][j+in[i]] += dp2[i][j];
dp2[i+1][j] += dp2[i][j];
dp2[i+1][j] %= DIV;
dp2[i+1][j+in[i]] %= DIV;
}
}
//ans_d -= (cnt)*(cnt-1)/2;
ll ans_d = 0;
ll cnt = 0;
rep(i,100000){
if(i >= (sum+1)/2)ans_d += dp[n][i];
ans_d %= DIV;
}
if(sum%2 == 0)cnt += dp2[n][sum/2], cnt %= DIV;
cerr << ans << " " << ans_d << " " << cnt << endl;
ans += 10LL * DIV - 3*ans_d;
ans %= DIV;
cout << (ans + 3*cnt)%DIV<< endl;
} | #include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <deque>
using namespace std;
int main() {
//input
long n; cin >> n;
vector<int> v(n + 1);
for(int i = 1; i < n + 1; i++) cin >> v[i];
vector<int> e(100001,0);
vector<int> em(100001,0);
vector<int> o(100001,0);
vector<int> om(100001,0);
for(int i = 1; i < n + 1; i++) {
if(i % 2 == 1){
o[v[i]] += 1;
om[v[i]] += 1;
}else{
e[v[i]] += 1;
em[v[i]] += 1;
}
}
//compute
int ans;
sort(e.rbegin(),e.rend());
sort(o.rbegin(),o.rend());
bool p,q,r;
p = (count(o.begin(),o.end(),o[0]) == 1);
q = (count(e.begin(),e.end(),e[0]) == 1);
r = (find(om.begin(),om.end(),o[0]) - om.begin() == find(em.begin(),em.end(),e[0]) - em.begin());
if( p && q && r ){
ans = n - max( o[0] + e[1],o[1] + e[0] );
}else{
ans = n - ( o[0] + e[0] );
}
//output
cout << ans << endl;
} | 0 |
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
void caesar(string &s, int n) {
int i;
char c;
for (i = 0; c = s[i]; i++) {
if (c >= 'a' && c <= 'z')
s[i] = 'a' + (c - 'a' + n) % 26;
}
}
int main() {
int n;
string s;
while (getline(cin, s)) {
for (n = 0; n < 26; n++) {
caesar(s, 1);
if (s.find("the") != string::npos || s.find("this") != string::npos || s.find("that") != string::npos) {
cout << s << endl;
break;
}
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n, q;
while (scanf("%d %d", &n, &q) && n){
int a[128] = {0};
for (int i = 0; i < n; i++){
int m;
scanf("%d", &m);
for (int j = 0; j < m; j++){
int x;
scanf("%d", &x);
a[x]++;
}
}
int mpos = 1;
for (int i = 1; i < 128; i++){
if (a[i] > a[mpos]) mpos = i;
}
printf("%d\n", mpos * (a[mpos] >= q));
}
return (0);
} | 0 |
#include<bits/stdc++.h>
//今日も20分で解けなかったので、他の方のプログラムで勉強させていただきました。
using namespace std;
int main(){
int N,M;
cin >> N >> M;
int num_max,num_min;
for(int i = 0; i < M; i++){
if(i ==0 ){
cin >> num_max >> num_min;
}else{
int a,b;
cin >> a >> b;
if(num_max < a){num_max = a;}
if(num_min > b){num_min = b;}
}
}
if((num_min-num_max) < 0){
cout << 0;
}else{
cout << num_min-num_max+1;
}
} | //include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定 O(√A)
bool is_prime(int x){
if(x<=1) return false;
for(int i=2;i*i<=x;i++)
if(x%i==0) return false;
return true;
}
/*順列生成
do {
// 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/
//絶対値 abs()
//文字→数字 '0' アルファベット→数字 'a' 'A'が65番,'a'が97番だわ
//型キャスト char('a'+1)
//グローバル変数宣言
ll p=0,q=0;//r=0;
int main()
{
ll n,m;
cin>>n>>m;
vl l(m),r(m);
q=n;
rep(i,m){cin>>l[i]>>r[i];p=max(p,l[i]);q=min(q,r[i]);}
ll a=0;
a=max(a,q-p+1);
print(a)
} | 1 |
#include <iostream>
using namespace std;
bool cell[12][12];
void search(int i, int j){
if(i<0 || i>11 || j<0 || j>11) return;
if(cell[i][j]) cell[i][j] = false;
else return;
search(i+1, j);
search(i-1, j);
search(i, j+1);
search(i, j-1);
}
int main(){
while(1){
int ans = 0;
//ÇÝÝ
bool flag = false;
for(int i=0;i<12;i++){
for(int j=0;j<12;j++){
char buf;
if(!(cin >> buf)){
flag = true;
break;
}
buf -= '0';
if(buf) cell[i][j] = true;
else cell[i][j] = false;
}
if(flag) break;
}
if(flag) break;
//Tõ
for(int i=0;i<12;i++){
for(int j=0;j<12;j++){
if(cell[i][j]){
search(i, j);
ans++;
}
}
}
cout << ans << endl;
}
} | #include <cstdio>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int par[16][16];
int rank[16][16];
char map[16][16];
int cnt;
void init();
void unite(int y1, int x1, int y2, int x2);
int find(int y, int x);
int main()
{
while (scanf("%s", &map[1][1]) != EOF){
for (int i = 2; i <= 12; i++) scanf("%s", &map[i][1]);
init();
for (int i = 1; i <= 12; i++){
for (int j = 1; j <= 12; j++){
if (map[i][j] == '1'){
cnt++;
unite(i, j, i - 1, j);
unite(i, j, i + 1, j);
unite(i, j, i, j - 1);
unite(i, j, i, j + 1);
}
}
}
printf("%d\n", cnt);
}
return 0;
}
void init()
{
for (int i = 0; i < 16; i++){
for (int j = 0; j < 16; j++){
par[i][j] = i * 16 + j;
rank[i][j] = 1;
}
}
cnt = 0;
}
void unite(int y1, int x1, int y2, int x2)
{
if (map[y2][x2] == '1' && find(y1, x1) != find(y2, x2)){
if (rank[y1][x1] < rank[y2][x2]){
par[y1][x1] = y2 * 16 + x2;
rank[y1][x1]++;
}
else {
par[y2][x2] = y1 * 16 + x1;
rank[y2][x1]++;
}
cnt--;
}
}
int find(int y, int x)
{
if (par[y][x] != y * 16 + x){
par[y][x] = find(par[y][x] / 16, par[y][x] % 16);
}
return par[y][x];
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};
int main() {
ll n;
cin >> n;
map<ll, ll> m1, m2;
set<P, greater<P>> st1, st2;
rep(i, n) {
ll v;
cin >> v;
if(i % 2)
m1[v]++;
else
m2[v]++;
}
m1[0] = m2[0] = 0;
for(auto v : m1) st1.emplace(v.second, v.first);
for(auto v : m2) st2.emplace(v.second, v.first);
auto it = st1.begin();
P a = *it;
++it;
P b = *it;
it = st2.begin();
P c = *it;
++it;
P d = *it;
ll ans;
if(a.second == c.second) {
ll n1 = n - a.first - d.first;
ll n2 = n - b.first - c.first;
ans = min(n1, n2);
} else
ans = n - a.first - c.first;
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
int n;
ll x;
cin >> n >> x;
vector<ll> a(n);
rep(i,n) cin >> a.at(i);
sort(a.begin(),a.end());
ll i=0;
while(x-a.at(i)>=0){
x-=a.at(i);
i++;
if(i==n)break;
}
if(i==n&&x>0)cout << i-1 << endl;
else cout << i << endl;
}
| 0 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll, int> pli;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin >> s;
int n = s.size();
rep(i, n - 1){
if(s.substr(i, 2) == "AC"){
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
}
| #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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 maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw_2(62,1);
int main(){
{rep1(i,61) pw2[i]=2*pw2[i-1];}
{rep1(i,61) pw_2[i]=-2*pw_2[i-1];}
ll N; cin>>N;
if(N==0){
cout<<0<<endl;
return 0;
}
vector<ll> ans;
ll rem=N;
ll i=0;
while(rem!=0){
if(rem%pw2[i+1]!=0){
ans.pb(1);
rem-=pw_2[i];
}
else ans.pb(0);
i++;
}
rrep(i,sz(ans)) cout<<ans[i];
}
| 0 |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
vector<ll>path[101010];
ll flg[101010][2];
ll A, B, C;
ll A_cnt, B_cnt;
int main(){
ll N, M;
cin >> N >> M;
rep(i, M){
ll x, y;
cin >> x >> y;
path[x].push_back(y);
path[y].push_back(x);
}
rep1(i, N){
if(flg[i][0] || flg[i][1])continue;
if(path[i].empty()){
C++;
continue;
}
flg[i][0] = 1;
queue<P>Q;
Q.push(P(i, 0));
while(!Q.empty()){
ll idx = Q.front().first;
ll v = Q.front().second;
Q.pop();
rep(j, path[idx].size()){
ll to = path[idx][j];
if(flg[to][v ^ 1])continue;
flg[to][v ^ 1] = 1;
Q.push(P(to, v ^ 1));
}
}
if(flg[i][1])B++;
else A++;
}
rep1(i, N){
if(flg[i][0] && flg[i][1])A_cnt++;
else if(flg[i][0] || flg[i][1])B_cnt++;
}
cout << B * B + 2 * A * B + 2 * A * A + 2 * B_cnt * C + 2 * A_cnt * C + C * C << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using vi = vector<int>;
using pii = pair<int, int>;
#define fir first
#define sec second
template<class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
// input
int d, g;
cin >> d >> g;
vector<int> p(d), c(d);
rep(i, d) {
cin >> p[i] >> c[i];
}
// solve
int min_c = 1000;
rep(bit, 1<<d) {
int cnt = 0, scr = 0;
rep(i, d) {
if (bit & 1<<i) {
scr += 100 * (i+1) * p[i] + c[i];
cnt += p[i];
}
}
if (scr >= g) chmin(min_c, cnt);
else {
repr(i, d) {
if (~bit & 1<<i) {
rep(j, p[i]-1) {
scr += 100 * (i+1);
cnt++;
if (scr >= g) break;
}
}
if (scr >= g) break;
}
if (scr >= g) chmin(min_c, cnt);
}
}
// output
cout << min_c << endl;
} | 0 |
#include <cstdio>
#include <cstring>
#include <vector>
int main()
{
char str[1001], buff[1001], command[100];
int q, a, b;
scanf("%s", str);
scanf("%d", &q);
for(int i = 0; i < q; i++){
scanf("%s", command);
if(strcmp(command, "print") == 0){
scanf("%d", &a);
scanf("%d", &b);
for(int j = 0; j <= b - a; j++){
buff[j] = str[a + j];
}
buff[b-a+1] = '\0';
printf("%s\n", buff);
}
else if(strcmp(command, "reverse") == 0){
scanf("%d", &a);
scanf("%d", &b);
strcpy(buff, str);
for(int j = 0; j <= b - a; j++){
str[a + j] = buff[b - j];
}
}
else if(strcmp(command , "replace") == 0){
scanf("%d", &a);
scanf("%d", &b);
std::vector<char> p(b - a + 2);
scanf("%s", p.data());
for(int j = 0; j <= b - a; j++){
str[a + j] = p[j];
}
}
else {
printf("ERROR\n");
break;
}
}
return 0;
} | #include<iostream>
#include<string>
#include<sstream>
using namespace std;
int main()
{
string original;
int n;
getline(cin, original);
cin >> n;
//cout << original << endl;
//cout << n << endl;
while (n--) {
string order;
cin >> order;
int a, b;
cin >> a >> b;
if (order == "print") {
cout << original.substr(a, b - a + 1) << endl;
}
else if (order == "replace") {
string tmp;
cin >> tmp;
for (int i = a; i <= b; i++) {
original[i] = tmp[i - a];
}
//cout << "replace ????????????" << original << endl;
}
else if (order == "reverse") {
string tmp = "";
for (int i = b; i >= a; i--) {
tmp += original[i];
}
//cout << tmp << endl;
for (int i = a; i <= b; i++) {
original[i] = tmp[i - a];
}
//cout << "reverse ????????????" << original << endl;
}
}
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
void printVector(const vector<int>& vec) {
for (int value : vec) {
cout << value << " ";
}
cout << endl;
}
int main() {
int N,M;
cin >> N >> M;
vector<int> p(M);
vector<string> S(M);
for(int i=0;i<M;i++) {
cin >> p.at(i) >> S.at(i);
}
vector<vector<int>> submits(N,vector<int>(2,0));
for(int i=0;i<M;i++) {
if(submits.at(p.at(i)-1).at(0) != 0) {
continue;
}
if(S.at(i) == "WA") {
submits.at(p.at(i)-1).at(1)++;
}else{
submits.at(p.at(i)-1).at(0)++;
}
}
int ac = 0;
int pena = 0;
for(int i=0;i<N;i++) {
if (submits.at(i).at(0) == 0) {
continue;
}
ac += submits.at(i).at(0);
pena += submits.at(i).at(1);
}
cout << ac << " " << pena << endl;
/*
cout << "ans" << endl;
for(int i=0;i<N;i++) {
cout << submits.at(i).at(0) <<" "<< submits.at(i).at(1) << endl;
}
*/
} | #include<iostream>
#include<vector>
using namespace std;
vector<int> v[10000], rev[10000], order, group(10000, 0);
vector<bool> vis(10000);
void dfs(int x){
vis[x] = true;
for(int j : v[x]){
if(!vis[j]) dfs(j);
}
order.push_back(x);
}
void rdfs(int x, int k){
group[x] = k;
vis[x] = true;
for(int j : rev[x]){
if(!vis[j]) rdfs(j, k);
}
}
int main(){
int n, m;
cin >> n >> m;
while(m--){
int s, t;
cin >> s >> t;
v[s].push_back(t);
rev[t].push_back(s);
}
fill(vis.begin(),vis.end(),0);
for(int i = 0; i < n; i++){
if(!vis[i]) dfs(i);
}
fill(vis.begin(),vis.end(),0);
int k = 0;
for(int i = order.size()-1; i >= 0; i--){
if(!vis[order[i]]) rdfs(order[i], k++);
}
int q;
cin >> q;
while(q--){
int u, v;
cin >> u >> v;
cout << (group[u]==group[v]) << endl;
}
return 0;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF=INT_MAX/4;
const long long MOD=998244353;
const double EPS=1e-14;
const bool DEBUG=false;
const string YES = "YES";
const string NO = "NO";
const string Yes = "Yes";
const string No = "No";
template<class T>
void debug(T head){
if(DEBUG){
cout<<head<<endl;
}
}
template <class Head, class... Body>
void debug(Head head, Body... body){
if(DEBUG){
cout<<head<<" ";
debug(body...);
}
}
/////
void answer(ll sx, ll sy, ll tx, ll ty){
for(int i=sy; i<ty; ++i){
cout<<"U";
}
for(int i=sx; i<tx; ++i){
cout<<"R";
}
for(int i=sy; i<ty; ++i){
cout<<"D";
}
for(int i=sx; i<tx; ++i){
cout<<"L";
}
cout<<"L";
for(int i=sy; i<ty+1; ++i){
cout<<"U";
}
for(int i=sx; i<tx+1; ++i){
cout<<"R";
}
cout<<"D";
cout<<"R";
for(int i=sy; i<ty+1; ++i){
cout<<"D";
}
for(int i=sx; i<tx+1; ++i){
cout<<"L";
}
cout<<"U";
cout<<endl;
return;
}
/////
int main(int argc, char* argv[]){
cin.tie(0);
ios::sync_with_stdio(0);
cout.precision(16);
ll sx, sy, tx, ty;
cin>>sx>>sy>>tx>>ty;
answer(sx, sy, tx, ty);
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;
//cin.tie(0);ios::sync_with_stdio(false);
int main() {
int sx, sy, tx, ty;
cin >> sx >> sy >> tx >> ty;
string ans = "";
for (int i = 0; i < 2; i++) {
string head = "";
head += string(ty - sy + i, 'U');
head += string(tx - sx + i, 'R');
head = string(i, 'L') + head;
head += string(i, 'D');
string tail = "";
tail += string(ty - sy + i, 'D');
tail += string(tx - sx + i, 'L');
tail = string(i, 'R') + tail;
tail += string(i, 'U');
ans += head + tail;
}
cout << ans << endl;
return 0;
}
| 1 |
#include<bits/stdc++.h>
#define no {puts("No");return 0;}
#define yes {puts("Yes");return 0;}
#define nc() getchar()
using namespace std;
const int N=300010;
/*inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}*/
inline int read(){
char ch=nc();int sum=0;
while(!(ch>='0'&&ch<='9'))ch=nc();
while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
return sum;
}
int c[N],n;
void add(int x,int k){
while(x<=n){
c[x]+=k;
x+=x&-x;
}
}
int query(int x){
int ans=0;
while(x){
ans+=c[x];
x-=x&-x;
}
return ans;
}
int a[N],fu[N],s[N];
bool vis[N];
int main(){
n=read();
int s1=0,s2=0;
for(int i=1;i<=3;i++){
for(int j=1;j<=n;j++){
int x;
x=read();
if(i==1){
if(x%3==0){
a[j]=x/3;
fu[j]=1;
if(j&1) s1++;
else s2++;
}else{
if(x%3!=1) {no;}
a[j]=x/3+1;
}
if(vis[a[j]]) {no;}
if((j&1)^(a[j]&1)) {no;}
vis[a[j]]=1;
}
else{
if(fu[j]){
if(x!=a[j]*3-i+1) {no;}
}else{
// printf("a(%d)=%d\n",j,a[j]);
if(x!=(a[j]-1)*3+i) {no;}
}
}
}
}
// for(int i=1;i<=n;i++) printf("%d ",a[i]);cout<<endl;
int i;
if(n&1) i=n;else i=n-1;
for(;i>0;i-=2){
s2+=query(a[i]);
add(a[i],1);
}
if(n&1) i=n-1;else i=n;
memset(c,0,sizeof(c));
for(;i>0;i-=2){
s1+=query(a[i]);
add(a[i],1);
}
// printf("%d %d\n",s1,s2);
if(s1%2==0&&s2%2==0) {yes;}
else {no;}
return 1;
}
| #define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair <int,int> P;
static const double EPS = 1e-8;
char stage[20][20];
int tx[] = {-1,0,1,0};
int ty[] = {0,1,0,-1};
class Data{
public:
char dx;
char dy;
char stage[20][20];
Data(char dx,char dy,char stage[20][20]){
this->dx = dx;
this->dy = dy;
memcpy(this->stage,stage,sizeof(char)*(20*20));
}
};
typedef pair <int,Data> PP;
int main(){
int w,h;
char sx,sy,gx,gy;
while(~scanf("%d %d",&w,&h)){
if(w==h && h==0) break;
for(int y=0;y<h;y++){
for(int x=0;x<w;x++){
int n;
scanf("%d",&n);
stage[y][x] = n;
if(stage[y][x]==2){
sx=x;
sy=y;
}
else if(stage[y][x]==3){
gx=x;
gy=y;
}
}
}
queue<PP> que;
que.push(PP(0,Data(sx,sy,stage)));
int res = 11;
while(!que.empty()){
int c = que.front().first;
int qx = que.front().second.dx;
int qy = que.front().second.dy;
char tmpStage[20][20];
memcpy(tmpStage,que.front().second.stage,sizeof(char)*(20*20));
que.pop();
for(int i=0;i<4;i++){
for(int d=1;d<=max(w,h);d++){
int dx = qx + tx[i]*d;
int dy = qy + ty[i]*d;
if(dx < 0 || dx >= w || dy < 0 || dy >= h) break;
if(d==1 && tmpStage[dy][dx] == 1) break;
if(tmpStage[dy][dx] == 1){
char mx = dx - tx[i];
char my = dy - ty[i];
if(c+1 <= 10){
//cost[my][mx] = c+1;
tmpStage[dy][dx] = 0;
que.push(PP(c+1,Data(mx,my,tmpStage)));
//cout << mx << " " << my << endl;
tmpStage[dy][dx] = 1;
}
break;
}
else if(tmpStage[dy][dx] == 3){
if(c+1 <= 10){
res = min(res,c+1);
}
break;
}
}
}
}
printf("%d\n", res > 10 ? -1 : res);
}
} | 0 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
/*----------------------------------ここからマクロ----------------------------------*/
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(n) for(int i=0;i<(int)n;++i)
#define rep2(i,n) for(int i=0;i<(int)n;++i)
#define rep3(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define rep4(i,a,b,c) for(int i=(int)a;i<(int)b;i+=(int)c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#ifdef _DEBUG
#define debug1(a) cerr << #a << ": " << a << "\n"
#define debug2(a,b) cerr << #a << ": " << a << ", " << #b << ": " << b << "\n"
#define debug3(a,b,c) cerr << #a << ": " << a << ", " << #b << ": " << b << ", " << #c << ": " << c << "\n"
#define debug4(a,b,c,d) cerr << #a << ": " << a << ", " << #b << ": " << b << ", " << #c << ": " << c << ", " << #d << ": " << d << "\n"
#define debug(...) overload4(__VA_ARGS__,debug4,debug3,debug2,debug1)(__VA_ARGS__)
#define vecout(a) cerr << #a << ": [";rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "":",");}cerr << "]\n"
#else
#define debug(...)
#define vecout(a)
#endif
#define mp make_pair
//struct doset{doset(int n){cout << fixed << setprecision(n);cerr << fixed << setprecision(n);}};
//struct myset{myset(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}};
void myset(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
void doset(int n){cout << fixed << setprecision(n);}
using ll = long long;
using ld = long double;
using dou = double;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod1 = 1000000007LL;
const ll mod2 = 998244353LL;
typedef pair<ll,ll> P;
template<class T, class U> inline bool chmin(T& a, const U& b){ if(a > b){ a = b; return 1; } return 0; }
template<class T, class U> inline bool chmax(T& a, const U& b){ if(a < b){ a = b; return 1; } return 0; }
template<class T, class U> inline bool change(T& a,U& b){if(a > b){swap(a,b);return 1;}return 0;}
//nのm乗をMODで割ったあまりO(logm)
ll modpow(ll n,ll m,ll MOD){
if(m == 0)return 1;
if(m < 0)return -1;
ll res = 1;
while(m){
if(m & 1)res = (res * n) % MOD;
m >>= 1;
n *= n;
n %= MOD;
}
return res;
}
ll mypow(ll n,ll m){
if(m == 0)return 1;
if(m < 0)return -1;
ll res = 1;
while(m){
if(m & 1)res = (res * n);
m >>= 1;
n *= n;
}
return res;
}
//素数判定O(sqrt(N))
template<class T>
inline bool isp(T n){
bool res = true;
if(n == 1 || n == 0)return false;
else{
for(ll i = 2;i * i <= n;i++){
if(n % i == 0){
res = false;
break;
}
}
return res;
}
}
template<class T = int>
T in(){T x;cin >> x;return x;}
inline bool Yes(bool b){cout << (b ? "Yes\n":"No\n");return b;}
inline bool YES(bool b){cout << (b ? "YES\n":"NO\n");return b;}
/*----------------------------------マクロここまで----------------------------------*/
int main(){
myset();
string S;
cin >> S;
map<char,ll> ma;
ll ans = 0;
for(char c : S){
ma[c]++;
for(auto x : ma){
if(x.first == c)continue;
ans += x.second;
}
}
cout << ans + 1 << "\n";
} | #include<bits/stdc++.h>
#define ll long long
using namespace std;
#define INF 1e15
int main()
{
string s;cin>>s;
ll hash[1000]={0};
for(int i=0;i<s.length();i++)
hash[s[i]-'0']++;
ll count=0;
ll n=s.length();
for(int i=0;i<1000;i++)
count+=(hash[i]*(hash[i]-1))/2;
ll res=(((n*(n-1))/2))-count+1;
cout<<res<<endl;;
} | 1 |
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
#define N 500005
#define ll long long
ll n;
double a[N];
ll cnt2[N],cnt5[N],ten[N];
ll sum[5005][5005],ans;
ll len1,len2;
int main(){
scanf("%lld",&n);
for(ll i=1;i<=n;i++){
scanf("%lf",a+i);
ten[i]=9;
ll JZY=llround(a[i]*1000000000);
// printf("%lld\n",JZY);
while(JZY%2==0&&JZY) JZY>>=1,cnt2[i]++;
while(JZY%5==0&&JZY) JZY/=5,cnt5[i]++;
// for(ll j=0,mul=1;j<=10;j++,mul*=10){
//// if(i==n)printf("read %lf %lld %lld\n",a[i]*mul,(ll)(a[i]*mul),(a[i]*mul)-(ll)(a[i]*mul)<1e-9);
// if(a[i]*mul==llround(a[i]*mul)){
// ten[i]=j;
//// printf("%lld %lld %lld\n",cnt2[i],cnt5[i],ten[i]);
// break;
// }
// }
}
for(ll i=1;i<=n;i++)
len1=max(len1,cnt2[i]),len2=max(len2,cnt5[i]);
len1+=20,len2+=20;
// printf("border %lld %lld\n",len1,len2);
for(ll i=1;i<=n;i++){
// printf("num %lf\n",a[i]);
// printf("check %lld %lld\n",ten[i]-cnt2[i]+10,ten[i]-cnt5[i]+10);
for(ll x=ten[i]-cnt2[i]+20;x<=len1;x++)
for(ll y=ten[i]-cnt5[i]+20;y<=len2;y++)
ans+=sum[x][y];
// printf("add %lld %lld\n",cnt2[i]-ten[i]+10,cnt5[i]-ten[i]+10);
sum[cnt2[i]-ten[i]+20][cnt5[i]-ten[i]+20]++;
}
printf("%lld",ans);
}
/*
7
0.9
1
1
1.25
2.3
5
70
*/ | #include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<int,int>P;
map<P,int>mp;
int main(){
int n;
cin>>n;
while(n--){
ld s;
cin>>s;
ll k=ll(s*1000000000.0+0.5);
ll cnt2=0,cnt5=0;
while(k%2==0){
k/=2,cnt2++;
}
while(k%5==0){
k/=5;cnt5++;
}
mp[make_pair(cnt2,cnt5)]++;
}
ll ans=0;
for(auto&v:mp){
for(auto&u:mp){
if(v.first.first+u.first.first>=18&&v.first.second+u.first.second>=18)
{
if(v==u)ans+=1ll*v.second*(v.second-1);
else ans+=1ll*v.second*u.second;
}
}
}
cout<<ans/2<<endl;
return 0;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
string str;
while(cin>>str){
if(str.length()!=2)
reverse(str.begin(),str.end());
cout<<str<<endl;
}
return 0;
}
| #include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long
using namespace std;
int main(){
string s;cin>>s;
if(s.size()==2)cout<<s;
else rep(i, 3)cout<<s[2-i];
return 0;
} | 1 |
#include<iostream>
using namespace std;
const int MAX = 50;
int main()
{
while (true)
{
int n, p;
cin >> n >> p;
if (!n && !p)
break;
int pOfCan[MAX] = { 0 };
int pOfBowl = p;
int winIdx = -1;
int idx = 0;
while (true)
{
if (idx > n - 1)
idx = 0;
if (pOfBowl > 0)
{
pOfCan[idx]++;
pOfBowl--;
}
else if (pOfBowl == 0)
{
if (pOfCan[idx] == p)
{
winIdx = idx;
break;
}
pOfBowl = pOfCan[idx];
pOfCan[idx] = 0;
}
idx++;
}
cout << winIdx << endl;
}
}
| #include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
const int MAX_W=20;
const int DIRECTIONS=4;//0:up/1:right/2:down/3:left
const int MAX_DEPTH=10;
const int INF=1<<27;
struct tpl{
int ary[MAX_W][MAX_W];
int depth;
int last;
int x;
int y;
};
int w,h;
int dfs(const tpl& t){
int minDepth=INF;
if(t.depth+1>MAX_DEPTH)return minDepth;
REP(i,DIRECTIONS){
tpl u;
u.depth=t.depth+1;
u.last=i;
REP(j,h)REP(k,w)u.ary[j][k]=t.ary[j][k];
u.x=t.x;
u.y=t.y;
if(i==0&&u.y>0&&u.ary[u.y-1][u.x]!=1){
for(;u.y>=0;u.y--){
if(u.ary[u.y][u.x]==3){
minDepth=min(minDepth,u.depth);
break;
}else if(u.y>0&&u.ary[u.y-1][u.x]==1){
u.ary[u.y-1][u.x]=0;
minDepth=min(minDepth,dfs(u));
break;
}
}
}else if(i==1&&u.x<w-1&&u.ary[u.y][u.x+1]!=1){
for(;u.x<=w-1;u.x++){
if(u.ary[u.y][u.x]==3){
minDepth=min(minDepth,u.depth);
break;
}else if(u.x<w-1&&u.ary[u.y][u.x+1]==1){
u.ary[u.y][u.x+1]=0;
minDepth=min(minDepth,dfs(u));
break;
}
}
}else if(i==2&&u.y<h-1&&u.ary[u.y+1][u.x]!=1){
for(;u.y<=h-1;u.y++){
if(u.ary[u.y][u.x]==3){
minDepth=min(minDepth,u.depth);
break;
}else if(u.y<h-1&&u.ary[u.y+1][u.x]==1){
u.ary[u.y+1][u.x]=0;
minDepth=min(minDepth,dfs(u));
break;
}
}
}else if(i==3&&u.x>0&&u.ary[u.y][u.x-1]!=1){
for(;u.x>=0;u.x--){
if(u.ary[u.y][u.x]==3){
minDepth=min(minDepth,u.depth);
break;
}else if(u.x>0&&u.ary[u.y][u.x-1]==1){
u.ary[u.y][u.x-1]=0;
minDepth=min(minDepth,dfs(u));
break;
}
}
}
}
return minDepth;
}
void solve(const tpl& t){
int result=dfs(t);
cout<<(result==INF?-1:result)<<endl;
}
int main(){ _;
while(cin>>w>>h,(w|h)!=0){
tpl t;
t.depth=0;
t.last=-1;
REP(i,h)REP(j,w){
cin>>t.ary[i][j];
if(t.ary[i][j]==2){
t.ary[i][j]=0;
t.x=j;
t.y=i;
}
}
solve(t);
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif
void init() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
}
int p;
bool check(int x) {
cout << x << endl;
string s; cin >> s;
if (s == "Vacant") exit(0);
if (x%2 == p && s == "Male") return true;
if (x%2 != p && s == "Female") return true;
return false;
}
void solve() {
string s; int n;
cin >> n;
cout << 0 << endl;
cin >> s;
if (s == "Vacant") return;
if (s == "Female") p = 1;
int lo = 0, hi = n;
while (lo+1 < hi) {
int mid = (lo+hi)/2;
if (check(mid)) lo = mid;
else hi = mid;
}
}
int main() {
int t = 1; //scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin>>n;
string s;
cin>>s;
string back_s=s.substr(n,n);
reverse(ALL(back_s));
map<pair<string,string>,ll> m;
REP(bit,(1<<n)){
string b="",r="";
REP(i,n){
if((bit>>i)&1)
b+=back_s[i];
else
r+=back_s[i];
}
if(b>r)
swap(b,r);
m[make_pair(b,r)] += 1;
}
ll ans=0;
REP(bit,(1<<n)){
string b="",r="";
REP(i,n){
if((bit>>i)&1)
b+=s[i];
else
r+=s[i];
}
if(b>r)
swap(b,r);
if(b==r)
ans+=m[make_pair(b,r)];
else
ans+=m[make_pair(b,r)]/2;
}
cout<<ans<<endl;
}
| 0 |
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int dig=60;
#define N 233
inline ll read(){
ll 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 T,n;
ll a[N];
char s[N];
struct Basis{
ll d[64];
void clear(){
memset(d,0,sizeof(d));
}
void Insert(ll x){
for(int i=dig;i>=0;--i){
if((x>>i)&1){
if(d[i]){
x^=d[i];
}
else{
d[i]=x;
return;
}
}
}
}
bool check(ll x){
for(int i=dig;i>=0;--i){
if((x>>i)&1){
if(!d[i])return false;
x^=d[i];
}
}
return true;
}
}B;
int Solve(){
n=read();
for(int i=1;i<=n;++i){
a[i]=read();
}
scanf("%s",s+1);
B.clear();
for(int i=n;i>=1;--i){
if(s[i]=='0'){
B.Insert(a[i]);
}
else{
if(!B.check(a[i]))return 1;
}
}
return 0;
}
int main(){
T=read();
while(T--){
printf("%d\n",Solve());
}
return 0;
}
| #include <iostream>
using namespace std;
int main(){
int n,p,i,m,a=0,I;
int box[100]={};
while(1){
cin>>n>>p;
a=0;
if(n==0&&p==0) break;
else{
while(1){
for(i=0;i<n;i++){
m=i;
if(p>0){
box[m]+=1;
p-=1;
}
else if(p==0){
for(I=0;I<n;I++){
if(box[I]==0) a++;
}
if(a==n-1) {
break;
}
else {
p=box[m];
box[m]=0;
a=0;
}
}
}
if(a==n-1) break;
}
if(m-1<0){
m=n;
}
cout<<m-1<<endl;
}
for(i=0;i<n;i++){
box[i]=0;
}
}
return 0;
} | 0 |
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int vis[10],ans[10],vis1[10];
int a[100],b[100],k=0;
char mp[10][10];
struct note
{
int x,y;
} l[1000];
int check(int x,int y)
{
for(int i=0; i<k; i++)
{
if(l[i].x==x||l[i].y==y||abs(x-l[i].x)==abs(y-l[i].y))
return 0;
}
return 1;
}
void pri()
{
for(int i=0; i<9; i++)
{
for(int j=0; j<9; j++)
mp[i][j]='.';
}
for(int i=0; i<k; i++)
mp[l[i].x][l[i].y]='Q';
for(int i=1; i<9; i++)
{
for(int j=1; j<9; j++)
printf("%c",mp[i][j]);
printf("\n");
}
}
void dfs(int x)
{
if(x>8)
{
pri();
return;
}
else if(vis[x]==0)
{
for(int j=1; j<=8; j++)
{
if(vis1[j]==0&&check(x,j))
{
l[k].x=x;
l[k++].y=j;
vis1[j]=1;
dfs(x+1);
vis1[j]=0;
k--;
}
}
}
else
dfs(x+1);
}
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(vis,0,sizeof(vis));
memset(vis1,0,sizeof(vis1));
k=0;
for(int i=1; i<=n; i++)
{
scanf("%d%d",&a[i],&b[i]);
vis[a[i]+1]=1;
vis1[b[i]+1]=1;
l[k].x=a[i]+1;
l[k++].y=b[i]+1;
}
dfs(1);
}
return 0;
}
| #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
#define N 300010
#define ll long long
int n,m,p[N],fa[N],deep[N],degree[N],q[N],t,root;
bool flag[N];
struct data{int to,nxt;
}edge[N];
void addedge(int x,int y){t++;edge[t].to=y,edge[t].nxt=p[x],p[x]=t;}
void topsort()
{
int head=0,tail=0;
for (int i=1;i<=n;i++) if (!degree[i]) q[++tail]=i;
while (tail<n)
{
int x=q[++head];
for (int i=p[x];i;i=edge[i].nxt)
{
degree[edge[i].to]--;
if (deep[x]+1>deep[edge[i].to])
{
deep[edge[i].to]=deep[x]+1;
fa[edge[i].to]=x;
}
if (!degree[edge[i].to]) q[++tail]=edge[i].to;
}
}
}
int main()
{
n=read(),m=read();
for (int i=1;i<n+m;i++)
{
int x=read(),y=read();
addedge(x,y);degree[y]++;
}
topsort();
for (int i=1;i<=n;i++) printf("%d\n",fa[i]);
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
#include<bits/stdc++.h>
using namespace std;
using cost_t=int;
struct Edge {
int from, to;
cost_t cost;
Edge(int from, int to, cost_t cost) : from(from), to(to), cost(cost) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
vector<int> articulation_points(Graph& g){
int n = g.size();
vector<int> pre(n,-1);
vector<int> low(n);
vector<int> res;
int k=0;
function<int(int,int,int)> dfs=[&](int v,int prev,int org){
low[v] = pre[v];
bool isok=true;
int cnt = 0;
for(auto& e:g[v]){
if(e.to==prev) continue;
if(pre[e.to]==-1){
pre[e.to] = k++;
low[v] = min(low[v], dfs(e.to,v,org));
isok = isok && low[e.to]<pre[v];
cnt++;
}
else low[v] = min(low[v], pre[e.to]);
}
if(v==org){
if(g[v].size()!=1 && cnt>1) res.push_back(v);
}
else if(!isok) res.push_back(v);
return low[v];
};
// if connected -> dfs(0,-1,0);
for(int i=0;i<n;i++){
if(pre[i]==-1){
pre[i]=k++;
dfs(i,-1,i);
}
}
return res;
}
int main(){
int V,E;
cin>>V>>E;
Graph g(V);
for(int i=0;i<E;i++){
int s,t;
cin>>s>>t;
g[s].push_back(Edge(s,t,0));
g[t].push_back(Edge(t,s,0));
}
auto res= articulation_points(g);
sort(res.begin(),res.end());
for(auto v:res){
cout<<v<<endl;
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
T f=0,x=0;char c=getchar();
while(!isdigit(c)) f=c=='-',c=getchar();
while(isdigit(c)) x=x*10+c-48,c=getchar();
return f?-x:x;
}
namespace run{
int s[1009][1009];
char c[1009][1009];
char c4[10][10]={
{'a','a','b','c'},
{'d','d','b','c'},
{'b','c','a','a'},
{'b','c','d','d'}
};
char c5[10][10]={
{'a','a','b','b','a'},
{'b','c','c','.','a'},
{'b','.','.','c','b'},
{'a','.','.','c','b'},
{'a','b','b','a','a'}
};
char c7[10][10]={
{'a','a','b','b','c','c','.'},
{'d','d','.','d','d','.','a'},
{'.','.','d','.','.','d','a'},
{'.','.','d','.','.','d','b'},
{'d','d','.','d','d','.','b'},
{'.','.','d','.','.','d','c'},
{'.','.','d','.','.','d','c'}
};
int main(){
int n=read<int>();
if(n<=2) puts("-1"),exit(0);
else if(n%3==0){
for(int i=1;i<=n;i+=3)
s[i][i]=s[i][i+1]=s[i+1][i+2]=s[i+2][i+2]=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(s[i][j]) printf("a");
else printf(".");
}
cout<<endl;
}
}else{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++) c[i][j]='.';
int x=0,y=0,z=0,peg=0;
for(x=0;x<=n/4;x++){
for(y=0;x*4+y*5<=n;y++){
int now=n-x*4-y*5;
z=now/7;
if(z*7==now){peg=1;break;}
}
if(peg) break;
}
for(int i=1;i<=x;i++){
int now=i*4-3;
for(int j=now;j<=i*4;j++)
for(int k=now;k<=i*4;k++)
c[j][k]=c4[j-now][k-now];
}
for(int i=1;i<=y;i++){
int now=x*4+i*5-4;
for(int j=now;j<=x*4+i*5;j++)
for(int k=now;k<=x*4+i*5;k++)
c[j][k]=c5[j-now][k-now];
}
for(int i=1;i<=z;i++){
int now=x*4+y*5+i*7-6;
for(int j=now;j<=x*4+y*5+i*7;j++)
for(int k=now;k<=x*4+y*5+i*7;k++)
c[j][k]=c7[j-now][k-now];
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
printf("%c",c[i][j]);
}
puts("");
}
}
return 0;
}
}
int main(){
#ifdef my
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
return run::main();
} | 0 |
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;
double d(double x, double y, double a, ll b) {
return sqrt((x - a) * (x - a) + (y - b) * (y - b));
}
ll fact(ll n) {
if(n == 0) return 1;
return n * fact(n - 1);
}
void solve() {
int n;
cin >> n;
int arr[n];
vector<pair<int,int>> c(n);
double ans = 0;
for(int i = 0; i < n; ++i) cin >> c[i].first >> c[i].second;
for(int i = 0; i < n; ++i) arr[i] = i + 1;
do{
for(int i = 0; i < n - 1; ++i) {
ans += d(c[arr[i] - 1].first, c[arr[i] - 1].second, c[arr[i + 1] - 1].first , c[arr[i + 1] - 1].second);
}
}while(next_permutation(arr, arr + n));
cout << ans / fact(n) << endl;
}
int main() {
ios_base :: sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout.precision(35);
solve();
return 0;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vll vector<long long>
#define pll pair<long long, long long>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1e18
typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;
const int N=1e5+5;
vll v[N];
ll vis[N];
vll path;
ll maxh[N];
ll f=0;
void dfs(ll x,ll s,ll dest)
{
if(f)return;
if(x==dest)
{
f=1;
path.pb(x);
return;
}
path.pb(x);
for(auto it:v[x])
{
if(it==s)continue;
dfs(it,x,dest);
}
if(f)return;
path.pop_back();
}
void dfs2(ll x,ll s)
{
ll f=0;
// cout<<x+1<<"\n";
for(auto it:v[x])
{
if(it==s)continue;
f=1;
dfs2(it,x);
maxh[x]=max(maxh[x],maxh[it]+1ll);
}
if(!f)
{
maxh[x]=1;
}
}
void solve()
{
ll n;
cin>>n;
ll aa,bb;
cin>>aa>>bb;
aa--,bb--;
ll i,j;
for(i=1;i<n;i++)
{
ll x,y;
cin>>x>>y;
x--,y--;
v[x].pb(y);
v[y].pb(x);
};
dfs(aa,-1,bb);
// for(auto it:path)
// {
// cout<<it+1<<" ";
// }
// all i need is max height of subtree
dfs2(bb,-1);
ll maxi=0;
for(i=1;i<sz(path);i++)
{
// distance travelled to reach node path[i] = i;
ll dist_1 = i;
ll dist_from_bb = sz(path)-1-i;
if(dist_1>dist_from_bb)continue;
ll maxheight = maxh[path[i]]-1;
ll dif = dist_from_bb-dist_1;
ll tans = dist_1;
tans+=(dif+(maxheight-1));
// ll tans = (maxheight)+dist_from_bb;
// cout<<dif<<" "<<maxheight<<" "<<dist_from_bb<<" ";
// cout<<path[i]+1<<"<-- "<<tans<<"\n";
maxi=max(maxi,tans);
}
cout<<maxi<<"\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if (fopen("input.txt","r" ))
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
cout<<setprecision(20);
ll t=1;
// cin>>t;
while(t--)
{
solve();
}
return 0;
} | 0 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
int a,b,c,N;
while(cin >> a >> b >> c && a){
cin >> N;
vector< vector<int> > v(N,vector<int>(4));
vector<int> chk(a+b+c,2);
rep(i,N){
rep(j,4){
cin >> v[i][j];
if(j!=3)v[i][j]--;
}
}
rep(i,N){
if(v[i][3] == 1){
rep(j,3) chk[v[i][j]] = 1;
}
}
rep(i,N){
if(v[i][3] == 0){
rep(j,3){
if(chk[v[i][j]] == 2){
int c = 0;
rep(k,3)c += chk[v[i][k]] == 1;
if(c==2)chk[v[i][j]] = 0;
}
}
}
}
rep(i,a+b+c) cout << chk[i] << endl;
}
} | #include <iostream>
#include <string>
using namespace std;
int main(){
int a;
int b;
int c;
int h;
int n;
while(cin >>a>>b>>c){
if(a==0&&b==0&&c==0){break;}
cin >>n;
int d[n];
int e[n];
int f[n];
int g[n];
int i[a+b+c];
h=0;
while(h<n){
cin >>d[h];
cin >>e[h];
cin >>f[h];
cin >>g[h];
h=h+1;}
h=0;
while(h<a+b+c){
i[h]=2;
h=h+1;}
h=0;
while(h<n){
if(g[h]==1){i[d[h]-1]=1; i[e[h]-1]=1; i[f[h]-1]=1;}
h=h+1;}
h=0;
while(h<n){
if(i[d[h]-1]==1&&i[e[h]-1]==1&&g[h]==0){i[f[h]-1]=0;}
if(i[f[h]-1]==1&&i[e[h]-1]==1&&g[h]==0){i[d[h]-1]=0;}
if(i[d[h]-1]==1&&i[f[h]-1]==1&&g[h]==0){i[e[h]-1]=0;}
h=h+1;}
h=0;
while(h<a+b+c){
cout <<i[h]<<endl;
h=h+1;}
}} | 1 |
#include <iostream>
using namespace std;
int main() {
// 一年の秒数
double score;
double leate;
cin >> score >> leate;
// 以下のコメント/* */を消して追記する
cout << leate * 2 - score << endl;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int k,n;
cin >> k >> n;
int a[n];
int d=0,e;
for(int i=0;i<n;i++){
cin >> a[i];
if(d<a[i]){
d=a[i];
e=i;
}
}
cout << max(a[e]- 1 -(k-a[e]),0);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 * 2;
int main() {
int a[3];
rep(i, 3) cin >> a[i];
int k;
cin >> k;
sort(a, a + 3, greater<int>());
ll out = a[0] * pow(2, k) + a[1] + a[2];
cout << out << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
int main(){
int a, b, c;
cin >> a >> b >> c;
int k;
cin >> k;
if (a<b) swap(a, b);
if (a<c) swap(a, c);
rep(i, k) {
a *= 2;
}
int ans = a + b + c;
cout << ans << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
#include<math.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
int main () {
int k, x ;
cin >> k >> x ;
int t = x + (k - 1) ;
int p = x - (k - 1) ;
for(int i = p; i <= t ; i++){
cout << i << " " ;
}
cout << endl ;
} | // lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
string str,stra,straa;
ll x,y,z;
char ca,cb,cc;
cin>>x>>k;
for(ll i=-1000;i<=1000;i++){
if(k-x+1<=i&&i<=k+x-1) cout<<i<<" ";
}
return 0;
}
| 1 |
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
int main() {
int n;
cin >> n;
vector<ll> a(n), b(n);
vector<ll> score(n);
ll ans = 0;
rep(i, n) {
cin >> a[i] >> b[i];
score[i] = a[i] + b[i];
ans += a[i];
}
sort(score.rbegin(), score.rend());
rep(i, n) {
if (i % 2) ans -= score[i];
}
cout << ans << endl;
} | #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
double naiseki(pair<double,double> v1,pair<double,double> v2){
return v1.first*v2.first+v1.second*v2.second;
}
int main(){
int N;
int x[101],y[101];
pint ab[101][101];
vector<double> kakudo[101];
scan(N);
rep(i,N){
scan(x[i]);scan(y[i]);
}
if(N==2){
prin(0.5),prin(0.5);
}
else{
rep(i,N){
rep(j,N){
if(i==j) continue;
else{
ab[i][j]=mp(x[i]-x[j],y[i]-y[j]);
if(naiseki(mp(x[i]-(double)(x[i]+x[j])/2,y[i]-(double)(y[i]+y[j])/2),ab[i][j])<0){
ab[i][j]=mp(x[j]-x[i],y[j]-y[i]);
}
}
//printf("i:%d j:%d ab:(%d,%d) naiseki:%f\n",i,j,ab[i][j].first,ab[i][j].second,naiseki(mp(x[i]-(double)(x[i]+x[j])/2,y[i]-(double)(y[i]+y[j])/2),ab[i][j]));
}
}
rep(i,N){
rep(j,N){
if(i==j) continue;
kakudo[i].push_back(atan2((double)ab[i][j].second,(double)ab[i][j].first));
//printf("i:%d j:%d kakudo:%f(%f)\n",i,j,kakudo[i].back(),kakudo[i].back()*180/M_PI);
}
sort(kakudo[i].begin(),kakudo[i].end());
int flag=0;
double thetamin,thetamax;
rep(j,kakudo[i].size()){
if(j==0){
if(kakudo[i][0]+M_PI*2-kakudo[i].back()>=M_PI){
flag=1;
thetamin=kakudo[i][0],thetamax=kakudo[i].back();
}
}
else{
if(kakudo[i][j]-kakudo[i][j-1]>=M_PI){
flag=1;
thetamin=kakudo[i][j],thetamax=kakudo[i][j-1];
if(thetamin>thetamax) thetamax+=M_PI*2;
}
}
}
//printf("i: max:%f min:%f\n",thetamax,thetamin);
if(flag){
prin((M_PI-(thetamax-thetamin))/(M_PI*2));
}
else{
prin(0.0);
}
}
}
return 0;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
#define endl '\n'
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
int a, b, c;
cin >> a >> b >> c;
if (min(a,b) <= c && c <= max(a,b))
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
if(a%b ==0){
cout<<(a/b)*c<<endl;}
else{
cout<<((a/b)+1)*c<<endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
typedef long long ll;
int n;
int a[maxn], prep[maxn], sufp[maxn];
ll ans = 1e18;
ll pre[maxn], suf[maxn];
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
int cur = 1;
pre[1] = a[1];
for(int i = 2; i <= n; ++i)
{
pre[i] = pre[i - 1] + a[i];
while(pre[cur] * 2 <= pre[i]) ++cur;
prep[i] = cur - 1;
}
cur = n;
suf[n] = a[n];
for(int i = n - 1; i; --i)
{
suf[i] = suf[i + 1] + a[i];
while(suf[cur] * 2 <= suf[i]) --cur;
sufp[i] = cur - 1;
}
for(int i = 3; i < n; ++i)
{
int l2 = i - 1;
for(int j = 0; j < 2; ++j)
for(int k = 0; k < 2; ++k)
{
int l1 = prep[i - 1] + j;
int l3 = sufp[i] + k;
if(l1 < l2 && l2 < l3 && l3 < n)
{
ll x1 = pre[l1], x2 = pre[l2] - pre[l1], x3 = pre[l3] - pre[l2], x4 = pre[n] - pre[l3];
//cout << i << ' ' << x1 << ' ' << x2 << ' ' << x3 << ' ' << x4 << endl;
ans = min(ans, max(max(x1, x2), max(x3, x4)) - min(min(x1, x2), min(x3, x4)));
}
}
}
printf("%lld\n", ans);
return 0;
}
| #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 ll mod2 = 998244353;
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);
int n; cin >> n;
vector<ll> A(n); rep(i, n) cin >> A[i];
vector<vector<int>> B(n+1, vector<int>(60));
ll ans = 0;
rep(i, n) {
rep(j, 60) {
(ans += ((A[i]>>j)&1 ? i-B[i][j] : B[i][j]) * ((1LL<<j) % mod)) %= mod;
B[i+1][j] = B[i][j] + ((A[i]>>j)&1);
}
}
cout << ans << endk;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define pb push_back
#define mp make_pair
#define ff first
#define INF LLONG_MAX
#define ss second
#define range(x) (x).begin(), (x).end()
#define vll vector<ll>
#define vstr vector<string>
#define vvll vector<vector<ll>>
#define vp vector<pll>
#define vvp vector<vp>
#define mapll map<ll, ll>
#define mapstr smap<string, ll>
#define setll set<ll>
#define setstr set<string>
#define digits(N) floor(log10(N)) + 1
const ll mod = 1e9 + 7;
#define FLUSH fflush(stdout)
#define arr1d_debug(arr, i, ans) \
cout << #arr << '[' << i << "] = " << ans << ' ' << flush
#define arr2d_debug(arr, i, j, ans) \
cout << #arr << '[' << i << ']' << '[' << j << "] = " << ans << ' ' << flush
#define debug1(x) \
cout << #x << " = " << x << endl
#define debug2(x, y) \
cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define debug3(x, y, z) \
cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define newline cout << endl
#define print_container(container) \
for (auto &it : container) \
cout << it << ' '; \
newline;
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
/*
std : merge, rotate, unique, generate, fill, iota
*/
ll ll_scan()
{
ll x;
cin >> x;
return x;
}
string str_scan()
{
string x;
cin >> x;
return x;
}
ll inefficiency(ll x, ll y, vvll &prefix_table)
{
ll ans = 0;
for (ll i = 0; i < 101; i++)
{
ll temp = prefix_table[y + 1][i] - prefix_table[x][i];
if (temp > 1)
ans += temp;
}
return ans;
}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
IOS;
ll t = 1;
// t = ll_scan();
while (t--)
{
ll x = 1, k = 10;
ll n = ll_scan();
list<bool> ans;
if (n == 0)
cout << 0;
else
while (n != 0)
{
bool bit = n % 2;
ans.push_front(bit);
n = ceil(n / -2.0);
x *= -2;
}
for (auto &it : ans)
cout << it;
// newline;
}
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <ctype.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vl = vector<ll>;
using vvl = vector<vl >;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;
#define TR ","
#define TS " "
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define repe(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
ll gcd(ll a, ll b) {
if (a < b) swap(a, b);
if (b == 0) return a;
return gcd(b, a % b);
}
ll lcm(ll x, ll y) {
return x / gcd(x, y) * y;
}
ll waz = 76543217;
void printVector(const vector<int>& vec) {
for (int value : vec) {
cout << value << " ";
}
cout << endl;
}
int main()
{
IO;
ll N; cin >> N;
string ans = "";
if (N == 0) {
cout << 0 << endl;
return 0;
}
while (1) {
if (N % 2 == 0) {
ans = to_string(0) + ans;
N /= -2;
}
else if (N != 1) {
ans = to_string(1) + ans;
if (N >= 0) { N /= -2; }
else { N = N / (-2) + 1; }
}
else if (N == 1) {
ans = to_string(1) + ans;
break;
}
}
cout << ans << endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
vi x,y,id;
ll dis(int i,int j){
return (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
}
double cross(int i,int j){
if(x[i]==x[j]&&y[i]>y[j])return inf;
if(x[i]==x[j]&&y[i]<y[j])return -inf;
if(x[j]<x[i])return (y[i]-y[j])/(double)(x[i]-x[j]);
if(x[j]>x[i])return (y[i]-y[j])/(double)(x[j]-x[i]);
}
vi Convex_Hull(){
int n=x.size();
if(n >= 3){
vi ch;
for(int i=0;i<n;i++){
while(ch.size()>=2&&cross(ch.back(),ch[ch.size()-2])<cross(i,ch.back()))ch.pop_back();
ch.eb(i);
}
ch.eb(n-2);
for(int i=n-3,t=ch.size();i>=0;i--){
while(ch.size()>=t&&cross(ch.back(),ch[ch.size()-2])>cross(i,ch.back()))ch.pop_back();
ch.eb(i);
}
ch.pop_back();
return ch;
}
vi res;
rep(i,2)res.pb(i);
return res;
}
int main(){
ll n;cin>>n;
if(n==2){
rep(i,n)out(0.5);
return 0;
}
vector<PP> v(n);
x=vi(n);y=vi(n);id=vi(n);
rep(i,n)cin>>get<0>(v[i])>>get<1>(v[i]);
rep(i,n)get<2>(v[i])=i;
sort(all(v));
rep(i,n)tie(x[i],y[i],id[i])=v[i];
vi t;
t=Convex_Hull();
// outv(t);
vector<double> ans(n);
rep(i,t.size()){
ll j=i-1,k=i+1;
if(j<0)j+=t.size();
if(k==t.size())k=0;
j=t[j];k=t[k];ll p=t[i];
ll a=dis(k,j),b=dis(p,k),c=dis(p,j);
double d=(b+c-a)/(2*sqrt(b)*sqrt(c));
ans[id[p]]=(pi-acos(d))/(2*pi);
}
double sum=1;
rep(i,t.size())sum-=ans[id[t[i]]];
rep(i,t.size())ans[id[t[i]]]+=sum/t.size();
decimal;
for(double x:ans)out(x);
} | #include<bits/stdc++.h>
using namespace std;
#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 pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
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};
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;
}
struct Dinic {
struct edge {
int to, cap, rever;
edge(int to, int cap, int rever):to(to), cap(cap), rever(rever){}
};
vector< vector<edge> > graph;
vector<int> level, iter;
Dinic(int V):graph(V), level(V), iter(V){}
void add_edge(int from, int to, int cap) {
graph[from].emplace_back(to, cap, graph[to].size());
graph[to].emplace_back(from, 0, graph[from].size()-1);
}
void bfs(int s) {
fill(all(level), -1);
queue<int> que;
level[s] = 0;
que.push(0);
while(que.size()) {
int v = que.front(); que.pop();
for(edge& e : graph[v]) {
if(e.cap > 0 && level[e.to] < 0) {
level[e.to] = level[v] + 1;
que.push(e.to);
}
}
}
}
int dfs(int v, int t, int f) {
if(v == t) return f;
for(int& i = iter[v]; i < graph[v].size(); i++) {
edge& e = graph[v][i];
if(e.cap > 0 && level[v] < level[e.to]) {
int d = dfs(e.to, t, min(e.cap, f));
if(d > 0) {
e.cap -= d;
graph[e.to][e.rever].cap += d;
return d;
}
}
}
return 0;
}
int max_flow(int s, int t) {
int flow = 0;
while(true) {
bfs(s);
if(level[t] < 0) return flow;
fill(all(iter), 0);
int f; while((f = dfs(s, t, inf)) > 0) flow += f;
}
}
};
int main(){
ll n;cin >> n;
Dinic dn(2*n+2);
ll s=0,t=2*n+1;
vpl a(n),b(n);
rep(i,n){
cin >> a[i].fi >> a[i].se;
}
rep(i,n){
cin >> b[i].fi >> b[i].se;
}
rep(i,n){
dn.add_edge(s,i+1,1);
dn.add_edge(i+1+n,t,1);
}
rep(i,n){
rep(j,n){
if(a[i].fi<b[j].fi&&a[i].se<b[j].se){
dn.add_edge(i+1,n+1+j,1);
}
}
}
cout << dn.max_flow(s,t) <<endl;
} | 0 |
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main(){
char str[20];
scanf("%s",str);
reverse(str,str + strlen(str));
printf("%s\n",str);
return 0;
} | #include<iostream>
#include<cstring>
using namespace std;
void reverseChar(char* str);
char str[50],rstr[50];
int i;
int main()
{
cin>>str;
reverseChar(str);
cout<<str << endl;
return 0;
}
void reverseChar(char* str)
{
for(i=0;i<strlen(str)/2;i++)
{
char temp= str[i];
str[i]=str[strlen(str)-i-1];
str[strlen(str)-i-1]=temp;
}
} | 1 |
#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;
bool f(const vector<int>& v1, const vector<int>& v2) {
int c1 = accumulate(v1.begin(), v1.end(), 0);
int c2 = accumulate(v2.begin(), v2.end(), 0);
if (c1 < c2) return false;
if (c1 > c2) return true;
c1 = 0, c2 = 0;
for (int i = 9; i >= 0; i--) {
c1 += v1[i];
c2 += v2[i];
if (c1 > c2) return true;
if (c1 < c2) return false;
}
return true;
}
int main() {
int n, m;
cin >> n >> m;
vector<int> v = {0,2,5,5,4,5,6,3,7,6};
vector<pair<int, int>> vp;
for (int i = 0; i < m; i++) {
int a;
cin >> a;
vp.push_back(make_pair(v[a], -a));
}
sort(vp.begin(), vp.end());
for (int i = 0; i < m; i++) {
vp[i].second *= -1;
}
vector<vector<vector<int>>> res(m, vector<vector<int>>(n + 1, vector<int>(0)));
vector<int> base(10, 0);
for (int i = 0; i * vp[0].first <= n; i++) {
base[vp[0].second] += i;
res[0][n - i * vp[0].first] = base;
base[vp[0].second] = 0;
}
for (int i = 0; i < m - 1; i++) {
for (int j = 0; j <= n; j++) {
if (res[i][j].size() == 0) continue;
vector<int> digit = res[i][j];
for (int k = j / vp[i + 1].first; k >= 0; k--) {
int remain = j - k * vp[i + 1].first;
digit[vp[i + 1].second] += k;
if (res[i + 1][remain].size() == 0 || f(digit, res[i + 1][remain])) {
res[i + 1][remain] = digit;
}
digit[vp[i + 1].second] -= k;
}
}
}
string s;
for (int i = 0; i < 10; i++) {
s += string(res[m - 1][0][i], i + '0');
}
sort(s.begin(), s.end(), greater<char>());
cout << s << endl;
}
| #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
typedef pair<int,int> P;
typedef long long ll;
int main() {
int a, b;
cin >> a >> b;
int sum = 1, cnt = 0;
while(sum < b) {
sum += a-1;
cnt++;
}
cout << cnt << endl;
return 0;
}
| 0 |
#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var)\
cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;
template <typename Iter>
Iter partition(Iter begin, Iter end, Iter pivot) {
if (distance(pivot, end) != 1) {
iter_swap(end -1, pivot);
pivot = end - 1;
}
auto x = end;
for (auto it = begin; it != end; ++it) {
if (it != pivot && *it <= *pivot) {
x = (x == end) ? begin : x + 1;
if (x != it) {
iter_swap(x, it);
}
}
}
x = (x == end) ? begin : x + 1;
iter_swap(x, pivot);
return x;
}
int main() {
int n;
cin >> n;
vector<int> nums;
for (int t, i = 0; i < n; ++i) {
cin >> t;
nums.push_back(t);
}
auto pivot = partition(nums.begin(), nums.end(), nums.end() - 1);
bool first = true;
for (auto it = nums.begin(); it != nums.end(); ++it) {
if (!first)
cout << " ";
first = false;
bool is_pivot = it == pivot;
if (is_pivot)
cout << "[";
cout << *it;
if (is_pivot)
cout << "]";
}
cout << endl;
} | #include <bits/stdc++.h>
#include<math.h>
#include<algorithm>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
using PL = pair<ll, ll> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007
int modpow(ll a, ll n){
if(n == 0) return 1 ;
if(n == 1) return a % mod ;
if(n % 2) return (a * modpow(a, n-1))%mod ;
ll t = modpow(a, n/2) ;
return (t*t) % mod ;
}
int main() {
ll n ;
cin >> n ;
vector<ll> a (n) ;
vector<ll> c (60) ;
rep(i, n) {
cin >> a[i] ;
rep(j, 60){
if(a[i] >> j & 1){
c[j]++ ;
}
}
}
ll ans = 0 ;
ll k = n;
rep(i, n){
rep(j, 60){
if(a[i] >> j & 1){
ans += modpow(2,j)*(k - c[j]) ;
ans %= mod ;
c[j]-- ;
}
else {
ans += modpow(2,j)*c[j] ;
}
}
k-- ;
}
cout << ans << endl ;
} | 0 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
int n;
cin >> n;
vector<int> a(n);
rep(i,n) cin >> a[i];
int ans = 1001001001;
rep(i,n) {
int cnt = 0;
while(a[i] % 2 == 0) {
a[i] /= 2;
cnt++;
}
ans = min(ans, cnt);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;
typedef pair <int, int> pii;
const int N = 3e3 + 5;
const long long INF = 1e18;
const int mod = 998244353;//786433;//998244353;
const double Pi = acos(-1);
void Fastio()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
int n;
int a[200005];
map <int, int> M;
int main()
{
int t = 0;
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
M[a[i]]++;
}
sort(a + 1, a + n + 1);
for(int i = n; i >= 1; i--)
{
if(M[a[i]] == 0)
{
continue;
}
int temp = log2(a[i]);
temp = 1 << (temp + 1);
M[a[i]]--;
if(M[temp - a[i]] > 0)
{
t++;
M[temp - a[i]]--;
}
}
cout << t;
} | 0 |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a) begin(a),end(a)
#define FOR(x,val,to) for(int x=(val);x<int((to));++x)
#define FORE(x,val,to) for(auto x=(val);x<=(to);++x)
#define FORR(x,arr) for(auto &x: arr)
#define FORS(x,plus,arr) for(auto x = begin(arr)+(plus); x != end(arr); ++x)
#define FORREV(x,plus,arr) for(auto x = (arr).rbegin()+(plus); x !=(arr).rend(); ++x)
#define REE(s_) {cout<<s_<<'\n';exit(0);}
#define GET(arr) for(auto &i: (arr)) sc(i)
#define whatis(x) cerr << #x << " is " << x << endl;
#define e1 first
#define e2 second
#define INF 0x7f7f7f7f
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::vector<std::string> vs;
typedef int64_t ll;
typedef uint64_t ull;
#define umap unordered_map
#define uset unordered_set
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
template<class T> ostream& operator<<(ostream &os, set<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) { os<<"("<<P.first<<","<<P.second<<")"; return os; }
inline int fstoi(const string &str){auto it=str.begin();bool neg=0;int num=0;if(*it=='-')neg=1;else num=*it-'0';++it;while(it<str.end()) num=num*10+(*it++-'0');if(neg)num*=-1;return num;}
inline void getch(char &x){while(x = getchar_unlocked(), x < 33){;}}
inline void getstr(string &str){str.clear(); char cur;while(cur=getchar_unlocked(),cur<33){;}while(cur>32){str+=cur;cur=getchar_unlocked();}}
template<typename T> inline bool sc(T &num){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){if(c == EOF) return false;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; return true;}template<typename T, typename ...Args> inline void sc(T &num, Args &...args){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; sc(args...); }
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //s.find_by_order(), s.order_of_key() <- works like lower_bound
template<typename T> using ordered_map = tree<T, int, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
bool srt(pi a, pi b){
return a.e1+a.e2 < b.e1+b.e2;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n;
sc(n);
pi a[n];
FORR(i,a)
sc(i.e1,i.e2);
sort(a,a+n,srt);
ll dp[n+1];
ll LINF = 1e18;
FORR(i,dp)
i = LINF;
dp[0] = 0;
FORR(i,a){
/* whatis(i) */
for(int x = n-1; x >= 0; --x){
/* whatis(x) */
/* whatis(dp[x]) */
if(dp[x] == LINF) continue;
if(dp[x] > i.e1) continue;
/* if(dp[ */
dp[x+1] = min(dp[x+1],dp[x]+i.e2);
}
}
for(int i = n+1; --i;)
if(dp[i] != LINF) REE(i)
}
| #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef vector<int> vi;
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int MAXN = 5050;
const int INF = 0x3f3f3f3f;
int dp[MAXN][MAXN];
vector<pii> prt;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
int n;
cin >> n;
rep (i, 1, n) {
int h, p;
cin >> h >> p;
prt.emplace_back(h, p);
}
sort(all(prt), [&] (pii a, pii b) {
return a.fst + a.sed < b.fst + b.sed;
});
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
auto chkMin = [&] (int & a, int b) {
a = ~a ? min(a, b) : b;
};
int res = 0;
rep (i, 1, n) {
int h = prt[i - 1].fst;
int p = prt[i - 1].sed;
rep (j, 0, i - 1) if (~dp[i - 1][j]) {
chkMin(dp[i][j], dp[i - 1][j]);
if (dp[i - 1][j] <= h) {
res = max(res, j + 1);
chkMin(dp[i][j + 1], dp[i - 1][j] + p);
}
}
}
cout << res << endl;
return 0;
} | 1 |
//Author: AnandRaj anand873
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "
const int MOD = 998244353,MAX = 1e6+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
if(p==0) return 1;
ll z=powN(a,p/2);
z=(z*z)%MOD;
if(p%2) z=(z*a)%MOD;
return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX, true);
vector<int> MinDiv(MAX);
void Sieve()
{
is_prime[0] = is_prime[1] = false;
int i,j;
for (i = 2; i*i <= MAX; i++)
{
if (is_prime[i])
{
MinDiv[i]=i;
for (j = i * i; j <= MAX; j += i)
{
is_prime[j] = false;
MinDiv[j]=i;
}
}
}
for(int i=2;i<=MAX;i++) if(is_prime[i]) MinDiv[i]=i;
}
//////////////////Sieve////////////////////
int main()
{
int n,k;
cin>>n>>k;
vi A(n);
take(A,0,n);
sort(all(A));
int gcd = 0;
for(int i=0;i<n;i++) gcd = __gcd(gcd,A[i]);
bool can=false;
for(int i=n-1;i>=0;i--)
{
if(A[i]>=k&&(A[i]-k)%gcd==0) can=true;
}
if(can) cout<<"POSSIBLE"<<endl;
else cout<<"IMPOSSIBLE"<<endl;
} | #include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define int ll
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
int read(){
int i;
scanf("%lld",&i);
return i;
}
using vi=vector<int>;
#define PB push_back
#define ALL(x) x.begin(),x.end()
int gcd(int a,int b){
return b?gcd(b,a%b):a;
}
signed main(){
int n=read(),k=read();
vi a(n);
REP(i,n)a[i]=read();
int mx=*max_element(ALL(a));
FOR(i,1,n)
a[0]=gcd(a[0],a[i]);
if(k%a[0]==0&&k<=mx)
cout<<"POSSIBLE"<<endl;
else
cout<<"IMPOSSIBLE"<<endl;
}
| 1 |
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
#define f(i,a,b) for(int i = a; i < b; i++)
// #define endl '\n'
using ll = long long;
using db = long double;
using ii = pair<int, int>;
const int N = 1e5+5, LG = 17, MOD = 998244353;
const int SQ = 390;
const long double EPS = 1e-7;
int n, x[N], L;
int tb[N][17];
int32_t main(){
#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif // ONLINE_JUDGE
cin >> n;
f(i,0,n){
cin >> x[i];
}
cin >> L;
for(int i = 0, j = 0; i < n; i++){
while(j<n&&x[j]-x[i]<=L)j++;
tb[i][0] = j - 1;
}
f(k,1,17)
for(int i = 0; i <n; i++)
tb[i][k] = tb[tb[i][k-1]][k-1];
int q; cin >> q;
while(q--){
int x, y; cin >> x >> y; --x,--y;
if(x>y)swap(x,y);
int ans = 0;
for(int k = 16; k >= 0; --k)
if(tb[x][k] < y){
x = tb[x][k];
ans += (1 << k);
}
cout <<ans+1<<'\n';
}
return 0;
}
| #include <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
static const int MAX = 100000;
vector<int> graph[MAX];
vector<bool> discovered(MAX, false);
vector<int> prenum(MAX, 0), parent(MAX, 0), lowest(MAX, 0);
int V, E;
int t = 0;
void dfs(int vertex, int prev)
{
prenum[vertex] = lowest[vertex] = ++t;
discovered[vertex] = true;
for (auto it = graph[vertex].begin(); it != graph[vertex].end(); ++it) {
if (!discovered[*it]) {
parent[*it] = vertex;
dfs(*it, vertex);
lowest[vertex] = min(lowest[vertex], lowest[*it]);
} else if (*it != prev) {
lowest[vertex] = min(lowest[vertex], prenum[*it]);
}
}
}
set<int> arts;
void art_points()
{
dfs(0, -1);
int num_root_children = 0;
for (int i = 1; i < V; i++) {
int p = parent[i];
if (p == 0)
num_root_children++;
else if (prenum[p] <= lowest[i]) {
arts.insert(p);
}
}
if (num_root_children > 1) {
arts.insert(0);
}
for (auto it = arts.begin(); it != arts.end(); ++it)
cout << *it << endl;
}
int main()
{
cin >> V >> E;
for (int i = 0; i < E; i++) {
int s, t;
cin >> s >> t;
graph[s].push_back(t);
graph[t].push_back(s);
}
art_points();
return 0;
}
| 0 |
#include <bits/stdc++.h>
#define nmax 100005
using namespace std;
string s;
int n,ans[nmax];
bool check(){
for(int i=2;i<n;i++){
if((ans[i-1]==0)){
if((s[i-1]=='o'))
ans[i]=ans[i-2];
else
ans[i]=1-ans[i-2];
}
else{
if(s[i-1]=='o')
ans[i]=1-ans[i-2];
else
ans[i]=ans[i-2];
}
}
if(ans[0]==0){
if(s[0]=='o' && (ans[n-1]!=ans[1])){
return 0;
}
if(s[0]=='x' && (ans[n-1]==ans[1])){
return 0;
}
}
else{
if(s[0]=='x' && (ans[n-1]!=ans[1])){
return 0;
}
if(s[0]=='o' && (ans[n-1]==ans[1])){
return 0;
}
}
if(ans[n-1]==0){
if(s[n-1]=='o' && (ans[n-2]!=ans[0])){
return 0;
}
if(s[n-1]=='x' && (ans[n-2]==ans[0])){
return 0;
}
}
else{
if(s[n-1]=='x' && (ans[n-2]!=ans[0])){
return 0;
}
if(s[n-1]=='o' && (ans[n-2]==ans[0])){
return 0;
}
}
return 1;
}
int main(){
cin >> n;
cin >> s;
bool flag=0;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
ans[0]=i;
ans[1]=j;
if(check()){
flag=1;
break;
}
}
if(flag){
break;
}
}
if(!flag){
cout << -1 << endl;
}
else{
for(int i=0;i<n;i++){
if(!ans[i]){
cout << 'S';
}
else{
cout << 'W';
}
}
}
cout << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
int main(){
int X, Y;
cin >> X >> Y;
int ans = 0;
if(X == 1 && Y == 1) ans += 400000;
if(X == 1) ans += 300000;
if(X == 2) ans += 200000;
if(X == 3) ans += 100000;
if(Y == 1) ans += 300000;
if(Y == 2) ans += 200000;
if(Y == 3) ans += 100000;
cout << ans << endl;
}
| 0 |
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i,0,n)
#define BFOR(bit,a,b) for(int bit = (a); bit < (1<<(b)); ++bit)
#define BREP(bit,n) BFOR(bit,0,n)
using namespace std;
using ll = long long;
int main() {
ll x;
cin >> x;
ll ans = (x/11) * 2;
if(x%11 > 0 && x%11 <= 6) ans += 1;
if(x%11 >= 7) ans += 2;
cout << ans << endl;
} | #include<iostream>
using namespace std;
int main()
{
int a,sum,e,f;
cin>>a;
e=a*a;
f=e*a;
sum=a+e+f;
cout<<sum<<endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, x[N], y[N], ansd = INT_MAX;
char d[N];
void solvelr()
{
vector<int> a[N], b[N];
for (int i = 0; i < n; ++i)
{
if (d[i] == 'L')
a[y[i]].push_back(x[i]);
else if (d[i] == 'R')
b[y[i]].push_back(x[i]);
}
for (int i = 0; i < N; ++i)
{
sort(a[i].begin(), a[i].end());
sort(b[i].begin(), b[i].end());
}
for (int i = 0; i < N; ++i)
{
for (int xc: b[i])
{
auto it = upper_bound(a[i].begin(), a[i].end(), xc);
if (it == a[i].end())
continue;
else
{
int d = *it - xc;
d *= 5;
ansd = min(ansd, d);
}
}
}
}
void solveud()
{
vector<int> a[N], b[N];
for (int i = 0; i < n; ++i)
{
if (d[i] == 'U')
a[x[i]].push_back(y[i]);
else if (d[i] == 'D')
b[x[i]].push_back(y[i]);
}
for (int i = 0; i < N; ++i)
{
sort(a[i].begin(), a[i].end());
sort(b[i].begin(), b[i].end());
}
for (int i = 0; i < N; ++i)
{
for (int yc: a[i])
{
auto it = upper_bound(b[i].begin(), b[i].end(), yc);
if (it == b[i].end())
continue;
else
{
int d = *it - yc;
d *= 5;
ansd = min(ansd, d);
}
}
}
}
bool cmp(pair<int, int> lhs, pair<int, int> rhs)
{
return lhs.first < rhs.first;
}
void solve1()
{
vector<pair<int, int> > a[2 * N];
for (int i = 0; i < n; ++i)
{
int dif = x[i] - y[i];
a[dif + 200000].push_back(make_pair(x[i], d[i]));
}
for (int i = 0; i < 2 * N; ++i)
{
int l = -1, r = -1, u = -1, d = -1;
sort(a[i].begin(), a[i].end(), cmp);
for (pair<int, int> p: a[i])
{
if (p.second == 'L')
{
if (u != -1)
ansd = min(ansd, 10 * (p.first - u));
l = p.first;
}
else if (p.second == 'R')
r = p.first;
else if (p.second == 'U')
u = p.first;
else if (p.second == 'D')
{
if (r != -1)
ansd = min(ansd, 10 * (p.first - r));
d = p.first;
}
}
}
}
void solve2()
{
vector<pair<int, int> > a[2 * N];
for (int i = 0; i < n; ++i)
{
int dif = x[i] + y[i];
a[dif].push_back(make_pair(x[i], d[i]));
}
for (int i = 0; i < 2 * N; ++i)
{
int l = -1, r = -1, u = -1, d = -1;
sort(a[i].begin(), a[i].end(), cmp);
for (pair<int, int> p: a[i])
{
if (p.second == 'L')
{
if (d != -1)
ansd = min(ansd, 10 * (p.first - d));
l = p.first;
}
else if (p.second == 'R')
r = p.first;
else if (p.second == 'U')
{
if (r != -1)
ansd = min(ansd, 10 * (p.first - r));
u = p.first;
}
else
d = p.first;
}
}
}
int main(int argc, char const *argv[])
{
cin >> n;
for (int i = 0; i < n; ++i)
{
cin >> x[i] >> y[i] >> d[i];
}
solvelr();
solveud();
solve1();
solve2();
if (ansd == INT_MAX)
cout << "SAFE" << '\n';
else
cout << ansd << '\n';
return 0;
} | #include <iostream>
#include <string>
using namespace std;
void shake(int D[], char c) {
int tmp;
switch (c) {
case 'S':
tmp = D[0];
D[0] = D[4];
D[4] = D[5];
D[5] = D[1];
D[1] = tmp;
break;
case 'E':
tmp = D[0];
D[0] = D[3];
D[3] = D[5];
D[5] = D[2];
D[2] = tmp;
break;
case 'W':
tmp = D[0];
D[0] = D[2];
D[2] = D[5];
D[5] = D[3];
D[3] = tmp;
break;
case 'N':
tmp = D[0];
D[0] = D[1];
D[1] = D[5];
D[5] = D[4];
D[4] = tmp;
break;
case 'R':
tmp = D[1];
D[1] = D[3];
D[3] = D[4];
D[4] = D[2];
D[2] = tmp;
break;
case 'L':
tmp = D[1];
D[1] = D[2];
D[2] = D[4];
D[4] = D[3];
D[3] = tmp;
break;
}
}
void print(int D[], int n)
{
int i;
cout << "\n---" << n << "---\n";
for (i=0; i<6; i++) cout << "D[" << i << "]:" << D[i] << "\n";
}
int main()
{
int n;
cin >> n;
int D[n][6], i, j, x, y;
bool is=false;
string op;
for (i=0; i<n; i++) for (j=0; j<6; j++) cin >> D[i][j];
for (x=0; x<n; x++) {
for (y=0; y<n; y++) {
if (x==y) break;
op = "NNNNRNNNN";
for (i=0; i<op.size(); i++) {
if (D[x][0]==D[y][0]&&D[x][5]==D[y][5]) break;
else shake(D[y], op[i]);
}
op = "RRRR";
for (i=0; i<op.size(); i++) {
if (D[x][0]==D[y][0]&&D[x][1]==D[y][1]) {
if (D[x][2]==D[y][2]&&D[x][3]==D[y][3]) {
if (D[x][4]==D[y][4]&&D[x][5]==D[y][5]) {
is=true;
break;
}
}
}
shake(D[y], op[i]);
}
if (is) break;
}
if (is) break;
}
if (is) cout << "No\n";
else cout << "Yes\n";
} | 0 |
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<algorithm>
#include<functional>
using namespace std;
int n,q;
int a=0;
int c=0;
int s[10000]={};
int t[10000]={};
int main()
{
cin>>n;
for(int i=0;i<n;i++)
{
cin>>s[i];
}
cin>>q;
for(int j=0;j<q;j++)
{
cin>>t[j];
}
for(int k=0;k<n;k++)
{
for(int l=0;l<q;l++)
{
a=s[k]^t[l];
if(a==0)
{
c+=1;
t[l]=-1;
}
}
}
cout<<c<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
long long N,a,c=1,A[100002]={};A[0]=3;
cin>>N;
for(int i=0;i<N;i++){
scanf("%d",&a);
c*=(A[a]-A[a+1]++);
c%=1000000007;
}
cout<<c<<endl;
} | 0 |
#include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
using namespace std;
#define gcu getchar_unlocked
int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;}
int in() {return in(gcu());}
bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bool scan(char &c){c=gcu();gcu();return c!=EOF;}
//bool scan(string &s){int c;s="";
// for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
//vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T> vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef vo
int main() {
for (int e, m; (e = m = in());) {
for (int z = cbrt(e) + 0.00001; z >= 0; z--) {
int te = e - z * z * z;
int y = (int)sqrt(te);
int tm = z + y + te - y * y;
if (y > m)
break;
m = min(m, tm);
}
out(m, '\n');
}
}
| #include <iostream>
#define MAXN 1000001;
using namespace std;
int m,e,sum1,sum2,x,y,z,minn;
int main(){
while(1){
cin >>e;
if(e==0)break;
x=y=z=0;
minn=MAXN;
while(1){
sum1=z*z*z;
if(e<sum1)break;
y=0;
while(1){
sum2=sum1+y*y;
if(e<sum2)break;
if(y+z+(e-sum2)<minn)minn=y+z+(e-sum2);
y++;
}
z++;
}
cout <<minn<<endl;
}
} | 1 |
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
//typedef complex<double> P;
typedef pair<int, int> P;
const int MAX_V = 100010;
const int INF = 1e9 + 7;
int dijkstra(const vector< vector<P> > &cost, int s, int t, int V){
priority_queue<P, vector<P>, greater<P> > open;
open.push(P(s, 0));
int closed[MAX_V];
REP(i, V) closed[i] = INF;
while(!open.empty()){
P tmp = open.top(); open.pop();
int now = tmp.first, c = tmp.second;
if(closed[now] < c) continue;
closed[now] = c;
REP(i, cost[now].size()){
int next = cost[now][i].first, nc = cost[now][i].second;
if(nc == INF || c + nc >= closed[next]) continue;
closed[next] = c + nc;
open.push(P(next, closed[next]));
}
}
REP(i, V){
if(closed[i] == INF) cout <<"INF" <<endl;
else cout <<closed[i] <<endl;
}
return closed[t];
}
int main() {
int V, E, r;
cin >>V >>E >>r;
vector< vector<P> > cost(V);
REP(i, E){
int f, t, c; cin >>f >>t >>c;
cost[f].push_back(P(t, c));
}
//REP(i, E){
// if((int)cost[i].size() <= 0) continue;
// SORT(cost[i]);
// vector<P> tmp;
// int now = cost[i][0].first;
// tmp.push_back(cost[i][0]);
// FOR(j, 1, cost[i].size()){
// if(now == cost[i][j].first) continue;
// now = cost[i][j].first;
// tmp.push_back(cost[i][j]);
// }
// cost[i] = tmp;
//}
dijkstra(cost, r, -1, V);
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct edge{ int u,v,cost; };
vector<edge> edges;
int uf_par[10000];
int uf_rank[10000];
void uf_init(int uf_n){
for(int i = 0;i < uf_n;i++){
uf_par[i] = i;
uf_rank[i] = 0;
}
}
int uf_find(int uf_x){
if(uf_par[uf_x] == uf_x) return uf_x;
else return uf_par[uf_x] = uf_find(uf_par[uf_x]);
}
void uf_unite(int uf_x,int uf_y){
uf_x = uf_find(uf_x);
uf_y = uf_find(uf_y);
if(uf_x == uf_y) return;
if(uf_rank[uf_x] < uf_rank[uf_y]){
uf_par[uf_x] = uf_y;
}else{
uf_par[uf_y] = uf_x;
if(uf_rank[uf_x] == uf_rank[uf_y]) uf_rank[uf_x]++;
}
}
bool uf_same(int uf_x,int uf_y){
return uf_find(uf_x) == uf_find(uf_y);
}
bool krus_comp(const edge& e1, const edge& e2){
return e1.cost < e2.cost;
}
int kruskal(int V){
sort(edges.begin(),edges.end(),krus_comp);
uf_init(V);
int krus_res = 0;
for(int i = 0;i < edges.size();i++){
edge krus_e = edges[i];
if(!uf_same(krus_e.u,krus_e.v)){
uf_unite(krus_e.u,krus_e.v);
krus_res += krus_e.cost;
}
}
return krus_res;
}
int main(){
int V,E;
cin >> V >> E;
for(int i = 0;i < E;i++){
int a,b,c;
cin >> a >> b >> c;
edges.push_back({a,b,c});
}
cout << kruskal(V) << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;
vector<ll> used(100010), tp;
vector<vector<ll>> G(100010);
/*
void dfs(ll v){
if(used[v]) return;
used[v] = 1;
for(auto& u:G[v]){
dfs(u);
}
tp.push_back(v);
}*/
int main(){
ll N,M;
cin >> N >> M;
vector<ll> rc(N),deg(N);
ll a,b;
rep(i,N-1+M){
cin >> a >> b;
a--;b--;
rc[b]++;
G[a].push_back(b);
deg[b]++;
}
ll root;
rep(i,N){
if(rc[i] == 0){
root = i;
break;
}
}
queue<ll> que;
vector<ll> par(N,-1);
que.push(root);
while(!que.empty()){
ll v = que.front();
que.pop();
for(auto& u:G[v]){
deg[u]--;
if(deg[u] == 0){
par[u] = v;
que.push(u);
}
}
}
rep(i,N){
cout << par[i]+1 << endl;
}
/*dfs(root);
vector<ll> v(N);
rep(i,N){
v[tp[i]] = i;
}
//PR(v,N);
vector<ll> ans(N,-1);
rep(i,N){
for(auto& u:G[i]){
if(v[i] > v[u]){
//cout << u+ << endl;
ans[i] = u;
break;
}
}
}
rep(i,N){
cout << ans[i]+1 << endl;
}
/*queue<ll> que;
que.push(root);
prev[root] = -1;
used[root] = 1;*/
/*
while(!que.empty()){
ll v = que.front();
que.pop();
for(auto& u:G[v]){
if(used[u] != 0){
G[prev[u]].erase(lower_bound(G[prev[u]].begin(),G[prev[u]].end(),u));
prev[u] = v;
que.push(u);
continue;
}
used[u] = 1;
prev[u] = v;
que.push(u);
}
}*/
/*rep(i,N){
cout << prev[i]+1 << endl;
}*/
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;
#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back
int main()
{
ll N, M;
cin >> N >> M;
vec s(M), c(M);
REP(i,0,M) {
cin >> s[i] >> c[i];
--s[i];
}
ll d = 1;
bool f = true;
REP(i,0,N) d *= 10;
REP(i,N==1?0:d/10,d) {
string S = to_string(i);
f = true;
REP(j,0,M) {
if(!(s[j] < SZ(S) && S[s[j]]-'0' == c[j])) {
f = false;
break;
}
}
if(f) {
PR(i);
break;
}
}
if(!f) PR(-1);
return 0;
}
/*
*/ | 0 |
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
int main() {
string s;
cin >> s;
s[3] = '8';
cout << s << endl;
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
string S;
cin >> S;
cout << S.substr(0, S.size() - string("FESTIVAL").size()) << endl;
}
| 0 |
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define x first
#define y second
typedef pair<int,int> pii;
typedef long long ll;
const int MAXN=100005;
int n,m;
int co[MAXN];
bool vis[MAXN];
vector<int> E[MAXN];
bool dfs(int u){
bool tag=1;
vis[u]=1;
for(int i=0;i<(int)E[u].size();i++){
int v=E[u][i];
if(vis[v]) tag&=(co[v]!=co[u]);
else{
co[v]=co[u]^1;
tag&=dfs(v);
}
}
return tag;
}
int main(){
//freopen("squared.in","r",stdin);
//freopen("squared.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
E[u].push_back(v);
E[v].push_back(u);
}
int cnt=0,p=0,q=0;
for(int i=1;i<=n;i++){
if(vis[i]) continue;
if(!E[i].size()) cnt++;
else{
if(dfs(i)) q++;
else p++;
}
}
printf("%lld\n",(ll)cnt*cnt+2ll*cnt*(n-cnt)+p*p+2ll*p*q+2ll*q*q);
fclose(stdin);
fclose(stdout);
}
| #pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int t[101];
int pri[26];
int res = 0;
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++)
{
pr[i] = i;
}
}
int parent(int x) {
if (x == pr[x]) return x;
return pr[x] = parent(pr[x]);
}
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py) return false;
if (px < py) {
pr[py] = px;
}
else {
pr[px] = py;
}
return true;
}
void solv() {
int n;
cin >> n;
uini(n);
pair<ll, int> xr[100010];
pair<ll, int> yr[100010];
for (size_t i = 1; i <= n; i++)
{
ll x, y;
cin >> x >> y;
xr[i] = pair<ll, int>(x, i);
yr[i] = pair<ll, int>(y, i);
}
sort(xr, xr + n + 1);
sort(yr, yr + n + 1);
map<ll, vector<pair<int, int>>> mx;
for (int i = 2; i <= n; i++)
{
ll rem = abs( xr[i].first - xr[i - 1].first);
mx[rem].push_back(pii(xr[i].second, xr[i - 1].second));
ll remy = abs(yr[i].first - yr[i - 1].first);
mx[remy].push_back(pii(yr[i].second, yr[i - 1].second));
}
ll res = 0;
for (map<ll, vector<pii>>::iterator i = mx.begin(); i != mx.end(); i++)
{
ll val = i->first;
vector<pii> v = i->second;
for (int j = 0; j < v.size(); j++)
{
if (unit(v[j].first, v[j].second)) {
res += val;
}
}
}
cout << res << endl;
}
int main() {
solv();
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b){
if(a > b){
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b){
if(a < b){
a = b;
return true;
}
return false;
}
int main(){
int n;
ll T;
cin >> n >> T;
ll ans = 0;
vector<ll> v(n);
for(int i = 0; i < n; i++){
cin >> v[i];
}
for(int i = 1; i < n; i++){
ans += min(T, v[i] - v[i-1]);
}
ans += T;
cout << ans << endl;
return 0;
}
| #include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
typedef uint64_t ull;
typedef int64_t sll;
static const ull MOD = 1000000007LL;
int n;
int k;
int q;
ull a[200019];
ull umin (ull a, ull b) {
return (a < b) ? a : b;
}
ull umax (ull a, ull b) {
return (a > b) ? a : b;
}
ull solve () {
sll i, j, ki;
ull res = 0;
ull allxor = 0;
for (i = 0; i < n; i++) {
allxor ^= a[i];
}
for (i = 0; i < n; i++) {
a[i] &= ~allxor;
}
ull rank = 0;
for (i = 59; i >= 0; i--) {
for (j = rank; j < n; j++) {
if (a[j] & (1LL << i)) break;
}
if (j == n) {
continue;
}
if (j > rank) a[rank] ^= a[j];
for (j = rank + 1; j < n; j++) {
a[j] = umin(a[j], a[j] ^ a[rank]);
}
rank++;
}
ull x = 0;
for (i = 0; i < n; i++) {
x = umax(x, x ^ a[i]);
}
res = (x * 2) + allxor;
return res;
}
int main(void){
scanf("%d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
}
printf("%lld\n", solve());
return 0;
}
| 0 |
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define INF 100000005
#define MAX 100001
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
bool b[501];
int main(){
int n, m, t1,t2;
while(1){
stack<int> s[501];
scanf("%d%d", &n, &m);
if(!n)break;
fill(b, b+501, false);
rep(i,m){
scanf("%d%d", &t1, &t2);
s[t1].push(t2);
s[t2].push(t1);
}
while(!s[1].empty()){
t1 = s[1].top();s[1].pop();
b[t1] = 1;
while(!s[t1].empty()){
t2 = s[t1].top();s[t1].pop();
b[t2] = true;
}
}
int ans = 0;
rrep(i,n)if(b[i]&&i!=1)ans++;
printf("%d\n", ans);
}
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int countup_days(int m, int d) // m月d日が、1月1日から何日目か返す
{
int sum = 0;
const int month[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,};
for (int i=1; i<m; i++) {
sum += month[i];
}
return sum + d -1;
}
string what_day(int days) // 1/1からdays日後は何曜日か文字列を返す
{
string day[] = {"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"};
return day[days%7];
}
int main()
{
int m, d;
while (true) {
cin >> m >> d;
if (m==0 && d==0)
break;
cout << what_day(countup_days(m, d)) << endl;
}
} | 0 |
#include <climits>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>
typedef std::vector<int> TList;
long long int c;
void merge(TList& A, int left, int mid, int right)
{
int n1 = mid - left;
int n2 = right - mid;
TList L(A.begin() + left, A.begin() + left + n1);
L.push_back(INT_MAX);
TList R(n2+1);
for(int i = 0; i < n2; ++i){
R[i] = A[mid + i];
}
R[n2] = INT_MAX;
int i = 0;
int j = 0;
for(int k = left; k < right; ++k){
if(L[i] <= R[j]){
A[k] = L[i];
i = i + 1;
}
else{
A[k] = R[j];
j = j + 1;
c += L.size() - 1 - i;
}
}
}
void mergeSort(TList& A, int left, int right)
{
if(left+1 < right){
int mid = (left + right)/2;
mergeSort(A, left, mid);
mergeSort(A, mid, right);
merge(A, left, mid, right);
}
}
int main()
{
int n;
std::cin >> n;
TList A(n);
for(std::size_t i = 0; i < n; ++i){
std::cin >> A[i];
}
c = 0;
mergeSort(A, 0, n);
std::cout << c << std::endl;
} | #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
template<typename T>
struct BIT {
int n;
vector<T> d;
BIT(int n=0):n(n),d(n+1) {}
void add(int i, T x=1) {
for (; i <= n; i += i&-i) {
d[i] += x;
}
}
T sum(int i) {
T x = 0;
for (; i; i -= i&-i) {
x += d[i];
}
return x;
}
T sum(int l, int r) {
return sum(r) - sum(l-1);
}
};
signed main()
{
cin.tie( 0 ); ios::sync_with_stdio( false );
ll n; cin>>n;
vll a(n);
rep(i,n) cin>>a[i];
auto b=a;
vsort(b);
b.erase(unique(all(b)),b.end());
// rep(i,b.size()) cout<<b[i]<<' ';
// cout<<endl;
BIT<ll> bit(b.size()+5);
ll ans=0;
rep(i,n){
ll rank=lower_bound(all(b),a[i])-b.begin()+1;
// cout<<rank<<endl;
ans+=i-bit.sum(rank);
bit.add(rank);
}
cout<<ans<<endl;
}
| 1 |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
inline int read()
{
int x = 0, f = 1; char ch = getchar();
while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
return x * f;
}
const int N = 5100;
int n,tot; ll a[N][N];
int vis[N * 20],pri[N];
void init()
{
vis[1] = 1;
for(int i = 2;i <= 10000;i ++)
{
if(!vis[i]) pri[++ tot] = i;
for(int j = 1;j <= tot && pri[j] * i <= 10000;j ++)
{
vis[i * pri[j]] = 1;
if(i % pri[j] == 0) break;
}
}
}
ll gcd(ll x,ll y){return y ? gcd(y,x % y) : x;}
ll lcm(ll x,ll y){if(!x || !y) return x | y; return x / gcd(x,y) * y;}
int main()
{
n = read(); init();
if(n == 2) {puts("4 7\n23 10"); return 0;}
for(int i = 1;i <= n;i ++)
for(int j = (i + 1 & 1) + 1;j <= n;j += 2)
a[i][j] = pri[(i + j) / 2] * pri[n + (i - j) / 2 + (n + 1) / 2];
for(int i = 1;i <= n;i ++)
for(int j = (i & 1) + 1;j <= n;j += 2)
a[i][j] = lcm(lcm(a[i - 1][j],a[i][j - 1]),lcm(a[i][j + 1],a[i + 1][j])) + 1;
for(int i = 1;i <= n;i ++,cout << "\n") for(int j = 1;j <= n;j ++) cout << a[i][j] << " ";
return 0;
}
| #include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100010
int a[5][MAXN],n,tg[5],to[MAXN];
int Abs(int x)
{
return x>=0?x:-x;
}
int main()
{
scanf("%d",&n);
for(int i=0;i<3;i++)
for(int j=1;j<=n;j++)
scanf("%d",&a[i][j]);
for(int i=1;i<=n;i++)
{
to[i]=a[1][i]/3+1;
if(!((a[0][i]-a[1][i]==-1&&a[1][i]-a[2][i]==-1&&a[0][i]%3==1)||(a[0][i]-a[1][i]==1&&a[1][i]-a[2][i]==1&&!(a[0][i]%3)))||(Abs(i-to[i])&1))
{
printf("No\n");
return 0;
}
tg[i&1]^=(a[0][i]>a[1][i]);
}
for(int i=1;i<=n;i++)
{
while(to[i]!=i)
{
tg[i&1^1]^=1;
swap(to[i],to[to[i]]);
}
}
if(tg[0]||tg[1]) printf("No\n");
else printf("Yes\n");
} | 0 |
#include <iostream>
#include <vector>
using namespace std;
#define SENTINEL 2000000000
long long merge(vector<int>& array, int left, int mid, int right) {
long long cnt = 0; // 転倒数を数える
// 分割した配列LとRを生成
int n1 = mid - left; // Lの大きさ
int n2 = right - mid; // Rの大きさ
vector<int> L(n1 + 1);
vector<int> R(n2 + 1);
for (int i = 0; i < n1; ++i) {
L[i] = array[left + i];
}
for (int i = 0; i < n2; ++i) {
R[i] = array[mid + i];
}
L[n1] = SENTINEL;
R[n2] = SENTINEL;
// LとRを比べて,もとの配列へソート
int i = 0, j = 0;
for (int k = left; k < right; ++k) {
if (L[i] <= R[j]) {
array[k] = L[i++];
} else {
array[k] = R[j++];
cnt += n1 - i;
}
}
return cnt;
}
long long mergeSort(vector<int>& array, int left, int right) {
int mid;
long long cnt1, cnt2, cnt3;
if (left + 1 < right) {
mid = (left + right) / 2;
cnt1 = mergeSort(array, left, mid);
cnt2 = mergeSort(array, mid, right);
cnt3 = merge(array, left, mid, right);
return cnt1 + cnt2 + cnt3;
} else {
return 0;
}
}
int main() {
int n;
cin >> n;
vector<int> array(n);
for (int i = 0; i < n; ++i) {
cin >> array[i];
}
long long ans = mergeSort(array, 0, n);
cout << ans << endl;
return 0;
}
| #include <stdio.h>
#include <limits.h>
#define MAX 200000
#define INF INT_MAX
typedef long long ll;
void merge(int*, int, int, int);
void mergesort(int*, int, int);
ll ans;
int n, a[MAX];
int main(){
int i;
scanf("%d" ,&n);
for(i = 0 ; i < n ; i++){
scanf("%d" ,a + i);
}
mergesort(a,0,n);
printf("%lld\n" ,ans);
return 0;
}
void merge(int a[], int left, int mid, int right){
int n1 = mid - left, n2 = right - mid;
int L[n1+1], R[n2+1], i, j, k;
for(i = 0 ; i < n1 ; i++){
L[i] = a[left + i];
}
for(i = 0 ; i < n2 ; i++){
R[i] = a[mid + i];
}
L[n1] = R[n2] = INF;
for(i = 0, j = 0, k = left ; k < right ; k++){
if(i < n1 && (j == n2 || L[i] <= R[j])){
a[k] = L[i++];
}else{
ans += (n1 + n2) / 2 - i;
a[k] = R[j++];
}
}
}
void mergesort(int a[], int left, int right){
int mid;
if(left + 1 < right){
mid = (left + right) / 2;
mergesort(a, left, mid);
mergesort(a, mid, right);
merge(a, left, mid, right);
}
}
| 1 |
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
int main(){
int n,memo;
priority_queue<int,vector<int>,greater<int> > que;
cin >> n;
int a[n];
rep(i,0,n){
cin >> a[i];
}
sort(a,a+n);
rep(i,1,sqrt(a[n-1])+1){
rep(j,0,n){
if(a[j] % i)break;
else if(j == n-1)que.push(i);
}
if(a[n-1]/i == i)continue;
rep(j,0,n){
if(a[j] % (a[n-1]/i))break;
else if(j == n-1)que.push(a[n-1]/i);
}
}
while(!que.empty()){
if(que.top() == memo){
que.pop();
continue;
}
memo = que.top(); que.pop();
cout << memo << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
using ll = long long;
ll gcd(ll a, ll b){
//cout << "a : " << a << "b : " << b << endl;
if(b == 0)
return a;
else
return gcd(b, a % b);
}
ll lcm(ll a, ll b){
ll g = gcd(a, b);
return a / g * b;
}
int main(){
int n;
cin >> n;
set<int> s;
if (n == 2){
ll a, b;
cin >> a >> b;
ll g = gcd(a, b);
for (int i = 1; i <= sqrt(g); i++){
if(g % i==0){
s.insert(i);
s.insert(g / i);
}
}
for (auto itr = s.begin(); itr != s.end(); itr++){
cout << *itr << endl;
}
}else{
ll a, b, c;
cin >> a >> b >> c;
ll g = gcd(a, b);
//cout << g << endl;
g = gcd(g, c);
//cout << g << endl;
for (int i = 1; i <= sqrt(g); i++)
{
if(g % i==0){
s.insert(i);
s.insert(g / i);
}
}
for (auto itr = s.begin(); itr != s.end(); itr++){
cout << *itr << endl;
}
}
return 0;
}
| 1 |
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;
string convert(string str) {
int idx = 0;
for (;;) {
idx = str.find("Hoshino", idx);
if (idx == string::npos) break;
str.replace(idx, 7, "Hoshina");
idx += 7;
}
return str;
}
int main() {
int n;
string str;
getline(cin, str);
n = atoi(str.c_str());
for (int i = 0; i < n; i++) {
getline(cin, str);
cout << convert(str) << endl;
}
return 0;
} | #include <stdio.h>
#include <string.h>
int main()
{
int n;
char *p;
char str[1000];
scanf("%d\n",&n);
while(n--){
gets(str);
for(p;p=strstr(str,"Hoshino");)p[6]='a';
puts(str);
}
return 0;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int main(){
long long n,ans = 1;
map<int,long long> prime;
cin >> n;
for(int num = n;2 <= num;num--){
int buf = num;
for(int i = 2;i * i<= n;i++){
int count = 0;
while(buf % i == 0)buf /= i,count++;
prime[i] += count;
}
if(buf != 1)prime[buf]++;
}
for(auto pri : prime){
ans = ans * (pri.second + 1) % MOD;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n;
char s[maxn];
typedef long long ll;
const ll mod = 1e9 + 7;
ll fac(int x) { ll ret = 1; for(int i = 1; i <= x; ++i) ret = ret * i % mod; return ret;}
ll f(int i, int j)
{
if(i == 0) return j == 0;
if(s[i] == 'B')
{
if(j & 1)
return f(i - 1, j - 1);
else
return f(i - 1, j + 1) * (j + 1) % mod;
}
else
{
if(j & 1)
return f(i - 1, j + 1) * (j + 1) % mod;
else if(j > 0)
return f(i - 1, j - 1);
else
return 0;
}
}
int main()
{
scanf("%d", &n);
scanf("%s", s + 1);
cout << f(2 * n, 0) * fac(n) % mod << endl;
return 0;
} | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.