code_file1
stringlengths 80
4k
| code_file2
stringlengths 91
4k
| similar_or_different
int64 0
1
|
---|---|---|
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
tree<int, null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T>
void remdup(vector<T>& v) {
sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif
#define MOD 1000000007
void solve(){
int n ; cin >> n ;
int mx = 0 ;
for(int i = 1 ; i*i <= n ;++i ){
mx = max(mx,i*i);
}
cout << mx << endl;
}
signed main() {
unsyncIO();
int tt =1 ;
// cin >> tt;
rep(i,0,tt) solve();
#ifdef np
cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
| #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define REP(i,e,s) for(register int i=e; i<=s; i++)
#define DREP(i,e,s) for(register int i=e; i>=s; i--)
#define ll long long
#define DE(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG(a) DE("DEBUG: %d\n",a)
#define int long long
int read() {
int x=0,f=1,ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int MOD=1e9+7,MAXN=200000+10;
int fac[MAXN],inv[MAXN];
int qpow(int a,int b) {
int ans=1;
while(b) {
if(b&1) ans=(ans*a)%MOD;
a=(a*a)%MOD;
b>>=1;
}
return ans;
}
int c(int m,int n) {
if(n==m||!m||!n) return 1;
return ((fac[m]*inv[n]%MOD)*inv[m-n])%MOD;
}
int calc(int x_1,int y_1,int x_2,int y_2) {
return c(abs(x_2-x_1)+abs(y_2-y_1),abs(x_2-x_1));
}
signed main() {
int h=read(),w=read(),a=read(),b=read();
fac[0]=1;
REP(i,1,h+w) fac[i]=(fac[i-1]*i)%MOD;
REP(i,1,h+w) inv[i]=qpow(fac[i],MOD-2);
int ans=0;
REP(i,1,h-a) {
ans=(ans+calc(1,1,b,i)*(calc(b+1,i,w,h)))%MOD;
}
printf("%lld\n",ans%MOD);
return 0;
} | 0 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
int N, K;
cin >> N >> K;
vector<double> p(N+1, 0);
int x;
double val;
for(int i=1; i<=N; i++){
cin >> x;
val = x*(x+1) * 0.5 / x;
p.at(i) = p.at(i-1) + val;
}
double maxi=0;
for(int i=0; i<N-K+1; i++){
maxi = max(maxi, p.at(K+i) - p.at(i));
}
printf("%.6f\n", maxi);
return 0;
} | //...Bismillahir Rahmanir Rahim...
// Code by Asad Bin Saber
#include <bits/stdc++.h>
using namespace std;
// typedefs...
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
// constants...
const double PI = acos(-1);
const int Mod = 1e9+7; // 998244353;
const int MXS = 2e5+5;
const int MXI = 1e9+5;
const ll MXL = 1e15+5;
const int INF = 1e5+5;
// defines...
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
// chess moves...
// int dx[] = {+0, +0, -1, +1}; ///Up-down, Left-Right
// int dy[] = {+1, -1, +0, +0};
// int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
// int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1};
// int dx[] = {-2, -2, -1, -1, 1, 1, 2, 2}; ///Knight's Move
// int dy[] = {-1, 1, -2, 2, -2, 2, -1, 1};
// structs...
struct hash_pair {
template <class T1, class T2>
size_t operator()(const pair<T1, T2>& p) const
{
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};
// functions...
ll gcd(ll a, ll b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
ll lcm(ll a, ll b)
{
return (a/gcd(a, b)*b);
}
ll comb(ll a, ll b, ll M)
{
ll x = max(a-b, b), ans=1;
for(ll K=a, L=1; K>=x+1; K--, L++){
ans *= K;
ans /= L;
}
return ans % M;
}
void task()
{
//code here...
int n, ans, mn = MXI;
cin >> n;
int ara[n];
for(int K=0; K<n; K++) cin >> ara[K];
ans = n;
for(int K=0; K<n; K++){
mn = min(mn, ara[K]);
if(mn<ara[K]) ans--;
}
cout << ans << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
task();
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n; cin >> n;
if (n == 2) {
int o, e; cin >> o >> e;
if (o == e) cout << 1 << endl;
else cout << 0 << endl;
return 0;
}
const int p = n / 2;
const int z = 100001;
vector<int> o_num(z, 0), e_num(z, 0);
for (int i = 0; i < n; i++) {
int v; cin >> v;
if (i % 2 == 0) o_num[v]++;
else e_num[v]++;
}
int o_firstCnt = 0;
int o_secondCnt = 0;
int o_firstCntValue = 0;
int e_firstCntValue = 0;
int e_firstCnt = 0;
int e_secondCnt = 0;
for (int i = 0; i < z; i++) {
if (o_firstCnt <= o_num[i]) {
o_firstCntValue = i;
o_firstCnt = o_num[i];
}
if (e_firstCnt <= e_num[i]) {
e_firstCntValue = i;
e_firstCnt = e_num[i];
}
}
sort(o_num.rbegin(), o_num.rend());
sort(e_num.rbegin(), e_num.rend());
o_firstCnt = o_num[0];
o_secondCnt = o_num[1];
e_firstCnt = e_num[0];
e_secondCnt = e_num[1];
int ans;
if (o_firstCntValue != e_firstCntValue) {
ans = n - o_firstCnt - e_firstCnt;
}
else { // o_firstCntValue == e_firstCntValue
ans = min(n - o_secondCnt - e_firstCnt, n - o_firstCnt - e_secondCnt);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, v;
cin >> n;
int* ohash = (int*) calloc(100000, sizeof(int));
int* ehash = (int*) calloc(100000, sizeof(int));
for (int i = 0; i < n/2; i++) {
cin >> v;
ohash[v - 1]++;
cin >> v;
ehash[v - 1]++;
}
int omax = 0, emax = 0;
for (int i = 0; i < 100000; i++) {
if (ohash[i] > ohash[omax]) omax = i;
if (ehash[i] > ehash[emax]) emax = i;
}
if (omax != emax) {
cout << n - ohash[omax] - ehash[emax];
}
else {
int omax2 = 0, emax2 = 0;
for (int i = 0; i < 100000; i++) {
if (ohash[i] > ohash[omax2] && i != omax) omax2 = i;
if (ehash[i] > ehash[emax2] && i != emax) emax2 = i;
}
if (ohash[omax] == n/2 && ehash[emax] == n/2) {
cout << n/2;
}
else if (ohash[omax] == n/2) {
cout << n/2 - ehash[emax2];
}
else if (ehash[emax] == n/2) {
cout << n/2 - ohash[omax2];
}
else {
cout << min(n - ohash[omax] - ehash[emax2], n - ohash[omax2] - ehash[emax]);
}
}
free(ohash);
free(ehash);
return 0;
} | 1 |
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
void solve(){
ll n;
cin>>n;
ll rem, num = 26;
string str="";
while(n != 0){
// cout<<1<<endl;
rem = n%26;
if(rem == 0){
str += 'z';
n = n/26;
n--;
}
else{
rem--;
n = n/26;
char ch = 'a';
ch += rem;
str += ch;
}
// n;
}
reverse(str.begin(),str.end());
cout<<str<<endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int q;
q=1;
// cin>>q;
while(q--) solve();
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
int n;
cin >> n;
ll ans = 0;
for (int i = 1; i <= n; ++i) {
if (i % 3 && i % 5) ans += i;
}
cout << ans << endl;
return 0;
} | 0 |
using namespace std;
#include <bits/stdc++.h>
int main(){
int a,b;cin>>a>>b;
if(a<=8&&b<=8)std::cout << "Yay!" << std::endl;
else
std::cout << ":(" << std::endl;
} | // Sakhiya07 - Yagnik Sakhiya
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define MOD 1000000007
const int N = 100005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
void solve()
{
ll l,r;
cin >> l >> r;
ll dif = (r - l + 1);
if(dif>=2020)
{
cout<<"0\n";
}
else
{
ll ans = 1e18;
for(ll i=l;i<=r;i++)
{
for(ll j=i+1;j<=r;j++)
{
ll temp = i*j;
temp %= 2019;
ans = min(ans,temp);
}
}
cout<<ans;
}
}
int main()
{
FAST;
int t = 1;
// cin >> t;
for(int i=1;i<=t;i++)
{
solve();
}
} | 0 |
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
constexpr ll inf = INT64_MAX / 4;
constexpr double pi = asin(1) * 2;
constexpr ll mod = 1000000007;
pair<ll, ll> extgcd(ll a, ll b) {
if (b == 0)return make_pair(a, 0);
auto t = extgcd(b, a % b);
return make_pair(t.second, t.first - t.second * (a / b));
}
ll invmod(ll n) {
return extgcd(n, mod).first;
}
class modint {
public:
ll n;
modint() = default;
explicit modint(ll number) {
n = ((number % mod) + mod) % mod;
}
bool operator==(modint e) {
return n == e.n;
}
modint operator+(modint e) {
return modint(n + e.n);
}
modint operator-(modint e) {
return modint(n - e.n);
}
modint operator-(ll e) {
return modint(n - e);
}
modint operator*(modint e) {
return modint(n * e.n);
}
modint operator/(modint e) {
return modint(n * invmod(e.n));
}
};
template<class T>
T f1(T n, T m) {
return m * m * (n * n * (n + T(1)) - (n * (n + T(1)) * (T(2) * n + T(1))) / T(3));
}
template<class T>
T f2(T n, T m) {
return (f1(n, m) + f1(m, n)) / T(2);
}
template<class T>
T comb(T n, T k) {
return k == T(0) ? T(1) : comb(n - T(1), k - T(1)) * n / k;
}
int main() {
modint n, m, k;
cin >> n.n >> m.n >> k.n;
cout << (f2(n, m) * comb(n * m - 2, k - 2)).n << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
// 組合せを素数で割った値を求める
const int MAX = 510000;
const int MOD = 1e9 + 7;
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() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, m, k;
cin >> n >> m >> k;
COMinit();
ll ans = 0;
for(int i = 1; i <= m - 1; i++){
ll keep = (((i * n * n) % MOD) * (m - i)) % MOD;
keep *= COM(n * m - 2, k - 2);
keep %= MOD;
ans += keep;
ans %= MOD;
}
for(int i = 1; i <= n - 1; i++){
ll keep = (((i * m * m) % MOD) * (n - i)) % MOD;
keep *= COM(n * m - 2, k - 2);
keep %= MOD;
ans += keep;
ans %= MOD;
}
cout << ans << '\n';
} | 1 |
#include <cstdio>
#include <cstdlib>
#include <numeric>
using namespace std;
int main() {
char *line = NULL;
size_t buffer_size = 0;
while (getline(&line, &buffer_size, stdin) > 0) {
int ls[10];
int v1, v2;
sscanf(line, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
ls, ls+1, ls+2, ls+3, ls+4, ls+5, ls+6, ls+7, ls+8, ls+9,
&v1, &v2);
int total_len = accumulate(ls, ls + 10, 0);
double x1 = v1 * static_cast<double>(total_len) / (v1 + v2);
for (int i = 0, acc = 0; i < 10; ++i) {
acc += ls[i];
if (x1 <= acc) {
printf("%d\n", i + 1);
break;
}
}
}
free(line);
return 0;
} | #include<stdio.h>
int main(void){
int l[10],v[2];
int sv,sl,i;
double n;
while(~scanf("%d",l)){
sv=0;sl=l[0];
for(i=1;i<=9;i++){
scanf(",%d",l+i);
sl+=l[i];
}
for(i=0;i<2;i++){
scanf(",%d",v+i);
sv+=v[i];
}
n=sl/(double)sv;
n*=v[0];
for(i=0;n>0;i++)n-=l[i];
printf("%d\n",i);
}
return 0;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define xx first
#define yy second
#define pii pair <int, int >
#define pll pair < ll, ll >
#define xx first
#define yy second
#define vi vector < int >
#define vl vector < ll >
#define vp vector < pii >
#define inf 100000000
#define f(i, c, n) for(int i = c; i < n; i++)
#define fe(i, c, n) for(int i = c; i <= n; i++)
#define fr(i, n, c) for(int i = n - 1; i >= c; i--)
#define be(a) a.begin(), a.end()
#define vsort(a) sort(a.begin(), a.end())
#define mem(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define srti(a, n) sort(a, a + n)
#define srtd(a, n) sort(a, a + n, greater<int>())
#define LB(a, x) (lower_bound(vbe(a), x) - a.begin())
#define UB(a, x) (upper_bound(vbe(a), x) - a.begin())
#define S " "
#define N "\n"
//cout << "Case " << ++cs << ": " <<
#define fast ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FILE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
void solve() {
int a, b, c, d;
cin >> a >> b >> c >> d;
int mn = min(a, b);
mn += min(c, d);
cout << mn << N;
}
int main() {
// FILE;
fast;
// int t; cin >> t; while(t--)
solve();
} | #include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
#define ref goto refrain
class dice{
public:
int o,u,s,e,n,w;//over,under,south,east,north,west
void change(char a);
};
void dice::change(char a){
int tem=o;
if(a=='S'){
o=n; n=u; u=s; s=tem;
}
else if(a=='E'){
o=w; w=u; u=e; e=tem;
}
else if(a=='N'){
o=s; s=u; u=n; n=tem;
}
else if(a=='W'){
o=e; e=u; u=w; w=tem;
}
else{
cout<<"Error!"<<endl;
exit(0);
}
}
int main(){
dice a;
cin>>a.o>>a.s>>a.e>>a.w>>a.n>>a.u;
char com[100];
cin>>com;
int m=strlen(com);
for(int i=0;i<m;i++){
a.change(com[i]);
}
cout<<a.o<<endl;
return 0;
} | 0 |
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
struct UnionFind {
vector<int> data;
UnionFind(int size) : data(size, -1) { }
bool unionSet(int x, int y) {
x = root(x); y = root(y);
if (x != y) {
if (data[y] < data[x]) swap(x, y);
data[x] += data[y]; data[y] = x;
}
return x != y;
}
bool findSet(int x, int y) {
return root(x) == root(y);
}
int root(int x) {
return data[x] < 0 ? x : data[x] = root(data[x]);
}
int size(int x) {
return -data[root(x)];
}
};
struct Edge {
int a, b, cost;
Edge(int a, int b, int cost) : a(a), b(b), cost(cost) {}
bool operator<(const Edge& o)const {
return cost < o.cost;
}
};
int main() {
cin.tie(0); ios::sync_with_stdio(false);
int n, Ans = 0; cin >> n;
vector<Edge> es;
for (int i = 1; i <= n;i++) {
for (int j = 1; j <= n; j++) {
int temp; cin >> temp;
if (j < i)continue;
if (temp != -1) {
Edge e(i, j, temp);
es.push_back(e);
}
}
}
sort(es.begin(), es.end());
/*kruskal*/
UnionFind uf(n+1);
for (int i = 0; i < es.size();i++) {
//cout << es[i].a << " " << es[i].b << " " << es[i].cost << endl;
Edge& e = es[i];
if (!uf.findSet(e.a, e.b)) {
Ans += e.cost;
uf.unionSet(e.a, e.b);
}
}
cout << Ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int main()
{
int n; cin >> n;
arr<int> A(n, vector<int>(n));
vector<int> opp(n);
rep(i, n){
rep(j, n-1) {cin >> A[i][j]; A[i][j]--;}
A[i][n-1] = -1;
opp[i] = A[i][0];
}
vector<int> IND(n, 0);
int ans = 0;
int finished = 0;
while(finished<n){
ans++;
// printf("day %d: ", ans);
// rep(i, n) cout << opp[i] << " ";
// pr("");
vector<bool> seen(n, false);
int game = 0;
rep(i, n){
if(IND[i]==n) continue;
if(seen[i]) continue;
seen[i] = true;
if(IND[opp[i]]==n) continue;
if(i == opp[opp[i]]){
if(seen[opp[i]]) continue;
int t = opp[i];
// printf("%d: %d %d\n", ans+1, i, opp[i]);
IND[i]++;
IND[t]++;
if(IND[i]==n-1) finished++;
else opp[i] = A[i][IND[i]];
if(IND[t]==n-1) finished++;
else opp[t] = A[t][IND[t]];
seen[t] = true;
game++;
}
}
if(game==0) {pr(-1); return 0;}
}
pr(ans);
return 0;} | 0 |
#include <iostream>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int n, m;
int t[13][13];
int main(){
while(cin >> n, n){
rep(i,13)rep(j,13)t[i][j]=0;
rep(i,n)rep(j,n){
cin >> m;
t[i][j] = m;
t[n][j] += m;
t[i][n] += m;
t[n][n] += m;
}
rep(i,n+1){
rep(j,n+1){
printf("%5d",t[i][j]);
}
cout << endl;
}
}
return 0;
} | #include <stdio.h>
int main(void){
int n;
int a,b;
int aSum, bSum;
while (scanf("%d", &n), n!=0){
aSum = bSum=0;
for (int i=0; i<n; i++){
scanf("%d %d", &a, &b);
if (a>b) aSum += (a+b);
else if (a<b) bSum += (a+b);
else aSum += a, bSum += b;
}
printf("%d %d\n", aSum, bSum);
}
return 0;
} | 0 |
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;
void Main(){
ll N, l;
sll(N);
// vector<ll> ls(N, 0);
map<ll, ll> counter;
rep(i, N){
sll(l);
counter[l] ++;
}
ll ans = 0;
for(auto p1:counter){
for(auto p2:counter){
if(p1.first >= p2.first){
continue;
}
for(auto p3:counter){
if(p1.first >= p3.first){
continue;
}else if(p2.first >= p3.first){
continue;
}
if(p3.first >= p1.first + p2.first){
continue;
}
ans += (p1.second * p2.second * p3.second);
}
}
}
cout << ans <<endl;
}
int main(){
Main();
} | #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> L(n);
rep(i,n) cin >> L[i];
int res = 0;
for(int i = 0; i < n; ++i) {
for(int j = i + 1; j < n; ++j) {
for(int k = j + 1; k < n; ++k) {
if(L[i] == L[j] || L[j] == L[k] || L[k] == L[i]) continue;
vector<int> v = {L[i],L[j],L[k]};
sort(v.begin(), v.end());
res += (v[0] + v[1] > v[2]);
}
}
}
cout << res << "\n";
return 0;
} | 1 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main(){
int a,b;
cin >> a >>b;
int mx = max(a,b);
int mn = min(a,b);
int mx2 = max(mx-1,mn);
cout << mx + mx2 << endl;
}
// cout << fixed << setprecision(15) << << endl;
| #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>
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;
const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323;
long long int mi=0;
long long int N,res=0,abssum=0;
long long int A,B,C,K;
string S;
pll clo[200020],revclo[200020];
int main()
{
cout << fixed << setprecision(18);
cin>>S;
if(S.length()==3){
reverse(S.begin(),S.end());
}
cout<<S<<endl;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string a(int aa, int b) {
if(aa <= 8 && b <= 8) {
return "Yay!";
}
return ":(";
}
int main() {
int aa, b;
cin >> aa >> b;
cout << a(aa, b);
}
| /*
R R R R R R R R R R R R R R R R R R
R R R R R RR R R R R R R R R
R R R R R R R R R R R R R R R R R
R R R R R R R R R R R R R R R R R R R
R R R R R RR R R R R R R R R R
R R R R R R R R R R R RR R R R R R R R R R
*/
#include<bits/stdc++.h>
using namespace std;
#define bf ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define pr 10
#define mx 100000 // 10^6
#define md 1000000007
#define result(a) cout<<a<<endl;
#define forr(a,x) for(int i=a;i<=x;i++)
#define input(n,a) int a[n];for(int i=0;i<n;i++)cin>>a[i];
#define print(a) for(auto it:a)cout<<it<<' '; //0-based
#define printt(n,a) for(i=0;i<n;i++)cout<<a[i]<<' '; //1-based
#define sz(a) cout<<a.size()<<endl;
#define prefx(n,a) for(i=1;i<n;i++)a[i]=a[i-1]+a[i]; //0-based
#define sortt(v) sort(v.begin(),v.end());
#define srt(n,a) sort(a,a+n);
#define rev(n,a) reverse(a,a+n);
#define revr(a) reverse(a.begin(),a.end());
#define yes cout<<"Yes\n";
#define no cout<<"No\n";
int main()
{
int a,b;
cin>>a>>b;
if(a<=8&&b<=8)
{
cout<<"Yay!\n";
}
else
{
cout<<":(\n";
}
}
| 1 |
#include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
long long ans = 0, before;
cin >> before;
bool HasNoAns = (before > 0);
for (int i = 1; i < N; i++) {
int now;
cin >> now;
if (now == 0) {
before = now;
continue;
}
if (now == before + 1) ans++;
else {
if (now <= before) ans += now;
else HasNoAns = true;
}
before = now;
}
cout << (HasNoAns ? -1 : ans) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int a[200002], b[200002];
int main(){
int n;
scanf("%d", &n);
bool ok = 1;
for(int i=1;i<=n;i++){
scanf("%d", &a[i]);
if(a[i] > a[i-1] && a[i]-a[i-1] > 1){
ok = 0;
}
if(i == 1 && a[i] != 0){
ok = 0;
}
}
if(!ok) printf("-1\n");
else{
long long ans = 0;
for(int i=n;i>=1;i--){
if(a[i] == 0) continue;
if(a[i]+1 == a[i+1]) continue;
ans += a[i];
}
printf("%lld\n", ans);
}
} | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;
#define INF (1LL << 60)
#define MOD 998244353
#define PI 3.14159265358979323846
#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back
ll modpow(ll a, ll n, ll m)
{
if(n == 0) return 1;
ll t = modpow(a, n >> 1, m);
t = t * t % m;
if(n & 1) t = t * a % m;
return t;
}
int main()
{
ll N;
cin >> N;
vec D(N);
REP(i,0,N) cin >> D[i];
vec A(N, 0);
if(D[0] != 0) PR(0);
else {
ll m = 0;
REP(i,0,N) {
++A[D[i]];
m = MAX(m,D[i]);
}
if(A[0] > 1) PR(0);
else {
ll cnt = 1;
REP(i,1,m+1) {
cnt = (cnt * modpow(A[i-1], A[i], MOD)) % MOD;
}
PR(cnt);
}
}
return 0;
}
/*
*/ | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> D(N), cnt(N);
for (int i = 0, d; cin >> d; i++) {
D.at(i) = d;
cnt.at(d)++;
}
if (D.at(0) || cnt.at(0) != 1) return cout << 0 << "\n", 0;
long ans = 1;
int mx = *max_element(D.begin(), D.end());
for (long i = 1; i <= mx; i++) {
long tmp = cnt.at(i);
while (tmp--) {
ans *= cnt.at(i - 1);
ans %= 998244353;
}
}
cout << ans << "\n";
} | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifdef _DEBUG
//freopen("_in" , "r", stdin );
//freopen("_out", "w", stdout);
#endif
ios::sync_with_stdio(0); cin.tie(0);
string s[3]; cin >> s[0] >> s[1] >> s[2];
int i = 0;
for(;;) {
if (!s[i].size()) break;
int t;
if (s[i][0] == 'a') t = 0;
if (s[i][0] == 'b') t = 1;
if (s[i][0] == 'c') t = 2;
s[i].erase(0, 1);
i = t;
}
if (i == 0) cout << 'A';
if (i == 1) cout << 'B';
if (i == 2) cout << 'C';
cout << '\n';
}
| #include<bits/stdc++.h>
using namespace std;
int main(){
int N;
cin>>N;
int A[N];
for(int i=0;i<N;i++){
cin>>A[i];
}
bool ans=true;
sort(A,A+N);
for(int i=0;i<N-1;i++){
if(A[i]==A[i+1]){
ans =false;
break;
}
}
if(ans){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
} | 0 |
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=998244353;
const int MAX=1e5+10;
const ll INF=1e18;
const double PI=acos(-1);
int main() {
ios_base::sync_with_stdio(false);
int n,x;
cin >> n >> x;
vector<int> a(n);
rep(i,n) cin >> a[i];
sort(a.begin(),a.end());
int ans=n-1;
rep(i,n) {
x-=a[i];
if (x==0) {
ans=i+1;
break;
} else if (x<0) {
ans=i;
break;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; }
ll modc(ll a, char op, ll b, ll _mod=mod)
{
a %= _mod; b %= _mod; ll res = 1;
switch (op) {
case '+': res = (a + b) % _mod; break;
case '-': res = (a - b) % _mod; break;
case '*': res = a * b % _mod; break;
case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
case '^': res = intpow(a, b, _mod); break;
case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break;
}
if (res < 0) { res += _mod; } return res;
}
int main()
{
ll N, x;
cin >> N >> x;
vll a(N);
rep(i, 0, N) cin >> a[i];
ll ans = 0;
sort(all(a));
rep(i, 0, N) {
if (i != N-1) {
if (x >= a[i]) {
x -= a[i];
++ans;
}
} else {
if (a.back() == x) ++ans;
}
}
cout << ans << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384
int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0 : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin>>n;
vector<pll> a,b;
rep(i,n){
string s;
cin>>s;
pll p(0,0);
rep(j,s.size()){
if(s[j]=='(')p.fs++;
else p.fs--;
chmin(p.sc,p.fs);
}
if(p.fs>=0) a.push_back(p);
else b.push_back(p);
}
sort(all(a),[](const auto &a,const auto &b){
if(a.sc!=b.sc)return a.sc>b.sc;
else return a.fs>b.fs;
});
sort(all(b),[](const auto &a,const auto &b){
return a.fs-a.sc>b.fs-b.sc;
});
ll cur=0;
bool ans=true;
for(auto x:a){
if(cur+x.sc<0)ans=false;
cur+=x.fs;
}
for(auto x:b){
if(cur+x.sc<0)ans=false;
cur+=x.fs;
}
Yn(ans&&cur==0);
}
| #include<iostream>
#include<string>
using namespace std;
int main(void){
string str;
int q;
cin >> str;
cin >> q;
for (int i=0;i<q;i++){
string c;
cin >> c;
if (c=="print"){
int a,b;
cin >> a >> b;
for (int i=a;i<=b;i++)
cout << str[i];
cout << endl;
}
if (c=="reverse"){
int a,b;
cin >> a >> b;
char t;
for (int i=0;i<=(b-a)/2;i++){
t=str[a+i];
str[a+i]=str[b-i];
str[b-i]=t;
}
}
if (c=="replace"){
int a,b;
string r;
cin >> a >> b >> r;
str.replace(a,b-a+1,r);
}
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[5009];
ll a[5000];
int main()
{
ll n;ll ans=0;
multiset<ll>s;cin>>n;
for(int i=0;i<n;i++){
ll x;cin>>x;
if(s.size()==0){
s.insert(x);
ans++;
}
else
{
auto z=s.begin();
if(*z>=x){
s.insert(x);ans++
; }else{
auto it=s.lower_bound(x);it--;
s.erase(s.find(*it));
s.insert(x);
}
}
}cout<<ans;
} | #include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
ll n;
vector<ll>a;
int main(){
cin>>n;
a.resize(n+1);
rep(i,n)cin>>a[i+1];
vector<ll>ans(n+1,0);
ll M = 0;
for(int i=n;i>=1;i--){
int j=2;
int cnt = 0;
//倍数の和を求める
while (i*j<=n){
if(ans[i*j]==1)cnt++;
j++;
}
if((a[i]%2)!=(cnt%2)){
ans[i]++;
M++;
}
}
cout << M << endl;
for(int i=1;i<=n;i++){
if(ans[i]==1)cout<<i<<endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n) \
cerr << __LINE__ << ": " << #x << " = {"; \
for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
cerr << ((hoge) ? "," : "") << x[hoge]; \
cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
int A[N];
vector<pair<int, bool>> xy[N];
for (int i = 0; i < N; i++) {
cin >> A[i];
xy[i].resize(A[i]);
for (int j = 0; j < A[i]; j++) {
cin >> xy[i][j].first >> xy[i][j].second;
xy[i][j].first--;
}
}
int ans = 0;
for (int s = 1; s < (1 << N); s++) {
bool isok = true;
for (int i = 0; i < N; i++)
if ((s >> i) & 1) {
for (int j = 0; j < A[i]; j++) {
isok &= !(((s >> xy[i][j].first) & 1) ^ xy[i][j].second);
}
}
if (isok) ans = max(ans, __builtin_popcount(s));
}
cout << ans << '\n';
return 0;
}
| #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
const int INF=1<<29;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n;//計算する行列の数
const int MAX_N =110;
int dp[MAX_N][MAX_N];//dp[i][j]:=Ai...Ajの計算に必要な最小のコスト
pii A[MAX_N];//行列firstを行secondを列とする。
void init(){
for(int i =0; i < n;i++){
for(int j = 0;j < n;j++){
dp[i][j]=INF;
}
}
for(int i =0;i < n;i++){
dp[i][i]=0;
}
}
int solve(){
for(int k =1;k <n;k++){
for(int i =0;i <n-k;i++){
for(int j =i;j <i+k;j++){
int sz =A[i].first*A[j].second*A[i+k].second;
dp[i][i+k]=
min(dp[i][i+k],dp[i][j]+dp[j+1][i+k]+sz);
}
}
}
return dp[0][n-1];
}
int main(){
cin>>n;
init();
for(int i =0;i < n;i++){
cin>>A[i].first>>A[i].second;
}
cout <<solve()<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<int, int>
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 1e5 + 10;
ll x[N], p[N];
ll ans;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n, S; cin >> n >> S;
int pos = -1;
for (int i=0; i<n; i++)
{
cin >> x[i] >> p[i];
if(x[i] < S) pos = i;
}
int st = 0, en = n - 1, dir = -1;
while(true)
{
if(st > pos){ ans += x[en] - S; break ;}
else if(en <= pos){ ans += S - x[st]; break; }
if(p[st] >= p[en])
{
if(dir != 0) ans += x[en] - x[st];
dir = 0;
p[st] += p[en];
en --;
}else
{
if(dir != 1) ans += x[en] - x[st];
dir = 1;
p[en] += p[st];
st ++;
}
}
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
const int maxn=100005;
inline int read(){
register int x=0,w=1,ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')w=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-48;
return w*x;
}
int n,s,x[maxn];
long long p[maxn];
long long calc(int l,int r,int lst){
if(s<x[l])return x[r]-s;
if(x[r]<s)return s-x[l];
if(p[l]>=p[r]){
p[l]+=p[r];
return calc(l,r-1,l)+(lst==r)*(x[r]-x[l]);
}
else{
p[r]+=p[l];
return calc(l+1,r,r)+(lst==l)*(x[r]-x[l]);
}
}
int main(){
n=read(),s=read();
for(int i=1;i<=n;i++)
x[i]=read(),p[i]=read();
cout<<calc(1,n,p[1]<p[n]?1:n)<<'\n';
return 0;
} | 1 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
#include <set>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };
const double PI = 3.14159265358979323846;
int main() {
int x;
cin >> x;
int five_hund = 0;
int five = 0;
five_hund = x / 500;
five = (x % 500) / 5;
cout << five_hund * 1000 + five * 5 << endl;
return 0;
}
| /*
-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;
cin>>n;
m=n/500;
n%=500;
m*=1000;
a=n/5;
m+=(a*5);
cout<<m<<endl;
}
| 1 |
#include <iostream>
#include <algorithm>
using namespace std;
int partition(int A[], int p, int r) {
int x = A[r];
int i = p;
for (int j = p; j < r; j++) {
if (A[j] <= x) {
swap(A[i++], A[j]);
}
}
swap(A[i], A[r]);
return i;
}
int main() {
int n;
cin >> n;
int A[n], suffix;
for (int i = 0; i < n; i++) {
cin >> A[i];
}
suffix = partition(A, 0, n - 1);
for (int i = 0; i < n; i++) {
if (i == suffix) {
cout << "[" << A[i] << "]";
}
else {
cout << A[i];
}
if (i < n - 1) {
cout << " ";
}
}
cout << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef bitset<705> bs;
// dp[i] is number of colorings with sum equal to i
ll dp[300 * 300 + 5];
const int MOD = 998244353;
ll modpow(ll b, ll e, ll m) {
ll r = 1;
while(e) {
if(e%2) {
r*=b;
r%=m;
}
b*=b;
b%=m;
e/=2;
}
return r;
}
ll compensate(vector<int>& v) {
memset(dp, 0, sizeof(dp));
dp[0] = 1;
int tot = 0;
for(int out: v) {
for(int i = 90000; i >= out; i--) {
dp[i] += dp[i-out];
dp[i] %= MOD;
}
tot += out;
}
return 3 * dp[tot/2];
}
void solve() {
int n;
cin >> n;
dp[0] = 1;
ll total = 1;
int sum = 0;
vector<int> v;
for(int i = 0; i < n; i++) {
total *= 3;
total %= MOD;
int t;
cin >> t;
v.push_back(t);
sum += t;
for(int x = 300 * 300; x >= 0; x--) {
dp[x] = 2 * dp[x];
if(x >= t) dp[x] += dp[x-t];
dp[x] %= MOD;
}
}
ll ret = total;
for(int i = (sum+1)/2; i <= sum; i++) {
ret += 3 * (MOD - dp[i]);
ret %= MOD;
}
if(sum%2 == 0) {
ret += compensate(v);
ret %= MOD;
}
cout << ret << "\n";
}
void casesolve() {
int t;
cin >> t;
for(int i = 1; i <= t; i++) {
cout << "Case #" << i << ": ";
solve();
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
solve();
// casesolve();
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s;
int k;
cin >> s >> k;
int n = s.size();
vector<vector<vector<int>>> dp(n, vector<vector<int>>(n, vector<int>(k + 1)));
for (int i = n - 1; i >= 0; i--) {
for (int j = i; j <= n - 1; j++) {
for (int l = 0; l <= k; l++) {
if (i == j) {
dp[i][j][l] = 1;
} else if (i + 1 == j) {
dp[i][j][l] = 2;
if (l == 0 && s[i] != s[j]) {
dp[i][j][l] = 1;
}
} else {
dp[i][j][l] = max(dp[i + 1][j][l], dp[i][j - 1][l]);
// dp[i][j][l] = max(dp[i][j][l], dp[i + 1][j - 1][l] + 1);
if (s[i] == s[j]) {
dp[i][j][l] = max(dp[i][j][l], dp[i + 1][j - 1][l] + 2);
} else if (l != 0) {
dp[i][j][l] = max(dp[i][j][l], dp[i + 1][j - 1][l - 1] + 2);
}
}
}
}
}
cout << dp[0][n - 1][k] << '\n';
return 0;
}
| #include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<limits>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define clr(a,v) memset((a),(v),sizeof(a))
const int MAX_N = 100, INF = std::numeric_limits<int>::max()>>2;
int n;
int r[MAX_N], c[MAX_N];
std::vector<std::vector<int> > dp( MAX_N, std::vector<int>( MAX_N, INF ) );
/*int rec( int b, int e )
{
if( b == e )
return dp[b][e] = 0;
if( ~dp[b][e] )
return dp[b][e];
int ret = INF;
rep( i, e-b )
ret = std::min( ret, rec( b, b+i )+rec( b+i+1, e )+r[b]*c[b+i]*c[e] );
return dp[b][e] = ret;
}*/
int main()
{
scanf( "%d", &n );
rep( i, n )
scanf( "%d%d", r+i, c+i );
rep( i, n )
dp[i][i] = 0;
repi( w, 1, n ) rep( i, n ) if( i+w < n ) repi( j, i, i+w )
dp[i][i+w] = std::min( dp[i][i+w], dp[i][j]+dp[j+1][i+w]+r[i]*c[j]*c[i+w] );
printf( "%d\n", dp[0][n-1] );
return 0;
} | 0 |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
int n,q,a,b;
ll x[222222];
struct node
{
ll lazy;
ll ans;
};
node st[2][800111];
void build(int ty, int id, int l, int r)
{
st[ty][id].lazy=0;
if(r-l<2)
{
st[ty][id].ans=ll(1e14);
if(l==a)
{
st[ty][id].ans=abs(x[0] - b);
}
if(ty==0) st[ty][id].ans-=l;
else st[ty][id].ans+=l;
return ;
}
int mid=(l+r)>>1;
build(ty,id*2,l,mid); build(ty,id*2+1,mid,r);
st[ty][id].ans=min(st[ty][id*2].ans,st[ty][id*2+1].ans);
}
void push(int ty, int id, int l, int r)
{
if(st[ty][id].lazy!=0)
{
st[ty][id].ans+=st[ty][id].lazy;
if(r-l>=2)
{
st[ty][id*2].lazy+=st[ty][id].lazy;
st[ty][id*2+1].lazy+=st[ty][id].lazy;
}
st[ty][id].lazy=0;
}
}
void update(int ty, int id, int l, int r, int pos, ll v)
{
push(ty,id,l,r);
if(pos>=r||pos<l) return ;
if(r-l<2)
{
st[ty][id].ans=min(v,st[ty][id].ans);
return ;
}
int mid=(l+r)>>1;
update(ty,id*2,l,mid,pos,v); update(ty,id*2+1,mid,r,pos,v);
st[ty][id].ans=min(st[ty][id*2].ans,st[ty][id*2+1].ans);
}
void add(int ty, int id, int l, int r, int ql, int qr, ll v)
{
push(ty,id,l,r);
if(ql>=r||l>=qr) return ;
if(ql<=l&&r<=qr)
{
st[ty][id].lazy+=v;
push(ty,id,l,r);
return ;
}
int mid=(l+r)>>1;
add(ty,id*2,l,mid,ql,qr,v); add(ty,id*2+1,mid,r,ql,qr,v);
st[ty][id].ans=min(st[ty][id*2].ans,st[ty][id*2+1].ans);
}
ll query(int ty, int id, int l, int r, int ql, int qr)
{
push(ty,id,l,r);
if(ql>=r||l>=qr) return ll(1e15);
if(ql<=l&&r<=qr) return st[ty][id].ans;
int mid=(l+r)>>1;
return min(query(ty,id*2,l,mid,ql,qr), query(ty,id*2+1,mid,r,ql,qr));
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>q>>a>>b; a--; b--;
for(int i=0;i<q;i++) {cin>>x[i]; x[i]--;}
ll ans=ll(1e18);
for(int z=0;z<2;z++)
{
for(int ty=0;ty<2;ty++) build(ty,1,0,n);
for(int i=1;i<q;i++)
{
ll real = min(query(0,1,0,n,0,x[i]) + x[i], query(1,1,0,n,x[i],n) - x[i]);
for(int j=0;j<2;j++) add(j,1,0,n,0,n,abs(x[i-1]-x[i]));
update(0,1,0,n,x[i-1],real-x[i-1]);
update(1,1,0,n,x[i-1],real+x[i-1]);
}
for(int i=0;i<n;i++)
{
ans=min(ans,query(0,1,0,n,i,i+1)+i);
}
swap(a,b);
}
cout<<ans<<'\n';
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
const ll INF = 1e16;
#define PI (acos(-1))
//const ll mod = 1000000007;
struct LazySegmentTree {
private:
int n;
vector<ll> node, lazy;
public:
LazySegmentTree() {
int sz = 200050;
n = 1; while(n < sz) n *= 2;
node.resize(2*n-1);
lazy.resize(2*n-1, 0);
for(int i=0; i<sz; i++) node[i+n-1] = INF;
for(int i=n-2; i>=0; i--) node[i] = min(node[i*2+1], node[i*2+2]);
}
// k 番目のノードについて遅延評価を行う
void eval(int k, int l, int r) {
// 遅延配列が空でない場合、自ノード及び子ノードへの
// 値の伝播が起こる
if(lazy[k] != 0) {
node[k] += lazy[k];
// 最下段かどうかのチェックをしよう
// 子ノードは親ノードの 1/2 の範囲であるため、
// 伝播させるときは半分にする
if(r - l > 1) {
lazy[2*k+1] += lazy[k];
lazy[2*k+2] += lazy[k];
}
// 伝播が終わったので、自ノードの遅延配列を空にする
lazy[k] = 0;
}
}
void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
if(r < 0) r = n;
// k 番目のノードに対して遅延評価を行う
eval(k, l, r);
// 範囲外なら何もしない
if(b <= l || r <= a) return;
// 完全に被覆しているならば、遅延配列に値を入れた後に評価
if(a <= l && r <= b) {
lazy[k] += x;
eval(k, l, r);
}
// そうでないならば、子ノードの値を再帰的に計算して、
// 計算済みの値をもらってくる
else {
add(a, b, x, 2*k+1, l, (l+r)/2);
add(a, b, x, 2*k+2, (l+r)/2, r);
node[k] = min(node[2*k+1], node[2*k+2]);
}
}
ll getmin(int a, int b, int k=0, int l=0, int r=-1) {
if(r < 0) r = n;
// 関数が呼び出されたらまず評価!
eval(k, l, r);
if(b <= l || r <= a) return 1e17;
if(a <= l && r <= b) return node[k];
ll vl = getmin(a, b, 2*k+1, l, (l+r)/2);
ll vr = getmin(a, b, 2*k+2, (l+r)/2, r);
return min(vl, vr);
}
};
int main() {
//cout.precision(10);
LazySegmentTree seg, forward, backward;
ll N, Q, A, B;
cin >> N >> Q >> A >> B;
for(int i = 1; i <= N; i++) {
forward.add(i, i + 1, i);
backward.add(i, i + 1, (N - i));
}
seg.add(A, A+1, -INF);
forward.add(A, A+1, -INF);
backward.add(A, A+1, -INF);
//cerr << backward.getmin(1, 3) << endl;
ll before = B;
while(Q--) {
ll x;
cin >> x;
ll val = backward.getmin(1, x) - N + x;
//cerr << val << endl;
val = min(val, forward.getmin(x, N + 1) - x);
//cerr << val << endl;
seg.add(1, N + 1, abs(x - before));
forward.add(1, N + 1, abs(x - before));
backward.add(1, N + 1, abs(x - before));
ll beforeval = seg.getmin(before, before + 1);
//cerr << seg.getmin(before, before + 1) << endl;
seg.add(before, before + 1, val - beforeval);
//cerr << seg.getmin(before, before + 1) << endl;
forward.add(before, before + 1, val - beforeval);
//cerr << forward.getmin(before, before + 1) << endl;
backward.add(before, before + 1, val - beforeval);
//cerr << backward.getmin(before, before + 1) << endl;
before = x;
//cerr << endl << Q << endl;
/*
for(int i = 1; i <= N; i++) {
cerr << i << " " << seg.getmin(i, i + 1) << endl;
}
*/
}
cout << seg.getmin(1, N + 1) << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
string s;
int main() {
cin.sync_with_stdio(0); cin.tie(0);
cin >> s;
int lc = 0, rc = 0;
for (auto& i : s) {
if (i == 'S') lc++;
else {
if (lc) lc--;
else rc++;
}
}
cout << lc + rc;
}
| #include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>>
////////////////////////////////////////////////////////
int main() {
string s; cin >> s;
bool f = true;
while(f){
bool f = true;
rep(i, 0, sz(s)-5){
if(s[i]=='S'&&s[i+1]=='S'&&s[i+2]=='S'&&
s[i+3]=='T'&&s[i+4]=='T'&&s[i+5]=='T'){
s.erase(i, 6);
f = false;
i -= 5;
}
}
rep(i, 0, sz(s)-1){
if(s[i] == 'S' && s[i+1] == 'T'){
s.erase(i, 2);
f = false;
i--;
}
}
if(f) break;
}
co(sz(s));
return 0;
}
| 1 |
#include<iostream>
#include<climits>
using namespace std;
int main(){
int n,a[5001];
int ans;
a[0]=0;
while(cin>>n&&n){
ans = INT_MIN;
for(int i=1;i<=n;i++){
cin>>a[i];
a[i] += a[i-1];
}
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j++){
ans = max(ans,a[j]-a[i-1]);
}
}
cout<<ans<<endl;
}
return 0;
} | #include <iostream>
#include <limits>
#include <algorithm>
using namespace std;
int main()
{
for (int n; cin >> n && n;) {
vector<int> sequence(n);
int sum = 0;
int max_val = numeric_limits<int>::min();
for (int x, i = 0; i < n && cin >> x; i++) {
if (sum < 0)
sum = x;
else
sum += x;
max_val = max(max_val, sum);
}
cout << max_val << endl;
}
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int mod=1000000007;
const int INF=1001001001;
int main() {
int N;
cin>>N;
string s,t;
cin>>s>>t;
for(int i=N;i>=0;i--){
string v=s;
reverse(v.begin(),v.end());
string r=v.substr(0,i);
reverse(r.begin(),r.end());
if(r==t.substr(0,i)){cout<<2*N-i<<endl;return 0;}
}
cout<<2*N<<endl;
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef pair<int, int> P;
vector<int> G[100000];
int depth[100000];
bool ok[100000];
P depth_pair[100000];
void dfs_depth(int v, int d){
depth[v] = d;
for(int i = 0; i < G[v].size(); i++){
if(depth[G[v][i]] == -1) dfs_depth(G[v][i], d+1);
}
}
void dfs_ok(int v){
ok[v] = true;
for(int i = 0; i < G[v].size(); i++){
if(depth[G[v][i]] > depth[v] && !ok[G[v][i]]) dfs_ok(G[v][i]);
}
}
int main(){
int N, K;
cin >> N >> K;
int ans = 0;
for(int i = 0; i < N; i++){
depth[i] = -1;
int a;
cin >> a;
a--;
if(i == 0){
if(a != 0) ans++;
}else{
G[a].push_back(i);
G[i].push_back(a);
}
}
//cout << ans << endl;
dfs_depth(0, 0);
for(int i = 0; i < N; i++) depth_pair[i] = P(depth[i], i);
sort(depth_pair, depth_pair+N, greater<P>());
for(int i = 0; i < N; i++){
if(depth_pair[i].first <= K) break;
if(!ok[depth_pair[i].second]){
ans++;
int cur = depth_pair[i].second;
//cout << depth_pair[i].second << endl;
//K-1個上まで
for(int j = 0; j < K-1; j++){
for(int k = 0; k < G[cur].size(); k++){
if(depth[G[cur][k]] < depth[cur]){
cur = G[cur][k];
break;
}
}
}
dfs_ok(cur);
}
}
cout << ans << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int ans = 0;
int minimum = N;
for(int i = 0; i < N; i++) {
int P;
cin >> P;
if(P <= minimum) {
minimum = P;
ans++;
}
}
cout << ans << endl;
} | #include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,e) for(int i=(s);(i)<(int)(e);++(i))
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define ppb(x) pop_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))
typedef long long ll;
const int N = 200000;
int n;
int p[N];
int main() {
fscanf(stdin, "%d ", &n);
int res = 0, m = N;
REP(i,n) {
fscanf(stdin, "%d ", p+i);
m = min(m, p[i]);
if (p[i] <= m) res++;
}
fprintf(stdout, "%d\n", res);
return 0;
}
| 1 |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = INT_MAX / 2;
const ll inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);
vector<int> eratos(int max_n) {
vector<int> is_prime(max_n, 1);
is_prime[0] = is_prime[1] = 0;
for (int i = 2; i < max_n; i++) {
if (!is_prime[i]) continue;
for (int j = i * 2; j < max_n; j += i) {
is_prime[j] = 0;
}
}
return is_prime;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
/*------------------------------*/
int n;
cin >> n;
vector<int> prime = eratos(55555);
vector<int> ans;
for (int i = 0; i < sz(prime); i++)
{
if (prime[i]) {
if (i % 10 == 1) {
ans.push_back(i);
}
}
}
rep(i, n) {
cout << ans[i] << " ";
}
cout << endl;
return 0;
} | #include <iostream>
#include <iomanip>
using namespace std;
int main(void)
{
const double PI=3.1415926535897932;
int r; cin >> r;
double l = (double) (2 * r) * PI;
cout << fixed << setprecision(15) << l << endl;
}
| 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 pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main(){
ll h,w;cin >> h >>w;
vvl g(h,vl(w));
rep(i,h){
rep(j,w){
cin >> g[i][j];
g[i][j]%=2;
}
}
vector<pair<pl,pl>> ans;
rep(i,h){
if(i%2==0){
rep(j,w-1){
if(g[i][j]){
ans.pb({{i,j},{i,j+1}});
g[i][j+1]++;
g[i][j+1]%=2;
}
}
if(g[i][w-1]){
if(i+1<h){
ans.pb({{i,w-1},{i+1,w-1}});
g[i+1][w-1]++;
g[i+1][w-1]%=2;
}
}
}
else{
per(j,w-1){
if(g[i][j+1]){
ans.pb({{i,j+1},{i,j}});
g[i][j]++;
g[i][j]%=2;
}
}
if(g[i][0]){
if(i+1<h){
ans.pb({{i,0},{i+1,0}});
g[i+1][0]++;
g[i+1][0]%=2;
}
}
}
}
cout << ans.size() <<endl;
for(auto p:ans){
cout << p.fi.fi+1 <<" " << p.fi.se+1 <<" "<<p.se.fi+1 << " " << p.se.se+1 <<endl;
}
} | // #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;
#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
mt19937 __gen = mt19937(__rd()); \
uniform_int_distribution<int> __dis(1, 1E8); \
auto rnd = bind(__dis, __gen)
const int INF = 1E18;
const int mod = 1E9 + 7;
const int maxn = 100 + 5;
int32_t main() {
fastIO();
int n, m;
cin >> n >> m;
int vec[n][m];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) cin >> vec[i][j];
}
vector<pair<pii, pii>> op;
for (int i = 0; i < n; ++i) {
if (i < n-1) {
for (int j = 0; j < m; ++j) {
if (vec[i][j] & 1) {
op.pb({{i+1, j+1}, {i+2, j+1}});
++vec[i+1][j];
}
}
}
else {
for (int j = 0; j < m-1; ++j) {
if (vec[i][j] & 1) {
op.pb({{i+1, j+1}, {i+1, j+2}});
++vec[i][j+1];
}
}
}
}
cout << op.size() << "\n";
for (auto x : op) cout << x.X.X << " " << x.X.Y << " " << x.Y.X << " " << x.Y.Y << "\n";
return 0;
} | 1 |
#include <iostream>
#include <vector>
using namespace std;
int main(void){
int n;
cin >> n;
vector<double> a(n);
double sum = 0;
for(int i = 0;i < n;i++){
cin >> a[i];
sum += a[i];
}
double ave = sum / n;
double t = 101;
int ans = -1;
for(int i = a.size() - 1;i >= 0;i--){
if(t >= abs(ave - a[i])){
t = abs(ave - a[i]);
ans = i;
}
}
cout << ans << endl;
}
| #include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;
int main()
{
int N; cin >> N;
vector<double> as(N); for (auto &ai : as) cin >> ai;
const double avg = accumulate(as.begin(), as.end(), 0.0) / static_cast<double>(N);
map<double, int> diff2IndexMap;
for (int i = N - 1; i >= 0; --i)
{
diff2IndexMap[abs(as[i] - avg)] = i;
}
cout << diff2IndexMap.begin()->second << endl;
}
| 1 |
#include<cstdio>
using namespace std;
#define LL long long
#define mod 998244353
const int NN=1000000+117;
LL fact[NN]={};
LL rev[NN]={};
LL comp(int m,int n){
return fact[n]*rev[m]%mod*rev[n-m]%mod;
}
LL ksm(LL a,LL b){
LL ret=1;
while(b){
if(b&1){
(ret*=a)%=mod;
}
(a*=a)%=mod;
b>>=1;
}
return ret;
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
int top=n+m;
fact[0]=1;
for(int i=1;i<=top;++i)
fact[i]=fact[i-1]*i%mod;
rev[top]=ksm(fact[top],mod-2);
for(int i=top;i>=1;--i)
rev[i-1]=rev[i]*i%mod;
if(n<m)m^=n^=m^=n;
LL ans=0;
for(int i=1;i<=m;++i){
ans+=comp(i,2*i)*comp(m-i,n+m-2*i)%mod;
ans%=mod;
}
ans=ans*rev[2]%mod*rev[m+n]%mod*fact[n]%mod*fact[m]%mod;
ans+=n;
ans%=mod;
printf("%lld\n",ans);
} | #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
#define eprintf(...) 42
#endif
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
clock_t startTime;
double getCurrentTime() {
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
const ll MOD = 998244353;
ll add(ll x, ll y) {
x += y;
if (x >= MOD) return x - MOD;
return x;
}
ll sub(ll x, ll y) {
x -= y;
if (x < 0) return x + MOD;
return x;
}
ll mult(ll x, ll y) {
return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
if (p == 0) return 1;
if (p & 1) return mult(x, bin_pow(x, p - 1));
return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
return bin_pow(x, MOD - 2);
}
const int N = (int)1e6 + 77;
ll f[N], rf[N];
ll getC(int n, int k) {
if (k < 0 || k > n) return 0;
return mult(f[n], mult(rf[k], rf[n - k]));
}
int main()
{
startTime = clock();
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
f[0] = 1;
for (int i = 1; i < N; i++)
f[i] = mult(f[i - 1], i);
rf[N - 1] = rev(f[N - 1]);
for (int i = N - 1; i > 0; i--)
rf[i - 1] = mult(rf[i], i);
int n, m;
scanf("%d%d", &n, &m);
ll ans = 0;
for (int k = 1; k <= min(n, m); k++)
ans = add(ans, mult(getC(2 * k, k), getC(n + m - 2 * k, n - k)));
ans = mult(ans, rev(mult(2, getC(n + m, m))));
ans = add(ans, max(n, m));
printf("%lld\n", ans);
return 0;
}
| 1 |
#include <iostream>
using namespace std;
bool Include3(int n){
if(n%10==3){
return true;
}
n/=10;
if(n){
return Include3(n);
}
return false;
}
void CheckNum(int n){
if(n%3==0){
cout << " " << n;
return;
}
if(n>9){
if(Include3(n)){
cout << " " << n;
}
}
}
int main(void){
int n;
cin >> n;
for(int i=1;i<=n;i++){
CheckNum(i);
}
cout << endl;
} | #include <iostream>
#include <math.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n;i++) {
if (i % 3 == 0) {
cout << " " << i;
}
else {
for (int j = 0; j < 4;j++) {
int n;
int m;
n = pow(10, j + 1);
m = n / 10;
if (j == 0 && i % n == 3) {
cout << " " << i;
break;
}else if (j != 0 && (i % n) / m == 3) {
cout << " " << i;
break;
}
}
}
}
cout << endl;
//cin >> /*変数他*/;
//cout << /*文字列*/ << endl;
return 0;
}
| 1 |
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int n,h,w,res1,res2;
signed main(){
cin>>n>>h>>w;
res1=n-h;
res1++;
res2=n-w;
res2++;
res1=res1*res2;
cout<<res1<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;
const double PI = acos(-1);
int main(){
int n,h,w; cin >> n >> h >> w;
int ans = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(h+i-1 >= n) break;
if(w+j-1 >= n) break;
ans++;
}
}
cout << ans << endl;
return 0;
}
| 1 |
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
//#include "MyMath.h"
//#include "MyDisjointset.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <stdio.h>
using namespace std;
typedef pair<int, int> P;
const int INF = 1000000000;
struct edge {
int from, to, cost;
};
int main() {
int v, e, r; cin >> v >> e >> r;
vector <edge> ed;
for (int i = 0; i < e; i++) {
int s, t, co; cin >> s >> t >> co;
edge e1; e1.from = s; e1.to = t; e1.cost = co;
ed.push_back(e1);
}
int *d = new int[v];
fill(d, d + v, INF);
d[r] = 0;
while (true) {
bool update = false;
for (int i = 0; i < ed.size(); i++) {
edge ex = ed[i];
if (d[ed[i].from] != INF && d[ed[i].to] > d[ed[i].from] + ex.cost) {
d[ed[i].to] = d[ed[i].from] + ex.cost;
//cout << "from " << d[ed[i].from] << " to " << d[ed[i].to] << " cost " << ex.cost << endl;
update = true;
}
}
if (!update) break;
}
for (int i = 0; i < v; i++) {
if (d[i] == INF) cout << "INF" << endl;
else cout << d[i] << endl;
}
delete[] d;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100005;
struct sj{
int a,l,r;ll x;
inline sj(){}
inline sj(int a,int l,int r,ll x):a(a),l(l),r(r),x(x){}
inline bool operator<(const sj &t)const{return x>t.x;}
}d[N];
inline void cmax(ll &a,ll b){if(a<b)a=b;}
inline ll Y(int i,ll k){
ll a=d[i].a;
if(k<=a)return k*d[i].l;
else return k*d[i].r+a*(d[i].l-d[i].r);
}
int main(){
int n,i,a,l,r,x;
ll L=0ll,R,M,S,g=0ll,t1,t2;
scanf("%d%d",&n,&x);R=(S=(t1=((ll)x))*n)-1ll;
for(i=1;i<=n;++i){
scanf("%d%d%d",&a,&l,&r);t2=a;
d[i]=sj(a,l,r,t1*r+t2*(l-r));
g+=l*t2;
}
sort(d+1,d+n+1);
while(L<=R){
M=(L+R)>>1;
l=M/x;
r=M%x;
// printf("M=%lld l=%d r=%d",M,l,r);
// for(i=1;i<=n;++i)printf(" (%d,%d)",d[i].x,Y(i,r));
// printf("\n");
t1=-1000000000000ll;t2=0ll;
for(i=1;i<=l;++i){
t2+=d[i].x;
cmax(t1,Y(i,r)-d[i].x);
}
t1+=d[i].x;
for( ;i<=n;++i)cmax(t1,Y(i,r));
if(t1+t2>=g)R=(S=M)-1ll;else L=M+1ll;
}
printf("%lld",S);
return 0;
} | 0 |
#include <bits/stdc++.h>
#define rep2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x) {
return x * x;
}
signed main() {
int R, G;
cin >> R >> G;
cout << 2. * G - R << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int r, g;
cin >> r;
cin >> g;
cout << g - r + g << endl;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int inf = 1e9 + 5;
const int nax = 105;
char sl[nax][nax];
// int pref[nax][nax];
int dp[nax][nax][nax], old[nax][nax][nax];
int fixX[nax][nax], fixY[nax][nax];
/*int getSum(int x1, int y1, int x2, int y2) {
if(x1 > x2) return 0;
if(y1 > y2) return 0;
if(x1 == x2) return fixX[x1][y2] - (y1 ? fixX[x1][y1-1] : 0);
if(y1 == y2) return fixY[y1][x2] - (x1 ? fixY[y1][x1-1] : 0);
assert(false);
}*/
int sumY(int y, int x1, int x2) {
if(x1 > x2) return 0;
maxi(x1, 0);
mini(x2, nax - 1);
return fixY[y][x2] - (x1 ? fixY[y][x1-1] : 0);
}
int sumX(int x, int y1, int y2) {
if(y1 > y2) return 0;
maxi(y1, 0);
mini(y2, nax - 1);
return fixX[x][y2] - (y1 ? fixX[x][y1-1] : 0);
}
int main() {
int h, w;
scanf("%d%d", &h, &w);
int ex, ey;
REP(y, h) {
scanf("%s", sl[y]);
REP(x, w) {
if(x) fixY[y][x] += fixY[y][x-1];
if(y) fixX[x][y] += fixX[x][y-1];
//if(x) pref[x][y] += pref[x-1][y];
//if(y) pref[x][y] += pref[x][y-1];
//if(x && y) pref[x][y] -= pref[x-1][y-1];
if(sl[y][x] == 'E') {
ex = x;
ey = y;
}
else if(sl[y][x] == 'o') {
//++pref[x][y];
++fixX[x][y];
++fixY[y][x];
}
}
}
int ans = 0;
REP(a,nax)REP(b,nax)REP(c,nax) dp[a][b][c] = old[a][b][c] = -inf;
dp[ex][ey][ey] = 0;
FORD(x1, ex, 0) {
if(x1 != ex) REP(a,nax)REP(b,nax)REP(c,nax) {
old[a][b][c] = dp[a][b][c];
dp[a][b][c] = -inf;
}
FOR(x2, ex, w - 1) FORD(y1, ey, 0) FOR(y2, ey, h - 1) {
int & me = dp[x2][y1][y2];
//if(y2 < h - ey + y1) {
// puts("a");
if(y1 >= (y2 - ey))
maxi(me, dp[x2][y1+1][y2] + sumY(y1, max(x1, x2 - ex), min(x2, w - 1 - (ex - x1))));
if(y2 < h - (ey - y1))
maxi(me, dp[x2][y1][y2-1] + sumY(y2, max(x1, x2 - ex), min(x2, w - 1 - (ex - x1))));
//if(x2 < w - ex + x1) {
// puts("b");
if(x2 < w - (ex - x1))
maxi(me, (x2 ? dp[x2-1][y1][y2] : 0) + sumX(x2, max(y1, y2 - ey), min(y2, h - 1 - (ey - y1))));
if(x1 >= (x2 - ex))
maxi(me, old[x2][y1][y2] + sumX(x1, max(y1, y2 - ey), min(y2, h - 1 - (ey - y1))));
//printf("%d,%d,%d,%d -> %d\n", x1, x2, y1, y2, me);
maxi(ans, me);
}
}
printf("%d\n", ans);
/*FOR(x1, 0, ex) {
int x2 = ex - 1;
while(x2 + 1 < w && x2 + 1 + (ex - x1) < w) ++x2;
if(x2 == ex - 1) continue;
FOR(y1, 0, ey) {
int y2 = ey - 1;
while(y2 + 1 < h && y2 + 1 + (ey - y1) < h) ++y2;
if(y2 == ey - 1) continue;
int maybe = pref[x2][y2];
if(x1) maybe -= pref[x1-1][y2];
if(y1) maybe -= pref[x2][y1-1];
if(x1 && y1) maybe += pref[x1-1][y1-1];
//printf("%d %d %d %d\n", x1, x2, y1, y2);
maxi(ans, maybe);
}
}
printf("%d\n", ans); */
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define int long long
namespace yspm{
inline int read()
{
int res=0,f=1; char k;
while(!isdigit(k=getchar())){if(k=='-') f=-1;}
while(isdigit(k)){res=res*10+k-'0'; k=getchar();}
return res*f;
}
const int N=2e3+10;
int n,m,T,sum1[N][N],g[N][N];
int lin[N][N],row[N][N],sum2[N][N];
char s[N];
signed main()
{
n=read(); m=read(); T=read();
for(int i=1;i<=n;++i)
{
scanf("%s",s);
for(int j=1;j<=m;++j) g[i][j]=s[j-1]-'0';
}
for(int i=1;i<=n;++i)
{
for(int j=1;j<=m;++j)
{
sum1[i][j]=sum1[i-1][j]+sum1[i][j-1]-sum1[i-1][j-1];
sum2[i][j]=sum2[i-1][j]+sum2[i][j-1]-sum2[i-1][j-1];
if(g[i][j]) ++sum2[i][j];
row[i][j]=row[i][j-1]; lin[i][j]=lin[i-1][j];
if(g[i][j])
{
if(g[i-1][j]) ++sum1[i][j],++row[i][j];
if(g[i][j-1]) ++sum1[i][j],++lin[i][j];
}
}
}
int x1,y1,x2,y2;
while(T--)
{
x1=read(); y1=read(); x2=read(); y2=read();
int tmp=sum1[x2][y2]-sum1[x2][y1-1]-sum1[x1-1][y2]+sum1[x1-1][y1-1];
tmp-=lin[x2][y1]-lin[x1-1][y1];
tmp-=row[x1][y2]-row[x1][y1-1];
int ans=sum2[x2][y2]-sum2[x2][y1-1]-sum2[x1-1][y2]+sum2[x1-1][y1-1]-tmp;
printf("%lld\n",ans);
}
return 0;
}
}
signed main()
{
yspm::main();
return 0;
} | 0 |
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>>
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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 x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32; で小文字に
// cout << fixed << setprecision (20); 小数点以下20桁まで
//実行時間制約2秒では2×10^8回くらいまで計算できる
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n,m,v,p;
cin>>n>>m>>v>>p;
vector<ll> q(n);
rep(i,n){
cin>>q[i];
}
sort(all(q));
reverse(all(q));
//————————————————二分探索——————————————————————————
int ng = n;
int ok = p-1;
while (abs(ok - ng) > 1) {
int mid = (ng + ok) / 2;
ll x=q[mid]+m;
if(x<q[p-1]){
ng=mid;
continue;
}
int cnt=n-mid+p-1;
ll hyo=m*cnt;
for(int i=p-1;i<mid;i++){
hyo+=x-q[i];
}
(m*v<=hyo? ok : ng) = mid;
}
cout << ok+1 << endl;
//——————————————————————————————————————————
} | #include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
T f=0,x=0;char c=getchar();
while(!isdigit(c)) f=c=='-',c=getchar();
while(isdigit(c)) x=x*10+c-48,c=getchar();
return f?-x:x;
}
#define int long long
namespace run{
const int N=2e5+9;
int a[N],m,v,p,n,ans,sum[N];
int main(){
n=read<int>(),m=read<int>(),v=read<int>(),ans=p=read<int>();
for(int i=1;i<=n;i++) a[i]=read<int>();
sort(a+1,a+n+1);
for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
// for(int i=1;i<=n;i++) cout<<a[i]<<" ";cout<<endl;
for(int i=1;i<=n-p;i++){
if(m+a[i]<a[n-p+1]) continue;
else{
int tmp=(p-1+i)*m+((n-p+1-i)*(a[i]+m)-(sum[n-p+1]-sum[i]));
// cout<<tmp<<endl;
if(tmp>=m*v) ans++;
}
}
printf("%lld\n",ans);
return 0;
}
}
#undef int
int main(){
#ifdef my
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#endif
return run::main();
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))
const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;
int main(){
ll n;
cin >> n;
vector<ll> sq;
ll cnt = 1;
while (cnt * cnt <= n)
{
sq.push_back(cnt*cnt);
cnt++;
}
sort(sq.begin(), sq.end());
cout << sq[sq.size() - 1] << endl;
return 0;
} | #include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }
ll INF = 1001001001;
ll LINF = 1001001001001001001ll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin>>s;
ll n = sz(s);
reverse(rng(s));
s.push_back('0');
vvl dp(n + 2, vl(2, LINF));
dp[0][0] = 0, dp[0][1] = 0;
rep(i, n + 1) rep(j, 2) rep(k, 2) { // j:繰り上がりをする k:繰り上がりされた
ll c = s[i] - '0';
if (i > 0 && k) c++;
if (c == 10 && j == 0) continue;
if (c == 0 && j == 1) continue;
if (j) chmin(dp[i + 1][j], dp[i][k] + (10 - c) % 10);
else chmin(dp[i + 1][j], dp[i][k] + c);
}
cout<<min(dp[n + 1][0], dp[n + 1][1])<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++){
cin>>a.at(i);
}
sort(a.begin(),a.end());
int flag=0;
for(int i=0;i<n-1;i++){
if(a.at(i)==a.at(i+1)){
flag=1;
}
}
if(flag==0){
cout<<"YES";
}else{
cout<<"NO";
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n;
cin >>n;
map<int,int>mp;
for(int i=0;i<n;i++){
int a;
cin>>a;
mp[a]++;
mp[a]%=2;
}
long long kotae=0;
auto begin=mp.begin(),end=mp.end();
for(auto iter=begin;iter!=end;iter++){
int x=iter->second;
if(x==1)kotae++;
}
cout<<kotae<<endl;
return 0;
}
| 0 |
#include <stdio.h>
int main(void){
int n,i,j,k;
scanf("%d",&n);
int retsu[n];
for (i = 1; i <= n; i++){
k = n - i;
scanf("%d",&retsu[k]);
}
for (j = 0; j < n; j++){
if( j ) printf(" ");
printf("%d",retsu[j]);
}
printf("\n");
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
int n;
cin>>n;
vector<ll> a(n),b(n),c(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
cin>>b[i];
}
for(int i=0;i<n;i++){
cin>>c[i];
}
sort(a.begin(),a.end());
sort(c.begin(),c.end());
ll ans=0;
for(int i=0;i<n;i++){
auto it=lower_bound(a.begin(),a.end(),b[i]);
ll Adis=distance(a.begin(),it);
it=upper_bound(c.begin(),c.end(),b[i]);
ll Cdis=distance(it,c.end());
ans+=(Adis*Cdis);
}
cout<<ans<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
for (int i = 0; i < n; ++i)
cin >> b[i];
reverse(b.begin(), b.end());
int start = -1, fin = -1;
for (int i = 0; i < n; ++i) {
if (a[i] == b[i]) {
if (start == -1) start = i;
fin = i;
}
}
bool bad = 0;
if (start != -1) {
for (int i = 0, j = start; j <= fin; ++i) {
if (i == start) i = fin + 1;
if (i == n) {
bad = 1;
break;
}
if (a[i] != b[j] && b[j] != b[i]) {
swap(b[i], b[j++]);
}
}
}
if (bad) {
cout << "No" << '\n';
}
else {
cout << "Yes" << '\n';
for (int i = 0; i < n; ++i) {
if (i) cout << " ";
cout << b[i];
}
cout << '\n';
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
int main(){
int N;
cin >> N;
vector<int> A(N);
vector<int> B(N);
rep(i,N){
cin >> A[i];
}
rep(i,N){
cin >> B[i];
}
map<int,int> mpa;
map<int,int> mpb;
rep(i,N){
mpa[A[i]]++;
mpb[B[i]]++;
}
vector<int> a(N + 1, 0);
vector<int> b(N + 1, 0);
rep(i,N){
a[A[i]] = i + 1;
}
rep(i,N){
b[B[i]] = i + 1;
}
rep(i,N){
a[i + 1] = max(a[i + 1], a[i]);
b[i + 1] = max(b[i + 1], b[i]);
}
cout << endl;
int max_sum = 0;
int max_pointer = 1;
for (int i = 1; i <= N; i++){
if (max_sum < mpa[i] + mpb[i]){
max_sum = mpa[i] + mpb[i];
max_pointer = i;
}
}
bool possible = true;
vector<int> C(N);
if (max_sum > N){
possible = false;
}
else{
int zurashi = -1 * N;
rep(i,N){
zurashi = max(zurashi, a[i + 1] - b[i]);
}
rep(i,N){
C[(i + zurashi) % N] = B[i];
}
}
if (!possible) cout << "No" << endl;
else{
cout << "Yes" << endl;
rep(i,N){
cout << C[i] << " ";
}
cout << endl;
}
} | 1 |
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef long long ll;
int gi() {
int x=0,o=1;char ch=getchar();
while(!isdigit(ch)&&ch!='-') ch=getchar();
if(ch=='-') o=-1,ch=getchar();
while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
return x*o;
}
struct dat {
int l,r;
bool operator<(const dat &A) const {
return r<A.r;
}
} a[N];
int n,pre1[N],suf1[N],pre2[N],suf2[N],ans;
int len(int l,int r) {
if(l>r) return 0;
return r-l+1;
}
int main() {
cin>>n;
for(int i=1;i<=n;i++) a[i].l=gi(),a[i].r=gi();
sort(a+1,a+n+1);
pre2[0]=1e9;
for(int i=1;i<=n;i++) {
pre1[i]=max(pre1[i-1],a[i].l);
pre2[i]=min(pre2[i-1],a[i].r);
}
suf2[n+1]=1e9;
for(int i=n;i;i--) {
suf1[i]=max(suf1[i+1],a[i].l);
suf2[i]=min(suf2[i+1],a[i].r);
}
for(int i=1;i<=n;i++) {
int L=max(pre1[i-1],suf1[i+1]);
int R=min(pre2[i-1],suf2[i+1]);
ans=max(ans,a[i].r-a[i].l+1+len(L,R));
if(i^n) ans=max(ans,len(pre1[i],pre2[i])+len(suf1[i+1],suf2[i+1]));
}
cout<<ans;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
const ll p=1000000007;
int main(){
ll n;
cin >> n;
ll bb=0;
ll k[n];
rep(i,n){
ll a,b;
cin >> a >> b;
bb+=b;
k[i]=a+b;
}
sort(k,k+n);
ll ans=0;
rep(i,n-n/2){
ans+=k[n-1-2*i];
}
cout << ans-bb << endl;
}
| 0 |
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,m,q;
cin>>n>>m>>q;
int out=0,mi=inf;
vi a(n),b(m);
rep(i,n)cin>>a[i],cmin(mi,a[i]);
out+=mi;
mi=inf;
rep(i,m)cin>>b[i],cmin(mi,b[i]);
out+=mi;
rep(i,q){
int x,y,z;
cin>>x>>y>>z;
cmin(out,a[x-1]+b[y-1]-z);
}
cout<<out<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int a,b,m;
cin >> a >> b >> m;
vector<int> refs(a);
vector<int> renges(b);
for(int i = 0; i < a; i++) {
cin >> refs.at(i);
}
for(int i = 0; i < b; i++) {
cin >> renges.at(i);
}
int ans = refs.at(0) + renges.at(0);
for(int i = 0; i < m; i++) {
int aIndex,bIndex,discount;
cin >> aIndex >> bIndex >> discount;
int tempAns = refs.at(aIndex - 1) + renges.at(bIndex - 1) - discount;
if(tempAns < ans) {
ans = tempAns;
}
}
std::sort(refs.begin(), refs.end());
std::sort(renges.begin(), renges.end());
int noDiscount = refs.at(0) + renges.at(0);
if(noDiscount < ans) {
cout << noDiscount << endl;
} else {
cout << ans << endl;
}
return 0;
} | 1 |
#include<stdio.h>
#include<string.h>
void haichi(void);
void Block(int,int);
int c,d,x,y,xg,yg,M,Flag;
int MAP[101][101],MF[101][101];
int main(void)
{
int w,h,xs,ys,n;
while(1){
Flag=0;
memset(MAP,0,sizeof(MAP));
memset(MF,0,sizeof(MF));
scanf("%d %d",&w,&h);
if(w == 0 && h == 0) break;
scanf("%d %d %d %d",&xs,&ys,&xg,&yg);
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d %d %d %d",&c,&d,&x,&y);
haichi();
}
/*for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
printf("%d",MAP[i][j]);
}
printf("\n");
}*/
M = MAP[ys][xs];//
if(MAP[ys][xs] == MAP[yg][xg])
Block(xs,ys);
if(Flag==1)
printf("OK\n");
else
printf("NG\n");
}
return 0;
}
void haichi(void)
{
if(d==0){
MAP[y][x]=c;MAP[y][x+1]=c;MAP[y][x+2]=c;MAP[y][x+3]=c;
MAP[y+1][x]=c;MAP[y+1][x+1]=c;MAP[y+1][x+2]=c;MAP[y+1][x+3]=c;
}
else if(d==1){
MAP[y][x]=c;MAP[y][x+1]=c;
MAP[y+1][x]=c;MAP[y+1][x+1]=c;
MAP[y+2][x]=c;MAP[y+2][x+1]=c;
MAP[y+3][x]=c;MAP[y+3][x+1]=c;
}
}
void Block(int X,int Y)
{
MF[Y][X] = 1;
//printf("%d",M);
if(X == xg && Y == yg)
Flag = 1;
if(MAP[Y-1][X] == M && MF[Y-1][X] == 0) Block(X,Y-1); //???
if(MAP[Y+1][X] == M && MF[Y+1][X] == 0) Block(X,Y+1); //???
if(MAP[Y][X-1] == M && MF[Y][X-1] == 0) Block(X-1,Y); //???
if(MAP[Y][X+1] == M && MF[Y][X+1] == 0) Block(X+1,Y); //???
} | #include<iostream>
using namespace std;
#define MAX 100
#define BLANK 0
#define LONG 4
#define SHORT 2
#define HORIZONTAL 0
#define VERTICAL 1
#define VISITED 9
int field[MAX+2][MAX+2];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
void rec(int x,int y,int c)
{
int i;
if(field[x][y]!=c)return;
field[x][y]=VISITED;
for(i=0;i<4;i++)rec(x+dx[i],y+dy[i],c);
return;
}
int main()
{
int w,h,xs,ys,xg,yg,n,c,d,x,y;
int i,j;
while(cin>>w>>h>>xs>>ys>>xg>>yg>>n,w|h){
for(j=1-1;j<=h+1;j++)for(i=1-1;i<=w+1;i++)field[i][j]=BLANK;
while(n-->0){
cin>>c>>d>>x>>y;
if(d==HORIZONTAL)
for(i=0;i<LONG;i++)for(j=0;j<SHORT;j++)field[x+i][y+j]=c;
else
for(i=0;i<SHORT;i++)for(j=0;j<LONG;j++)field[x+i][y+j]=c;
}
if(field[xs][ys]!=BLANK)rec(xs,ys,field[xs][ys]);
puts(field[xg][yg]==VISITED?"OK":"NG");
}
} | 1 |
#include <iostream>
#include <vector>
using namespace std;
const int V_MAX = 100000;
struct LowLink
{
const vector<vector<int>> &g;
int V;
vector<vector<int>> dfs_tree;
vector<int> dfs_roots;
int pre_order[V_MAX];
int p_ord = 0;
int lowlink[V_MAX];
bool articulation[V_MAX] = {};
vector<pair<int, int>> bridge;
LowLink(const vector<vector<int>> &g) : g(g), V(g.size()), dfs_tree(g.size()) {}
void dfs(int v, int parent) {
lowlink[v] = pre_order[v] = p_ord;
p_ord++;
for (int nv : g[v]) {
if (nv == parent) continue;
if (pre_order[nv] == -1) {
dfs_tree[v].push_back(nv);
dfs(nv, v);
lowlink[v] = min(lowlink[v], lowlink[nv]);
}
lowlink[v] = min(lowlink[v], pre_order[nv]);
}
}
void calc() {
p_ord = 0;
fill(pre_order, pre_order+V_MAX, -1);
for (int i = 0; i < V; i++) {
if (pre_order[i] != -1) continue;
dfs_roots.push_back(i);
dfs(i, -1);
}
for (int i = 0; i < V; i++) {
for (int j : dfs_tree[i]) {
if (pre_order[i] < lowlink[j]) bridge.push_back({i, j});
}
}
for (int i = 0, x = 0; i < V; i++) {
bool ok = false;
if (x < dfs_roots.size() && dfs_roots[x] == i) {
if (dfs_tree[i].size() > 1) ok = true;
x++;
} else {
for (int j : dfs_tree[i]) {
if (pre_order[i] <= lowlink[j]) ok = true;
}
}
articulation[i] = ok;
}
}
};
int main() {
int V, E;
cin >> V >> E;
vector<vector<int>> g(V);
for (int i = 0; i < E; i++) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
LowLink L(g);
L.calc();
for (int i = 0; i < V; i++) {
if (L.articulation[i]) cout << i << endl;
}
return 0;
}
| #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end
vector<int> g[101010];
int col[101010],cnt;
bool dfs(int v,int c){
col[v]=c; cnt++; bool res=1;
for(int t:g[v]){
if(col[t]!=-1){
if(col[t]+c!=1)res=0;
}
else if(!dfs(t,c^1))res=0;
} return res;
}
int main(){
int n,m; cin>>n>>m;
rep(i,0,n)col[i]=-1;
rep(i,0,m){
int x,y; cin>>x>>y; x--; y--;
g[x].push_back(y); g[y].push_back(x);
}
ll a=0,b=0,c=0;
rep(i,0,n)if(col[i]==-1){
cnt=0; bool f=dfs(i,0);
if(cnt==1)a++;
else if(f)b++; else c++;
}
cout<<(a*a+a*(n-a)*2)+(b+c)*(b+c)+b*b<<endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n, cnt = 0; cin >> n;
ll x; cin >> x;
vector<ll> a(n);
rep(i,n) cin >> a[i];
sort(a.begin(), a.end());
rep(i,n) {
if (x >= a[i]) {
if (i == n-1 && x == a[i]) cnt++;
else if (i != n-1) {
x -= a[i];
cnt++;
}
}
else break;
}
cout << cnt << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*
*/
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
ll N;
cin >> N;
vector<ll> A(N, 0);
rep(i, N) cin >> A[i];
ll high = A[0], ans = 0;
rep(i, N){
ans += max(high - A[i], 0LL);
chmax(high, A[i]);
}
cout << ans << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) begin(v),end(v)
using ll = long long;
int main() {
int n;cin>>n;
int ans=0;
for(int i=1;i<=n;i++){
if(i*i>n)break;
ans=max(ans,i*i);
}
cout<<ans<<endl;
} | #include <iostream>
using namespace std;
int main(void)
{
int x; cin >> x;
int ans = 0;
ans += 1000 * (x / 500);
x = x % 500;
ans += 5 * (x / 5);
cout << ans << endl;
} | 0 |
/*
ID: anonymo14
TASK: wormhole
LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;
#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back
#define REP(i,a,b) for(int i=a; i<=b; i++)
#define MOD 1000000007
void solve(int test_case) {
ll a,b;
cin>>a>>b;
ll dc = __gcd(a,b);
int cnt = 1;
for(ll i=2;i*i<=dc;i++) {
if(dc%i==0) {
cnt++;
while(dc%i==0)dc/=i;
}
}
if(dc!=1)cnt++;
cout<<cnt;
}
int main() {
////// FILE BASED IO////
//freopen("wormhole.in", "r", stdin);
//freopen("wormhole.out", "w", stdout);
///////////////
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin>>t;
REP(i,1,t) {
solve(i);
}
return 0;
}
| #include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;
int main() {
int N, M, L, R;
cin >> N >> M;
int a, b;
a = 0;
b = N;
for (int i = 0; i < M; i++) {
cin >> L >> R;
a = max(a, L);
b = min(b, R);
}
int ret = b - a;
if (ret < 0) ret = 0;
else ret++;
cout << ret << endl;
} | 0 |
#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>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
//#define INF 1e18
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX]; //n!, 1/n!, 1/n
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(ll n, ll k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
map<ll,ll> prime_factor(ll n){
map<ll,ll> res;
for(ll i=2;i*i<=n;i++){
while(n%i==0){
++res[i];
n /= i;
}
}
if(n!=1) res[n] = 1;
return res;
}
int main(){
ll n,m;
cin >> n >> m;
COMinit();
ll ans=1;
map<ll,ll> M = prime_factor(m);
for(auto p : M){
ll k = p.second;
ans *= COM(n+k-1,k);
ans %= MOD;
}
cout << ans << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rall(x) (x).rbegin(),(x).rend()
int main(){
int n; cin>>n;
n*=2;
vector<int> v(n);
rep(i,n) cin>>v[i];
sort(rall(v));
int cnt=0;
for(int i=0; i<n; i+=2){
cnt+=v[i+1];
}
cout<<cnt<<endl;
} | #include<iostream>
#include<vector>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<map>
#define INF 0xFFFFFF
#define ull unsigned long long
#define ll long long
#define ms(x,a) memset(x,a,sizeof(x))
#define endl "\n"
#define M(a,b) (a+b)/2
#define L(x) 2*x
#define R(x) 2*x+1
using namespace std;
typedef pair<int,ll> ii;
typedef pair<int,ii> iii;
int Move[8][2]={{1,0},{-1,0},{0,1},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}};
/*
nothing at all
*/
int scr(string s){
int score=INF;
for(int i=0;i<s.size()-1;i++){
score=min(score,abs(s[i]-s[i+1]));
}
//cout<<s<<" "<<score<<endl;
return score;
}
int main(){
int n;
cin>>n;
int arr[2*n+10];
for(int i=0;i<2*n;i++){
cin>>arr[i];
}
sort(arr,arr+(2*n));
int rzlt=0;
for(int i=0;i<n;i++){rzlt+=arr[2*i];}
cout<<rzlt;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define PB push_back
#define PII pair <long long , long long>
#define FAST ios::sync_with_stdio(false);cin.tie(0);
const int maxn = 2e3 + 30;
string a[maxn];
int vertex[maxn][maxn] , er[maxn][maxn] , ed[maxn][maxn];
int main() {
int n , m , q;
cin >> n >> m >> q;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if(a[i - 1][j - 1] == '1') {
vertex[i][j]++;
}
vertex[i][j] += vertex[i - 1][j] + vertex[i][j - 1] - vertex[i - 1][j - 1];
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
// if(a[i - 1][j - 1] == '1' && a[i - 2][j - 1] == '1') {
// ed[i][j]++;
// }
if(a[i - 1][j - 1] == '1' && a[i][j - 1] == '1') {
ed[i][j]++;
}
ed[i][j] += ed[i - 1][j] + ed[i][j - 1] - ed[i - 1][j - 1];
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
// if(a[i - 1][j - 1] == '1' && a[i - 1][j - 2] == '1') {
// er[i][j]++;
// }
if(a[i - 1][j - 1] == '1' && a[i - 1][j] == '1') {
er[i][j]++;
}
er[i][j] += er[i - 1][j] + er[i][j - 1] - er[i - 1][j - 1];
}
}
while(q--) {
int x1 , y1 , x2 , y2;
ll p1 = 0 , p2 = 0;
cin >> x1 >> y1 >> x2 >> y2;
p1 = vertex[x2][y2] - vertex[x2][y1 - 1] - vertex[x1 - 1][y2] + vertex[x1 - 1][y1 - 1];
p2 += ed[x2 - 1][y2] - ed[x2 - 1][y1 - 1] - ed[x1 - 1][y2] + ed[x1 - 1][y1 - 1];
p2 += er[x2][y2 - 1] - er[x1 - 1][y2 - 1] - er[x2][y1 - 1] + er[x1 - 1][y1 - 1];
cout << p1 - p2 << endl;
}
} | #include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;
int main(){
cin>>N>>M>>Q;
vector<string> grid(N);
rep(i,N) cin>>grid[i];
mat edge(N, vec(M, 0)), num(N + 1, vec(M + 1, 0)), addr(N, vec(M,0)), addc(N, vec(M,0));
rep(i,N){
rep(j,M){
bool blue = grid[i][j] == '1';
if(i > 0) {
edge[i][j] += edge[i-1][j] + (blue && grid[i-1][j] == '1');
addc[i][j] = addc[i-1][j] + (blue && grid[i-1][j] == '1');
}
if(j > 0) {
edge[i][j] += edge[i][j-1] + (blue && grid[i][j-1] == '1');
addr[i][j] = addr[i][j-1] + (blue && grid[i][j-1] == '1');
}
if(i > 0 && j > 0) edge[i][j] -= edge[i-1][j-1];
num[i+1][j+1] = num[i][j+1] + num[i+1][j] - num[i][j] + blue;
}
}
vec x(2), y(2);
rep(i,Q){
rep(j,2) cin>>x[j]>>y[j];
--x[0], --y[0];
ll res = 0;
rep(j,2) rep(k,2) res += (j^k ? -1 : 1) * num[x[j]][y[k]];
--x[1], --y[1];
rep(j,2) rep(k,2) res += (j^k ? 1 : -1) * edge[x[j]][y[k]];
res -= addr[x[0]][y[1]] - addr[x[0]][y[0]];
res -= addc[x[1]][y[0]] - addc[x[0]][y[0]];
cout<<res<<endl;
}
/*rep(i,N){
rep(j,M) cout<<edge[i][j]<<' ';
cout<<endl;
}*/
} | 1 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
char c[55][55];
bool visited[55][55];
int d[55][55];
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
queue<P> Q;
int main()
{
int H,W;
cin >> H >> W;
int cntW = 0;
rep(i,H)
{
rep(j,W)
{
cin >> c[i][j];
if (c[i][j] == '.') cntW++;
}
}
rep(i,55)
{
rep(j,55)
{
d[i][j] = 1e8;
}
}
d[0][0] = 0;
Q.push(P(0,0));
while(!Q.empty())
{
P q = Q.front();
int f = q.first, s = q.second;
Q.pop();
if (visited[f][s]) continue;
visited[f][s] = true;
rep(i,4)
{
int xx = f+dx[i], yy = s+dy[i];
if (xx >= 0 && xx < H && yy >= 0 && yy < W && c[xx][yy] == '.')
{
d[xx][yy] = min(d[xx][yy],d[f][s]+1);
Q.push(P(xx,yy));
}
}
}
/*
rep(i,H)
{
rep(j,W)
{
cout << d[i][j] << " ";
}
cout << endl;
}
*/
if (d[H-1][W-1] == 1e8) cout << -1 << endl;
else cout << cntW - d[H-1][W-1] - 1 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef vector<bool> vbool;
typedef vector<int> vint;
#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep_rev(i, n) for (int i = n-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <class T, class S> inline bool chmax(T &a, S b) {
if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
if(a > b) {a = b;return 1;} return 0;
}
template <class T>
void line(vector<T> &x){for (auto&& xi : x) cin >> xi;}
inline void IN(void){ return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return;}
#define INT(...) int __VA_ARGS__; IN (__VA_ARGS__)
#define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)
template <class T> void UNIQUE(vector<T> &x) {
sort(all(x)); x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(T first, T end){
for (auto i = first; i < end - 1; i++) cout << *i << " ";
cout << *(end-1) << endl;
}
template<class... T>
void debug_print(T... args){
vector<lint> tmp = initializer_list<lint>{args...};
print_vec(all(tmp));
}
template<class T>
void print(T a){ cout << a << endl;}
vector<string> Yes = {"No", "Yes"};
vector<string> YES = {"NO", "YES"};
int ord(char x){ return (int)(x - 'a');}
char chr(lint x){ return (char)(x + (lint)('a'));}
lint mod = 1e9+7;
// lint mod =
lint sum(vlint a){lint ret = 0; for(auto&& v:a) ret += v; return ret;}
lint vmini(vlint a, lint &index){
lint ret = LLONG_MAX;
rep(i, Size(a)){ if (chmin(ret, a[i])) index = i;}
return ret;
}
lint vmaxi(vlint a, lint &index){
lint ret = -LLONG_MAX;
rep(i, Size(a)){ if (chmax(ret, a[i])) index = i;}
return ret;
}
lint vmin(vlint a){
lint ret = LLONG_MAX; for (auto && v : a) chmin(ret, v); return ret;
}
lint vmax(vlint a){
lint ret = -LLONG_MAX; for (auto && v : a) chmax(ret, v); return ret;
}
vlint base_3(int k){
vlint ret; while (k > 0){ ret.pb(k % 3); k /= 3;} reverse(all(ret)); return ret;
}
map<lint, lint> trial_division(lint n){
map<lint, lint> factor;
lint tmp = (lint)(sqrt(n)) + 1;
for (lint i = 2; i < tmp; ++i){
while (n % i == 0){
n /= i;
factor[i] ++;
}
}
if(n != 1) factor[n] ++;
return factor;
}
lint dist(lint x1, lint y1, lint x2, lint y2){
return (x1-x2) * (x1-x2) + (y1-y2) * (y1 - y2);
}
int main(){
INT(h, w);
char o;
vector<vint> grid(h+2, vint(w+2, 0));
int cnt = 0;
rep1(i, h+1){
rep1(j, w+1){
cin >> o;
if (o == '.'){
grid[i][j] = 1;
cnt ++;
}
}
}
queue<pair<int, int>> q;
q.push({1, 1});
vector<vint> dist(h+2, vint(w+2, -1));
dist[1][1] = 0;
int y, x, ny, nx;
vint dx = {-1, 0, 0, 1};
vint dy = {0, -1, 1, 0};
while (!q.empty()){
y = q.front().first;
x = q.front().second; q.pop();
rep(i, 4){
ny = y + dy[i];
nx = x + dx[i];
if (dist[ny][nx] != -1 || grid[ny][nx] == 0){
continue;
}
q.push({ny, nx});
dist[ny][nx] = dist[y][x] + 1;
}
}
if (dist[h][w] == -1){
print(-1);
}
else{
print(cnt - dist[h][w]-1);
}
}
| 1 |
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}
int main2() {
int N = nextLong();
int Q = nextLong();
fenwick_tree<ll> fw(N+10);
REP(i, N) {
int x = nextLong();
fw.add(i, x);
}
REP(qqq, Q) {
int t = nextLong();
if (t == 0) {
int p = nextLong();
int x = nextLong();
fw.add(p, x);
}
else
{
int l = nextLong();
int r = nextLong();
ll ans = fw.sum(l, r);
cout << ans << '\n';
}
}
return 0;
}
int main() {
#ifdef LOCAL
for (;!cin.eof();cin>>ws)
#endif
main2();
return 0;
} | #include <iostream>
#include <stdio.h>
using namespace std;
double sum(int b[],int);
void bubble(int b[],int);
int main(){
int a;
cin >> a;
int b[a];
for (int i=0;i<a;i++)
cin >> b[i];
bubble(b,a);
cout << b[0] << " " << b[a-1] << " " ;
printf("%.0f\n",sum(b,a));
}
void bubble(int b[],int a){
int x;
for (int i=0;i< a-1 ;i++){
for (int j=0;j<a-1 ;j++)
if(b[j]>b[j+1]){
x=b[j];
b[j]=b[j+1];
b[j+1]=x;
}
}
}
double sum(int b[], int a){
double sum=0;
for (int i=0;i<a;i++)
sum += b[i];
return sum;
} | 0 |
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <sstream>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[510][510];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
if (x % y == 0) return y;
return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
ll g = gcd(a, b);
return a / g * b;
}
void comb(vector<vector <ll> >& v) {
for (ll i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (ll k = 1; k < v.size(); k++) {
for (int j = 1; j < k; j++) {
v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
}
}
}
ll GetDigit(ll num) {
return log10(num) + 1;
}
ll Combination(int n, int r)
{
if (n - r < r) r = n - r;
if (r == 0) return 1;
if (r == 1) return n;
vector<ll> numerator(r);
vector<ll> denominator(r);
for (int k = 0; k < r; k++)
{
numerator[k] = n - r + k + 1;
denominator[k] = k + 1;
}
for (int p = 2; p <= r; p++)
{
int pivot = denominator[p - 1];
if (pivot > 1)
{
int offset = (n - r) % p;
for (int k = p - 1; k < r; k += p)
{
numerator[k - offset] /= pivot;
denominator[k] /= pivot;
}
}
}
ll result = 1;
for (int k = 0; k < r; k++)
{
if (numerator[k] > 1) result *= numerator[k];
result %= ma;
}
return result;
}
/*
ll bfs() {
queue<P> que;
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) dis[i][j] = INF;
}
que.push(P(sy - 1, sx - 1));
dis[sy - 1][sx - 1] = 0;
while (que.size() > 0) {
P p = que.front();
que.pop();
if (p.first == gy - 1 && p.second == gx - 1) break;
for (ll i = 0; i < 4; i++) {
ll ny = p.first + dy[i];
ll nx = p.second + dx[i];
if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
que.push(P(ny, nx));
dis[ny][nx] = dis[p.first][p.second] + 1;
}
}
}
return dis[gy - 1][gx - 1];
}*/
int main() {
cin >> n;
string t;
cin >> s >> t;
if (s == t) {
cout << n << endl;
return 0;
}
ll cnt = 0;
ll p = -1;
rep(i, n) {
ll tmp = cnt;
rep(j, n - i) {
if (s[i + j] != t[j]) {
++cnt;
break;
}
}
if (tmp == cnt)break;
}
cout << n+cnt << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,s,n) for(int i = s; i < (int)(n); i++)
int main() {
int n;
string s,t;
cin >> n >> s >> t;
int ans = 2*n;
rep(i,1,n+1){
if(s.substr(n-i,i) == t.substr(0,i)) ans = 2*n-i;
}
cout << ans << endl;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
int calc(vector<int> N, int i, int j, int k) {
return N.at(0) + pow(-1, i) * N.at(1) + pow(-1, j) * N.at(2)+pow(-1, k) * N.at(3);
}
void prt(vector<int> N, vector<int> P) {
cout << N.at(0);
rep(i, 3) {
if (P.at(i) % 2 == 0) cout << "+"; else cout << "-";
cout << N.at(i + 1);
}
cout << "=7" << endl;
}
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
string S;
cin >> S;
vector<int> N(4);
rep(i, 4) N.at(i) = S.at(i) - 48;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int k =0; k < 2; k++) {
vector<int> parity = {i, j, k};
if (calc(N, i, j, k) == 7) {
prt(N, parity);
return 0;
}
}
}
}
return 0;
}
| #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
using namespace std;
typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
const ll SIZE = 1e6 * 2 + 10, INF = INT64_MAX;
ll dp[100], bstX[35000][20], bstY[35000][20];
vector<vector<ll>> gr, psh;
vector<set<ll>> s;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
set<ll> ss;
void debug() {
debug();
}
vector<ll> vec;
bool solve() {
vector<ll> pr, suf;
pr.push_back(0);
suf.push_back(0);
ll cnt = 0, val = 0, s = 0;
for (int i = 0; i < vec.size(); i++) {
if (vec[i] != 1) {
cnt++;
val = vec[i];
}
pr.push_back(gcd(pr.back(), vec[i]));
s += vec[i] - 1;
}
if (cnt == 0) return false;
if (cnt == 1 && val == 2) return true;
for (int i = vec.size() - 1; i >= 0; i--) {
suf.push_back(gcd(suf.back(), vec[i]));
}
reverse(suf.begin(), suf.end());
for (int i = 0; i < vec.size(); i++) {
if (vec[i] == 1) continue;
ll g = gcd(pr[i], suf[i + 1]);
g = gcd(g, vec[i] - 1);
if (g != 1) {
vec[i]--;
for (int j = 0; j < vec.size(); j++) {
vec[j] /= g;
}
bool k = solve();
for (int j = 0; j < vec.size(); j++) {
vec[j] *= g;
}
vec[i]++;
if (!k) return true;
}
}
if (s % 2 == 0) {
return false;
}
else {
return true;
}
}
int main()
{
fastInp;
ll n;
cin >> n;
vec.resize(n);
ll s = 0;
for (int i = 0; i < n; i++) {
cin >> vec[i];
s += vec[i] - 1;
}
if (n % 2 == 0) {
if (s % 2 == 0) {
cout << "Second";
}
else {
cout << "First";
}
}
else {
if (s % 2 == 0) {
if (solve()) {
cout << "First";
}
else {
cout << "Second";
}
}
else {
cout << "First";
}
}
return 0;
} | 0 |
#include <cstdio>
int main()
{
int a,b,c,sum;
scanf("%d/%d/%d",&a,&b,&c);
sum = a + 1;
if(b < 10)
{
printf("%d/0%d",sum,b);
}
else
{
printf("%d/%d",sum,b);
}
if(c < 10)
{
printf("/0%d",c);
}
else
{
printf("/%d",c);
}
}
| #define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MAX_N = 1000000010;
int main(void) {
ll n;
cin >> n;
vector<ll> v;
ll num = 1;
while (num * num < MAX_N) {
v.push_back(num * num);
num++;
}
reverse(v.begin(), v.end());
for (auto sq : v) {
if (sq <= n) {
cout << sq << endl;
return 0;
}
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> A(M);
for (int i = 0; i < M; i++) {
cin >> A[i];
}
// 昇順で確認する必要がある
sort(A.begin(), A.end());
vector<int> p = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
// マッチをi本使ったときの桁数の最大値
// 初期値は-1で埋めておく
// 要素数は N + 7 (pの最大値) + α
vector<int> dp(N+10, -1);
dp[0] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
int k = p[A[j]];
dp[i + k] = max(dp[i + k], dp[i] + 1);
}
}
// 残りのマッチの本数
int remain = N;
while (0 < remain) {
// 答え
int answer = 0;
// 使うマッチの本数
int use = 0;
for (int i = 0; i < M; i++) {
// 使いたいマッチの本数
int k = p[A[i]];
// マッチが使える場合
if (k <= remain) {
// kを使った後の残ったマッチの本数でも桁数が最大値が作れる場合はOK
if (dp[remain - k] == dp[remain] - 1) {
// OK場合でもMはできる限り大きい数にする
answer = A[i];
use = k;
}
}
}
// マッチの数を減らす
remain -= use;
cout << answer;
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;
int main() {
fast_io
int n, t;
cin >> n >> t;
vector<P> ti_ta(n);
rep(i,n) cin >> ti_ta[i].first >> ti_ta[i].second;
sort(ti_ta.begin(), ti_ta.end());
vector<vector<int>> dp(n, vector<int>(t+1, 0));
rep(i,t+1) {
if (i >= ti_ta[0].first) dp[0][i] = ti_ta[0].second;
}
int ans = 0;
rep(i,n) {
rep(ti,t+1) {
if(i == n-1) break;
// i+1番目の食べ物を食べるときにi番目までの食べ物を食べるのにかかる時間
int nti = ti - ti_ta[i+1].first;
// もしi+1番目の食べ物を食べると制限時間内に食べ終わらないとき
if (nti < 0) dp[i+1][ti] = dp[i][ti];
// もしi+1番目の食べ物を食べないほうがいいときor食べたほうがいいとき
else dp[i+1][ti] = max(dp[i][ti], dp[i][nti] + ti_ta[i+1].second);
}
int ans_tmp;
if (i == 0) ans_tmp = ti_ta[0].second;
else ans_tmp = dp[i-1][t-1] + ti_ta[i].second;
ans = max(ans, ans_tmp);
}
cout << ans << endl;
return 0;
} | 0 |
//...Bismillahir Rahmanir Rahim...
// Code by Asad Bin Saber
#include <bits/stdc++.h>
using namespace std;
// typedefs...
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
// constants...
const double PI = acos(-1);
const int Mod = 1e9+7; // 998244353;
const int MXS = 2e5+5;
const int MXI = 1e9+5;
const ll MXL = 1e15+5;
const int INF = 1e5+5;
// defines...
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
// chess moves...
// int dx[] = {+0, +0, -1, +1}; ///Up-down, Left-Right
// int dy[] = {+1, -1, +0, +0};
// int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
// int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1};
// int dx[] = {-2, -2, -1, -1, 1, 1, 2, 2}; ///Knight's Move
// int dy[] = {-1, 1, -2, 2, -2, 2, -1, 1};
// structs...
struct hash_pair {
template <class T1, class T2>
size_t operator()(const pair<T1, T2>& p) const
{
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};
// functions...
ll gcd(ll a, ll b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
ll lcm(ll a, ll b)
{
return (a/gcd(a, b)*b);
}
ll comb(ll a, ll b, ll M)
{
ll x = max(a-b, b), ans=1;
for(ll K=a, L=1; K>=x+1; K--, L++){
ans *= K;
ans /= L;
}
return ans % M;
}
void task()
{
//code here...
int n, ans, mn = MXI;
cin >> n;
int ara[n];
for(int K=0; K<n; K++) cin >> ara[K];
ans = n;
for(int K=0; K<n; K++){
mn = min(mn, ara[K]);
if(mn<ara[K]) ans--;
}
cout << ans << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
task();
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ft ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pi pair<int,int>
#define pb push_back
#define F first
#define S second
#define B begin()
#define E end()
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;
int main()
{
ft
ll t,i,j,n,m,l=INT_MAX,r=0;
cin>>n;
for(i=0;i<n;i++)
{
cin>>m;
if(m<=l)
{
l=m;
r++;
}
}
cout<<r<<"\n";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#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, n, m) for(int (i) = (n); (i) < (m); ++(i))
constexpr int INF = 1e9;
// constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;
int main(){
string S;
cin >> S;
ll ans = 0;
int N = S.size();
bool flag = false;
REPR(i, N-1){
int d = S[i] - '0';
if(flag) d++;
flag = false;
if(d < 5){
ans += d;
}
else if(d > 5){
ans += 10 - d;
flag = true;
}
else{
if(i != 0 && S[i-1] >= '5'){
ans += d;
flag = true;
}
else{
ans += d;
}
}
}
if(flag) ans++;
cout << ans << endl;
return 0;
} | #include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 1000005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
string s;
int dp[N][2];
int calc(int idx,int carry)
{
if(idx == s.length())
return carry;
if(dp[idx][carry]!=-1)return dp[idx][carry];
int ans=1e9;
int val=s[idx]-'0'+carry;
if(val<10)ans=min(ans,calc(idx+1,0)+val);
ans=min(ans,calc(idx+1,1)+(10 - val));
return dp[idx][carry]=ans;
}
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>s;
reverse(all(s));
memset(dp,-1,sizeof(dp));
cout<<calc(0,0)<<endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll N,M;
cin >> N >> M;
vector<ll> A(N+M-1),B(N+M-1),G[N],in_cnt(N,0);
vector<bool> is_root(N,true);
for(int i=0;i<N+M-1;i++){
cin >> A[i] >> B[i];
A[i]--,B[i]--;
G[A[i]].push_back(B[i]);
is_root[B[i]] = false;
in_cnt[B[i]]++;
}
int root;
for(int i=0;i<N-1;i++){
if(is_root[i]) root = i;
}
vector<ll> pa(N,-1);
queue<ll> q;
q.push(root);
while(q.size()){
ll from = q.front();
q.pop();
for(auto to:G[from]){
pa[to] = from;
in_cnt[to]--;
if(in_cnt[to] == 0){
q.push(to);
}
}
}
pa[root] = -1;
for(auto x:pa){
cout << x+1 << "\n";
}
}
| #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif
void init() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
}
const int N = 1e5+23;
vector<int> g[N], ans;
bool bio[N];
int parent[N];
void dfs(int u) {
bio[u] = true;
for (int v: g[u]) {
if (bio[v]) continue;
dfs(v);
}
ans.push_back(u);
}
void solve() {
int n, m; scanf("%d%d", &n, &m);
for (int u, v, i = 0; i < n-1+m; ++i) {
scanf("%d%d", &u, &v);
g[u].push_back(v);
}
for (int i = 1; i <= n; ++i) {
if (bio[i]) continue;
dfs(i);
}
for (int u: ans)
for (int v: g[u])
if (!parent[v])
parent[v] = u;
for (int i = 1; i <= n; ++i) printf("%d\n", parent[i]);
}
int main() {
init();
int t = 1; //scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
inline void prep ()
{
cin.tie (0);
cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
// 32 mil = ~1 sec
long long mymod(long long num){
if (num< 0 && !(num%mod == 0)){
if (mod == 1){
return 0;
}
return mod-abs(num)%mod;
}else{
return num%mod;
}
}
/*string sentence = And I feel fine...;
istringstream iss(sentence);
*/
double eps = .000000001;
long long modpow(long long x, long long n) {
if (n == 0) return 1%mod;
long long u = modpow(x,n/2);
u = (u*u)%mod;
if (n%2 == 1) u = (u*x)%mod;
return u;
}
long long n, a, b, c, d;
bool memoo[1001][1001];
long long memo[1001][1001];
long long shortmod(long long num){
if (num >= mod){
num -= mod;
}
return num;
}
void EE(int a, int b, int& x, int& y)
{
if(a%b == 0)
{
x=0;
y=1;
return;
}
EE(b,a%b,x,y);
int temp = x;
x = y;
y = temp - y*(a/b);
}
int inverse(int a)
{
int x,y;
EE(a,mod,x,y);
if(x<0) x += mod;
return x;
}
long long facts[1001];
long long invfacts[1001];
long long inverses[1001];
long long func(int left, int grpsze){
if (left == 0 && grpsze > b){
return 1;
}
if (left < 0 || grpsze > b){
return 0;
}
if (memoo[left][grpsze]){
return memo[left][grpsze];
}
long long res = 0;
long long choose = 1;
int templeft = left;
templeft -= grpsze*(c-1);
choose *= modpow(invfacts[grpsze], c-1);
choose %= mod;
choose *= invfacts[c-1];
choose %= mod;
for (int i=c; i <= d; i++){
if (templeft <= 0){
break;
}
choose *= invfacts[grpsze];
choose %= mod;
choose *= inverses[i];
choose %= mod;
templeft -= grpsze;
res += (choose*func(templeft, grpsze+1))%mod;
res = shortmod(res);
}
res += func(left, grpsze+1);
res = shortmod(res);
memoo[left][grpsze] = true;
memo[left][grpsze] = res;
return res;
}
int main ()
{
prep();
cin >> n >> a >> b >> c >> d;
long long cur = 1;
for (int i=1; i<=1000; i++){
cur *= i;
cur %= mod;
facts[i] = cur;
}
facts[0] = 1;
invfacts[0] = 1;
inverses[0] = 1;
cur = 1;
for (int i=1; i<=1000; i++){
cur *= inverse(i);
cur %= mod;
invfacts[i] = cur;
}
for (int i=1; i<=1000; i++){
inverses[i] = inverse(i);
}
cout << (facts[n]*func(n, a))%mod;
return 0;
}
| #include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<list>
#include <cstring>
#include <functional>
//#include<unordered_map>
//#include<unordered_set>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF ((Int)1<<60)
#define EPS (1e-10)
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define RREP(i,n) for(int i=1; i<=(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
typedef long long Int;
typedef pair<Int, Int> P;
typedef vector<double> vec;
typedef vector<vec> mat;
const int N = 100005;
//////////////////////////////
void add(int64_t& a, int64_t b) {
a = (a + b) % MOD;
}
void mul(int64_t& a, int64_t b) {
a = a*b % MOD;
}
vector<int64_t> fact, seq_inv, fact_inv;
void create_fact_mod(int num) {
fact[0] = fact[1] = 1;
for (int i = 2; i <= num; i++) fact[i] = fact[i - 1] * i % MOD;
}
void create_seq_inv_mod(int num) {
seq_inv[0] = seq_inv[1] = 1;
for (int i = 2; i <= num; i++) seq_inv[i] = (MOD - MOD / i) * seq_inv[MOD%i] % MOD;
}
void create_fact_inv_mod(int num) {
fact_inv[0] = fact_inv[1] = 1;
for (int i = 2; i <= num; i++) fact_inv[i] = fact_inv[i - 1] * seq_inv[i] % MOD;
}
void create_mod_tables(int num) {
fact.resize(num + 1);
seq_inv.resize(num + 1);
fact_inv.resize(num + 1);
create_fact_mod(num);
create_seq_inv_mod(num);
create_fact_inv_mod(num);
}
int64_t comb_mod(int n, int k) {
return fact[n] * fact_inv[n - k] % MOD * fact_inv[k] % MOD;
}
int64_t perm_mod(int n, int k) {
return fact[n] * fact_inv[n - k] % MOD;
}
int64_t power_mod(int64_t num, int64_t power) {
int64_t prod = 1;
num %= MOD;
while (power > 0) {
if (power & 1) prod = prod * num % MOD;
num = num * num % MOD;
power >>= 1;
}
return prod;
}
int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y) {
int64_t d = a;
if (b != 0) {
d = extgcd(b, a%b, y, x);
y -= (a / b) * x;
}
else {
x = 1; y = 0;
}
return d;
}
int64_t inv_mod(int64_t a) {
int64_t x, y;
extgcd(a, MOD, x, y);
return (MOD + x%MOD) % MOD;
}
void solve()
{
int M, A, B, C, D;
cin >> M >> A >> B >> C >> D;
create_mod_tables(1000);
static int64_t dp[1001][1001];
dp[A - 1][0] = 1;
for (int i = A; i <= B; i++)
for (int j = 0; j <= M; j++) {
add(dp[i][j], dp[i - 1][j]);
int n = M - j;
int64_t pw = power_mod(fact_inv[i], C);
for (int k = C; k <= D && i*k <= n; k++) {
int64_t res = comb_mod(n, i*k) * fact[i*k] % MOD * pw % MOD * fact_inv[k] % MOD;
mul(pw, fact_inv[i]);
add(dp[i][j + i*k], dp[i - 1][j] * res);
}
}
cout << dp[B][M] << endl;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13);
solve();
return 0;
}
| 1 |
#include <iostream>
using ll = long long;
using namespace std;
/* initialize */
int temp, n;
/* main */
int partition(int A[],int p,int r){
int x = A[r];
int i = p-1;
for (int j = p; j < r; j++) {
if (A[j] <= x){
i++;
temp = A[i];
A[i] = A[j];
A[j] = temp;
}
}
temp = A[i+1];
A[i+1] = A[r];
A[r] = temp;
return i+1;
}
int main() {
int q;
cin >> n;
int A[100000];
for (int j = 0; j < n; ++j) {
scanf("%d", &A[j]);
}
q = partition(A, 0, n-1);
for (int k = 0; k < n; k++) {
if(k) printf(" ");
if (k == q) printf("[%d]", A[k]);
else printf("%d", A[k]);
}
cout << "\n";
return 0;
}
| #include <iostream>
using namespace std;
const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;
int main(){
int N;
cin >> N;
int A[N];
for(int i=0; i<N; i++){
cin >> A[i];
}
int B[N];
long ans = 0;
for(int i=0; i<N; i++){
if(i-A[i]<0){
cout << -1 << endl;
return 0;
}
B[i] = i - A[i];
}
for(int i=1; i<N; i++){
if(B[i]<B[i-1]) {
cout << -1 << endl;
return 0;
}
if(B[i-1]<B[i])ans += (i-1) - B[i-1];
}
ans += (N-1)-B[N-1];
cout << ans << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
long long dp[2][2000000],cnt[2000000]={},z=0LL;
long long modpow(int a,int b)
{
if (b==0)
{
return 1LL;
}
long long ans=modpow(a,b/2);
ans*=ans;
ans%=mod;
if (b%2==1)
{
ans*=a;
ans%=mod;
}
return ans;
}
int main(int argc, char const *argv[])
{
int n;
cin>>n;
int a[n];
for (int i = 0; i < n; ++i)
{
cin>>a[i];
}
int s[n];
s[0]=a[0];
for (int i = 1; i < n; ++i)
{
s[i]=s[i-1]^a[i];
}
for (int i = 0; i < 2000000; ++i)
{
dp[0][i]=1LL;
}
for (int i = 0; i < n; ++i)
{
if (s[i]==0)
{
++z;
}
dp[0][s[i]]+=dp[1][s[i]]*(z-cnt[s[i]])%mod;
dp[0][s[i]]%=mod;
dp[1][s[i]]+=dp[0][s[i]];
dp[1][s[i]]%=mod;
cnt[s[i]]=z;
}
if (s[n-1]!=0)
{
cout<<dp[0][s[n-1]]<<endl;
}
else
{
long long ans=modpow(2,z-1);
for (int i = 1; i < 2000000; ++i)
{
ans+=dp[1][i];
ans%=mod;
}
cout<<ans<<endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int charToInt(char c){
char zero_num = '0';
return (int)c - (int)zero_num;
}
signed main(){
int MOD = pow(10,9)+7;
int H, W, K; cin>>H>>W>>K;
if(W==1){
cout<<1<<endl;
return 0;
}
// 一列における棒の組み合わせをbit全探索で先に作っておく
// [[],[0],[1],[0,2],...]
// これの意味は0: 0-1の間, 1: 1-2の間に棒をおく、という感じである。
vector<vector<int>> combi_list;
for(int i=0;i< (1<<(W-1));i++){
bitset<7> s(i);
vec_int temp_combi;
for(int i=0;i<W-1;i++){
if(s[i]==1){
temp_combi.push_back(i);
}
}
// 作ったものが合法かをチェックする
int prev=-100;
int flag = 0;
for(auto a: temp_combi){
if(a-prev==1){
flag=1;
break;
}
prev=a;
}
if(flag==1)continue;
combi_list.push_back(temp_combi);
}
/*
for(auto aa: combi_list){
cout<<"aa"<<endl;
for(auto bb: aa){
cout<<bb<<endl;
}
}
*/
int DP[H+1][W];
rep(i,H+1){
rep(j,W){
DP[i][j]=0;
}
}
DP[0][0] = 1;
for(int i=1;i<H+1;i++){
for(int j=0;j<W;j++){
// 最初にそのまま落ちてくるパターン
int pattern = 0;
for(auto aa: combi_list){
int flag = 1;
for(auto bb: aa){
if(bb==j||bb==j-1){
flag=0;
break;
}
}
if(flag==0)continue;
pattern++;
}
DP[i][j] += DP[i-1][j]*pattern;
// 一個左の棒から落ちてくるパターン
pattern = 0;
for(auto aa: combi_list){
int flag = 0;
for(auto bb: aa){
if(bb==j-1){
flag=1;
break;
}
}
if(flag==0)continue;
pattern++;
}
if(j>0){
DP[i][j] += DP[i-1][j-1]*pattern;
}
// 一個右の棒から落ちてくるパターン
pattern = 0;
for(auto aa: combi_list){
int flag = 0;
for(auto bb: aa){
if(bb==j){
flag=1;
break;
}
}
if(flag==0)continue;
pattern++;
}
if(j<W-1){
DP[i][j] += DP[i-1][j+1]*pattern;
}
DP[i][j] = DP[i][j]%MOD;
}
}
cout<<DP[H][K-1]<<endl;
return 0;
} | 0 |
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
char c=getchar();bool f=0;x=0;
while(!isdigit(c)) f|=c=='-',c=getchar();
while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
read(x);read(a...);
}
template<class t> inline void write(t x){
if(x<0) putchar('-'),write(-x);
else{if(x>9) write(x/10);putchar('0'+x%10);}
}
const int N=1e5+5;
int n,m,p,a[N],b[N],ans=1e9;
signed main(){
read(n,m,p);
for(int i=1;i<=n;i++) read(a[i]);
for(int i=1;i<=m;i++) read(b[i]);
ans=*min_element(a+1,a+1+n)+*min_element(b+1,b+1+n);
while(p--){
int x,y,z;
read(x,y,z);
ans=min(ans,a[x]+b[y]-z);
}
write(ans);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;
const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()
int A, B, M, x, y, c, a[mxN], b[mxN];
void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
int main() {
fast();
cin >> A >> B >> M;
int mnA = mxN, mnB = mxN;
for (int i = 0; i < A; ++i) {
cin >> a[i];
mnA = min(a[i], mnA);
}
for (int i = 0; i < B; ++i) {
cin >> b[i];
mnB = min(b[i], mnB);
}
int mn = mxN;
for (int i = 0; i < M; ++i) {
cin >> x >> y >> c;
mn = min((a[x - 1] + b[y - 1]) - c, mn);
}
if (mnB + mnA < mn)
cout << mnB + mnA;
else
cout << mn;
return 0;
}
| 1 |
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>
// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
int main(){
int N;
int M;
int Q;
cin >> N >> M >> Q;
int l;
int r;
vector<vector<int>> x(N, vector<int>(N, 0));
vector<vector<int>> c(N, vector<int>(N, 0));
vector<int> p(Q);
vector<int> q(Q);
int tmp_p;
int tmp_q;
for(int i=0; i<M; i++){
cin >> l >> r;
l--;
r--;
x[l][r]++;
}
for(int i=0; i<Q; i++){
cin >> tmp_p >> tmp_q;
tmp_p--;
tmp_q--;
p[i]=tmp_p;
q[i]=tmp_q;
}
for(int i=0; i<N; i++){
for(int j=i; j<N; j++){
c[i][j]+=x[i][j];
if(j!=i){
c[i][j]+=c[i][j-1];
}
}
}
for(int i=0; i<Q; i++){
int ans=0;
for(int j=p[i]; j<=q[i]; j++){
ans+=c[j][q[i]];
}
cout << ans << endl;
}
return 0;
}
| #include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;
// typedef long long int
typedef long long int ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
// typedef pair<ll,ll> pll;
const int modi = 1e9+7;
const int mxn = 1e5+10;
vi adj[mxn];
void dfs(int u ,int p, int* dis, int d = 0){
dis[u] = d;
for(auto v:adj[u]){
if(v==p)continue;
dfs(v,u,dis,d+1);
}
}
void solve(){
int n;
cin >> n;
int t,a; // t is going away a is coming near
cin >> t >> a;
--t,--a;
for(int i =0;i<n-1;i++){
int u ,v;
cin >> u >> v;
--u,--v;
adj[u].pb(v);
adj[v].pb(u);
}
vector<int> leaves;
for(int i =0;i<n;i++)
{
if(adj[i].size()==1){
leaves.pb(i);
}
}
int dt[n],da[n];
dfs(t,-1,dt);
dfs(a,-1,da);
int ans =0;
for(auto e:leaves){
// cout << e << " " << endl;
if(dt[e]>da[e])
continue;
ans = max(ans,da[e]-1);
}
cout << ans << endl;
}
int main(){
fast;
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
// int t;cin >> t;while(t--)
solve();
}
| 0 |
#include <iostream>
#include <cstdlib>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
using namespace std;
struct edge {int to, cost;};
typedef int Vertex;
typedef pair<int, Vertex> P;
typedef vector<vector<edge>> Graph;
Graph make_graph(const int V, const int E){
Graph G(V);
for(int i = 0; i < E; ++i){
int s,t,d; cin >> s >> t >> d;
G[s].emplace_back(edge{t, d});
}
return G;
}
// ???????????´???????????§??????????????¢????±???????
/*int dijkstra(Graph &G, Vertex s, Vertex t){
vector<int> d(G.size(), INF);
d[s] = 0;
priority_queue<P, vector<P>, greater<P>> q;
q.push(make_pair(0, s));
while(!q.empty()){
int cost = q.top().first;
Vertex current = q.top().second;
q.pop();
if(t == current) break;
if(d[current] < cost) continue;
for(auto &e : G[current]){
if(d[e.to] > d[current] + e.cost){
d[e.to] = d[current] + e.cost;
q.push(make_pair(d[e.to], e.to));
}
}
}
return d[t];
}*/
vector<int> dijkstra(Graph &G, Vertex s){
vector<int> d(G.size(), INT_MAX);
d[s] = 0;
priority_queue<P, vector<P>, greater<P>> q;
q.push(make_pair(0, s));
while(!q.empty()){
int cost = q.top().first;
Vertex current = q.top().second;
q.pop();
if(d[current] < cost) continue;
for(auto &e : G[current]){
if(d[e.to] > d[current] + e.cost){
d[e.to] = d[current] + e.cost;
q.push(make_pair(d[e.to], e.to));
}
}
}
return d;
}
int main(){
int V, E, r; cin >> V >> E >> r;
Graph G = make_graph(V, E);
vector<int> d = dijkstra(G, r);
for(int v = 0; v < V; ++v){
//int dist = dijkstra(G, r, v);
//if(dist == INF) cout << "INF\n";
//else cout << dist << endl;
if(d[v] < INT_MAX) cout << d[v] << endl;
else cout << "INF\n";
}
return EXIT_SUCCESS;
} | #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
int k;
int m=0;
x=0;
for(;;){
k = getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
inline void wt_L(char a){
putchar_unlocked(a);
}
inline void wt_L(int x){
int s=0;
int m=0;
char f[10];
if(x<0){
m=1;
x=-x;
}
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
if(m){
putchar_unlocked('-');
}
while(s--){
putchar_unlocked(f[s]+'0');
}
}
int main(){
int N;
int K;
rd(N);
rd(K);
wt_L(N-K+1);
wt_L('\n');
return 0;
}
// cLay varsion 20191123-1
// --- original code ---
// {
// int N, K;
// rd(N,K);
// wt(N-K+1);
// }
| 0 |
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
string s;
cin >> s;
vector<int> sumW(n + 1, 0);
REP(i, n) {
if (s[i] == 'W') sumW[i + 1] = sumW[i] + 1;
else sumW[i + 1] = sumW[i];
}
vector<int> sumE(n + 1, 0);
REP(i, n) {
if (s[i] == 'E') sumE[i + 1] = sumE[i] + 1;
else sumE[i + 1] = sumE[i];
}
int mini = INT_MAX;
REP(i, n + 1) {
int toRight = sumW[i];
int toLeft = sumE[n] - sumE[i];
mini = min(mini, toRight + toLeft);
}
cout << mini << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
//入力
int n;
string s; //左が縦の行数、右が横の列数(念のため、余裕をもって+1)
int num_e = 0; //西向きの合計人数
int num_w = 0; //東向きの合計人数
cin >> n >> s;
for (int i=0; i<n; i++) {
if (s[i]=='E') num_e++;
if (s[i]=='W') num_w++;
}
int ans = 300000;
int change_w = 0; //リーダーの西で向きを変える必要のある人数。西の端から一個ずつ東へズレてカウントしていく。
int change_e = num_e; //リーダーの東で向きを変える必要のある人数(リーダーの西側に区切り線を置いてる感じ)
for (int i=0; i<n; i++) {
if (s[i]=='E') change_e--; //リーダーが'E'の場合、東側から'E'が一人減る
if (change_e + change_w <= ans) ans = change_e + change_w;
if (s[i]=='W') change_w++; //リーダーが'W'の場合、西側に'W'が一人増える
}
cout << ans << endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif
namespace IO {
static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;
inline char myGetchar() {
static char buf[IN_BUF], *ps = buf, *pt = buf;
if (ps == pt) {
ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
}
return ps == pt ? EOF : *ps++;
}
template<typename T>
inline bool read(T &x) {
bool op = 0;
char ch = getchar();
x = 0;
for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
op ^= (ch == '-');
}
if (ch == EOF) {
return false;
}
for (; isdigit(ch); ch = getchar()) {
x = x * 10 + (ch ^ '0');
}
if (op) {
x = -x;
}
return true;
}
inline int readStr(char *s) {
int n = 0;
char ch = getchar();
for (; isspace(ch) && ch != EOF; ch = getchar())
;
for (; !isspace(ch) && ch != EOF; ch = getchar()) {
s[n++] = ch;
}
s[n] = '\0';
return n;
}
inline void myPutchar(char x) {
static char pbuf[OUT_BUF], *pp = pbuf;
struct _flusher {
~_flusher() {
fwrite(pbuf, 1, pp - pbuf, stdout);
}
};
static _flusher outputFlusher;
if (pp == pbuf + OUT_BUF) {
fwrite(pbuf, 1, OUT_BUF, stdout);
pp = pbuf;
}
*pp++ = x;
}
template<typename T>
inline void print_(T x) {
if (x == 0) {
putchar('0');
return;
}
static int num[40];
if (x < 0) {
putchar('-');
x = -x;
}
for (*num = 0; x; x /= 10) {
num[++*num] = x % 10;
}
while (*num){
putchar(num[*num] ^ '0');
--*num;
}
}
template<typename T>
inline void print(T x, char ch = '\n') {
print_(x);
putchar(ch);
}
inline void printStr_(const char *s, int n = -1) {
if (n == -1) {
n = strlen(s);
}
for (int i = 0; i < n; ++i) {
putchar(s[i]);
}
}
inline void printStr(const char *s, int n = -1, char ch = '\n') {
printStr_(s, n);
putchar(ch);
}
}
using namespace IO;
const int N = 2500005, P = 998244353;
int n, m;
int fac[N], inv[N];
int qpow(int a, int b) {
int s = 1;
for (; b; b >>= 1) {
if (b & 1) {
s = 1ll * s * a % P;
}
a = 1ll * a * a % P;
}
return s;
}
void init(int n) {
fac[0] = 1;
for (int i = 1; i <= n; ++i) {
fac[i] = 1ll * fac[i - 1] * i % P;
}
inv[n] = qpow(fac[n], P - 2);
for (int i = n; i; --i) {
inv[i - 1] = 1ll * inv[i] * i % P;
}
}
int C(int n, int m) {
if (m < 0 || m > n) {
return 0;
}
return 1ll * fac[n] * inv[m] % P * inv[n - m] % P;
}
int main() {
read(n), read(m);
init(n + 3 * m);
int ans = 0;
for (int i = m & 1; i <= n && i <= m; i += 2) {
int S = (3 * m - i) >> 1, s = 0;
for (int j = 0; j <= i && m * j <= S; ++j) {
for (int k = 0; k <= n - i && m * j + (m + 1) * k <= S; ++k) {
int t = 1ll * C(i, j) * C(n - i, k) % P * C(S - m * j - (m + 1) * k + n - 1, n - 1) % P;
if ((j + k) & 1) {
s = (s + P - t) % P;
} else {
s = (s + t) % P;
}
}
}
ans = (ans + 1ll * s * C(n, i)) % P;
}
print(ans);
}
| #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 998244353
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 2500100
long long kai[N];
long long rkai[N];
long long xx[30];
int yy[30];
void kaiz(void) {
kai[0] = 1;
f(i, N - 1) {
kai[i + 1] = kai[i] * (i + 1);
kai[i + 1] = kai[i + 1] % MOD;
}
int x = MOD - 2;
f(i, 30) {
if (x % 2 == 1)yy[i] = 1;
else yy[i] = 0;
x = x / 2;
}
f(i, N) {
xx[0] = kai[i];
f(j, 29) {
xx[j + 1] = xx[j] * xx[j];
xx[j + 1] = xx[j + 1] % MOD;
}
rkai[i] = 1;
f(j, 30) {
if (yy[j] == 1) {
rkai[i] = rkai[i] * xx[j];
rkai[i] = rkai[i] % MOD;
}
}
}
}
long long ni(long long x, long long y) {
if (x < 0 || y<0 || y>x)return 0;
long long re = kai[x];
re = re * rkai[x - y];
re = re % MOD;
re = re * rkai[y];
re = re % MOD;
return re;
}
int main() {
long long q, n, m, k;
long long x, y, z;
long long s, ans;
bool v = true;
ans = 0;
kaiz();
scanf("%lld %lld", &n, &m);
k = m % 2;
s = 0;
for (long long i = 0; i <= ((m - k) / 2); i++) {
x = ni(n - 2 + i, n - 2);
s = (s + x) % MOD;
}
ans = 0;
while (k <= m&&k<=n) {
x = (3 * m) - k;
x=x/2;
x = ni(x + n - 1, n - 1);
y = (n * s) % MOD;
x = (x - y + MOD) % MOD;
y = (m - k) / 2;
y = ni(n + y - 2, n - 2);
y = (y*(n - k)) % MOD;
x = (x + y) % MOD;
z = ni(n, k);
z = (z * x) % MOD;
ans = (ans + z) % MOD;
x = (m - k) / 2;
x = ni(x + n - 2, n - 2);
s = (s - x + MOD) % MOD;
k += 2;
}
printf("%lld\n", ans);
return 0;
} | 1 |
#include <stdio.h>
int main() {
int H, W, N;
scanf("%d %d %d", &H, &W, &N);
if(W >= H){
for(int i = 1; i <= H; i++) {
if (W * i >= N) {
printf("%d", i);
break;
}
}
}
else {
for(int i = 1; i <= W; i++){
if (H * i >= N) {
printf("%d", i);
break;
}
}
}
return 0;
} | #include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
using namespace std;
int main()
{
int H, W, N;
cin >> H >> W >> N;
if (H >= W) {
if (N % H == 0) {
cout << N / H << endl;
}
else {
cout << N / H + 1 << endl;
}
}
else {
if (N % W == 0) {
cout << N / W << endl;
}
else {
cout << N / W + 1 << endl;
}
}
}
| 1 |
#include<stdio.h>
int main()
{
int a = 0, b = 0, x, y, n, i;
for (;;){
scanf("%d", &n);
if (n == 0)
break;
for (i = 0; i < n; i++){
scanf("%d %d", &x, &y);
if (x > y){
a += x + y;
}
else if (x == y){
a += x;
b += y;
}
else
b += x + y;
}
printf("%d %d\n", a, b);
a = 0;
b = 0;
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n;
while(1){
cin >> n;
if(n == 0) break;
int num[10000][2] = {};
int score[2] = {};
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < 2; ++j){
cin >> num[i][j];
}
if (num[i][0] > num[i][1])
{
score[0] += num[i][0] + num[i][1];
} else if (num[i][0] == num[i][1])
{
score[0] += num[i][0];
score[1] += num[i][1];
} else{
score[1] += num[i][0] + num[i][1];
}
}
cout << score[0] << " " << score[1] << endl;
}
return 0;
} | 1 |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define ld long double
#define ordered_set tree < ll , null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update >
//added two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set]
//(2)set.order_of_key(k)[count of elements strictly less than k]
typedef vector< int > vi;
typedef vector<long long> lvi;
typedef vector< vector<int> > vvi;
typedef vector< vector<long long> > lvvi;
typedef pair< int,int > ii;
typedef pair< long long,long long > lii;
typedef vector<pair<int,int>> vii;
typedef vector<pair<long long,long long>> lvii;
typedef vector<vector<pair<int,int>>> vvii;
typedef vector<vector<pair<long long,long long>>> lvvii;
typedef vector<bool> vb;
// #ifdef ONLINE_JUDGE
// #define endl '\n'
// #endif
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)//remember i is an iterator
#define tc(t) int (t); cin>>(t);while((t)--)
#define ff first
#define ss second
#ifdef ONLINE_JUDGE
#define error(args...) 0
#else
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#endif
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr <<"[ "<< *it << " = " << a << " ]"<< endl;
err(++it, args...);
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
const long long mod = 1e9 + 7;
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
long long mos() { return 0LL; }
template<typename T, typename... Args>
T mos(T a, Args... args) { return ((a + mos(args...))%mod + mod)%mod; }
long long mop() { return 1LL; }
template<typename T, typename... Args>
T mop(T a, Args... args) { return (a*mop(args...))%mod; }
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
cin>>n>>k;
vi a(n);
for (int i = 0; i < n; ++i)
{
cin>>a[i];
}
int k1=k;
while(k>0)
{
// vi b(n);
vi suffix(n+1,0);
for (int i = 0; i < n; ++i)
{
// for(int j=max(0,i-a[i]);j<=min(n-1,i+a[i]);j++)
// {
// b[j]++;
// }
int low = max(0,i-a[i]),high = 1+min(n-1,i+a[i]);
suffix[low]++;
suffix[high]--;
// error(i,low,high);
}
a[0]=suffix[0];
for(int i=1;i<n;i++)
{
suffix[i]+=suffix[i-1];
a[i]=suffix[i];
}
k--;
bool ok=true;
for (int i = 0; i < n; ++i)
{
// cout<<a[i]<<" ";
if(a[i]!=n) ok=false;
}
// cout<<endl;
if(ok) break;
}
// cout<<"steps: "<<k1-k<<endl;
for (int i = 0; i < n; ++i)
{
cout<<a[i]<<" ";
}
cout<<endl;
return 0;
}
// WA
// 1. overflow
// 2. re-initialize global variables for every test case.
// 3. edge cases like n=1
// Run time error
// 1. division by zero.
// 2. array bounds.
// TLE
// 1. uncomment that #define endl '\n' line | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i=0; i<(int64_t)(n); i++)
#define all(v) v.begin(), v.end()
//c
int main(){
int n, k;cin >> n >> k;
vector<vector<int>> a(51, vector<int>(n));
rep(i, n) cin >> a[0][i];
rep(i, k){
vector<int> memo(n+1);
rep(j, n){
int min, max;
min=j-a[i][j];
max=j+1+a[i][j];
if(min<0) min=0;
if(max>n) max=n;
memo[min]++;
memo[max]--;
}
int cnt=0;
rep(j, n){
cnt+=memo[j];
a[i+1][j]=cnt;
}
bool fin=true;
rep(j, n){
if(a[i][j]!=a[i+1][j]) fin=false;
}
if(fin){
k=i+1;
break;
}
}
rep(j, n-1){
cout << a[k][j] << " ";
}
cout << a[k][n-1] << endl;
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)
const ll MOD = 1000000007;
const ll INF = (ll)1e15;
class UnionFind
{
public:
UnionFind(int n)
: mN(n)
{
REP(i, n)
{
mNodeTbl.push_back(i);
mRankTbl.push_back(0);
}
}
int find(int x)
{
if (x == mNodeTbl[x])
return x;
return mNodeTbl[x] = find(mNodeTbl[x]);
}
bool same(int x, int y)
{
return find(x) == find(y);
}
void unit(int x, int y)
{
x = find(x);
y = find(y);
if (x == y)
return;
if (mRankTbl[x] < mRankTbl[y])
{
mNodeTbl[x] = y;
}
else
{
mNodeTbl[y] = x;
if (mRankTbl[x] == mRankTbl[y])
mRankTbl[x]++;
}
}
private:
int mN;
vector<int> mNodeTbl;
vector<int> mRankTbl;
};
struct grid
{
pll g;
int index;
};
vector<grid> G,X,Y;
ll len(pll a)
{
return std::min(abs(G[a.first].g.first - G[a.second].g.first), abs(G[a.first].g.second - G[a.second].g.second));
}
int main()
{
ll N;
cin >> N;
UnionFind uf(N);
G.resize(N);
REP(i, N)
{
cin >> G[i].g.first >> G[i].g.second;
G[i].index = i;
}
X=G;
Y=G;
priority_queue<pll, vector<pll>, function<bool(pll, pll)>> q([](pll a, pll b) { return len(a) > len(b); });
sort(X.begin(),X.end(), [](grid a, grid b) { return a.g.first > b.g.first; });
REP(i, N - 1)
{
q.push(pll(X[i].index, X[i + 1].index));
}
sort(Y.begin(),Y.end(), [](grid a, grid b) { return a.g.second > b.g.second; });
REP(i, N - 1)
{
q.push(pll(Y[i].index, Y[i + 1].index));
}
ll s = 0;
while (!q.empty())
{
pll t = q.top();
q.pop();
if (uf.same(t.first, t.second))
continue;
uf.unit(t.first, t.second);
s += len(t);
}
cout << s << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
int N, a, b, c, d, ans = 0;
cin >> N;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> A, B;
for (int i = 0; i < N; i++)
{
cin >> a >> b;
A.push(make_pair(a, b));
}
for (int i = 0; i < N; i++)
{
cin >> c >> d;
B.push(make_pair(c, d));
}
priority_queue<pair<int, int>> ayx;
for (int x = 0; x < 2 * N; x++)
{
if (B.top().first != x)
continue;
int bx, by;
tie(bx, by) = B.top();
B.pop();
while (!A.empty() && A.top().first < x)
{
ayx.emplace(make_pair(A.top().second, A.top().first));
A.pop();
}
queue<pair<int, int>> tmp;
while (!ayx.empty())
{
if (ayx.top().second < bx && ayx.top().first < by)
{
ayx.pop();
ans++;
break;
}
else
{
tmp.push(ayx.top());
ayx.pop();
}
}
while (!tmp.empty())
{
ayx.push(tmp.front());
tmp.pop();
}
}
cout << ans << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
//#define int long long
//signed main(){
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int h,w;
cin >> h >> w;
vector<bool> a(h*w,false);
queue<int> que;
for(int i = 0; i < h; i++) {
string tmp;
cin >> tmp;
for(int j = 0; j < w; j++) {
int idx=i*w+j;
if(tmp[j]=='#'){
a[idx]=true;
que.push(idx);
}
}
}
int cnt=0;
int ans=0;
while(cnt<h*w) {
int n=que.size();
cnt+=n;
for(int i = 0; i < n; i++) {
int idx=que.front();
int add[4]={1,-1,w,-w};
for(int j = 0; j < 4; j++) {
int t=idx+add[j];
int r=idx/w+add[j]/w;
int c=idx%w+add[j]%w;
if(r<0||r>=h||c<0||c>=w||a[t]==true) continue;
a[t]=true;
que.push(t);
}
que.pop();
}
ans++;
}
cout << ans-1 << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using ll = long long;
int main(){
int D, G, p[11], c[11];
cin >> D >> G;
for(int i = 0; i < D; ++i){
cin >> p[i] >> c[i];
}
int ans = 1e9;
rep(tmp, 1<<D){
int scr = 0, num = 0, max_id = -1;
rep(i,D){
if((tmp>>i) & 1){
scr += 100 * (i+1) * p[i] + c[i];
num += p[i];
}else{
max_id = i;
}
}
if(scr < G){
int sum = 100 * (max_id + 1);
int rmn = (G - scr + sum - 1) / sum;
if(rmn >= p[max_id]){
continue;
}
num += rmn;
}
ans = min(ans, num);
}
cout << ans << endl;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n); (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define rev(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c) for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define mp make_pair
#define pb push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }
const double INF = 1000000000;
const ll MOD = 1000000007LL;
const double EPS = 1E-12;
template<typename T> T add(T x, T y){ if(abs(x+y) < EPS*(abs(x)+abs(y))) return 0; return x + y; }
template<typename T> inline bool semieq(T x, T y){ return abs(x - y) < EPS; }
template<typename T> inline bool semige(T x, T y){ return y - x < -EPS; }
template<typename T> inline bool semile(T x, T y){ return x - y < -EPS; }
const int MAX_N = 10;
const int n = MAX_N;
double x[MAX_N+1];
double v[2];
int main()
{
while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x[0], &x[1], &x[2], &x[3], &x[4], &x[5], &x[6], &x[7], &x[8], &x[9], &v[0], &v[1])){
double len = 0.0;
rep(i, n) len += x[i];
double left = 0.0;
double right = INF;
double t;
while(semile(left, right)){
t = (left + right) / 2.0;
if((v[0] + v[1]) * t > len) right = t;
else left = t;
}
rep(i, n-1) x[i+1] += x[i];
cout << upper_bound(x, x+n, v[0] * t) - x + 1<< endl;
}
return 0;
} | #include<iostream>
#include<map>
using namespace std;
int main(void){
int l[10];
int v1,v2;
char c;
while(cin >> l[0]){
int sum = 0;
int ans=0;
sum= l[0];
for(int i = 1;i < 10;i++){
cin >> c >> l[i];
sum+=l[i];
}
cin >> c >> v1 >> c >> v2;
//cout << v1 << " " << v2 << endl;
double ti = sum/double(v1+v2);
double tmp = ti*double(v1);
//cout << ti << " " << tmp << endl;
for(int i = 0;i < 10;i++){
tmp-=l[i];
if(tmp<=0){
ans=i+1;
break;
}
}
cout << ans << endl;
}
return 0;
}
| 1 |
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
double x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
double x = (double)(x2 - x1) * (double)(x2 - x1);
double y = (double)(y2 - y1) * (double)(y2 - y1);
cout << fixed << setprecision(6) << (double)sqrt(x+y) << endl;
return 0;
}
| #include <iostream>
#include <cmath>
using namespace std;
int main(void){
double x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << fixed << sqrt(pow(fabs(x1-x2),2)+pow(fabs(y1-y2),2)) << endl;
return 0;
}
| 1 |
#include <iostream>
#include <vector>
using namespace std;
int main() {
while(true){
vector<vector<int>> m(21);
for(auto &mm : m){
mm.resize(21,0);
}
int N,M;
cin >> N;
if(N==0)break;
for(int i=0;i<N;i++){
int x,y;
cin >> x >> y;
m[x][y]=1;
}
cin>>M;
int x=10,y=10;
for(int i=0;i<M;i++){
char c;
int d,dx=0,dy=0;
cin >> c >> d;
switch(c){
case 'N':
dy=1;
break;
case 'E':
dx=1;
break;
case 'S':
dy=-1;
break;
case 'W':
dx=-1;
break;
}
for(int j=0;j<d;j++){
x+=dx;
y+=dy;
if(m[x][y]==1){
m[x][y]=0;
N--;
}
}
}
if(N==0){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
}
return 0;
} | #include <stdio.h>
typedef struct _Gem{
int x;
int y;
bool hit;
} Gem;
static void
pick_gem(Gem* g, int n, int x, int y)
{
for (int i = 0; i < n; i++) {
if (!g[i].hit && g[i].x == x && g[i].y == y) {
g[i].hit = true;
return;
}
}
}
static bool
check_gem(Gem* g, int n)
{
for (int i = 0; i < n; i++) {
if (g[i].hit == false) {
return false;
}
}
return true;
}
int
main(void)
{
char line[80];
int n;
int m;
Gem g[20];
char d[30];
int l[30];
while (true) {
if (fgets(line, sizeof line, stdin) == NULL) {
return 1;
}
if (sscanf(line, "%d", &n) != 1) {
return 1;
}
if (n == 0) {
break;
}
for (int i = 0; i < n; i++) {
if (fgets(line, sizeof line, stdin) == NULL) {
return 1;
}
if (sscanf(line, "%d %d", &(g[i].x), &(g[i].y)) != 2) {
return 1;
}
g[i].hit = false;
}
if (fgets(line, sizeof line, stdin) == NULL) {
return 1;
}
if (sscanf(line, "%d", &m) != 1) {
return 1;
}
for (int i = 0; i < m; i++) {
if (fgets(line, sizeof line, stdin) == NULL) {
return 1;
}
if (sscanf(line, "%c %d", &(d[i]), &(l[i])) != 2) {
return 1;
}
}
int x = 10;
int y = 10;
for (int i = 0; i < m; i++) {
if (d[i] == 'N') {
for (int k = 1; k <= l[i]; k++) {
pick_gem(g, n, x, ++y);
}
} else if (d[i] == 'S') {
for (int k = 1; k <= l[i]; k++) {
pick_gem(g, n, x, --y);
}
} else if (d[i] == 'E') {
for (int k = 1; k <= l[i]; k++) {
pick_gem(g, n, ++x, y);
}
} else {
for (int k = 1; k <= l[i]; k++) {
pick_gem(g, n, --x, y);
}
}
}
printf("%s\n", (check_gem(g, n) ? "Yes" : "No"));
}
return 0;
} | 1 |
#include <cstdio>
#include <algorithm>
using namespace std;
int n, ans, tot, to[1000005], u[1000005], v[1000005];
char S[1000005], T[1000005];
bool check(int x) {
for (int i = 1; i <= tot - x; ++i)
if (u[i + x] - x < v[i])
return false;
return true;
}
int main() {
scanf("%d", &n);
scanf("%s", S + 1);
scanf("%s", T + 1);
int ptr = n;
for (int i = n; i >= 1; --i) {
ptr = min(ptr, i);
while (ptr > 0 && S[ptr] != T[i]) --ptr;
if (ptr == 0) {
puts("-1");
return 0;
}
if (to[ptr] == 0) to[ptr] = i;
}
for (int i = 1; i <= n; ++i)
if (to[i] != 0) {
++tot;
u[tot] = i;
v[tot] = to[i];
}
int L = 0, R = n, mid;
while (L < R) {
mid = (L + R) >> 1;
if (check(mid)) R = mid;
else L = mid + 1;
}
printf("%d\n", R);
return 0;
}
| #include<bits/stdc++.h>
constexpr auto MAXN = 1000000+500;
std::string s,t;
std::queue<int> que;
signed main(void)
{
int len,down,up; size_t ans = 0;
std::cin>>len>>s>>t;
if(s == t){ puts("0"); return 0; }
down = up = len-1;
while(down >= 0){
while(down && t[down-1]==t[down]) --down;
while(up>=0 && (up>down || s[up]!=t[down])) --up;
if(up < 0){ puts("-1"); return 0; }
while(!que.empty() && que.front()-que.size() >= down) que.pop();
if(up != down) que.push(up);
ans = std::max(ans,que.size()+1);
--down;
}
std::cout<<ans<<std::endl;
return 0;
}
| 1 |
#include <cstdio>
#include <set>
int main()
{
int s, t; //number of integers for S and T
int count = 0; // number of integers of T in S
std::set<int> S; // set S to be checked against
scanf("%d", &s);
for (int i = 0; i < s; ++i) {
int input;
scanf("%d", &input);
S.insert(input);
}
scanf("%d", &t);
for (int i = 0; i < t; ++i) {
int input;
scanf("%d", &input);
if ( S.find(input) != S.end() ) ++count; // increment count if found in S
}
printf("%d\n", count);
}
| #include <iostream>
#define ll long long
using namespace std;
int main () {
int q,p = 0,n; cin >> q; ll ans = 0;
while (q--){
cin >> n;
if (n<p) ans += p-n;
else p=n;
} cout << ans << "\n";
return 0;
} | 0 |
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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; }
// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
ll x;
mint():x(0){}
mint(ll x):x((x%mod+mod)%mod){}
// mint(ll x):x(x){}
mint& fix() { x = (x%mod+mod)%mod; return *this;}
mint operator-() const { return mint(0) - *this;}
mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
mint operator+(const mint& a)const{ return mint(*this) += a;}
mint operator-(const mint& a)const{ return mint(*this) -= a;}
mint operator*(const mint& a)const{ return mint(*this) *= a;}
bool operator<(const mint& a)const{ return x < a.x;}
bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//
vector<ll> divisor(ll n) {
vector<ll> ret;
for (int 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.begin(), ret.end());
return ret;
}
int main() {
ll n, m;
cin >> n >> m;
vector<ll> d = divisor(m);
ll ans = 1;
for (auto x : d) {
if (x*n <= m) ans = x;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
using namespace std;
int main(){
int l[11],v1,v2,ans;
double x;
while(1){
int sum=0,y=0;
rep(i,0,10){
scanf("%d,",&l[i]);
sum+=l[i];
}
if(scanf("%d,%d",&v1,&v2)==EOF) break;
x=(double)sum*v1/(v1+v2);
rep(j,0,10){
y+=l[j];
if(y>=x){
ans=j+1;
break;
}
}
cout<<ans<<endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define vl vector<ll>
int main() {
ll D, G;
cin >> D >> G;
vl p(D), c(D);
rep(i, D) cin >> p[i] >> c[i];
int ans = 1e9;
rep(i, 1<<D) {
vl P = p;
int prob = 0;
ll score = 0;
rep(j, D) {
if (i>>j&1) {
score += ((j+1) * 100 * P[j]);
score += c[j];
prob += P[j];
P[j] = 0;
}
}
int itr = D-1;
bool ok = true;
while(score < G) {
while (P[itr] < 1) {
itr--;
if (itr < 0) {
ok = false;
break;
}
}
if (ok) {
score += ((itr+1)*100);
prob++;
P[itr]--;
}
else break;
}
if (ok) ans = min(prob, ans);
// cout << "i: " << i << " score: " << score << " prob: " << prob << endl;
// rep(j, D) cout << (j+1)*100 << ": " << p[j] - P[j] << endl;
}
cout << ans << endl;
return 0;
}
| #define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
ll dp[11][210000];
const int INF=1e9;
int main() {
ll d,g;
cin>>d>>g;
g/=100;
vector<int> P(d+1),C(d+1);
int x;
rep(i,d){
cin>>P[i+1]>>x;
C[i+1]=x/100;
}
rep(i,11){
rep(j,210000) dp[i][j]=INF;
}
dp[0][0]=0;
for(int i=1;i<=d;i++){
for(int j=0;j<=g+20000;j++){
for(int k=0;k<P[i];k++){
if(j-k*i<0) continue;
dp[i][j]=min(dp[i][j],dp[i-1][j-k*i]+k);
}
if(j-P[i]*i-C[i]<0) continue;
dp[i][j]=min(dp[i][j],dp[i-1][j-P[i]*i-C[i]]+P[i]);
}
}
ll ans=INF;
for(int i=g;i<=g+20000;i++){
ans=min(ans,dp[d][i]);
}
cout<<ans<<endl;
return 0;
} | 1 |
#include<bits/stdc++.h>
using namespace std;
int main(void){
int cp;
int hako[3];
for(int i = 0; i < 3; i++)
cin >> hako[i];
for(int i = 1; i < 3; i++){
cp = hako[i];
hako[i] = hako[0];
hako[0] = cp;
}
for(int i = 0; i < 3; i++){
cout << hako[i] << " ";
}
cout << "\n";
return 0;
} | /*
@uthor: Amit Kumar
user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
ll google_itr = 1;
#define google(x) cout<<"Case #"<<x<<":"
#define pi 3.14159265358979323846264338327950L
const ll mod = 1e9+7;
const ll inf = 1e18;
ll popcount(ll num){
num = num - ((num >> 1) & 0x55555555);
num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
vector<pair<ll,ll>> factor_arr;
void myfactor(ll num){
ll count = 0;
while (!(num % 2)) {
num >>= 1; count++;
}
if (count) factor_arr.push_back({2,count});
for (auto i = 3; i <= sqrt(num); i += 2) {
count = 0;
while (num % i == 0) {
count++;
num /= i;
}
if (count) factor_arr.push_back({i,count});
}
if (num > 2) factor_arr.push_back({num,1});
}
void virus(){
ll a,b,c;
cin>>a>>b>>c;
cout<<c<<" "<<a<<" "<<b;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif*/
ll t=1;
//cin>>t;
while(t--){
auto start = high_resolution_clock::now();
virus();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<seconds>(stop - start);
//cout << "Time: "<<duration.count()<<endl;
//your code goes here
}
return 0;
} | 1 |
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include<list>
#include<cctype>
#include<utility>
#include<algorithm>
#include<cmath>
#include<cctype>
using namespace std;
///入力順はここで定義
enum FACE { TOP,BACK, RIGHT ,LEFT , FRONT, BOTTOM};
template <class T>
class dice {
public:
dice() {
id[TOP] = 0; id[FRONT] = 1; id[LEFT] = 2;
id[RIGHT] = 3; id[BACK] = 4; id[BOTTOM] = 5;
}
T& operator[] (int f) { return var[id[f]]; }
const T& operator[] (int f) const { return var[id[f]]; }
bool operator==(const dice<T>& b) const {
const dice<T> &a = *this;
return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
}
//回転はここで
void roll_n() { roll(TOP, BACK, BOTTOM, FRONT); }
void roll_s() { roll(TOP, FRONT, BOTTOM, BACK); }
void roll_e() { roll(TOP, LEFT, BOTTOM, RIGHT); }
void roll_w() { roll(TOP, RIGHT, BOTTOM, LEFT); }
void roll_z() { roll(FRONT, RIGHT, BACK, LEFT); }
vector<dice> all_rolls() {
vector<dice> ret;
for (int k = 0; k < 6; (k&1?roll_w():roll_s()),++k)
for (int i = 0; i < 4; roll_z(), ++i)
ret.push_back(*this);
return ret;
}
bool equivalent_to(const dice& di) {
for (int k = 0; k < 6; (k&1?roll_w():roll_s()),++k)
for (int i = 0; i < 4; roll_z(), ++i)
if (*this == di) return true;
return false;
}
private:
void roll(FACE a, FACE b, FACE c, FACE d) {
T tmp = id[a];
id[a] = id[b]; id[b] = id[c];
id[c] = id[d]; id[d] = tmp;
}
T var[6];
int id[6];
};
int main()
{
int n;cin >> n;
vector<dice<int>> vd(n);
for(int i=0;i<n;i++){
for(int j=0;j<6;j++){
int a;cin >> a;
vd[i][j] = a;
}
}
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(vd[i].equivalent_to(vd[j])){
cout << "No" << endl;
exit(0);
}
}
}
cout << "Yes" << endl;
/*
vector<dice<int>> d(2);
for(int j=0;j<2;j++)
for(int i=0;i<6;i++){
int n; cin >>n;
d[j][i] = n;
}
if(d[0].equivalent_to(d[1])){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
int n;cin >> n;
for(int i=0;i<n;i++){
int top,back;
cin >> top >> back;
for(int i=0;i<vd.size();i++){
if(vd[i][TOP] == top && vd[i][BACK] == back){
cout << vd[i][RIGHT] << endl;
break;
}
}
}*/
return 0;
} | #include<cstdio>
int comparedice(void);
class dice{
private:
int a,b,c,d,e,f;
public:
void setnumber(void);
void E(void);
void W(void);
void S(void);
void N(void);
void R(void);
void V(void);
int frontside(int x,int y);
int putme(char me);
};
void dice::setnumber(void){
scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
}
void dice::E(void){
int a1=a,c1=c,d1=d,f1=f;
a=d1;
c=a1;
d=f1;
f=c1;
}
void dice::W(void){
int a1=a,c1=c,d1=d,f1=f;
a=c1;
c=f1;
d=a1;
f=d1;
}
void dice::S(void){
int a1=a,b1=b,e1=e,f1=f;
a=e1;
b=a1;
e=f1;
f=b1;
}
void dice::N(void){
int a1=a,b1=b,e1=e,f1=f;
a=b1;
b=f1;
e=a1;
f=e1;
}
int dice::frontside(int x,int y){
int i=0,a1,b1,c1,d1,e1,f1;
while(1){
a1=a;
b1=b;
c1=c;
d1=d;
e1=e;
f1=f;
a=b1;
b=c1;
c=a1;
d=f1;
e=d1;
f=e1;
i++;
if(i==4)break;
}
if (b!=x){
a=e1;
b=f1;
c=d1;
d=c1;
e=a1;
f=b1;
}
//printf("%d %d %d %d %d %d\n",a,b,c,d,e,f);
i=0;
while (b!=x){
a1=a;
b1=b;
c1=c;
d1=d;
e1=e;
f1=f;
a=b1;
b=c1;
c=a1;
d=f1;
e=d1;
f=e1;
i++;
if(i==4)break;
}
if(i==4){ return 0;}
i=0;
while(c!=y){
a1=a;
c1=c;
d1=d;
f1=f;
a=d1;
c=a1;
d=f1;
f=c1;
i++;
if(i==5) break;
}
if(i==5) {return 0;}
return 1;
}
int dice::putme(char me){
if(me=='a'){
return a;
}else if(me=='b'){
return b;
}else if(me=='c'){
return c;
}else if(me=='d'){
return d;
}else if(me=='e'){
return e;
}else {
return f;
}
}
int comparedice(dice,dice);
int main(void){
int n;
scanf("%d",&n);
dice koro[n];
int i,j;
for (i=0;i<n;i++){
koro[i].setnumber();
}
for (i=0;i<n;i++){
for(j=0;j<i;j++){
if (comparedice(koro[i],koro[j])==0){
printf("No\n");
}
if (comparedice(koro[i],koro[j])==0){return 0;}
}
}
printf("Yes\n");
return 0;
}
int comparedice(dice koro1,dice koro2){
int i,j;
for(i=0;i<3;i++){
for(j=0;j<4;j++){
if(
(koro1.putme('a')==koro2.putme('a'))
&&(koro1.putme('b')==koro2.putme('b'))
&&(koro1.putme('c')==koro2.putme('c'))
&&(koro1.putme('d')==koro2.putme('d'))
&&(koro1.putme('e')==koro2.putme('e'))
&&(koro1.putme('f')==koro2.putme('f'))
){return 0;}
koro2.E();
}
koro2.E();
koro2.N();
}
koro2.N();
koro2.E();
koro2.E();
for(i=0;i<3;i++){
for(j=0;j<4;j++){
if(
(koro1.putme('a')==koro2.putme('a'))
&&(koro1.putme('b')==koro2.putme('b'))
&&(koro1.putme('c')==koro2.putme('c'))
&&(koro1.putme('d')==koro2.putme('d'))
&&(koro1.putme('e')==koro2.putme('e'))
&&(koro1.putme('f')==koro2.putme('f'))
){return 0;}
koro2.E();
}
koro2.E();
koro2.N();
}
return 1;
} | 1 |
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
return *ci++;
}
inline int getint() {
int A = 0;
if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
return A;
}
//わけわかめ
int P[100001];
bool dame[100001];
int Find(int A) {
if (P[A] < 0) return A << 1;
return P[A] = Find(P[A] >> 1) ^ (P[A] & 1);
}
int main() {
//cin.tie(0);
//ios::sync_with_stdio(false);
int N = getint(), M = getint();
rep1(i, N) P[i] = -1;
rep(i, M) {
int a = Find(getint());
int b = Find(getint());
//なんてセンスのない
int a1 = a >> 1;
int b1 = b >> 1;
if (a1 == b1) {
if (!((a ^ b) & 1)) dame[a1] = true;
continue;
}
if (P[a1] > P[b1]) {
P[b1] += P[a1];
dame[b1] |= dame[a1];
P[a1] = b ^ !(a & 1);
}
else {
P[a1] += P[b1];
dame[a1] |= dame[b1];
P[b1] = a ^ !(b & 1);
}
}
ll x = 0, y = 0, z = 0;
rep1(i, N) {
if (P[i] < 0) {
if (P[i] == -1) z++;
else if (dame[i]) y++;
else x++;
}
}
printf("%lld\n", x * x + (x + y) * (x + y) + 2 * N * z - z * z);
Would you please return 0;
} | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
vector<ll>path[101010];
ll flg[101010][2];
ll A, B, C;
ll A_cnt, B_cnt;
int main(){
ll N, M;
cin >> N >> M;
rep(i, M){
ll x, y;
cin >> x >> y;
path[x].push_back(y);
path[y].push_back(x);
}
rep1(i, N){
if(flg[i][0] || flg[i][1])continue;
if(path[i].empty()){
C++;
continue;
}
flg[i][0] = 1;
queue<P>Q;
Q.push(P(i, 0));
while(!Q.empty()){
ll idx = Q.front().first;
ll v = Q.front().second;
Q.pop();
rep(j, path[idx].size()){
ll to = path[idx][j];
if(flg[to][v ^ 1])continue;
flg[to][v ^ 1] = 1;
Q.push(P(to, v ^ 1));
}
}
if(flg[i][1])B++;
else A++;
}
rep1(i, N){
if(flg[i][0] && flg[i][1])A_cnt++;
else if(flg[i][0] || flg[i][1])B_cnt++;
}
cout << B * B + 2 * A * B + 2 * A * A + 2 * B_cnt * C + 2 * A_cnt * C + C * C << endl;
return 0;
} | 1 |
#include <iostream>
using namespace std;
int n;
int M[100][100];
int prim(){
int d[100]; //最小コスト
int color[100];
int p[100];
for(int i=0;i<n;i++){
d[i] = (1 << 21);
color[i] = 0;
p[i] = -1;
}
d[0] = 0;
p[0] = 0;
int mincost;
int u;
int cost = 0;
while(true){
mincost = (1 << 21);
for(int i=0;i<n;i++){
if(color[i] != 2 && d[i] < mincost){
mincost = d[i];
u = i;
}
}
if(mincost == (1 << 21)) break;
color[u] = 2;
cost += mincost;
// uと隣接する頂点についてdの更新
for(int i=0;i<n;i++){
if(M[u][i] != -1 && color[i] != 2 && M[u][i] < d[i]){
d[i] = M[u][i];
p[i] = u;
color[i] = 1;
}
}
}
return cost;
}
int main(){
cin >> n;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cin >> M[i][j];
}
}
cout << prim() << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(){
int a[5], k, ans = 0;
for(int i = 0; i < 5; i++)
cin >> a[i];
cin >> k;
for(int i = 0; i < 5; i++)
for(int j = 0; j < 5; j++)
if(a[i] < a[j] && a[j] - a[i] > k)
ans++;
if(ans)cout << ":(";
else cout << "Yay!";
return 0;
} | 0 |
//Author: ReseeCher
#include<bits/stdc++.h>
#define LL long long
#define F(x,y,z) for(int x=y;x<=z;++x)
#define D(x,y,z) for(int x=y;x>=z;--x)
#define ckmax(a,b) (a)=max(a,b)
#define ckmin(a,b) (a)=min(a,b)
#define pb push_back
#define Ad(x,y) (x)=((x)+(y))%P
using namespace std;
const int N=305;
const int P=998244353;
LL R(){
LL ans=0,f=1;char c=getchar();
for(;c<'0'||c>'9';c=getchar()) if (c=='-') f=-1;
for(;c>='0'&&c<='9';c=getchar()) ans=ans*10+c-'0';
return ans*f;
}
int a[N],n,m;
LL dp[N][N][N];
char s[N];
LL an[N];
int main(){
//freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
cin>>(s+1);int len=strlen(s+1);
int K=R();
++n;
F(i,1,len)
if(s[i]=='1')++a[n],++m;
else ++n;
dp[0][0][0]=1;
F(i,0,n-1)
F(j,0,m)
F(k,0,m){
if(!dp[i][j][k])continue;
int lim=min(m+a[i+1]-j,min(m+a[i+1]-k,m));
F(u,max(a[i+1]-j,0),lim){
Ad(dp[i+1][j+(u-a[i+1])][k+max(0,u-a[i+1])],dp[i][j][k]);
}
}
F(i,0,m)an[i]=dp[n][0][i];
F(i,1,m)Ad(an[i],an[i-1]);
cout<<an[min(K,m)];
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
double dp[301][301][301];
int n;
double sushi(int o,int z, int t){
if(z<0||o<0||t<0)
return 0.0;
if(z==0&&o==0&&t==0)
return 0.0;
if(dp[o][z][t]>=0.0)
return (double) dp[o][z][t];
dp[o][z][t]= o*sushi(o-1,z,t)+z*sushi(o+1,z-1,t)+t*sushi(o,z+1,t-1)+n;
dp[o][z][t]/=(o+z+t);
return dp[o][z][t];
}
int main(){
int o=0,z=0,t=0;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
if(a[i]==2)
z++;
else if(a[i]==1)
o++;
else
t++;
}
memset(dp,-1.0,sizeof (dp));
dp[0][0][0]=0.0;
cout<<fixed<<setprecision(12)<<sushi(o,z,t);
} | 0 |
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, q, a, b, l, val[800007][3], tag[800007];
int read()
{
int num = 0;
char c = getchar();
while (c<'0' || c>'9')c = getchar();
while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
return num;
}
int add(int w, int v)
{
for (int j = 0; j <= 2; j++)
val[w][j] += v;
tag[w] += v;
return 0;
}
int down(int w)
{
if (!tag[w])return 0;
add(2 * w, tag[w]);
add(2 * w + 1, tag[w]);
tag[w] = 0;
return 0;
}
int up(int w)
{
for (int i = 0; i <= 2; i++)
val[w][i] = min(val[2 * w][i], val[2 * w + 1][i]);
return 0;
}
int change(int w, int l, int r, int x, int v)
{
if (l == r)
{
val[w][0] = v;
val[w][1] = v - x;
val[w][2] = v + x;
return 0;
}
down(w);
int mid = (l + r) / 2;
if (x <= mid)change(2 * w, l, mid, x, v);
else change(2 * w + 1, mid + 1, r, x, v);
up(w);
return 0;
}
int ask(int p, int w, int l, int r, int x, int y)
{
if (x <= l && r <= y)
return val[w][p];
down(w);
int mid = (l + r) / 2, res = 1e18;
if (x <= mid)res = min(res, ask(p, 2 * w, l, mid, x, y));
if (y > mid)res = min(res, ask(p, 2 * w + 1, mid + 1, r, x, y));
return res;
}
signed main()
{
n = read();
q = read();
a = read();
b = read();
l = read();
memset(val, 0x3f, sizeof val);
change(1, 1, n, b, abs(l - a));
change(1, 1, n, a, abs(l - b));
for (int i = 2; i <= q; i++)
{
int num = read(), len = abs(num - l);
int res1 = ask(0, 1, 1, n, num, num) + len;
int res2 = ask(1, 1, 1, n, 1, num) + num;
int res3 = ask(2, 1, 1, n, num + 1, n) - num;
add(1, len);
change(1, 1, n, l, min(res1, min(res2, res3)));
l = num;
}
printf("%lld\n", val[1][0]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
const int mod=998244353;
const int INF=0x3f3f3f3f;
ll quick(ll a,ll b)
{
ll ret=1;
while(b)
{
if(b&1)
ret=ret*a%mod;
a=a*a%mod;
}
return ret;
}
ll inv(ll a){return quick(a,mod-2);}
const int maxn=1e5+7;
ll l[maxn],u[maxn],b[maxn];
struct val{
ll value;
int id;
bool operator<(const val &a)const{
return value>a.value;
}
}v[maxn];
ll n,x;
ll tot;
bool check(ll cur)
{
ll cnt=cur/x;
ll ret=0;
ll rm=cur%x;
for(int i=0;i<cnt+(rm!=0);i++)
ret+=v[i].value;
ll mx=0;
if(rm)
{
for(int i=0;i<n;i++)
{
int id=v[i].id;
mx=max(mx,ret-(i>=cnt?v[cnt].value:v[i].value)+(rm>b[id]?(rm-b[id])*u[id]+b[id]*l[id]:rm*l[id]));
}
}
else mx=ret;
return mx>=tot;
}
int main()
{
scanf("%lld%lld",&n,&x);
tot=0;
for(int i=0;i<n;i++)
{
scanf("%lld%lld%lld",&b[i],&l[i],&u[i]);
tot+=l[i]*b[i];
v[i].value=b[i]*l[i]+(x-b[i])*u[i];
v[i].id=i;
//dbg(i,v[i].value);
}
sort(v,v+n);
ll L=0,R=n*x;
ll ans;
while(L<=R)
{
ll mid=L+R>>1;
if(check(mid)) R=mid-1,ans=mid;
else L=mid+1;
}
printf("%lld\n",ans);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 400;
int h, w;
string s;
int grid[MX][MX];
ll black[MX*MX], white[MX*MX];
bool used[MX][MX];
ll ans;
int curGroup = -1;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
void dfs(int x, int y) {
used[x][y] = true;
if (grid[x][y]) black[curGroup]++;
else white[curGroup]++;
for (int i = 0; i < 4; i++) {
int a = x + dx[i], b = y + dy[i];
if (a < 0 || a >= h || b < 0 || b >= w) continue;
if (grid[a][b] == grid[x][y]) continue;
if (used[a][b]) continue;
dfs(a, b);
}
}
int main() {
cin.sync_with_stdio(0); cin.tie(0);
cin >> h >> w;
for (int i = 0; i < h; i++) {
cin >> s;
for (int j = 0; j < w; j++) {
if (s[j] == '#') grid[i][j] = 1;
else grid[i][j] = 0;
}
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
curGroup++;
if (!used[i][j]) dfs(i, j);
}
}
for (int i = 0; i <= curGroup; i++) {
ans += white[i] * black[i];
}
cout << ans;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
ll dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
ll counterb=0,counterw=0;
void dfs(ll x,ll y,ll H, ll W,vector<vector<bool>> &field,vector<vector<bool>> &check){
check[x][y]=1;
if(field[x][y]==1){counterb++;}
if(field[x][y]==0){counterw++;}
bool meter=(x+y+field[x][y])%2;
for(int i=0;i<4;i++){if(x+dx[i]>=0&&x+dx[i]<H&&y+dy[i]>=0&&y+dy[i]<W){
if(check[x+dx[i]][y+dy[i]]==0&&(x+y+dx[i]+dy[i]+field[x+dx[i]][y+dy[i]])%2==meter){
dfs(x+dx[i],y+dy[i],H,W,field,check);
};}
;}
}
int main(){
ll H;
cin >> H;
ll W;
cin >> W;
vector<vector<bool>> field(H, vector<bool>(W, 0));
vector<vector<bool>> check(H, vector<bool>(W, 0));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
char k;
cin>>k;
if(k=='#'){field[i][j]=1;}
;}
;}
ll ans=0;
for(ll i=0;i<H;i++){
for(ll j=0;j<W;j++){
if(check[i][j]==0){
dfs(i,j,H,W,field,check);ans+=counterb*counterw;
counterb=0;counterw=0;
}
;}
;}
cout<<ans<<endl;
return 0;
}
| 1 |
#include<iostream>
#include<algorithm>
using namespace std;
unsigned long long int i, fin, num[3];
int n;
int main(){
cin >> n;
for(i=0;i<n;i++){
cin >> num[i];
}
if(n==2){
fin = min(num[0], num[1]);
for(i=1;i<=fin;i++){
if(!(num[0]%i) && !(num[1]%i)){
cout << i << endl;
}
}
}
if(n==3){
fin = min(num[0], num[1]);
fin = min(num[2], fin);
for(i=1;i<=fin;i++){
if(!(num[0]%i) && !(num[1]%i) && !(num[2]%i)){
cout << i << endl;
}
}
}
return 0;
} | #include <iostream>
using namespace std;
int main()
{
int n;
int i;
int temp;
cin >> n;
int* p = new int[n];
for (i = n - 1; i >= 0; i--) {
cin >> p[i];
}
for (i = 0; i < n; i++) {
if (i < n - 1) {
cout << p[i] << " ";
} else {
cout << p[i] << endl;
}
}
delete [] p;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
struct node{
long long x,p;
}a[100010];
bool cmp(node a,node b){
return a.x<b.x;
}
long long n,s,ans;
int main(){
scanf("%lld%lld",&n,&s);
for (int i=1;i<=n;i++)
scanf("%lld%lld",&a[i].x,&a[i].p);
sort(a+1,a+n+1,cmp);
long long l=n,l1=1;
while (l>=l1){
if (a[l].x<=s){
ans+=s-a[l1].x;
break;
}
if (a[l1].x>=s){
ans+=a[l].x-s;
break;
}
ans+=a[l].x-a[l1].x;
if (a[l1].p>=a[l].p)
while (l>l1 && a[l1].p>=a[l].p) a[l1].p+=a[l].p,l--;
else
while (l>l1 && a[l].p>a[l1].p) a[l].p+=a[l1].p,l1++;
}
printf("%lld",ans);
return 0;
} | #include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define pi std::pair<int, int>
#define mkp std::make_pair
#define ll long long
#define pb push_back
#define fi first
#define se second
//{{{IO
namespace IO{
template <class I> void read(I &x){
x = 0; char ch = getchar(); bool f = false;
for(; !isdigit(ch); ch = getchar()) f |= (ch == '-');
for(; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + ch - '0';
return ;
}
int read_int(){ int x; return read(x), x;}
ll read_ll(){ ll x; return read(x), x;}
template <class I>
void chmax(I &x, I y){x = x > y ? x : y;}
template <class I>
void chmin(I &x, I y){x = x < y ? x : y;}
#define ri read_int()
#define rl read_ll()
}
using IO::read_int;
using IO::read_ll;
using IO::chmax;
using IO::chmin;
//}}}
//{{{Mod
namespace Mod{
// const int mod = 1e9 + 7;
// const int mod = 1004535809;
const int mod = 998244353;
inline void MOD(int &x){ x -= x >= mod ? mod : 0;}
inline void add(int &x, int y){ x = x + y >= mod ? x + y - mod : x + y;}
inline int Add(int x, int y){ return x + y >= mod ? x + y - mod : x + y;}
inline void mul(int &x, int y){ x = 1ll * x * y % mod;}
inline int Mul(int x, int y){ return 1ll * x * y % mod;}
}
//}}}
#define N 100005
int n, s, cnt;
int x[N], num[N];
ll a[N];
void solve(int l, int r){
if(l > r) return ;
if(l == r) return num[++cnt] = l, void();
if(x[l] > s){
while(r >= l) num[++cnt] = r--;
return ;
}
if(x[r] < s){
while(r >= l) num[++cnt] = l++;
return ;
}
if(a[l] >= a[r]){
num[++cnt] = r; a[l] += a[r]; solve(l, r - 1);
}
else{
num[++cnt] = l; a[r] += a[l]; solve(l + 1, r);
}
return ;
}
int main(){
n = ri; s = ri;
for(int i = 1; i <= n; ++i)
x[i] = ri, a[i] = ri;
solve(1, n); ll res = 0;
// for(int i = cnt; i >= 1; --i)
// debug("%d ", num[i]);
for(int i = cnt; i >= 1; --i)
res += abs(x[num[i]] - s), s = x[num[i]];
printf("%lld\n", res);
return 0;
} | 1 |
#include "bits/stdc++.h"
using namespace std;typedef long long lint;typedef vector<lint> liv;
//#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(),v.end()
#define linf 1152921504606846976
#define MAXN 100010
#define md 1000000007//998244353
#define pb push_back
#define _vcppunko4(tuple) _getname4 tuple
#define _getname4(_1,_2,_3,_4,name,...) name
#define _getname3(_1,_2,_3,name,...) name
#define _trep2(tuple) _rep2 tuple
#define _trep3(tuple) _rep3 tuple
#define _trep4(tuple) _rep4 tuple
#define _rep1(n) for(lint i=0;i<n;++i)
#define _rep2(i,n) for(lint i=0;i<n;++i)
#define _rep3(i,a,b) for(lint i=a;i<b;++i)
#define _rep4(i,a,b,c) for(lint i=a;i<b;i+=c)
#define _trrep2(tuple) _rrep2 tuple
#define _trrep3(tuple) _rrep3 tuple
#define _trrep4(tuple) _rrep4 tuple
#define _rrep1(n) for(lint i=n-1;i>=0;i--)
#define _rrep2(i,n) for(lint i=n-1;i>=0;i--)
#define _rrep3(i,a,b) for(lint i=b-1;i>=a;i--)
#define _rrep4(i,a,b,c) for(lint i=a+(b-a-1)/c*c;i>=a;i-=c)
template<class T>
istream& operator>>(istream& is,vector<T>& vec);
template<class T,size_t size>
istream& operator>>(istream& is,array<T,size>& vec);
template<class T,class L>
istream& operator>>(istream& is,pair<T,L>& p);
template<class T>
ostream& operator<<(ostream& os,vector<T>& vec);
template<class T,class L>
ostream& operator<<(ostream& os,pair<T,L>& p);
template<class T>
istream& operator>>(istream& is,vector<T>& vec){ for(T& x: vec) is>>x;return is; }
template<class T,class L>
istream& operator>>(istream& is,pair<T,L>& p){ is>>p.first;is>>p.second;return is; }
//template<class T>
//ostream& operator<<(ostream& os,vector<T>& vec){ os<<vec[0];rep(i,1,vec.size())os<<' '<<vec[i];return os; }
//template<class T>
//ostream& operator<<(ostream& os,deque<T>& deq){ os<<deq[0];rep(i,1,deq.size())os<<' '<<deq[i];return os; }
template<class T,class L>
ostream& operator<<(ostream& os,pair<T,L>& p){ os<<p.first<<" "<<p.second;return os; }
inline void in(){}
template <class Head,class... Tail>
inline void in(Head&& head,Tail&&... tail){ cin>>head;in(move(tail)...); }
template <class T>
inline bool out(T t){ cout<<t<<'\n';return 0; }
inline bool out(){ cout<<'\n';return 0; }
template <class Head,class... Tail>
inline bool out(Head head,Tail... tail){ cout<<head<<' ';out(move(tail)...);return 0; }
#define rep(...) _vcppunko4((__VA_ARGS__,_trep4,_trep3,_trep2,_rep1))((__VA_ARGS__))
#define rrep(...) _vcppunko4((__VA_ARGS__,_trrep4,_trrep3,_trrep2,_trrep1))((__VA_ARGS__))
#define lin(...) lint __VA_ARGS__;in(__VA_ARGS__)
#define stin(...) string __VA_ARGS__;in(__VA_ARGS__)
#define vin(type,name,size) vector<type> name(size);in(name)
int main(){
lint xs=0,ys=0,cur=0;
lin(n,m);
vin(lint,x,n);vin(lint,y,m);
//rep(n)x[i]+=1e9;rep(m)y[i]+=1e9;
rep(n-1){
cur+=x[n-i-1]-x[i]+md;cur%=md;
xs+=cur;xs%=md;
}cur=0;
rep(m-1){
cur+=y[m-i-1]-y[i]+md;cur%=md;
ys+=cur;ys%=md;
}lint ans=(xs*ys)%md;
cout<<ans<<endl;
}
|
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second
using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
// const int mod=998244353;
// const int mod=1e9+9;
// const int INF=4e18+10;
const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
template<typename T1,typename T2>
void set_min(T1& a, T2 b)
{
a=min(a, (T1)b);
}
int multiply(int a, int b, int in_mod){return (a*b)%in_mod;}
int mult_identity(int a){return 1;}
auto power(auto a, int b, int in_mod)
{
auto prod=mult_identity(a);
auto mult=a%in_mod;
while(b!=0)
{
if(b%2)
{
prod=multiply(prod,mult, in_mod);
}
mult=multiply(mult, mult,in_mod);
b/=2;
}
return prod;
}
int mod_inv(int q, int in_mod)
{
return power(q, in_mod-2,in_mod);
}
void solve()
{
int n, m;
cin>>n>>m;
vector<int> x, y;
for(int i=0;i<n;i++)
{
int b;
cin>>b;
x.pb(b);
}
for(int i=0;i<m;i++)
{
int b;
cin>>b;
y.pb(b);
}
sort(all(x));
sort(all(y));
int ans=0;
//precomputer the vector;
int vec=0;
for(int i=1;i<n;i++)
{
vec += i*(n-i)%mod * (x[i]-x[i-1]);
vec%=mod;
}
for(int i=1;i<m;i++)
{
ans += i*(m-i)%mod *vec%mod * (y[i]-y[i-1]);
ans%=mod;
}
cout<<ans<<endl;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
if(fopen("INPUT.txt","r"))
{
freopen ("INPUT.txt" , "r" , stdin);
freopen ("OUTPUT.txt" , "w" , stdout);
}
#endif
auto clk=clock();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// -------------------------------------Code starts here---------------------------------------------------------------------
int t=1;
// cin>>t;
for(int test=1;test<=t;test++)
{
// cout<<"Case #"<<test<<": ";
// cout<<endl;
solve();
// cout<<endl;
}
// -------------------------------------Code ends here------------------------------------------------------------------
clk = clock() - clk;
cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
return 0;
}
| 1 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
int main() {
int h, w;
cin >> h >> w;
char s[h][w];
rep(i, h) rep(j, w) cin >> s[i][j];
rep(i, h) rep(j, w) {
if (s[i][j] == '.') continue;
bool ok = false;
for (int y = -1; y <= 1; y += 2) {
int dy = i + y;
if (dy >= 0 && dy < h && s[dy][j] == '#') ok = true;
}
for (int x = -1; x <= 1; x += 2) {
int dx = j + x;
if (dx >= 0 && dx < w && s[i][dx] == '#') ok = true;
}
if (!ok) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}
| #include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000
bool dp[82][82][128002];
void solve_abc_e() {
ll h, w;
ll ans = 0;
cin >> h >> w;
ll a[82][82], b[82][82], c[82][82];
rep(i, 82)rep(j, 82) {
a[i][j] = b[i][j] = c[i][j] = 0;
}
rep(i, h)rep(j, w) {
cin >> a[i][j];
}
rep(i, h)rep(j, w) {
cin >> b[i][j];
}
rep(i, h)rep(j, w) {
c[i][j] = abs(a[i][j] - b[i][j]);
}
dp[0][0][c[0][0]] = true;
rep(i, h)rep(j, w) {
rep(p, 128001) {
if (dp[i][j][p]) {
dp[i + 1][j][abs(p + c[i + 1][j])] = true;
dp[i + 1][j][abs(p - c[i + 1][j])] = true;
dp[i][j + 1][abs(p + c[i][j + 1])] = true;
dp[i][j + 1][abs(p - c[i][j + 1])] = true;
}
}
}
rep(p, 128001) {
if (dp[h - 1][w - 1][p]) {
cout << p << "\n";
return;
}
}
}
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
solve_abc_e();
return 0;
} | 0 |
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
if(a<b)return b;
else return a;
}
ll lmin(ll a,ll b){
if(a<b)return a;
else return b;
}
ll gcd(ll a,ll b){
if(a<b)swap(a,b);
if(a%b==0)return b;
return gcd(b,a%b);
}
ll beki(ll n,ll k){
ll ret=1;
ll now=n;
while(k>0){
if(k%2==1){
ret*=now;
ret%=mod;
}
now*=now;
now%=mod;
k/=2;
}
return ret;
}
ll gyaku(ll n){
return beki(n,mod-2);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll n;cin>>n;
ll a,b,c,d;cin>>a>>b>>c>>d;
ll dp[n+1][n+1];
rep(i,0,n+1)rep(j,0,n+1)dp[i][j]=0;
dp[a-1][0]=1;
ll nck[1001][1001];
rep(i,0,1001)nck[i][0]=1;
rep(i,0,1001)nck[i][i]=1;
ll gya[1001];
rep(i,1,1001)gya[i]=gyaku(i);
rep(i,1,1001){
rep(j,1,i){
nck[i][j]=nck[i-1][j-1]+nck[i-1][j];
nck[i][j]%=mod;
}
}
rep(i,a-1,b){
int t=0;
rep(j,0,n+1){
dp[i+1][j]+=dp[i][j];
dp[i+1][j]%=mod;
if(t==1)continue;
ll sum=1;
ll now=n-j;
rep(k,0,c){
if(now<0){
sum=-1;
break;
}
sum*=nck[now][i+1];
sum%=mod;
sum*=gya[k+1];
sum%=mod;
now-=i+1;
}
if(sum==-1){
t=1;
continue;
}
rep(k,c,d+1){
if(j+(i+1)*k>n)break;
dp[i+1][j+(i+1)*k]+=dp[i][j]*sum;
dp[i+1][j+(i+1)*k]%=mod;
sum*=nck[n-(j+(i+1)*k)][i+1];
sum%=mod;
sum*=gya[k+1];
sum%=mod;
}
}
}
cout<<dp[b][n]<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dlb;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef pair<ll, pair<ll,ll> > iii;
const int kn = 2e5 + 5;
const ll mod = 1e9 + 7;
#define x first
#define y second
#define _it iterator
#define pb push_back
#define pf push_front
#define ms(val,a) memset(a,val,sizeof(a))
#define ff(i,n) for(int i=1;i<=n;i++)
#define _ff(i,n) for(int i=n;i>=1;i--)
#define f(i,a,b) for(int i = a; i <=b; i++)
#define _f(i,a,b) for(int i = b; i>=a;i--)
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n, par[kn];
ll ans = 0;
struct data{
int x, y;
int id;
};
bool option(data cac, data lon)
{
if(cac.x != lon.x) return cac.x < lon.x;
return cac.y < lon.y;
}
data a[2][kn];
int Find(int i)
{
if(par[i] == i) return i;
return par[i] = Find(par[i]);
}
void dj(int i, int j, int cost)
{
int pi = Find(i), pj = Find(j);
if(pi == pj) return;
par[pi] = pj;
ans += cost;
}
int la[2][kn], ra[2][kn];
set< iii > pq;
int main() {
//freopen("a.inp","r",stdin);
//freopen("a.out","w",stdout);
cin >> n;
ff(i,n) par[i] = i;
ff(i,n)
{
cin >> a[0][i].x >> a[0][i].y;
a[1][i].x = a[0][i].y; a[1][i].y = a[0][i].x;
a[0][i].id = a[1][i].id = i;
la[0][i] = la[1][i] = i-1;
ra[0][i]=ra[1][i] = i+1;
}
la[0][1] = la[1][1] = -1;
ra[0][n] = ra[1][n] = -1;
sort(a[0]+1,a[0]+n+1,option);
sort(a[1]+1,a[1]+n+1,option);
for(int i = 2; i<=n; i++)
{
pq.insert(iii(a[0][i].x - a[0][i-1].x, ii(i,0)));
pq.insert(iii(a[1][i].x - a[1][i-1].x, ii(i,1))); // 0 la day 1, 1 la day 2
}
while(pq.size())
{
iii tmp = *pq.begin();
pq.erase(pq.begin());
dj(a[tmp.y.y][tmp.y.x].id, a[tmp.y.y][tmp.y.x-1].id, a[tmp.y.y][tmp.y.x].x - a[tmp.y.y][tmp.y.x-1].x);
}
cout << ans;
}
//hahahahahahahahahhahahahahahaahahahahhahahahahahahah | 0 |
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(long int I=X;I<Y;I++)
#define REP(I,X) for(long int I=X;I>=0;I--)
#define INF 1e9+7
using namespace std;
int main(){
int a,b,c;
vector<int> ans;
while(1){
cin >> a >> b >> c;
if(!(a|| b || c))break;
int N,i,j,k,l;
cin >> N;
set<int> unbroken;
set<int> broken;
int ii[N],jj[N],kk[N],ll[N];
FOR(i,0,N)cin >> ii[i] >> jj[i] >> kk[i] >> ll[i];
FOR(count1,0,N)FOR(count2,0,N){
int i = ii[count2],j = jj[count2],k = kk[count2],l = ll[count2];
if(l){
unbroken.insert(i);
unbroken.insert(j);
unbroken.insert(k);
}
else{
if(unbroken.count(i) && unbroken.count(j))broken.insert(k);
if(unbroken.count(j) && unbroken.count(k))broken.insert(i);
if(unbroken.count(k) && unbroken.count(i))broken.insert(j);
}
}
FOR(i,1,a+b+c+1){
if(unbroken.count(i))ans.push_back(1);
else if(broken.count(i))ans.push_back(0);
else ans.push_back(2);
}
}
for(auto x:ans)cout << x << endl;
}
| #include <bits/stdc++.h>
using namespace std;
const int maxn=112345;
int n,x[maxn],l,q,f[maxn][20];
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;++i) scanf("%d",&x[i]);
scanf("%d%d",&l,&q);
for (int i=1;i<n;++i) {
int t=upper_bound(x+1,x+1+n,x[i]+l)-x-1;
f[i][0]=t;
}
f[n][0]=f[n+1][0]=n+1;
for (int i=1;i<20;++i)
for (int j=1;j<=n+1;++j)
f[j][i]=f[f[j][i-1]][i-1];
while (q--) {
int a,b;scanf("%d%d",&a,&b);
if (a>b) swap(a,b);
int num=0;
for (int i=19;i>=0;--i)
if (f[a][i]<=b) {
num+=1<<i;
a=f[a][i];
}
printf("%d\n",num+(a!=b));
}
return 0;
}
| 0 |
// #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min, std::next_permutation, std::lower_bound
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <numeric> // std::gcd, std::lcm
#include <limits> // std::numeric_limits<long int>::max()
#include <unordered_map>
#include <map>
#include <cmath> // std::atan2
#include <deque>
using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007
#define rep(i,n) for (long long i = 0; i < (n); ++i)
int main() {
ll N, K;
cin >> N >> K;
vector<ll> V(N);
rep (i, N) cin >> V[i];
deque<ll> treasures;
rep (i, N) treasures.push_back(V[i]);
ll ans = numeric_limits<ll>::min();
for (ll numpop = min(N, K); numpop >= 0; numpop--) {
ll numpush = K - numpop;
for (ll numpopL = 0; numpopL < numpop + 1; numpopL++) {
ll numpopR = numpop - numpopL;
vector<ll> mytreasures;
rep (i, numpopL) {
mytreasures.push_back(treasures.at(i));
// cerr <<"L"<< mytreasures.back() << endl;
}
rep (i, numpopR) {
mytreasures.push_back(treasures.at(N - i - 1));
// cerr <<"R"<< mytreasures.back() << endl;
}
ll sum = 0;
for (const auto mytreasure : mytreasures) {
sum += mytreasure;
}
sort(mytreasures.begin(), mytreasures.end());
for (ll i = 0; i < mytreasures.size() && i < numpush && mytreasures.at(i) < 0;
++i) {
sum -= mytreasures.at(i);
}
ans = max(ans, sum);
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
const int N = 50, K = 100;
ll mem[N+2][N+1][K+1];
ll opt(int i, int j, int k, vector<int>& v) {
ll& ans = mem[i+1][j+1][k];
if(ans == -1) {
if(i <= j) {
ans = max({
k >= 1 ? v[i] + opt(i + 1, j, k - 1, v) : 0,
k >= 1 ? v[j] + opt(i, j - 1, k - 1, v) : 0,
k >= 2 ? opt(i + 1, j, k - 2, v) : 0,
k >= 2 ? opt(i, j - 1, k - 2, v) : 0
});
} else {
ans = 0;
}
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> v(n);
cin >> v;
memset(mem, -1, sizeof mem);
ll ans = 0;
for(int kk = 0; kk <= k; kk++) {
ans = max(ans, opt(0, n - 1, kk, v));
}
cout << ans << endl;
return 0;
}
| 1 |
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
long long int n=0;
cin >> n;
long long int ans=0;
int i=0;
int amari=0;
vector<int>dog;
while(n>0){
if(n%26 == 0){
amari=n%26;
dog.push_back(amari);
n/=26;
n--;
continue;
}
amari=n%26;
dog.push_back(amari);
n/=26;
}
reverse(begin(dog),end(dog));
for(int i=0;i<(dog.size());i++){
char c;
if(dog.at(i) == 0){
cout << "z";
continue;
}
c = dog.at(i)+96;
cout << c;
}
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
const long long INF = 1LL << 60;
using Graph = vector<vector<ll>>;
int main()
{
string s;
cin >> s;
ll n = s.length();
//2文字条件
for (int i = 0; i < n - 1; i++)
{
if (s[i] == s[i + 1])
{
cout << i + 1 << " " << i + 2 << endl;
return 0;
}
}
//3文字条件
for (int i = 0; i < n - 2; i++)
{
if (s[i] == s[i + 2])
{
cout << i + 1 << " " << i + 3 << endl;
return 0;
}
}
cout << -1 << " " << -1 << endl;
}
| 0 |
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
double x1,x2,y1,y2,x,y,z;
cin>>x1>>y1>>x2>>y2;
x=x2-x1;
y=y2-y1;
x *=x;
y *=y;
z=sqrt(x+y);
printf("%lf\n",z);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;
//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
ll res = 1;
while (n) {
if (n & 1)res = res * a%m;
a = a * a%m; n >>= 1;
}
return res;
}
struct modint {
ll n;
modint() :n(0) { ; }
modint(ll m) :n(m) {
if (n >= mod)n %= mod;
else if (n < 0)n = (n%mod + mod) % mod;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
if (n == 0)return modint(1);
modint res = (a*a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
void solve() {
int H, W, K; cin >> H >> W >> K;
ll dp[105][10];
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
rep(i, H){
rep(j, W){
rep(k, 1 << W-1){
bool ok = true;
rep(l, W-2){
if((1 & (k >> l)) && (1 & (k >> l+1))) ok = false;
}
if(!ok) continue;
if(j > 0 && (1 & (k >> j-1))){
dp[i+1][j-1] = modint(modint(dp[i+1][j-1]) + modint(dp[i][j]));
}else if(j <= W-2 && (1 & (k >> j))){
dp[i+1][j+1] = modint(modint(dp[i+1][j+1]) + modint(dp[i][j]));
}else{
dp[i+1][j] = modint(modint(dp[i+1][j]) + modint(dp[i][j]));
}
}
}
}
cout << dp[H][K-1] << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
//cout << fixed << setprecision(10);
//init_f();
//init();
//int t; cin >> t; rep(i, t)solve();
solve();
// stop
return 0;
}
| 0 |
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
int main (int argc, char *argv[]) {
vector<int> v1(4), v2(2);
for (int i = 0; i < 4; ++i) {
cin >> v1[i];
}
for (int i = 0; i < 2; ++i) {
cin >> v2[i];
}
sort(v1.begin(), v1.end(), greater<int>());
sort(v2.begin(), v2.end(), greater<int>());
cout<<v1[0] + v1[1] + v1[2] + v2[0]<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
typedef pair<ll,ll> ipair;
#define F first
#define S second
/*
//functions from gfg
long long int power(long long int x,long long int y,long long int p)
{
long long int res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
{//d=(long double)x/p;
res = (res*x) % p;
}
// y must be even now
y = y>>1; // y = y/2
x=(x*x)%p;
}
return res%p;
}
long long int gcd(long long int a,long long int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
long long int binomialCoeff(long long int n, ll k)
{
ll res = 1;
// Since C(n, k) = C(n, n-k)
if (k > n - k)
k = n - k;
// Calculate value of [n*(n-1)*---*(n-k+1)] / [k*(k-1)*---*1]
for (ll i = 0; i < k; ++i)
{
res *= (n - i);
res /= (i + 1);
}
return res;
}
void sieve(int n, vector<ll> &primes)
{
vector<int> prime(n,1);
ll p;
for ( p=2; p*p<=n; p++)
{
// If prime[p] is not changed, then it is a prime
if (prime[p] == 1)
{
for (int i=p*p; i<=n; i += p)
prime[i] = 0;
}
}
for(p=2;p<=n;p++)
{
if(prime[p])
primes.pb(p);
}
}
void dfs(vector<ll> adj[] ,ll src,vector<ll> &vis)
{
vis[src]=1;
for(ll i=0;i<adj[src].size();i++)
{
if(vis[adj[src][i]]==0)
dfs(adj,adj[src][i],vis)
}
}
*/
int main() {
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
ll n,i,j,p,k,m,t,ans=0;
cin>>n>>t;
ll dp[3005][3005];
memset(dp, 0, sizeof(dp));
vector<ll> a(n),b(n);
vector<pair<ll,ll> > val(n);
for(i=0;i<n;i++)
{
cin>>a[i]>>b[i];
val[i].F=a[i];
val[i].S=b[i];
}
sort(val.begin(),val.end());
for(i=0;i<n;i++)
{
a[i]=val[i].F;
b[i]=val[i].S;
}
for(i=0;i<t;i++)
{
for(j=0;j<n;j++)
{
if(i+a[j]<t)
{
dp[j+1][i+a[j]] = max(dp[j][i]+b[j],dp[j+1][i+a[j]]);
}
dp[j+1][i] = max(dp[j][i],dp[j+1][i]);
}
}
for(i=0;i<n;i++)
{
ans=max(ans,dp[i][t-1]+b[i]);
}
cout<<ans<<endl;
// for(i=0;i<n;i++)
// {
// cout<<a[i]<<" ";
// }
// cout<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
// #define INF __INT32_MAX__
#define INF 1e9
#define LINF __LONG_LONG_MAX__
int main() {
int H, W; cin >> H >> W;
vector<vc> S(H, vc(W));
int cnt = 0;
rep(i, H) {
rep(j, W) {
cin >> S[i][j];
if (S[i][j] == '.') cnt++;
}
}
vector<vi> mp = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
vector<vi> route(H, vi(W, INF));
route[0][0] = 1;
queue<pair<int, int>> q;
q.push(make_pair(0, 0));
while (!q.empty()) {
pair<int, int> p = q.front(); q.pop();
int ux = p.first; int uy = p.second;
if (S[ux][uy] == '#') continue;
S[ux][uy] = '#';
for (int i = 0; i < 4; i++) {
int vx = ux + mp[i][0];
int vy = uy + mp[i][1];
if (vx >= 0 && vx < H && vy >= 0 && vy < W && S[vx][vy] != '#') {
q.push(make_pair(vx, vy));
route[vx][vy] = min(route[vx][vy], route[ux][uy] + 1);
}
}
}
if (S[H - 1][W - 1] == '.') {
cout << -1 << endl;
} else {
int d = route[H - 1][W - 1];
cout << (cnt - d) << endl;
}
}
| #include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
int n,m;
int g[500][500];
int main(){
while(scanf("%d%d",&n,&m),n){
for(int i=0;i<n;i++)
for(int j=0;j<n;j++) g[i][j]=100000;
for(int i=0;i<m;i++){
int a,b;
scanf("%d%d",&a,&b);
g[a-1][b-1]=1;g[b-1][a-1]=1;
}
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
for(int k=0;k<n;k++) g[j][k]=min(g[j][k],g[j][i]+g[i][k]);
int res=0;
for(int i=1;i<n;i++) if(g[0][i]<=2)res++;
printf("%d\n",res);
}
} | 0 |