code_file1
stringlengths 80
4k
| code_file2
stringlengths 91
4k
| similar_or_different
int64 0
1
|
---|---|---|
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline T range(T l, T r) {
return uniform_int_distribution<T>(l, r)(rng);
}
inline void setin(string s) {
freopen(s.c_str(), "r", stdin);
}
inline void setout(string s) {
freopen(s.c_str(), "w", stdout);
}
template <typename T> void Min(T &a, T b) {
a = min(a, b);
}
template <typename T> void Max(T &a, T b) {
a = max(a, b);
}
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int N = 3e2 + 15;
int n, k;
string s;
int dp[2][N][N]; // dp[i][operation_applied][free_ones]
int a[N], p[N][N];
inline int add(int a, int b) {
a += b;
if(a >= mod)
a -= mod;
if(a < 0)
a += mod;
return a;
}
inline void add_t(int &a, int b) {
a = add(a, b);
}
inline void construct() {
int sz = 1;
for(int i = 1; i <= n && s[i] == '1'; ++i)
a[1] = i;
for(int i = a[1] + 1; i <= n; ++i) {
if(s[i] == '0') {
if(i + 1 <= n && s[i + 1] == '0')
a[++sz] = 0;
}
else {
int j = i;
while(j + 1 <= n && s[j + 1] == '1')
++j;
a[++sz] = j - i + 1;
i = j;
}
}
n = sz;
}
inline void solve() {
// dp[i][operation_applied][free_ones]
dp[(n + 1) & 1][0][0] = 1;
int sum = 0;
for(int i = n; i >= 1; --i) {
int bit = i & 1;
memset(dp[bit], 0, sizeof(dp[bit]));
for(int k = 0; k < N; ++k)
for(int t = 0; t < N; ++t)
p[k][t] = add(k && t ? p[k-1][t-1] : 0, dp[bit ^ 1][k][t]);
for(int k = 0; k < N; ++k) {
int val = 0;
for(int t = N - 1; t >= 0; --t) {
add_t(dp[bit][k][t], val);
if(k - a[i] - 1 >= 0 && t - a[i] - 1 >= 0)
add_t(dp[bit][k][t], add(p[k][t], -p[k - a[i] - 1][t - a[i] - 1]));
else
add_t(dp[bit][k][t], p[k][t]);
add_t(val, dp[bit ^ 1][k][t]);
}
}
sum += a[i];
}
}
inline void output() {
int ans = 0;
for(int i = 0; i < min(N, k + 1); ++i)
add_t(ans, dp[1][i][0]);
cout << ans << endl;
}
main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// setin("input.txt");
cin >> s >> k;
n = s.size();
s = '#' + s;
construct();
solve();
output();
return 0;
} | #include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}
void test_case() {
int n , r;
cin>>n>>r;
if(n >= 10) {
cout<<r<<endl;
return;
}
int ans = r + 100*(10-n);
cout<<ans<<endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout<<fixed<<setprecision(20);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int t = 1;
//cin >> t;
while(t--)
{
test_case();
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;
// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)
// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
// グラフ表現
using Graph = vector<vector<int>>;
// グラフの辺表現
using Edge = map<pair<int,int>,int>;
// n次元配列の初期化。第2引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
// 最大公約数
ll gcd(ll a,ll b){
if (a%b == 0) return(b);
else return(gcd(b, a%b));
}
// 最小公倍数
ll lcm(ll a, ll b){
return a*b/gcd(a, b);
}
int main()
{
cout << fixed << setprecision(15);
double n, m, d;
cin >> n >> m >> d;
if(d == 0){
cout << (m-1)/n << endl;
return 0;
}
double a = m-1;
double b = 2*(n-d);
double c = n*n;
cout << a*b/c << endl;
return 0;
} | #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <stack>
#include <complex>
#include <functional>
#include <tuple>
using namespace std;
#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
using ll = long long;
constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右下左上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, -1 };
constexpr int dy[] = { 0, 1, 0, -1, 1, 1 };
namespace {
template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// 標準出力
void Write(long long x, const char* end = "\n") { std::cout << x << end; }
template <typename T> void Write(const T& x, const char* end = "\n") { std::cout << x << end; }
template <typename T, typename U> void Write(const T& x, const U& y, const char* end = "\n") { std::cout << x << " " << y << end; }
template <typename T, typename U, typename V> void Write(const T& x, const U& y, const V& z, const char* end = "\n") { std::cout << x << " " << y << " " << z << end; }
//template <typename... Args> void Write(Args const&... args) { bool a = true; for (auto const& x : { args... }) { if (a) a = false; else std::cout << " "; std::cout << x; } std::cout << "\n"; }
template <typename T> void Write(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; ++i) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }
template <typename T> void Write(const std::vector<std::vector<T>>& x, const char* sep = " ", const char* end = "\n") { for (auto v : x) Write(v, sep, end); }
// 標準入力
struct Read {
std::size_t szi, szj;
Read(std::size_t _szi = 1, std::size_t _szj = 1) : szi(_szi), szj(_szj) {}
template <typename T> operator T () const { T a; std::cin >> a; return a; }
template <typename T> operator std::vector<T>() const { std::vector<T> a(szi); for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i]; return a; }
template <typename T> operator std::vector<std::vector<T>>() const {
std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
for (std::size_t i = 0; i < szi; ++i) for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j]; return a;
}
template <typename T, typename U> operator std::vector<std::pair<T, U>>() const {
std::vector<std::pair<T, U>> a(szi);
for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i].first >> a[i].second; return a;
}
};
struct Reads {
template <typename T> Reads(T& a) { std::cin >> a; }
template <typename T, typename U> Reads(T& a, U& b) { std::cin >> a >> b; }
template <typename T, typename U, typename V> Reads(T& a, U& b, V& c) { std::cin >> a >> b >> c; }
template <typename T, typename U, typename V, typename W> Reads(T& a, U& b, V& c, W& d) { std::cin >> a >> b >> c >> d; }
};
Read read;
}
int main() {
int n, m, d; Reads(n, m, d);
double ans;
// 隣同士の差がdであるものの個数の平均
ans = (double)((n - d) * 2) / (n * (double)n) * (m - 1);
if (d == 0) ans /= 2.0;
cout << fixed << setprecision(8) << ans << endl;
return 0;
}
| 1 |
#include<iostream>
#include<algorithm>
#include<vector>
#define F first
#define S second
#define PB push_back
using namespace std;
const int MAXN = 10005;
int sz[MAXN], par[MAXN];
vector<pair<int, pair<int, int> > > e;
int getpar(int x)
{
if(par[x] == -1)
return x;
return par[x] = getpar(par[x]);
}
bool add(int x, int y)
{
x = getpar(x), y = getpar(y);
if(x == y)
return false;
if(sz[x] < sz[y])
swap(x, y);
sz[x] += sz[y];
par[y] = x;
return true;
}
int main()
{
int n, m;
cin >> n >> m;
fill(par, par + n, -1);
fill(sz, sz + n, 1);
for(int i = 0; i < m; i++)
{
int x, y, w;
cin >> x >> y >> w;
e.PB({w, {x, y}});
}
sort(e.begin(), e.end());
int ans = 0;
for(auto x : e)
if(add(x.S.F, x.S.S))
ans += x.F;
cout << ans << endl;
return 0;
} | #include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
long long int INF = 1000000000000LL;
#define MAX_V 120000
struct edge{
long long int to, cost;
};
typedef pair<long long int, long long int> P;
vector<edge> G[MAX_V];
long long int d[MAX_V];
void shortest_path(int s, int V){
priority_queue<P, vector<P>, greater<P> > que;
for(int i = 0; i < V; i++){
d[i] = INF;
}
d[s] = 0;
que.push(P(0, s));
while(!que.empty()){
P p = que.top();
que.pop();
int v = p.second;
if(d[v] < p.first){
continue;
}
for(int i = 0; i < G[v].size(); i++){
edge e = G[v][i];
if(d[e.to] > e.cost + d[v]){
d[e.to] = d[v] + e.cost;
que.push(P(d[e.to], e.to));
}
}
}
}
int main(){
int V, E, s;
cin >> V >> E >> s;
for(int i = 0; i < E; i++){
int u, v, cost;
edge e;
cin >> u >> v >> cost;
e.cost = cost;
e.to = v;
G[u].push_back(e);
}
shortest_path(s, V);
for(int i = 0; i < V; i++){
if(d[i] == INF){
cout << "INF" << endl;
}else{
cout << d[i] << endl;
}
}
return 0;
}
| 0 |
#pragma target("avx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;
#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
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(A v) {
bool first = true;
string res = "{";
for (const auto& x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
//------ Believe yourself as a genius!!!!!! ------
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum[ohara], k, q;
int main(void) {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin >> n;
rep(i, n) cin >> a[i], sum[i] = a[i];
rrep(i, 1, n) sum[i] += sum[i - 1];
ans = LINF;
rrep(i, 1, n - 2) {
ll peace1, peace2, peace3, peace4, dis;
ll le = 0, ri = i - 1, mid;
while (ri - le > 1) {
mid = (le + ri) / 2;
if (sum[mid] >= sum[i] - sum[mid])
ri = mid;
else
le = mid;
}
dis = LINF;
rrep(j, le, ri + 1) {
if (dis >= abs(sum[j] - (sum[i] - sum[j]))) {
dis = abs(sum[j] - (sum[i] - sum[j]));
peace1 = sum[j];
peace2 = sum[i] - sum[j];
}
}
le = i + 1, ri = n - 2, mid;
while (ri - le > 1) {
mid = (le + ri) / 2;
if (sum[mid] - sum[i] >= sum[n - 1] - sum[mid])
ri = mid;
else
le = mid;
}
dis = LINF;
rrep(j, le, ri + 1) {
if (dis >= abs((sum[j] - sum[i]) - (sum[n - 1] - sum[j]))) {
dis = abs((sum[j] - sum[i]) - (sum[n - 1] - sum[j]));
peace3 = sum[j] - sum[i];
peace4 = sum[n - 1] - sum[j];
}
}
ans = min(ans, max({peace1, peace2, peace3, peace4}) -
min({peace1, peace2, peace3, peace4}));
}
Cout(ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
int main(){
ll N;
cin >> N;
vector<ll> A(N), B(N), C(N);
rep(i,N){
cin >> A[i];
}
rep(i,N){
if(A[i] > i){
cout << -1 << endl;
return 0;
}
}
rep(i,N-1){
if(A[i+1] - A[i] > 1){
cout << -1 << endl;
return 0;
}
}
map<ll,ll> mp;
rep(i,N){
B[i] = i-A[i];
mp[B[i]] = A[i];
}
rep(i,N-1){
if(B[i+1] < B[i]){
cout << -1 << endl;
return 0;
}
}
ll ans = 0;
for(auto& e:mp){
ans += e.second;
}
cout << ans
<< endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
int get_int(){int x;scanf("%d",&x);return x;}
typedef long long ll;
const int mod = 998244353;
inline int mul(int x,int y){return 1ll*x*y%mod;}
int add(int x,int y) {return x+y>=mod?x+y-mod:x+y;}
int sub(int x,int y) {return x-y>=0?x-y:x-y+mod;}
int sq(int x){return 1ll*x*x%mod;}
int pows(int a,int b){return b == 0?1:(b&1?mul(a,sq(pows(a,b/2))):sq(pows(a,b/2)));}
const int maxn = 305;
int cnt[maxn*maxn];
int cnt2[maxn*maxn];
int sum;
int N;
void cal(int n,vector<int> &vi){
cnt[0] = 1;
cnt2[0] = 1;
_for(i,0,N){
int l = vi[i];
for(int j = sum;j>=0;j--){
cnt2[j] = add(cnt2[j],cnt2[j]);
if(j-l >= 0) {
cnt[j] = add(cnt[j],cnt[j-l]);
cnt2[j] = add(cnt2[j],cnt2[j-l]);
}
}
}
}
int main()
{
vector<int> vi;
N = get_int();
_for(i,0,N){
int num = get_int();
sum += num;
vi.push_back(num);
}
sort(ALL(vi));
int ans = pows(3,N);
//printf("all:%d\n",ans);
cal(N,vi);
//_rep(i,0,sum) printf("%d\n",cnt2[i]);
_rep(i,(sum+1)/2,sum){
ans = sub(ans,mul(3,cnt2[i]));
//printf("%d\n",cnt2[i]);
}
if(!(sum&1)){
ans = add(ans,mul(cnt[sum/2],3));
}
printf("%d\n",ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
int main(){
int n;
cin >> n;
cout << n/3 << endl;
} | 0 |
#define _USE_MATH_DEFINES
#include <cmath>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<vector>
#include<cctype>
#define rep(i,start,n) for(int i=start;i<n;i++)
#define And &&
#define Or ||
#define Lb cout<<endl
using namespace std;
int main(void) {
string str; cin >> str;
int q; cin >> q;
string meirei, x;
int a, b;
rep(i, 0, q) {
cin >> meirei;
cin >> a >> b;
if (meirei == "replace") {
cin >> x;
rep(j, 0, x.length()) {
str[a + j] = x[j];
}
}
else if (meirei == "reverse") {
rep(j, 0, (b - a + 1) / 2) {
char temp;
temp = str[a + j];
str[a + j] = str[b - j];
str[b - j] = temp;
}
}
else {
rep(j, 0, (b - a + 1)) {
cout << str[a + j];
}
cout << endl;
}
}
} | #include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
int main()
{
string S;
cin >> S;
int n;
cin >> n;
for(int i=0; i<n; ++i){
string order;
cin >> order;
if( order == "print"){
int a, b;
cin >> a >> b;
string sub = S.substr(a,b-a+1);
cout << sub << endl;
}else if( order == "reverse"){
int a, b;
cin >> a >> b;
reverse(S.begin()+a, S.begin()+b+1);
}if( order == "replace"){
int a, b;
string r;
cin >> a >> b >> r;
S.replace(a, b-a+1, r);
}
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
priority_queue<int, vector<int>, greater<int>> pq;
for (int i = 0; i < n; ++i) {
int x; cin >> x;
if (pq.size() < k) pq.push(x);
else if (pq.size() >= k && x > pq.top()) {
pq.pop();
pq.push(x);
}
}
int res = 0;
while (!pq.empty()) {
res += pq.top(); pq.pop();
}
cout << res << "\n";
}
| /** Created by: Marcos Portales
Codeforces User: marcosportales
Country: Cuba
Copyright */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,x,y) for(int i=(x);i<(y);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 400010;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Test.insert(x)late ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long , null_type , less<long long> , rb_tree_tag , tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
if( !e ) return 1;
if( e & 1 ) return qpow(b,e-1) * b % mod;
int pwur = qpow(b,e>>1);
return (pwur * pwur) % mod;
}
int modinv(int x){
return qpow(x,mod-2);
}
/// My Code -------------------------------------------------
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cout.setf(ios::fixed); cout.precision(0);
srand(time(NULL));
//freopen("a.in","r",stdin);
//freopen("a.in","w",stdout);
int n,k;
cin>>n>>k;
vi v(n);
rep(i,n){
cin>>v[i];
}
sort(rall(v));
int ans=0;
rep(i,k){
ans+=v[i];
}
cout<<ans;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 123456789;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;
#define Endl endl
/*--------------------template--------------------*/
class UF
{
public:
vi rank, p;
UF() {}
UF(ll size)
{
rank.resize(size, 0);
p.resize(size, 0);
REP(i, size)
{
makeSet(i);
}
}
void makeSet(ll x)
{
p[x] = x;
rank[x] = 0;
}
bool same(ll x, ll y)
{
return findSet(x) == findSet(y);
}
void unite(ll x, ll y)
{
link(findSet(x), findSet(y));
}
void link(ll x, ll y)
{
if (rank[x] > rank[y])
{
p[y] = x;
}
else
{
p[x] = y;
if (rank[x] == rank[y])
{
rank[y]++;
}
}
}
ll findSet(ll x)
{
if (x != p[x])
{
p[x] = findSet(p[x]);
}
return p[x];
}
};
class Edge
{
public:
ll source, target, cost;
Edge(ll source = 0, ll target = 0, ll cost = 0) : source(source), target(target), cost(cost) {}
bool operator<(const Edge &e) const
{
return cost < e.cost;
}
};
ll kruskal(ll n, vector<Edge> edges)
{
ll totalCost = 0;
sort(ALL(edges));
UF dset = UF(n + 1);
REP(i, n)
{
dset.makeSet(i);
}
ll source, target;
REP(i, edges.size())
{
Edge e = edges[i];
if (!dset.same(e.source, e.target))
{
totalCost += e.cost;
dset.unite(e.source, e.target);
}
}
return totalCost;
}
int main()
{
ll cost, source, target;
cin >> n >> m;
vector<Edge> edges;
REP(i, m)
{
cin >> source >> target >> cost;
edges.push_back(Edge(source, target, cost));
}
cout << kruskal(n, edges) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
for(int i=0;i<(int)(s.size());++i) {
cout << s[i];
if(i == (int)(s.size())-1) cout << endl;
else cout << " ";
}
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
os << p.first << ":" << p.second;
return os;
}
template<typename T>
struct edge {
int src, to;
T cost;
// edge(int src, int to, T cost): src(src), to(to), cost(cost) {}
// // G[i].push_back({src, to, cost}) requires no constructor
};
template<typename T>
using Graph = vector<vector<edge<T>>>;
template<typename T>
struct SCC {
int sz, cnt, num;
vi post, comp;
vector<pair<int, int>> vp;
vector<bool> sel;
Graph<T> revg;
SCC(int sz): sz(sz) {
cnt = 0;
num = 0;
post.resize(sz, -1);
comp.resize(sz, -1);
sel.resize(sz, false);
revg.resize(sz);
}
void build(const Graph<T> &g) {
for(int i=0;i<sz;++i) {
if(sel[i]) continue;
sel[i] = true;
dfs1(g, i);
}
rev(g, revg);
for(int i=0;i<sz;++i) {
vp.emplace_back(make_pair(post[i], i));
}
sort(vp.begin(), vp.end());
reverse(vp.begin(), vp.end());
sel.clear();
sel.resize(sz, false);
for(int i=0;i<sz;++i) {
if(sel[vp[i].second]) continue;
sel[vp[i].second] = true;
comp[vp[i].second] = num;
dfs2(revg, vp[i].second);
num++;
}
}
vi get_comp() {return comp;}
Graph<T> build_graph(const Graph<T> &g) {
build(g);
vector<set<int>> s(sz);
Graph<T> res(sz);
for(int i=0;i<sz;++i) {
for(int j=0;j<(int)(g[i].size());++j) {
s[comp[i]].insert(comp[g[i][j].to]);
}
}
for(int i=0;i<sz;++i) {
for(auto j: s[i]) {
if(i != j) res[i].push_back(edge<int>({i, j, 1}));
}
}
return res;
}
void dfs1(const Graph<T> &g, int now) {
for(int i=0;i<(int)(g[now].size());++i) {
int nxt = g[now][i].to;
if(sel[nxt]) continue;
sel[nxt] = true;
dfs1(g, nxt);
}
post[now] = cnt;
cnt++;
}
void rev(const Graph<T> &g, Graph<T> &revg) {
for(int i=0;i<sz;++i) {
for(int j=0;j<(int)(g[i].size());++j) {
revg[g[i][j].to].push_back({
g[i][j].to, g[i][j].src, g[i][j].cost});
}
}
}
void dfs2(const Graph<T> &revg, int now) {
for(int i=0;i<(int)(revg[now].size());++i) {
int nxt = revg[now][i].to;
if(sel[nxt]) continue;
sel[nxt] = true;
comp[nxt] = num;
dfs2(revg, nxt);
}
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
int n, m; cin >> n >> m;
Graph<int> g(n);
for(int i=0;i<m;++i) {
int s, t; cin >> s >> t;
g[s].push_back({s, t ,1});
}
SCC<int> scc(n);
scc.build(g);
auto comp = scc.get_comp();
int q; cin >> q;
for(int i=0;i<q;++i) {
int u, v; cin >> u >> v;
cout << (comp[u] == comp[v]) << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
char a,b,c;
cin>>a>>b>>c;
int ans = 0;
if(a=='R'&&b=='R'&&c=='R')
ans = 3;
else if((a=='R' && b=='R')|| (b=='R'&&c=='R'))
ans= 2;
else if(a=='R'||b=='R'||c=='R')
ans =1;
cout<<ans;
return 0;
}
| #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main() {
int n = 10;
vector<int> a(n), b(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
sort(a.begin(), a.end(), greater<int>());
sort(b.begin(), b.end(), greater<int>());
cout << a[0] + a[1] + a[2] << " " << b[0] + b[1] + b[2] << endl;
return 0;
} | 0 |
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author rahdirigs
*/
#include <bits/stdc++.h>
using namespace std;
const int mxN = 310;
double dp[mxN][mxN][mxN];
bool vis[mxN][mxN][mxN];
int N;
class TaskJ {
public:
void solve(std::istream& in, std::ostream& out) {
in >> N;
int a[4] = {0};
for (int i = 0; i < N; i++) {
int x; in >> x;
a[x]++;
}
memset(vis, false, sizeof(vis));
double ans = rec(a[1], a[2], a[3]);
out << fixed << setprecision(12) << ans;
}
double rec(int x, int y, int z) {
double &ret = dp[x][y][z];
if (x < 0 || y < 0 || z < 0) return 0;
if (x == 0 && y == 0 && z == 0) return 0;
if (vis[x][y][z]) return ret;
vis[x][y][z] = true;
int rem = x + y + z;
double val = N + x * rec(x - 1, y, z) + y * rec(x + 1, y - 1, z) + z * rec(x, y + 1, z - 1);
return ret = val / rem;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
TaskJ solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ar array
#define endl '\n'
#define ll long long
#define in insert
#define pb push_back
#define vt vector
#define P_Q(x) priority_queue<x>
#define p_q(x) priority_queue<x, vector<x>, greater<x>>
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(ll i=a;i>=b;i--)
#define FOR(m) Rep(i,1,m)
#define For(m) Rep(i,0,m-1)
#define Rbl(x,a) for(auto &x : a)
#define FIO ios::sync_with_stdio(0); cin.tie(0);
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpii vector<pii>
#define vpll vector<pll>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define mod 1000000007
const int mxN = 301;
double dp[mxN][mxN][mxN] = {};
double p[mxN][mxN][mxN] = {};
ll n;
int main()
{
FIO
cin >> n;
int c[3] = {}, num;
For(n) cin >> num, c[--num]++;
ll one = c[0], two = c[1], three = c[2];
p[one][two][three] = 1;
for(int k = n; k >= 0; k--)
{
for(int j = n; j >= 0; j--)
{
for(int i = n; i >= 0; i--)
{
if(i+j+k == 0 || i+j+k > n)
continue;
dp[i][j][k] += p[i][j][k] * n / (i+j+k);
if(i > 0)
{
p[i-1][j][k] += p[i][j][k] * i / (i+j+k);
dp[i-1][j][k] += dp[i][j][k] * i / (i+j+k);
}
if(j > 0)
{
p[i+1][j-1][k] += p[i][j][k] * j / (i+j+k);
dp[i+1][j-1][k] += dp[i][j][k] * j / (i+j+k);
}
if(k > 0)
{
p[i][j+1][k-1] += p[i][j][k] * k / (i+j+k);
dp[i][j+1][k-1] += dp[i][j][k] * k / (i+j+k);
}
}
}
}
cout << fixed << setprecision(10) << dp[0][0][0] << endl;
} | 1 |
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
int n,m;
cin >> n >> m;
if(n == m){
cout << 2*m;
}
else{
cout << 2*max(m,n)-1;
}
} | #include <iostream>
using namespace std;
int main()
{
int a, b, ans = 0;
cin >> a >> b;
ans += max(a , b);
if(a == b) ans += max(a, b);
else ans += ans - 1;
cout << ans << endl;
return 0;
} | 1 |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <string>
#include <bitset>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;
const int INF = INT_MAX;
int main(void) {
int v, e, s, t, d;
scanf("%d %d", &v, &e);
int g[v][v];
rep(i, v) rep(j, v) g[i][j] = INF;
rep(i, v) g[i][i] = 0;
rep(i, e) {
scanf("%d %d %d", &s, &t, &d);
g[s][t] = d;
}
rep(k, v) {
rep(i, v) {
if (g[i][k] == INF) continue;
rep(j, v) {
if (g[k][j] == INF) continue;
g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
}
}
}
int flag = 1;
rep(i, v) {
if (g[i][i] < 0) {
flag = 0;
break;
}
}
if (flag) {
rep(i, v) {
rep(j, v) {
if (j) printf(" ");
if (g[i][j] == INF) printf("INF");
else printf("%d", g[i][j]);
}
printf("\n");
}
}
else printf("NEGATIVE CYCLE\n");
return 0;
} | /*
Problem 33
https://atcoder.jp/contests/abc088/tasks/abc088_d
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<int> dx = {0, 0, 1, -1};
vector<int> dy = {1, -1, 0, 0};
/* function */
/* main */
int main(){
int h, w;
cin >> h >> w;
vector<vector<bool>> grid(h, vector<bool>(w));
int ans = h * w;
for (int i = 0; i < h*w; i++) {
char c; cin >> c;
grid[i/w][i%w] = c == '.';
ans -= (c == '#'); // 黒マスの分あらかじめ引いとく
}
vector<vector<int>> dist(h, vector<int>(w, 0));
queue<pii> q;
q.emplace(0, 0);
dist[0][0] = 1;
while(!q.empty()) {
pii p = q.front(); q.pop();
int x = p.first, y = p.second;
for (int i = 0; i < dx.size(); i++) {
int nx = x + dx[i], ny = y + dy[i];
if (nx < 0 || h <= nx || ny < 0 || w <= ny) continue;
if (!grid[nx][ny] || dist[nx][ny] != 0) continue;
dist[nx][ny] = dist[x][y] + 1;
q.emplace(nx, ny);
}
}
cout << ((dist[h-1][w-1] == 0) ? -1 : ans - dist[h-1][w-1]) << '\n';
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DD long double
#define M 1000000007
#define INF 1e18
void setIO(string s = "") {
cin.sync_with_stdio(0); cin.tie(0);
if (s.size()) s += ".in", freopen(s.c_str(), "r", stdin);
}
int tt = 1;
void solve() {
set<int> nums;
int a;
while (cin >> a) nums.insert(a);
cout << ((nums.size() == 2) ? "Yes" : "No") << endl;
}
int main() {
setIO();
while (tt--) {
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define endl "\n"
typedef long long ll;
const int BIG_NUM = 1e9;
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int a, b, c;
cin >> a >> b >> c;
if(a == b && b != c) {
cout << "Yes";
} else if(b == c && c != a) {
cout << "Yes";
} else if(c == a && a != b) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
}
| 1 |
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
signed main(){
string s;
cin>>s;
cout<<s.substr(0,s.size()-8)<<endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.length()%2 != 0) {
cout << "No" << endl;
return 0;
}
else {
for (int i = 0; i < s.length(); i++) {
if (i%2==0 && s[i]!='h' || i%2==1 && s[i]!='i') {
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
} | 0 |
#include"bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;
int main() {
int a, b, c, d, e, k;
vector<int>at(5);
rep(i, 5)cin >> at[i];
cin >> k;
bool ans = true;
rep(i, 4)for (int j = i + 1; j < 5; j++)if (abs(at[i] - at[j]) > k)ans = false;
if (ans) {
cout << "Yay!" << endl;
}
else {
cout << ":(" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(){
int x[7];
bool q=true;
for(int i=0;i<6;i++){
cin>>x[i];
}
if(x[4]-x[0]>x[5])q=false;
if(q==true) cout<<"Yay!";
else cout<<":(";
cout<<"\n";
return 0;
} | 1 |
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;
typedef pair<int, int> P;
typedef pair<long long, long long> LLP;
int main() {
string N_str;
cin >> N_str;
int n = N_str.length();
vector<int> N(n, 0);
rep(i,n) N[i] = N_str[n - 1 - i] - '0';
vector<vector<int>> dp(n + 1, vector<int>(2, INF));
dp[0][0] = 0;
rep(i,n) rep(j,2) {
N[i] += j;
rep(A,10) {
int p = i + 1, q = 0;
int B = A - N[i];
if (B < 0) {
q = 1;
B += 10;
}
dp[p][q] = min(dp[p][q], dp[i][j] + A + B);
}
N[i] -= j;
}
cout << min(dp[n][0], dp[n][1] + 1) << endl;
return 0;
} | #include<iostream>
using namespace std;
int main(){
string s;
cin>>s;
int r=0;
for(int i=0;i<3;i++){
if(s[i]=='R')
r=1;
}
for(int i=0;i<2;i++){
if(s[i]=='R'){
if(s[i]==s[i+1])
r++;
}
}
cout<<r<<"\n";
}
| 0 |
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
#define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
#define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int N,X;
LL b[SIZE],l[SIZE],u[SIZE];
bool used[SIZE];
int main(){
R(N,X);
LL need=0;
priority_queue<PLL>h0,h1,h2;
REP(i,N){
R(b[i],l[i],u[i]);
need+=b[i]*l[i];
h0.push({l[i]*b[i]+u[i]*(X-b[i]),i});
}
LL an=0;
while(need>=h0.top().F){
an+=X;
used[h0.top().S]=1;
need-=h0.top().F;
h0.pop();
}
if(need<=0){
W(an);
return 0;
}
int add_id=h0.top().S;
LL add_v=l[add_id]*b[add_id]+u[add_id]*(X-b[add_id]);
LL mi=1e18;
REP(i,N){
if(used[i]){
LL need2=need-add_v+l[i]*b[i]+u[i]*(X-b[i]);
if(l[i]*b[i]>=need2){
mi=min(mi,(need2+l[i]-1)/l[i]);
}
else{
mi=min(mi,(need2-l[i]*b[i]+u[i]-1)/u[i]+b[i]);
}
}
else{
if(l[i]*b[i]+u[i]*(X-b[i])<need)continue;
if(l[i]*b[i]>=need){
mi=min(mi,(need+l[i]-1)/l[i]);
}
else{
mi=min(mi,(need-l[i]*b[i]+u[i]-1)/u[i]+b[i]);
}
}
}
an+=mi;
W(an);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)
typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());
const int N = 1e5+100;
ll n, x, s;
ll B[N], L[N], U[N], su[N], idx[N];
ll ans = LINF;
V<pair<ll, int>> v;
ll check(ll m, int i){
int j = idx[i];
ll ss = (j<m ? su[m+1]-v[j].fi : su[m]);
if(ss>=s) return x*m;
if(ss+L[i]*B[i]>=s) return x*m + (s-ss+L[i]-1)/L[i];
if(ss+v[j].fi>=s) return x*m + (s-ss+(U[i]-L[i])*B[i]+U[i]-1)/U[i];
return LINF;
}
main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> x;
FOR(i, 0, n){
ll b, l, u;
cin >> b >> l >> u;
B[i] = b;
L[i] = l;
U[i] = u;
s += b*l;
v.pb(mp(u*(x-b)+l*b, i));
}
sort(all(v));
reverse(all(v));
FOR(i, 0, n){
su[i+1] += su[i]+v[i].fi;
idx[v[i].se] = i;
}
FOR(i, 0, n){
int j = idx[i], l = -1, r = n-1, m;
while(r-l>1){
m = (r+l)/2;
if(check(m, i)<LINF){
r = m;
}else{
l = m;
}
}
mins(ans, check(r, i));
}
cout << ans << endl;
} | 1 |
#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++)
static long Gcd(long m, long n)
{
long temp;
while (m % n != 0)
{
temp = n;
n = m % n;
m = temp;
}
return n;
}
int charToInt(char c){
char zero_num = '0';
return (int)c - (int)zero_num;
}
map< int, int > prime_factor(int n) {
map< int, int > ret;
for(int64_t i = 2; i * i <= n; i++) {
while(n % i == 0) {
ret[i]++;
n /= i;
}
}
if(n != 1) ret[n] = 1;
return ret;
}
signed main(){
int A, B;cin>>A>>B;
int gcd = Gcd(A,B);
/* vec_int factors;
for(int i=1;i*i<=gcd;i++){
if(gcd%i==0){
factors.push_back(i);
factors.push_back(gcd/i);
}
}
sort(factors.begin(), factors.end());
*/
map<int, int> pfs = prime_factor(gcd);
cout<<pfs.size()+1<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
class UnionFind
{
public:
vector<int> parent;
UnionFind(int N)
{
for (int i = 0; i < N; i++)
{
parent.push_back(-1);
}
}
int root(int A)
{
if (parent[A] < 0)
return A;
return parent[A] = root(parent[A]);
}
int size(int A)
{
return -parent[root(A)];
}
bool unite(int A, int B)
{
A = root(A);
B = root(B);
if (A == B)
return false;
if (size(A) < size(B))
swap(A, B);
parent[A] += parent[B];
parent[B] = A;
return true;
}
};
vector<pair<long long, long long>> prime(long long N)
{
vector<pair<long long, long long>> res;
for (long long i = 2; i * i <= N; i++)
{
if (N % i != 0)
continue;
long long ex = 0;
while (N % i == 0)
{
ex++;
N = N / i;
}
res.push_back({i, ex});
}
if (N != 1)
res.push_back({N, 1});
return res;
}
int main(void)
{
long long A, B;
cin >> A >> B;
vector<pair<long long, long long>> PA = prime(A);
vector<pair<long long, long long>> PB = prime(B);
map<long long, long long> result;
for (int i = 0; i < PA.size(); i++)
{
result[PA[i].first]++;
}
for (int i = 0; i < PB.size(); i++)
{
result[PB[i].first]++;
}
long long count = 1;
for (auto ans : result)
{
if (ans.second == 2)
count++;
}
cout << count << endl;
return 0;
}
| 1 |
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;
using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)
vector<vector<pair<int, ll>>> eda(100000 + 5); // pair には num, dist
vector<ll> dist(100000 + 5);
void makeCost(int n, int k)
{
queue<pair<pair<int,ll>, int>> q; // pair には ((num, dist) from)
dist[k] = 0;
for (auto a : eda[k]) {
q.push(make_pair(a, k));
}
while (!q.empty()) {
auto now = q.front();
q.pop();
int number = now.first.first;
int from = now.second;
ll distance = now.first.second;
dist[number] = dist[from] + distance;
for (auto tmp : eda[number]) {
if (tmp.first == from) continue;
q.push(make_pair(tmp, number));
}
}
}
int main()
{
int n;
cin >> n;
for (int i = 1; i < n; i++) {
ll a, b, c;
cin >> a >> b >> c;
eda[a].push_back(make_pair(b, c));
eda[b].push_back(make_pair(a, c));
}
int q, k;
cin >> q >> k;
makeCost(n, k);
rep (i, q) {
int x, y;
cin >> x >> y;
cout << dist[x] + dist[y] << endl;
}
}
| #include<iostream>
using namespace std;
int n, m, k;
int t[100][100], c[100][100];
int INF = 1<<21;
void solve(){
for(int k = 0; k < m; k++){
for(int i = 0; i < m; i++){
for(int j = 0; j < m; j++){
t[i][j] = min(t[i][j], t[i][k] + t[k][j]);
c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
}
}
}
}
int main(){
while(1){
cin >> n >> m;
if(n + m == 0) break;
for(int i = 0; i < m; i++){
for(int j = 0; j < m; j++){
c[i][j] = t[i][j] = INF;
}
}
int a, b, cost, tim;
for(int i = 0; i < n; i++){
cin >> a >> b >> cost >> tim;
a--; b--;
c[a][b] = c[b][a] = cost;
t[a][b] = t[b][a] = tim;
}
solve();
cin >> k;
int p, q, r;
for(int i = 0; i < k; i++){
cin >> p >> q >> r;
p--; q--;
if(r == 0) cout << c[p][q] << endl;
else if(r == 1) cout << t[p][q] << endl;
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
#include <set>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;
const int MOD = 998244353;
long long ruizyou(long long m,long long n){
if(m == 0)return 0;
if(m == 1)return 1;
long long ans = 1;
long long tmp = m;
for(int i=0;i<=30;i++){
if(n & (1<<i)){
ans *= tmp;
ans %= MOD;
}
tmp *= tmp;
tmp %= MOD;
}
return ans;
}
long long kaizyou(long long x){
if(x == 0)return 1;
return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
long long bunsi = kaizyou(x);
long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
return bunsi * ruizyou(bunbo,MOD-2) % MOD;
}
struct unionfind{
vector<int> par;
vector<vector<int>> children;
vector<int> hukasa;
vector<int> kazu;
unionfind(int n){
par = vector<int>(n);
hukasa = vector<int>(n,0);
kazu = vector<int>(n,1);
for(int i=0;i<n;i++){
par.at(i) = i;
}
}
int root(int x){
if(par.at(x) == x)return x;
return root(par.at(x));
}
void unite(int x,int y){
int rx = root(x);
int ry = root(y);
if(rx == ry)return;
if(hukasa.at(rx) >= hukasa.at(ry)){
par.at(ry) = rx;
hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
kazu.at(rx) += kazu.at(ry);
}
else{
par.at(rx) = ry;
kazu.at(ry) += kazu.at(rx);
}
}
void newkazu(){
int n = kazu.size();
for(int i=0;i<n;i++){
kazu.at(i) = kazu.at(root(i));
}
}
bool same(int x,int y){
return root(x) == root(y);
}
};
int ctoi(char a){
return a - '0';
}
long long gcd(long long a,long long b){
long long c = max(a,b);
long long d = min(a,b);
if(d % c == 0)return c;
return gcd(c,d%c);
}
long long lcm(long long a,long long b){
return a * b / gcd(a,b);
}
int main(){
int h,w;
cin >> h >> w;
vector<vector<char>> s(h,vector<char>(w));
for(int i=0;i<h;i++){
for(int j=0;j<w;j++)cin >> s.at(i).at(j);
}
vector<vector<int>> table(h,vector<int>(w,-1));
queue<pii> q;
q.push(pii(0,0));
table.at(0).at(0) = 1;
bool flag = false;
int count;
while(!q.empty()){
pii tmppair = q.front();
q.pop();
int x,y;
tie(x,y) = tmppair;
set<pii> se;
if(x-1 >= 0)se.insert(pii(x-1,y));
if(x+1 < h)se.insert(pii(x+1,y));
if(y-1 >= 0)se.insert(pii(x,y-1));
if(y+1 < w)se.insert(pii(x,y+1));
for(auto t:se){
int tx,ty;
tie(tx,ty) = t;
if(s.at(tx).at(ty) == '.' && table.at(tx).at(ty) == -1){
table.at(tx).at(ty) = table.at(x).at(y) + 1;
q.push(t);
}
if(t == pii(h-1,w-1)){
count = table.at(tx).at(ty);
flag = true;
break;
}
}
if(flag) break;
}
if(!flag) cout << -1 << endl;
else{
int count2 = 0;
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(s.at(i).at(j) == '#')count2++;
}
}
cout << h * w - count - count2 << endl;
}
} | #include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
int h,w;
int arr[105][105];
bool visited[105][105];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int main(){
int white=0;
cin>>h>>w;
for(int i=1; i<=h; i++){
string s;
cin>>s;
for(int j=0; s[j]; j++){
if(s[j]=='.'){
arr[i][j+1] = 1;
white++;
}
}
}
queue<pair<pi,int> >q;
q.push(make_pair(pi(1,1),1));
visited[1][1] = true;
while(!q.empty()){
pair<pi,int> curr = q.front();
int y = curr.first.first;
int x = curr.first.second;
int d = curr.second;
q.pop();
if(y==h && x==w){
cout<<white-d;
return 0;
}
for(int i=0; i<4; i++){
int yy = y+dy[i];
int xx = x+dx[i];
if(yy<1 || xx<1 || yy>h || xx>w) continue;
if(!visited[yy][xx] && arr[yy][xx]){
visited[yy][xx] = true;
q.push(make_pair(pi(yy,xx),d+1));
}
}
}
cout<<-1;
} | 1 |
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(x.rbegin(), x.rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MAXI(x) max_element(ALL(x)) - x.begin()
#define SUM(x) accumulate(ALL(x), 0ll)
#define COUNT(x, y) count(ALL(x), y);
#define ANS cout << ans << "\n"
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define Yes cout << "Yes\n";
#define No cout << "No\n";
#define YN YES else NO
#define yn Yes else No
#define init() \
cin.tie(0); \
ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v) \
cerr << "[debugV] " << #v << ":"; \
rep(z, v.size()) cerr << " " << v[z]; \
cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
using vp = vector<P>;
using vs = vector<string>;
template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
rep(j, v.size()) i >> v[j];
return i;
}
template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
return i >> v.first >> v.second;
}
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
return to_string(x).size();
}
ll gcd(ll x, ll y) {
return y ? gcd(y, x % y) : x;
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
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;
}
void rec(ll v, const vvll& G, vector<bool>& seen, vll& order) {
seen[v] = true;
for (auto next : G[v]) {
if (seen[next]) continue;
rec(next, G, seen, order);
}
order.push_back(v);
}
signed main() {
init();
ll N, M;
cin >> N >> M;
vvll G(N);
vvll G2(N);
rep(i, N + M - 1) {
ll a, b;
cin >> a >> b;
a--;
b--;
G[a].pb(b);
G2[b].pb(a);
}
vector<bool> seen(N, 0);
vll order;
rep(i, N) {
if (seen[i]) continue;
rec(i, G, seen, order);
}
REVERSE(order);
vll order2(N);
rep(i, N) order2[order[i]] = i;
rep(i, N) {
ll max_index = -1;
ll ma = -1;
for (auto gg : G2[i])
if (ma < order2[gg]) {
max_index = gg;
ma = order2[gg];
}
COUT(max_index + 1);
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
int a[200000], vs[200000],vs1[100006],p[300000];
vector<int>v[200000];
queue<int>q;
int f(int n)
{
int i, k=0;
vs[n]=1; q.push(n);
while(q.size()){
n=q.front(); q.pop();
for(i=0; i<v[n].size(); i++){
if(vs1[v[n][i]]==1){
p[v[n][i]]=n;
q.push(v[n][i]);
}
else vs1[v[n][i]]--;
}
}
return 1;
}
int main()
{
IO;
int i, j, m, k, n, t, l=0, mx,ll,mxx,mx1;
cin>>n>>m;
for(i=1; i<=n+m-1; i++){
cin>>j>>k;
v[j].push_back(k);
vs1[k]++;
}
for(i=1; i<=n; i++)
if(vs1[i]==0)k=i;
f(k);
for(i=1; i<=n; i++) cout<<p[i]<<endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
struct int_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
struct pair_hash {
size_t operator()(pii x) const {
return int_hash{}(x.first) ^ (int_hash{}(x.second) << 16);
}
};
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<cd> vcd;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pii>> vvpii;
typedef vector<vector<pll>> vvpll;
typedef unordered_map<int, int, int_hash> umpii;
typedef unordered_map<ll, ll, int_hash> umpll;
typedef unordered_set<int, int_hash> usi;
typedef unordered_set<ll, int_hash> usll;
typedef unordered_set<pii, pair_hash> uspii;
typedef queue<int> qi;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = numeric_limits<int>::max();
const int MX = 100001; //check the limits, dummy
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n; cin >> n;
vpii v(n, {0, 0});
F0R(i, n) {
cin >> v[i].f;
cin >> v[i].s;
}
sort(v.begin(), v.end(), [](const pii &p1, const pii &p2){ return p1.f + p1.s < p2.f + p2.s; });
vvi dp(n + 1, vi(n + 1, inf));
dp[0][0] = 0;
int ans = 0;
F0R(i, n) {
F0R(j, i + 1) {
dp[i + 1][j + 1] = min(dp[i][j + 1], v[i].f >= dp[i][j] ? dp[i][j] + v[i].s : inf);
ans = max(ans, dp[i + 1][j + 1] == inf ? 0 : j + 1);
}
}
cout << ans << endl;
}
|
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */
using namespace std;
/* g++ -g -std=c++11 */
/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define FOR(i,a,b) for (int i=(a); i < (b); ++i)
#define FORR(i,a,b) for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c) for (__typeof((c).begin()) i=(c).begin(); \
i != (c).end(); ++i)
#define FOR_ALLR(i,c) for (__typeof((c).rbegin()) i=(c).rbegin(); \
i != (c).rend(); ++i)
#define SZ(array) (sizeof(array)/sizeof(array[0]))
#define lc(x) (x<<1) /* 2*x */
#define rc(x) (x<<1 | 1) /* 2*x+1 */
#define lowbit(x) (x & (-x)) /* 0b10100 -> 0b100 */
typedef long long LL;
typedef map<int,int> MII;
typedef pair<int,int> PII;
typedef set<int> SI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<int> VI;
typedef vector<string> VS;
/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }
const LL inf = 1e16;
VI H,P, sorted;
bool cmp(const int i, const int j)
{ return H[i]+P[i] < H[j]+P[j]; }
int main()
{
#ifdef foo_
freopen("foo", "rt", stdin);
#endif
ios::sync_with_stdio(false);
int n;
while (cin >> n) {
H = P = sorted = VI(n);
FOR(i,0,n) {
cin >> H[i] >> P[i];
sorted[i] = i;
}
sort(ALL(sorted),cmp);
vector<LL> dp = vector<LL>(n+1,inf);
dp[0] = 0; int ans = 0;
FOR(i,0,n) {
const int j = sorted[i];
FORR(x,n-1,-1) if (dp[x] != inf && dp[x] <= H[j]) {
dp[x+1] = min(dp[x+1], dp[x]+P[j]);
ans = max(ans, x+1);
}
}
cout << ans << endl;
}
return 0;
}
| 1 |
#include<iostream>
#include<vector>
#include<algorithm>
int n,x;
std::vector<int> vec;
long long int num(){
long long int lli=0;
for(auto v:vec){
lli+=static_cast<long long int>(v);
}
return lli;
}
int main(){
std::cin>>n;
for(int i=0;i<n;++i){
std::cin>>x;
vec.push_back(x);
}
sort(vec.begin(),vec.end());
std::cout<<*vec.begin()<<" "<<*(vec.end()-1)<<" "<<num()<<std::endl;
return 0;
} | /* ░░█ ▄▀█ █ █▀ █░█ █▀█ █▀▀ █▀▀ █▀█ ▄▀█ █▀▄▀█
█▄█ █▀█ █ ▄█ █▀█ █▀▄ ██▄ ██▄ █▀▄ █▀█ █░▀░█ */
// Author : Udit "luctivud" Gupta @ (https://www.linkedin.com/in/udit-gupta-1b7863135/)
#include <bits/stdc++.h>
#pragma GCC optimize "trapv"
using namespace std;
typedef long long int lld;
typedef unsigned long long int llu;
#define TESTCASES() cin >> (T3X0); T353 = T3X0; while(T3X0--)
#define _input(V3C) for(auto &V3C_I7 : (V3C)) cin >> (V3C_I7)
#define mems(A77AY, V4LU) memset((A77AY), (V4LU), sizeof((A77AY)))
#define CH3K(I7, E4, S7) (((S7)<0) ? (I7)>(E4) : (I7)<(E4))
#define for4(I7,S4,E4,S7) for(auto I7=(S4); CH3K(I7,E4,S7); (I7)+=(S7))
void solveEachTest(lld T35TC453N = 1) {
int ans = 0;
int n ; cin >> n;
string a, b, c;
cin >> a >> b >> c;
for (int i = 0; i < n; i++) {
set <char> se;
se.insert(a[i]);
se.insert(b[i]);
se.insert(c[i]);
ans += (se.size() - 1);
}
cout << ans;
cout << "\n";
return;
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0);
lld T3X0 = 0, T353 = 1;
// TESTCASES()
solveEachTest(T353 - T3X0);
return 0;
}
| 0 |
#include<bits/stdc++.h>
#define ls (p<<1)
#define rs (p<<1|1)
using namespace std;
/*
需要维护的是
a[i]区间最大值
a[i]-i的区间最小值
*/
#define inf 1000000
#define M 200005
int f[M<<2],laz[M<<2],mx[M<<2];
int n,m;
int res,pos;
void up(int p){
mx[p]=max(mx[ls],mx[rs]);
f[p]=min(f[ls],f[rs]);
}
void down(int l,int mid,int r,int p){
if (laz[p]){
laz[ls]=laz[rs]=laz[p];
mx[ls]=mx[rs]=laz[p];
f[ls]=laz[p]-mid;
f[rs]=laz[p]-r;
laz[p]=0;
}
}
void build(int l,int r,int p){
if (l==r){
mx[p]=l;
f[p]=0;
return ;
}
int mid=(l+r)>>1;
build(l,mid,ls);
build(mid+1,r,rs);
up(p);
}
void pt(int l,int r,int p){
if (l==r){
printf("%d ",mx[p]);
return ;
}
int mid=(l+r)>>1;
down(l,mid,r,p);
pt(l,mid,ls);
pt(mid+1,r,rs);
up(p);
}
void qu(int l,int r,int p){
if (mx[p]<pos)return;
if (l==r){
res=l;
return;
}
int mid=(l+r)>>1;
down(l,mid,r,p);
qu(l,mid,ls);
if (res)return;
qu(mid+1,r,rs);
}
int qu(int k){
res=0;
pos=k;
qu(1,m+1,1);
return res;
}
void upd(int l,int r,int x,int y,int k,int p){
if (l==x&&r==y){
laz[p]=k;
mx[p]=k;
f[p]=k-r;
return ;
}
int mid=(l+r)>>1;
down(l,mid,r,p);
if (y<=mid){
upd(l,mid,x,y,k,ls);
}
else if (x>mid){
upd(mid+1,r,x,y,k,rs);
}
else{
upd(l,mid,x,mid,k,ls);
upd(mid+1,r,mid+1,y,k,rs);
}
up(p);
}
void upd(int l,int r,int k){
int resl=qu(l);
int resr=qu(r+1)-1;
// printf("%d %d\n",resl,resr);
if (resl<=resr&&resr<=m)upd(1,m+1,resl,resr,k,1);
}
int qu(int l,int r,int x,int y,int p){
if (l==x&&r==y){
// printf("%d %d %d\n",x,y,f[p]);
return f[p];
}
int mid=(l+r)>>1;
down(l,mid,r,p);
if (y<=mid)return qu(l,mid,x,y,ls);
if (x>mid)return qu(mid+1,r,x,y,rs);
return min(qu(l,mid,x,mid,ls),qu(mid+1,r,mid+1,y,rs));
}
int calc(int i){
int res=qu(1,m+1,1,m,1);
if (res>=m)return -1;
return res+i;
}
/*
4 4
2 4
1 1
2 3
2 4
*/
int main(){
// freopen("1.in","r",stdin);
scanf("%d%d",&n,&m);
int i,l,r;
build(1,m+1,1);
for (i=1;i<=n;i++){
scanf("%d%d",&l,&r);
if (r==m){
upd(l,r,inf);
}
else{
upd(l,r,r+1);
}
// pt(1,m+1,1); printf("\n");
printf("%d\n",calc(i));
}
return 0;
} | #ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
static const LL INF = 1LL << 60;
template<typename T, int SIZE, T DEF_VAL, const T& Compare(const T&, const T&)>
class SegmentTree {
vector<T> val;
public:
SegmentTree() : val(SIZE * 2, DEF_VAL) { }
void update(int i, const T& value) {
i += SIZE;
val[i] = value;
while (i > 1) i >>= 1, val[i] = Compare(val[i * 2], val[i * 2 + 1]);
}
T get(LL a, LL b, int l = 0, int r = SIZE, size_t i = 1) {
if (r <= a || b <= l) return DEF_VAL;
if (a <= l && r <= b) return val[i];
return Compare(get(a, b, l, (l + r) / 2, i * 2), get(a, b, (l + r) / 2, r, i * 2 + 1));
}
LL find_leftmost_index(LL a, LL b, const T& value, int l = 0, int r = SIZE, int i = 1) {
if (Compare(val[i], value) != val[i]) return -1;
if (r <= a || b <= l) return -1;
if (i >= SIZE) return i - SIZE;
LL leftmost_index = find_leftmost_index(a, b, value, l, (l + r) / 2, i * 2);
if (leftmost_index >= 0) return leftmost_index;
return find_leftmost_index(a, b, value, (l + r) / 2, r, i * 2 + 1);
}
LL find_rightmost_index(LL a, LL b, const T& value, int l = 0, int r = SIZE, int i = 1) {
if (Compare(val[i], value) != val[i]) return -1;
if (r <= a || b <= l) return -1;
if (i >= SIZE) return i - SIZE;
LL rightmost_index = find_rightmost_index(a, b, value, (l + r) / 2, r, i * 2 + 1);
if (rightmost_index >= 0) return rightmost_index;
return find_rightmost_index(a, b, value, l, (l + r) / 2, i * 2);
}
};
void solve(long long H, long long W, std::vector<long long> &A, std::vector<long long> &B) {
SegmentTree<long long, 1 << 18, INF, min> st;
for (int i = 0; i < W; ++i) {
st.update(i, 0);
}
for (LL y = 0; y < H; ++y) {
LL a = A[y], b = B[y];
while (true) {
LL min_value = st.get(a, b);
if (min_value == INF) break;
LL index = st.find_leftmost_index(a, b, min_value);
LL next_cost = min_value + b - index;
if (b < W && next_cost < st.get(b, b + 1)) {
st.update(b, next_cost);
}
st.update(index, INF);
}
LL cost = y + 1 + st.get(0, W);
cout << (cost < INF ? cost : -1) << endl;
}
}
int main() {
long long H;
scanf("%lld", &H);
long long W;
scanf("%lld", &W);
std::vector<long long> A(H);
std::vector<long long> B(H);
for (int i = 0; i < H; i++) {
scanf("%lld", &A[i]); A[i]--;
scanf("%lld", &B[i]);
}
solve(H, W, A, B);
return 0;
}
| 1 |
#include<stdio.h>
#include<string.h>
#define PRINT "print"
#define REVER "reverse"
#define REPLA "replace"
int main(){
int a,b,q,i,j,k;
char tmp;
char comm[20],str[1001],p[1001];
scanf("%s %d",str,&q);
for(i=0;i<q;i++){
scanf("%s",comm);
if(strcmp(comm,PRINT) == 0){
scanf("%d %d",&a,&b);
for(j=a;j<=b;j++){
printf("%c",str[j]);
}
printf("\n");
}else if(strcmp(comm,REVER) == 0){
scanf("%d %d",&a,&b);
while(a<b){
tmp = str[a];
str[a] = str[b];
str[b] = tmp;
a++;
b--;
}
}else if(strcmp(comm,REPLA) == 0){
scanf("%d %d %s",&a,&b,p);
for(j=a;j<=b;j++){
str[j] = p[j-a];
}
}
}
return 0;
} | #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main () {
// input
string str;
cin >> str;
int q;
cin >> q;
string result = str;
int res_len = result.length();
for (int i=0; i<q; i++) {
string order;
int a, b;
cin >> order >> a >> b;
if (order == "print") {
// output
cout << result.substr(a, b-a+1) << endl;
} else if (order == "reverse") {
string reversed = "";
for (int j=0; j<a; j++) {
reversed += result[j];
}
for (int jj=b; jj>a-1; jj--) {
reversed += result[jj];
}
for (int jjj=b+1; jjj<res_len; jjj++) {
reversed += result[jjj];
}
result = reversed;
//cout << reversed << endl;
} else if (order == "replace") {
string p;
cin >> p;
string replaced = "";
for (int k=0; k<a; k++) {
replaced += result[k];
}
for (int kk=a; kk<b+1; kk++) {
replaced += p[kk-a];
}
for (int kkk=b+1; kkk<res_len; kkk++) {
replaced += result[kkk];
}
result = replaced;
//cout << result << endl;
}
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll K;cin >> K;
ll x = K / 50;
ll y = K % 50;
vector<ll> ans;
cout << 50 << endl;
for (int i = 0;i < 51;i++) {
if (i + y != 50)
ans.push_back(i);
}
for (int i = 0;i < 50;i++) {
cout << ans[i] + x << " ";
}
} | #include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
using namespace std;
////////////// Prewritten code follows. Look down for solution. ////////////////
#define x first
#define y second
#define LEN(x) ((int)(x).size())
#define ALL(x) x.begin(), x.end()
using ll = long long;
using llu = long long unsigned;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vpii = vector<pii>;
const ld EPS = 1e-9;
inline int cmp(ld x, ld y = 0, ld tol = EPS) {
return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}
const int MOD = 1;
inline int mod(ll x, int m = MOD) {
return (int)(((x%m) + m)%m);
}
template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
////////////////////////// Solution starts below. //////////////////////////////
vector<string> vec = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
int main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(10);
string s;
cin >> s;
int ans = 0;
int p = 0;
while(vec[p] != s) ++p;
while(vec[p] != "SUN") {
p = (p+1)%7;
++ans;
}
if(!ans) ans += 7;
cout << ans << '\n';
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
struct edge{
int to,cost;
edge(){
to = 0; cost = 0;
}
edge(int t,int c){
to = t;
cost = c;
}
};
int n;
vector<edge> G[100001];
long long int d[100001];
const long long int INF = 1000000000000;
void Dijkstra(int s){
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > que;
fill(d,d+n,INF);
d[s] = 0;
que.push(make_pair(0,s));
while(!que.empty()){
pair<int,int> p = que.top(); que.pop();
int v = p.second;
if(d[v] < p.first){
continue;
}
for(int i=0; i<G[v].size(); i++){
edge e = G[v][i];
if(d[e.to] > d[v] + e.cost){
d[e.to] = d[v] + e.cost;
que.push(make_pair(d[e.to],e.to));
}
}
}
}
int main() {
cin >> n;
int ed,r;
cin >> ed >> r;
int a, b, c;
for (int i = 0; i < ed; i++) {
scanf(" %d %d %d", &a, &b, &c);
G[a].push_back(edge(b, c));
}
Dijkstra(r);
for (int i = 0; i < n; i++) {
if(d[i]!=INF){
cout << d[i] << endl;
}
else{
cout << "INF" << endl;
}
}
return 0;
} | #include<stdio.h>
int main(void)
{
int n,pm,pe,pj,i,j,pme,pmej;
scanf("%d",&n);
while(n!=0){
for(i=0;i<n;i++){
scanf("%d %d %d",&pm,&pe,&pj);
pme=(pm+pe)/2;
pmej=(pm+pe+pj)/3;
if(pm==100 || pe==100 || pj==100){
printf("A\n");
}
else if(pme>=90){
printf("A\n");
}
else if(pmej>=80){
printf("A\n");
}
else if(pmej>=70){
printf("B\n");
}
else if(pmej>=50 && pm>=80 || pe>=80){
printf("B\n");
}
else {
printf("C\n");
}
}
scanf("%d",&n);
}
return 0;
} | 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);
string s;
cin >> s;
vector<int> cnt(26,0);
for(int i = 0; i < s.size(); i++) {
cnt[s[i]-'a']++;
}
if(s.size()==26) {
int idx=25;
while(idx>0 && s[idx-1]>s[idx]) idx--;
if(idx==0) {
cout << "-1" << "\n";
return 0;
}
char e='z'+1;
for(int i = idx; i < s.size(); i++) if(s[idx-1]<s[i]) e=min(e,s[i]);
for(int i = 0; i < idx-1; i++) cout << s[i];
cout << e << "\n";
}
else{
cout << s;
int idx=0;
while(cnt[idx]!=0) idx++;
cout << char('a'+idx) << "\n";
}
return 0;
} | #include<iostream>
using namespace std;
int main(){
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
if (i % 3 ==0 || i % 10 == 3 || (i/10)%10==3|| (i/100)%10==3 || (i/1000)%10==3){
cout << " " << i;
}
}
cout << endl;
return 0;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7,inv2=5e8+4;
inline int poww(long long x,int y)
{
long long ret=1;
while(y)
{
if(y&1)ret*=x,ret%=MOD;
x*=x,x%=MOD;
y>>=1;
}
return ret;
}
int n,k;
long long dp[2333][2333];
long long fac[4555555],invfac[4555555];
inline long long c(int a,int b)
{
return fac[a]*invfac[b]%MOD*invfac[a-b]%MOD;
}
int main()
{
ios_base::sync_with_stdio(false);
cin>>n>>k;
if(k==1)return cout<<1<<endl,0;
fac[0]=1;
for(int i=1;i<=4000000;i++)fac[i]=fac[i-1]*i%MOD;
invfac[4000000]=poww(fac[4000000],MOD-2);
for(int i=4000000;i>=1;i--)invfac[i-1]=invfac[i]*i%MOD;
dp[n+1][n]=1;
for(int i=n;i>=1;i--)
{
long long sum=0;
for(int j=n;j>=i;j--)
{
sum+=dp[i+1][j];sum%=MOD;
dp[i][j]=c(n-j+(n-i)*(k-1)+k-2,k-2)*sum%MOD;
// cerr<<"dp "<<i<<','<<j<<'='<<dp[i][j]<<endl;
}
}
long long sum=0;
for(int i=1;i<=n;i++)sum+=dp[1][i];
cout<<sum%MOD*fac[n]%MOD<<endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=(a),_ed=(b);i<=_ed;++i)
#define DREP(i,a,b) for(int i=(a),_ed=(b);i>=_ed;--i)
#define mp(x,y) make_pair((x),(y))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
inline int read(){
register int x=0,f=1;register char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}
while(isdigit(ch)){x=x*10+(ch^'0');ch=getchar();}
return f?x:-x;
}
const int mod=1000000007;
int n,k,f[4005][2005],fac[16000005],ifc[16000005];
inline void inc(int& x,int y){x=x+y<mod?x+y:x+y-mod;}
inline void dec(int& x,int y){x=x-y>=0?x-y:x-y+mod;}
inline int power(int b,int n){int ans=1;for(;n;n>>=1,b=1ll*b*b%mod)if(n&1)ans=1ll*ans*b%mod;return ans;}
inline int C(int n,int m){return (n<0||m<0||n<m)?0:1ll*fac[n]*ifc[m]%mod*ifc[n-m]%mod;}
int main(){
// freopen("in.in","r",stdin);
n=read(),k=read();
REP(i,fac[0]=1,16000001)fac[i]=1ll*fac[i-1]*i%mod;
ifc[16000001]=power(fac[16000001],mod-2);
DREP(i,16000001,1)ifc[i-1]=1ll*ifc[i]*i%mod;
if(k==1)return puts("1"),0;
f[0][0]=1;
REP(i,0,n+n-1)REP(j,0,i>>1)if(f[i][j]){
if(i-j>j)inc(f[i+1][j+1],f[i][j]);
int num=(i-j)*(k-1)+j+1;
inc(f[i+1][j],1ll*(n-i+j)*f[i][j]%mod*C(k-2+num-1,num-1)%mod);
}
printf("%d\n",f[n+n][n]);
return 0;
}
| 1 |
#include<iostream>
#include<cstdio>
using namespace std;
int a[2010][2010];char s[2010];
int h[2010][2010],r[2010][2010],l[2010][2010];
int top=0,ans=0,st[2010];
int main()
{
int n,m;scanf("%d%d",&n,&m);ans=n;
for(int i=1;i<=n;i++)
{
scanf("%s",s);
for(int j=1;j<=m;j++)a[i][j]=(s[j-1]=='#');
}
for(int i=n;i>=1;i--)
for(int j=m;j>=2;j--)a[i][j]^=a[i][j-1];
for(int j=2;j<=m;j++)h[1][j]=1;
for(int i=2;i<=n;i++)
for(int j=2;j<=m;j++)if(a[i][j]==a[i-1][j])h[i][j]=h[i-1][j]+1;else h[i][j]=1;
for(int i=1;i<=n;i++)
{
for(int j=2;j<=m;j++)
{
while(top&&h[i][st[top]]>h[i][j]){r[i][st[top]]=j-1;top--;}
st[++top]=j;
}
while(top)r[i][st[top--]]=m;
}
for(int i=1;i<=n;i++)
{
for(int j=2;j<=m;j++)
{
while(top&&h[i][st[top]]>=h[i][j]){top--;}
if(top==0)l[i][j]=2;else l[i][j]=st[top]+1;st[++top]=j;
}
top=0;
}
for(int i=1;i<=n;i++)
{
for(int j=2;j<=m;j++)ans=max(ans,(r[i][j]-l[i][j]+2)*h[i][j]);
}
printf("%d",ans);return 0;
} | // Have a nice day
// ∠( ᐛ 」∠)
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define x first
#define y second
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
template <typename T> inline T read()
{
T sum=0, fl=1; char ch=getchar();
for(; !isdigit(ch); ch=getchar()) if(ch=='-') fl=-1;
for(; isdigit(ch); ch=getchar()) sum=(sum<<3)+(sum<<1)+ch-'0';
return sum*fl;
}
const int maxn=2000+5;
int n, m, ans;
char s[maxn][maxn];
int l[maxn], r[maxn], h[maxn], c[maxn][maxn];
void Solve()
{
n=read<int>(), m=read<int>(); ans=max(n, m);
for(int i=1; i<=n; ++i) scanf("%s", s[i]+1);
--n, --m;
for(int i=1; i<=n; ++i)
for(int j=1; j<=m; ++j)
if(((s[i][j]=='#')+(s[i+1][j]=='#')+(s[i][j+1]=='#')+(s[i+1][j+1]=='#'))&1);
else c[i][j]=1;
for(int i=1; i<=m; ++i) l[i]=r[i]=maxn;
for(int i=1; i<=n; ++i)
{
for(int j=1, p=0; j<=m; ++j)
{
if(c[i][j]) ++p; else p=0;
l[j]=min(l[j], p);
}
for(int j=m, p=0; j>=1; --j)
{
if(c[i][j]) ++p; else p=0;
r[j]=min(r[j], p);
}
for(int j=1; j<=m; ++j)
{
if(c[i][j]) ++h[j], ans=max(ans, (l[j]+r[j])*(h[j]+1));
else l[j]=r[j]=maxn, h[j]=0;
}
}
printf("%d\n", ans);
}
int main()
{
// freopen("081d.in","r",stdin);
//freopen("081d.out","w",stdout);
Solve();
return 0;
}
| 1 |
#include<stdio.h>
#define N 100
int A[N + 1][N + 1];
int p[N + 1];
int solve(int i, int j)
{
if(!(A[i][j] < 0)){ return A[i][j]; }
if(j == i){ A[i][i] = 0; return 0; }
if(j == i + 1){
A[i][j] = p[i - 1] * p[i] * p[i + 1];
return A[i][j];
}
int min = -1, x;
for(int k = i; k < j; k++){
x = solve(i, k) + solve(k + 1, j) + p[i - 1] * p[k] * p[j];
if(min < 0){ min = x; }
else{ if(min > x) min = x; }
}
A[i][j] = min;
return min;
}
int main()
{
int i, j, n;
scanf("%d", &n);
for(i = 1; i <= n; i++){
scanf("%d %d", &p[i - 1], &p[i]);
for(j = 1; j <= n; j++){
A[i][j] = -1;
}
}
printf("%d\n", solve(1, n));
return 0;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
ll memo[111][111];
int n, a[111], b[111];
ll rec(int l, int r){
if(memo[l][r] != 1e9) return memo[l][r];
if(l == r) return memo[l][r] = 0;
ll ret = 1e9;
FOR(m, l, r){
ret = min(ret, rec(l, m) + rec(m + 1, r) + a[l] * b[m] * b[r]);
}
return memo[l][r] = ret;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
FOR(i,0,n) cin >> a[i] >> b[i];
FOR(i,0,111)FOR(j,0,111)memo[i][j]=1e9;
cout << rec(0,n-1) << endl;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;
int main()
{
string s ,t;
cin>>s>>t;
cout<<t<<s<<endl;
return 0;
}
| #include<stdio.h>
int main()
{
char a[105];
char b[105];
scanf("%s %s", &a, &b);
printf("%s%s", &b, &a);
return 0;
} | 1 |
#include "assert.h"
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <vector>
using namespace std;
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, n, a) for (int i = n; i >= a; --i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int, int> PII;
mt19937 mrand(random_device{}());
inline int in() {
char ch = getchar();
int f = 1, x = 0;
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
return f * x;
}
const int inf = (1 << 30);
const int mod = 998244353;
const int N = 100010;
LL cnt[50][30];
int main() {
#ifndef ONLINE_JUDGE
freopen("in.in", "r", stdin);
// freopen("out.out", "w", stdout);
#endif
int n = in();
int tmp = 1e9, A = 0, B = 0;
while (tmp % 2 == 0)
++A, tmp /= 2;
while (tmp % 5 == 0)
++B, tmp /= 5;
cerr << A << " " << B << endl;
LL ans = 0;
rep(_, 1, n) {
double x;
cin >> x;
LL tmp = llround(x * 1e9) ;
int a = 0, b = 0;
while (tmp % 2 == 0)
++a, tmp /= 2;
while (tmp % 5 == 0)
++b, tmp /= 5;
rep(i, 0, 49) rep(j, 0, 29) {
if (i + a >= A * 2 && j + b >= B * 2)
ans += cnt[i][j];
}
cnt[a][b]++;
cerr << ans << endl;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
vector<vector<ll>> cnt(62, vector<ll>(62, 0));
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (find(s.begin(), s.end(), '.') == s.end()) s.push_back('.');
int pos = 0;
while (s[pos] != '.') pos++;
s += string(10 - s.size() + pos, '0');
ll y = 0;
for (auto c : s) {
if (isdigit(c)) y = y * 10 + c - '0';
}
int p2 = 0, p5 = 0;
for (; y % 2 == 0; y /= 2, p2++);
for (; y % 5 == 0; y /= 5, p5++);
cnt[p2][p5]++;
}
ll ans = 0;
for (int p2 = 0; p2 < 62; p2++) {
for (int p5 = 0; p5 < 62; p5++) {
for (int pp2 = 0; pp2 < 62; pp2++) {
for (int pp5 = 0; pp5 < 62; pp5++)
ans += cnt[p2][p5] * cnt[pp2][pp5] * (min(p2 + pp2, p5 + pp5) >= 18) *
(pair<int, int>{p2, p5} != pair<int, int>{pp2, pp5});
}
}
}
for (int p2 = 0; p2 < 62; p2++) {
for (int p5 = 0; p5 < 62; p5++) ans += cnt[p2][p5] * (cnt[p2][p5] - 1) * (min(p2, p5) * 2 >= 18);
}
cout << ans / 2 << '\n';
}
| 1 |
/**
* @copyright (c) 2020 Daisuke Hashimoto
*/
#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;
// std::cout << std::setprecision(20) << 1.1 << endl;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int64_t N;
cin >> N;
// const int64_t L = static_cast<int64_t>(T.length());
vector<int64_t> A(N + 1, 0);
for (int64_t i = 1; i <= N; ++i) {
cin >> A[i];
}
vector<int64_t> result;
vector<int64_t> B(N + 1, 0);
for (int64_t i = N; i >= 1; --i) {
int64_t temp = 0;
for (int64_t j = 2 * i; j <= N; j += i) {
temp += B[j];
temp %= 2;
}
if (temp != A[i]) {
B[i] = 1;
result.emplace_back(i);
}
}
cout << result.size() << endl;
for (int64_t i = 0; i < static_cast<int64_t>(result.size()); ++i) {
if (i != 0) {
cout << " " << endl;
}
cout << result[i];
}
cout << endl;
return 0;
}
| /*
Written by Nitrogens
Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
const int maxn = 1e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;
#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
ll x[maxn], y[maxn];
ll a[maxn], b[maxn];
ll sum(ll n) {
return n * (n + 1) / 2 % Mod;
}
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%lld", &x[i]);
for (int i = 1; i <= m; i++) scanf("%lld", &y[i]);
for (int i = 1; i < n; i++) a[i] = (x[i + 1] - x[i] + Mod) % Mod;
for (int i = 1; i < m; i++) b[i] = (y[i + 1] - y[i] + Mod) % Mod;
n--, m--;
ll X = 0, Y = 0;
for (int i = 1; i <= n; i++) {
ll cnt = sum(n) - sum(i - 1) - sum(n - i);
cnt %= Mod;
cnt = (cnt + Mod) % Mod;
ll delta = cnt * a[i] % Mod;
X = (X + delta) % Mod;
}
for (int i = 1; i <= m; i++) {
ll cnt = sum(m) - sum(i - 1) - sum(m - i);
cnt %= Mod;
cnt = (cnt + Mod) % Mod;
ll delta = cnt * b[i] % Mod;
Y = (Y + delta) % Mod;
}
ll ans = X * Y % Mod;
printf("%lld\n", ans);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";
int main()
{
ll a, b;
cin >> a >> b;
map<ll,int> ad, bd;
ll na = a, nb = b;
for (ll i = 2; i*i <= a; i++) {
while (na%i == 0) {
ad[i]++;
na /= i;
}
}
if (na > 1) ad[na] ++;
for (ll i = 2; i*i <= b; i++) {
while (nb%i == 0) {
bd[i]++;
nb /= i;
}
}
if (nb > 1) bd[nb] ++;
ll ans = 1;
for (auto ea : ad) {
if (bd[ea.first] > 0) ans++;
}
cout << ans << "\n";
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
ll gcd(ll a,ll b){
while(b>0){
ll r=a%b;
a=b;
b=r;
}
return a;
}
int main(){
ll a,b;
cin >> a >> b;
ll p=gcd(a,b);
ll i;
ll cp=p;
vector<ll> ans(2000);
ans.at(0)=1;
ll j=1;
for(i=2;i*i<=p;i++){
bool is=false;
while(cp%i==0){
cp/=i;
is=true;
}
if(is){
ans.at(j)=i;
j++;
}
}
if(cp!=1){
ans.at(j)=cp;
}
rep(i,2000){
if(ans.at(i)==0){
break;
}
}
rep(i,2000){
if(ans.at(i)==0){
cout << i;
return 0;
}
}
} | 1 |
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); ++i)
// using namespace atcoder;
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
//マクロ
// forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define inf 2147483647 // int値の最大値
#define MOD 1000000007 // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first // pairの一つ目の要素
#define S second // pairの二つ目の要素
#define CST(x) cout << fixed << setprecision(x) //小数点以下の桁数指定
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 gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
//各桁の和
int sumDight(int x) {
int sum = 0;
while (x > 0) {
sum += (x % 10);
x /= 10;
}
return sum;
}
//回文数
int divideReverse(int x) {
int reverse = 0;
int r;
while (x > 0) {
r = x % 10;
reverse = reverse * 10 + r;
x /= 10;
}
return reverse;
}
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n;
vector<string> s(110);
rep(i, n) cin >> s[i];
cin >> m;
vector<string> t(110);
rep(i, m) cin >> t[i];
map<string, int> a;
rep(i, n) { a[s[i]] += 1; }
rep(i, m) a[t[i]] -= 1;
int ma =0;
for (auto p :a){
if (ma < a.at(p.first)) ma = a.at(p.first);
}
if(ma>0)cout << ma << endl;
else
cout << 0 << endl;
}
| #include<iostream>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
int lst[Max];
string ls[Max];
map<string, int> ma1, ma2;
int main()
{
int n, m, g = 0;
cin >> n;
for (int i = 1;i <= n;i++)
{
string t;
cin >> t;
ma1[t]++;
ls[++g] = t;
}
cin >> m;
for (int i = 1;i <= m;i++)
{
string t;
cin >> t;
ma2[t]++;
ls[++g] = t;
}
int ma = -1e9 - 5;
for (int i = 1;i <= g;i++)
{
ma = max(ma, ma1[ls[i]] - ma2[ls[i]]);
}
cout << max(0,ma);
} | 1 |
#include <bits/stdc++.h>
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 RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1e18
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; }
void solve_abc_a() {
ll n, m;
ll x, y;
ll a, b, d;
ll c;
//char c;
ll h, w;
ll k;
string s, t;
//ll s, t;
ll l_ans = 0;
string s_ans = "NG";
cin >> a >> b;
if (a<=8 && b<=8){
s_ans = "Yay!";
}
else{
s_ans = ":(";
}
cout << s_ans << endl;
return;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed;
cout << setprecision(7);
solve_abc_a();
return 0;
}
| //#include "stdafx.h"
#include<bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int a,b,ans,q;
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>a>>b;
q=abs(a-b);
ans=16-(a+b);
if(q>ans/2)
cout<<":(\n";
else
cout<<"Yay!\n";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
int R, G;
cin >> R >> G;
cout << 2 * G - R << endl;
} | #include <bits/stdc++.h>
#include <vector>
using namespace std;
int main() {
int a,b,ans=0;
cin >> a >> b;
for(int i = a;i<b+1;i++){
if(i/10000==i%10&&(i/1000-(i/10000)*10)==(i%100-i%10)/10)ans++;
}
cout << ans;
} | 0 |
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define INF 10000000
#define MAX_V 101
struct edge{int to;LL cost;};
typedef pair<LL,int> P;//firstは最短距離,secondは頂点番号
int V;
vector<edge> G[MAX_V];
LL d[MAX_V];
void dijkstra(int s){
priority_queue<P,vector<P>,greater<P> > que;
fill(d,d+V,INF);
d[s]=0;
que.push(P(0,s));
while(!que.empty()){
P p=que.top();que.pop();//仮の最短距離が短い順に取り出す
int v=p.second;
if(d[v]<p.first)continue;
REP(i,G[v].size()){
edge e=G[v][i];
if(d[e.to]>d[v]+e.cost){
d[e.to]=d[v]+e.cost;
que.push(P(d[e.to],e.to));//仮の最短距離と頂点の組を更新が行われる度に追加していく
}
}
}
}
int main(){
long n,k;
while(cin>>n>>k){
if(n==0&&k==0)break;
V=n;
REP(i,n)G[i].clear();
REP(i,k){
int ch;
cin>>ch;
if(ch){
int ct,dt;
LL et;
cin>>ct>>dt>>et;
ct--;dt--;
edge ed={dt,et};
G[ct].PB(ed);
ed.to=ct;
G[dt].PB(ed);
}else{
int a,b;
cin>>a>>b;
a--;b--;
dijkstra(a);
if(d[b]<INF)cout<<d[b]<<endl;
else cout<<"-1"<<endl;
}
}
}
return 0;
} | #include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll INF = 10000000000;
int main(){
int v,e;
ll d[100][100];
scanf("%d %d",&v,&e);
fill(d[0],d[0]+10000,INF);
for(int i=0;i<v;i++) d[i][i] = 0;
for(int i=0;i<e;i++){
int s,t;
ll dist;
scanf("%d %d %lld",&s,&t,&dist);
d[s][t] = dist;
}
for(int k=0;k<v;k++){
for(int i=0;i<v;i++){
for(int j=0;j<v;j++){
if(d[i][k]!=INF&&d[k][j]!=INF) d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
}
}
}
bool flag = false;
for(int i=0;i<v;i++){
if(d[i][i]<0) flag = true;
}
if(flag){
printf("NEGATIVE CYCLE\n");
}else{
for(int i=0;i<v;i++){
for(int j=0;j<v;j++){
if(d[i][j]==INF) printf("INF");
else printf("%lld",d[i][j]);
if(j==v-1) printf("\n");
else printf(" ");
}
}
}
return 0;
} | 0 |
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
int n;
int k;
vector<int> card;
set< string > cd;
set< vector<int> > ccd;
/*
string IteratorToString(vector<int>::iterator begin, vector<int>::iterator end){
string str = "";
char ch[256];
for(;begin < end;begin++){
sprintf(ch,"%d",*begin);
str += ch;
}
return str;
}
*/
string VectorToString(const vector<int> &vec){
string str = "";
for(int i=0;i<vec.size();i++){
char ch[256];
sprintf(ch,"%d",vec[i]);
str += ch;
}
return str;
}
string VectorToDebugText(const vector<int> &vec){
string str = "";
for(int i=0;i<vec.size();i++){
char ch[256];
sprintf(ch,"%d",vec[i]);
str += ch;
str += ":";
}
return str;
}
void solve(int a,vector<int> v){
if(v.size() == k){
sort(v.begin(),v.end());
ccd.insert(v);
return;
}
if(a == n){return;}
solve(a + 1,v);
v.push_back(card[a]);
solve(a + 1,v);
}
int main(){
while(1){
int self;
scanf("%d %d",&n,&k);
if(n == 0 && k == 0){
break;
}
card.clear();
cd.clear();
ccd.clear();
for(int i=0;i<n;i++){
scanf("%d",&self);
card.push_back(self);
}
vector<int> cc(k);
sort(card.begin(),card.end());
/*
while(next_permutation(card.begin(),card.end())){
cd.insert(VectorToString(card.begin(),card.begin()+k));
}
*/
solve(0,vector<int>());
for(set<vector<int> >::iterator it = ccd.begin();it != ccd.end();it++){
vector<int> vec = *it;
sort(vec.begin(),vec.end());
cd.insert(VectorToString(vec));
//printf("[%s]\n",VectorToDebugText(vec).c_str());
while(next_permutation(vec.begin(),vec.end())){
//printf("%s\n",VectorToDebugText(vec).c_str());
//printf("%s\n",VectorToString(vec).c_str());
cd.insert(VectorToString(vec));
}
}
printf("%d\n",cd.size());
}
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
if(a.first != b.first){
return a.first < b.first;
}else{
return a.second < b.second;
}
}
bool compareg(Pi a, Pi b) {
if(a.second != b.second){
return a.second > b.second;
}else{
return a.first > b.first;
}
}
bool In_map(ll y,ll x,ll h,ll w){
if(y<0 || x<0 || y>=h || x>=w){
return 0;
}else{
return 1;
}
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
const vector<ll> d2{0, 1, 0, 2, 0, 1};
const vector<ll> d3{0, 0, 1, 0, 0, 1};
const vector<ll> d5{0, 0, 0, 0, 1, 0};
int main() {
string s1,s2;
cin>>s1>>s2;
ll N = s1.size();
ll M = s2.size();
vector<vector<ll>>dp(N+1,vector<ll> (M+1));
rep(i,N){
dp[i+1][0] = i+1;
}
rep(i,M){
dp[0][i+1] = i+1;
}
rep(i,N){
rep(j,M){
if(s1[i] == s2[j]){
dp[i+1][j+1] = min({dp[i][j],dp[i+1][j]+1,dp[i][j+1]+1});
}else{
dp[i+1][j+1] = min({dp[i][j]+1 ,dp[i+1][j]+1,dp[i][j+1]+1});
}
}
}
cout<<dp[N][M]<<endl;
return 0;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
vector<vector<string>>ans={
{"-1"}, //0
{"-1"}, //1
{"-1"}, //2
{ //3
"..a",
"..a",
"bb."
},
{ //4
"abcc",
"abdd",
"eefg",
"hhfg"
},
{ //5
"..abc",
"..abc",
"ddeff",
"gge.h",
"iijjh"
},
{ //6
"...abc",
"...abc",
"d.ee.f",
"dgg..f",
"hhi.jj",
"kkill."
},
{
"....abc",
"....abc",
"....def",
"....def",
"gghh..i",
"jjkk..i",
"llmmnn."
}
};
int n;
void printA(vector<string>ans){
for(auto x:ans){
cout<<x<<endl;
}
}
void manage(vector<string>ans,int prev){
for(auto x:ans){
cout<<string(prev,'.')
<<x
<<string(n-prev-x.length(),'.')
<<endl;
}
}
void rec(int n,int prev){
if(n==0)return;
if(n>9&&n!=13||n==6){
// cout<<6<<" ";
manage(ans[6],prev);
rec(n-6,prev+6);
}
else if(n>8||n%5==0){
// cout<<5<<" ";
manage(ans[5],prev);
rec(n-5,prev+5);
}
else{
// cout<<"4"<<" ";
manage(ans[4],prev);
rec(n-4,prev+4);
}
}
int main(){
cin>>n;
if(n<8)printA(ans[n]);
// for(int i=9;i<30;i++){
// rec(i,0);
// cout<<endl;
// }
else rec(n,0);
}
//..abc
//..abc
//ddeff
//gge.h
//iijjh
//abcc
//abdd
//eefg
//hhfg
//..a
//..a
//bb.
| #include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }
// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;
using namespace std;
signed main() {
int N;
cin >> N;
if(N == 2){
cout << -1 << endl;
return 0;
}else if(N == 3){
cout << "aa." << endl;
cout << "..a" << endl;
cout << "..a" << endl;
return 0;
}
int x, y;
if(N%4 == 0){
x = N/4;
y = 0;
}else{
x = N/4-1;
y = N-(N/4-1)*4;
}
vector<vector<char>> vec(N, vector<char>(N, '.'));
REP(i, x){
vec[i*4+0][i*4+0] = 'a';
vec[i*4+0][i*4+1] = 'a';
vec[i*4+0][i*4+2] = 'b';
vec[i*4+0][i*4+3] = 'c';
vec[i*4+1][i*4+0] = 'd';
vec[i*4+1][i*4+1] = 'd';
vec[i*4+1][i*4+2] = 'b';
vec[i*4+1][i*4+3] = 'c';
vec[i*4+2][i*4+0] = 'b';
vec[i*4+2][i*4+1] = 'c';
vec[i*4+2][i*4+2] = 'a';
vec[i*4+2][i*4+3] = 'a';
vec[i*4+3][i*4+0] = 'b';
vec[i*4+3][i*4+1] = 'c';
vec[i*4+3][i*4+2] = 'd';
vec[i*4+3][i*4+3] = 'd';
}
REP(i, x*4) REP(j, x*4){
cout << vec[i][j];
if(j == x*4-1){
REP(k, y) cout << '.';
cout << endl;
}
}
if(y == 5){
REP(i, x*4) cout << '.'; cout << "aabba" << endl;
REP(i, x*4) cout << '.'; cout << "bcc.a" << endl;
REP(i, x*4) cout << '.'; cout << "b..cb" << endl;
REP(i, x*4) cout << '.'; cout << "a..cb" << endl;
REP(i, x*4) cout << '.'; cout << "abbaa" << endl;
}else if(y == 6){
REP(i, x*4) cout << '.'; cout << "aabc.." << endl;
REP(i, x*4) cout << '.'; cout << "ddbc.." << endl;
REP(i, x*4) cout << '.'; cout << "..aabc" << endl;
REP(i, x*4) cout << '.'; cout << "..ddbc" << endl;
REP(i, x*4) cout << '.'; cout << "bc..aa" << endl;
REP(i, x*4) cout << '.'; cout << "bc..dd" << endl;
}else if(y == 7){
REP(i, x*4) cout << '.'; cout << "aabbcc." << endl;
REP(i, x*4) cout << '.'; cout << "dd.dd.a" << endl;
REP(i, x*4) cout << '.'; cout << "..d..da" << endl;
REP(i, x*4) cout << '.'; cout << "..d..db" << endl;
REP(i, x*4) cout << '.'; cout << "dd.dd.b" << endl;
REP(i, x*4) cout << '.'; cout << "..d..dc" << endl;
REP(i, x*4) cout << '.'; cout << "..d..dc" << endl;
}
return 0;
} | 1 |
#include<iostream>
using namespace std;
int main(){
long long data[2][4000],n,i,f,id,a,b;
while(1){
cin>>n;
if(n==0) break;
for(i=0; i<4000; i++) data[0][i]=-1,data[1][i]=0;
for(i=0;i<n;i++){
cin>>id>>a>>b;
for(f=0;f<i+1;f++){
if(data[0][f]==id){
(a*b<1000000)? (data[1][f]+=(a*b)) : (data[1][f]=1000000);
break;
}else if(data[0][f]==-1){
data[0][f]=id;
(a*b<1000000)? (data[1][f]=(a*b)) : (data[1][f]=1000000);
break;
}
}
}
for(i=0,f=0;i<n;i++){
if(data[1][i]>=1000000)cout<<data[0][i]<<"\n",f=1;
if(data[0][i]==-1)break;
//cout<<"id : "<<data[0][i]<<" sale: "<<data[1][i]<<endl;
}
if(f==0)cout<<"NA"<<endl;
}
} | #include<iostream>
#include<string>
using namespace std;
int main( )
{
string str, cmd, p;
int q;
int a, b;
cin>>str;
cin>>q;
while( q-- ) {
cin>>cmd;
if( "print" == cmd ) {
cin>>a>>b;
cout<<str.substr( a, b-a+1 )<<endl;
} else if( "reverse" == cmd ) {
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;
}
} else if( "replace" == cmd ) {
cin>>a>>b>>p;
str.replace( a, b-a+1, p );
}
}
return 0;
} | 0 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using VVI = vector<vector<int>>;
const int INF = 1001001001;
const int MOD = 1000000007;
template <typename T>
void print(const T &v);
int main()
{
int n;
cin >> n;
vector<ll> a(n), b(n), c(n);
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
sort(a.begin(), a.end());
for (int i = 0; i < n; i++)
{
cin >> b[i];
}
sort(b.begin(), b.end());
for (int i = 0; i < n; i++)
{
cin >> c[i];
}
sort(c.begin(), c.end());
vector<ll> mid(n + 1);
for (int i = 0; i < n; i++)
{
int idx = distance(a.begin(), lower_bound(a.begin(), a.end(), b[i]));
mid[i + 1] = mid[i] + idx;
}
ll ans = 0;
for (int i = 0; i < n; i++)
{
int idx = distance(b.begin(), lower_bound(b.begin(), b.end(), c[i]));
ans += mid[idx];
}
cout << ans << endl;
return 0;
}
// Use For Debug
template <typename T>
void print(T const &v)
{
for (int i = 0; i < v.size(); i++)
{
if (i)
cout << " ";
cout << v[i];
}
cout << endl;
} | /*input
5
3 3 3 3 3
*/
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdint.h>
#include <tgmath.h>
using namespace std;
/******* All Required define Pre-Processors and typedef Constants *******/
#define ar array
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define tests int r; cin >> r; while(r--)
#define MP make_pair
#define PI acos(-1)
typedef pair<long long, long long> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;
#define godspeed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define M(x) ((x)%(1000000007))
vector<int> adj_list[100010];
bool visited[10010];
void dfs(int node){
visited[node] = true;
for(int n: adj_list[node]){
if(!visited[n]){
dfs(n);
}
}
}
int main() {
int64 n;
cin>>n;
int64 ma = 1000;
int64 count = 0;
rep(i,n){
int64 a;
cin>>a;
if(i==0){
ma = a;
}
else{
if(ma>a){
count+=ma-a;
}
else{
ma = a;
}
}
}
cout<<count<<endl;
}
| 0 |
#include <stdio.h>
#define INF 10000000
int main(void){
int n,m;
while(scanf("%d %d",&m,&n),n,m){
int i,j;
int a,b,cost,time,c;
int DPc[256][256];
int DPt[256][256];
int k,ans[256];
for(i=0;i<256;i++){
for(j=0;j<256;j++){
if(i==j){
DPc[i][j]=0;
DPt[i][j]=0;
}
else{
DPc[i][j]=INF;
DPt[i][j]=INF;
}
}
}
for(i=0;i<m;i++){
scanf("%d %d %d %d", &a, &b, &cost, &time);
DPc[a][b]=cost;
DPc[b][a]=cost;
DPt[a][b]=time;
DPt[b][a]=time;
}
for(k=0;k<=n;k++){
for(i=0;i<=n;i++){
for(j=0;j<=n;j++){
if(DPt[i][k]+DPt[k][j]<DPt[i][j]){
DPt[i][j]=DPt[i][k]+DPt[k][j];
}
if(DPc[i][k]+DPc[k][j]<DPc[i][j]){
DPc[i][j]=DPc[i][k]+DPc[k][j];
}
}
}
}
scanf("%d", &m);
for(i=0;i<m;i++){
scanf("%d %d %d", &a, &b, &c);
if(c==1){
ans[i]=DPt[a][b];
}
else {
ans[i]=DPc[a][b];
}
}
for(i=0;i<m;i++){
printf("%d\n",ans[i]);
}
}
return 0;
} | #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
while(1){
int n;
cin >> n;
if(n == 0) break;
for(int i = 0; i < n; i++){
int pm,pe,pj;
int heikin = 0;
cin >> pm >> pe >> pj;
heikin = pm + pe + pj;
heikin /= 3;
if(pm == 100 || pe == 100 || pj == 100) cout << "A" << endl;
else if((pm + pe) / 2 >= 90) cout << "A" << endl;
else if(heikin >= 80) cout << "A" << endl;
else if(heikin >= 70) cout << "B" << endl;
else if(heikin >= 50 && pm >= 80 || pe >= 80) cout << "B" << endl;
else cout << "C" << endl;
}
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;
double equal(double a, double b) {
return fabs(a - b) < DBL_EPSILON;
}
std::istream &operator>>(std::istream &in, set<string> &o) {
string a;
in >> a;
o.insert(a);
return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
ll a;
in >> a;
o.push(a);
return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;
int main() {
ll a, b;
int k;
cin >> a >> b >> k;
rep(i, k) {
if (i % 2 == 0) {
if (a % 2 == 1) a--;
a /= 2;
b += a;
} else {
if (b % 2 == 1) b--;
b /= 2;
a += b;
}
}
cout << a << ' ' << b << endl;
}
| #include<bits/stdc++.h>
using namespace std;
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a, b, c) for(int a = b; a >= c; --a)
#define fi first
#define se second
#define pb push_back
#define int long long
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
const int N = 2e5 + 100;
const int maxN = 6e6;
const int oo = 1e18;
const int mod = 1e9 + 7;
signed main() {
// freopen("test.inp", "r", stdin);
// freopen("spm.out", "w", stdout);
ios_base::sync_with_stdio(false); cout.tie(0);
int n, m, d; cin >> n >> m >> d;
double ans = (double) (m - 1.00) * 2.00 * (n - d) * 1.00 / (n * 1.00 * n);
if(d == 0) ans /= 2.00;
cout << fixed << setprecision(10) << ans;
}
| 0 |
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
#define int long long
const int maxn = 2e3 + 10;
inline int Max(int a, int b) { return a > b ? a : b; }
inline int Min(int a, int b) { return a > b ? b : a; }
namespace FastIO {
inline int read()
{
int f = 1, r = 0;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') {
f = -1;
}
c = getchar();
}
while (isdigit(c)) {
r = 10 * r + c - '0';
c = getchar();
}
return f * r;
}
inline void write(int x)
{
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) { write(x), puts(""); }
};
using namespace FastIO;
int N, K, dp[maxn][maxn], fac[maxn * maxn], ifac[maxn * maxn];
inline int exgcd(int a, int b, int& x, int& y)
{
if (b == 0) {
x = 1, y = 0;
return a;
}
int d = exgcd(b, a % b, x, y);
int tmp = y;
y = x - a / b * y;
x = tmp;
return d;
}
inline int inv(int a, int b)
{
int x, y;
exgcd(a, b, x, y);
return (x + MOD) % MOD;
}
inline int C(int m, int n)
{
int tmp = (fac[m] * ifac[n] % MOD) * ifac[m - n] % MOD;
return tmp;
}
signed main()
{
//freopen("C:\Users\hjw\Downloads\testdata (4).in", "r", stdin);
N = read(), K = read();
if (K == 1) {
puts("1");
return 0;
}
fac[0] = 1, ifac[0] = inv(1, MOD);
for (ri i = 1; i <= N * K; ++i) {
fac[i] = fac[i - 1] * i % MOD;
ifac[i] = inv(fac[i], MOD);
}
dp[0][1] = 1;
for (ri j = 2; j <= N; ++j) {
dp[0][j] = dp[0][j - 1] * C(j * (K - 1) - 1, K - 2) % MOD;
}
for (ri i = 1; i <= N; ++i) {
for (ri j = i; j <= N; ++j) {
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] * C(j * (K - 1) + i - 1, K - 2)) % MOD;
}
}
dp[N][N] = (dp[N][N] * fac[N] % MOD);
writeln(dp[N][N]);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const ll MOD = 1000000007;
const int SIZE = 1010;
ll inv[SIZE],fac[SIZE],finv[SIZE];
void make(){
fac[0]=fac[1]=1;
finv[0]=finv[1]=1;
inv[1]=1;
for(int i=2;i<SIZE;i++){
inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
fac[i]=fac[i-1]*(ll) i%MOD;
finv[i]=finv[i-1]*inv[i]%MOD;
}
}
ll Combination (int a,int b) {
if(a<b) return 0;
return fac[a]*(finv[b]*finv[a-b]%MOD)%MOD;
}
ll dp[1010][1010];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n,a,b,c,d;
cin>>n>>a>>b>>c>>d;
make();
FOR(i,0,1010) dp[i][0] = 1;
FOR(i,a,b+1) {
FOR(j,0,n+1) {
if(dp[i][j] == 0) continue;
if(j != 0) (dp[i+1][j] += dp[i][j]) %= MOD;
ll p = 1;
for(int k = 1; k <= d && j + i * k <= n; k++) {
p = (((p * Combination(n - j - i * (k - 1), i) % MOD) * inv[k]) % MOD) % MOD;
if(k >= c) (dp[i+1][j+i*k] += (dp[i][j] * p) % MOD) %= MOD;
}
}
}
cout << dp[b+1][n] << endl;
return 0;
} | 0 |
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 200
#define LN 63
#define ull unsigned long long
using namespace std;
int n,ans;ull a[N+5],v[LN+5];char op[N+5];
I void Clear() {ans=0;for(RI i=LN;~i;--i) v[i]=0;}
I void Ins(ull x)
{
for(RI i=LN;~i;--i) if((x>>i)&1) {if(!v[i]) return (void)(v[i]=x);x^=v[i];}
}
I bool Q(ull x)
{
for(RI i=LN;~i;--i) if((x>>i)&1) {if(!v[i]) return 0;x^=v[i];}return 1;
}
int main()
{
RI Tt,i;scanf("%d",&Tt);W(Tt--)
{
for(Clear(),scanf("%d",&n),i=1;i<=n;++i) scanf("%llu",a+i);scanf("%s",op+1);
for(ans=1,i=n;i;--i) if(a[i])
{if(op[i]=='1'&&!Q(a[i])) {ans=0;break;}op[i]=='0'&&(Ins(a[i]),0);}
putchar(49-ans),putchar('\n');
}return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, n) for (int i = 1; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;
void solve() {
int N;
cin >> N;
vector<lint> A(N);
rep(i, N) cin >> A[i];
string S;
cin >> S;
vector<lint> base;
for (int i = N - 1; i >= 0; --i) {
lint x = A[i];
for (auto b : base) {
x = min(x, x ^ b);
}
if (x) {
if (S[i] == '0') {
base.push_back(x);
sort(base.rbegin(), base.rend());
} else {
cout << 1 << "\n";
return;
}
}
}
cout << 0 << "\n";
}
int main() {
int T;
cin >> T;
rep(i, T) solve();
return 0;
}
| 1 |
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n , x;
cin>>n;
for(int i=1 ; i<=n ; i++){
x=i;
if(i%3==0 && x%10!=3){
cout << " " << i;
} else if(x%10==3) {
cout << " " << i;
} else {
for(int j=0 ; j<(int(log10((double)n))) ; j++){
x/=10;
if(x){
if(x%10==3){
cout << " " << i;
break;
}
}
}
}
}
cout << endl;
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
int n;
string s1 = "Hoshino", s2 = "Hoshina";
string::size_type pos;
cin >> n;
cin.ignore();
for (int i = 0; i < n; i++) {
string line;
getline(cin, line);
for (pos = line.find(s1); pos != string::npos; pos = line.find(s1, s2.length() + pos))
line.replace(pos, s1.length(), s2);
cout << line << endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef pair<int,int> P;
const int INF = 1e9+7;
int main(){
int N,K;
cin >> N >> K;
if(N%K){
cout << "1";
}else{
cout << "0";
}
} | #include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;
int N, a[100010];
string S;
signed main(){
cin >> N >> S;
REP(st, 4){
if(st & 1){
a[0] = 1;
if(st & 2) a[N - 1] = 1;
else a[N - 1] = 0;
}else{
a[0] = 0;
if(st & 2) a[N - 1] = 1;
else a[N - 1] = 0;
}
REP(i, N){
if(a[i] == 0){
if(S[i] == 'o') a[(i + 1 + N) % N] = a[(i - 1 + N) % N];
else a[(i + 1 + N) % N] = 1 - a[(i - 1 + N) % N];
}else{
if(S[i] == 'o') a[(i + 1 + N) % N] = 1 - a[(i - 1 + N) % N];
else a[(i + 1 + N) % N] = a[(i - 1 + N) % N];
}
}
if(st & 1){
if(a[0] == 0) continue;
if(st & 2){
if(a[N - 1] == 0) continue;
}else{
if(a[N - 1] == 1) continue;
}
}else{
if(a[0] == 1) continue;
if(st & 2){
if(a[N - 1] == 0) continue;
}else{
if(a[N - 1] == 1) continue;
}
}
REP(i, N){
if(a[i] == 0) cout << "S";
else cout << "W";
}
cout << endl;
return 0;
}
PRINT("-1");
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
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 = 1LL << 60;
const int inf = 1001001001;
int main(){
ll n, q;
string s;
cin >> n >> q >> s;
vector<ll> dp(n, 0);
for(ll i = 0; i < n-1; i++){
if(s[i] == 'A' && s[i+1] == 'C'){
dp[i+1] = (dp[i] + 1);
}
else{
dp[i+1] = dp[i];
}
}
while(q){
ll l,r;
cin >> l >> r;
cout << dp[r-1] - dp[l-1] << endl;
q--;
}
} | #include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;
int main(){
int n,q;
cin >> n >> q;
string s;
cin >> s;
vector<int> cnt;
cnt.push_back(0);
int tmp=0;
for(int i=1;i<n;i++){
if(s.at(i-1)=='A' && s.at(i)=='C') {
tmp++;
cnt.push_back(tmp);
}else{
cnt.push_back(tmp);
}
}
for(int i=0;i<q;i++){
int r,l;
cin >> r >> l;
int ans=cnt.at(l-1)-cnt.at(r-1);
cout << ans << endl;
}
} | 1 |
#include<cstdio>
const int mod=1000000007;
long long power(long long a,int k){
long long ans=1,y=a;
while(k){
if(k%2)
ans=ans*y%mod;
y=y*y%mod;
k=k/2;
}
return ans;
}
long long fun[1<<17],ans=1;
int main(){
long long n,m;
scanf("%lld%lld",&n,&m);
fun[0]=1;
for(int i=1;i<1<<17;i++){
fun[i]=fun[i-1]*i%mod;
}
for(int i=2;i*i<=m;i++){
if(m%i==0){
long long s=0;
while (m%i==0) {
m=m/i;
s++;
}
ans=ans*fun[n+s-1]%mod*power(fun[n-1], mod-2)%mod*power(fun[s], mod-2)%mod;
}
}
if(m>1)
ans=ans*n%mod;
printf("%lld\n",ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
t=0; char ch=getchar(); int f=1;
while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(1e5)+10;
const int mod=(1e9)+7;
const int M=(1e7)+9;
int n,m,tot,d[maxn],iv[maxn],ivjc[maxn],jc[maxn];
int dp[40][maxn],ans;
vector<int> g[maxn];
struct Haxi {
int to[maxn],tot,head[M],nxt[maxn],w[maxn];
void insert(int x,int y) {
tot++; nxt[tot]=head[x%M];
head[x%M]=tot; to[tot]=x; w[tot]=y;
}
int find(int x) {
for (int i=head[x%M];i;i=nxt[i])
if (to[i]==x) return w[i];
return 0;
}
} Map;
int C(int x,int y) {
if (x<y||y<0) return 0;
return (ll)jc[x]*ivjc[y]%mod*ivjc[x-y]%mod;
}
void update(int &x,int y) {
x+=y; if (x>=mod) x-=mod;
}
int main() {
read(n); read(m);
iv[0]=jc[0]=ivjc[0]=iv[1]=jc[1]=ivjc[1]=1;
for (int i=2;i<maxn;i++) {
jc[i]=(ll)jc[i-1]*i%mod;
iv[i]=(ll)(mod-mod/i)*iv[mod%i]%mod;
ivjc[i]=(ll)ivjc[i-1]*iv[i]%mod;
}
for (int i=1;(ll)i*i<=m;i++)
if (m%i==0) {
d[++tot]=i;
if (m/i!=i) d[++tot]=m/i;
}
sort(d+1,d+tot+1);
int x;
for (int i=1;i<=tot;i++) {
Map.insert(d[i],i);
x=d[i];
for (int j=1;(ll)j*j<=d[i];j++)
if (x%j==0) {
g[Map.find(j)].push_back(i);
if (x/j!=j) g[Map.find(x/j)].push_back(i);
}
}
int mx=min(n,35);
dp[0][1]=1;
for (int i=0;i<mx;i++)
for (int j=1;j<=tot;j++) if (dp[i][j]) {
for (int k=0;k<g[j].size();k++) if (g[j][k]!=j) {
update(dp[i+1][g[j][k]],dp[i][j]);
}
}
for (int i=0;i<=mx;i++) {
update(ans,(ll)dp[i][tot]*C(n,i)%mod);
}
printf("%d\n",ans);
return 0;
}
/*
0. Enough array size? Enough array size? Enough array size? Interger overflow?
1. Think TWICE, Code ONCE!
Are there any counterexamples to your algo?
2. Be careful about the BOUNDARIES!
N=1? P=1? Something about 0?
3. Do not make STUPID MISTAKES!
Time complexity? Memory usage? Precision error?
*/ | 1 |
#include <iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define INF bit(60)
#define pb push_back
#define mod 1000000007
using namespace std;
using uif = uint_fast64_t;
using ll = long long int;
using tTree = __gnu_pbds::tree<ll, __gnu_pbds::null_type, less<ll>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
#define FACSIZE 200002
ll invfac[FACSIZE];
ll fac[FACSIZE];
template <class T>
bool chmax(T &, const T &);
template <class T>
bool chmin(T &, const T &);
ll gcd(ll, ll);
ll powLL(ll x, ll y);
ll mod_pow(ll, ll);
ll mod_add(ll, ll);
ll mod_mul(ll, ll);
ll mod_div(ll, ll);
ll comb(ll, ll);
void make_fact(ll);
void make_invfact(ll);
void fact_init();
char f(ll i, char center, char left, string &s)
{
char c;
if (center == 'S')
{
if (s[i] == 'o')
{
return left;
}
else
{
if (left == 'S')
return 'W';
else
return 'S';
}
}
else
{
if (s[i] == 'o')
{
if (left == 'S')
return 'W';
else
return 'S';
}
else
return left;
}
return c;
}
int main(void)
{
ll n;
cin >> n;
string s;
cin >> s;
vector<string> cand(4);
cand[0] = "SS";
cand[1] = "SW";
cand[2] = "WS";
cand[3] = "WW";
for (ll k = 0; k < 4; k++)
{
//cout << k << endl;
string ans = cand[k];
for (ll i = 1; i < n - 1; i++)
{
//cout << i << endl;
auto c = f(i, ans[i], ans[i - 1], s);
ans += c;
}
auto center = ans[n - 1];
auto left = ans[n - 2];
if (f(n - 1, center, left, s) == ans[0])
{
if (f(0, ans[0], ans[n - 1], s) == ans[1])
{
cout << ans << endl;
return 0;
}
}
}
cout << -1 << endl;
return 0;
}
ll mod_pow(ll x, ll r)
{
if (r == 0)
return 1;
else if (r == 1)
return x % mod;
else if (r % 2 == 0)
{
ll t = mod_pow(x, r / 2) % mod;
return mod_mul(t, t);
}
else
{
ll t = mod_pow(x, r / 2) % mod;
ll k = mod_mul(t, t);
return (k % mod) * (x % mod);
}
}
ll mod_add(ll a, ll b)
{
return ((a % mod) + (b % mod)) % mod;
}
ll mod_mul(ll a, ll b)
{
return ((a % mod) * (b % mod)) % mod;
}
ll mod_div(ll a, ll b)
{
return mod_mul(a, mod_pow(b, mod - 2));
}
void fact_init()
{
make_fact(FACSIZE - 1);
make_invfact(FACSIZE);
}
void make_fact(ll n)
{
fac[0] = 1;
rep(i, n)
{
fac[i + 1] = mod_mul(fac[i], i + 1);
}
}
void make_invfact(ll n)
{
invfac[n] = mod_pow(fac[n], mod - 2);
for (int i = n - 1; i >= 0; i--)
{
invfac[i] = mod_mul(invfac[i + 1], i + 1);
}
}
ll comb(ll n, ll r)
{
return mod_mul(mod_mul(fac[n], invfac[r]), invfac[n - r]);
}
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 qp(ll a, ll b)
{
ll ans = 1LL;
do
{
if (b & 1LL)
ans = 1LL * mod_mul(ans, a) % mod;
a = 1LL * mod_mul(a, a) % mod;
} while (b >>= 1LL);
return ans;
}
ll qp(ll a, ll b, ll mo)
{
ll ans = 1LL;
do
{
if (b & 1LL)
ans = 1LL * (ans % mo) * (a % mo);
a = 1LL * (a % mo) * (a % mo);
} while (b >>= 1LL);
return ans;
}
ll gcd(ll a, ll b)
{
return b ? gcd(b, a % b) : a;
}
ll powLL(ll x, ll y)
{
ll ans = 1LL;
for (ll i = 0LL; i < y; i++)
ans *= x;
return ans;
} | #include <iostream>
#include <string>
int main() {
std::string s, t; std::cin >> s >> t;
std::cout << (t+s) << std::endl;
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
string str;
cin>>str;
cout<<2018<<str.substr(str.find('7')+1)<<endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
string ans = "Yes";
for(int i=0; i<s.size(); i++)
{
if(i%2==0 && s.at(i) != 'h') ans = "No";
else if(i%2==1 && s.at(i) != 'i') ans = "No";
}
if(s.length()%2==1) ans = "No";
cout << ans << '\n';
return 0;
}
| 0 |
/**
* @brief 8クイーン問題を扱う
*
* @date 2016/02/29
*/
//****************************************
// 必要なヘッダファイルのインクルード
//****************************************
#include <iostream>
#include <vector>
//****************************************
// 型シノニム
//****************************************
using array1D = std::vector<int>;
using array2D = std::vector<array1D>;
//****************************************
// 大域変数の定義
//****************************************
static const int N = 8; /**< マスの数 */
static const int FREE = 0, NOFREE = 1; /**< クイーンが配置できるか否か */
//****************************************
// 構造体の定義
//****************************************
struct board {
array1D row; /**< row[x]がNOFREEならば行xは被襲撃位置 */
array1D col; /**< col[x]がNOFREEならば列xは被襲撃位置 */
array1D dpos; /**< dpos[x]がNOFREEならば左下の列xは被襲撃位置 */
array1D dneg; /**< dneg[x]がNOFREEならば右下の列xは被襲撃位置 */
array2D state; /**< 盤面の状態 */
board() : row(N, FREE), col(N, FREE),
dpos(2 * N - 1, FREE), dneg(2 * N - 1, FREE),
state(N, array1D(N, FREE)) { }
/**< 盤面の状態を印刷する */
void print()
{
for (int y = 0; y < N; y++) {
for (int x = 0; x < N; x++) {
if (state[y][x] && row[y] != x) { return; }
}
}
for (int y = 0; y < N; y++) {
for (int x = 0; x < N; x++) {
std::cout << ((row[y] == x) ? "Q" : ".");
}
std::cout << std::endl;
}
}
/**< @brief 座標(x, y)にQueenを配置する */
void move(int x, int y)
{
row[y] = x;
col[x] = dpos[y + x] = dneg[y - x + N - 1] = NOFREE;
}
/**< @brief 座標(x, y)からQueenを取り除く */
void undo(int x, int y)
{
row[y] = col[x] = dpos[y + x] = dneg[y - x + N - 1] = FREE;
}
/**< @brief 座標(x, y)にQueenを配置可能かどうか調べる */
bool canMove(int x, int y)
{
return !(col[x] || dpos[y + x] || dneg[y - x + N - 1]);
}
/**
* @brief 再帰的に盤面を探索し、Queenが配置できる場所を探す
* @param 探索対象のy座標
*/
void visit(int y)
{
// Queenの配置に成功した
if (y >= N) { print(); return; }
for (int x = 0; x < N; x++) {
// 座標(x, y)が配置不可能な場合、continue
if (!canMove(x, y)) { continue; }
move(x, y); // 座標(x, y)にQueenを配置する
visit(y + 1); // 次の行へ再帰
undo(x, y); // 座標(x, y)からQueenを取り除く
}
}
/**< @brief 座標(x, y)にQueenを初期段階で配置する */
void initqueen(int x, int y)
{
state[y][x] = true;
}
};
//****************************************
// 関数の定義
//****************************************
int main()
{
using namespace std;
board B;
int k; cin >> k;
for (int i = 0; i < k; i++) {
int r, c; cin >> r >> c;
B.initqueen(c, r);
}
B.visit(0);
return 0;
} | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define INIVAL 2147483647
int *a, *ts, c, s, t, v;
void update(int k, int l, int r)
{
if (r<s || t<=l) return;
if (s<=l && r<=t) {
a[k] = v;
ts[k] = c;
} else if (l<r-1) {
update(((k+1)<<1)-1, l, (l+r)>>1);
update((k+1)<<1, (l+r)>>1, r);
}
}
int main()
{
int i, k, n, z, w, latest;
char *p,buf[64] = {0};
buf[62] = '\n';
fgets(buf, 64, stdin);
for (n=0,p=buf; *p>' '; n=n*10+*(p++)-'0');
w = n>1 ? pow(2,(int)ceil(log2(n)))-1 : 1;
ts = (a = (int*)malloc((w+n)*2*sizeof(int))) + w+n;
for (i=0; i<w+n; i++) ts[i] = -1;
a[0] = INIVAL;
ts[0] = 0;
c = 0;
while (fgets(buf, 64, stdin)) {
for (s=0,p=buf+2; *p>' '; s=s*10+*(p++)-'0');
if (*buf=='0') { // update(s, t, x)
for (t=0,p++; *p>' '; t=t*10+*(p++)-'0');
for (v=0,p++; *p>' '; v=v*10+*(p++)-'0');
t++;
update(0, 0, w+1);
c++;
} else { // find(x) x->s
latest = -1;
for (k=w+s; ; k=(k-1)>>1) {
if (ts[k]>latest) {
latest = ts[k];
z = a[k];
}
if (k==0) break;
}
if (z<10) {
putc_unlocked('0'+z, stdout);
putc_unlocked('\n', stdout);
} else {
for (i=62; z>0; buf[--i]='0'+z%10,z/=10);
fputs(buf+i, stdout);
}
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int x, y, add = 1;
cin >> x >> y;
if ((x > 0 && y > 0) || (x < 0 && y < 0)) {
if (x < y)
add = 0;
else
add = 2;
} else if (x == 0 && y > 0)
add = 0;
else if (x < 0 && y == 0)
add = 0;
cout << abs(abs(x) - abs(y)) + add << endl;
}
| #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main() {
int N, M;
cin >> N >> M;
vector<int> num(N, -1);
for (int i=0; i<M; i++) {
int si, ci;
cin >> si >> ci;
si--;
if ((num[si] != -1) && (num[si] != ci)){
cout << -1;
return 0;
}
num[si] = ci;
}
if (N == 1) {
if (num[0] == -1) {
cout << 0;
return 0;
} else {
cout << num[0];
return 0;
}
} else {
for (int j=0; j<N; j++){
if (j == 0 && num[j] == 0) {
cout << -1;
return 0;
}
if (j == 0 && (num[j] == -1)){
num[j] = 1;
}
if (num[j] == -1) {
num[j] = 0;
}
}
}
// // bool first_val = true;
// for (int j=0; j<N; j++) {
// if ((j == 0) && (num[j] == 0) && (N != 1)){
// cout << -1;
// return 0;
// } else if ((j == 0) && (num[j]==-1)) {
// num[j] = 1;
// }
// // if (num[j] != -1) first_val = false;
// // if ((j==0) && (num[j] == -1)) num[j] = 1;
// if (num[j] == -1){
// num[j] = 0;
// }
// }
int ans = 0;
for (int k=0; k<N;k++) {
ans = ans * 10 + num[k];
}
cout << ans << endl;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
int n,offset,j,pre,ans;
string s,t;
deque<int> q;
int main()
{
cin>>n>>s>>t;
q.push_back(n);j=n-1;
for (int i=n-1;i>=0;i--)
{
pre=j;
while(j>=0 && (j>i || s[j]!=t[i])) j--;
if (j<0)
{
printf("-1\n");
return 0;
}
if (pre==j)
{
while(!q.empty() && q.back()-offset>=i) q.pop_back();
q.push_back(i+offset);
}
else
{
offset++;
if (i!=j)
{
ans=max(ans,(int)q.size());
q.push_front(j+offset);
}
}
}
cout<<ans<<endl;
return 0;
} | #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
using namespace std;
char s[1010101];
char t[1010101];
stack <int> p[26];
int q[1010101],qs=1,qe=0;
int cc[1010101];
int main()
{
int n,la,now,c=0,ans=0;
scanf("%d",&n);
now=n;
la=n+1;
scanf("%s",s+1);
scanf("%s",t+1);
for(int i=1;i<=n;i++)
p[s[i]-'a'].push(i);
for(int i=n;i>=1;i--)
{
while(now>i)
now--;
while(!p[t[i]-'a'].empty()&&p[t[i]-'a'].top()>now)
p[t[i]-'a'].pop();
if(p[t[i]-'a'].empty())
{
printf("-1");
return 0;
}
now=p[t[i]-'a'].top();
if(now==la||now==i)
{
la=now;
continue;
}
la=now;
while(qs<=qe&&q[qs]-cc[qs]-c+1>i)
{
ans=max(ans,cc[qs]+c);
qs++;
}
c++;
q[++qe]=now;
cc[qe]=1-c;
}
for(int i=qs;i<=qe;i++)
ans=max(ans,cc[i]+c);
printf("%d",ans);
return 0;
} | 1 |
#include<bits/stdc++.h>
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
#define mp make_pair
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define endl '\n'
#define int long long int
using namespace std;
signed main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
string s;cin >> s;
int n = s.length();
int k;cin >> k;
vector<vi> dp(n+1, vi(n+1));
vector<vi> prev(n+1, vi(n+1));
for(int change = 0; change <= k; change++){
for(int len = 1; len <= n; len++){
for(int start =0; start <= n - len; start++){
dp[start][len] = max(dp[start+1][len-1], dp[start][len-1]);
if(s[start] == s[start + len -1]){
dp[start][len] = max(1 + (len != 1) + dp[start+1][max(len-2,0LL)], dp[start][len]);
}else if(change > 0){
dp[start][len] = max(1 + (len != 1) + prev[start+ 1][max(len-2,0LL)], dp[start][len]);
// cout << dp[start][len] << " ";
}
}
// cout << endl;
}
swap(dp, prev);
}
cout << prev[0][n];
}
| #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 |
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iterator>
#include <fstream>
#include <math.h>
#include <random>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <list>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <ctime>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, from, to) for (int i = from; i < to; i++)
#define ROF(i, from, to) for (int i = from; i > to; i--)
const long double PI = 3.141592653589793238463;
const int INF = 0x3f3f3f3f;
const int INFS = 1000000000;
const ll M = 1000000007;
const ll LLINF = 1000000000000000000;
const double EPS = 1e-8;
#define int long long
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<int> x(n);
map<int, int> mp = {};
FOR(i, 0, n) {
cin >> x[i];
mp[x[i]] = i;
}
int l;
cin >> l;
vector<vector<int> > st(n, vector<int>(21));
FOR(i, 0, n)
st[i][0] = mp[*(--upper_bound(x.begin(), x.end(), x[i] + l))];
FOR(j, 1, 21) {
FOR(i, 0, n) {
st[i][j] = st[st[i][j - 1]][j - 1];
// cout << i << ' ' << j << ' ' << st[i][j] << endl;
}
}
int m, a, b, cr, ans;
cin >> m;
while (m--) {
cin >> a >> b;
if (a > b)
swap(a, b);
--a; --b;
ans = 0;
cr = a;
ROF(j, 20, -1) {
if (st[cr][j] < b) {
cr = st[cr][j];
ans += (1 << j);
}
}
++ans;
cout << ans << "\n";
}
return 0;
}
| #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
using ll = long long;
using namespace std;
#define LOG_MAX 30
// 1つ先が無い(木の根など)場合、値を負かn以上とする
template <typename T>
class Doubling {
const size_t n;
vector<vector<T>> next;
public:
Doubling() {}
Doubling(vector<T> first_row)
: n(first_row.size()),
next(LOG_MAX, vector<T>(n)) {
copy(first_row.begin(), first_row.end(), next[0].begin());
for (size_t i=1; i<LOG_MAX; i++) {
for (size_t j=0; j<n; j++) {
next[i][j] = (
(0 <= next[i-1][j] && (size_t)next[i-1][j] < n)
? next[i-1][(size_t)next[i-1][j]]
: next[i-1][j]
);
}
}
}
T query(T i, int step=1) {
for (int k=LOG_MAX-1; k>=0; k--) {
if ((step >> k) & 1) i = next[(size_t)k][(size_t)i];
if (i < 0 || n <= (size_t)i) break;
}
return i;
}
};
int main() {
int n, q;
cin >> n;
long x[n], l;
for (auto &xi:x) cin >> xi;
cin >> l >> q;
vector<int> first_row(n);
for (int i=0; i<n; i++) {
int ub = upper_bound(x+i, x+n, x[i] + l) - x;
first_row[i] = ub - 1;
}
Doubling<int> db(first_row);
for (int i=0, a, b; i<q; i++) {
cin >> a >> b;
a--; b--;
if (a > b) swap(a, b);
int l=0, r=n-1;
while (r - l > 1) {
int m = (l + r + 1) / 2,
dest = db.query(a, m);
if (b > dest) l = m;
else r = m;
}
cout << r << '\n';
}
return 0;
}
| 1 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <tuple>
#include <bitset>
#include <random>
#define REP(i,n) for(int i=0;i<n;i++)
#define INF 1000000007
using namespace std;
using pii=pair<int,int>;
int main() {
int sx,sy,tx,ty;
cin>>sx>>sy>>tx>>ty;
int dx=tx-sx,dy=ty-sy;
string ans="";
string right(dx,'R'),left(dx,'L'),up(dy,'U'),down(dy,'D');
ans=ans+up+right+down+left+'L'+up+'U'+'R'+right+'D'+'R'+down+'D'+'L'+left+'U';
cout<<ans<<endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array) (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
int a,b,c,d; cin>>a>>b>>c>>d;
rep(i,c-a)cout<<"R";
rep(i,d-b)cout<<"U";
rep(i,c-a)cout<<"L";
rep(i,d-b)cout<<"D";
cout<<"L";
rep(i,d-b+1)cout<<"U";
rep(i,c-a+1)cout<<"R";
cout<<"D"<<"R";
rep(i,d-b+1)cout<<"D";
rep(i,c-a+1)cout<<"L";
cout<<"U"<<endl;
} | 1 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using lint=long long;
int main(){
int n; scanf("%d",&n);
vector<lint> a(n);
rep(i,n) scanf("%lld",&a[i]);
bool ok=(a[0]==0);
rep(i,n-1) if(a[i+1]-a[i]>=2) ok=false;
if(!ok){
puts("-1");
return 0;
}
lint ans=0;
int pre=0;
for(int i=1;i<=n;i++){
if(i==n || a[i-1]+1!=a[i]){
ans+=a[i-1];
pre=i;
}
}
printf("%lld\n",ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define for_(i,a,b) for(int i=a;i<b;++i)
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int n, a[3], p;
int main() {
cin >> n;
for_(i,0,n) cin >> a[i];
p = gcd(a[0], a[1]);
if (n == 3) p = gcd(a[2], p);
vector< int > c;
for_(i,1,0 || i*i <= p) {
if (p % i == 0) {
c.push_back(i);
if (p/i != i) c.push_back(p/i);
}
}
sort(c.begin(), c.end());
for_(i,0,(int)c.size()) {
bool ok = 1;
for_(j,0,n) ok &= (a[j] % c[i] == 0);
if (ok) cout << c[i] << endl;
}
return 0;
} | 0 |
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <bitset>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <stack>
#include <map>
#include <set>
//#include <ordered_set>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll
#define sqr(x) ((x) * (x))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define int long long
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;
const double pi = acos (-1.0);
const double eps = 1e-9;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
int n, x, now;
struct e {
int l, r, b;
}a[N];
bool cmp (e a, e b) {
return (a.r * (x - a.b) + a.l * a.b) > (b.r * (x - b.b) + b.l * b.b);
}
inline bool check (int h) {
now = h;
int ans = 0;
int res = -inf;
bool ok = 0;
for (int i = 1; i <= n; i ++) {
if (h >= x) {
h -= x;
ans += (x - a[i].b) * a[i].r;
}
else {
int sum = 0;
ok = 1;
for (int j = i; j <= n; j ++) {
sum -= a[j].l * a[j].b;
}
for (int j = i; j <= n; j ++) {
sum += a[j].l * a[j].b;
res = max (res, ans + sum + (h - a[j].b) * a[j].l);
res = max (res, ans + sum + (h - a[j].b) * a[j].r);
sum -= a[j].l * a[j].b;
}
for (int j = 1; j < i; j ++) {
int in = ans - (x - a[j].b) * a[j].r + sum + a[i].l * a[i].b;
if (h < a[j].b) in += (h - a[j].b) * a[j].l;
else in += (h - a[j].b) * a[j].r;
in += (x - a[i].b) * a[i].r;
res = max (res, in);
}
break;
}
}
if (!ok) res = ans;
return (res >= 0);
}
inline void boost () {
ios_base :: sync_with_stdio (0);
cin.tie (0), cout.tie (0);
}
inline void Solve () {
cin >> n >> x;
for (int i = 1; i <= n; i ++) cin >> a[i].b >> a[i].l >> a[i].r;
sort (a + 1, a + n + 1, &cmp);
int l = 0, r = inf, pos = -1;
while (l <= r) {
int mid = l + r >> 1;
if (check (mid)) r = mid - 1, pos = mid;
else l = mid + 1;
}
cout << pos;
}
signed main () {
#ifdef QWERTY
freopen("input", "r", stdin);
#endif
// freopen (".in", "r", stdin);
// freopen (".out", "w", stdout);
boost ();
int tt = 1;
//cin >> tt;
while (tt --) {
Solve ();
}
return 0;
} | #include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <numeric>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;
int main(){
int n;
ll x;cin >> n >> x;
vector<ll> a(n);
rep(i,n) cin >> a[i];
ll ans = 0;
if(a[0]>x) {
ans += a[0]-x;
a[0] = x;
}
rep(i,n-1){
//cout << " " << ans << endl;
if(a[i]+a[i+1]>x){
ans += a[i+1] - (x-a[i]);
a[i+1] = x-a[i];
}
}
//rep(i,n) cout << a[i] << endl;
cout << ans << endl;
}
| 0 |
#include <iostream>
#include <vector>
#include<math.h>
#include <algorithm>
using namespace std;
int main()
{
int a;
long long k;
cin>>a;
k=a+a*a+a*a*a;
cout<<k;
} | # include<iostream>
# include<math.h>
using namespace std;
int main()
{
int a,b;
cin>>a;
b=pow(a,1)+pow(a,2)+pow(a,3);
cout<<b<<"\n";
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n,a[9]={111,222,333,444,555,666,777,888,999};
cin>>n;
for(int i=0;i<9;i++){
if(n<=a[i]) {
cout<<a[i]<<endl;
return 0;
}
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
template<typename T>
struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;
/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;
int main()
{
string x; cin>>x;
int s=0;
int t=0;
for (auto c:x) {
if (c == 'S') {
s++;
} else {
if (s > 0) s--;
else t++;
}
}
cout << t+s << endl;
return 0;
}
| 0 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define INF 1010001000
#define loop(i, n) for (int i = 0; i < n; i++)
#define mp make_pair
typedef pair<int, int> i_i;
bool dfs(vector<vector<int> > &g);
int sx, sy, gx, gy;
int w, h;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main()
{
while (cin >> w >> h, (w|h) ) {
w++;
h++;
vector<vector<int> > graph(w, vector<int>(h, 0));
cin >> sx >> sy >> gx >> gy;
int blocks;
cin >> blocks;
loop(i, blocks){
int c, d, x, y;
cin >> c >> d >> x >> y;
if (d) {
for (int j = x; j < x+2; j++) {
for (int k = y; k < y+4; k++) {
graph[j][k] = c;
}
}
} else {
for (int j = x; j < x+4; j++) {
for (int k = y; k < y+2; k++) {
graph[j][k] = c;
}
}
}
}
cout << ((dfs(graph))?"OK":"NG") << endl;
}
return 0;
}
bool dfs(vector<vector<int> > &g)
{
int cl = g[sx][sy];
vector<vector<bool> > check(w, vector<bool>(h, false));
queue<i_i > q;
q.push(mp(sx,sy));
while(!q.empty()){
int x = q.front().first, y = q.front().second;
q.pop();
if(x == gx && y == gy){
return true;
}
if(check[x][y]){
continue;
} else {
check[x][y] = true;
}
loop(i, 4) {
int nx = x + dx[i], ny = y + dy[i];
if (0 < nx && nx < w && 0 < ny && ny < h){
if (g[nx][ny] == cl){
q.push(mp(nx,ny));
}
}
}
}
return false;
} | #include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define INF 100000005
#define MAX 100001
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
bool b[501];
int main(){
int n, m, t1,t2;
while(1){
stack<int> s[501];
scanf("%d%d", &n, &m);
if(!n)break;
fill(b, b+501, false);
rep(i,m){
scanf("%d%d", &t1, &t2);
s[t1].push(t2);
s[t2].push(t1);
}
while(!s[1].empty()){
t1 = s[1].top();s[1].pop();
b[t1] = 1;
while(!s[t1].empty()){
t2 = s[t1].top();s[t1].pop();
b[t2] = true;
}
}
int ans = 0;
rrep(i,n)if(b[i]&&i!=1)ans++;
printf("%d\n", ans);
}
return 0;
} | 0 |
#include<bits/stdc++.h>
#include <algorithm>
#include <complex>
using namespace std;
typedef long long ll;
typedef complex<long double> point;
const ll N = 2e5+5,mod=1e9+7,inf=1e9+5;
long double pi=3.14159265359;
ll a[N],b[N],inv[N],fact[N];
int n,c;
ll fp(int base,int exp){
if(exp==0)return 1;
ll ans=fp(base,exp/2);
ans=(ans*ans)%mod;
if(exp%2)
ans=(ans*base)%mod;
return ans;
}
ll ncr(int n,int r){
return ((fact[n]*inv[n-r])%mod*inv[r])%mod;
}
int main()
{
iostream::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,m,mm;
inv[0]=fact[0]=1;
for(int i=1;i<2e5;i++){
fact[i]=(i*fact[i-1])%mod;
inv[i]=fp(fact[i],mod-2);
}
cin>>n>>m;
mm=m;
ll ans=1;
for(int i=2;i*i<=m;i++){
int c=0;
while(m%i==0){
m/=i;
c++;
}
ans*=ncr(n+c-1,c);
ans%=mod;
}
if(m>1){
ans*=n;
ans%=mod;
}
cout<<ans;
return 0;
}
| #include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define inver(a) power(a, mod - 2)
using namespace std;
inline char nc()
{
return getchar();
static char buf[100000], *l = buf, *r = buf;
return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x)
{
x=0; int f=1,ch=nc();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
x*=f;
}
typedef long long ll;
const int mod = 998244353;
const int MAXK = 2000 + 5;
const int MAXN = 2000 + 5;
int K, N;
inline int add(int x) {return x >= mod ? x - mod : x;}
ll power(ll x, ll y)
{
ll re = 1;
while(y)
{
if(y & 1) re = re * x % mod;
x = x * x % mod;
y >>= 1;
}
return re;
}
const int maxn = MAXN + MAXK;
int fac[maxn];
int inv[maxn];
void init_binom(int n)
{
fac[0] = 1;
for(int i = 1; i <= n; ++i)
{
fac[i] = (ll)fac[i - 1] * i % mod;
}
inv[n] = inver(fac[n]);
for(int i = n; i >= 1; --i)
{
inv[i - 1] = (ll)inv[i] * i % mod;
}
}
int binom(int x, int y)
{
if(x < y) return 0;
return (ll)fac[x] * inv[y] % mod * inv[x - y] % mod;
}
int F(int x, int y)
{
if(x == 0 && y == 0) return 1;
return binom(x + y - 1, x);
}
int sol(int k, int n, int m)
{
int an = 0;
for(int j = 0, p = 1; j <= m && j <= n; ++j)
{
an = (an + (ll)binom(m, j) * F(n - j, k - 2 * m + j) % mod * p) % mod;
p = add(p << 1);
}
return an;
}
int main()
{
read(K), read(N);
init_binom(K + N);
for(int i = 2; i <= 2 * K; ++i)
{
int m = 0;
for(int a = 1, b = i - 1; a < b; ++a, --b)
{
if(b <= K) ++m;
}
if(i & 1) printf("%d\n", sol(K, N, m));
else printf("%d\n", add(sol(K - 1, N, m) + sol(K - 1, N - 1, m)));
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(int argc, const char *argv[]) {
int n, m;
cin >> n >> m;
vector<ll> va(n);
for (int i = 0; i < n; ++i) {
cin >> va[i];
}
vector<ll> csum{0};
partial_sum(va.begin(), va.end(), back_inserter(csum));
map<ll, ll> cnts;
for (auto s : csum) {
cnts[s % m]++;
}
ll ans = 0;
for (auto &p : cnts) {
ans += (p.second * (p.second - 1)) / 2;
}
cout << ans << '\n';
return 0;
} | #include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
const double PI = 3.14159265358979323846264338327950288;
ll A[100010];
ll sum[100010];
int main()
{
int N;
ll M;
cin >> N >> M;
for (int i = 0; i < N; i++) cin >> A[i];
ll ans = 0;
map<ll, ll> mp;
for (int i = 0; i < N; i++) {
sum[i + 1] = (sum[i] + A[i]) % M;
}
sort(sum, sum + N + 1);
ll cnt = 1;
for (int i = 0; i < N; i++) {
if (sum[i] == sum[i + 1]) {
cnt++;
}
else {
ans += cnt * (cnt - 1) / 2;
cnt = 1;
}
}
ans += cnt * (cnt - 1) / 2;
cout << ans << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int R;
cin >>R;
double a=3.14;
cout << 2*R*a << endl;
} | #include <bits/stdc++.h>
using namespace std;
//型名省略
typedef long long ll;
typedef vector<long long> vl;
typedef vector<vector<long long>> vvl;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
//マクロ
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define rep2(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define all(A) A.begin(), A.end()
//正誤判定
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}
//main関数
int main() {
double PI = 3.1415926536;
ll r; cin >> r;
cout << 2 * r * PI << endl;
} | 1 |
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<utility>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<list>
#include<set>
#include<stdlib.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
vector<long long> Prime;
void SieveOfEratosthenes(long long e) //setup vector<long long>Prime(~x)
{
bool *x=new bool[e];
for (long long i = 0; i <= e; i++)x[i] = false;
for (long long i = 2; i <= e; i++)
{
if (x[i]);
else
{
Prime.push_back(i);
for (long long l = i; l <= e; l += i)x[l] = true;
}
}
return;
}
struct XY
{
int x;
int y;
};
int in()
{
int x;
cin >> x;
return x;
}
/*
(char)'1' - (int)48 = (int)1;
???1111181
*/
////////////////////////////////////////////////////
int main()
{
vector<pair<int, int > > ans;
for (int i = 1; i <= 150; i++)
{
for (int l = i+1; l <= 150; l++)
{
pair<int, int> now;
now.first = i*i + l*l;
now.second = i;
ans.push_back(now);
}
}
bool enn = true;
while (enn)
{
enn = false;
for (int i = 1; i < ans.size(); i++)
{
if (ans[i].first == ans[i - 1].first&&ans[i].second < ans[i-1].second)
{
swap(ans[i], ans[i - 1]);
enn = true;
}
if (ans[i].first < ans[i - 1].first)
{
swap(ans[i], ans[i - 1]);
enn = true;
}
}
}
int h,w;
while (cin>>h>>w&&h)
{
int t = h*h + w*w;
rep(i, ans.size())
{
if (ans[i].first==t&&h<ans[i].second)
{
cout << ans[i].second << " " << sqrt(ans[i].first - (ans[i].second*ans[i].second)) << endl;
break;
}
else if (ans[i].first > t)
{
cout << ans[i].second << " " << sqrt(ans[i].first - (ans[i].second*ans[i].second)) << endl;
break;
}
}
}
} | # include <bits/stdc++.h>
using namespace std;
char s[1000010];
char t[1000010];
int n;
queue<int> q;
int main() {
scanf("%d", &n); scanf("%s", s); scanf("%s", t);
if(strcmp(s, t) == 0) { puts("0"); return 0; }
int k = n - 1;
int ans = 0;
int last = -1;
for(int i = n - 1; i >= 0; --i) {
k = min(k, i);
while(k >= 0 && s[k] != t[i]) --k;
if(k < 0) { puts("-1"); return 0; }
if(k==last) continue; last=k;
while(q.size() && i < q.front() - (int)q.size() + 1) q.pop();
q.push(k);
ans = max(ans, (int)q.size());
}
printf("%d\n",ans);
return 0;
}
| 0 |
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };
string S;
signed main(){
cin >> S;
rep(i, 8) S.pop_back();
cout << S << endl;
} | #include <algorithm>
#include <iostream>
#include <vector>
int main()
{
std::string s;
std::cin >> s;
std::cout << s.substr(0, s.length() - 8) << std::endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void)
{
vector<ll> cost(5);
ll N;
cin >> N;
for (int i = 0; i < 5; i++)
{
cin >> cost[i];
}
ll result = (ll) ceil((double) N / *min_element(cost.begin(), cost.end())) + 4;
cout << result << endl;
return 0;
}
| #include <iostream>
#include <vector>
using namespace std;
int main(){
int n;
cin >> n;
vector<int> a(n);
int mod = 1000000007;
long long sum = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
sum += a[i];
sum %= mod;
}
long ans = 0;
for(int j = 0; j < n; j++){
sum -= a[j];
if(sum < 0) sum += mod;
ans += a[j] * sum;
ans %= mod;
}
cout << ans << endl;
return 0;
}
| 0 |
#include<bits/stdc++.h>
#define fo(i,a,b) for(register int (i)=(a);(i)<=(b);++(i))
#define rd read()
#define maxn 200001
#define gc getchar()
#define mem(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define pb push_back
#define db double
#define pu puts(" ")
using namespace std;
const int p=998244353;
int read()
{
int x=0,f=1;
char ch=gc;
while(!isdigit(ch))
{
if(ch=='-')f=-1;
ch=gc;
}
while(isdigit(ch))x=x*10+ch-48,ch=gc;
return x*f;
}
void print(int x)
{
if(x<0)putchar('-'),x=-x;
if(x>9)print(x/10);
putchar(x%10+48);
}
int qp(int a,int b)
{
int ans=1;
while(b)
{
if(b&1)ans=(ll)ans*a%p;
a=(ll)a*a%p;
b>>=1;
}
return ans%p;
}
int main()
{
int a=rd,b=rd,k=rd;
fo(i,1,k)
{
if(i%2==1)
{
if(a%2==1)a--;a/=2,b+=a;}
else{if(b%2==1)b--;b/=2,a+=b;}
}
printf("%d %d\n",a,b);
return 0;
} | #include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(string &a){reverse(a.begin(),a.end()) ;}
int main(){
ll a,b,k ;
cin >> a >> b >> k ;
for(int i=0;i<k;i++){
if(i&1){
b -= (b&1) ;
a += b/2 ;
b /= 2 ;
}else{
a -= (a&1) ;
b += a/2 ;
a /= 2 ;
}
}
cout << a << " " << b << endl ;
}
| 1 |
#include <bits/stdc++.h>
#define INF 100000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;
int main()
{
ll N;
cin >> N;
vector<ll> A(N);
for (ll i = 0; i < N; ++i) {
cin >> A.at(i);
}
sort(A.begin(), A.end());
ll ans = 0;
vector<bool> used(N, false);
for (ll i = N - 1; i >= 0; --i) {
if (used.at(i)) {
continue;
}
used.at(i) = true;
ll pow2 = 1;
while (pow2 <= A.at(i)) {
pow2 *= 2;
}
ll need = pow2 - A.at(i);
ll l = lower_bound(A.begin(), A.end(), need) - A.begin() - 1;
ll r = upper_bound(A.begin(), A.end(), need) - A.begin();
r = min(r, i);
// cout << "nned" << need << endl;
// cout << l << ' ' << r << endl;
if (l == r) {
continue;
}
while (l + 1 != r) {
ll m = (l + r) / 2;
if (used.at(m)) {
l = m;
}
else {
r = m;
}
}
// cout << "l" << l << "r" << r << endl;
if (r == N) {
continue;
}
if (A.at(r) != need) {
continue;
}
if (used.at(r)) {
continue;
}
used.at(r) = true;
ans += 1;
// for (ll j = l; j < r; ++j) {
// if (!used.at(j)) {
// used.at(j) = true;
// ans += 1;
// break;
// }
// }
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
ll n,ans=0;cin>>n;
multiset<ll> st;
for(ll i=0,x;i<n;i++)cin>>x,st.insert(x);
while(!st.empty()){
auto itr= st.end();
itr--;
ll val = *itr;
st.erase(itr);
ll p=0;
while(val >= (1ll<<p) )p++;
ll req = (1ll<<p) - val;
itr=st.find(req);
if(itr==st.end())continue;
ans++;
st.erase(itr);
}
cout<<ans;
}
| 1 |
#include <bits/stdc++.h>
#define re register
#define SIZE 305
#define INF 0x7f7f7f
using namespace std;
int n;
int a[SIZE];
int cnt[5];
double dp[SIZE*3][SIZE*2][SIZE],ans=0;
inline double dfs(int i,int j,int k)
{
if(dp[i][j][k]!=-1)
return dp[i][j][k];
dp[i][j][k]=0;
double x=i*1.0,y=j*1.0,z=k*1.0;
double m=x+y+z;
if(i+j+k<n)
dp[i][j][k]+=dfs(i+1,j,k)*(x+1)/(m+1);
if(i-1>=0)
dp[i][j][k]+=dfs(i-1,j+1,k)*(y+1)/m;
if(j-1>=0)
dp[i][j][k]+=dfs(i,j-1,k+1)*(z+1)/m;
return dp[i][j][k];
}
int main()
{
scanf("%d",&n);
for(re int i=1;i<=n;++i)
scanf("%d",&a[i]),++cnt[a[i]];
for(re int i=0;i<=cnt[3]+cnt[2]+cnt[1]+1;++i)
for(re int j=0;j<=cnt[3]+cnt[2]+1;++j)
for(re int k=0;k<=cnt[3]+1;++k)
if(i>cnt[3]+cnt[2]+cnt[1] || j>cnt[3]+cnt[2] || k>cnt[3])
dp[i][j][k]=0;
else
dp[i][j][k]=-1;
dp[cnt[1]][cnt[2]][cnt[3]]=1;
for(re int i=0;i<=cnt[3]+cnt[2]+cnt[1];++i)
for(re int j=0;j<=cnt[3]+cnt[2];++j)
for(re int k=0;k<=cnt[3];++k)
{
if(i==0 && j==0 && k==0)
continue;
ans+=(double) (dfs(i,j,k)*n)/(double) (i+j+k);
}
printf("%.10lf\n",ans);
return 0;
} | //Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double
int n;
int vis[302][302][302];
double cache[302][302][302];
double dp(int one,int two,int three)
{
int tot=one+two+three;
if(!tot)
return 0;
if(one<0 || two<0 || three<0)
return -1;
if(vis[one][two][three])
return cache[one][two][three];
double ans=0;
double x=n*1.0/(n-(n-tot)*1.0);
ans=x*((n-tot)*1.0/n + (one*1.0/n)*(1+dp(one-1,two,three))
+(two*1.0/n)*(1+dp(one+1,two-1,three))
+(three*1.0/n)*(1+dp(one,two+1,three-1)));
vis[one][two][three]=1;
return cache[one][two][three]=ans;
}
int32_t main()
{
IOS;
cin>>n;
int freq[4]={};
for(int i=0;i<n;i++)
{
int a;
cin>>a;
freq[a]++;
}
cout<<fixed<<setprecision(12);
cout<<dp(freq[1],freq[2],freq[3]);
}
| 1 |
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000000
#define MAX 200001
#define MOD 1000000007
template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};
int main(){
int N;
cin >> N;
vector<ll> A(N);
for(int i = 0; i < N; i++) cin >> A[i];
reverse(A.begin(), A.end());
vector<ll> dp(N,INF);
for(int i = 0; i < N; i++){
auto iter = upper_bound(dp.begin(), dp.end(), A[i]);
ll idx = iter - dp.begin();
dp[idx] = A[i];
}
cout << lower_bound(dp.begin(), dp.end(), INF) - dp.begin() << endl;
} | //
// Created on 2020/08/10.
//
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
int main() {
int n;
cin>>n;
vector<int>L;
int init;
cin>>init;
L.push_back({init});
for (int i = 1; i < n; ++i) {
int a;
cin>>a;
int ok = L.size() - 1;
int ng = -1;
int mid = (ok + ng) / 2;
while(1 < abs(ok - ng)){
if(L[mid] < a){
ok = mid;
}else{
ng = mid;
}
mid = (ok + ng) / 2;
}
if(L[ok] < a){
L[ok] = a;
}else if(L[ok] >= a){
L.push_back(a);
}}
cout<<L.size()<<endl;
return 0;
}
| 1 |
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#define ll long long
using namespace std;
int d,dep,m;
ll ans;
int c[20],c0[20];
ll f[20],a[20];
void dfs(int k,ll w,ll s){
if (k==m){
ans+=1ll*(w==d)*s;
return;
}
if (abs(w-1ll*d)>a[k]*20) return;
int i,cnt;
for (i=0;i<20;i++){
if (!k) cnt=c0[i];
else cnt=c[i];
if (!a[k]) cnt=i<10;
if (!cnt) continue;
dfs(k+1,w+a[k]*1ll*(i-10),s*1ll*cnt);
}
}
void solve(int n){
m=0;
int i;
for (i=0;i<n;i++){
if (i>n-i-1) break;
a[m++]=f[n-i-1]-f[i];
}
dfs(0,0,1);
}
int main(){
int i,j;
f[0]=1; for (i=1;i<=18;i++) f[i]=f[i-1]*10ll;
for (i=0;i<=9;i++)
for (j=0;j<=9;j++) c[i-j+10]++;
for (i=0;i<=9;i++)
for (j=1;j<=9;j++) c0[i-j+10]++;
scanf("%d",&d);
for (dep=1;dep<=19;dep++) solve(dep);
printf("%lld\n",ans);
return 0;
} | #include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long long p10[20];
long long calc(int a,int b,int c,long long d){
if(b>c){
if(d==0)return 1;
else return 0;
}
if(b==c){
if(d==0)return 10;
else return 0;
}
if(ABS(d)>=p10[c+1])return 0;
long long ret=0;
for(int i=-10;i<10;i++){
int ks=10-ABS(i);
if(b==0&&i>=0)ks--;
ret+=calc(a,b+1,c-1,d-i*(p10[c]-p10[b]))*ks;
}
return ret;
}
int main(){
p10[0]=1;
for(int i=1;i<20;i++)p10[i]=p10[i-1]*10;
int a;scanf("%d",&a);
long long ret=0;
for(int i=2;i<=18;i++){
ret+=calc(i,0,i-1,a);
// printf("%d\n",ret);
}
printf("%lld\n",ret);
} | 1 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n;
cin>>n;
ll mi=ll(1e18);
for(int i=0;i<5;i++){
ll a;
cin>>a;
mi=min(mi,a);
}
ll x=n/mi;
if(n%mi==0) x--;
cout<<5+x<<endl;
} | #include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll Nmax=1e9;
const ll INF=1e9;
int main(){
ll n,a,b,c,d,e;
cin>>n>>a>>b>>c>>d>>e;
ll m=min(a,min(b,min(c,min(d,e))));
cout<<(n-1)/m+5;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization ("Ofast")
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define siz(s) (int)s.size()
template<class T> inline bool chmin(T &a, T b) {
if(a>b){a=b;return true;}
return false;
}
template<class T> inline bool chmax(T &a, T b) {
if(a<b){a=b;return true;}
return false;
}
template<class T> inline int getidx(vector<T> &v, T a) {
return lower_bound(all(v), a) - v.begin();
}
constexpr int mod=1e9+7;
constexpr int inf=3e18;
int N,M;
vector<int>G[100005];
vector<int>G2[300005];
bool used[100005];
vector<int>xx;
void dfs(int x){
used[x]=true;
for(int i:G[x])if(!used[i]){
dfs(i);
}
xx.push_back(x);
}
int bfs(){
queue<P>que;
int dis[300005];
fill(dis,dis+300000,inf);
dis[0]=0;que.push({0,0});
while(!que.empty()){
P p=que.front();que.pop();
if(dis[p.second]<p.first)continue;
for(int i:G2[p.second]){
if(dis[i]==inf){
dis[i]=p.first+1;
que.push({dis[i],i});
}
}
}
return dis[N-1];
}
vector<P>edge[1000005];
signed main(){
cin>>N>>M;
rep(i,M){
int a,b,c;cin>>a>>b>>c;a--;b--;c--;
edge[c].push_back({a,b});
}
int now=100000;
rep(i,1000000){
for(P j:edge[i]){
G[j.first].push_back(j.second);
G[j.second].push_back(j.first);
}
for(P j:edge[i]){
if(!used[j.first]){
dfs(j.first);
for(int k:xx){
G2[now].push_back(k);
G2[k].push_back(now);
}
now++;
xx.clear();
}
if(!used[j.second]){
dfs(j.second);
for(int k:xx){
G2[now].push_back(k);
G2[k].push_back(now);
}
now++;
xx.clear();
}
}
for(P j:edge[i]){
used[j.first]=false;
used[j.second]=false;
G[j.first].clear();
G[j.second].clear();
}
}
int ans=bfs();
cout<<(ans==inf?-1:ans/2)<<endl;
}
| #include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 400005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
struct node {
int to,next,val;
}E[MAXN * 10];
int head[MAXN],sumE;
int N,M,Ncnt;
int c[MAXN],dis[MAXN];
vector<int> to[MAXN];
bool vis[MAXN];
priority_queue<pii > Q;
void add(int u,int v,int c) {
E[++sumE].to = v;
E[sumE].next = head[u];
E[sumE].val = c;
head[u] = sumE;
}
void Solve() {
read(N);read(M);
int q,p;
Ncnt = M;
for(int i = 1 ; i <= M ; ++i) {
read(q);read(p);read(c[i]);
to[q].pb(i);to[p].pb(i);
}
for(int i = 1 ; i <= N ; ++i) {
sort(to[i].begin(),to[i].end(),[](int a,int b) {return c[a] < c[b];});
int nw = ++Ncnt;
for(int j = 0 ; j < to[i].size() ; ++j) {
int p = j;
while(p < to[i].size() - 1 && c[to[i][p + 1]] == c[to[i][j]]) ++p;
for(int h = j + 1 ; h <= p ; ++h) {
add(to[i][j],to[i][h],0);
add(to[i][h],to[i][j],0);
}
add(to[i][j],nw,0);
add(nw,to[i][j],1);
j = p;
}
}
for(int i = 1 ; i <= Ncnt ; ++i) dis[i] = 1e9;
for(auto t : to[1]) {dis[t] = 1;Q.push(mp(-1,t));}
while(!Q.empty()) {
pii now = Q.top();Q.pop();
if(vis[now.se]) continue;
int u = now.se;vis[u] = 1;
for(int i = head[u] ; i ; i = E[i].next) {
int v = E[i].to;
if(dis[v] > dis[u] + E[i].val) {
dis[v] = dis[u] + E[i].val;
Q.push(mp(-dis[v],v));
}
}
}
int ans = 1e9;
for(auto t : to[N]) ans = min(ans,dis[t]);
if(ans >= 1e9) {
puts("-1");return;
}
else {out(ans);enter;}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin>>N;
vector<int> vec(N);
for(int i=0;i<N;i++){
cin>>vec.at(i);
}
vector<int> arr(N);
for(int i=0;i<N;i++){
int num=0;
while(vec.at(i)%2==0){
vec.at(i) = vec.at(i)/2;
num+=1;
}
arr.at(i)=num;
}
int ans=arr.at(0);
for(int i=1;i<N;i++){
ans = min(ans, arr.at(i));
}
cout<<ans<<endl;
} | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main()
{
int N;
cin >> N;
int num[N];
int i = 0, count = 0;
while (i < N)
cin >> num[i++];
int flag=0;
while (true)
{
i = 0;
while (i < N)
{
if (num[i] % 2 != 0)
flag = 1;
num[i] /= 2;
i++;
}
if (flag == 1)
break;
count++;
}
cout << count << endl;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const ll mod = 1e9 + 7;
const int maxn = 1e5+5;
vector<int>tar;
ll v[maxn];
ll b[65];
void ins(ll x) {
for (int i = 0 ; i < tar.size() ; i++) {
if (x & (1LL<<(tar[i]))) {
if (b[i]) {
x ^= b[i];
}
else {
b[i] = x;
break;
}
}
}
}
void go() {
int n;
cin >> n;
ll sum = 0;
f1(n) {
cin >> v[i];
sum ^= v[i];
}
for (int i = 60 ; i >= 0 ; i--) {
if (sum & (1LL<<i)) {
}
else {
tar.pb(i);
}
}
f1(n) {
ins(v[i]);
}
ll ans = 0;
for (int i = 0 ; i < tar.size() ; i++) {
if (b[i] && !(ans & (1LL<<tar[i]))) {
ans ^= b[i];
}
}
cout << ans + (sum ^ ans) << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int c = 0;
int t;
if (!c) {
t = 1;
}
else {
cin >> t;
}
while (t--) {
go();
}
}
| #include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
vector<long long> a(n), base;
for(auto & e : a) cin >> e;
long long all = 0;
for(auto & e : a) all ^= e;
for(auto & e : a) e &= ~all;
for(auto e : a){
for(auto b : base) e = min(e, e ^ b);
if(e){
base.push_back(e);
}
}
sort(base.rbegin(), base.rend());
long long up = 0;
for(auto b : base) up = max(up, up ^ b);
cout << all + 2 * up << endl;
return 0;
} | 1 |
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
int main(){
int N,M;
cin>>N>>M;
VI A(N-1+M),B(N-1+M);
rep(i,N-1+M) cin>>A[i]>>B[i];
VVI X(N,VI(0));
VI I(N);
rep(i,N-1+M){
X[A[i]-1].pb(B[i]-1);
I[B[i]-1]++;
}
int S=0;
rep(i,N) if(I[i]==0) S=i;
VI T(0);
T.pb(S);
queue<int> Q;
Q.push(S);
VI F(N);
F[S]++;
while(!Q.empty()){
int now=Q.front();
Q.pop();
rep(i,X[now].size()){
int nxt=X[now][i];
if(!F[nxt]){
I[nxt]--;
if(!I[nxt]){
Q.push(nxt);
T.pb(nxt);
}
}
}
}
VI Z(N);
rep(i,N){
int now=T[i];
if(!Z[now]) Z[now]=1;
rep(j,X[now].size()){
int nxt=X[now][j];
Z[nxt]=max(Z[nxt],Z[now]+1);
}
}
VI ans(N);
rep(i,N){
rep(j,X[i].size()){
int nxt=X[i][j];
if(Z[i]+1==Z[nxt]) ans[nxt]=i+1;
}
}
ans[S]=0;
rep(i,N) cout<<ans[i]<<endl;
}
| #include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
typedef long double ld;
typedef long long ll;
using namespace std;
int n, m;
#define MAXN (1 << 17)
#define INF (1 << 30)
vector<int> a[MAXN];
vector<int> rev[MAXN];
int p[MAXN];
int v[MAXN];
int f[MAXN];
int curt;
void dfs(int cur) {
v[cur] = 1;
curt++;
for (int i = 0; i < a[cur].size(); i++) {
int nnext = a[cur][i];
if (!v[nnext]) {
dfs(nnext);
}
}
curt++;
f[cur] = curt;
}
int main() {
cin >> n >> m;
for (int i = 0; i < n + m - 1; i++) {
int t1, t2;
cin >> t1 >> t2;
a[t1].push_back(t2);
rev[t2].push_back(t1);
p[t2] = t1;
}
int s = 1;
while (p[s]) {
s = p[s];
}
dfs(s);
/* for (int i = 1; i <= n; i++) {
cerr << f[i] << " ";
}
cerr << endl;
*/ for (int i = 1; i <= n; i++) {
int best = INF;
int bestind = 0;
for (int j = 0; j < rev[i].size(); j++) {
int nnext = rev[i][j];
if (f[nnext] < best) {
best = f[nnext];
bestind = nnext;
}
}
cout << bestind << endl;
}
return 0;
}
| 1 |
/* {{{ Shinobu kawaii */
/*
______ __ _ __
.' ____ \ [ | (_) [ |
| (___ \_| | |--. __ _ .--. .--. | |.--. __ _
_.____`. | .-. | [ | [ `.-. |/ .'`\ \| '/'`\ \[ | | |
| \____) | | | | | | | | | | || \__. || \__/ | | \_/ |,
\______.'[___]|__][___][___||__]'.__.'[__;.__.' '.__.'_/
*/
// clang-format off
/* }}} */
#include <bits/stdc++.h>
using namespace std;
// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
/* cpp template {{{ */
/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()
/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';
/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
// clang-format on
/* }}} */
signed main() {
string s;
cin >> s;
int j, o, i; j = o = i = 0;
int res = 0;
for (char c : s) {
// cerr << j << " " << o << " " << i << endl;
if (c == 'J') {
if (o == 0 && i == 0) {
j++;
} else {
if (j > 0 && o > 0 && i > 0) {
if (j >= o && i >= o) {
chmax(res, o);
}
}
j = o = i = 0;
j++;
}
} else if (c == 'O') {
if (j > 0 && i == 0) {
o++;
} else {
if (j > 0 && o > 0 && i > 0) {
if (j >= o && i >= o) {
chmax(res, o);
}
}
j = o = i = 0;
}
} else if (c == 'I') {
if (j > 0 && o > 0) {
i++;
} else {
if (j > 0 && o > 0 && i > 0) {
if (j >= o && i >= o) {
chmax(res, o);
}
}
j = o = i = 0;
}
}
}
if (j > 0 && o > 0 && i > 0) {
if (j >= o && i >= o) {
chmax(res, o);
}
}
print(res);
return 0;
} | //#define USE_CPP11
// #define USE_PRINTF
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <complex>
#include <memory>
#include <sstream>
#ifdef USE_CPP11
#include <unordered_map>
#include <unordered_set>
#include <functional>
#endif
#define PRINT(obj) cout << obj << endl
#define REP(i, n) for(int (i) = 0; (i) < (n); i++)
#define SPACE " "
typedef long long ll;
const int INF = 1e9 + 10;
using namespace std;
namespace Scanner {
#ifdef USE_PRINTF
int nextInt() { int d; scanf("%d" , &d); return d; }
float nextFloat() { float f; scanf("%f" , &f); return f; }
double nextDouble() { double f; scanf("%lf", &f); return f; }
string nextString() { string s; scanf("%s" , &s); return s; }
ll nextll() { ll l; scanf("%ll", &l); return l; }
#else
int nextInt() { int d; cin >> d; return d; }
float nextFloat() { float f; cin >> f; return f; }
double nextDouble() { double f; cin >> f; return f; }
string nextString() { string s; cin >> s; return s; }
ll nextll() { ll l; cin >> l; return l; }
#endif
string getLine() {
string input;
getline(cin, input);
return input;
}
};
namespace myLibrary {
vector<string> split(const string& str, char delim) {
vector<string> ret;
size_t current = 0, found;
while ((found = str.find_first_of(delim, current)) != string::npos) {
ret.push_back(string(str, current, found - current));
current = found + 1;
}
ret.push_back(string(str, current, str.size() - current));
return ret;
}
#ifdef USE_CPP11
///
/// higher-order functional
/// This is something like map in haskell, python, etc.
/// Sample usage:
/// vector<int> a = {1, 2, 3, 4, 5};
/// vector<int> b = myLibrary::_Map<int, int>(a, [](int n){
/// return n * n;
/// });
/// Result:
/// b = 1, 4, 9, 16, 25
///
template<typename T_IN, typename T_OUT, class Functor>
vector<T_OUT> _Map(vector<T_IN> src, Functor func) {
vector<T_OUT> ret;
for (int i = 0; i < src.size(); i++) {
ret.push_back(func(src[i]));
}
return ret;
}
#endif
};
/// BEGIN //////////////////////////////////////////////////////////
int main() {
while (true) {
int m = Scanner::nextInt();
int nmin = Scanner::nextInt();
int nmax = Scanner::nextInt();
if (m + nmin + nmax == 0) {
break;
}
vector<int> Ps(m);
REP(i, m) {
int p = Scanner::nextInt();
Ps[i] = p;
}
int ans, ans_diff = -1;
for (int i = nmin - 1; i <= nmax - 1; i++) {
int diff = Ps[i] - Ps[i + 1];
if (diff >= ans_diff) {
ans_diff = diff;
ans = i;
}
}
PRINT(ans + 1);
}
return 0;
}
/// END ////////////////////////////////////////////////////////// | 0 |
#include <stdio.h>
int main()
{
int n,a[5000];
while(1){
int max=-100001;
scanf("%d",&n);
if(n==0)
break;
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(int i=0;i<n;i++){
int sum=0;
for(int j=i;j<n;j++){
sum+=a[j];
if(max<sum)
max=sum;
}
}
printf("%d\n",max);
}
return 0;
} | #include <algorithm>
#include <cstdio>
#include <deque>
#include <numeric>
#include <vector>
using namespace std;
template <typename C>
vector<int> compact(const C& container) {
vector<int> compacten;
int sign = 1;
int acc = 0;
for (auto n : container) {
if (n == 0) { continue; }
if (sign * n > 0) {
acc += n;
} else {
compacten.push_back(acc);
acc = n;
sign *= -1;
}
}
compacten.push_back(acc);
return compacten;
}
int main() {
while (true) {
int n;
scanf("%d", &n);
if (n == 0) { break; }
deque<int> seq;
for (int i = 0; i < n; ++i) {
int x;
scanf("%d", &x);
seq.push_back(x);
}
int max_elem;
if ((max_elem = *max_element(seq.begin(), seq.end())) <= 0) {
printf("%d\n", max_elem);
continue;
}
while (seq.size() != 0 && seq.front() <= 0) { seq.pop_front(); }
while (seq.size() != 0 && seq.back() <= 0) { seq.pop_back(); }
auto compacten_seq = compact(seq);
vector<int> partial_sums = { compacten_seq.back() };
for (int i = compacten_seq.size() - 1; i > 0; i -= 2) {
int s = partial_sums.back() + compacten_seq[i - 1];
partial_sums.push_back(compacten_seq[i - 2] + (s < 0 ? 0 : s));
}
printf("%d\n", *max_element(partial_sums.begin(), partial_sums.end()));
}
return 0;
} | 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG
signed main() {
int N, A, B, C, D, E; cin >> N >> A >> B >> C >> D >> E;
int k = min(min(min(min(A,B),C),D),E);
int ans = (N+k-1)/k+4;
cout << ans << endl;
}
| #include <iostream>
#include <vector>
#include <string>
#include <sstream>
std::vector<std::string> split(std::string &str, char delim) {
std::vector<std::string> result;
std::istringstream is(str);
std::string buf;
while (getline(is, buf, delim)) {
result.push_back(buf);
}
return result;
}
bool inputDataSet(std::vector<int> *l, int *v1, int *v2) {
std::string line;
if (!getline(std::cin, line)) { return false; }
std::vector<std::string> tokens = split(line, ',');
if (tokens.size() != 12) { return false; }
for (int i = 0; i < 10; ++i) {
std::istringstream is(tokens[i]);
if (!(is >> (*l)[i])) { return false; }
}
std::istringstream is1(tokens[10]), is2(tokens[11]);
if (!((is1 >> *v1) && (is2 >> *v2))) { return false; }
return true;
}
template <class Iterator>
int sum(Iterator first, Iterator last) {
int sum = 0;
for (; first != last; ++first) { sum += *first; }
return sum;
}
int main() {
std::vector<int> l(10);
int v1, v2;
while (inputDataSet(&l, &v1, &v2)) {
const int x1 = 0, x2 = sum(l.begin(), l.end());
v2 = -v2;
if (v1 == v2) { continue; } // ツ堕環妥篠堕ャツ度 0 ツづ按づァツ古ーツ債キツつオツづ按つ「
const double x = static_cast<double>(x1) + static_cast<double>(-(x1 - x2) * v1) / static_cast<double>(v1 - v2); // ツ渉ャツ青板つェツ静伉偲個づつウツづェツづゥツづ債「ツづゥ
int n = 0, sum = 0;
for (std::vector<int>::iterator it = l.begin(); it != l.end() && static_cast<double>(sum) < x; ++it) {
sum += *it;
++n;
}
std::cout << n << std::endl;
}
return 0;
} | 0 |
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;
int main(void) {
string week[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
string s;
cin >> s;
for (Int i = 0; i < 7; ++i) {
if (week[i] == s) {
cout << 7 - i << endl;
}
}
return 0;
}
| #include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vec(a) vector<int>a
using namespace std;
//fibonacci
int binet(int n)
{
return (pow((1+sqrt(5)),n-1)-pow((1-sqrt(5)),n-1))/(pow(2,n-1)*sqrt(5));
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("output.txt", "w", stdout);
freopen("input.txt", "r", stdin);
#endif
fastio
string str;
cin>>str;
if(str=="SUN")
cout<<7<<"\n";
if(str=="MON")
cout<<6<<"\n";
if(str=="TUE")
cout<<5<<"\n";
if(str=="WED")
cout<<4<<"\n";
if(str=="THU")
cout<<3<<"\n";
if(str=="FRI")
cout<<2<<"\n";
if(str=="SAT")
cout<<1<<"\n";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
ll power(ll a,ll b){
ll ans=1;
while(b>0){
if(b%2!=0){
ans=(ans*a)%mod;
}
a=((a%mod)*(a%mod))%mod;
b>>=1;
}
return ans;
}
void sieve(int n){
bool prime[n+1];
memset(prime,true,sizeof(prime));
for(int p=2;p*p<=n;p++){
if(prime[p]){
for(int i=p*p;i<=n;i+=p)
prime[i]=false;
}
}
for(int p=2;p<=n;p++){
if(prime[p])
cout<<p<<" ";
}
}
int main() {
IOS;
int t=1;
//cin>>t;
while(t--){
int k,x;
cin>>k>>x;
for(int i=(x-k+1);i<=x+k-1;i++){
cout<<i<<" ";
}
}
return 0;
} | #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int A[3];
unsigned int use[100000001];
priority_queue<int,vector<int>,greater<int> > ans;
int main()
{
int n;
cin >>n;
int Min = 1e+9;
for(int i = 0;i < n;i++){
cin >>A[i];
if(Min >A[i]){
Min = A[i];
}
}
if(n ==2){
for(int i = 1;i <=Min;i++){
if(A[0]%i==0&&use[i]!=1&&A[1]%i==0){
use[i] = 1;
ans.push(i);
}
}
}
if(n == 3){
for(int i = 1;i <=Min;i++){
if(A[0]%i==0&&use[i]!=1&&A[1]%i==0&&A[2]%i==0){
use[i] = 1;
ans.push(i);
}
}
}
while(!ans.empty()){
cout <<ans.top()<<endl;
ans.pop();
}
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
long long g=0,n,a,mx=0,k;
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>a;
mx=max(mx,a);
g=__gcd(g,a);
}
if(k>mx){
cout<<"IMPOSSIBLE";
}
else{
if(k%g==0){
cout<<"POSSIBLE";
}
else{
cout<<"IMPOSSIBLE";
}
}
} | #include<iostream>
#include<tuple>
#include<vector>
#include<algorithm>
#include<cmath>
using std::begin;
using std::end;
int gcd(int n, int m) {
if(n < m) return gcd(m, n);
if(m == 0) return n;
return gcd(m, n % m);
}
void print_kouyakusu(int n) {
std::vector<int> v;
for(int i{1}; i <= std::sqrt(n); ++i) {
if(n % i == 0) {
v.push_back(i);
if(i * i != n) {
v.push_back(n / i);
}
}
}
std::sort(begin(v), end(v));
for(int e: v) {
std::cout << e << std::endl;
}
}
int main(int, char**) {
int n;
std::cin >> n;
if(n == 2) {
int a, b;
std::cin >> a >> b;
int d{gcd(a, b)};
print_kouyakusu(d);
} else {
int a, b, c;
std::cin >> a >> b >> c;
int d{gcd(a, b)};
int d2{gcd(c, d)};
print_kouyakusu(d2);
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int64_t MOD;
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;
}
int main(){
int N;
cin >> N >> MOD;
create_mod_tables(10000);
static int64_t dp[6010][4001];
dp[3*N][N] = 1;
for(int i=3*N; i>0; i--) for(int j=0; j<=2*N; j++){
add(dp[i-1][min(2*N, j+1)], dp[i][j]);
if(i>=2 && j > 0) add(dp[i-2][j-1], dp[i][j] * (i-1));
if(i>=3) add(dp[i-3][j], dp[i][j] * (i-1) * (i-2));
}
int64_t ans = 0;
for(int j=N; j<=2*N; j++) add(ans, dp[0][j]);
cout << ans << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int N, mod, i2[10009], i3[10009];//[100][100][100];//[270 * 3][270 * 3][270 * 4];
int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;}
int subtract (int x, int y) {if (x >= y) return x - y; return x - y + mod;}
int mul (int x, int y) {return 1LL * x * y % mod;}
void adto (int &x, int y) {x += y; if (x >= mod) x -= mod;}
int power (int a, int b)
{
int p = 1;
for (int i=0; (1<<i) <= b; i++)
{
if (b & (1 << i)) p = mul (p, a);
a = mul (a, a);
}
return p;
}
int fac[2000009], inv[2000009];
void Prec (int lim){fac[0] = inv[0] = 1;for (int i=1; i<=lim; i++)fac[i] = mul (fac[i - 1], i);
inv[lim] = power (fac[lim], mod - 2);for (int i=lim - 1; i>=0; i--)inv[i] = mul (inv[i + 1], i + 1);}
int comb (int N, int K){if (K > N || N < 0 || K < 0) return 0; int ans = mul (fac[N], inv[N - K]);ans = mul (ans, inv[K]);return ans;}
int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);
scanf ("%d %d", &N, &mod), Prec(4 * N + 100);
/*dp[0][0][N] = 1;
for (int i=0; i<3 * N; i++)
{
int ni = (i + 1) & 1;
memset (dp[ni], 0, sizeof (dp[ni]));
for (int j=0; j<=i; j++)
for (int k=0; k<=4 * N; k++)
if (dp[i & 1][j][k] > 0)
{
///k = N + cnt1 - cnt2
///j = how many numbers smaller than or equal to i i have left
adto (dp[ni][j + 1][k], dp[i & 1][j][k]);///don't group this one
if (j >= 2)
adto (dp[ni][j - 2][k], mul (dp[i & 1][j][k], j * (j - 1)));
if (j >= 1 && k > 0)
adto (dp[ni][j - 1][k - 1], mul (dp[i & 1][j][k], j));
adto (dp[ni][j][k + 1], dp[i & 1][j][k]);
}
}*/
int ans = 0;
//for (int k=N; k<=4 * N; k++)
// adto (ans, dp[(3 * N) & 1][0][k]);
i2[0] = i3[0] = 1;
int invv3 = power (3, mod - 2);
for (int i=1; i<=3 * N; i++)
i2[i] = mul (i2[i - 1], inv[2]),
i3[i] = mul (i3[i - 1], invv3);
for (int cnt1 = 0; cnt1 <= 3 * N; cnt1 ++)
for (int cnt2 = 0; cnt2 <= cnt1 && 2 * cnt2 + cnt1 <= 3 * N; cnt2 ++)
if ((3 * N - cnt1 - 2 * cnt2) % 3 == 0)
{
int cnt3 = (3 * N - cnt1 - 2 * cnt2) / 3;
int curr = mul (mul (fac[3 * N], i2[cnt2]), i3[cnt3]);
curr = mul (curr, inv[cnt1]), curr = mul (curr, inv[cnt2]), curr = mul (curr, inv[cnt3]);
//printf ("%d %d %d -> %d\n", cnt1, cnt2, cnt3, curr);
adto (ans, curr);
}
printf ("%d\n", ans);
return 0;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);
int main()
{
optimize();
int k;
string s;
cin>> k>> s;
if(s.size()> k)
s= s.substr(0, k) +"...";
cout<< s<< '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(){
int k;
string s;
cin>>k>>s;
if(s.length()<=k) cout<<s<<endl;
else{
for(int i=0;i<k;i++) cout<<s[i];
cout<<"."<<"."<<"."<<endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;
namespace output {
void pr(int x) { cout << x; }
void pr(long x) { cout << x; }
void pr(ll x) { cout << x; }
void pr(unsigned x) { cout << x; }
void pr(unsigned long x) { cout << x; }
void pr(unsigned long long x) { cout << x; }
void pr(float x) { cout << x; }
void pr(double x) { cout << x; }
void pr(ld x) { cout << x; }
void pr(char x) { cout << x; }
void pr(const char* x) { cout << x; }
void pr(const string& x) { cout << x; }
void pr(bool x) { pr(x ? "true" : "false"); }
template<class T> void pr(const complex<T>& x) { cout << x; }
template<class T1, class T2> void pr(const pair<T1,T2>& x);
template<class T> void pr(const T& x);
template<class T, class... Ts> void pr(const T& t, const Ts&... ts) {
pr(t); pr(ts...);
}
template<class T1, class T2> void pr(const pair<T1,T2>& x) {
pr("{",x.f,", ",x.s,"}");
}
template<class T> void pr(const T& x) {
pr("{"); // const iterator needed for vector<bool>
bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0;
pr("}");
}
void print() { pr("\n"); } // print w/ spaces
template<class T, class... Ts> void print(const T& t, const Ts&... ts) {
pr(t); if (sizeof...(ts)) pr(" "); print(ts...);
}
}
using namespace output;
int main() {
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int N, M; cin >> N >> M;
vector<vi> dum (N, vi (M));
F0R(i, N) {
F0R(j, M) {
cin >> dum[i][j];
}
}
// misread inputs have to reformat
vector<vi> grid (N, vi (M));
F0R(i, N) F0R(j, M) grid[i][dum[i][j]-1] = j + 1;
vector<bool> used (M);
int worst = N;
F0R(t, M) {
int best = N;
vi count (M);
F0R(i, N) {
int lo_ind = M + 1;
int lo_act = -1;
F0R(j, M) if (!used[j]) {
if (grid[i][j] < lo_ind) {
lo_ind = grid[i][j];
lo_act = j;
}
}
count[lo_act]++;
}
int biggest = 0;
F0R(i, M) if (count[i] > count[biggest]) biggest = i;
worst = min(worst, count[biggest]);
used[biggest] = true;
}
print(worst);
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
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 INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;
void solve() {
int a, b;
cin >> a >> b;
a--;
int cnt = 0;
while(cnt * a + 1 < b) cnt++;
cout << cnt << endl;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
| 0 |
//
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
int f(int n)
{
switch(n){
case 1:
return 1;
break;
case 2:
return 2;
break;
case 3:
return 4;
break;
default:
int a[30];
a[0]=1;
a[1]=2;
a[2]=4;
for(int i=3;i<n;++i){
a[i]=a[i-1]+a[i-2]+a[i-3];
}
return a[n-1];
break;
}
}
int tenjyou(double n)
{
if(n==(int)n){
return (int) n;
}else{
return (int) n+1;
}
}
int main()
{
int n;
int m=0;
vector<int> answer;
while(cin>>n&&n>0){
double day,year;
day=tenjyou(f(n)/10.0);
year=tenjyou(day/365.0);
answer.push_back(year);
m+=1;
}
for(int i=0;i<m;++i){
cout<<answer[i]<<endl;
}
} |
#include<iostream>
#include<vector>
using namespace std;
int foot(int);
int main() {
int n;
vector<int>floor;
cin >> n;
while (n != 0) {
floor.push_back(n);
cin >> n;
}
floor.push_back(0);
int i = 0;
while (floor[i] != 0) {
int res = 0;
res = foot(floor[i]) / 3650;
if( foot(floor[i]) % 3650 != 0) res++;
cout << res << endl;
i++;
}
cin >> n;
return 0;
}
int foot(int n) {
if (n == 1)return 1;
if (n == 2)return 2;
if (n == 3)return 4;
if (n < 1)return 0;
return foot(n - 1) + foot(n - 2) + foot(n - 3);
} | 1 |
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define l first
#define r second
#define int long long
int n;
string s;
int q;
long long pr[1500000];
vector<pair<int, int> > keks;
long long prr[1500000];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> s;
for (int i = 0; i < s.size(); i++)
{
if (i)
pr[i] = pr[i - 1]; pr[i] += s[i] == 'M';
if (s[i] == 'C') keks.push_back({i, pr[i]});
}
for (int i = 0; i < keks.size(); i++)
{
if (i) prr[i] = prr[i - 1];
prr[i] += keks[i].second;
}
cin >> q;
for (int i = 0; i < q; i++)
{
int k = 0;
cin >> k;
long long ans = 0;
int l = -1, l2 = -1;
for (int j = 0; j < s.size(); j++)
{
if (s[j] == 'D')
{
while (l + 1 < keks.size() && keks[l + 1].first < j + k) l++;
while (l2 + 1 < keks.size() && keks[l2 + 1].first < j) l2++;
ans += prr[l] - (l2 >= 0 ? prr[l2] : 0) - (l - l2) * pr[j];
}
}
cout << ans << "\n";
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N,Y;
cin >> N >> Y;
bool fin=false;
for(int i=0;i<(Y/10000)+1;i++){
for(int j=0;j<((Y-10000*i)/5000)+1;j++){
if(((Y-10000*i-5000*j)/1000)+i+j==N){
cout << i << " " << j << " " << (Y-10000*i-5000*j)/1000 <<endl;
fin = true;
break;
}
}
if(fin==true)break;
}
if(fin==false){
cout <<"-1 -1 -1" << endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int n,d1,d2;
int col[603][603],col1[605][605],col2[605][605];
int dx[4803],dy[4803],cnt;
vector<pair<int,int> > typ[2][2];
void Col(int x,int y,int tar)
{
col[x][y] = tar;
for(int i = 1;i <= cnt; ++ i)
{
int nx = x + dx[i],ny = y + dy[i];
if(nx >= 1 && nx <= n && ny >= 1 && ny <= n && !col[nx][ny])
Col(nx,ny,tar ^ 1);
}
}
int main()
{
scanf("%d%d%d",&n,&d1,&d2);
n *= 2;
for(int i = 0;i <= n; ++ i)
for(int j = i;j <= n; ++ j)
if(i * i + j * j == d1)
{
dx[++ cnt] = i; dy[cnt] = j;
dx[++ cnt] = j; dy[cnt] = i;
dx[++ cnt] = -i; dy[cnt] = -j;
dx[++ cnt] = -j; dy[cnt] = -i;
dx[++ cnt] = i; dy[cnt] = -j;
dx[++ cnt] = j; dy[cnt] = -i;
dx[++ cnt] = -i; dy[cnt] = j;
dx[++ cnt] = -j; dy[cnt] = i;
}
for(int i = 1;i <= n; ++ i)
for(int j = 1;j <= n; ++ j)
{
if(!col[i][j])
Col(i,j,2);
col1[i][j] = col[i][j] - 2;
}
cnt = 0;
for(int i = 0;i <= n; ++ i)
for(int j = i;j <= n; ++ j)
if(i * i + j * j == d2)
{
dx[++ cnt] = i; dy[cnt] = j;
dx[++ cnt] = j; dy[cnt] = i;
dx[++ cnt] = -i; dy[cnt] = -j;
dx[++ cnt] = -j; dy[cnt] = -i;
dx[++ cnt] = i; dy[cnt] = -j;
dx[++ cnt] = j; dy[cnt] = -i;
dx[++ cnt] = -i; dy[cnt] = j;
dx[++ cnt] = -j; dy[cnt] = i;
}
memset(col,0,sizeof(col));
for(int i = 1;i <= n; ++ i)
for(int j = 1;j <= n; ++ j)
{
if(!col[i][j])
Col(i,j,2);
col2[i][j] = col[i][j] - 2;
typ[col1[i][j]][col2[i][j]].push_back(make_pair(i,j));
}
for(int i = 0;i < 2; ++ i)
for(int j = 0;j < 2; ++ j)
if(typ[i][j].size() >= n * n / 4)
{
for(int k = 0;k < n * n / 4; ++ k)
printf("%d %d\n",typ[i][j][k].first - 1,typ[i][j][k].second - 1);
return 0;
}
return 0;
} | #include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef pair<Pii,Pii> Ppp;
typedef vector<int> Vi;
inline void read(int &x) {
x=0; char c=getchar(); int f=1;
while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
static ui seed=416;
return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 606;
int n,d1,d2;vector<Pii> res;
void solve(int d1, int d2, vector<Ppp> s){//now,real
vector<Ppp> a,b;
rep(i,0,SZ(s)-1)if(!((s[i].fi.fi+s[i].fi.se)&1)){
a.pb(Ppp(Pii((s[i].fi.fi+s[i].fi.se)/2,(s[i].fi.se-s[i].fi.fi)/2),s[i].se));
}
else{
s[i].fi.fi++;
b.pb(Ppp(Pii((s[i].fi.fi+s[i].fi.se)/2,(s[i].fi.se-s[i].fi.fi)/2),s[i].se));
}
if(SZ(a)<SZ(b))swap(a,b);
if(d1&d2&1)rep(i,0,SZ(a)-1)res.pb(a[i].se);
else{
bool bo=0;if(d2&1)d2=d1,bo=1;if(d1&1)d1=d2,bo=1;
if(bo)solve(d1/2,d2/2,a);
else{solve(d1/2,d2/2,a);solve(d1/2,d2/2,b);}
}
}
int getdis(Pii a, Pii b){return (a.fi-b.fi)*(a.fi-b.fi)+(a.se-b.se)*(a.se-b.se);}
int main() {
read(n);read(d1);read(d2);
vector<Ppp>d;rep(i,0,n*2-1)rep(j,0,n*2-1)d.pb(Ppp(Pii(i,j),Pii(i,j)));
solve(d1,d2,d);
// rep(i,0,SZ(res)-1)rep(j,i,SZ(res)-1)assert(d1!=(getdis(res[i],res[j]))&&d2!=(getdis(res[i],res[j])));
// assert(SZ(res)>=n*n);
rep(i,0,n*n-1)printf("%d %d\n",res[i].fi,res[i].se);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
namespace IO {
#define gc getchar()
template <typename T>
inline void read(T& x) {
x = 0; bool f = 1; char ch;
for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1;
for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48);
x = f ? x : -x;
}
#undef gc
}
const int MAXN = 2e5 + 10;
int n, arr[2][MAXN], l[2][MAXN], r[2][MAXN], ansl, ansr, cnt[MAXN], ans[MAXN];
int main() {
IO::read(n);
ansr = INT_MAX;
rep(_, 0, 1) rep(i, 1, n) IO::read(arr[_][i]);
rep(_, 0, 1) rep(i, 1, n) {
if (arr[_][i] != arr[_][i - 1]) l[_][arr[_][i]] = i;
if (arr[_][i] != arr[_][i + 1]) r[_][arr[_][i]] = i;
}
rep(i, 1, n) {
if (l[0][i] && l[1][i]) {
ansl = max(ansl, r[0][i] - l[1][i] + 1);
// ansr = min(ansr, abs(l[0][i] - r[1][i]));
ansr = min(ansr, l[0][i] - r[1][i] + n - 1);
}
}
// printf("l = %d, r = %d\n", ansl, ansr);
if (ansl > ansr) return puts("No"), 0;
puts("Yes");
rep(i, 1, n) {
ans[(i + ansl - 1) % n + 1] = arr[1][i];
}
rep(i, 1, n) printf("%d ", ans[i]);
return 0;
} | #include<bits/stdc++.h>
using namespace std;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
int h, w; cin >> h >> w;
char s[h+2][w+2];
for(int i = 0; i < w+2; i++) s[0][i] = '.';
for (int i = 1; i <= h; i++)
{
s[i][0] = '.';
for (int j = 1; j <= w; j++)
{
cin >> s[i][j];
}
s[i][h+1] = '.';
}
for(int i = 0; i < w+2; i++) s[h+1][i] = '.';
bool res = true;
for (int i = 1; i <= h; i++)
{
for (int j = 1; j <= w; j++)
{
if(s[i][j] == '.') continue;
bool tmp = false;
for (int k = 0; k < 4; k++)
{
if(s[i+dx[k]][j+dy[k]] == '#')
tmp = true;
}
if(!tmp) res = false;
}
}
if(res) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
| 0 |
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000 //1e4
#define base10_5 100000 //1e5
#define base10_6 1000000 //1e6
#define base10_7 10000000 //1e7
#define base10_8 100000000 //1e8
#define base10_9 1000000000 //1e9
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>
//#include <stack>
//#include <queue>
// #include <iomanip>
// cout << fixed << setprecision(15) << y << endl;
string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";
ll A;
ll B;
ll C;
ll N;
ll M;
ll K;
ll ltmp;
string stmp;
double dtmp;
vector<ll> inv,fact,invfact;
void setupCombination(ll n_max,ll mod){
fact.resize(n_max+1);
inv.resize(n_max+1);
invfact.resize(n_max+1);
fact[0]=inv[0]=invfact[0]=1;
inv[1]=1;
for(ll i=0;i<n_max;i++){
fact[i+1]=fact[i]*(i+1)%mod;
if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
invfact[i+1]=invfact[i]*inv[i+1]%mod;
}
}
ll getCombination(ll n,ll k,ll mod){
if(n<0||k<0||k>n)return 0;
return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}
/*
max 448,000,000
count_map['0']=0;
for(auto x : count_map) {
string key = x.first;
ll value = x.second;
}
*/
ll getMod(ll value,ll mod){
if(value == 0) return 0;
if(mod==0) return -1;
value %= mod;
if(value<0) value += mod;
return value;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N;
cin >> M;
cin >> K;
ll allnum = N*M;
setupCombination(allnum+10,MOD);
ll base = getCombination(allnum-2,K-2,MOD);
base = getMod(base,MOD);
ll ans = 0;
for( ll yoko = 0 ; yoko <N ; yoko++ ){
for( ll tate = 0 ; tate <M ; tate++ ){
ll count = (N-yoko) * (M-tate);
if(tate*yoko>0) count *=2;
ll distance = yoko + tate;
//cout << distance << " : " << count << endl;
ll dA = count * distance;
dA = getMod(dA,MOD);
ans += dA;
ans = getMod(ans,MOD);
}
}
ans = ans * base;
ans = getMod(ans,MOD);
cout << ans << endl;
} | #include <iostream>
int main(){
int n, x, t; std::cin >> n >> x >> t;
std::cout << (n + x - 1) / x * t << '\n';
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif
void init() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
}
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;
}
| #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
int main(){
int N,M;
cin>>N>>M;
VI A(N-1+M),B(N-1+M);
rep(i,N-1+M) cin>>A[i]>>B[i];
VVI X(N,VI(0));
VI I(N);
rep(i,N-1+M){
X[A[i]-1].pb(B[i]-1);
I[B[i]-1]++;
}
int S=0;
rep(i,N) if(I[i]==0) S=i;
VI T(0);
T.pb(S);
queue<int> Q;
Q.push(S);
VI F(N);
F[S]++;
while(!Q.empty()){
int now=Q.front();
Q.pop();
rep(i,X[now].size()){
int nxt=X[now][i];
if(!F[nxt]){
I[nxt]--;
if(!I[nxt]){
Q.push(nxt);
T.pb(nxt);
}
}
}
}
VI Z(N);
rep(i,N){
int now=T[i];
if(!Z[now]) Z[now]=1;
rep(j,X[now].size()){
int nxt=X[now][j];
Z[nxt]=max(Z[nxt],Z[now]+1);
}
}
VI ans(N);
rep(i,N){
rep(j,X[i].size()){
int nxt=X[i][j];
if(Z[i]+1==Z[nxt]) ans[nxt]=i+1;
}
}
ans[S]=0;
rep(i,N) cout<<ans[i]<<endl;
}
| 1 |
#include <stdio.h>
int main(){
int num, angka1, angka2, angka3;
scanf("%d", &num);
angka1 = num/100;
angka2 = (num - angka1 * 100)/10;
angka3 = num % (angka1 * 100 + angka2 * 10);
if(angka1 == 7 || angka2 == 7 || angka3 == 7){
puts("Yes");
} else{
puts("No");
}
return 0;
} | #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define Rep(i,s,f) for(int i=(int)s;i<(int)f;i++)
using ll=long long;
using namespace std;
int f(ll a,ll b)
{
return (int)max(log10(a),log10(b));
}
int main()
{
ll N;
cin>>N;
int ans=10;
for(int i=1;i<sqrt(N)+1;i++)
{
if(N%i!=0) continue;
ll k=N/i;
int v=f(i,k);
ans=min(ans,v);
}
cout<<ans+1<<endl;
return 0;
}
| 0 |
#include <stdio.h>
#include <string.h>
int main(void)
{
int i, j;
int n;
int len;
char str[1024];
scanf("%d\n", &n);
for (j = 0; j < n; j++){
fgets(str, 1024, stdin);
len = strlen(str);
for (i = 0; i < len; i++){
if (strncmp(&str[i], "Hoshino", 7) == 0){
strncpy(&str[i], "Hoshina", 7);
}
}
printf("%s", str);
}
return (0);
} | #include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
string str;
cin >> n;
cin.ignore();
while (n > 0){
getline(cin, str);
int len = 0;
while (1){
len = str.find("Hoshino", len);
if (len == -1) break;
str[len + 6] = 'a';
}
cout << str << endl;
n--;
}
return (0);
} | 1 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
using namespace std;
using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
void solve() {
int n;
cin >> n;
int rmin = 2e9, lmax = 0;
vector<pair<int, int>> lr;
rep(i, n) {
int l, r;
cin >> l >> r;
r++;
lr.emplace_back(l, r);
amin(rmin, r);
amax(lmax, l);
}
int ans = 0;
{
int sum = 0;
sum += max(rmin - lmax, 0);
int ma = 0;
rep(i, n) {
int l, r;
tie(l, r) = lr[i];
amax(ma, r - l);
}
sum += ma;
ans = sum;
}
{
sort(all(lr));
reverse(all(lr));
int rr = lr[0].second;
reps(i, n - 1) {
int l, r;
tie(l, r) = lr[i];
amax(ans, max(rmin - l, 0) + max(rr - lmax, 0));
amin(rr, r);
}
}
cout << ans << endl;
}
| #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>
#include<bitset>
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> PI;
typedef pair<int, int> P;
typedef vector<double> vec;
typedef vector<vec> mat;
const int N = 100005;
//////////////////////////////
int n, T;
P a[3300];
int dp[3300][3300];
void solve()
{
cin >> n >> T;
REP(i, n) {
cin >> a[i].first >> a[i].second;
}
sort(a, a + n);
for (int i = 0; i < n; i++) {
for (int t = 0; t < T; t++) {
dp[i + 1][t] = max(dp[i + 1][t], dp[i][t]);
if (t - a[i].first >= 0) dp[i + 1][t] = max(dp[i + 1][t], dp[i][t - a[i].first] + a[i].second);
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
ans = max(ans, dp[i][T - 1] + a[i].second);
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(13);
solve();
return 0;
}
| 0 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int n,m,a[300][300],ans=999;
bool ok[301];
int main(){
cin>>n>>m;
rep(i,n)rep(j,m)cin>>a[i][j];
rep(k,m){
int x[301]={};
rep(i,n){
int j=0;
while(ok[a[i][j]])j++;
x[a[i][j]]++;
}
int X=1;
for(int i=1;i<=m;i++){
if(x[X]<x[i])X=i;
}
ans=min(x[X],ans);
ok[X]=1;
}
cout<<ans<<endl;
} | #include<bits/stdc++.h>
using namespace std;
#define RI register int
const int N=105;
char mp[N][N];
int f[2][N][N][N],a[N][N],n,m,sx,sy,ans;
int gets(int x1,int y1,int x2,int y2)
{return a[x2][y2]-a[x1-1][y2]-a[x2][y1-1]+a[x1-1][y1-1];}
int main()
{
scanf("%d%d",&n,&m);
for(RI i=1;i<=n;++i) {
scanf("%s",mp[i]+1);
for(RI j=1;j<=m;++j) {
a[i][j]=a[i-1][j]+a[i][j-1]-a[i-1][j-1]+(mp[i][j]=='o');
if(mp[i][j]=='E') sx=i,sy=j;
}
}
for(RI x1=0,t=0;x1<sx;++x1,t^=1)
for(RI y1=0;y1<sy;++y1)
for(RI x2=0;x2<=n-sx;++x2)
for(RI y2=0;y2<=m-sy;++y2) {
if(x1&&sx-x1>x2)
f[t][y1][x2][y2]=max(f[t][y1][x2][y2],f[t^1][y1][x2][y2]+
gets(sx-x1,max(sy-y1,y2+1),sx-x1,min(sy+y2,m-y1)));
if(y1&&sy-y1>y2)
f[t][y1][x2][y2]=max(f[t][y1][x2][y2],f[t][y1-1][x2][y2]+
gets(max(sx-x1,x2+1),sy-y1,min(sx+x2,n-x1),sy-y1));
if(x2<n&&sx+x2<=n-x1)
f[t][y1][x2][y2]=max(f[t][y1][x2][y2],f[t][y1][x2-1][y2]+
gets(sx+x2,max(sy-y1,y2+1),sx+x2,min(sy+y2,m-y1)));
if(y2<m&&sy+y2<=m-y1)
f[t][y1][x2][y2]=max(f[t][y1][x2][y2],f[t][y1][x2][y2-1]+
gets(max(sx-x1,x2+1),sy+y2,min(sx+x2,n-x1),sy+y2));
ans=max(ans,f[t][y1][x2][y2]);
}
printf("%d\n",ans);
return 0;
} | 0 |
#include <bits/stdc++.h>
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define numa(x,a) for(auto x: a)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define pf push_front
#define sec second
#define sz(x) ((int)(x).size())
#define ALL( c ) (c).begin(), (c).end()
#define gcd(a,b) __gcd(a,b)
#define endl "\n"
using namespace std;
template <int POS, class TUPLE> void deploy(std::ostream &os, const TUPLE &tuple){}
template <int POS, class TUPLE, class H, class ...Ts> void deploy(std::ostream &os, const TUPLE &t){ os << (POS == 0 ? "" : ", ") << get<POS>(t); deploy<POS + 1, TUPLE, Ts...>(os, t); }
template <class T> std::ostream& operator<<(std::ostream &os, std::vector<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::set<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T, class K> std::ostream& operator<<(std::ostream &os, std::map<T, K> &mp){ int remain = mp.size(); os << "{"; for(auto e: mp) os << "(" << e.first << " -> " << e.second << ")" << (--remain == 0 ? "}" : ", "); return os; }
#define DEBUG1(var0) { std::cerr << (#var0) << "=" << (var0) << endl; }
#define DEBUG2(var0, var1) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG1(var1); }
#define DEBUG3(var0, var1, var2) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG2(var1,var2); }
#define DEBUG4(var0, var1, var2, var3) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG3(var1,var2,var3); }
#define DEBUG5(var0, var1, var2, var3, var4) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG4(var1,var2,var3,var4); }
#define DEBUG6(var0, var1, var2, var3, var4, var5) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG5(var1,var2,var3,var4,var5);}
typedef long long ll;
#define MAX_V 100100
int V;
vector <pair <int,ll> > edge[MAX_V];
vector <pair <int,ll> > Redge[MAX_V];
vector <int> vs;
bool used[MAX_V];
int cmp[MAX_V];
void reverse_edge(){
rep2(i,1,V+1){//1-indexedにしてます
rep(j,sz(edge[i])){
Redge[edge[i][j].fir].pb(mp(i,edge[i][j].sec));
}
}
}
void dfs(int now){
used[now] = true;
rep(i,sz(edge[now])){
if(!used[edge[now][i].fir]){
dfs(edge[now][i].fir);
}
}
vs.pb(now);
}
void rdfs(int now,int k){
used[now] = true;
cmp[now] = k;
rep(i,sz(Redge[now])){
if(!used[Redge[now][i].fir]){
rdfs(Redge[now][i].fir,k);
}
}
}
int scc(){
memset(used,0,sizeof(used));
vs.clear();
rep2(v,1,V+1){//1-indexed
if(!used[v]){
dfs(v);
}
}
memset(used,0,sizeof(used));
reverse_edge();
int k = 0;
for(int i = sz(vs)-1;i >= 0;i--){
if(!used[vs[i]]){
k += 1;
rdfs(vs[i],k);
}
}
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> V;
int E;
cin >> E;
rep(i,E){
int x,y;
cin >> x >> y;
x += 1;
y += 1;
edge[x].pb(mp(y,1));
}
scc();
int Q;
cin >> Q;
rep(i,Q){
int x,y;
cin >> x >> y;
x += 1;
y += 1;
if(cmp[x] == cmp[y]){
cout << 1 << endl;
}else{
cout << 0 << endl;
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define N 100005
int n, m;
vector<int> to[N];
int dfn[N], low[N], bel[N], tim, cnt;
stack<int> stk;
bitset< N > vis;
void tarjan(int u)
{
dfn[u] = low[u] = ++tim; stk.push(u); vis.set(u);
for (auto v : to[u])
{
if (!dfn[v])
{
tarjan(v);
low[u] = min(low[u], low[v]);
}
else if (vis[v])
low[u] = min(low[u], dfn[v]);
}
if (low[u] == dfn[u])
{
int t; ++cnt;
do
{
t = stk.top(); stk.pop();
bel[t] = cnt; vis.reset(t);
}
while (t != u);
}
}
signed main(void)
{
cin >> n >> m;
for (int u, v; m--; )
{
cin >> u >> v;
to[u].push_back(v);
}
for (int i = 0; i < n; ++i)
if (!dfn[i])tarjan(i);
int q; cin >> q;
while (q--)
{
int x, y;
cin >> x >> y;
cout << (bel[x] == bel[y]) << endl;
}
} | 1 |