code_file1
stringlengths 80
4k
| code_file2
stringlengths 91
4k
| similar_or_different
int64 0
1
|
---|---|---|
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;
vector<P> test[15];
int main() {
int n;
cin >> n;
rep(i,n) {
int a;
cin >> a;
rep(j,a) {
int x, y;
cin >> x >> y;
x--;
test[i].emplace_back(x,y);
}
}
int ans = 0;
rep(is,1<<n) {
int cnt = __builtin_popcount(is);
bool ok = true;
rep(i,n) {
if (is>>i&1) {
for (auto p : test[i]) {
int x = p.first, y = p.second;
int t = is>>x&1;
if (t != y) ok = false;
}
}
}
if (ok) ans = max(ans, cnt);
}
cout << ans << endl;
return 0;
} | #include <cstdio>
#include <vector>
using namespace std;
struct node{
int key;
int parent, left, right;
node(){ parent=-1; left=-1; right=-1; }
};
vector<node> tree;
int root=-1;
void print_pre(int id)
{
if(id==-1){ return; }
printf(" %d", tree[id].key);
print_pre(tree[id].left);
print_pre(tree[id].right);
}
void print_in(int id)
{
if(id==-1){ return; }
print_in(tree[id].left);
printf(" %d", tree[id].key);
print_in(tree[id].right);
}
void insert(int z)
{
int y=-1;
int x=root;
while(x!=-1){
y=x;
if(tree[z].key<tree[x].key){
x=tree[x].left;
} else{
x=tree[x].right;
}
}
tree[z].parent=y;
if(y==-1){
root=z;
} else if(tree[z].key<tree[y].key){
tree[y].left=z;
} else{
tree[y].right=z;
}
}
int find(int key)
{
int x=root;
while(x!=-1){
int k=tree[x].key;
if(key==k){
return x;
} else if(key<k){
x=tree[x].left;
} else{
x=tree[x].right;
}
}
return -1;
}
void delete_(int z)
{
auto which=[](int z){
auto p=&tree[tree[z].parent];
if(p->left==z){
return &p->left;
} else{
return &p->right;
}
};
if(tree[z].left!=-1 && tree[z].right!=-1){
int x=tree[z].right;
while(tree[x].left!=-1){
x=tree[x].left;
}
tree[z].key=tree[x].key;
z=x;
}
if(tree[z].left==-1 && tree[z].right==-1){
if(tree[z].parent!=-1){
*(which(z))=-1;
} else{
root=-1;
}
} else if(tree[z].left!=-1){
if(tree[z].parent!=-1){
*(which(z))=tree[z].left;
} else{
root=tree[z].left;
}
tree[tree[z].left].parent=tree[z].parent;
} else{
if(tree[z].parent!=-1){
*(which(z))=tree[z].right;
} else{
root=tree[z].right;
}
tree[tree[z].right].parent=tree[z].parent;
}
}
int main()
{
int m;
scanf("%d", &m);
tree=vector<node>(m);
int n=0;
for(int i=0; i<m; i++){
char buf[8]; scanf("%s", buf);
if(*buf=='i'){
int k; scanf("%d", &k);
tree[n].key=k;
insert(n);
n++;
} else if(*buf=='f'){
int k; scanf("%d", &k);
printf("%s\n", find(k)!=-1 ? "yes" : "no");
} else if(*buf=='d'){
int k; scanf("%d", &k);
int id=find(k);
if(id!=-1){
delete_(id);
}
} else{
print_in(root);
printf("\n");
print_pre(root);
printf("\n");
}
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
vector<int > p(2);
rep(i,2){cin >> p[i];}
cout << p[1] + (p[1]-p[0]) << endl;
} | //Radhe Radhe
#include<bits/stdc++.h>
#define godspeed ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep1(i,a,b) for(ll i=a; i<=b; i++)
#define repVect(i,n) for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"YES"<<'\n';
#define no cout<<"NO"<<'\n';
using namespace std;
int main()
{
godspeed
ll i,j,k,l,r,g;
string a,b;
cin>>r>>g;
cout<<2*g-r<<endl;
return 0;
}
| 1 |
#include <iostream>
#include <math.h>
using namespace std;
void factor(int n,int arr[]){
for(int i=2;i<=n;i++){
if(n%i==0){
arr[i]+=1;
factor(n/i,arr);
break;
}
}
}
int main() {
int n;
cin>>n;
int arr[n+1]={0};
for(int i=1;i<=n;i++){
factor(i,arr);
}
long int result=1;
for(int i=0;i<=n;i++){
if(arr[i]>0){
result*=arr[i]+1;
result=result%(1000000000+7);
}
}
cout<<result;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 2e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};
map<ll, int> res;
void factorize(ll n) {
for (int i=2; i*i<=n; i++) {
while (n%i == 0) {
++res[i];
n /= i;
}
}
if (n != 1) ++res[n];
}
int main() {
ll n; cin >> n;
REP(i,2,n+1) factorize(i);
ll ans = 1;
rep(i,n+1) {
ans *= res[i]+1;
ans %= mod;
}
// for (auto x : res) {
// ans *= x.second+1;
// ans %= mod;
// }
cout << ans << endl;
} | 1 |
#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 998244353
#define inf 1000000000
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x,ll y, ll md=inf){ll res = 1;x%=md;while(y){if(y&1)res = (res*x)%md;x *= x; if(x>=md) x %= md; y >>= 1;}return res;}
using namespace std;
#define endl '\n'
#define int ll
signed main() {
fast;
int n;
cin>>n;
vector<pair<pii,char>> v(n);
for(int i=0;i<n;i++) cin>>v[i].f.f>>v[i].f.s>>v[i].s;
map<int,set<int>> mn1, mn2;
int f = 1;
int ans = inf;
for(int i=0;i<n;i++) {
if(v[i].s=='U') {
mn1[v[i].f.f].insert(v[i].f.s);
}
if(v[i].s=='R') {
mn2[v[i].f.s].insert(v[i].f.f);
}
}
for(int i=0;i<n;i++) {
if(v[i].s=='D') {
auto it = mn1[v[i].f.f].lower_bound(v[i].f.s);
if(it!=mn1[v[i].f.f].begin()) {
it--;
f = 0;
ans = min(ans, 5*(v[i].f.s-*it));
}
}
if(v[i].s=='L') {
auto it = mn2[v[i].f.s].lower_bound(v[i].f.f);
if(it!=mn2[v[i].f.s].begin()) {
it--;
f = 0;
ans = min(ans, 5*(v[i].f.f-*it));
}
}
}
sort(all(v));
map<int,int> st[4];
for(int i=0;i<n;i++) {
int x = v[i].f.f + v[i].f.s;
if(v[i].s=='U' && st[3].count(x)) {
f = 0;
ans = min(ans, 10*abs(v[i].f.f-st[3][x]));
}
if(v[i].s=='L' && st[1].count(x)) {
f = 0;
ans = min(ans, 10*abs(v[i].f.f-st[1][x]));
}
if(v[i].s=='U') st[0][x] = v[i].f.f;
if(v[i].s=='D') st[1][x] = v[i].f.f;
if(v[i].s=='L') st[2][x] = v[i].f.f;
if(v[i].s=='R') st[3][x] = v[i].f.f;
}
map<int,int> dt[4];
for(int i=0;i<n;i++) {
int x = v[i].f.f - v[i].f.s;
if(v[i].s=='D' && dt[3].count(x)) {
f = 0;
ans = min(ans, 10*abs(v[i].f.f-dt[3][x]));
}
if(v[i].s=='L' && dt[0].count(x)) {
f = 0;
ans = min(ans, 10*abs(v[i].f.f-dt[0][x]));
}
if(v[i].s=='U') dt[0][x] = v[i].f.f;
if(v[i].s=='D') dt[1][x] = v[i].f.f;
if(v[i].s=='L') dt[2][x] = v[i].f.f;
if(v[i].s=='R') dt[3][x] = v[i].f.f;
}
if(f) cout<<"SAFE";
else cout<<ans;
} | #include <stdio.h>
#include <string.h>
int main (){
char a[3][35];
int length [3];
for (int i = 0;i<3;i++){
scanf ("%s", a[i]);
length[i]=strlen(a[i]);
}
if(a[0][length[0]-1]== a[1][0] &&a[1][length[1]-1]==a[2][0]){
printf("YES");
}else{
printf("NO");
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
int N;
cin >> N;
map<int, int> mp;
bool is = true;
rep(i, N){
int a;
cin >> a;
if(mp.count(a) != 0){
is = false;
break;
}else{
mp[a]++;
}
}
if(is) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
} | #include <bits/stdc++.h>
#include <cstdlib>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
int main() {
int N;
cin >> N;
vector<int> A(N);
string ans="YES";
map<int, int> hoge;
rep(i,N) {
cin >> A[i];
if(hoge[A[i]] == 1) ans="NO";
else hoge[A[i]] = 1;
}
cout << ans << endl;
return 0;
} | 1 |
/*
-ensure correct output format
-ensure printing required output
-reread the problem statement
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define F first
#define S second
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x) (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
if(a==0 || b==0)return 0;
return a/__gcd(a,b)*b;
}
void input(ll ara[],ll n)
{
for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
for(ll i=0; i<n; i++)
cout<<ara[i]<<" ";
cout<<endl;
}
int main()
{
fastread();
ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;
bool flag=false;
string str;
n=3;
ll ara[n+2];
input(ara,n);
sort(ara,ara+n);
cout<<ara[0]+ara[1]<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)
// vector
#define ALL(x) x.begin(), x.end()
// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
cout << a;
ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
cout << a << ' ';
pr(b);
}
int ans = 0;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
int main()
{
int a, b, c;
cin >> a >> b >> c;
pr((a + b + c) - max(a, max(b, c)));
return 0;
}
| 1 |
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;
int main(){
ll n, q;
cin >> n >> q;
char s[n];
ll rui[n+1] = {};
rep(i, n){
cin >> s[i];
if(i == 0)continue;
rui[i+1] = rui[i];
if(s[i] == 'C' && s[i-1] == 'A')rui[i+1]++;
}
rep(i, q){
ll l, r;
cin >> l >> r;
cout << rui[r] - rui[l] << endl;
}
} | #include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int n, q, l, r;
string s;
cin >> n >> q >> s;
vector<int> ac(n + 1, 0);
for (int i = 1; i < n; i++) {
if (s[i-1] == 'A' && s[i] == 'C') ac[i] = ac[i-1] + 1;
else ac[i] = ac[i-1];
}
vector<int> ans(q, 0);
for (int i = 0; i < q; i++) {
cin >> l >> r;
ans[i] = ac[r-1] - ac[l-1];
}
for (int i = 0; i < q; i++) cout << ans[i] << endl;
} | 1 |
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main()
{
int n, q;
int count = 0;
int s[10000];
int t[500];
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> s[i];
}
cin >> q;
for (int i = 0; i < q; i++)
{
cin >> t[i];
}
for (int i = 0; i < q; i++)
{
int j = 0;
while (true)
{
if (t[i] == s[j])
{
count++;
break;
}
if (j == n)
{
break;
}
j++;
}
}
cout << count << endl;
return 0;
} | #include <cstdio>
int main(){
int n;
int a[3];
scanf("%d", &n);
for(int i = 0; i < n; i++) scanf("%d", &a[i]);
for(int i = 1; i <= 100000000; i++){
bool ok = true;
for(int j = 0; j < n; j++){
if(a[j]%i != 0) ok = false;
}
if(ok) printf("%d\n", i);
}
} | 0 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;
int main(void){
int a,b; cin >> a >> b;
string s; cin >> s;
bool ok = true;
if(s.size()!=a+b+1) ok = false;
a--;b--;
rep(i,s.size()){
if(i==a+1 && s[i]!='-') ok =false;
if(i!=a+1 && s[i]-'0'<0 || s[i]-'0'>9) ok = false;
}
if(ok) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string A, B, S;
cin >> A >> B >> S;
cout << ((regex_match(S, regex("\\d{" + A + "}-\\d{" + B + "}"))) ? "Yes" : "No") << "\n";
} | 1 |
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);
using namespace std;
namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;
int n;
bool solve(vi &a){
int e = 0, oi, one = 0;
ll sum = 0;
rep(i, n){
if(a[i] % 2 == 0) e++;
else oi = i;
if(a[i] == 1) one++;
sum += a[i] - 1;
}
if(one) return sum % 2;
if(e % 2) return 1;
if(e == n - 1){
a[oi]--;
int g = a[0];
for(int i : a) g = __gcd(i, g);
for(int &i : a) i /= g;
return !solve(a);
}
return 0;
}
int main(){
cin.tie(0); cin.sync_with_stdio(0);
cin >> n;
vi a(n); rep(i, n) cin >> a[i];
cout << (solve(a) ? "First" : "Second") << endl;
return 0;
} | #include<iostream>
#include<vector>
using namespace std;
vector<long> dp;
vector<long> pre;
void rec(int i, vector<int>& nottaken, long scoresofar, int mask, int group)
{
if(i==nottaken.size())
{
dp[mask]=max(dp[mask],scoresofar+pre[group]);
return;
}
rec(i+1,nottaken,scoresofar,mask,group);
rec(i+1,nottaken,scoresofar,mask^(1<<nottaken[i]),group^(1<<nottaken[i]));
}
int main(){
int n;
cin>>n;
vector<vector<long>> a(n,vector<long>(n));
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
cin>>a[i][j];
}
pre.resize(1<<n);
for(int mask=0;mask<(1<<n);mask++)
{
for(int i=0;i<n;i++)
{
if(mask&(1<<i))
{
for(int j=i+1;j<n;j++)
{
if(mask&(1<<j))
pre[mask]+=a[i][j];
}
}
}
}
dp.resize(1<<n,-99999999);
dp[0]=0;
for(int mask=0;mask<(1<<n);mask++)
{
vector<int> nottaken;
for(int i=0;i<n;i++)
{
if(!(mask&(1<<i)))
nottaken.push_back(i);
}
rec(0,nottaken,dp[mask],mask,0);
}
cout<<dp[(1<<n)-1];
} | 0 |
#include <iostream>
using namespace std;
int main(){
int n,b[200],bb[200][200],a,c,min;
cin>>n;
for(int i=1;i<n;i++){
cin>>a>>c;
b[i]=a;
}
cin>>a>>c;
b[n]=a;
b[n+1]=c;
for(int i=1;i<=n;i++){
bb[i][i]=0;
if(i<n)bb[i+1][i]=b[i]*b[i+1]*b[i+2];
}
for(int i=2;i<=n-1;i++){
for(int j=1;j<=n-i;j++){
min=1000000000;
for(int l=j;l<j+i;l++){
if(min>bb[l][j]+bb[j+i][l+1]+b[j]*b[l+1]*b[j+i+1])
min=bb[l][j]+bb[j+i][l+1]+b[j]*b[l+1]*b[j+i+1];
}
bb[j+i][j]=min;
}
}
cout<<bb[n][1]<<endl;
return 0;
}
/*
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
cout<<bb[i][j]<<" ";
}
}
*/ | #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
int dp[111][111],n,L[111],R[111];
int dfs(int l,int r){
if(dp[l][r]!=-1)return dp[l][r];
if(l==r)return dp[l][r]=0;
int res=1e17;
for(int i=l;i<r;i++){
res=min(res,dfs(l,i)+dfs(i+1,r)+L[l]*R[i]*R[r]);
}
return dp[l][r]=res;
}
signed main(){
memset(dp,-1,sizeof(dp));
cin>>n;
r(i,n)cin>>L[i]>>R[i];
dfs(0,n-1);
cout<<dp[0][n-1]<<endl;
}
| 1 |
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
int n;
while (cin>>n)
{
if (n == 0)break;
int data[11][11] = { 0 };
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cin >> data[i][j];
}
}
for (int i = 0; i < n; i++) //??????????¨????
{
for (int j = 0; j < n; j++)
{
data[i][n] += data[i][j];
}
}
for (int i = 0; i < n; i++) //??????????¨????
{
for (int j = 0; j < n+1; j++) //n??????????????????
{
data[n][j] += data[i][j];
}
}
for (int i = 0; i < n+1; i++)
{
for (int j = 0; j < n+1; j++)
{
cout.width(5);
cout << data[i][j];
}
cout << endl;
}
}
return 0;
} | #include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include <memory>
#include <iomanip>
std::vector<int> parse_line(std::string const& line) {
using namespace std;
vector<int> result;
istringstream s(line);
string element;
while (getline(s, element, ' ')) {
stringstream buf;
int value = 0;
buf << element;
buf >> value;
result.push_back(value);
}
return std::move(result);
}
int main(int argc, char* argv[])
{
using namespace std;
while (true) {
string line;
getline(std::cin, line);
auto elements = parse_line(line);
auto length = elements[0];
if (length == 0) break;
vector<int> total(length + 1);
size_t width = length + 1;
for (size_t i = 0; i < length; ++i) {
getline(cin, line);
elements = parse_line(line);
int sum = 0;
for (size_t n = 0; n < length; ++n) {
int val = elements[n];
sum += val;
total[n] += val;
cout << setw(5) << val;
}
cout << setw(5) << sum << endl;
total[length] += sum;
}
for (size_t i = 0; i < width; ++i) {
cout << setw(5) << total[i];
}
cout << endl;
}
return 0;
} | 1 |
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265358979;
vector<pair<ll, ll>> pf(ll n){
vector<pair<ll, ll>> res;
for (ll i = 2; i*i <= n; i++){
if (n%i != 0){
continue;
}
else{
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;
//素因数分解
//入力:ll
//出力:vector<pair<ll, ll>>
//res[i].first == i番目に小さい素因数
//res[i].second == res[i].firstの指数
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll a,b;
cin >> a >> b;
ll g = gcd(a,b);
vector<pair<ll, ll>> x = pf(g);
cout << x.size()+1 << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repe(i,n) for(int i=0;i<n;i++)
#define repa(i,j,n) for(int i=j;i<n;i++)
//#define v.all() v.begin(),v.end()
#define repr(i,n) for(int i=n;i>=0;i--)
#define int long long int
#define vi vector<int>
#define vpi vector<pair<int,int>>
int gcd(int a,int b){
if(b==0) return a;
else return gcd(b,a%b);
}
vi primef(int n){
vi a,ref;
a.push_back(1);
while(n%2==0) {
a.push_back(2);
n/=2;
}
for(int i=3;i<=sqrt(n);i+=2){
while(n%i==0){
a.push_back(i);
n/=i;
}
}
if(n>2) a.push_back(n);
sort(a.begin(), a.end());
ref.push_back(a[0]);
for(int i=1;i<a.size();i++){
if(a[i]!=a[i-1]) {
ref.push_back(a[i]);
}
}
return ref;
}
signed main(){
int t=1;
//cin>>t;
while(t--) {
int ai,bi;
cin>>ai>>bi;
vi a,b;
a=primef(ai);
b=primef(bi);
// for(int i=0;i<a.size();i++){
// cout<<a[i]<<" ";
// }
// cout<<endl;
// for(int i=0;i<b.size();i++){
// cout<<b[i]<<" ";
// }
// cout<<endl;
int ct=0;
map<int,int> m;
rep(i,a.size()) m[a[i]]=0;
rep(i,b.size()) m[b[i]]=0;
rep(i,a.size()) m[a[i]]=1;
rep(i,b.size()){
if(m[b[i]]==1) {ct++;}
}
cout<<ct<<endl;
}
return 0;
} | 1 |
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000007
using namespace std;
int main(){
long n;
cin >> n;
string ans = "";
while(n){
if(n%2==0){
ans.push_back('0');
}else{
ans.push_back('1');
n -= 1;
}
n /= (-2);
}
if(int(ans.size())==0)ans.push_back('0');
rep(i,int(ans.size())){
cout << ans[int(ans.size())-1-i];
}
cout << endl;
return 0;
} | #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 all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
ll V;
vector<vector<edge> > G;
vector<ll> d;
graph(ll n){
init(n);
}
void init(ll n){
V = n;
G.resize(V);
d.resize(V);
rep(i,V){
d[i] = INF;
}
}
void add_edge(ll s, ll t, ll cost){
edge e;
e.to = t, e.cost = cost;
G[s].push_back(e);
}
void dijkstra(ll s){
rep(i,V){
d[i] = INF;
}
d[s] = 0;
priority_queue<P,vector<P>, greater<P> > que;
que.push(P(0,s));
while(!que.empty()){
P p = que.top(); que.pop();
ll v = p.second;
if(d[v]<p.first) continue;
for(auto e : G[v]){
if(d[e.to]>d[v]+e.cost){
d[e.to] = d[v]+e.cost;
que.push(P(d[e.to],e.to));
}
}
}
}
};
class UnionFind
{
public:
int par[100005];
int depth[100005];
int nGroup[100005];
UnionFind(int n) {
init(n);
}
void init(int n) {
for(int i=0; i<n; i++) {
par[i] = i;
depth[i] = 0;
nGroup[i] = 1;
}
}
int root(int x) {
if(par[x] == x) {
return x;
} else {
return par[x] = root(par[x]);
}
}
bool same(int x, int y) {
return root(x) == root(y);
}
void unite(int x, int y) {
x = root(x);
y = root(y);
if(x == y) return;
if(depth[x] < depth[y]) {
par[x] = y;
nGroup[y] += nGroup[x];
nGroup[x] = 0;
} else {
par[y] = x;
nGroup[x] += nGroup[y];
nGroup[y] = 0;
if(depth[x] == depth[y])
depth[x]++;
}
}
};
const ll MAX = 510000;
ll 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;
}
}
// 二項係数計算
ll COM(ll n, ll k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
ll n; cin>>n;
if(n==0) cout << 0 << endl;
else{
ll ca = 0;
ll k = 1;
ll m = 0;
if(n>0){
while(1){
ca+=k;
if(ca>=n){
n-=k;
break;}
m+=2;
k*=4;
}
}
else{
k = -2;
m++;
while(1){
ca+=k;
if(ca<=n){
n-=k;
break;}
m+=2;
k*=4;
}
}
ll a[m+1]={};
a[m]=1;
ll mm = 0;
//cout << n << endl;
while(1){
if(n==0)break;
if(n>0){
k = 1;
mm = 0;
ca = 0;
while(1){
ca+=k;
if(ca>=n){
break;}
mm+=2;
k*=4;
}
a[mm]++;
n-=k;
continue;
}
else{
k = -2;
mm = 1;
ca = 0;
while(1){
ca+=k;
if(ca<=n){
break;}
mm+=2;
k*=4;
}
a[mm]++;
n-=k;
continue;
}
}
rep(i,m+1){
cout << a[m-i];}
}}
| 1 |
#include <bits/stdc++.h>
#define debug(var) do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef vector<v2> v3;
typedef unordered_map<ll, unordered_map<ll, ll>> graph;
const ll INF = 1ll << 50;
const ll mod = 1000000007;
ll n;
v1 a;
v3 dp;
ll bias = 3;
int main(){
cin >> n;
a = v1(n);
for(ll i = 0;i < n;i++){
cin >> a[i];
}
dp = v3(2, v2(6, v1(n+1, -INF)));
dp[0][3][0] = 0;
for(ll i = 0;i < n;i++){
for(ll j = 0;j < 2;j++){
for(ll k = -2;k <= 1;k++){
ll x = k + bias;
if(j == 0){
chmax(dp[0][x-1][i+1], dp[j][x][i]);
chmax(dp[1][x+1][i+1], dp[j][x][i] + a[i]);
}else{
chmax(dp[0][x-1][i+1], dp[j][x][i]);
}
}
}
}
ll d = n/2 - (n-n/2);
cout << max(dp[0][d+bias][n], dp[1][d+bias][n]) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e17;
const int N=2e5+10;
int a[N];
ll f[N],c1[N],c2[N];
int n;
int main() {
ll ans,cnt;
int i;
ans=-INF;
scanf("%d",&n);
for (i=1;i<=n;i++) {
scanf("%d",&a[i]);
if (i==1) c2[i]=a[i];
else if (i%2==0) c1[i]=c1[i-2]+a[i];
else c2[i]=c2[i-2]+a[i];
}
for (i=2;i<=n;i++) {
if (i%2==0) f[i]=max(f[i-2]+a[i],c2[i-1]);
else f[i]=max(f[i-2]+a[i],f[i-1]);
// cout<<i<<' '<<f[i]<<endl;
}
printf("%lld\n",f[n]);
return 0;
} | 1 |
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>
#include <stack>
using namespace std;
#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double
ostream& operator<< (ostream &out, const vector<int> &b) {
for (auto k : b) out << k << " ";
return out;
}
istream& operator>> (istream& in, pii& b) {
in >> b.first >> b.second;
return in;
}
ostream& operator<< (ostream& out, const pii& b) {
out << "{" << b.first << ", " << b.second << "}";
return out;
}
template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}
#ifdef LOCAL
#define dbg(x) cout << #x << " : " << (x) << "\n";
const int INF = 1e18;
// const int mod = 2600000069;
// const int p = 10;
#else
#define dbg(x) 57
const int INF = 1e18;
// const int mod = 2600000069;
// const int p = 179;
#endif
const ld PI = acos(-1);
#define time clock() / (double) CLOCKS_PER_SEC
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
const int MAXN = 1e5 + 10;
int n, k;
vector<int> g[MAXN];
int ans = 0;
int d[MAXN];
void dfs(int v) {
d[v] = 0;
for (auto u : g[v]) {
dfs(u);
if (d[u] == k - 1 && v != 0) {
ans++;
} else {
chkmax(d[v], d[u] + 1);
}
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
}
if (k == 1) {
for (int i = 0; i < n; i++) {
if (a[i] != 0) {
ans++;
}
}
cout << ans << "\n";
return 0;
}
if (a[0] != 0) {
ans++;
a[0] = 0;
}
for (int i = 1; i < n; i++) {
g[a[i]].pb(i);
}
dfs(0);
cout << ans << "\n";
}
/*
*/ | #include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 305
using namespace std;
int n, k, dp[N][N][N];
char s[N];
int f(int bas, int son, int k){
if(bas == son)
return 1;
if(bas > son)
return 0;
int &r = dp[bas][son][k];
if(r != -1)
return r;
if(s[bas] == s[son])
r = f(bas + 1, son - 1, k) + 2;
if(k)
r = max(r, f(bas + 1, son - 1, k - 1) + 2);
r = max(r, f(bas + 1, son - 1, k));
r = max(r, f(bas, son - 1, k));
r = max(r, f(bas + 1, son, k));
return r;
}
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
memset(dp, -1, sizeof dp);
scanf("%s %d",s + 1, &k);
n = strlen(s + 1);
printf("%d\n", f(1, n, k));
return 0;
} | 0 |
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数(任意精度)
typedef pair<int, int> P;
// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9)+7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
vector< pair<ll, ll> > p;
for (ll i = 2; i * i <= n; i++) {
if ((n % i) != 0) continue;
p.push_back(make_pair(i, 0));
while ((n % i) == 0) {
n /= i;
p[i].second += 1;
}
p.push_back(make_pair(n, 0));
}
if (n != 1) p.push_back(make_pair(n, 1));
return p;
}
// 組み合わせの整合性を保つ(後ほど解析する)
ll modinv(ll a) {
ll b = MOD, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= MOD;
if (u < 0) { u += MOD; }
return u;
}
// 順列
ll permutation(const ll n, const ll m) {
ll result = 1;
for (ll i = n; i > n - m; i--) { result = (result * i) % MOD; }
return result;
}
// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
if (x == 0) return 1;
ll res = repeat_square(n, x/2);
res = res * res % MOD;
if ((x % 2) == 1) res = res * n % MOD;
return res;
}
// 組み合わせ
ll combination(const ll n, const ll a) {
ll x = 1, y = 1;
for(ll i = 0; i < a; i++){
x = x * (n-i) % MOD;
y = y * (i+1) % MOD;
}
return x * repeat_square(y, MOD-2) % MOD;
}
int main() {
ll x;
cin >> x;
ll n = x / 11; // (5,6) or (6,5) のペア数でわる
ll m = x % 11; // 残りの数
ll result = n*2;
int min = 1000000;
rep(i, 2) { // 1, 6 始まりとそれ以外でパターンを分ける
int count = 0, temp = m;
bool flag = true;
while (temp > 0) {
if (i == 0) { // 1, 6 始まり
temp -= flag ? 5 : 6;
} else { // それ以外
temp -= flag ? 6 : 5;
}
count++;
flag = !flag;
}
if (min > count) min = count;
}
cout << (result + min) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
namespace IO {
#define gc getchar()
template <typename T>
inline void read(T& x) {
x = 0; bool f = 1; char ch;
for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1;
for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48);
x = f ? x : -x;
}
#undef gc
}
const int MAXN = 2e5 + 10;
int n, arr[2][MAXN], cnt[2][MAXN], val;
vector<int> pos;
int main() {
IO::read(n);
rep(_, 0, 1) rep(i, 1, n) IO::read(arr[_][i]), cnt[_][arr[_][i]]++;
reverse(arr[1] + 1, arr[1] + n + 1);
rep(i, 1, n) if (arr[0][i] == arr[1][i]) val = arr[0][i], pos.push_back(i);
int l = 1, r = n; bool flg = false;
for (auto cur_pos : pos) {
if (flg == false) {
if (arr[0][l] != val && arr[1][l] != val) {
swap(arr[1][l], arr[1][cur_pos]);
++l;
} else flg = true;
}
if (flg == true) {
if (arr[0][r] != val && arr[1][r] != val) {
swap(arr[1][r], arr[1][cur_pos]);
--r;
} else return puts("No"), 0;
}
}
puts("Yes");
rep(i, 1, n) printf("%d ", arr[1][i]);
return 0;
} | 0 |
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
vector<long long> x(n);
vector<long long> y(m);
for (auto i = 0; i < n; ++i)
{
cin >> x[i];
}
for (auto i = 0; i < m; ++i)
{
cin >> y[i];
}
auto sumX = 0ll;
auto mod = (long long)1e9 + 7;
for (auto i = 1; i < n; ++i)
{
auto diff = x[i] - x[i - 1];
sumX += (((diff * i) % mod) * (n - 1 - i + 1)) % mod;
sumX %= mod;
}
auto sum = 0ll;
for (auto i = 1; i < m; ++i)
{
auto diff = y[i] - y[i - 1];
sum += (((((diff * i) % mod) * (m - 1 - i + 1)) % mod) * sumX) % mod;
sum %= mod;
}
cout << sum << endl;
return 0;
} | #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<memory.h>
using namespace std;
typedef long long ll;
const int Max = 4e5 + 5;
int lst[Max];
int main()
{
int n, x;
cin >> n >> x;
for (int i = 1;i <= n;i++)
{
scanf("%d", &lst[i]);
}
ll sum = 0;
if (lst[1] > x)
{
sum = lst[1] - x;
lst[1] = x;
}
for (int i = 2;i <= n;i++)
{
if (lst[i - 1] + lst[i] > x)
{
int t = lst[i] + lst[i - 1] - x;
lst[i] -= t;
sum += t;
}
}
cout << sum << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N;
vector<string> blue(N);
for(int i = 0; i < N; i++){
cin >> blue.at(i);
}
cin >> M;
vector<string> red(M);
for(int i = 0; i < M; i++){
cin >> red.at(i);
}
int ans = 0;
int maxans = 0;
for(int i = 0; i < N; i++){
int bcnt = 1;
int rcnt = 0;
for(int j = 0; j < N; j++){
if(i == j){
continue;
}
if(blue.at(i) == blue.at(j)){
bcnt++;
}
}
for(int j = 0; j < M; j++){
if(blue.at(i) == red.at(j)){
rcnt--;
}
}
ans = bcnt + rcnt;
if(maxans < ans){
maxans = ans;
}
}
cout << maxans << endl;
} | #include<stdio.h>
void fanc(int,int);
int map[13][13];
int main(void)
{
int i,j;
int c;
char s[13];
while(scanf("%s",s)!=EOF){
c=0;
for(i=0;i<12;i++){
map[0][i]=s[i]-'0';
}
for(i=1;i<12;i++){
scanf("%s",s);
for(j=0;j<12;j++){
map[i][j]=s[j]-'0';
}
}
/* for(i=0;i<12;i++){
for(j=0;j<12;j++){
printf("%d ",map[i][j]);
}
printf("\n");
}*/
for(i=0;i<12;i++){
for(j=0;j<12;j++){
if(map[i][j]==1){
c++;
map[i][j]=0;
fanc(i,j);
}
}
}
printf("%d\n",c);
}
return 0;
}
void fanc(int x,int y)
{
if(x+1<12){
if(map[x+1][y]==1){
map[x+1][y]=0;
fanc(x+1,y);
}
}
if(x-1>=0){
if(map[x-1][y]==1){
map[x-1][y]=0;
fanc(x-1,y);
}
}
if(y+1<12){
if(map[x][y+1]==1){
map[x][y+1]=0;
fanc(x,y+1);
}
}
if(y-1>=0){
if(map[x][y-1]==1){
map[x][y-1]=0;
fanc(x,y-1);
}
}
} | 0 |
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
#define N 100050
int n,a[N],b[N],mp[N][3],l[2];
void gun() {
puts("No"); exit(0);
}
int main() {
scanf("%d",&n);
int i,x,y,z;
for(x=0;x<3;x++) for(i=1;i<=n;i++) scanf("%d",&mp[i][x]);
for(i=1;i<=n;i++) {
x=mp[i][0], y=mp[i][1], z=mp[i][2];
if(x+1==y&&y+1==z) {
if(z%3) gun();
a[i]=z/3, b[i]=0;
}else if(x-1==y&&y-1==z) {
if(x%3) gun();
a[i]=x/3, b[i]=1;
}else gun();
if((a[i]&1)!=(i&1)) gun();
if(b[i]) l[i&1]^=1;
}
for(i=1;i<=n;i++) {
while(a[i]!=i) {
l[!(i&1)]^=1;
swap(a[i],a[a[i]]);
}
}
puts(l[0]||l[1]?"No":"Yes");
}
| #include<bits/stdc++.h>
using namespace std;
void gofail(){
cout<<"No\n";
exit(0);
}
const int N=100100;
int a[N],b[N],c[N],sum[3*N],sum1,sum2,n;
void add(int x){for(;x;x-=x&-x)sum[x]^=1;}
int qry(int x){int ans=0;for(;x<=3*n;x+=x&-x)ans^=sum[x];return ans;}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;
for(int i=1;i<=n;++i)cin>>a[i];
for(int i=1;i<=n;++i)cin>>b[i];
for(int i=1;i<=n;++i)cin>>c[i];
for(int i=1;i<=n;++i){
if(a[i]<b[i]){
if(a[i]+1!=b[i])gofail();
if(b[i]+1!=c[i])gofail();
if(c[i]%3)gofail();
a[i]=a[i]/3+1;b[i]=0;
}else{
if(a[i]-1!=b[i])gofail();
if(b[i]-1!=c[i])gofail();
if(a[i]%3)gofail();
a[i]=a[i]/3;b[i]=1;
}
if((a[i]^i)&1)gofail();
if(i&1)sum2^=b[i];
else sum1^=b[i];
}
for(int i=1;i<=n;i+=2){
sum1^=qry(a[i]);
add(a[i]);
}
memset(sum,0,sizeof sum);
for(int i=2;i<=n;i+=2){
sum2^=qry(a[i]);
add(a[i]);
}
if(sum1||sum2)gofail();
cout<<"Yes\n";
return 0;
}
| 1 |
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<int> outp;
int icn;
int icd;
int g;
vector<int> ice;
for(g = 0;;g++){
vector<int> ice(10,0);
cin >> icn;
if(icn == 0){
break;
}else{
for(int a = 0;a< icn;a++){
cin >> icd;
ice[icd] += 1;
}
outp.insert(outp.end(),ice.begin(),ice.end());
}
}
for(int n = 0;n<g * 10;n++){
if(outp[n] == 0){
cout << "-";
}else{
for(int c = 0;c<outp[n];c++){
cout << "*" ;
}
}
cout << endl;
}
return 0;
} | // #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
#define MP make_pair
#define fastIO cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
int INPUT_INT() { int d; cin >> d; return d; } // 入力をpush_back(d)やarray[d]に使う時に無駄な変数を使わない
// ------------------- include, typedef, define END. -------------------
void solve(VI in){
FOR(i, 0, in.size()){
if (in[i]){
while (in[i]--){
cout << "*";
}
cout << endl;
}
else{
cout << "-" << endl;
}
}
}
int main(){
int n;
while (cin >> n,n){
VI input(10,0);
FOR(i, 0, n){
input[INPUT_INT()]++;
}
solve(input);
}
return 0;
} | 1 |
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT \
cin.tie(0); \
ios::sync_with_stdio(false);
template <class T>
inline bool chmax(T& a, T b) {
return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
return a = (a > b) ? b : a;
}
ll const INF = 1LL << 60;
ll const MOD = 1000000007;
// 約数の列挙 O(√n)
vector<ll> divisor(ll n) {
vector<ll> res;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (i != n / i) res.push_back(n / i);
}
}
return res;
}
int main() {
INIT;
ll N;
cin >> N;
vector<ll> a(N + 1, 0);
reps(i, 1, N + 1) cin >> a[i];
vector<ll> b;
vector<ll> sum(N + 1, 0);
ll ans = 0;
for (ll i = N; i > 0; i--) {
if (sum[i] % 2 != a[i]) {
b.pb(i);
vector<ll> divs = divisor(i);
rep(j, SZ(divs)) { sum[divs[j]]++; }
}
// cout << i << ": ";
// repv(sum) cout << *it << " ";
// cout << endl;
}
sort(ALL(b));
cout << SZ(b) << endl;
if (SZ(b) > 0) {
repv(b) { cout << *it << " "; }
cout << endl;
}
return 0;
} | #include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#include <list>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pNO cout << "NO" << endl
#define pYES cout << "YES" << endl
#define endl "\n"
#define pi 3.14159265358979
using namespace std;
using ll = long long;
int main() {
int N; cin >> N;
vi vec(N);
rep(i, N) cin >> vec[i];
vi ball(N, -1);
vi ans;
int bcnt = 0;
for (int i = N - 1; i > -1; i--) {
int subsum = 0;
for (int j = 2; (i + 1) * j - 1 < N; j++) {
int ind = (i + 1) * j - 1;
subsum += ball[ind];
}
subsum %= 2;
int to_add = subsum ^ vec[i];
bcnt += to_add;
ball[i] = to_add;
if (ball[i]) {
ans.push_back(i + 1);
}
}
cout << bcnt << endl;;
for (auto aa : ans) {
cout << aa << " ";
}
cout << endl;
} | 1 |
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define ll long long
using namespace std;
const int N=50005;
int n,p[N],vis[N],cnt,now; ll a[505][505],v1[N],v2[N];
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
void init(int n){
rep (i,2,n){
if (!vis[i]) p[++cnt]=i;
for (int j=1;j<=cnt&&i*p[j]<=n;j++){
vis[i*p[j]]=1;
if (i%p[j]==0) break;
}
}
}
int main(){
scanf("%d",&n);
if (n==2) return puts("4 7\n23 10"),0;
init(10000);
rep (i,1,n) a[i][0]=a[i][n+1]=a[0][i]=a[n+1][i]=1;
now=1;
for (int i=1+1;i<=n+n;i+=2) v1[i]=p[now++];
for (int i=(n&1)?1-n:2-n;i<=n-1;i+=2) v2[i+n]=p[now++];
rep (i,1,n) rep (j,1,n) if (!((i+j)&1)) a[i][j]=v1[i+j]*v2[i-j+n];
rep (i,1,n) rep (j,1,n) if ((i+j)&1) a[i][j]=lcm(lcm(a[i][j-1],a[i][j+1]),lcm(a[i-1][j],a[i+1][j]))+1;
rep (i,1,n){rep (j,1,n) printf("%lld ",a[i][j]); puts("");}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int m;
cin >> m;
vector<int> nodes;
vector<pair<int, int>> child;
int n = 0;
for (int i = 0; i < m; i++){
string q;
cin >> q;
if (q == "insert"){
int k;
cin >> k;
if (n != 0){
int v = 0;
while (1){
if (k < nodes[v]){
if (child[v].first != -1){
v = child[v].first;
} else {
child[v].first = nodes.size();
break;
}
} else {
if (child[v].second != -1){
v = child[v].second;
} else {
child[v].second = nodes.size();
break;
}
}
}
}
nodes.push_back(k);
child.push_back(make_pair(-1, -1));
n++;
}
if (q == "find"){
int k;
cin >> k;
if (n == 0){
cout << "no" << endl;
} else {
int v = 0;
while (1){
if (k < nodes[v]){
if (child[v].first == -1){
cout << "no" << endl;
break;
} else {
v = child[v].first;
}
} else if (k > nodes[v]){
if (child[v].second == -1){
cout << "no" << endl;
break;
} else {
v = child[v].second;
}
} else {
cout << "yes" << endl;
break;
}
}
}
}
if (q == "delete"){
int k;
cin >> k;
int v = 0;
int u;
while (1){
if (k < nodes[v]){
u = v;
v = child[v].first;
} else if (k > nodes[v]){
u = v;
v = child[v].second;
} else {
break;
}
}
if (child[v].first != -1 && child[v].second != -1){
u = v;
int w = child[v].second;
while (child[w].first != -1 || child[w].second != -1){
u = w;
if (child[w].first != -1){
w = child[w].first;
} else {
w = child[w].second;
}
}
swap(nodes[v], nodes[w]);
v = w;
}
if (child[v].first != -1 && child[v].second == -1){
int w = child[v].first;
nodes[v] = nodes[w];
child[v].first = child[w].first;
child[v].second = child[w].second;
} else if (child[v].second != -1 && child[v].first == -1){
int w = child[v].second;
nodes[v] = nodes[w];
child[v].first = child[w].first;
child[v].second = child[w].second;
} else {
if (child[u].first == v){
child[u].first = -1;
} else {
child[u].second = -1;
}
}
n--;
}
if (q == "print"){
//Inorder
if (n != 0){
stack<int> S;
vector<int> t(nodes.size(), 0);
S.push(0);
while (!S.empty()){
int v = S.top();
S.pop();
if (t[v] == 1){
cout << ' ' << nodes[v];
}
if (t[v] == 0){
S.push(v);
if (child[v].second != -1){
S.push(child[v].second);
}
S.push(v);
if (child[v].first != -1){
S.push(child[v].first);
}
}
t[v]++;
}
}
cout << endl;
//Preorder
if (n != 0){
stack<int> S;
vector<int> t(nodes.size(), 0);
S.push(0);
while (!S.empty()){
int v = S.top();
S.pop();
if (t[v] == 0){
cout << ' ' << nodes[v];
}
if (t[v] == 0){
S.push(v);
if (child[v].second != -1){
S.push(child[v].second);
}
S.push(v);
if (child[v].first != -1){
S.push(child[v].first);
}
}
t[v]++;
}
}
cout << endl;
}
}
}
| 0 |
/*
** author:mahmoud magdy
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
inline int D()
{
int m ;
cin>>m;
return m ;
}
inline ll lD()
{
ll m ;
cin>>m;
return m ;
}
inline double dD()
{
double m;
cin>>m;
return m;
}
void fast()
{
ios_base :: sync_with_stdio( 0 ) ;
cin.tie( 0 ) ;
cout.tie( 0 ) ;
}
int main()
{
fast();
int n=D();
set<int>st;
for(int i=0;i<n;++i){
st.insert(D());
}
if(st.size()==n)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
| #include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言
int main()
{
int n;
cin >> n;
vector<long int>f(n);
int i;
string s;
s = "YES";
for (i = 0; i < n; i++)
{
cin >> f.at(i);
}
sort(f.begin(), f.end());
for (i = 0; i < n - 1; i++)
{
if (f.at(i) == f.at(i + 1))
{
s = "NO";
break;
}
}
cout << s << endl;
} | 1 |
/* *******************Bismillahir Rahmanir Rahim************************
MD. ASFAKUL GHANI!
*ProMAGFAT*!
SECRET_warning :)->FAT CSE-25!
JAHANGIRNAGAR UNIVERSITY!
Dhaka,Bangladesh!
*/
#include <bits/stdc++.h>
#include <set>
using namespace std;
#define fasterIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define Im int main()
#define ll long long
#define sc scanf
#define pf printf
#define rn0 return 0
#define rn return
#define f0(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define f2(i,n) for(ll i=n-1;i>=0;i--)
#define pi 2*acos(0.0)
#define modulo 1000003
#define dd double
#define PI 3.14159265358979
#define pi 2*acos(0.0)
#define p_b push_back
#define ps push
/*
ll for_binarySearch(ll a,ll b,ll aa[],ll x){while(a<=b){ll mid=(a+b)/2;if(aa[mid]==x) return 1;else if(aa[mid] > x) b=mid-1;else a=mid+1;}return -1;}
ll for_gcd(ll a,ll b){if(a==0) return b;else return for_gcd(b%a,a);}
ll for_prime(ll x){for (ll i=2;i*i<=x;i++){if(x%i==0) return 0;}return 1;}
void for_swap(char *x,char *y){char temp;temp=*x;*x=*y;*y=temp;}
ll for_big_mod(ll b,ll p,ll m){if(p==0) return 1;else if(p%2==0){ll k=for_big_mod(b,p/2,m);return (k*k)%m;}else return ((b%m)*(for_big_mod(b,p-1,m)))%m;}
ll for_josephus(ll n,ll k){if(n==1) return 1;return (for_josephus(n-1,k)+k-1)%n+1;}
ll for_gcdExtended(ll a,ll b,ll *x,ll *y){if(a==0){*x=0;*y=1;return b;}ll x1,y1;ll gcd=for_gcdExtended(b%a,a,&x1,&y1);*x=y1-(b/a)*x1;*y=x1;return gcd;}
*/
void debug1()
{
cout << "***" << endl;
}
void debug11(ll n)
{
cout << n << endl;
}
#define ipair pair <ll,ll>
#define inf 12345678912345
ll n,m,p;
vector <ipair> v1[101010];
pair <ll,ipair> pp[101010];
vector <ll> dis;
void FAT_dj(ll src)
{
priority_queue <ipair, vector<ipair>, greater<ipair> > pq;
pq.ps(make_pair(0,src));
dis[src] = 0;
while (!pq.empty()){
ll u = pq.top().second;
pq.pop();
vector <ipair> ::iterator it;
for (it = v1[u].begin(); it != v1[u].end(); it += 1){
ll v = (*it).first;
ll w = (*it).second;
if (dis[v] > dis[u] + w){
dis[v] = dis[u] + w;
pq.ps(make_pair(dis[v],v));
}
}
}
}
void FAT_Ncycle(ll src)
{
dis[src] = 0;
for (ll i = 0; i < n; i += 1){
if (src == i) continue;
for (ll j = 0; j < m; j += 1){
ll w = pp[j].first;
ll u = pp[j].second.first;
ll v = pp[j].second.second;
if (dis[u] + w < dis[v] && dis[u] != inf){
dis[v] = dis[u] + w;
}
}
}
}
Im
{
/*#ifdef FAT
freopen("input.txt","w",stdin);
#endif // FAT*/
//fasterIO;
cin>>n>>m;
for (ll i = 0; i < m; i += 1){
ll u,v,w;
cin>>u>>v>>w;
v1[u].p_b(make_pair(v,w));
pp[i] = make_pair(w,make_pair(u,v));
//v1[v].p_b(make_pair(u,w));
}
for (ll k = 0; k < n; k += 1){
for (ll i = 0; i <= n; i += 1) dis.p_b(inf);
FAT_Ncycle(k);
if (k==0){
for (ll i = 0; i < m; i += 1){
ll w = pp[i].first;
ll u = pp[i].second.first;
ll v = pp[i].second.second;
if (dis[u] != inf && dis[u] + w < dis[v]){
cout << "NEGATIVE CYCLE" << endl;
rn0;
}
}
}
if (dis[0] == inf) cout << "INF";
else cout << dis[0];
for (ll i = 1; i < n; i += 1){
if (dis[i] == inf) cout << " " << "INF";
else cout << " " << dis[i];
}
cout << endl;
dis.clear();
}
for (ll i = 0; i < n; i += 1) v1[i].clear();
// main();
rn0;
} | #include <bits/stdc++.h>
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
scan1(x); scan(xs...);
}
template<typename W>
struct N003 {
typedef std::vector<long> LI;
typedef std::vector<W> LW;
long n, e;
LI ss, ds;
LW ws;
std::vector<LI> iss;
N003(long n_, const LI& ss_, const LI& ds_, const LW& ws_)
: n(n_), e(ss_.size()), ss(ss_), ds(ds_), ws(ws_) {
iss.resize(n+1);
for(long i = 0; i < e; ++i) {
iss[ss[i]].push_back(i);
}
}
};
template<typename W>
struct N006 {
std::vector<std::vector<W>> xss;
bool negativeCycle;
N006(const N003<W>& g, W inf) : negativeCycle(false) {
xss.resize(g.n+1);
for(auto& xs : xss) xs.resize(g.n+1, inf);
for(long i = 0; i < g.n+1; ++i) xss[i][i] = 0;
for(long i = 0; i < g.e; ++i) {
xss[g.ss[i]][g.ds[i]] = g.ws[i];
}
for(long z = 0; z < g.n+1; ++z) {
for(long x = 0; x < g.n+1; ++x) {
for(long y = 0; y < g.n+1; ++y) {
W d = xss[x][y];
W nd = xss[x][z] + xss[z][y];
xss[x][y] = std::min(d, nd);
}
}
}
for(long x = 0; x < g.n+1; ++x) {
for(long y = 0; y < g.n+1; ++y) {
if( xss[x][y] >= inf / 2 ) {
xss[x][y] = inf;
}
}
if( xss[x][x] < 0 ) {
negativeCycle = true;
}
}
}
};
struct Solver {
Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
void solve() {
typedef std::vector<long> LI;
long v, e;
scan(v, e);
LI ss(e+1), ds(e+1);
LI ws(e+1);
for(long i = 0; i < e; ++i) {
scan(ss[i], ds[i], ws[i]);
}
N003<long> g(v, ss, ds, ws);
N006<long> warshallfloyd(g, (1LL << 60));
if( warshallfloyd.negativeCycle ) {
puts("NEGATIVE CYCLE");
}
else {
for(long i = 0; i < v; ++i) {
for(long k = 0; k < v; ++k) {
if( warshallfloyd.xss[i][k] == (1LL << 60) ) {
printf("INF");
}
else {
printf("%ld", warshallfloyd.xss[i][k]);
}
putchar( k == v - 1 ? '\n' : ' ');
}
}
}
}
};
int main() {
loop std::unique_ptr<Solver>(new Solver())->solve();
} | 1 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int solve(int n, vector<int> & dims){
int dp[100][101] = {{0}};
for (int span = 2; span != n + 1; ++span){
for (int first = 0; first + span != n + 1; ++first){
for (int last = first + span; last != n + 1; ++last){
int record = 2000000000;
for (int mid = first + 1; mid != last; ++mid){
record = min(record, dp[first][mid] + dp[mid][last] + dims[first] * dims[last] * dims[mid]);
}
dp[first][last] = record;
}
}
}
return dp[0][n];
}
int main()
{
int n = 0;
cin >> n;
vector<int> dims(n + 1);
int r = 0;
int c = 0;
for (int i = 0; i != n; ++i){
cin >> r >> c;
dims[i] = r;
}
dims[n] = c;
cout << solve(n, dims) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define EPS 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define x real()
#define y imag()
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,a[105],b[105];
map<P,int>M;
typedef complex<double> pt;
bool eq(double a,double b){
return (-EPS < a-b && a-b < EPS);
}
double dot(pt a,pt b){
return (conj(a)*b).x;
}
double cross(pt a,pt b){
return (conj(a)*b).y;
}
bool cmp(const pt& a,const pt& b){
if(-EPS < a.x-b.x && a.x-b.x < EPS) return a.y < b.y;
else return a.x < b.x;
}
int ccw(pt a,pt b,pt c){
b -= a; c -= a;
//cout<<cross(b,c)<<endl;
if(cross(b,c) > EPS) return 1; // counter clockwise
if(cross(b,c) < -EPS) return -1; // clockwise
if(dot(b,c) < -EPS) return 2; //c-a-b
if(norm(b) < norm(c)) return -2; //a-b-c
return 0; //a-c-b
}
vector<pt>convex_hull(vector<pt>ps)
{
sort(ps.begin(),ps.end(),cmp);
int k=0,n = ps.size();
vector<pt>qs(n*2);
for(int i=0;i<n;i++)
{
while(k>1 && ccw(qs[k-2],qs[k-1],ps[i]) != 1) k--;
qs[k++] = ps[i];
}
for(int i=n-2,t=k;i>=0;i--)
{
while(k>t && ccw(qs[k-2],qs[k-1],ps[i]) != 1) k--;
qs[k++] = ps[i];
}
qs.resize(k-1);
return qs;
}
double ans[105];
int main(){
cin>>n;
vector<pt>vec;
rep(i,n){
cin>>a[i]>>b[i];
M[mp(a[i],b[i])] = i;
vec.pb(pt((double)(a[i]),(double)(b[i])));
}
vector<pt>c = convex_hull(vec);
if(c.size() == 2){
int xx = floor(c[0].real()+0.5);
int yy = floor(c[0].imag()+0.5);
ans[M[mp(xx,yy)]] = 0.5;
xx = floor(c[1].real()+0.5);
yy = floor(c[1].imag()+0.5);
ans[M[mp(xx,yy)]] = 0.5;
}
else{
for(int i=0;i<c.size();i++){
pt q = c[i];
pt p = c[(i-1+c.size())%c.size()];
pt r = c[(i+1)%c.size()];
double v = arg((p-q)/(r-q));
v = 3.141592653589 - v;
int xx = floor(c[i].real()+0.5);
int yy = floor(c[i].imag()+0.5);
ans[M[mp(xx,yy)]] = v / (2.0*3.141592653589);
}
}
rep(i,n){
printf("%.12f\n",ans[i]);
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG
int main(){
ll N;
cin>>N;
vector<ll> ex(N+10, 0);
if(N!=1){
for (ll i=2; i<N+1; i++){
ll onway=i; //途中の数
for(ll a=2; a*a<=onway; a++){
if(onway%a!=0)continue;
while(onway%a==0){
ex[a]++;
onway/=a;
}
}
if(onway!=1) ex[onway]++;
}
}
if(N==1) cout<<1<<endl;
else {
ll count=1;
for(ll i=2; i<=N; i++){
if(ex[i]==0)continue;
count*=ex[i]+1;
count%=mod;
}
cout<<count<<endl;
}
} | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int N;
long long A[MAXN], B[MAXN];
int main(){
scanf("%d", &N);
for(int i = 0; i < N; i++){
scanf("%lld", &A[i]);
B[i] = A[i];
}
long long r1 = 0, r2 = 0;
for(int i = 59, k = 0; i >= 0; i--){
int ind = -1, p = 0;
for(int j = 0; j < N; j++)if(B[j] & (1LL << i))
p ^= 1;
for(int j = k; j < N; j++)if(A[j] & (1LL << i)){
ind = j;
break;
}
if(p == 1){
r1 += 1LL << i;
continue;
}
if(ind == -1)continue;
swap(A[ind], A[k]);
if(!(r2 & (1LL << i)))r2 ^= A[k];
for(int j = k + 1; j < N; j++)
if(A[j] & (1LL << i))A[j] ^= A[k];
k++;
}
r2 &= ~r1;
printf("%lld\n", r1 + 2 * r2);
return 0;
}
| 0 |
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<set>
#include<vector>
using namespace std;
#define PI acos(-1.0)
#define pppp cout<<endl;
#define EPS 1e-8
#define LL long long
#define ULL unsigned long long //1844674407370955161
#define INT_INF 0x3f3f3f3f //1061109567
#define LL_INF 0x3f3f3f3f3f3f3f3f //4557430888798830399
// ios::sync_with_stdio(false);
// 那么cin, 就不能跟C的 scanf,sscanf, getchar, fgets之类的一起使用了。
const int dr[]= {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[]= {-1, 1, 0, 0, -1, 1, -1, 1};
int read()//输入外挂
{
int ret=0, flag=0;
char ch;
if((ch=getchar())=='-')
flag=1;
else if(ch>='0'&&ch<='9')
ret = ch - '0';
while((ch=getchar())>='0'&&ch<='9')
ret=ret*10+(ch-'0');
return flag ? -ret : ret;
}
const int maxn=100005;
LL dist[maxn];
bool vis[maxn];
int head[maxn];
int tot,n;
int fa[maxn];
struct node
{
int from,to;
LL w;
int next;
} edge[maxn*4];
struct Point
{
int id;
int x,y;
} p[maxn];
void add(int u,int v,LL w)
{
edge[tot].from=u;
edge[tot].to=v;
edge[tot].w=w;
edge[tot].next=head[u];
head[u]=tot++;
}
int Find(int x)
{
if(x==fa[x])
return x;
else
return fa[x]=Find(fa[x]);
}
bool cmp1(Point a,Point b)
{
return a.x<b.x;
}
bool cmp2(Point a,Point b)
{
return a.y<b.y;
}
bool cmp3(node a,node b)
{
return a.w<b.w;
}
int main()
{
memset(head,-1,sizeof(head));
for(int i=1; i<=maxn; i++)
fa[i]=i;
scanf("%d",&n);
for(int i=1; i<=n; i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
p[i].id=i;
}
sort(p+1,p+n+1,cmp1);
for(int i=2; i<=n; i++)
add(p[i-1].id,p[i].id,p[i].x-p[i-1].x);
sort(p+1,p+n+1,cmp2);
for(int i=2; i<=n; i++)
add(p[i-1].id,p[i].id,p[i].y-p[i-1].y);
sort(edge,edge+tot,cmp3);
int cnt=0;
LL ans=0;
for(int i=0; i<tot; i++)
{
int fu=Find(edge[i].from);
int fv=Find(edge[i].to);
if(fu!=fv)
{
fa[fu]=fv;
cnt++;
ans+=edge[i].w;
if(cnt==n-1)
break;
}
}
printf("%lld\n",ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back
ll N;
ll u,v;
ll ans;
vector<ll> vec[100005];
ll parent[100005];
bool leaf[100005]; //falseなら葉
void tree(ll par,ll n){
if(parent[n]!=0) return;
parent[n]=par;
for(auto &i:vec[n]) tree(n,i);
return;
}
ll Adis[100005];
ll Tdis[100005];
void Adfs(ll n,ll dis){
if(Adis[n]!=-1) return;
Adis[n]=dis;
for(auto&i:vec[n]) Adfs(i,dis+1);
return;
}
void Tdfs(ll n,ll dis){
if(Tdis[n]!=-1) return;
Tdis[n]=dis;
for(auto&i:vec[n]) Tdfs(i,dis+1);
return;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin>>N>>u>>v;
rep(i,N-1){
ll a,b;
cin>>a>>b;
vec[a].pb(b);
vec[b].pb(a);
}
tree(-1,v);
rep1(i,N+1){
ll n=parent[i];
if(n!=-1) leaf[n]=true;
}
fill(Adis+1,Adis+N+1,-1);
fill(Tdis+1,Tdis+N+1,-1);
Adfs(v,0);
Tdfs(u,0);
rep1(i,N+1){
if(!leaf[i]){
if(Tdis[i]<Adis[i]) ans=max(ans,Adis[i]);
}
}
cout<<ans-1<<endl;
}
| 0 |
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<iomanip>
#include<complex>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef stack<int> SI;
typedef queue<int> QI;
typedef list<int> LI;
typedef pair<int,int> PII;
typedef long long LL;
#define d(x) cout<<#x<<" = "<<(x)<<endl;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EMP empty()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(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 DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 1000000000
#define PI acos(-1.0)
////////////////////////////////////////////////
#define N 8
int row[N],col[N],dpos[N*2-1],dneg[N*2-1];
bool X[N][N];
void print()
{
REP(i,N)
{
REP(j,N)
{
if(X[i][j])
{
if(row[i]!=j)return ;
}
}
}
REP(i,N)
{
REP(j,N)
{
cout<<((row[i]==j)?"Q":".");
}
cout<<endl;
}
}
void recursive(int i)
{
if(i==N)
{
print();
return;
}
REP(j,N)
{
if(col[j]+dpos[i+j]+dneg[i-j+N-1]!=0)continue;
row[i]=j;col[j]|=1;dpos[i+j]|=1;dneg[i-j+N-1]|=1;
recursive(i+1);
row[i]^=row[i];col[j]^=col[j];dpos[i+j]^=dpos[i+j];dneg[i-j+N-1]^=dneg[i-j+N-1];
}
}
int main()
{
int k;
scanf("%d",&k);
REP(i,k)
{
int r,c;
scanf("%d%d",&r,&c);
X[r][c]=true;
}
recursive(0);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
ll x = 0; char ch = gc(); bool positive = 1;
for (; !isdigit(ch); ch = gc()) if (ch == '-') positive = 0;
for (; isdigit(ch); ch = gc()) x = x * 10 + ch - '0';
return positive ? x : -x;
}
inline void write(ll a){
if(a<0){
a=-a; putchar('-');
}
if(a>=10)write(a/10);
putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=305;
int n,a[N<<1][N<<1];
void hf(int x,int de){
int t=0;
while(x%4==0){x/=4; t++;}
if(x%4==2){
For(i,0,2*n-1){
For(j,0,2*n-1)if(i>>t&1)a[i][j]|=de;
}
}else {
For(i,0,2*n-1){
For(j,0,2*n-1)if(((i>>t)+(j>>t))&1)a[i][j]|=de;
}
}
}
vector<PI> v[4];
int main(){
n=read(); int d1=read(),d2=read();
hf(d1,1);
hf(d2,2);
For(i,0,2*n-1)For(j,0,2*n-1)v[a[i][j]].pb(mp(i,j));
For(i,0,3)if(v[i].size()>=n*n){
For(j,0,n*n-1)wri(v[i][j].fi),writeln(v[i][j].se); return 0;
}
} | 0 |
#include <iostream>
#define Free (-1)
#define NonFree (-2)
#define NoQ (-3)
using namespace std;
const int N = 8;
int row[N];
int col[N];
int dpos[15];
int dneg[15];
int inits[N];
void printBoard() {
for (int r = 0; r < N; ++r) {
for (int c = 0; c < N; ++c) {
if (row[r] != c) {
cout << ".";
} else {
cout << "Q";
}
}
cout << endl;
}
};
void putQueen(int i) {
int j;
if (i == N) {
printBoard();
return;
}
if (inits[i] == Free) {
for (j = 0; j < N; ++j) {
if (col[j] == NonFree ||
dpos[i + j] == NonFree ||
dneg[i - j + N - 1] == NonFree) {
continue;
}
row[i] = j;
col[j] = dpos[i + j] = dneg[i - j + N - 1] = NonFree;
putQueen(i + 1);
row[i] = NoQ;
col[j] = dpos[i + j] = dneg[i - j + N - 1] = Free;
}
}else{
putQueen(i + 1);
}
};
void DeskSetup(int r, int c) { // Basic
row[r] = c;
col[c] = dpos[r + c] = dneg[r - c + N - 1] = NonFree;
}
void InitDesk() { // Basic
for (int j = 0; j < N; ++j) {
row[j] = NoQ;
col[j] = inits[j] = Free;
}
for (int j = 0; j < 15; ++j) {
dpos[j] = dneg[j] = Free;
}
};
int main() {
int r, c, i;
InitDesk();
cin >> i;
for (int k = 0; k < i; ++k) {
cin >> r >> c;
DeskSetup(r, c);
inits[r] = NonFree;
}
putQueen(0);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll mod=1e9+7;
int main() {
ll m;
cin >> m;
ll n=0;
ll d=0;
for(ll i=0;i<m;i++) {
ll tc,td;
cin >> td >> tc;
n+=tc;
d+=td*tc;
}
cout << n-1+(d-1)/9 << endl;
} | 0 |
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <stack>
using namespace std;
int main(){
int n, p;
while(1){
cin >> n;
cin >> p;
if(n ==0 && p==0) break;
int sum[n];
int win=p;
int winner;
int flag = 0;
for(int i=0 ; i<n ; i++){
sum[i] = 0;
}
while(1){
for(int i=0 ; i<n ; i++){
if(p>0){
sum[i]++;
p--;
if(sum[i]==win){
flag = 1;
winner = i;
break;
}
}else{
p = sum[i];
sum[i] = 0;
}
}
if(flag == 1) break;
}
cout << winner << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(void) {
ll N, A, B;
cin >> N;
if(N == 1) {
cout << "Hello World" << endl;
} else {
cin >> A >> B;
cout << A + B << endl;
}
return 0;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
struct Graph{
Graph(int n):E(n),d(n){}
vector<vector<tuple<int,int,int>>>E;
vector<int>d;
void add_edge(int a,int b,int c,int d){
E[a].push_back(make_tuple(b,c,d));
}
void dijkstra(int s,int f){
priority_queue<P,vector<P>,greater<P>>q;
fill(d.begin(),d.end(),1e9);
q.push({d[s]=0,s});
while(q.size()){
auto p=q.top();q.pop();
if(p.first>d[p.second])continue;
for(auto& a:E[p.second]){
int x=get<0>(a),y=get<1>(a)+p.first;
if(f)y=get<2>(a)+p.first;
if(y<d[x])d[x]=y,q.push({y,x});
}
}
}
};
main(){
int n,m,a,b,c,d,k;
while(cin>>n>>m,n){
Graph E(m);
for(int i=0;i++<n;E.add_edge(--a,--b,c,d),E.add_edge(b,a,c,d))cin>>a>>b>>c>>d;
cin>>k;
for(int i=0;i++<k;cout<<E.d[--b]<<endl){
cin>>a>>b>>c;
E.dijkstra(--a,c);
}
}
} | #include<iostream>
#include<algorithm>
using namespace std;
#define MAX 1000000
int main(){
int n, m, a, b, cost, ti, k, p, q, r, point = 0;
int cost_[101][101], time_[101][101];
while ( cin >> n >> m && (n != 0 && m != 0)){
for (int i = 0; i < m; i++)
for (int j = 0; j < m; j++) { cost_[i][j] = time_[i][j] = MAX; }
for (int i = 0; i < n; i++){
cin >> a >> b >> cost >> ti;
cost_[a-1][b-1] = cost;
cost_[b-1][a-1] = cost;
time_[a-1][b-1] = ti;
time_[b-1][a-1] = ti;
}
for (int i = 0; i < m; i++){
for (int j = 0; j < m; j++){
for (int o = 0; o < m; o++){
cost_[j][o] = min(cost_[j][o], cost_[j][i] + cost_[i][o]);
time_[j][o] = min(time_[j][o], time_[j][i] + time_[i][o]);
}
}
}cin >> k;
for (int i = 0; i < k; i++){
cin >> p >> q >> r;
if (r != 1) cout << cost_[p-1][q-1] << endl;
else cout << time_[p-1][q-1] << endl;
}
}
return 0;
} | 1 |
#include<stdio.h>
#include<string.h>
int main(void) {
int a[10000],n,b=0,i,x,d=3;
char r[10000];
char s[10000];
scanf("%d", &n);
sprintf(s, "%d", d);
for(i = 1; i <= n; i++) {
sprintf(r,"%d", i);
if (i % 3 == 0) {
a[b] = i;
b++;
}
else if (strstr(r,s) != NULL) {
a[b] = i;
b++;
}
}
for (x = 0; x < b; x++) {
if (x == 0) {
printf(" ");
}
printf("%d",a[x]);
if (x == b - 1) {
printf("\n");
}
else {
printf(" ");
}
}
return 0;
}
| #include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
void call(int n) {
int i = 1;
int x;
bool flg = false;
while (1) {
// CHECK_NUM
x = i;
if ( x % 3 == 0 ){
cout << " " << i;
}
else {
while (1) {
// INCLUDE3
if ( x % 10 == 3 ){
cout << " " << i;
flg = true;
}
else {
x /= 10;
if ( x ) {
continue;
}
else {
flg = true;
}
}
if (flg == true) {
break;
}
}
}
flg = false;
// END_CHECK_NUM
if ( ++i <= n ) {
continue;
}
else {
cout << endl;
break;
}
}
}
int main(void)
{
int n;
cin >> n;
call(n);
return 0;
}
| 1 |
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;
int main() {
int A, B; cin >> A >> B;
vector<string> C(100);
for (int i = 0; i < 50; ++i) {
C[i] = string(100, '.'); // White
}
for (int i = 50; i < 100; ++i) {
C[i] = string(100, '#'); // Black
}
--A, --B;
for (int i = 0; i < 50 && B > 0; i += 2) {
for (int j = 0; j < 100 && B > 0; j += 2) {
C[i][j] = '#'; --B;
}
}
for (int i = 99; i > 50 && A > 0; i -= 2) {
for (int j = 0; j < 100 && A > 0; j += 2) {
C[i][j] = '.'; --A;
}
}
cout << 100 << " " << 100 << endl;
for (auto s : C) cout << s << endl;
}
| #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;
int main(void) {
int A, B;
cin >> A >> B;
cout << 100 << " " << 100 << endl;
vector< vector<int> > grad(100, vector<int>(100));
for(int i=0; i<50; i+=2) {
for(int j=0; j<100; j+=2) {
if(A > 1) {
grad[i][j] = 1;
--A;
}
}
}
for(int i=50; i<100; i++) {
for(int j=0; j<100; j++) {
grad[i][j] = 1;
if(B > 1 && i>50 && i%2 == 1 && j%2) {
grad[i][j] = 0;
--B;
}
}
}
for(int i=0; i<100; i++) {
for(int j=0; j<100; j++) {
if(grad[i][j]) {
cout << '.';
} else {
cout << '#';
}
}
cout << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 1e9+7;
int parent[N];
int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b%a, a);
}
int lcm(int a, int b) {
return (a*b)/gcd(a,b);
}
ll pow(ll x, ll y, ll p) {
if(y == 0) return 1;
ll res = 1;
x %= p;
if(x == 0) return 0LL;
while(y > 0) {
if(y & 1) res = (res*x) % p;
y >>= 1;
x = (x*x) % p;
}
return res;
}
int find(int x) {
return x == parent[x] ? x : parent[x] = find(parent[x]);
}
void Union(int x, int y) {
int xPar = find(x), yPar = find(y);
if(xPar != yPar) parent[xPar] = yPar;
}
ll nCr(ll n, ll r) {
ll res = 1;
for(ll i=1;i<=r;i++) {
res = res * (n - r + i) / i;
// is different from
// res *= (n -r + i) / i;
}
return res;
}
int ask(int i, int j) {
cout << "? " << i + 1 << ' ' << j + 1 << endl;
int v;
cin >> v;
return v;
}
void solve() {
int n, x, t;
cin >> n >> x >> t;
cout << (int)(ceil)(n / (double)x) * t << endl;
return;
}
int main()
{
IOS
//int t;
//cin >> t;
//while(t--)
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X, T;
cin >> N >> X >> T;
cout << (N + X - 1) / X * T << endl;
} | 1 |
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef double db;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef pair<ll,ll> PLL;
#define REP(x,l,u) for(ll x = l; x < u; x++)
#define RREP(x,l,u) for(ll x = l; x >= u; x--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mst(x,v) memset(x, v, sizeof(x))
#define sz(x) (ll)x.size()
string to_string(string s) {return s;}
string to_string(char c) {string s = string(1, c);return s;}
template <typename A, typename B> string to_string(pair<A,B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(vector<A> v) { string s = "("; int first = 1; for (A a : v) { if (!first) { s += ", "; } first = 0; s += to_string(a); } s += ")"; return s; }
template <typename A> string to_string(set<A> v) { string s = "("; int first = 1; for (A a : v) { if (!first) { s += ", "; } first = 0; s += to_string(a); } s += ")"; return s; }
void debug_out() {cerr << endl;}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }
void in() {}
template <typename A> void in(A & x) { cin >> x; }
template <typename A, typename B> void in(pair<A,B> & x) { in(x.first); in(x.second); }
template <typename A> void in(vector<A> & x) { REP(i,0,(ll)x.size()) in(x[i]); }
template <typename Head, typename... Tail> void in(Head & H, Tail & ... T) {in(H); in(T...); }
#ifndef ONLINE_JUDGE
#define debug(...) do { cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__); } while (false)
#else
#define debug(...) do { } while (false)
#endif
const ll inf = (ll)1e18 + 5;
const ll mod = 1e9+7;
ll nax = 1005;
VLL p(nax*nax, 1);
VLL P;
void init() {
p[0] = 0;
p[1] = 0;
for (ll x = 2; x < nax*nax; x++) {
if (p[x] == 0) {
continue;
}
P.push_back(x);
for (ll f = x; x * f < nax * nax; f++) {
p[x*f] = 0;
}
}
}
map<ll,ll> pf(ll x) {
map<ll,ll> f;
REP(i,0,sz(P)) {
if (P[i] * P[i] > x) break;
while (x % P[i] == 0) {
f[P[i]]++;
x /= P[i];
}
}
if (x > 1) f[x]++;
return f;
}
VLL F(100500, -1);
VLL INVF(100500, -1);
ll pow(ll a, ll b) {
if (b == 0) return 1;
ll h = pow(a, b/2);
ll ans = b % 2 ? h * h % mod * a : h * h;
ans %= mod;
return ans;
}
ll f(ll x) {
if (F[x] != -1) return F[x];
if (x == 0) return 1;
F[x] = f(x-1) * x % mod;
return F[x];
}
ll invf(ll x) {
if (INVF[x] != -1) return INVF[x];
INVF[x] = pow(f(x), mod-2);
return INVF[x];
}
ll ncr(ll n, ll r) {
// n! / r! / (n-r)!
ll ans = f(n);
ans *= invf(r);
ans %= mod;
ans *= invf(n-r);
ans %= mod;
return ans;
}
void solve() {
ll n, m;
in(n, m);
map<ll,ll> factors = pf(m);
REP(i,0,n) f(i); // ease on the recursion
ll ans = 1;
for (PLL a : factors) {
ans *= ncr(a.second + n - 1, a.second) % mod;
ans %= mod;
}
cout << ans << endl;
}
signed main() {
init();
ll t = 1;
REP(i,0,t) solve();
return 0;
} | #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};
vector<pair<long long, long long> > prime_factorize(long long N) {
vector<pair<long long, long long> > res;
for (long long a = 2; a * a <= N; ++a) {
if (N % a != 0) continue;
long long ex = 0; // 指数
// 割れる限り割り続ける
while (N % a == 0) {
++ex;
N /= a;
}
// その結果を push
res.push_back({a, ex});
}
// 最後に残った数について
if (N != 1) res.push_back({N, 1});
return res;
}
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() {
COMinit();
ll N,M;
cin >>N>>M;
ll ans=1;
const auto &res = prime_factorize(M);
for (auto p : res) {
ans = (ans*COM(N+p.second-1,p.second))%mod;
}
cout << ans << endl;
return 0;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
int n, m;
unordered_map<string, int> mp;
int main(void){
cin >> n;
rep(i, n){
string s;
cin >> s;
mp[s]++;
}
cin >> m;
rep(i, m){
string t;
cin >> t;
mp[t]--;
}
int ans = -INT_MAX;
for(auto i : mp){
ans = max(ans, i.second);
}
cout << max(ans, 0) << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;
const ll modP = 1000000007;
int main()
{
int n;
cin>>n;
vector<ll> A(n);
rep(i,n) cin>>A[i];
vector<ll> x(n+1,0);
vector<ll> y(n+1,0);
vector<ll> z(n+1,0);
for(int i = 0; i < n; i++){
x[i+1] = x[i];
y[i+1] = y[i];
z[i+1] = z[i];
if( A[i] == x[i]){
x[i+1]++;
}else if(A[i] == y[i]){
y[i+1]++;
}else{
z[i+1]++;
}
}
ll ans = 1;
for(int i = 0; i < n; i++){
int t = 0;
if( x[i] == A[i]) t++;
if( y[i] == A[i]) t++;
if( z[i] == A[i]) t++;
ans = (ans * t) % modP;
}
cout<<ans<<endl;
return 0;
}
| 0 |
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef pair < int, int > pii;
const int N = 16;
const int M = (1 << N);
const int INF = 0x3f3f3f3f;
int dp[N][M], g[N][N], n, m, rv[M];
int f(int st, int msk){
if(st == n - 1) return 0;
if(dp[st][msk] != -1) return dp[st][msk];
int sol = INF;
for(int msk1 = (msk - 1) & msk; msk1 ; msk1 = (msk1 - 1) & msk){
int msk2 = msk ^ msk1;
if(msk1 & (1 << (n - 1))) continue;
if(msk2 & (1 << st)) continue;
int sum = 0;
for(int t1 = msk1; t1 ; t1 -= t1 & (-t1)){
for(int t2 = msk2 ; t2 ; t2 -= t2 & (-t2)){
sum += g[rv[t1 & (-t1)]][rv[t2 & (-t2)]];
}
}
for(int t2 = msk2 ; t2 ; t2 -= t2 & (-t2)){
if(g[st][rv[t2 & (-t2)]]){
sol = min(sol, f(rv[t2 & (-t2)], msk2) + sum - g[st][rv[t2 & (-t2)]]);
}
}
}
return dp[st][msk] = sol;
}
int main(){
memset(dp, -1, sizeof(dp));
for(int i = 0;i<N;i++) rv[(1 << i)] = i;
memset(dp, -1, sizeof(dp));
scanf("%d%d", &n, &m);
for(int i = 0;i<m;i++){
int x, y;scanf("%d%d", &x, &y);x--;y--;
scanf("%d", &g[x][y]);
g[y][x] = g[x][y];
}
printf("%d\n", f(0, (1 << n) - 1));
}
| #pragma GCC optmize(3)
#include <cstdio>
#include <iostream>
#include <cstring>
#include <ctime>
#define rus register unsigned short
#define rs register short
using namespace std;
const int N = 15;
int G[N][N], dp[N][1 << N], cost[N][1 << N];
int n, m;
inline void upd(int &x, int y) {
if (x == -1) x = y;
else x = min(x, y);
}
inline int set_set(int x, int y) {
int ret = 0;
for (rs i = 0; i < n; i ++)
if (x & (1 << i)) ret += cost[i][y];
return ret;
}
int main() {
memset(dp, -1, sizeof dp);
scanf("%d%d", &n, &m);
for (int i = 1, x, y, z; i <= m; i ++) {
scanf("%d%d%d", &x, &y, &z);
x --; y --;
G[x][y] = G[y][x] = z;
}
int t = 1 << n;
for (rus s = 1; s < t; s ++)
for (rs i = 0; i < n; i ++)
if (s & (1 << i)) {
for (rs j = 0; j < n; j ++) cost[j][s] += G[i][j];
}
dp[0][1] = 0;
for (rus s = 1; s < t; s += 2) {
rus u = s ^ (t - 1);
for (rs i = 0; i < n; i ++)
if (s & (1 << i)) {
if (dp[i][s] == -1) continue;
for (rs j = 0; j < n; j ++)
if (!(s & (1 << j)) && G[i][j]) upd(dp[j][s | (1 << j)], dp[i][s] + cost[j][s ^ (1 << i)]);
for (rus v = u; v; v = (v - 1) & u)
upd(dp[i][v | s], dp[i][s] + set_set(v, s ^ (1 << i)));
}
}
printf("%d\n", dp[n - 1][t - 1]);
return 0;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n], b[n], c[n], d[n];
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 0; i < n; i++) {
cin >> c[i] >> d[i];
}
int blue_XtoY[205];
int red_XtoY[205];
memset(blue_XtoY, -1, sizeof(blue_XtoY));
memset(red_XtoY, -1, sizeof(red_XtoY));
for (int i = 0; i < n; i++) {
blue_XtoY[c[i]] = d[i];
red_XtoY[a[i]] = b[i];
}
int ans = 0;
set<int> st;
for (int right = 200; right >= 0; right--) {
if (red_XtoY[right] != -1) {
if (st.lower_bound(red_XtoY[right]) != st.end()) {
ans++;
st.erase(*st.lower_bound(red_XtoY[right]));
}
}
if (blue_XtoY[right] != -1) {
st.insert(blue_XtoY[right]);
}
}
cout << ans << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int n,a[203],ans;
int main(){
cin>>n;
for(int i=0;i<2*n;i++)
cin>>a[i];
sort(a,a+2*n);
for(int i=0;i<2*n;i+=2)
ans+=a[i];
cout<<ans;
} | 0 |
#include <bits/stdc++.h>
using namespace::std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;
template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
void _main() {
int n; cin >> n;
string s; cin >> s;
vector<int> w(n), e(n);
for (int i = 0; i < n; i++) {
if (i) w[i] = w[i - 1];
w[i] += s[i] == 'W';
}
for (int i = n - 1; i >= 0; i--) {
if (i + 1 < n) e[i] = e[i + 1];
e[i] += s[i] == 'E';
}
int ans = n;
for (int i = 0; i < n; i++) {
ans = min(ans, (i ? w[i - 1] : 0) + (i + 1 < n ? e[i + 1] : 0));
}
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("input.txt", "r", stdin);
int _t = 1;
// cin >> _t;
while (_t--) _main();
return 0;
}
| #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 vi = vector<int> ;
using vvi = vector<vector<int>> ;
using vl = vector<ll> ;
using vvl = vector<vector<ll>> ;
using vs = vector<string> ;
using vvs = vector<vector<string>> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
int main() {
ll n ;
cin >> n ;
vl a(n), b(n), c(n) ;
rep(i, n) cin >> a[i] ;
rep(i, n) cin >> b[i] ;
rep(i, n) cin >> c[i] ;
sort(a.begin(), a.end()) ;
sort(b.begin(), b.end()) ;
sort(c.begin(), c.end()) ;
ll ans = 0 ;
rep(i, n){
ll u = (lower_bound(a.begin(), a.end(), b[i]) - a.begin()) ;
ll v = n - (upper_bound(c.begin(), c.end(), b[i]) - c.begin()) ;
ans += u * v ;
}
cout << ans << endl ;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(int argc, char **argv) {
string s;
cin >> s;
bool ok = false;
for (int i = 0; i < s.length() - 1; ++i) {
ok |= s[i] == 'A' && s[i + 1] == 'C';
}
cout << (ok ? "Yes" : "No") << endl;
}
| #include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
//to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9
using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
long long GCD(long long a, long long b) {
if (b == 0) return a;
else return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
return a * b / GCD(a, b);
}
unsigned GetDigit(unsigned num) {
return std::to_string(num).length();
}
int tow(int n) {//2のn乗
if (n == 0)return 1;
int x = tow(n / 2);
x *= x;
if (n % 2 == 1)x *= 2;
return x;//@domino
}
int KETA(int n) { //Sum of Each Digit
int sum = 0;
while (n > 0) {
sum += n % 10; n /= 10;
}
return sum;
}
unsigned ND(unsigned num) {//Number of Digits
return std::to_string(num).length();//outmax=10
}
bool KIBN(string s) {
rep(i, s.size() / 2) {
if (s[i] != s[s.size() - 1 - i])return false;
}
return true;
}
/*
(char)toupper(a[n])=文字列のn文字目を大文字で出力
pow(a,b)=aのb乗
*/
int main(void) {
rapid_pleaseAC_fast;
string s;
cin >> s;
rep(i, s.size() - 1) {
if (s.substr(i, 2) == "AC") {
cout << "Yes" << rt;
return 0;
}
}
cout << "No" << rt;
please AC;
}
//参考:--- | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N; cin >> N;
for (int i = 100; i > 0; i /= 10) {
if (N / i == 7) {
cout << "Yes" << endl;
return 0;
}
N %= i;
}
cout << "No" << endl;
} | #pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h>
#include<random>
#define int long long
#define pp pair<int,int>
#define ss second
#define ff first
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type) type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v) sort(v,v+n)
#define mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
using namespace std;
//**********************************************DO IT NOW***************************************************************
void fastio()
{
#ifndef ONLINE_JUDGE
freopen("INPUT.txt","r",stdin);
freopen("OUTPUT.txt","w",stdout);
#endif
ios_base :: sync_with_stdio(false);
cin.tie(NULL) ;
cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
int a[1000000];
int pr(int n)
{
for(int i=2;i*i<=n;i++)
{
if(n%i==0)
return 0;
}
return 1;
}
signed main()
{
fastio();
int t=1;
// cin>>t;
while(t--)
{
string s;
cin>>s;
int c=0;
for(int i=0;i<s.length();i++)
{
if(s[i]=='7')
c++;
}
if(c)
cout<<"Yes";
else
cout<<"No";
}
}
// 🍪 🍪 🍪
| 1 |
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif
void d_err() {
cerr << endl;
}
template <typename H, typename... T>
void d_err(H h, T... t) {
cerr << h << " ";
d_err(t...);
}
template <typename T>
void print(T x) {
cout << x << endl;
}
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;
ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;
int main(){
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
ll L, R;
cin >> L >> R;
if (R - L >= 2018) {
print(0);
} else {
L %= 2019, R %= 2019;
int ans = 2018;
FOR(i, L, R + 1) FOR(j, i + 1, R + 1) {
ans = min(ans, i * j % 2019);
}
print(ans);
}
}
| #include <iostream>
using namespace std;
int main() {
int A, B; cin >> A >> B;
printf("%d\n", max(A + B, max(A - B, A * B)));
} | 0 |
#include<bits/stdc++.h>
using namespace std;
const int inf=1<<30,maxn=2000005;
int i,j,k,n,v[100000005];
int f[maxn],prime[maxn],tot,e[100005];
long long ans[505][505],mx;
map<long long,int> p;
void shai()
{
tot=0;
for(int i=2;i<maxn;i++)
{
if(!f[i])
prime[tot++]=i;
for(int j=0;j<tot&&prime[j]*i<maxn;j++)
{
f[i*prime[j]]=1;
if(i%prime[j]==0)
{
break;
}
}
}
}
long long gcd(long long a,long long b)
{
if(!b)
return a;
return gcd(b,a%b);
}
long long lcm(long long a,long long b)
{
if(a==0)
return b;
if(b==0)
return a;
return a/gcd(a,b)*b;
}
int main()
{
shai();
scanf("%d",&n);
int m=0;
for(i=1;i<=499;i+=2)
e[i]=++m;
for(i=2;i<=499;i+=2)
e[i]=++m;
for(i=500;i>=1;--i)
for(j=500;j>=1;--j)
if((i+j)&1)
{
for(k=prime[e[(i+j)/2]-1];v[k];k+=prime[e[(i+j)/2]-1]);
ans[i][j]=k;
v[k]=1;
p[k]=1;
}
for(i=1;i<=500;++i)
for(j=1;j<=500;++j)
if(ans[i][j]==0)
{
long long s=lcm(lcm(ans[i-1][j],ans[i][j-1]),lcm(ans[i+1][j],ans[i][j+1]));
ans[i][j]=s+1;
while(p[ans[i][j]])
ans[i][j]+=s;
p[ans[i][j]]=1;
}
for(i=1;i<=n;++i)
{
for(j=1;j<=n;++j)
{
printf("%lld ",ans[i][j]);
//mx=max(mx,ans[i][j]);
}
printf("\n");
}
//cout<<mx<<endl;
} | #include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> P;
signed main(){
vector<int> v;
int t=3;
while(v.size()<1000){
bool f=1;
for(int i=2;i*i<=t;i++)if(t%i==0)f=0;
if(f)v.push_back(t);
t++;
}
int d1[500][500],d2[500][500],c=0;
for(int i=-498;i<500;i+=2){
for(int j=-i;j+i<500;j++){
if(0<=j&&j<500&&0<=j+i&&j+i<500)d1[j][j+i]=v[c];
}
c++;
}
for(int i=0;i<1000;i+=2){
for(int j=1000;i-j<500;j--){
if(0<=j&&j<500&&0<=i-j&&i-j<500)d2[j][i-j]=v[c];
}
c++;
}
int n;
cin>>n;
int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0};
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(j)cout<<" ";
if((i+j)%2){
int res=1;
set<int> s;
for(int k=0;k<4;k++){
int nx=j+dx[k],ny=i+dy[k];
if(nx<0||ny<0||nx>=500||ny>=500)continue;
s.insert(d1[ny][nx]);
s.insert(d2[ny][nx]);
}
for(auto z:s){res*=z;}
cout<<res+1;
}
else cout<<d1[i][j]*d2[i][j];
}
cout<<endl;
}
return 0;
} | 1 |
#include <bits/stdc++.h> //万能头文件
using namespace std;
int main()
{
string a;
int pos=0; //记录位置
cin>>a;
a=a+"D"; //为防止最后一个字母是"A",添加一个不是"C"的字母
while(1)
{
pos=a.find("A",pos); //find()函数查找位置
if(pos<0) //如果没找到,返回-1
{
cout<<"No"<<endl; //endl养成好习惯
break; //跳出循环
}
if(a[pos+1]=='C') //判断"A"下一个是不是"C"
{
cout<<"Yes"<<endl;
break; //跳出循环
}
pos++; //下一次从pos+1找起
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define For(i, s, e) for(int i = s;i <= e;i++)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;
int main() {
string s;
cin >> s;
bool a=0,ac=0;
rep(i,s.size()-1) {
if(s[i] == 'A' && s[i+1] == 'C') ac = 1;
}
if(ac) cout << "Yes";
else cout << "No";
}
| 1 |
#include<bits/stdc++.h>
#define LL long long
#define MAXN 200005
using namespace std;
int N,M0,M1;
vector<int> adj[2][MAXN];
vector<int> s[2][MAXN];
int p[2][MAXN];
void dfs(int u, int x, int f){
p[f][u] = x;
s[f][x].push_back(u);
int v;
for(int k=0;k<adj[f][u].size();k++){
v = adj[f][u][k];
if(!p[f][v]) dfs(v, x, f);
}
}
int ans[MAXN], vis[MAXN];
void work(int id){
int x = p[0][id];
int v;
for(int k=0;k<s[0][x].size();k++){
v = s[0][x][k];
vis[p[1][v]]++;
}
for(int k=0;k<s[0][x].size();k++){
v = s[0][x][k];
ans[v] = vis[p[1][v]];
}
for(int k=0;k<s[0][x].size();k++){
v = s[0][x][k];
vis[p[1][v]]--;
}
}
int main(){
ios::sync_with_stdio(0);
cin>>N>>M0>>M1;
int u,v;
for(int i=1;i<=M0;i++){
cin>>u>>v;
adj[0][u].push_back(v);
adj[0][v].push_back(u);
}
for(int i=1;i<=M1;i++){
cin>>u>>v;
adj[1][u].push_back(v);
adj[1][v].push_back(u);
}
for(int i=1;i<=N;i++){
if(!p[0][i]){
dfs(i,i,0);
}
if(!p[1][i]){
dfs(i,i,1);
}
}
for(int i=1;i<=N;i++){
if(ans[i] == 0){
work(i);
}
}
//for(int i=1;i<=N;i++) cout<<p1[i]<<" "<<p2[i]<<endl;
for(int i=1;i<=N;i++) cout<<ans[i]<<" ";
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io;
typedef long long ll;
typedef long double db;
typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vii;
typedef pair<int, int> pi;
typedef tuple<int, int, int> t3;
typedef map<int, int> mi;
#define fi first
#define se second
#define vt vector
#define be begin()
#define ed end()
#define sz size()
#define cl clear()
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define lb(v, x) lower_bound(v.begin(), v.end(), x)
#define lbi(v, x) (lb(v, x) - v.begin())
#define tp(t, x, y) t x, y; tie(x, y)
#define tp3(t, x, y, z) t x, y, z; tie(x, y, z)
#define mp make_pair
#define mt make_tuple
#define co const
#define fc(x) for(int x = 1, _end = ri(); x <= _end; x++)
void uni(vi &v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); }
db rd() { db x; cin >> x; return x; }
ll ri() { ll x; cin >> x; return x; }
string rs() { string s; cin >> s; return s; }
pi rpi() { pi x; cin >> x.fi >> x.se; return x; }
vi rvi(int n, int f = 0) { vi v(n + f); for (int i = f; i < v.size(); i++) cin >> v[i]; return v; }
vii rvii(int n, int m, int f = 0) { vii v(n + f, vi(n + f)); for (int i = f; i < v.size(); i++) for (int j = f; j < v[0].size(); j++) cin >> v[i][j]; return v; }
void pr() {}; template <class T, class ...U> void pr(T x, U ...y) { cout << x << ' ', pr(y...); }
void prl() { cout << '\n'; }; template <class T, class ...U> void prl(T x, U ...y) { cout << x << ' ', prl(y...); }
void pr(const vi &v, int f = 0) { for (int i = f; i < v.size(); i++) cout << v[i] << ' '; }
void prl(const vi &v, int f = 0) { pr(v, f); cout << '\n'; }
void pr(const pi &x) { cout << x.fi << ' ' << x.se; };
void prl(const pi &x) { pr(x); cout << '\n'; }
#define rep(i, l, r) for (int i = l; i < r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
const int N = 2e5 + 5, M = 1e9 + 7;
int fa[N];
int fi(int x) {
return !fa[x] || fa[x] == x ? x : fa[x] = fi(fa[x]);
}
vi g[N];
map<int, vi> cnt;
bool vis[N];
void dfs(int u) {
vis[u] = 1;
cnt[fi(u)].pb(u);
for (auto &v : g[u]) {
if (!vis[v]) dfs(v);
}
}
int main() {
int n = ri(), a = ri(), b = ri();
rep(i, 0, a) {
int x = ri(), y = ri();
fa[fi(x)] = fi(y);
}
rep(i, 0, b) {
int u = ri(), v = ri();
g[u].pb(v);
g[v].pb(u);
}
vi ans(n + 1);
rep(i, 1, n + 1) {
if (!vis[i]) {
cnt.clear();
dfs(i);
for (auto &p : cnt) {
for (auto &v : p.se) {
ans[v] = p.se.sz;
}
}
}
}
pr(ans, 1);
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
#define fi first
#define se second
#define FOR(a,b,c) for(int a=b, __c=c; a<=__c; ++a)
const int N=2e5+5;
int n,a[N],b[N];
int cnt[N],d[N],ans[N];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n;
FOR(i,1,n) cin>>a[i];
FOR(i,1,n) cin>>b[i];
FOR(i,1,n) cnt[a[i]]++, cnt[b[i]]++, d[b[i]]++;
multiset<ii> s;
FOR(i,1,n) if(d[i]) s.insert({cnt[i],i});
FOR(i,1,n){
auto p=*s.rbegin();
s.erase(p);
if(p.se==a[i]){
if(s.empty()) return cout<<"No\n",0;
p=*s.rbegin();
s.erase(p);
s.insert(make_pair(cnt[a[i]],a[i]));
}
s.erase(make_pair(cnt[p.se],p.se));
d[p.se]--;
cnt[p.se]--;
if(d[a[i]]) s.erase({cnt[a[i]],a[i]});
cnt[a[i]]--;
if(d[p.se]) s.insert({cnt[p.se],p.se});
if(d[a[i]]) s.insert({cnt[a[i]],a[i]});
ans[i]=p.se;
}
cout<<"Yes\n";
FOR(i,1,n) cout<<ans[i]<<' ';
}
| // ALDS1_6_B.cpp
// Sort II - Partition
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
int Partition(vector<int>& A, int p, int r)
{
int tmp = A[r];
int i = p - 1;
for (int j = p; j < r; j++) {
if (A[j] <= tmp) {
i++;
swap(A[i], A[j]);
}
}
swap(A[++i], A[r]);
return i;
}
int main()
{
int n;
cin >> n;
vector<int> A(n);
for (int i = 0; i < n; i++) {
cin >> A[i];
}
int pivot = Partition(A, 0, n - 1);
for (int i = 0; i < n; i++) {
if (i > 0) cout << " ";
if (i == pivot) printf("[%d]", A[i]);
else cout << A[i];
}
cout << endl;
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<ll>>;
#define MAX 1000000007
int main()
{
int n;double l;
cin >> n >> l;
vector<double> taste(n);
rep(i,n){
taste[i]=l+i+1-1;
}
double sum=0;
rep(i,n){
sum+=taste[i];
}
int ans_i=MAX;
int p;
rep(i,n){
if(abs(taste[i]-0)<ans_i){
p=i;
ans_i=abs(taste[i]-0);
}
}
sum-=taste[p];
cout << sum << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int K,X;cin>>K>>X;
for (int i = X-K+1; i <= X+K-1; i++)cout<<i<<" ";
cout<<endl;
} | 0 |
#include<cstdio>
#include<cstring>
#include<stack>
#include<algorithm>
using namespace std;
const long long MAXN=1000005;
int n,m;
char S[MAXN],T[MAXN];
stack<int> s[30];
pair<int,int> que[MAXN];
int hd,tl;
int main()
{
scanf("%d%s%s",&n,S+1,T+1);
for(int i=1;i<=n;i++)
s[S[i]-'a'].push(i);
hd=1;tl=0;
int now=n,last=n+1,c=0;
int ans=0;
for(int i=n;i>=1;i--)
{
now=min(now,i);
while(!s[T[i]-'a'].empty()&&s[T[i]-'a'].top()>now)
s[T[i]-'a'].pop();
if(s[T[i]-'a'].empty())
{
puts("-1");
return 0;
}
now=s[T[i]-'a'].top();
if(now==i||now==last)
{
last=now;
continue;
}
last=now;
while(hd<=tl&&que[hd].first-que[hd].second-c+1>i)
{
ans=max(ans,que[hd].second+c);
hd++;
}
c++;
que[++tl]=make_pair(now,1-c);
}
for(int i=hd;i<=tl;i++)
ans=max(ans,que[i].second+c);
printf("%d\n",ans);
return 0;
}
| #define _DEBUG 1
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z) \
cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
<< endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
const ll LINF = 2e18;
const int INF = 1e9;
void solve(ll N, ll Q, std::string S, std::vector<ll> l, std::vector<ll> r) {
vector<ll> a(N, 0);
FOR(i, 1, N) {
a.at(i) = a.at(i - 1);
if (S.at(i) == 'C' && S.at(i - 1) == 'A') a.at(i) += 1;
}
rep(i, Q) cout << a.at(r.at(i) - 1) - a.at(l.at(i) - 1) << endl;
}
int main() {
ll N;
scanf("%lld", &N);
ll Q;
scanf("%lld", &Q);
std::string S;
std::cin >> S;
std::vector<ll> l(Q);
std::vector<ll> r(Q);
for (int i = 0; i < Q; i++) {
scanf("%lld", &l[i]);
scanf("%lld", &r[i]);
}
solve(N, Q, S, std::move(l), std::move(r));
return 0;
}
| 0 |
#include<stdio.h>
int main(void)
{
int a,s,d[2000],f,g,h,i,j;
scanf("%d %d",&a,&s);
while(a!=0&&s!=0){
for(i=1;i<=a;i++){
scanf("%d",&d[i]);
}
for(i=1;i<=a;i++){
for(j=i;j<=a;j++){
if(d[i]<d[j]){
f=d[i];
d[i]=d[j];
d[j]=f;
}
}
}
g=0;
h=0;
for(i=1;i<=a;i++){
if(g==s-1){
g=0;
d[i]=0;
}
else if(g!=s-1){
g++;
h+=d[i];
}
//printf("%d %d\n",g,d[i]);
}
printf("%d\n",h);
scanf("%d %d",&a,&s);
}
return 0;
} | #include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n, m;
long long p[1000];
while(1) {
cin >> n >> m;
if (n == 0 && m == 0) break;
long long ans = 0;
for (int i = 0; i < n; i++) {
cin >> p[i];
ans += p[i];
}
sort(p, p+n, std::greater<long long>());
for (int i = m-1; i < n; i += m) {
ans -= p[i];
}
cout << ans << endl;
}
} | 1 |
#include <iostream>
#include <string>
using namespace std;
const string check = "Hoshino";
int main()
{
int n;
string str;
cin >> n;
getline(cin,str);
for(int loop=0;loop<n;loop++){
getline(cin,str);
for(unsigned i=0;i<str.size();i++){
bool flag = true;
for(unsigned j=0;j<check.size();j++){
if(i+j < str.size()){
if(str[i+j] != check[j])
flag = false;
else{
if(j == check.size()-1 && flag)
str[i+j] = 'a';
}
}
}
}
cout << str << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>
using namespace std;
#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
int main() {
int n;
string sn;
getline(cin, sn);
n = atoi(sn.c_str());
REP(i, n){
string s;
getline(cin, s);
while (s.find("Hoshino") != string::npos){
s[s.find("Hoshino") + 6] = 'a';
}
cout << s << endl;
}
} | 1 |
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;
#define rep(i, a, n) for(int i=a; i<n; i++)
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REPS(i, n) for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n) for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c) for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n) setfill('0') << right << setw(n)
#define mp(a, b) make_pair(a, b)
#define toLower(c) c+0x20
#define toUpper(c) c-0x20
#define pb push_back
#define eb emplace_back
const int INF = 1e9;
const long long LLINF = 1e18;
const ull MOD = 998244353;
const int MSIZE = 100007;
const double Pi = 3.14159265358979323146;
int main(){
int match[10] = {6,2,5,5,4,5,6,3,7,6};
int n, m; cin >> n >> m;
vector<int> num(m), dp(n+100, -INF);
REP(i, m){
cin >> num[i];
}
dp[0]=0;
sort(RALL(num));
string ans = "";
for(int i=1; i<=n; i++){
REP(j, m){
if(i-match[num[j]]<0) continue;
dp[i] = max(dp[i], dp[i-match[num[j]]]+1);
}
}
//cout << n << ":" << ans << endl;
while(n>0){
REP(j, m){
if(n-match[num[j]]<0) continue;
if(dp[n-match[num[j]]]==dp[n]-1){
ans += ('0'+num[j]);
n-=match[num[j]];
//cout << n << ":" << ans << endl;
break;
}
}
}
cout << ans << endl;
}
| #include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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(b<a){a=b;return true;}return false;}
struct IOSetup{
IOSetup(){
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(12);
}
} iosetup;
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
os<<p.first<<" "<<p.second;
return os;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
return os;
}
template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
is>>p.first>>p.second;
return is;
}
template<typename T>
istream &operator>>(istream &is,vector<T>&v){
for(T &x:v)is>>x;
return is;
}
int dp[310][310][610];
signed main(){
string s;cin>>s;
int m;cin>>m;
int n=(int)s.size();
if(m>=n){
cout<<n<<endl;
return 0;
}
string t=s;
reverse(ALL(t));
rep(i,n)rep(j,n)rep(k,m+1){
chmax(dp[i+1][j+1][k],dp[i][j][k]+(s[i]==t[j]));
chmax(dp[i+1][j+1][k],dp[i][j+1][k]);
chmax(dp[i+1][j+1][k],dp[i+1][j][k]);
chmax(dp[i+1][j+1][k+1],dp[i][j][k]+1);
}
int res=0;
// t=rev(s)
// s = [a ][b ]
// t = [rb ][ra ]
// LCS(a,rb)=LCS(b,ra)
// 文字同士をマッチングさせることを考えるとそれはそう
rep(i,n+1)chmax(res,2*dp[i][n-i][m]);
rep(i,n) chmax(res,2*dp[i][n-1-i][m]+1);
cout<<res<<endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,s;
deque<pair<ll,ll> >vec;
ll rec(){
if(vec.empty()) return 0LL;
int sz = vec.size();
if(vec[0].sc >= vec[sz-1].sc){
vec[0].sc += vec[sz-1].sc;
ll pos = vec[sz-1].fi;
vec.pop_back();
sz--;
if(vec[0].fi > s){
return pos-s;
}
else if(vec[sz-1].fi < s){
return s-vec[0].fi-vec[0].fi+pos;
}
else{
if(vec[0].sc >= vec[sz-1].sc){
ll cst = pos-vec[sz-1].fi;
ll ans = rec();
return ans+cst;
}
else{
ll cst = pos-vec[0].fi;
ll ans = rec();
return ans+cst;
}
}
}
else{
vec[sz-1].sc += vec[0].sc;
ll pos = vec[0].fi;
vec.pop_front();
sz--;
if(vec[sz-1].fi < s){
return s-pos;
}
else if(vec[0].fi > s){
return vec[sz-1].fi-s-pos+vec[sz-1].fi;
}
else{
if(vec[0].sc >= vec[sz-1].sc){
ll cst = vec[sz-1].fi-pos;
ll ans = rec();
return ans+cst;
}
else{
ll cst = vec[0].fi-pos;
ll ans = rec();
return ans+cst;
}
}
}
}
int main(){
cin>>n>>s;
rep(i,n){
int x,p ; cin>>x>>p;
vec.pb(pair<ll,ll>(x,p));
}
if(vec[0].fi > s){
cout<<vec[n-1].fi-s<<endl;
return 0;
}
if(vec[n-1].fi < s){
cout<<s-vec[0].fi<<endl;
return 0;
}
ll ans = rec();
cout<<ans<<endl;
} | #include<iostream>
#include<algorithm>
using namespace std;
int main (void)
{
int n,m,p[100000],p2[100000],pp,w,a,i;
string s;
cin>>n>>m;
w=0;a=0;
for(i=0;i<n;i++){p[i]=0;p2[i]=0;}
for(i=0;i<m;i++)
{
cin>>pp>>s;
if(p2[pp-1]==0&&s=="WA"){p[pp-1]++;}
if(p2[pp-1]==0&&s=="AC"){a++;p2[pp-1]=1;}
}
for(i=0;i<n;i++)
{
if(p2[i]==1){w+=p[i];}
}
cout<<a<<" "<<w;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;
int main(){
ll n, t;
cin >> n >> t;
ll ans=0;
ll pre=0;
ll push=0;
cin >> pre;
for(int i=0; i<n-1; i++){
pre = push;
cin >> push;
if(push-pre < t) ans += push-pre;
else ans += t;
}
ans += t; //最後の一回
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;
const int MOD = 1000000007;
int main() {
ll N;
cin >> N;
vector<ll> A(N+2);
A[0] = 0;
for (int i = 1; i <= N; i++) cin >> A[i];
A[N+1] = 0;
ll sum = 0;
for (int i = 0; i <= N; i++){
sum += abs(A[i] - A[i + 1]);
}
for (int i = 0; i < N; i++) {
cout << sum - abs(A[i + 1] - A[i]) - abs(A[i + 1] - A[i + 2]) +abs(A[i] - A[i + 2])<< endl;
}
return 0;
} | 0 |
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
LL n,d;
LL col[2][500005] = {0};
LL v[4][500005],cnt[4] = {0};
LL id(LL x,LL y){ return x * n + y + 1; } // (x,y) -> id
LL getx(LL x){ return (x - 1) / n; } // id(x,y) -> x
LL gety(LL y){ return (y - 1) % n; } // id(x,y) -> y
void dfs(LL u,LL idd){
LL tx = getx(u),ty = gety(u);
for(LL dy,dx = 0;dx <= n;dx ++){
if(dx * dx > d) continue;
dy = sqrt(d - dx * dx);
if(dx * dx + dy * dy != d) continue;
if(tx + dx < n && ty + dy < n)
if(col[idd][id(tx + dx,ty + dy)] == -1) { col[idd][id(tx + dx,ty + dy)] = 1 - col[idd][u]; dfs(id(tx + dx,ty + dy),idd); }
if(tx + dx < n && ty - dy >= 0)
if(col[idd][id(tx + dx,ty - dy)] == -1) { col[idd][id(tx + dx,ty - dy)] = 1 - col[idd][u]; dfs(id(tx + dx,ty - dy),idd); }
if(tx - dx >= 0 && ty + dy < n)
if(col[idd][id(tx - dx,ty + dy)] == -1) { col[idd][id(tx - dx,ty + dy)] = 1 - col[idd][u]; dfs(id(tx - dx,ty + dy),idd); }
if(tx - dx >= 0 && ty - dy >= 0)
if(col[idd][id(tx - dx,ty - dy)] == -1) { col[idd][id(tx - dx,ty - dy)] = 1 - col[idd][u]; dfs(id(tx - dx,ty - dy),idd); }
}
}
int main(){
memset(col,-1,sizeof(col));
cin >> n; n <<= 1;
cin >> d;
for(LL i = 0;i < n;i ++)
for(LL j = 0;j < n;j ++)
if(col[0][id(i,j)] == -1){ col[0][id(i,j)] = 1; dfs(id(i,j),0); }
cin >> d;
for(LL i = 0;i < n;i ++)
for(LL j = 0;j < n;j ++)
if(col[1][id(i,j)] == -1){ col[1][id(i,j)] = 1; dfs(id(i,j),1); }
/*
for(LL i = 0;i < n;i ++)
for(LL j = 0;j < n;j ++)
cout << col[0][id(i,j)] << (j == n - 1 ? '\n' : ' ');
for(LL i = 0;i < n;i ++)
for(LL j = 0;j < n;j ++)
cout << col[1][id(i,j)] << (j == n - 1 ? '\n' : ' ');
*/
for(LL i = 1;i <= id(n - 1,n - 1);i ++){
LL co = col[0][i] + col[1][i] * 2;
v[co][++ cnt[co]] = i;
}
for(LL i = 0;i < 4;i ++){
if(cnt[i] >= n * n / 4){
for(LL j = 1;j <= n * n / 4;j ++) cout << getx(v[i][j]) << ' ' << gety(v[i][j]) << '\n';
break;
}
}
return 0;
} | // template version 1.8
// varibable settings {{{
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
#define int long long
#define INF 1e18
// #define INF 2147483647
#define MOD 998244353
#define infile "../test/sample-1.in"
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second
// }}}
// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
// dump macro
#ifdef PCM
#include "dump.hpp"
#else
#define dump(...) 42
#define dump_1d(...) 42
#define dump_2d(...) 42
#endif
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
// }}}
int dp[300][90005];
int dp2[300][90005];
int solve(){
int n;
cin>>n;
vi a(n); rep(i, n) {cin>>a[i];}
sort(all(a));
int S = accumulate(all(a), 0LL);
int r = (S%2==0 ? S/2 : S/2+1);
dump(S, r);
dp[0][a[0]]=1;
dp[0][0]=2;
rep(i, 1, n){
rep(j, S+5){
dp[i][j+a[i]] += dp[i-1][j];
dp[i][j+a[i]] %= MOD;
dp[i][j] += 2*dp[i-1][j];
dp[i][j] %= MOD;
}
}
int x = 0;
rep(i, r, S+5){
x+=dp[n-1][i];
x%=MOD;
}
int A = 1;
rep(i, n){
A *= 3;
A %= MOD;
}
int res;
if (S%2!=0){
res = A - 3*x;
res %=MOD;
}
else{
dp2[0][a[0]]=1;
dp2[0][0]=1;
rep(i, 1, n){
rep(j, S+5){
dp2[i][j+a[i]] += dp2[i-1][j];
dp2[i][j+a[i]] %= MOD;
dp2[i][j] += dp2[i-1][j];
dp2[i][j] %= MOD;
}
}
res = A - (3*x-dp2[n-1][S/2]*3);
res %=MOD;
}
cout << (res<0 ? res+MOD : res) << endl;
return 0;
}
signed main() { //{{{
#ifdef INPUT_FROM_FILE
std::ifstream in(infile);
std::cin.rdbuf(in.rdbuf());
#endif
solve();
return 0;
} //}}}
| 0 |
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int main(){
// sengen
LL n,a[5];
// nyuryoku
cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
// keisan
LL ans = 4;
LL plus = 0;
if(n%a[0] == 0){
plus = n/a[0];
}else{
plus = n/a[0] + 1;
}
for(int i=1;i<5;i++){
if(n%a[i] == 0){
plus = max(plus,n/a[i]);
}else{
plus = max(plus,n/a[i] + 1);
}
}
// syutsuryoku
cout << plus + ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
if (b < a)
{
a = b;
return true;
}
return false;
}
signed main()
{
ll n;
cin >> n;
vector<ll> a;
rep(i, 5)
{
ll b;
cin >> b;
a.push_back(b);
}
sort(all(a));
cout << (n + a[0] - 1LL) / a[0] + 4LL << endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pll pair <ll , ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define X first
#define Y second
#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)
vector <ll> o;
vector <ll> e;
vector <ll> a;
vector <ll> b;
void print()
{
for (ll i = 0; i < a.size(); i++)
{
cout << a[i] << " ";
}
cout << endl;
cout << b.size() << endl;
for (ll i = 0; i < b.size(); i++)
{
cout << b[i] << " ";
}
cout << endl;
}
int main()
{
ios_base :: sync_with_stdio(false);
cin.tie(0);
ll n , m;
cin >> n >> m;
for (ll i = 1; i <= m; i++)
{
ll x;
cin >> x;
if (x & 1)
{
o.pb(x);
}
else
{
e.pb(x);
}
}
if (o.size() == 0)
{
b.pb(1);
for (ll i = 0; i < (ll)(e.size()) - 1; i++)
{
a.pb(e[i]);
b.pb(e[i]);
}
a.pb(e.back());
b.pb(e.back() - 1);
print();
return 0;
}
if (o.size() == 1)
{
if (n == o[0])
{
a.pb(o[0]);
if (o[0] > 1)
{
b.pb(o[0] - 1);
}
b.pb(1);
}
else
{
a.pb(o[0]);
b.pb(o[0] + 1);
for (ll i = 0; i < (ll)(e.size()) - 1; i++)
{
a.pb(e[i]);
b.pb(e[i]);
}
a.pb(e.back());
b.pb(e.back() - 1);
}
print();
return 0;
}
if (o.size() == 2)
{
a.pb(o[0]);
if (o[0] > 1)
{
b.pb(o[0] - 1);
}
for (ll i = 0; i < e.size(); i++)
{
a.pb(e[i]);
b.pb(e[i]);
}
a.pb(o[1]);
b.pb(o[1] + 1);
print();
return 0;
}
cout << "Impossible";
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
using vc=vector<char>;
int dr[4]={-1,0,0,1};
int dc[4]={0,-1,1,0};
void bfs(const vector<vc> &field, vector<vi> &dist){
queue<pair<int,int>> que;
que.push({1,1});
dist[1][1]=0;
while(!que.empty()){
auto x=que.front(); que.pop();
for(int i=0;i<4;i++){
int nr=x.first+dr[i];
int nc=x.second+dc[i];
if(field[nr][nc]=='#') continue;
if(dist[nr][nc]!=-1) continue;
dist[nr][nc]=dist[x.first][x.second]+1;
que.push({nr,nc});
}
}
}
int main(){
int r,c;
cin >> r >> c;
vector<vc> field(r+2,vc(c+2,'#'));
int ans=0;
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
cin >> field[i][j];
if(field[i][j]=='.') ans++;
}
}
vector<vi> dist(r+2,vi(c+2,-1));
bfs(field,dist);
if(dist[r][c]==-1){
cout << "-1" << endl;
return 0;
}
cout << ans-dist[r][c]-1 << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
const int MAXN = 100000;
typedef pair<int, int> ii;
typedef vector<ii> vii;
vii adjList[MAXN];
int dist[MAXN]; bitset<MAXN> inq;
queue<int> q;
int main(){
int N, E, S;
cin >> N >> E >> S;
for (int i=0; i<E; i++){
int s, t, d;
cin >> s >> t >> d;
adjList[s].push_back(ii(d,t));
}
memset(dist, -1, sizeof(dist)); dist[S] = 0;
inq.reset(); inq[S] = 1;
q.push(S);
while (!q.empty()) {
int x = q.front(); q.pop();
inq[x] = 0;
for (vii::iterator it = adjList[x].begin(); it != adjList[x].end(); ++it) {
int nn = it->se;
int nd = dist[x]+it->fi;
if (dist[nn] != -1 && dist[nn] <= nd) continue;
dist[nn] = nd;
if (!inq[nn]) q.push(nn);
inq[nn] = 1;
}
}
for (int i=0; i<N; i++){
if (dist[i] == -1) cout << "INF" << endl;
else cout << dist[i] << endl;
}
} | #include <bits/stdc++.h>
//{{{ graph.hpp
#ifndef INCLUDE_GRAPH_HPP
#define INCLUDE_GRAPH_HPP
#include <vector>
namespace orislib {
struct Edge {
typedef int weight_t;
int from, to;
weight_t w;
Edge(int from, int to, weight_t w) : from(from), to(to), w(w) {}
bool operator<(const Edge& e) const {
return w > e.w;
}
};
typedef std::vector<Edge> Edges;
typedef std::vector<Edges> Graph;
}
#endif
//}}}
using namespace orislib;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
//{{{ templates
#define TMPINL_(...) template<__VA_ARGS__>inline
#define TT_ TMPINL_(typename T)
#define TTF_ TMPINL_(typename T,typename F)
#define TTTS_ TMPINL_(typename T,typename...Ts)
#define TITS_ TMPINL_(size_t I=0,typename...Ts)
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type&x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type&x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TITS_ typename enable_if<I==tuple_size<tuple<Ts...>>::value-1,string>::type join(string s,tuple<Ts...>t){return to_string(get<I>(t));}
TITS_ typename enable_if<I<tuple_size<tuple<Ts...>>::value-1,string>::type join(string s,tuple<Ts...>t){return to_string(get<I>(t))+s+join<I+1>(s,t);}
TT_ string join(string s,T t){return to_string(t);}
TTTS_ string join(string s,T t,Ts...ts){return join(s,t)+s+join(s,ts...);}
inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
inline int puts(const string&s){ return puts(s.c_str()); }
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
void dijkstra(const Graph& g, int s, vector<Edge::weight_t>& dist, vector<int>& prev)
{
const int V = g.size();
const Edge::weight_t INF = INT_MAX;
prev.assign(V, -1);
dist.assign(V, INF);
dist[s] = 0;
priority_queue<Edge> pq;
for (pq.push(Edge(-2, s, 0)); !pq.empty(); pq.pop()){
Edge c = pq.top();
if (prev[c.to] != -1) continue;
prev[c.to] = c.from;
dist[c.to] = c.w;
for (const auto& e : g[c.to]){
pq.push(Edge(e.from, e.to, e.w + c.w));
}
}
}
int main()
{
int V, E, r;
V = in(), E = in(), r = in();
Graph g(V);
for (int i = 0; i < E; i++){
int s, t, d;
s = in(), t = in(), d = in();
g[s].emplace_back(s, t, d);
}
vector<Edge::weight_t> ws;
vector<int> prev;
dijkstra(g, r, ws, prev);
show(ws, [](int v){
if (v == INT_MAX) cout << "INF";
else cout << v;
}, "\n");
return 0;
} | 1 |
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007
using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;
template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }
#ifdef DEBUG
#define debug(fmt, ...) \
printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
debug("size %ld: ", arr.size()); \
for(auto e: arr) cout << e << " "; \
cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif
int main(void) {
string str;
cin >> str;
stack<char> stack;
for(int i = 0; i < str.length(); i++) {
char ch = str[i];
switch(ch) {
case 'S':
stack.push('S');
break;
case 'T':
if((!stack.empty()) && stack.top() == 'S') {
stack.pop();
} else {
stack.push('T');
}
break;
default:
break;
}
debug("size: %ld\n", stack.size());
}
cout << stack.size() << endl;
return 0;
} | #include <iostream>
#include <cstring>
#include <stack>
using namespace std;
stack<char> stacky;
int solve(string X, int N, int ans) {
for(int i=0; i<N; i++) {
if(X[i] == 'S') stacky.push('S');
else { // encounter 't'
if(!stacky.empty()) stacky.pop();
else ans++;
}
}
ans += stacky.size();
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string X;
cin >> X;
int N = X.size();
cout << solve(X, N, 0) << endl;
} | 1 |
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[200000];
int main()
{
int i,n,flag=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
for(i=0;i<n-1;i++)
{
if(a[i]==a[i+1])
{
flag=1;
break;
}
}
if(flag==1)
{
printf("NO\n");
}
else
{
printf("YES\n");
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n; cin >> n;
map<ll, ll> mp;
for (int i = 0; i < n; i++) {
ll a; cin >> a;
mp[a]++;
}
ll cnt = 0;
for (auto u : mp) {
if (1 < u.second) cnt++;
}
string ans = "YES";
if (1 <= cnt) ans = "NO";
cout << ans << endl;
return 0;
} | 1 |
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define MOD 998244353
// x^n
ll mod_pow(ll x, ll n) {
if (n == 0) return 1;
ll res = mod_pow(x * x % MOD, n / 2);
if (n & 1) res = res * x % MOD;
return res;
}
// x^{-1}
ll mod_inv(ll x) { return mod_pow(x, MOD - 2); }
vector<ll> fact;
vector<ll> fact_inv;
void init_fact(int n) {
fact.resize(n + 1);
fact_inv.resize(n + 1);
fact[0] = fact_inv[0] = 1;
for (int i = 0; i < n; ++i) {
fact[i + 1] = fact[i] * (i + 1) % MOD;
fact_inv[i + 1] = fact_inv[i] * mod_inv(i + 1) % MOD;
}
}
ll nCr(ll n, ll r) {
if (n < r || n < 0 || r < 0) return 0;
return fact[n] * fact_inv[r] % MOD * fact_inv[n - r] % MOD;
}
ll nPr(ll n, ll r) { return nCr(n, r) * fact[r] % MOD; }
int main() {
int n, m, k;
cin >> n >> m >> k;
init_fact(n);
ll ans = 0;
for (int i = 0; i <= k; ++i) {
ll res = nCr(n - 1, n - 1 - i);
res = (res * m) % MOD;
res = (res * mod_pow(m - 1, n - 1 - i)) % MOD;
ans = (ans + res) % MOD;
}
cout << ans << endl;
return 0;
} | using namespace std;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(ll i=0;i<n;i++)
#define Rip(i,n) for(ll i=1;i<n;i++)
#define all(V) V.begin(),V.end()
#define ll long long
#define ld long double
#define MOD 1000000007
#define mod MOD
#define sec setprecision
constexpr double eps = 1e-9;
constexpr double PI = 3.141592653589793238462643383279;
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);
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (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;
}
}
vector<ll> soinnsuubunnkai(ll n) {
vector<ll>a;
while (n % 2 == 0) {
a.push_back(2);
n /= 2;
}
ll f = 3;
while (f * f <= n) {
if (n % f == 0) {
a.push_back(f);
n /= f;
}
else f += 2;
}
if (n != 1)
a.push_back(n);
return(a);
}
long long com(ll n, ll k) {
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll pow(ll a, ll b) {
a = a % mod;
if (b == 0)return(1);
else if (b % 2 == 0)return(pow((a * a) % mod, b / 2));
else return(a * (pow(a, b - 1)));
}
void solve() {
}
int main() {
int a, b, c;
cin >> a >> b >> c;
if (max(a, b) >= c && min(a, b) <= c)cout << "Yes" << endl;
else cout << "No" << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int lim = 4e4, Nmax = 505;
typedef long long ll;
int i, j;
ll a[Nmax][Nmax];
vector<int> primes;
bool used[lim+2];
void run_primes()
{
int i;
for(i=2; i<=lim; ++i)
if(!used[i])
{
primes.push_back(i);
for(j=i*i; j<=lim; j+=i) used[j] = 1;
}
}
int main()
{
// freopen("input", "r", stdin);
run_primes();
int n, N;
cin >> N;
n = N + ((N&1)^1);
for(i=0; i<n; ++i)
for(j=0; j<n; ++j)
if(!((i+j)&1)) a[i][j] = (ll) primes[(i+j)/2] * primes[(i-j)/2 + n + 1];
for(i=0; i<n; ++i)
for(j=0; j<n; ++j)
if((i+j)&1)
{
if(j && j<n-1) a[i][j] = a[i][j-1] * a[i][j+1] + 1;
else a[i][j] = a[i-1][j] * a[i+1][j] + 1;
}
for(i=0; i<N; ++i)
for(j=0; j<N; ++j)
cout << a[i][j] << " \n"[j==N-1];
return 0;
}
| #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
int p = 998244353;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define sq(a) (a)*(a)
#define rev(s) reverse(s.begin(),s.end())
#define end_program(s) cout << s <<endl;return 0
int kai_size = 500001;
vel kai(kai_size, 1);
vel ink(kai_size, 1);
vel dist;
int RE() {
vel v(3, 2);
return v.at(4);
}
int ru(int a, int r) {
if (r == 0) { return 1; }
int ans = ru(a, r / 2);
ans *= ans; ans %= p;
if (r % 2 == 1) { ans *= a; }
return ans % p;
}
int inv(int a) {
return ru(a, p - 2);
}
void make_kai() {
rep(i, kai_size-1) { kai[i + 1] = (kai[i] * (i + 1)) % p; }
rep(i, kai_size) { ink[i] = inv(kai[i]); }
}
int com(int n, int r) {
if (r < 0 || n < r) { return 0; }
int ans = kai[n] * ink[r];
ans %= p; ans *= ink[n - r]; ans %= p;
return ans;
}
vel dis(int mid1, vvel &way) {
int n = way.size();
vel dist(n, -1); dist[mid1] = 0;
queue<int> q;
q.push(mid1);
while (!q.empty()) {
int st = q.front(); q.pop();
rep(i, way[st].size()) {
int to = way[st][i];
if (dist[to] == -1) {
dist[to] = dist[st] + 1;
q.push(to);
}
}
}
return dist;
}
pin most_far(int now, int n, vvel &way) {
vel dist1 = dis(now, way);
pin ans = mkp(-1, 0);
rep(i, n) {
if (dist1[i] > ans.first) { ans = mkp(dist1[i], i); }
}
return ans;
}
int per(int a, int b) {
int ans = a % b;
if (ans < 0) { ans += b; }
return ans;
}
vel uni(vel &v) {
sor(v);
vel ans(1, v[0]);
for (int i = 1; i < v.size(); i++) {
if (v[i] != v[i-1]) { ans.push_back(v[i]); }
}
v = ans;
return v;
}
int s_gcd(int a, int b) {
if (b == 0) { return a; }
return s_gcd(b, a%b);
}
int gcd(int a, int b) {
if (a < b) { swap(a, b); }
return s_gcd(a, b);
}
bool is_prime(int i) {
for (int j = 2; j*j <= i; j++) {
if (i%j == 0) { return false; }
}
return true;
}
int get(int i, int j, vvel &ans) {
int n = ans.size();
if (i < 0 || n <= i || j < 0 || n <= j) { return 1; }
return ans[i][j];
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
int solve(int a, int b) {
if (a < b) { swap(a, b); }
if (b == 1) { return 1; }
return a % b;
}
signed main() {
int n; cin >> n;
vel prime(0);
int mod = 510;
for (int i = 1000; i < 10000; i++) {
if (is_prime(i)) { prime.push_back(i); }
}
vvel ans(n, vel(n,1));
rep(i, n) {
rep(j, n) {
if ((i + j) % 2 == 0) {
int x = (i + j) / 2;
int y = per((i - j) / 2, mod);
ans[i][j] = prime[x] * prime[y];
}
}
}
rep(i, n) {
rep(j, n) {
if ((i + j) % 2 == 1) {
j--;
int x = (i + j) / 2;
int y = per((i - j) / 2, mod);
ans[i][j+1] = prime[x] * prime[y];
j += 2;
x = (i + j) / 2;
y = per((i - j) / 2, mod);
ans[i][j-1] *= prime[x] * prime[y];
j--;
ans[i][j]++;
}
cout << ans[i][j];
if (j == n - 1) { cout << endl; }
else { cout << " "; }
}
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if (a!=b) {
cout << max(a,b)*2-1 << endl;
}
else
cout << a*2 << endl;
} | #include <bits/stdc++.h>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int main(){
int a,b;
cin>>a>>b;
vector<int> s(3);
s[0]=a+a-1;
s[1]=b+b-1;
s[2]=a+b;
int ans=0;
rep(i,3){
ans=max(ans,s[i]);
}
cout<<ans<<endl;
} | 1 |
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////
int N, X;
ll B[MAX_N], L[MAX_N], R[MAX_N];
int idx[MAX_N];
int fid[MAX_N];
ll RS[MAX_N], LS[MAX_N];
bool ok(ll m) {
int q = m / X;
int r = m % X;
rep(i, 0, N) {
ll tmp = 0;
if(r == 0) {
tmp += RS[q];
tmp += LS[N] - LS[q];
}
else {
if(B[i] > r) tmp += L[i] * (r - B[i]);
else tmp += R[i] * (r - B[i]);
if(fid[i] < q) {
tmp -= R[i] * (X - B[i]);
tmp += RS[q + 1];
tmp += LS[N] - LS[q + 1];
}
else {
tmp -= -L[i] * B[i];
tmp += RS[q];
tmp += LS[N] - LS[q];
}
}
if(tmp >= 0) {
return true;
}
}
return false;
}
void solve() {
cin >> N >> X;
rep(i, 0, N) {
cin >> B[i] >> L[i] >> R[i];
idx[i] = i;
}
sort(idx, idx + N, [](int i, int j){
return R[i] * (X - B[i]) + L[i] * B[i] > R[j] * (X - B[j]) + L[j] * B[j];
});
// rep(i, 0, N) {
// debug(R[i] * (X - B[i]) - L[i] * B[i], B[i], L[i], R[i]);
// }
// debug(vi(idx, idx + N));
rep(i, 0, N) {
int at = idx[i];
fid[at] = i;
RS[i + 1] = RS[i] + R[at] * (X - B[at]);
LS[i + 1] = LS[i] - L[at] * B[at];
}
ll lv = -1, rv = 1ll * N * X;
while(rv - lv > 1) {
ll m = (lv + rv) / 2;
if(ok(m)) rv = m;
else lv = m;
}
cout << rv << "\n";
}
uint32_t rd() {
uint32_t res;
#ifdef __MINGW32__
asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
res = std::random_device()();
#endif
return res;
}
int main() {
#ifndef LOCAL
ios::sync_with_stdio(false);
cin.tie(0);
#endif
cout << fixed;
cout.precision(20);
cerr << fixed;
cerr.precision(6);
rng.seed(rd());
#ifdef LOCAL
//freopen("in.txt", "wt", stdout); //for tester
freopen("in.txt", "rt", stdin);
#endif
solve();
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
template <typename CT, typename T> inline void reset_container(CT &c, int sz, T v){c.resize(sz); for(auto &x: c) x=v;}
#define taskname "C"
int n;
ll x;
ll start;
class subject{
public:
ll b, l, u, w;
void input(){
read(b);
read(l);
read(u);
start+=b*l;
w=(x-b)*u+b*l;
}
ll cost(ll x){
if(x<=b*l){
return (x-1)/l+1;
}
else{
x-=b*l;
return b+(x-1)/u+1;
}
}
} s[100001];
ll f[100001];
int get(int i){
int res=n;
int low=0, high=n-1, mid;
while(low<=high){
mid=(low+high)/2;
ll sum=f[mid];
if(mid<i) sum+=s[i].w;
if(sum>=start){
res=mid;
high=mid-1;
}
else low=mid+1;
}
return res;
}
int main(){
#ifdef Aria
if(fopen(taskname".in", "r"))
freopen(taskname".in", "r", stdin);
#endif // Aria
read(n);
read(x);
FOR(i, 1, n) s[i].input();
sort(s+1, s+n+1, [](subject A, subject B){
return A.w>B.w;
});
ll ans=x*n;
FOR(i, 1, n) f[i]=f[i-1]+s[i].w;
FOR(i, 1, n){
int j=get(i);
ll res=x*j;
if(j>i) res-=x;
ll now=start-f[j];
if(j>i) now+=s[i].w;
if(now>0) ans=min(ans, res+s[i].cost(now));
else ans=min(ans, res);
}
writeln(ans);
} | 1 |
#include <cstdio>
#include <cstring>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;
const int maxN=200+5;
int T;
int N;
ll A[maxN];
ll base[64];
char S[maxN];
void ins(ll x) {
for(int i=62;~i;--i) if(x>>i&1) {
if(base[i]) x^=base[i];
else {
for(int j=i+1;j<63;++j) if(base[j]>>i&1) {
base[j]^=x;
}
for(int j=i-1;~j;--j) if(x>>j&1) {
x^=base[j];
}
base[i]=x;
break;
}
}
}
bool sol() {
memset(base,0,sizeof(base));
for(int i=N;i>=1;--i) {
if(S[i]=='0') {
ins(A[i]);
}
else {
for(int j=62;~j;--j) if(A[i]>>j&1) {
if(!base[j]) return 1;
A[i]^=base[j];
}
}
}
return 0;
}
int main() {
scanf("%d",&T);
for(int kase=1;kase<=T;++kase) {
scanf("%d",&N);
for(int i=1;i<=N;++i) scanf("%lld",&A[i]);
scanf("%s",S+1);
printf("%d\n",sol());
}
return 0;
} | #include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i,n) for(int i = 0; i < n ; ++i)
#define REP(i,a,b) for(int i = a ; i <= b ; ++i)
#define filei freopen("input.txt", "r", stdin);
#define fileo freopen("output.txt", "w", stdout);
#define gooi cout<<"Case #"<<i+1<<" :";
#define s(n) scanf("%d",&n)
#define rev(i,n) for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) for(int i = a ; i >= b ; --i)
#define miN(a,b) (((a)<(b))?(a):(b))
#define sc(n) scanf("%c",&n)
#define tr(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define INF 1000000000
#define pii pair<long long int,long long int>
#define pb(a) push_back(a)
#define F first
#define S second
typedef long long ll;
using namespace std;
void pre(){}
void solve(){
ll n;cin>>n;
ll arr[n];
for(int i=0;i<n;i++){
cin>>arr[n-i-1];
}
string s;cin>>s;
set<ll,greater<ll>>basis;
reverse(s.begin(),s.end());
for(int i=0;i<n;i++){
for(auto j:basis){
arr[i]=min(arr[i],arr[i]^j);
}
if(arr[i]==0){
continue;
}
if( s[i]=='0' )
basis.insert(arr[i]);
if( s[i]=='1' ){
cout<<1<<"\n";
return;
}
}
cout<<0<<"\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
pre();
long long int num = 1;
cin>>num;
for(long long int i=0;i<num;i++){
solve();
}
}
| 1 |
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
while(1){
int sina[1000],n,m,sum=0;
scanf("%d%d",&n,&m);
if(n==0&&m==0)return 0;
for(int i=0;i<n;i++){
scanf("%d",&sina[i]);
sum+=sina[i];
}
sort(sina,sina+n);
for(int i=n-m;i>=0;i-=m){
sum-=sina[i];
}
printf("%d\n",sum);
}
} | #include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>
#include <vector>
#include <list>
using namespace std;
using namespace boost;
int main(int argc, char* argv[])
{
using sprtr = char_separator<char>;
using tknzr = tokenizer<sprtr>;
sprtr sep(" ", "", keep_empty_tokens);
int f, mf, mo;
string line;
while(1) {
int n, m;
{
getline(cin, line);
tknzr tkns(line, sep);
auto it = tkns.begin();
n = lexical_cast<int>(*it++);
m = lexical_cast<int>(*it);
}
if( n == 0 && m == 0 ) {
break;
}
list<int> ps;
{
getline(cin, line);
tknzr tkns(line, sep);
for( auto p : tkns ) {
//cout << p << endl;
ps.push_back(lexical_cast<int>(p));
}
}
ps.sort(greater<int>());
int div = n / m;
int mod = n % m;
int sum = 0;
auto it = ps.begin();
for( int i = 0; i < div; i++ ) {
for( int j = 0; j < m; j++ ) {
auto p = *it++;
if( j == m-1 ) continue;
sum += p;
}
}
if( mod ) {
for( int i = 0; i < mod; i++ ) {
auto p = *it++;
sum += p;
}
}
cout << sum << endl;
ps.clear();
}
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};
vector<long long> enum_divisors(long long N) {
vector<long long> res;
for (long long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
// 重複しないならば i の相方である N/i も push
if (N/i != i) res.push_back(N/i);
}
}
// 小さい順に並び替える
sort(res.begin(), res.end());
reverse(all(res));
return res;
}
int main() {
ll N,M;
cin >>N>>M;
const auto &res = enum_divisors(M);
for (int i = 0; i < res.size(); ++i){
if(res[i]<= (M/N)){
cout<<res[i]<<endl;
return 0;
}
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int main()
{
int n, k;
cin >> n >> k;
unordered_set<int> s;
for(int i = 0; i < k; i++) {
int d;
cin >> d;
s.insert(d);
}
while(true) {
int temp = n;
bool ok = true;
while(temp) {
int digit = temp % 10;
if(s.count(digit)) {
ok = false;
break;
}
temp /= 10;
}
if(ok) break;
n++;
}
cout << n;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn = 6005;
const int Maxm = 2005;
int n, mod;
int dp[Maxn][Maxm];
int main()
{
scanf("%d %d", &n, &mod);
dp[0][0] = 1;
for (int i = 1; i <= 3 * n; i++)
for (int j = 0; j <= n; j++) {
dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
if (i >= 2 && j >= 1)
dp[i][j] = (dp[i][j] + ll(dp[i - 2][j - 1]) * (i - 1)) % mod;
if (i >= 3 && j >= 1)
dp[i][j] = (dp[i][j] + ll(dp[i - 3][j - 1]) * (i - 1) % mod * (i - 2)) % mod;
}
int res = 0;
for (int j = 0; j <= n; j++)
res = (res + dp[3 * n][j]) % mod;
printf("%d\n", res);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef long double LD;
const int MOD = 1e9 + 7;
const int MAXS = 1 << 16;
int main() {
int N, X, Y, Z;
cin >> N >> X >> Y >> Z;
int xyz = (1 << (X + Y + Z - 1)) | (1 << (Y + Z - 1)) | (1 << (Z - 1));
int mask = (1 << (X + Y + Z)) - 1;
int mask2 = mask >> 1;
int dp[2][MAXS];
int idx = 0, _idx;
dp[idx][0] = 1;
for (int k = 0; k < N; ++k) {
_idx = idx;
idx ^= 1;
memset(dp[idx], 0, sizeof(dp[idx]));
for (int i = 0; i <= mask2; ++i) {
if (dp[_idx][i] > 0) {
for (int j = 1; j <= 10; j++) {
int _i = ((i << j) | (1 << (j-1)));
if ((_i&xyz) != xyz) (dp[idx][_i&mask2] += dp[_idx][i]) %= MOD;
}
}
}
}
long res = 1;
for (int i = 0; i < N; ++i) (res *= 10) %= MOD;
for (int i = 0; i <= mask2; ++i) (res -= dp[idx][i]) %= MOD;
cout << (res + MOD) % MOD << endl;
return 0;
}
| 0 |
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>
#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;
int IN(){
int c,f,x;
while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}
const int N=5e6+19;
int D,c,L,a,b,top;
int coe[2][50];
ll val[20],ans;
pair<ll,ll> A[N],B[N];
ll Pow(ll a,int b){
ll res=1;
for (;b;b>>=1,a=a*a) if (b&1) res=res*a;
return res;
}
void dfs_1(int x,ll v,ll coef){
if (x==top/2){
A[++a]=mp(v,coef);
return;
}
For(i,-9,10){
dfs_1(x+1,v+i*val[x],coef*coe[x==0][i+10]);
}
}
void dfs_2(int x,ll v,ll coef){
if (x==top){
B[++b]=mp(v,coef);
return;
}
For(i,-9,10){
dfs_2(x+1,v+i*val[x],coef*coe[x==0][i+10]);
}
}
void Main(){
a=0,b=0;
top=L/2;
For(i,0,L) val[i]=Pow(10,L-1-i)-Pow(10,i);
if (L%2==0){
dfs_1(0,0,1);
dfs_2(top/2,0,1);
} else{
dfs_1(0,0,L==1?1:10);
dfs_2(top/2,0,L==1?1:1);
}
sort(A+1,A+a+1);
sort(B+1,B+b+1);
c=b;
for (int la=1,ra;la<=a;la=ra+1){
ll tmp=A[la].se;
for (ra=la;ra+1<=a&&A[ra+1].fi==A[ra].fi;ra++) tmp+=A[ra+1].se;
for (;c>=1&&A[la].fi+B[c].fi>D;c--);
for (;c>=1&&A[la].fi+B[c].fi==D;c--) ans+=tmp*B[c].se;
}
}
int main(){
For(a,0,10) For(b,0,10) coe[0][a-b+10]++;
For(a,1,10) For(b,1,10) coe[1][a-b+10]++;
D=IN();
for (L=1;L<=18;L++) Main();
cout<<ans<<endl;
} | #include<bits/stdc++.h>
using namespace std;
#define int long long
int n, pw10[19], nDig, ans;
bool ok(int a, int b, int mod) { return ( ( (a % mod) + mod) % mod) == ( ( (b % mod) + mod) % mod); }
int bt(int pos, int d) {
int ret = 0;
if(pos == nDig / 2 + 1) {
return (d == 0) * (nDig % 2 ? 10 : 1);
}
for (int sub = -9; sub < 10; ++ sub) {
if( ok(d, sub * 9 * pw10[pos - 1], 9 * pw10[pos]) ) {
d -= sub * (pw10[nDig - pos] - pw10[pos - 1]);
int temp = 10 - abs(sub);
if(pos == 1) temp --;
ret += bt(pos + 1, d) * temp;
d += sub * (pw10[nDig - pos] - pw10[pos - 1]);
}
}
return ret;
}
signed main () {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
pw10[0] = 1; for (int i = 1; i < 19; ++i) pw10[i] = 10 * pw10[i - 1];
for (int i = 1; i <= 18; ++i) nDig = i, ans += bt(1, n);
cout << ans;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
// #define DEBUGGING
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
namespace __init {
struct InitIO {
InitIO() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(30);
}
} init_io;
}
#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#endif
template <typename T>
T make_v(T init) { return init; }
template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
return V<decltype(rec)>(s, rec);
#undef rec
}
VV<ll> edges;
pair<ll, bool> dfs(ll now, V<ll> &depth, ll d) {
PLL ret(1, true);
depth[now] = d;
for(ll nxt : edges[now]) {
if(depth[nxt] != -1) {
ll d1 = depth[nxt];
ll d2 = depth[now];
if((d1 % 2) == (d2 % 2)) ret.second = false;
} else {
auto tmp = dfs(nxt, depth, d + 1);
ll t1;
bool t2;
tie(t1, t2) = tmp;
ret.first += t1;
ret.second &= t2;
}
}
return ret;
}
int main() {
ll N, M;
cin >> N >> M;
edges.resize(N);
for(ll i = 0; i < M; i++) {
ll a, b;
cin >> a >> b;
a--;
b--;
edges[a].push_back(b);
edges[b].push_back(a);
}
V<ll> depth(N, -1);
V<pair<ll, bool>> subg;
ll tcnt = 0, lcnt = 0, ocnt = 0;
for(ll i = 0; i < N; i++) {
if(depth[i] != -1) continue;
auto ret = dfs(i, depth, 0);
ll s;
bool tree;
tie(s, tree) = ret;
if(s == 1) {
ocnt++;
} else {
subg.emplace_back(s, tree);
(tree ? tcnt : lcnt)++;
}
}
ll ans = 0;
for(const auto &ele : subg) {
ll n;
bool t;
tie(n, t) = ele;
ans += tcnt + lcnt;
ans += (ll)(t) * tcnt;
ans += n * ocnt;
}
DEBUG(ans);
ans += N * ocnt;
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> eg;
typedef vector<eg> el;
typedef vector<ii> vii;
typedef vector<vii> al;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
vvi g;
int cs[512][512][4];
const int MN = 17;
const int SH = 8;
int am[MN][MN];
int n;
const int MSK = 1<<15;
const int HL = (1<<SH)-1;
void pre() {
memset(cs,0,sizeof(cs));
for(int fm=0;fm<=HL;fm++) {
for(int sm=0;sm<=HL;sm++) {
for(int id=0;id<4;id++) {
ll a = fm,b = sm;
if(id&2) {
a <<= SH;
}
if(id&1) {
b <<= SH;
}
for(int i=0;i<n;i++) {
if(!((1<<i)&a)) continue;
for(int j=0;j<n;j++) {
if(!((1<<j)&b)) continue;
cs[fm][sm][id] += am[i][j];
}
}
}
}
}
}
ll calc(int a, int b) {
ll res = 0;
for(int i=0;i<4;i++) {
int fm=a,sm = b;
if(i&2) {
fm >>= SH;
} else {fm &= HL;}
if(i&1) {
sm >>= SH;
} else {sm &= HL;}
res += cs[fm][sm][i];
}
return res;
}
ll dp[1<<MN][MN];
int main() {
int m;
scanf("%d %d",&n,&m);
memset(am,0,sizeof(am));
for(int i=0;i<1<<MN;i++) {
for(int j=0;j<MN;j++) {
dp[i][j] = 1e12;
}
}
g.assign(n,vi());
for(int i=0;i<m;i++) {
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
a--;b--;
am[a][b] = am[b][a] = c;
g[a].push_back(b);
g[b].push_back(a);
}
pre();
dp[1][0] = 0;
for(int i=0;i<(1<<n);i++) {
for(int j=0;j<n;j++) {
for(int k=0;k<g[j].size();k++) {
int u = g[j][k];
dp[i|(1<<u)][u] = min(dp[i|(1<<u)][u],dp[i][j]+calc(i&(~(1<<j)),1<<u));
}
int mm = 1<<n;
int msk = ((1<<n)-1)&(~i);
while(1) {
mm--;
mm &= msk;
if(mm <= 0) break;
dp[mm|i][j] = min(dp[mm|i][j],dp[i][j]+calc(i&(~(1<<j)),mm));
}
}
}
printf("%lld\n",dp[(1<<n)-1][n-1]);
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)
#define Reps(i, x, N) for(int i = x; i < N; i++)
const int LLINF = 1LL << 60;
signed main()
{
int N, P;
while(cin >> N >> P, N || P) {
int w = P;
int have[55] = {0};
int i = 0;
while(true) {
if(w) have[i]++, w--;
else w += have[i], have[i] = 0;
if(have[i] == P) { cout << i << endl; break; }
i++; if(i == N) i = 0;
}
}
return 0;
} | #include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
#define INF 1000000000
int stone[50];
int main(){
while(true){
int n,p;
cin >> n >> p;
if(n==0 && p==0) break;
rep(i,n) stone[i]=0;
int bowl=p;
int idx=0;
while(true){
if(stone[idx]+1==p) break;
//??????????????????
while(bowl>0){
stone[idx]++;
bowl--;
idx = (idx+1)%n;
}
//?¬???????????????£????????????
while(stone[idx]==0) idx=(idx+1)%n;
//????????\??????
bowl=stone[idx];
stone[idx]=0;
idx= (idx+1)%n;
}
cout << idx << endl;
}
} | 1 |
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>
#include <omp.h>
using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) \
{ \
cout << "YES" << endl; \
} \
else \
{ \
cout << "NO" << endl; \
}
#define IFYes(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) \
{ \
cout << "Yes" << endl; \
} \
else \
{ \
cout << "No" << endl; \
}
#define IFyes(TRUE_OR_FALSE) \
if (TRUE_OR_FALSE) \
{ \
cout << "yes" << endl; \
} \
else \
{ \
cout << "no" << endl; \
}
#define DEBUG_OUTPUT_ARRAY(XXX, ONE) \
for (int i = 0; i < (ONE); i++) \
{ \
cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
}
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO) \
for (int i = 0; i < (ONE); i++) \
{ \
cout << "<<< i = " << i << " >>>" << endl; \
for (int j = 0; j < (TWO); j++) \
{ \
cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
} \
}
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
for (int i = 0; i < (ONE); i++) \
{ \
cout << i << " "; \
for (int j = 0; j < (TWO); j++) \
{ \
cout << XXX[i][j] << " "; \
} \
cout << endl; \
}
typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;
const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323;
//const long long int pl=1000000;
long long int N,X,m[200200],res=INF,L,R;
int main(){
cout << fixed << setprecision(18);
cin>>L>>R;
if(R-L>=2019){cout<<0<<endl;}
else{
for(long long int i = L; i <= R; i++){
for(long long int j = i+1; j <= R; j++){
res=min(res,(i*j)%2019);
}
}
cout<<res<<endl;
}
}
| #include<iostream>
#include <string>
using namespace std;
int main(){
while(1){
int n,p;
int flag=0;
int have[50];
//読み込み
cin>>n>>p;
int cup = p;
if(n == 0 && cup==0){
return 0;
}
for(int i=0; i<n; i++){
have[i]=0;
}
for(int i=0;;i=(i+1)%n){
if(cup==0){
cup = have[i];
have[i]=0;
}else if(cup>0){
have[i]++;
cup--;
if(have[i]==p){
cout<<i<<endl;
break;
}
}
}
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long x;
cin >> x;
long long m = x % 11LL;
long long q = x / 11LL;
long long ans = 0LL;
if (1 < m)
ans++;
if (7 <= m)
ans++;
ans += 2 * q;
if (m == 1)
ans++;
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin()) // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << endl
#define RETURN(x) \
cout << x << endl; \
return 0
#define init() \
cin.tie(0); \
ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v) \
cerr << "[debugV] " << #v << ":"; \
rep(i, v.size()) cerr << " " << v[i]; \
cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
return to_string(x).size();
}
ll gcd(ll x, ll y) {
return y ? gcd(y, x % y) : x;
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
vector<P> factorize(ll n) {
vector<P> result;
for (ll i = 2; i * i <= n; ++i) {
if (n % i == 0) {
result.pb({i, 0});
while (n % i == 0) {
n /= i;
result.back().second++;
}
}
}
if (n != 1) {
result.pb({n, 1});
}
return result;
}
vll divisor(ll n) {
vll ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n) ret.push_back(n / i);
}
}
SORT(ret);
return (ret);
}
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;
}
signed main() {
init();
ll N;
cin >> N;
ll ans = N / 11;
ans *= 2;
ll amari = N % 11;
if (amari == 0) {
RETURN(ans);
}
if (amari <= 6) {
ans++;
} else if (amari <= 11) {
ans += 2;
}
ANS;
return 0;
} | 1 |
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
#define INF 1 << 30;
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int n;
cin >> n;
vector<ll> a(n);
vector<vector<ll>> dp(n+1, vector<ll>(2, 0));
dp[0][1] = -INF;
ll sum = 0;
for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
for (int i = 0; i < n; i++) {
dp[i+1][0] = max(dp[i][0]+a[i], dp[i][1]-a[i]);
dp[i+1][1] = max(dp[i][0]-a[i], dp[i][1]+a[i]);
}
cout << dp[n][0] << endl;
} | #include <iostream>
using namespace std;
using ll = long long;
int main() {
ll N, A, ans{}, s{}, m{1 << 30};
cin >> N;
for (int i = 0; i != N; ++i) {
cin >> A;
if (A < 0) A *= -1, ++s;
m = min(m, A);
ans += A;
}
cout << ans - (s % 2 ? 2 * m : 0) << endl;
}
| 1 |
#include <bits/stdc++.h>
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
using namespace std;
typedef long long ll;
int main()
{
ll N;
cin >> N;
vector<ll> a(N), b(N), c(N), d(N);
vector<pair<ll, ll>> red, blue;
vector<bool> isUsed(N, false);
REP(i, N)
{
cin >> a[i] >> b[i];
red.push_back(make_pair(a[i], b[i]));
}
REP(i, N)
{
cin >> c[i] >> d[i];
blue.push_back(make_pair(c[i], d[i]));
}
sort(ALL(blue));
ll ans = 0;
REPV(it, blue)
{
ll bx = it->first, by = it->second;
priority_queue<pair<ll, ll>> q;
REP(i, N)
{
if (!isUsed[i])
{
ll rx = red[i].first, ry = red[i].second;
if (rx < bx && ry < by)
{
q.push(make_pair(ry, i));
}
}
}
if (!q.empty())
{
ans++;
ll maxIndex = q.top().second;
isUsed[maxIndex] = true;
}
}
cout << ans << endl;
}
| #include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
const ll mod = 1e9 + 7;
const ll inf = 1e18;
template < typename T >
void vprint(T &V){
for(auto v : V){
cout << v << " ";
}
cout << endl;
}
struct Point{
ll x;
ll y;
Point(ll x, ll y): x(x), y(y) {}
Point(){}
};
ll field[21][21];
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// input
for(;;){
// jewel num
ll N;
cin >> N;
if(N==0) return 0;
Point p = Point(10, 10);
FOR(i, 0, 21){
FOR(j, 0, 21){
field[i][j] = 0;
}
}
// jewel position
FOR(i, 0, N){
ll x, y;
cin >> x >> y;
field[y][x] = 1;
}
// move
ll count = 0;
ll M; cin >> M;
FOR(i, 0, M){
char c; cin >> c;
ll len; cin >> len;
FOR(j, 0, len){
if(c=='N') p.y++;
if(c=='S') p.y--;
if(c=='E') p.x++;
if(c=='W') p.x--;
if(field[p.y][p.x]==1){
field[p.y][p.x] = 0;
count++;
}
}
}
if(count==N){
p_yes();
}else{
p_no();
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<pair<int,int>> p(m);
for(int i=0;i<m;i++) cin >> p[i].first >> p[i].second;
for(int x=0;x<1000;x++) {
int keta = 1;
int nx = x/10;
vector<int> d(1,x%10);
while (nx) {
keta++;
d.push_back(nx%10);
nx /= 10;
}
if (keta != n) continue;
bool ok = true;
reverse(d.begin(), d.end());
for(int i=0;i<m;i++) {
if (d[p[i].first-1] != p[i].second) ok = false;
}
if (ok) {
cout << x << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using pv = pair<P,vector<int>>;
vector<int> graph[1005];
int main(){
int n,m;
cin >> n >> m;
vector<P> edge(m);
rep(i,m){
cin >> edge[i].first >> edge[i].second;
--edge[i].first;--edge[i].second;
graph[edge[i].first].push_back(edge[i].second);
}
int id = -1;
int mn = INF;
vector<int> ans;
rep(i,m){
vector<bool> seen(n,false);
queue<pv> q;
q.push(pv(P(edge[i].second,0),{}));
while(!q.empty()){
int now = q.front().first.first;
int c = q.front().first.second;
vector<int> way = q.front().second;
q.pop();
if(now==edge[i].first){
if(c < mn){
id = i;
mn = c;
way.push_back(now);
ans = way;
break;
}else{
break;
}
}
if(seen[now]) continue;
seen[now] = true;
way.push_back(now);
for(int j:graph[now]){
if(seen[j]) continue;
q.push(pv(P(j,c+1),way));
}
}
}
if(mn==INF){
cout << -1 << endl;
}else{
cout << (int)ans.size() << endl;
rep(i,ans.size()) cout << ans[i]+1 << endl;
}
return 0;
} | 0 |
#include "bits/stdc++.h"
#include "math.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll roundd(ll x,ll n){
if(x>n){return x%n;}
else if(x<0){return x%n+n;}
else return x;
}
bool isprime(ll n){
if(n==1)return false;
for (ll i = 2; i * i <= n; i++) {
if(n%i==0)return false;
}
return true;
}
int main(){
ll n;cin>>n;
rep(i,2,55556){
if(i%5==1&&isprime(i)){
cout<<i<<" ";n--;
}
if(n==0)break;
}
cout<<endl;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
template<class T> bool contain(const std::string& s, const T& v) {
return s.find(v) != std::string::npos;
}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
const int MOD = 1000000007;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back
vector<bool>a(55555,1);
int main(){
int n;cin>>n;
auto er=[&](){
VI res;
for(int i=2;i*i<=55555;i++){
int j=i+i;
while(j<55555){
a[j]=0;
j+=i;
}
}
rep(i,55555)if(i>=2 && a[i]==1 && i%10==1)res.emplace_back(i);
return res;
};
VI res=er();
rep(i,n)cout<<res[i]<<' ';
cout<<endl;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000; // n の最大値
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
int main() {
ll n,p;
cin>>n>>p;
ll ca=0;
ll a[n+2]={};
ll b[n+2]={};
ll m=0;
ll f=0;
for(ll i=1; i<n+1; i++){
cin>>a[i];}
for(ll i=0; i<p; i++){
for(ll k=1; k<=n; k++){
if(k-a[k]<=0){
b[0]++;}
else{
b[k-a[k]]++;}
if(k+a[k]>=n){
b[n+1]--;}
else{
b[k+a[k]+1]--;}}
ca=b[0];
b[0]=0;
for(ll k=1; k<=n; k++){
ca+=b[k];
b[k]=0;
a[k]=ca;
if(a[k]==n){
m++;}
}
if(m==n) {f++; break;}
m=0;
ca=0;}
for(ll i=1; i<=n; i++){
cout << a[i] << " ";}
cout << endl;}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;
struct BIT {
int n;
vector<long long> d;
BIT(int n=0):n(n),d(n+1) {}
void add(int i, long long x=1) {
for (i++; i <= n; i += i&-i) {
d[i] += x;
}
}
long long sum(int i) {
long long x = 0;
for (i++; i; i -= i&-i) {
x += d[i];
}
return x;
}
long long sum(int l, int r) {
return sum(r-1) - sum(l-1);
}
};
int main(){
int n,q;
cin >> n >> q;
vector<int> c(n);
for(int i = 0; i < n; i++) cin >> c[i], c[i]--;
vector<pair<pair<int,int>,int>> pq;
for(int i = 0; i < q; i++){
int l,r;
cin >> l >> r;
l--;r--;
pq.push_back(make_pair(make_pair(l,r),i));
}
vector<int> memo(n,-1);
vector<pair<int,int>> cp;
for(int i = 0; i < n; i++){
if(memo[c[i]] != -1) cp.push_back(make_pair(memo[c[i]],i));
memo[c[i]] = i;
}
sort(pq.rbegin(),pq.rend());
sort(cp.rbegin(),cp.rend());
BIT tree(n);
vector<int> ans(q,0);
int ncp = 0;
for(int i = 0; i < q; i++){
while(true){
if(ncp < (int)cp.size() && pq[i].first.first <= cp[ncp].first){
tree.add(cp[ncp].second,1);
ncp++;
} else break;
}
ans[pq[i].second] = pq[i].first.second-pq[i].first.first+1-tree.sum(pq[i].first.second);
}
for(int i = 0; i < q; i++) cout << ans[i] << endl;
return 0;
} | 0 |
#include <memory.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define MOD 998244353
#define INIT -1
int main()
{
string n;
cin >> n;
// result[i][0] : i - 1桁めまで払ってる 繰り下がりはない
// result[i][1] : i - 1桁目まで払ってる 繰り下がりあり
int result[1000010][2] = {};
result[0][0] = 0;
result[0][1] = 1;
for (int i = 1; i <= n.length(); i++)
{
result[i][0] = min(result[i - 1][0] + (n[i - 1] - '0'), result[i - 1][1] + (10 - (n[i - 1] - '0')));
result[i][1] = min(result[i - 1][1] + (10 - (n[i - 1] - '0') - 1), result[i - 1][0] + (n[i - 1] - '0' + 1));
}
cout << result[n.length()][0] << endl;
} | #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
using namespace std;
bool is_balanced(int s, int e, vector<int>& v) {
int len = e - s + 1;
for (auto i: v) {
if (i > len / 2 && len >= 2) {
return true;
}
}
return false;
}
void print(vector<int> v) {
cout << "{ ";
for (auto i : v) {
cout << i << ", ";
}
cout << " }" << endl;
}
int main() {
string s;
cin >> s;
vector<int> v(26, 0);
int i = 0, j = 0;
int len = (int) s.size();
int start, end;
while (j < len) {
v[s[j] - 'a']++;
if (is_balanced(i, j, v)) {
start = i + 1;
end = j + 1;
cout << start << " " << end << endl;
return 0;
} else {
if (j > i + 1) {
v[s[i] - 'a']--;
i++;
}
}
j++;
}
cout << -1 << " " << -1 << endl;
return 0;
} | 0 |
#include <string>
#include <math.h>
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
int aa = 0;
int bb = 0;
int cc = 0;
int dd = 0;
int ee = 0;
int ff = 0;
if (a == 1)
ee = 300000;
else if (a == 2)
aa = 200000;
else if (a == 3)
bb = 100000;
if (b == 1)
ff = 300000;
else if (b == 2)
cc = 200000;
else if (b == 3)
dd = 100000;
if (a == 1 && b == 1)
cout << "1000000";
else
cout << aa + bb + cc + dd + ee + ff;
} | #include<iostream>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<set>
#include<string.h>
#include<ctype.h>
using namespace std;
int arr[10];
int sub[10];
int n,k;
int now = 0;
int cont;
int c = 0;
set<int> visit2;
void saiki(int[],int);
int main()
{
for(;;)
{
visit2.clear();
int i;
c = 0;
now = 0;
scanf("%d",&n);
scanf("%d",&k);
if(n == 0 && k == 0){
break;
}
for(i = 0; i < n; i++){
scanf("%d",&arr[i]);
}
for(i = 0; i < n; i++){
sub[0] = arr[i];
// printf("\næªJ[hF%d\n",arr[i]);
saiki(sub,1);
now++;
}
cout <<visit2.size()-c << endl;
}
}
void saiki(int temp[], int kk)
{
//k:TõK
int used[50] = {0};
int i;
int t = 0;
char str[256] = "";
for(i = 0; i < kk; i++){
sprintf(str+strlen(str),"%d",temp[i]);
}
t = atoi(str);
if(kk == k){
visit2.insert(t);
return;
}
else{
int j;
// cout << "*t = " << t << endl;
for(i = 0; i < kk; i++){
for(j = 0; j < n; ++j ){
if( used[j] == 0 && arr[j] == temp[i] ){
// printf("J[h%dÍgpÏÝ\n",arr[j]);
used[j] = 1;
break;
}
}
}
for(i = 0; i < n; i++){
if(used[i] == 0){
temp[kk] = arr[i];
used[i] = 1;
saiki(temp, kk+1);
used[i] = 0;
}
}
}
}
| 0 |
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
int main()
{
flash;
//sieve();
int T=1,t,n,m,k,i;
// cin>>T;
while(T--)
{
cin>>n>>k;
int a[10]={0};
FOR(i,0,k){
cin>>t;
a[t]=1;
}
vector<int> vs;
FOR(i,0,10)
if(a[i]==0)
vs.pb(i);
// for(auto it:vs)cout<<it<<" ";cout<<endl;
int dg=0;
for(i=n;i>0;i/=10)dg++;
ll ans=0;
k = pow(10,dg-1);
int fl=0;
int num=n;
// cout<<dg<<" "<<k<<endl;
while(ans<num)
{
if(k==0){
ans = ans*10 + vs[0];
continue;
}
m = n/k;
n = n%k;
k/=10;
if(a[m]==0&fl==0){
ans = ans*10 + m;
continue;
}
dg=0;
if(fl==0)
{
for(auto it:vs)
if(it>=m)
{
dg=it;
break;
}
if(dg==0)
{
if(vs[0]!=0)
dg=vs[0];
else
{
if(ans==0)
dg=vs[1];
else
dg=vs[0];
}
}
ans = ans*10+dg;
fl=1;
}
else
{
ans = ans*10 + vs[0];
}
}
cout<<ans<<endl;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tii;
#define rep(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
int main(){
ll A,B; cin >> A >> B;
if(A<B) swap(A,B);
ll y = gcd(A,B);
ll yy = y;
ll x = 2;
ll ans = 1;
while(x*x<=y&&yy!=1){
if(yy%x==0){
ans++;
while(yy%x==0) yy /= x;
}
x++;
}
if(yy!=1) ans++;
cout << ans << endl;
} | 0 |
// God put a smile upon your face <3
#include <bits/stdc++.h>
#define slld(longvalue) scanf("%lld", &longvalue)
#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >
#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define bug printf("BUG\n")
#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX
#define mxd 2e8
#define mnd -2e8
#define pi 3.14159265359
using namespace std;
bool check(ll n, ll pos)
{
return n & (1LL << pos);
}
ll Set(ll n, ll pos)
{
return n = n | (1LL << pos);
}
int main()
{
ll i, j, k, l, m, n, o, r, q;
ll testcase;
ll input, flag, tag, ans;
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
double rad;
while(cin >> rad)
{
cout << setprecision(10) << fixed << 2.0 * acos(-1.0) * rad << "\n";
}
}
| #include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; ++i) // マクロ
using namespace std; // stdの省略
using pii = pair<int, int>; // pairの略記
using ll = long long; // long longの略記
int main(void) {
int r;
cin >> r;
cout << 2*r*M_PI << endl;
return 0;
} | 1 |
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <tuple>
#include <string.h>
#include <map>
#include <iomanip>
#include <time.h>
using namespace std;
typedef long long ll;
int n, m, id[100010];
bool vis[100010];
vector<int> G[100010], R[100010], po;
void dfs(int v) {
if (vis[v]) return;
vis[v] = 1;
for (auto& i : G[v]) dfs(i);
po.push_back(v);
}
void rev_dfs(int v, int num) {
if (vis[v]) return;
vis[v] = true;
id[v] = num;
for (auto& i : R[v]) rev_dfs(i, num);
}
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
G[a].push_back(b);
R[b].push_back(a);
}
for (int i = 0; i < n; i++) dfs(i);
for (int i = 0; i < n; i++) vis[i] = 0;
int num = 0;
reverse(po.begin(), po.end());
for (int i = 0; i < n; i++) {
int v = po[i];
if (!vis[v]) {
rev_dfs(v, num);
num++;
}
}
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int x, y;
cin >> x >> y;
cout << (id[x] == id[y]) << endl;
}
}
| #include "bits/stdc++.h"
#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}
using namespace std;
using ll = long long;
constexpr ll atcoder_mod = 1e9+7;
template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}
void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}
class ConnectNodeInfo{
vector<vector<pair<ll,ll>>> graph;
public:
ConnectNodeInfo(int node_num){
graph.resize(node_num);
}
void AddNonDirectionalConnection(ll u,ll v,ll w){
graph[u].emplace_back(v,w);
graph[v].emplace_back(u,w);
}
void AddDirectionalConnection(ll u,ll v,ll w){
graph[u].emplace_back(v,w);
}
vector<pair<ll,ll>>& operator[](ll index){
return graph[index];
}
size_t size(){return graph.size();}
};
class UnionFind{
vector<ll> rank;
vector<ll> diff_weight;
vector<ll> num;
public:
vector<ll> par;
UnionFind(ll N):par(N),num(N),rank(N),diff_weight(N){
for(ll i=0;i<N;i++){
par[i]=i;
num[i]=1;
rank[i]=0;
diff_weight[i]=0;
}
}
ll root(ll x){
if(par[x]==x){
return x;
}
ll r = root(par[x]);
diff_weight[x]+=diff_weight[par[x]];
return par[x]=r;
}
void unite(ll x,ll y){
ll rx = root(x);
ll ry = root(y);
if (rx == ry) return;
if(rank[rx]<rank[ry]) swap(rx,ry);
if(rank[rx]==rank[ry]) ++rank[rx];
par[ry] = rx;
num[rx] += num[ry];
}
void relate(ll x,ll y,ll w){
w+=weight(x),w-=weight(y);
ll rx = root(x);
ll ry = root(y);
if (rx == ry) return;
if(rank[rx]<rank[ry]){
swap(rx,ry);
w = -w;
}
if(rank[rx]==rank[ry]) ++rank[rx];
par[ry] = rx;
diff_weight[ry] = w;
num[rx] += num[ry];
}
bool same(ll x,ll y){
ll rx = root(x);
ll ry = root(y);
return rx == ry;
}
ll getsize(ll x){
return num[root(x)];
}
ll weight(ll x){
root(x);
return diff_weight[x];
}
ll diff(ll x,ll y){
return weight(y)-weight(x);
}
};
void FirstDFS(int child,int& post_count,vector<int>& post,ConnectNodeInfo& connect,vector<int>& memo){
memo[child] = 1;
for(auto& x:connect[child]){
if(!memo[x.first]){
FirstDFS(x.first,post_count,post,connect,memo);
}
}
post[child] = post_count++;
}
void SecondDFS(int start,int child,ConnectNodeInfo& connect,UnionFind& uf,vector<int>& memo){
uf.unite(start,child);
memo[child] = 1;
for(auto& x:connect[child]){
if(!memo[x.first]){
SecondDFS(start,x.first,connect,uf,memo);
}
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout<<fixed<<setprecision(10);
int N=in(),M=in();
ConnectNodeInfo connect(N),inverse_connect(N);
REP(i,M){
int u=in(),v=in();
connect.AddDirectionalConnection(u,v,1);
inverse_connect.AddDirectionalConnection(v,u,1);
}
int post_count=0;
vector<int> post(N,-1);
vector<int> memo(N,0);
REP(i,N){
if(!memo[i]) FirstDFS(i,post_count,post,connect,memo);
}
vector<pair<int,int>> new_order(N);
REP(i,N){
new_order[i].first=i;
new_order[i].second=post[i];
}
sort(ALL(new_order),PAIRCOMP(second,>));
UnionFind uf(N);
fill(ALL(memo),0);
REP(i,N){
if(!memo[new_order[i].first]) SecondDFS(new_order[i].first,new_order[i].first,inverse_connect,uf,memo);
}
int Q=in();
LOOP(Q){
int u=in(),v=in();
out(uf.same(u,v)?1:0);
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
using ll = long long;
const ll MOD = 1000000007;
ll A[520][520];
int main() {
for (int i = 0;i < 520;i++) {
for (int j = 0;j < 520;j++) {
A[i][j] = -1;
}
}
set<ll> S;
priority_queue<ll> T;
bool w;
for (int i = 5;;i++) {
w = 1;
if (i % 2 == 0)continue;
if (i % 3 == 0)continue;
for (int x : S) {
if (i % x == 0) {
w = 0;
break;
}
}
if (w) {
S.insert(i);
if (i > 550)T.push(i);
if (T.size() == 1200)break;
}
}
for (int i = 1;i < 520;i += 2) {
ll a = i, b = 1, c = T.top();T.pop();
while (a < 520 && b < 520) {
A[a][b] = c * (a + b);
a++;b++;
}
}
for (int i = 3;i < 520;i += 2) {
ll a = 1, b = i, c = T.top();T.pop();
while (a < 520 && b < 520) {
A[a][b] = c * (a + b);
a++;b++;
}
}
for (int i = 5;i < 513;i++) {
for (int j = 5;j < 513;j++) {
if (A[i][j] >= 0)continue;
A[i][j] = A[i - 1][j] * A[i + 1][j] + 1LL;
}
}
int N;
cin >> N;
for (int i = 0;i < N;i++) {
for (int j = 0;j < N;j++) {
cout << A[i + 8][j + 8];
if (j == N - 1)cout << "\n";
else cout << " ";
}
}
} | #include <bits/stdc++.h>
using namespace std;
#define lor(a,b,c) for(register int a=b;a<=c;++a)
#define ror(a,b,c) for(register int a=c;a>=b;--a)
typedef long long ll;
const int MAXN=505,MAXD=7919;
const int movx[4]={-1,0,1,0},movy[4]={0,1,0,-1};
int n; ll a[MAXN][MAXN];
bool vis[MAXD]; ll prime[MAXN<<1];
inline ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
inline ll lcm(ll a,ll b){
if(!a||!b) return a|b;
return a/gcd(a,b)*b;
}
inline void judge(){
int x,a[505][505];
scanf("%d",&x); lor(i,1,x) lor(j,1,x) scanf("%d",&a[i][j]);
}
int main(){
scanf("%d",&n);
if(n==2) return printf("4 7\n23 10\n"),0;
lor(i,2,MAXD){
if(!vis[i]) prime[++prime[0]]=i;
for(register int j=1;j<=prime[0]&&i*prime[j]<=MAXD;++j) vis[i*prime[j]]=true;
}
lor(i,1,n) lor(j,1,n) if(!((i+j)&1)){
a[i][j]=prime[(i+j)>>1]*prime[n+(n+1)/2+(i-j)/2];
}
lor(i,1,n) lor(j,1,n) if((i+j)&1){
a[i][j]=lcm(lcm(a[i-1][j],a[i][j-1]),lcm(a[i+1][j],a[i][j+1]))+1;
}
lor(i,1,n){
lor(j,1,n) printf("%lld ",a[i][j]); printf("\n");
}
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int k;
Node *p, *l, *r;
};
Node *NIL, *root;
void insert(int key) {
Node *parent = NIL;
Node *node = root;
Node *target = (Node *)malloc(sizeof(Node));
target->k = key;
target->l = NIL;
target->r = NIL;
while(node != NIL) {
parent = node;
if(target->k < node->k) {
node = node->l;
} else {
node = node->r;
}
}
target->p = parent;
if(parent == NIL) {
root = target;
} else {
if(target->k < parent->k) {
parent->l = target;
} else {
parent->r = target;
}
}
}
Node *findNode(int key) {
Node *node = root;
while(node != NIL) {
if(key < node->k) {
node = node->l;
} else if(key > node->k) {
node = node->r;
} else {
return node;
}
}
return NIL;
}
Node *getSuccessor(Node *target) {
if(target->r != NIL) {
target = target->r;
while(target->l != NIL) {
target = target->l;
}
return target;
}
Node *parent = target->p;
while(parent != NIL && target == parent->r) {
target = parent;
parent = parent->p;
}
return parent;
}
void deleteNode(int key) {
Node *target = findNode(key);
// error handling
if(target == NIL)
return;
Node *deleteNode;
Node *deleteNodeChild;
Node *deleteNodeParent;
// select node to delete.
if(target->l == NIL || target->r == NIL) {
deleteNode = target;
} else {
deleteNode = getSuccessor(target);
}
// select child node of node to delete.
if(deleteNode->l != NIL) {
deleteNodeChild = deleteNode->l;
} else {
deleteNodeChild = deleteNode->r;
}
// if node to delete has the children nodes.
if(deleteNodeChild != NIL) {
deleteNodeChild->p = deleteNode->p;
}
// if node to delete is root of tree.
if(deleteNode->p == NIL) {
root = deleteNodeChild;
// confirm which is node to delete.
} else if(deleteNode == deleteNode->p->l) {
deleteNode->p->l = deleteNodeChild;
} else {
deleteNode->p->r = deleteNodeChild;
}
if(target != deleteNode) {
target->k = deleteNode->k;
}
}
void inorder(Node *node) {
if(node == NIL)
return;
inorder(node->l);
printf(" %d", node->k);
inorder(node->r);
}
void preorder(Node *node) {
printf(" %d", node->k);
if(node->l != NIL) {
preorder(node->l);
}
if(node->r != NIL) {
preorder(node->r);
}
}
bool find(int key) {
Node *node = root;
while(node != NIL) {
if(key < node->k) {
node = node->l;
} else if(key > node->k) {
node = node->r;
} else {
return true;
}
}
return false;
}
int main() {
int n, key;
string com;
NIL = (Node *)malloc(sizeof(Node));
root = (Node *)malloc(sizeof(Node));
root = NIL;
root->p = NIL;
cin >> n;
for(int i = 0; i < n; i++) {
cin >> com;
if(com == "print") {
inorder(root);
printf("\n");
preorder(root);
printf("\n");
} else {
scanf("%d", &key);
if(com == "find") {
if(find(key)) {
printf("yes\n");
} else {
printf("no\n");
}
} else if(com == "insert") {
insert(key);
} else if(com == "delete") {
deleteNode(key);
}
}
}
}
| #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n;
int t[12][12];
int main(void){
while(cin>>n,n){
memset(t,0,sizeof(t));
for(int i=0;i<=n;i++){
for(int j=0;j<n;j++){
if(i != n){
cin>>t[i][j];
t[n][j] += t[i][j];
}
t[i][n] += t[i][j];
}
}
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
printf("%5d",t[i][j]);
}
cout<<endl;
}
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
ll t;
t = 1;
//cin t;
while (t--)
{
ll n, m;
cin >> n >> m;
int i = 1;
int j = n;
if (n % 2 != 0)
{
while (m--)
cout << i++ << " " << j-- << endl;
}
else
{
int count[n + 1] = {0};
int current = 1;
int x = n / 2;
int s = 1;
int s1 = x + 1;
for (int i = x - 1; i >= 1; i--)
{
if (m == 0)
break;
if (i % 2 == 0)
{
cout << s << " " << s + i << endl;
s++;
}
else
{
cout << s1 << " " << s1 + i << endl;
s1++;
}
m--;
}
// cout << i << " " << --j << endl;
}
}
}
| #include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll= long long;
using ld= long double;
using vl= vector<ll>;
using vd= vector<ld>;
using vs= vector<string>;
using vb= vector<bool>;
using vvl= vector<vector<ll>>;
using vvd= vector<vector<ld>>;
using vvs= vector<vector<string>>;
using vvb= vector<vector<bool>>;
using pll= pair<ll, ll>;
constexpr ll mod= 1e9 + 7;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for(ll(i)= 0; (i) < (n); (i)++)
#define REPS(i, n) for(ll(i)= 1; (i) <= (n); (i)++)
#define RREP(i, n) for(ll(i)= (n - 1); (i) >= 0; (i)--)
#define RREPS(i, n) for(ll(i)= (n); (i) > 0; (i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define YES(n) ((n) ? "YES" : "NO")
#define Yes(n) ((n) ? "Yes" : "No")
#define yes(n) ((n) ? "yes" : "no")
template <class T>
inline void chmin(T &a, T b) {
if(a > b) { a= b; }
}
template <class T>
inline void chmax(T &a, T b) {
if(a < b) { a= b; }
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
ll N,Q;
cin >> N >> Q;
fenwick_tree<ll> fw(N);
REP(i,N){
ll x;
cin >> x;
fw.add(i,x);
}
REP(i,Q){
ll b;
cin >> b;
if(b == 0){
ll p,t;
cin >> p >> t;
fw.add(p,t);
}else{
ll l,r;
cin >> l >> r;
cout << fw.sum(l,r) << "\n";
}
}
} | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int k;
cin>>k;
bool arr[k];
// memset(arr,false,sizeof(arr));
int temp;
for(int i=0;i<10;i++)
arr[i] = false;
for(int i=0;i<k;i++){
cin>>temp;
arr[temp] = true;
}
while(true){
bool flag=true;
int l = n;
while(l!=0){
int rem = l%10;
if(arr[rem]==true){
flag = false;
break;
}
l = l/10;
}
if(flag == true){
cout<<n;
break;
}
n++;
}
}
| #include <iostream>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;
#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999
#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;
typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;
int const MOD = 1000000007;
int main() {
int l[11]; l[0] = 0;
int v1, v2;
while(cin >> l[1]) {
int sum = l[1];
rep(i,2,11) {scanf(",%d", &l[i]); sum += l[i]; l[i] += l[i-1];}
scanf(",%d,%d", &v1, &v2);
double r = (double)sum / (v1 + v2);
double dist = r * v1;
rep(i,0,11) {
if(dist <= l[i]) {cout << i << endl; break;}
}
}
return 0;
} | 0 |
#include <iostream>
#include <cmath>
using namespace std;
struct Point
{
double x, y;
Point(double x=0, double y=0) : x(x), y(y) {}
double distance (const Point &o) const
{
return sqrt((x - o.x) * (x - o.x) + (y - o.y) * (y - o.y));
}
Point operator+(const Point &o) const
{
return Point(x+o.x, y+o.y);
}
Point operator-(const Point &o) const
{
return Point(x-o.x, y-o.y);
}
Point operator*(const double m) const
{
return Point(x*m, y*m);
}
Point operator/(const double d) const
{
return Point(x/d, y/d);
}
double cross(const Point &o) const
{
return x * o.y - y * o.x;
}
double dot(const Point &o) const
{
return x * o.x + y * o.y;
}
double atan() const
{
return atan2(y, x);
}
double norm() const
{
return dot(*this);
}
double area(const Point &a,const Point &b) const
{
double t = (a.x - x) * (b.y - y);
double t2 = (a.y - y) * (b.x - x);
double areas = abs(t-t2);
return areas/2;
}
};
int main()
{
Point p1,p2;
cin >> p1.x >> p1.y >> p2.x >> p2.y;
cout << fixed;
cout.precision(6);
cout << p1.distance(p2) << endl;
return 0;
} |
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main(){
double x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == x2){
cout << setprecision(12) << fabs(y1 - y2) << endl;
}
else if (y1 == y2){
cout << setprecision(12) << fabs(x1 - x2) << endl;
}
else {
cout << setprecision(12) << sqrt(pow(fabs(x1 - x2), 2) + pow(fabs(y1 - y2), 2)) << endl;
}
return 0;
}
| 1 |
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
int main()
{
ll N; cin>>N;
string S; cin>>S;
ll hitomi=0;
ll max_hitomi=0;
rep(i,N)
{
if(i==0) {continue;}
if(S.at(i)=='W') {hitomi++;}
}
rep(i,N)
{
if(i==0) {max_hitomi=hitomi; /*cout<<hitomi<<" "<<max_hitomi<<endl;*/ continue;}
if(S.at(i-1)=='E') {hitomi++;}
if(S.at(i)=='W') {hitomi--;}
max_hitomi=max(max_hitomi,hitomi);
//cout<<hitomi<<" "<<max_hitomi<<endl;
}
cout<<N-1-max_hitomi<<endl;
return 0;
} | #include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
int main() {
string S;
int w;
cin >> S >> w;
for (int i = 0; i < S.size(); i+=w) {
cout << S.at(i);
}
cout << endl;
} | 0 |
#include <iostream>
#include <string.h>
using namespace std;
int main() {
int N;
int cnt = 0;
cin >> N;
int a[N];
int a_next[N];
for (int i = 0; i < N; i++) {
int tmp;
cin >> tmp;
a[i] = tmp;
}
do {
int flg = 0;
for (int i = 0; i < N; i++) {
if (a[i] % 2 == 0){
a_next[i] = a[i] / 2;
}
else{
flg = 1;
break;
}
}
if (flg == 0){
cnt = cnt + 1;
for (int j = 0; j < N; j++) {
a[j] = a_next[j] ;
}
}
else{
cout << cnt << endl;
return 0;
}
} while (true);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int dmin = 100;
for (int i = 0; i < N; i++) {
int A, d = 0;
cin >> A;
while (A % 2 == 0) {
A /= 2;
d++;
}
dmin = min(dmin, d);
}
cout << dmin << endl;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
ll a,b,c;
cin>>a>>b>>c;
if(c>min(a,b) && c<max(a,b))
{
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
return 0;
}
| #include<iostream>
using namespace std;
int main(){
int a,b,c;
cin >> a >> b >> c;
cout << ((a-c)*(b-c)<0?"Yes":"No") << endl;
}
| 1 |
#include<iostream>
#include <climits>
#include<vector>
#include<numeric>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> A(N);
REP(i, N) cin >> A[i];
bool flag = true;
int res = 0;
while (flag) {
flag = false;
for (int i = N - 1;i > 0;i--) {
if(A[i-1]>A[i]){
int tmp = A[i];
A[i] = A[i - 1];
A[i - 1] = tmp;
flag = true;
res++;
}
}
}
REP(i, N) {
if (i < N - 1)cout << A[i] << " ";
else cout << A[i] << "\n";
}
cout << res << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n), b(n), c(n);
for (auto &x: a) cin >> x;
for (auto &x: b) cin >> x;
for (auto &x: c) cin >> x;
sort(a.begin(), a.end());
sort(b.begin(), b.end());
sort(c.begin(), c.end());
vector<long long> l(n);
int j = 0;
for (int i = 0; i < n; i++) {
while (j < n && c[j] <= b[i]) j++;
l[i] = n - j;
}
for (int i = n - 1; i > 0; i--) l[i-1] += l[i];
long long ans = 0;
j = 0;
for (int i = 0; i < n; i++) {
while (j < n && b[j] <= a[i]) j++;
if (j == n) break;
ans += l[j];
}
cout << ans << endl;
return 0;
} | 0 |
#include<bits/stdc++.h>
int main(){
using namespace std;
constexpr unsigned long MOD = 1000000007;
vector<unsigned long> tapi(1048576, 1), tapu(1048576), tape(1048576);
unsigned long ans{0}, t{500000004}, a{0}, z{0}, A;cin >> A;
while(cin >> A)if(a ^= A){
(tapu[a] += (tapi[a] += tapu[a] * (z - tape[a])) %= MOD) %= MOD;
ans += tapi[a];
tape[a] = z;
}else ++z, (t *= 2) %= MOD;
cout << (a ? tapi[a] : (ans + t) % MOD) << endl;
return 0;
} | #include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;
ll dp[41][1<<16][2];
int main(int argc, char* argv[])
{
int n,x,y,z;
scanf("%d%d%d%d", &n, &x, &y, &z);
int s=(1<<(x+y+z))+(1<<(y+z))+(1<<z);
int s2=s/2;
dp[0][0][0]=1;
int i,j,p,k;
for(i=0; i<n; i++) {
for(j=0; j<(1<<16); j++) {
for(p=0; p<2; p++) {
if(dp[i][j][p]) {
for(k=1; k<=10; k++) {
ll tmp=((ll)((j<<1)+1)<<(k-1));
int flag=p;
if(flag==0 && (tmp&s2)==s2) {
flag=1;
}
int j2=tmp%(1<<16);
dp[i+1][j2][flag]=(dp[i+1][j2][flag]+dp[i][j][p])%MOD;
}
}
}
}
}
ll ans=0;
for(j=0; j<(1<<16); j++) {
ans=(ans+dp[n][j][1])%MOD;
}
printf("%lld\n", ans);
return 0;
}
| 0 |
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
typedef long long lint;
using namespace std;
int main(){
string S;
cin>>S;
int ans=0,sc=0;
for(auto c:S){
if(c=='S'){
sc++;
ans++;
}else{
if(sc>0){
ans--;
sc--;
}else{
ans++;
}
}
}
cout<<ans<<endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin>>s;
string ans;
for (char c: s)
if (c == 'S') ans += c;
else if (ans.size() && ans.back() =='S') ans.pop_back();
else ans += c;
cout<<ans.size()<<endl;
}
| 1 |
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;
int main() {
int N; cin >> N; cout << 180 * (N-2) << endl;
}
| #include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
using namespace std;
void func()
{
int64_t N, ai = 0;;
cin >> N;
for (int64_t i = 1; i <= N; ++i)
{
if (i % 3 == 0 || i % 5 == 0)
continue;
ai += i;
}
cout << ai << endl;
}
int main() {
// while (1)
func();
return 0;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,n) for(int (i) = (a);i < (n);i++)
int main()
{
int n = 0, i = 0, output = 0;
cin >> n;
vector<int> skewer(2 * n, 0);
for(i = 0;i < 2*n; i++)
{
int temp = 0;
cin >> temp;
skewer.push_back(temp);
}
sort(skewer.begin(), skewer.end());
i = 0;
while(i < skewer.size())
{
output = output + skewer[i];
i = i + 2;
}
cout << output;
return 0;
}
| #include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using graph = vector<vector<int>>;
using P = pair<int,int>;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
int n;
cin >> n;
n *= 2;
int num[n];
rep(i,n){
cin >> num[i];
}
sort(num,num+n);
reverse(num,num+n);
ll ans = 0;
rep(i,n){
if(i % 2 == 1) ans += num[i];
}
cout << ans << endl;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)
// vector
#define ALL(x) x.begin(), x.end()
// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
cout << a;
ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
cout << a << ' ';
pr(b);
}
int ans = 0;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
int main()
{
vector<int> v(5);
rep(i, 5) cin >> v[i];
int k;
cin >> k;
sort(v.begin(), v.end());
if (v[4] - v[0] <= k)
pr("Yay!");
else
pr(":(");
return 0;
}
| #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main() {
vector<vector<string>> data(3);
string stra,strb,strc;
string next = "a";
cin >> stra;
cin >> strb;
cin >> strc;
int a = 0, b = 0, c = 0;
while (true) {
if (next == "a") {
if (a < stra.size()) {
next = stra[a];
a++;
}
else {
cout << "A" << endl;
break;
}
}
else if (next == "b") {
if (b < strb.size()) {
next = strb[b];
b++;
}
else {
cout << "B" << endl;
break;
}
}
else {
if (c< strc.size()) {
next = strc[c];
c++;
}
else {
cout << "C" << endl;
break;
}
}
}
return 0;
} | 0 |
#include <vector>
#include <functional>
#include <iostream>
using namespace std;
int main() {
int n, m; cin >> n >> m;
vector<vector<int> > adj(n);
while (m--) {
int u, v; cin >> u >> v;
u--; v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
long long a = 0, b = 0, c = 0;
int col[n];
bool visited[n];
fill(visited, visited+n, false);
function <bool(int, int)> dfs = [&](int i, int c) {
col[i] = c;
visited[i] = true;
bool ret = true;
for (int j : adj[i]) {
if (!visited[j]) { if (!dfs(j, -c)) ret = false; }
else if (col[j] == c) ret = false;
}
return ret;
};
for (int i = 0; i < n; i++) {
if (adj[i].empty()) a++;
else if (visited[i]) continue;
else if (dfs(i, 1)) b++;
else c++;
}
cout << 2 * a * n - a * a + b * b + (b + c) * (b + c) << endl;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<59;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 5010
ll dp[N];
int main(){
ll n;
cin>>n;
vector<ll> h(n), p(n);
rep(i, n) cin>>h[i]>>p[i];
vector<P> a(n);
rep(i, n) a[i] = P(h[i]+p[i], i);
sort(all(a));
fill(dp+1, dp+n+1, INF);
rep(i, n) for(int j = i; j >= 0; j--){
ll x = h[a[i].snd], y = p[a[i].snd];
if(dp[j]<=x) dp[j+1] = min(dp[j+1], dp[j]+y);
}
ll res = 0;
rep(i, n+1) if(dp[i]<INF) res = i;
cout<<res<<endl;
return 0;
}
| 0 |
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;
#define pb(n) push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define REP(i,s,e) for(int i=(s); i<(e); i++)
#define rep(i,n) REP(i,0,n)
#define REPE(i,s,e) for(int i=s; i>e; i--)
#define repe(i,n) REPE(i,n,-1)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
int main(){
int n;
while(cin >> n && n>0){
int a,b,sa=0,sb=0;
rep(i,n){
cin>>a>>b;
if(a>b) sa+=(a+b);
else if(a==b) sa+=a,sb+=b;
else sb+=(a+b);
}
cout<<sa<<" "<<sb<<endl;
}
} | #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#define f first
#define s second
#define mp make_pair
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef unsigned int uint;
typedef long long ll;
int sb[10][10000];
#define MAX (50000000)
int main(){
int n,k;
while(scanf("%d%d",&n,&k), n+k){
int dist[n][n];
REP(i,n) REP(j,n) dist[i][j] = MAX;
REP(i,n) dist[i][i] = 0;
while(k --> 0){
int s; scanf("%d",&s);
if(s == 0){
int a,b;
scanf("%d%d",&a,&b); a--; b--;
if(dist[a][b] == MAX) puts("-1");
else printf("%d\n",dist[a][b]);
}else{
int a,b,c;
scanf("%d%d%d",&a,&b,&c); a--; b--;
if(dist[a][b] < c) continue;
dist[a][b] = dist[b][a] = c;
REP(i,n){
dist[a][i] = dist[i][a] = min(dist[a][i], dist[a][b] + dist[b][i]);
dist[b][i] = dist[i][b] = min(dist[b][i], dist[b][a] + dist[a][i]);
}
REP(i,n) REP(j,n){
dist[i][j] = min(dist[i][j], dist[i][a] + dist[a][j]);
dist[i][j] = min(dist[i][j], dist[i][b] + dist[b][j]);
}
}
}
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int d, t, s;
string result;
cin >> d >> t >> s;
if(d <= t*s){
result = "Yes";
}else{
result = "No";
}
cout << result << endl;
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
void add_self(int& a, int b) {
a += b;
if(a >= mod) {
a -= mod;
}
}
int main(){
float d,t,s;
cin>>d>>t>>s;
if ((d/s)>t){
cout<<"No";
}
else{
cout<<"Yes";
}
} | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.