code_file1
stringlengths 87
4k
| code_file2
stringlengths 85
4k
|
---|---|
/**
* author: Dooloper
* created: 11.10.2020 23:54:26
**/
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repn(i,n) for(int i = 1; i <= (n); i++)
#define pb push_back
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cout << H << " ";
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
const double PI = acos(-1);
const int mod = 1000000007;
class mint {
long long x;
public:
mint(long long x=0) : x((x%mod+mod)%mod) {}
mint operator-() const {
return mint(-x);
}
mint& operator+=(const mint& a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint& a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint& a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint& a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint& a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint& a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
return a;
}
// for prime mod
mint inv() const {
return pow(mod-2);
}
mint& operator/=(const mint& a) {
return (*this) *= a.inv();
}
mint operator/(const mint& a) const {
mint res(*this);
return res/=a;
}
friend ostream& operator<<(ostream& os, const mint& m){
os << m.x;
return os;
}
};
#pragma endregion
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int t;
cin >> t;
while(t--){
int n;
cin >> n;
vector<int> a(n);
rep(i,n) cin >> a[i];
if(n%2){
cout << "Second\n" << endl;
}else{
sort(a.begin(),a.end());
bool win = false;
for(int i = 0; i < n; i += 2) win |= a[i] != a[i+1];
cout << (win ? "First": "Second") << "\n";
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "/debug.h"
#else
#define db(...)
#endif
#define all(v) v.begin(), v.end()
#define pb push_back
using ll = long long;
const int NAX = 2e5 + 5, MOD = 1000000007;
const string FIRST = "First";
const string SECOND = "Second";
auto solveCase(int n, const vector<int64_t> &a)
{
// TODO: edit here
if (n % 2)
return SECOND;
map<int, int> cnt;
for (auto &x : a)
cnt[x]++;
for (auto &x : cnt)
{
if(x.second % 2)
return FIRST;
}
return SECOND;
}
// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main()
{
#ifndef LOCAL
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
#endif
constexpr char endl = '\n';
// failed to analyze input format
// TODO: edit here
int t, n;
cin >> t;
for (size_t i = 0; i < t; i++)
{
cin >> n;
vector<int64_t> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
auto ans = solveCase(n, a);
cout << ans << '\n';
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define ff first
#define ss second
#define pi pair<int, int>
const int MX=300000;
const ll mod=1e9+7;
int dp[100];
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n; cin>>n;
set<int>st;
set<int>::iterator it;
for(int i=1; i<=min(n-2, 1666); i++) st.insert(6*i);
for(int i=1; ; i++)
{
if(st.size()==n-1 || 10*i>10000) break;
st.insert(10*i);
}
for(int i=1; ; i++)
{
if(st.size()==n) break;
st.insert(15*i);
}
for(it=st.begin(); it!=st.end(); it++) cout<<*(it)<<' ';
cout<<endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ull base = 131;
const ull mod1 = 1e9 + 9;
const ull mod2 = 1610612741;
const int maxn = 5e5 + 10;
int x;
int main()
{
cin >> x;
cout << 100-x%100;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define mp make_pair
#define infi INT_MAX
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define f(i,a,b) for(ll i=a;i<b;i++)
#define ff first
#define ss second
#define pll pair<ll,ll>
#define endl "\n"
#define ALL(v) v.begin(),v.end()
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define deb printf("*****************************\n");
#define idk printf("idk idk ! \n");
#define hi printf("hi ! \n");
#define bye printf("bye bye ! \n");
#define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define number_of_set_bits __builtin_popcountll
#define ld long double
//template<typename T>
//#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
int main()
{
fast
//#ifndef ONLINE_JUDGE
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//#endif // ONLINE_JUDGE
ll ntc=1;
// cin>>ntc;
f(ks,1,ntc+1)
{
//cout<<"Case #"<<i<<": ";
ll n; cin>>n;
map<string,int> a,b;
a.clear(), b.clear();
bool ans = false; string print = "";
f(i,0,n){
string s; cin>>s;
if(s[0] == '!'){
string p = s.substr(1);
if(a.count(p)) {
ans = true;
print = p;
break;
}
b[p]++;
} else {
if(b.count(s)){
ans = true;
print = s;
break;
}
a[s]++;
}
}
if(ans) cout<<print<<endl;
else cout<<"satisfiable"<<endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long int in[200007];
long long int ou[200007];
char s[27];
int main()
{
long long int i, n, j, pin=0, pou=0, x, y;
cin >> n;
for(i=0; i<n; i++){
cin >> s;
x=1;
y=0;
for(j=0; j<strlen(s); j++){
if(s[j]!='!'){
y+=(s[j]-'a'+1)*x;
x*=30;
}
}
if(s[0]=='!'){
ou[pou]=y;
pou++;
}
else{
in[pin]=y;
pin++;
}
}
sort(in, in+pin);
sort(ou, ou+pou);
for(x=0, y=0; (x<pin)&&(y<pou);){
if(in[x]==ou[y]){
break;
}
if(x==pin-1){
y++;
continue;
}
if(y==pou-1){
x++;
continue;
}
if(in[x]<ou[y]){
x++;
}
else{
y++;
}
}
if(in[x]==ou[y]){
while(in[x]){
cout << (char)(in[x]%30-1+'a');
in[x]/=30;
}
cout << '\n';
}
else{
cout << "satisfiable\n";
}
return 0;
}
|
#pragma region Macros
// #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
using namespace std;
using P = pair<int, int>;
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 int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
int n, m, q;
cin >> n >> m >> q;
vector<int> W(n), V(n), X(m);
rep(i, n) cin >> W[i] >> V[i];
rep(i, m) cin >> X[i];
rep(i, q){
int a, b;
cin >> a >> b;
a--;
vector<int> X2;
rep(j, m){
if (j < a || b <= j){
X2.push_back(X[j]);
}
}
sort(ALL(X2));
int k = X2.size();
int ans = 0;
vector<bool> used(n, false);
rep(j, k){
priority_queue<P> pq;
rep(s, n){
if(X2[j] >= W[s] & !used[s]){
pq.push({V[s], s});
}
}
if (!pq.empty()){
ans += pq.top().first;
used[pq.top().second] = true;
pq.pop();
}
}
cout << ans << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define ff first
#define ss second
#define mod 1000000007
#define inf 1e18
#define ninf (-1e18)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define debug(x) cout << #x << " = " << x << endl;
void solve() {
int n, m, q;
cin >> n >> m >> q;
vector<pair<int, int>> bag(n);
vector<int> box(m);
for (int i = 0 ; i < n ; i++) {
cin >> bag[i].ff >> bag[i].ss;
}
for (int i = 0; i < m; i++) {
cin >> box[i];
}
while (q--) {
int l, r;
cin >> l >> r;
l--, r--;
int ans = 0;
vector<int> newBox;
for (int i = 0; i < l; i++)
newBox.push_back(box[i]);
for (int i = r + 1; i < m; i++)
newBox.push_back(box[i]);
sort(newBox.begin(), newBox.end());
vector<bool> vis(n, false);
for (int cap : newBox) {
int mx = 0;
int ind = -1;
for (int i = 0; i < n; i++) {
if (vis[i])
continue;
if (bag[i].ff <= cap) {
if (bag[i].ss > mx) {
mx = bag[i].ss;
ind = i;
}
}
}
if (ind != -1) {
vis[ind] = 1;
ans += mx;
}
}
cout << ans << endl;
}
return;
}
int32_t main() {
IOS;
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
int v[109];
for(int i=0;i<4;i++){
cin>>v[i];
}
sort(v,v+4);
cout<<v[0]<<endl;
return 0;
}
| #include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> order_set;
typedef long long ll ;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define what_is(x) cout << #x << " is " << x << endl;
// #define endl '\n'
#define fi first
#define sec second
#define pb push_back
#define vi vector<int>
#define vii vector<pair<int,int>>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
void solve(){
int a1,a2,a3,a4;
cin>>a1>>a2>>a3>>a4;
cout<<min(min(min(a1,a2),a3),a4)<<endl;
return;
}
int main(){
fio;
int test;
// cin>>test;
test=1;
while(test--){
solve();
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll s2[100];
ll n;
ll qpow(ll a,ll b)
{
ll res=1;
while(b)
{
if(b&1)
{
res=res*a;
}
a=a*a;
b/=2;
}
return res;
}
ll f(ll i)
{
ll res;
if(i==0)
res=1;
else if(s2[i-1]==1)
res=f(i-1);
else
res=qpow(2,i)+f(i-1);
return res;
}
int main()
{
//int n;
cin>>n;
string s;
for(int i=0;i<n;i++)
{
cin>>s;
if(s=="AND")
s2[i]=1;
else
s2[i]=0;
}
ll ans=f(n);
cout<<ans<<endl;
}
| #include <bits/stdc++.h>
using namespace std;
void testcase(){
int n;
cin>>n;
vector<int> v1(n), v2(n);
for(int i = 0; i<n; i++){
cin>>v1[i]>>v2[i];
}
int l1 = INT_MAX, l2 = INT_MAX;
int p1, p2;
for(int i = 0; i<n; i++){
if(v1[i] < l1){
l1 = v1[i];
p1 = i;
}
if(v2[i] < l2){
l2 = v2[i];
p2 = i;
}
}
if(p1!=p2){
cout<<max(l1, l2);
}
else{
int L1 = INT_MAX, L2 = INT_MAX;
for(int i = 0; i<n; i++){
if(i != p1){
if(v1[i]< L1){
L1 = v1[i];
}
}
if(i != p2){
if(v2[i] < L2){
L2 = v2[i];
}
}
}
cout<<min({l1+l2, max(l1, L2), max(l2, L1)});
}
}
int main(){
ios_base::sync_with_stdio();
cin.tie(NULL);
testcase();
} |
//libraries
#include<bits/stdc++.h>
//namespace
using namespace std;
//typedef
//typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<long long> vll;
//define
#define i(x) cin>>x;
#define il(X) ll X; cin>>X;
#define ol(X) cout<<X<<endl;
#define os(X) cout<<X<<" ";
#define inpv(a,n) vector<ll> a(n); for(ll i=0;i<n;i++){cin>>a[i];}
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define line cout<<"\n";
#define pbp(a,b) push_back(make_pair(a,b));
#define iniv(A,n,p) vector<ll> A(n,p);
#define vst(A) sort(A.begin(),A.end());
#define rvst(A) sort(A.rbegin(),A.rend());
#define forin(i,a,b) for(ll i=a;i<=b;i++)
#define forde(i,a,b) for(ll i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const long long inf=(long long)1e18;
long long MOD=(long long)(1e9+7);
ll mod=MOD;
long long binpow(long long a, long long b, long long m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
ll modi(ll a)
{
return binpow(a,mod-2,mod);
}
// ll n,m;
// vector<unordered_set<ll> > adj(100001);
// vector<unordered_set<ll> > adj_rev(100001);
// iniv(vis,100001,0);
// stack<ll> s;
// void dfs(ll x)
// {
// if(vis[x]) return;
// for(auto p:adj[x])
// {
// if(!vis[p]) dfs(p);
// }
// s.push(x);
// }
int main()
{
#ifndef ONLINE_JUDGE
freopen ("input.txt" , "r" , stdin);
// freopen ("OUTPUT.txt" , "w" , stdout);
#endif
fio;
ll tt=1; //cin>>tt;
while(tt--)
{
il(n);
inpv(a,n);
vector<vll> adj(200001);
iniv(vis,200001,0);
ll ans=0;
forin(i,0,n-1)
{
if(!vis[a[i]])
{
vis[a[i]]=1;
ans++;
}
}
ll l=0,r=n-1;
while(l<r)
{
adj[a[l]].pb(a[r]);
adj[a[r]].pb(a[l]);
l++;
r--;
}
forin(i,1,200000)
{
if(vis[i])
{
ans--;
stack<ll> s;
s.push(i);
while(!s.empty())
{
ll x=s.top();
s.pop();
if(!vis[x]) continue;
vis[x]=0;
for(auto p:adj[x])
{
if(vis[p])
{
s.push(p);
}
}
}
}
}
ol(ans);
}
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define se second
#define fi first
typedef map<int, int> mi;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
signed main() {
#ifndef ONLINE_JUDGE
freopen("inputf.txt", "r", stdin);
freopen("outputf.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int h, w, x, y;
cin >> h >> w >> x >> y;
string s[h];
for(int i=0; i<h; i++) {
cin >> s[i];
}
x--;
y--;
int count=1;
for(int i=x; i<h and s[i][y]!='#'; i++) {
count++;
}
for(int i=x; i>=0 and s[i][y]!='#'; i--) {
count++;
}
for(int i=y; i<w and s[x][i]!='#'; i++) {
count++;
}
for(int i=y; i>=0 and s[x][i]!='#'; i--) {
count ++;
}
cout << count-4;
return 0;
} |
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
inline int read(){
int res=0;
bool zf=0;
char c;
while(((c=getchar())<'0'||c>'9')&&c!='-');
if(c=='-')zf=1;
else res=c-'0';
while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
if(zf)return -res;
return res;
}
const int maxn=2e5+5,P=998244353;
int f[maxn],g[maxn];
int p[maxn],r;
int v[maxn],inv[25];
signed main(){
int n=read(),m=read(),ans=1;
inv[1]=1;
for(register int i=2;i<=20;++i){
inv[i]=1ll*inv[P%i]*(P-P/i)%P;
}
for(register int i=2,t;i<=m;++i){
if(!v[i]){
f[i]=n,g[i]=1,p[++r]=i;
}
for(register int j=1;j<=r&&(t=i*p[j])<=m;++j){
v[t]=1;
if(i%p[j]){
f[t]=1ll*f[i]*n%P,g[t]=1;
}
else{
f[t]=1ll*f[i]*(n+g[i])%P*inv[g[i]+1]%P,g[t]=g[i]+1;
break;
}
}
ans+=f[i];
(ans>=P)&&(ans-=P);
}
printf("%d\n",ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
ll factorial[400005];
ll inverse[400005];
map<ll, ll> choosepre;
ll modpow(ll a, ll b) {
if(b == 0) return 1 % MOD;
ll half = modpow(a, b/2);
ll res = half * half;
res %= MOD;
if(b % 2 == 1) {
res *= a;
res %= MOD;
}
return res;
}
ll choose(ll n, ll k) {
// n! / k!(n-k)!
// n * (n - 1) * (n - 2) * ... * (n - k + 1)
ll ans = 1;
for(int i = 0; i < k; i++) {
ans *= (n - i);
ans %= MOD;
}
ans *= inverse[k]; // inverse
ans %= MOD;
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
factorial[0] = 1;
inverse[0] = 1;
for(int i = 1; i < 400005; i++) {
factorial[i] = factorial[i - 1] * i;
factorial[i] %= MOD;
inverse[i] = modpow(factorial[i], MOD - 2);
}
int N, M; cin >> N >> M;
ll ans = 1;
// huge overhead for choosing so precompute!!!!!!!
for(int i = 0; i < 18; i++) {
choosepre[i + N - 1] = choose(i + N - 1, N - 1);
}
for(int i = 2; i <= M; i++) {
int num = i;
ll expo_count = 0;
ll curr_count = 1;
double up = log(i) / log(2);
ll l = 0, r = ceil(up), mid;
while(l <= r) {
mid = (l + r) / 2;
ll power = modpow(2, mid);
if(num % power == 0) {
expo_count = max(expo_count, mid);
l = mid + 1;
}
else {
r = mid - 1;
}
}
num /= modpow(2, expo_count);
curr_count *= choosepre[expo_count + N - 1];
curr_count %= MOD;
for(int j = 3; j * j <= i; j += 2) {
if(num % j == 0) {
expo_count = 0;
up = log(i) / log(j);
l = 0, r = ceil(up);
while(l <= r) {
mid = (l + r) / 2;
ll power = modpow(j, mid);
if(num % power == 0) {
expo_count = max(expo_count, mid);
l = mid + 1;
}
else {
r = mid - 1;
}
}
curr_count *= choosepre[expo_count + N - 1];
curr_count %= MOD;
num /= modpow(j, expo_count);
}
//cout << i << ' ' << expo_count << '\n';
}
if(num > 2) { // still prime factor
expo_count = 1;
curr_count *= choosepre[expo_count + N - 1];
curr_count %= MOD;
}
ans += curr_count;
ans %= MOD;
}
cout << ans << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
vector<int> leader;
int find(int x) {
if (leader[x] == x) return x;
return leader[x] = find(leader[x]);
}
int main() {
int N, Q; cin >> N >> Q;
vector<int> C(N); for (auto &c : C) cin >> c, c--;
leader.resize(N);
iota(begin(leader), end(leader), 0);
vector<map<int, int>> A(N);
for (int i = 0; i < A.size(); i++) {
A[i][C[i]] = 1;
}
for (int i = 0; i < Q; i++) {
int type; cin >> type;
if (type == 1) {
int a, b; cin >> a >> b; a--, b--;
a = find(a), b = find(b);
if (a != b) {
if (A[a].size() < A[b].size()) swap(a, b);
for (auto [c, n] : A[b]) {
A[a][c] += n;
}
A[b].clear();
leader[b] = a;
}
} else {
int x, y; cin >> x >> y; x--, y--;
cout << A[find(x)][y] << '\n';
}
}
return 0;
} | // Coder: @SumitRaut
#include <bits/stdc++.h>
#define speedup ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr),cout.precision(12)
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;
#define sbc __builtin_popcount
#define pb push_back
#define em emplace
#define emb emplace_back
#define ff first
#define ss second
#define ll long long
const ll mod = 1e9+7;
template<typename T> void smax(T& a, T b) { if(a<b) a=b; }
template<typename T> void smin(T& a, T b) { if(a>b) a=b; }
template<typename T> T pw(T a,T b) { T p=1,one=1; while(b) { if(b&one) p=p*a; a=a*a; b >>=1; } return p; }
template<typename T> T pwm(T a,T b,T md=mod) { T p=1,one=1; while(b) { if(b&one) p=p*a%md; a=a*a%md; b >>=1; } return p; }
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
for(auto& it:v)
is>>it;
return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
for (auto &it : v)
os << it << ' ';
return os;
}
#ifndef ONLINE_JUDGE
class Timer { chrono::high_resolution_clock::time_point start_t, end_t; public: Timer() { start_t=chrono::high_resolution_clock::now(); } ~Timer() { end_t = chrono::high_resolution_clock::now(); auto duration = chrono::duration_cast<chrono::milliseconds>(end_t-start_t); cerr<<"\nRunTime: "<<duration.count()<<"ms"<<'\n'; } };
void debug() { cerr << '\n'; }
template <typename T, typename... Args>
void debug(T print, Args... args) { cerr << ' ' << print; debug(args...); }
#define deb(...) cerr << "[" << #__VA_ARGS__ << "]" << " --> ", debug(__VA_ARGS__)
#else
#define deb(...) void(0)
#endif
class dsu {
public:
vector<int> par;
vector<map<int,int>>Mp;
dsu() {}
dsu(int n_,vector<int>& ar) : par(n_, -1) {
Mp.resize(n_);
for(int i=0;i<n_;++i) {
Mp[i][ar[i]]=1;
}
}
int find(int cur) {
return par[cur] < 0 ? cur : (par[cur] = find(par[cur]));
}
bool Union(int a, int b) {
a = find(a), b = find(b);
if (a != b) {
if (par[a] > par[b])
swap(a, b);
par[a] += par[b];
for(auto& it:Mp[b]) {
Mp[a][it.ff]+=it.ss;
}
Mp[b].clear();
par[b] = a;
return 1;
}
return 0;
}
bool isConnected(int a, int b) {
return find(a) == find(b);
}
int size(int a) {
return -par[find(a)];
}
int cnt(int a,int k) {
return Mp[find(a)][k];
}
};
void solve() {
int n,q;
cin>>n>>q;
vector<int> que(n);
cin>>que;
dsu Ds(n,que);
while(q--) {
int op,x,y;
cin>>op>>x>>y;
if(op==1) {
Ds.Union(x-1,y-1);
} else {
cout<<Ds.cnt(x-1,y)<<'\n';
}
}
}
int main() {
#ifndef ONLINE_JUDGE
Timer timer;
#endif
speedup;
//int t; cin>>t; while(t--)
solve();
}
|
#include<bits/stdc++.h>
using namespace std;
#define light ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pb push_back
#define cases() ll t;cin>>t;while(t--)
#define all(c) c.begin(),c.end()
#define PI 3.14159265358979323846
const ll MAX = 2e6+5;
const ll INF = 1e18;
const ll MOD = 1e9+7;
vector<int> a[MAX];
int main()
{
int i,j,k,l,p,q,x,y,n,m;
cin >> n >> m;
for(i=0;i<=n;i++)
a[i].push_back(0);
for(i=1;i<=n;i++)
{
cin >> l;
a[l].push_back(i);
}
for(i=0;i<=n;i++)
a[i].push_back(n+1);
for(i=0;i<=n;i++)
{
for(j=0;j+1<a[i].size();j++)
{
if(a[i][j+1]-a[i][j]>m)
{
cout << i;
return 0;
}
}
}
} | #include<bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define Bye return 0
#define CodeTyper main
#define ll int long long
using namespace std;
int const max_size = 1.5e6+1;
int freq[max_size];
void solve() {
int n, m; cin>>n>>m;
set<int> s;
for (int i = 0; i<=max_size; i++)
s.insert(i);
memset(freq, 0, sizeof freq);
int a[n];
for (int i = 0; i<n; i++)
cin>>a[i];
for (int i = 0; i<m; i++){
s.erase(a[i]);
freq[a[i]]++;
}
int mex = min(*s.begin(), max_size);
for (int i = m; i<n; i++){
int l = i - m;
freq[a[l]]--;
freq[a[i]]++;
s.erase(a[i]);
if(freq[a[l]] <= 0)
s.insert(a[l]);
mex = min(mex, *(s.begin()));
}
cout<<mex<<endl;
}
int CodeTyper()
{
boost;
solve();
Bye;
}
/*
'Think FIRST, then CODE.'
'May the CODE be with YOU.'
'We are PROGRAMMERS, we have NO LIFE!'
*/
|
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath> // abs() for float, and fabs()
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int main()
{
// 入力
int N, Q;
cin >> N >> Q;
vector<ll> A(N), K(Q), C(N);
rep(i, N)
cin >> A[i];
rep(i, Q)
cin >> K[i];
rep(i, N)
C[i] = A[i] - (i+1);
rep(i, Q){
ll vec_index = lower_bound(C.begin(), C.end(), K[i]) - C.begin();
// cout << K[i] << ':' << vec_index << endl;
if(vec_index == N){
cout << A[N-1] + (K[i] - C[N-1]) << endl;
}else{
cout << (A[vec_index] - 1) - (C[vec_index] - K[i]) << endl;
}
}
} | #include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int x,y;
map<int,int>mp,vis;
int func(int v){
if(x>=v) return x-v;
if(vis[v]) return mp[v];
vis[v]=1;
int ans=v-x;
// if(v==1) {mp[v]=ans;return ans;}
if(v%2==1){
ans=min({ans,1+func(v+1),1+func(v-1)});
}
else{
ans=min(ans,1+func(v/2));
}
mp[v]=ans;
return ans;
}
void solve(){
cin>>x>>y;
cout<<func(y);
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int T=1;
// cin>>T;
while(T--){
solve();
}
}
|
#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;
template <typename T> using oset =
tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;
#define odrkey order_of_key
#define fbodr find_by_order
#define ll long long
#define sq(a) ((a)*(a))
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pi 3.1415926536
#define nwl cout << "\n"
#define sz 300000
ll Pow(ll a, ll b) {
if(a==0) return 0LL;
ll ans = 1;
for (int i = 0; i < b; i++) {
ans *= a;
}
return ans;
}
ll lcm(ll a, ll b) {
return (a * b) / __gcd(a, b);
}
ll two_knights(ll n) { // n>3
ll ans = n * n * (n * n - 1);
ans -= 8;
ans -= 24;
ans -= (n - 4) * 4 * 4;
ans -= 16;
ans -= (n - 4) * 6 * 4;
ans -= (n - 4) * (n - 4) * 8;
return ans / 2;
}
ll sm(ll n){
return (n*(n+1))/2;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
ll n;
cin >> n;
ll p=1;
for(int i=2;i<sqrt(n)+1;(i>2 ? i+=2: i++)){
ll cnt=0;
while(n%i==0){
cnt++;
n/=i;
}
if(i%2==1)p*=(cnt+1);
}
if(n>1 && n%2) p*=2;
cout << p*2 << endl;
}
| #include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> P;
int INF = 100000000;
int main()
{
ll i, n, active = 0, ans = 0, n2, a, k;
cin >> n;
n2 = n * 2;
auto solve = [&](ll k)
{
ll tmp;
tmp =n2 / k - k + 1;
if (abs(tmp) % 2 == 0)
ans++;
};
for (ll i = 1; i * i <= n2; i++)
{
if (n2 % i !=0 )
continue;
ll j = n2 / i;
solve(i);
solve(j);
}
cout << ans << endl;
return 0;
} |
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<>()で降順
#include <map>
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define ALL(x) (x).begin(),(x).end()
using namespace std;
using ll = long long int;
int main(){
string s;cin>>s;
vector<int> a(4);
int ans = 0;
rep(i,10000){
int b = i;
a[3] = b / 1000;
b %= 1000;
a[2] = b / 100;
b %= 100;
a[1] = b / 10;
b %= 10;
a[0] = b;
bool flag = false;
rep(i,4) if(s[a[i]]=='x') flag = true;
if(flag) continue;
vector<int> c(10);
rep(i,4) c[a[i]]++;
rep(i,10) if(s[i]=='o'&&c[i]==0) flag = true;
if(flag) continue;
ans++;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
//*************************MACROS*************************
#define endl "\n"
#define MOD = 1000000007
#define rep(i, k, n) for (i = k; i < n; ++i)
#define repr(i, k, n) for (i = n; i >= k; i--)
#define debug(x, y) cout << x << " : " << y << endl;
#define debugarr(arr, i, n) \
for (i = 0; i < n; i++) \
cout << arr[i] << " "; \
cout << endl;
//*************************MACROS*************************
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
vector<int> arr(n);
int i;
rep(i,0,n)
cin>>arr[i];
sort(arr.begin(),arr.end());
rep(i,0,n)
if(arr[i]!=i+1){
cout<<"No"<<endl;
return 0;
}
cout<<"Yes"<<endl;
return 0;
} |
#include <bits/stdc++.h>
void computeLPSArray(char* pat, int M, int* lps);
// Prints occurrences of txt[] in pat[]
int KMPSearch(char* pat, char* txt)
{
int M = strlen(pat);
int N = strlen(txt);
// create lps[] that will hold the longest prefix suffix
// values for pattern
int lps[M];
// Preprocess the pattern (calculate lps[] array)
computeLPSArray(pat, M, lps);
int gg=0;
int i = 0; // index for txt[]
int j = 0; // index for pat[]
while (i < N) {
if (pat[j] == txt[i]) {
j++;
i++;
}
if (j == M) {
gg++;
j = lps[j - 1];
}
// mismatch after j matches
else if (i < N && pat[j] != txt[i]) {
// Do not match lps[0..lps[j-1]] characters,
// they will match anyway
if (j != 0)
j = lps[j - 1];
else
i = i + 1;
}
}
return gg;
}
// Fills lps[] for given patttern pat[0..M-1]
void computeLPSArray(char* pat, int M, int* lps)
{
// length of the previous longest prefix suffix
int len = 0;
lps[0] = 0; // lps[0] is always 0
// the loop calculates lps[i] for i = 1 to M-1
int i = 1;
while (i < M) {
if (pat[i] == pat[len]) {
len++;
lps[i] = len;
i++;
}
else // (pat[i] != pat[len])
{
// This is tricky. Consider the example.
// AAACAAAA and i = 7. The idea is similar
// to search step.
if (len != 0) {
len = lps[len - 1];
// Also, note that we do not increment
// i here
}
else // if (len == 0)
{
lps[i] = 0;
i++;
}
}
}
}
// Driver program to test above function
int main()
{
char txt[12];
for(int i=0;i<12;i++){
scanf("%s",&txt[i]);
}
char pat[] = "ZONe";
int ggg=KMPSearch(pat, txt);
printf("%d",ggg);
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
cin >> S ;
int cnt = 0;
for (int i = 0; i < S.size()-3; i++)
{
if(S.substr(i,4) =="ZONe"){
cnt += 1;
}
}
cout << cnt << endl;
} |
#include <bits/stdc++.h>
using namespace std;
inline long long read(){
long long s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9'){
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9'){
s = s * 10 + ch - '0';
ch = getchar();
}
return s * w;
}
int main(){
int a = read(), b = read(), c = read();
bool f = c;
while(1){
if(!f){
if (a == 0){
puts("Aoki");
return 0;
}
a--;
}
else{
if (b == 0){
puts("Takahashi");
return 0;
}
b--;
}
f ^= 1;
}
return 0;
} | #include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
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;}
char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main(){
int n, k, m; cin >> n >> k >> m;
int c = n * m, sum = 0;
REP(i, 0, n-1){
int a; cin >> a;
sum += a;
}
if(c - sum > k){
cout << -1 << endl;
return 0;
}
cout << max(c-sum, 0) << endl;
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
cout<<n-1<<endl;
return 0;
} | #pragma region Macros
#include <bits/stdc++.h>
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define ALL(v) (v).begin(), (v).end()
#define LLA(v) (v).rbegin(), (v).rend()
#define SZ(v) (int)(v).size()
#define INT(...) \
int __VA_ARGS__; \
read(__VA_ARGS__)
#define LL(...) \
ll __VA_ARGS__; \
read(__VA_ARGS__)
#define DOUBLE(...) \
double __VA_ARGS__; \
read(__VA_ARGS__)
#define CHAR(...) \
char __VA_ARGS__; \
read(__VA_ARGS__)
#define STRING(...) \
string __VA_ARGS__; \
read(__VA_ARGS__)
#define VEC(type, name, size) \
vector<type> name(size); \
read(name)
#define VEC2(type, name, height, width) \
vector<vector<type>> name(height, vector<type>(width)); \
read(name)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
int from, to;
T cost;
edge(int f, int t, T c) : from(f), to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;
const char newl = '\n';
template <class T> inline vector<T> make_vec(size_t a, T val) {
return vector<T>(a, val);
}
template <class... Ts> inline auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
void read() {}
template <class T> inline void read(T &a) { cin >> a; }
template <class T, class S> inline void read(pair<T, S> &p) {
read(p.first), read(p.second);
}
template <class T> inline void read(vector<T> &v) {
for(auto &&a : v)
read(a);
}
template <class Head, class... Tail>
inline void read(Head &head, Tail &...tail) {
read(head), read(tail...);
}
template <class T> void write(const T &a) { cout << a << '\n'; }
template <class T> void write(const vector<T> &a) {
for(int i = 0; i < a.size(); i++)
cout << a[i] << (i + 1 == a.size() ? '\n' : ' ');
}
template <class Head, class... Tail>
void write(const Head &head, const Tail &...tail) {
cout << head << ' ';
write(tail...);
}
template <class T> void writel(const T &a) { cout << a << '\n'; }
template <class T> void writel(const vector<T> &a) {
for(int i = 0; i < a.size(); i++)
cout << a[i] << '\n';
}
template <class Head, class... Tail>
void writel(const Head &head, const Tail &...tail) {
cout << head << '\n';
write(tail...);
}
template <class T> auto sum(const vector<T> &a) {
return accumulate(ALL(a), T(0));
}
template <class T> auto min(const vector<T> &a) { return *min_element(ALL(a)); }
template <class T> auto max(const vector<T> &a) { return *max_element(ALL(a)); }
template <class T> inline void chmax(T &a, T b) { (a < b ? a = b : a); }
template <class T> inline void chmin(T &a, T b) { (a > b ? a = b : a); }
struct IO {
IO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(10);
}
} io;
#pragma endregion
int main() {
INT(n);
write(n == 1 ? 0 : n - 1);
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
class BIT{
public:
int size;
vector<long long> tree;
BIT(int n){
size = n;
tree = vector<long long>(n, 0);
return;
}
void add(int n, long long a) {
assert(n < size);
int x = n;
while (x < size){
tree[x] += a;
x |= x+1;
}
return;
}
long long getsum(int n) {
assert(n < size);
int x = n+1;
long long sum = 0;
while (x > 0) {
sum += tree[x-1];
x &= x-1;
}
return sum;
}
};
int main() {
int N;
cin >> N;
vector<ll> A(N), B(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
A[i] += i;
}
for (int i = 0; i < N; i++) {
cin >> B[i];
B[i] += i;
}
{
vector<ll> C = A, D = B;
sort(C.begin(), C.end());
sort(D.begin(), D.end());
if (C != D) {
cout << -1 << endl;
return 0;
}
}
map<ll, ll> mp;
set<ll> st;
map<ll, ll> cnt;
for (int i = 0; i < N; i++) {
st.insert(A[i]);
cnt[A[i]]++;
}
ll t = 0;
for (ll n : st) {
mp[n] = t;
t += cnt[n];
}
map<ll, ll> cnt2;
for (int i = 0; i < N; i++) {
ll pre = A[i];
A[i] = mp[A[i]]+cnt2[A[i]];
cnt2[pre]++;
}
cnt2.clear();
for (int i = 0; i < N; i++) {
ll pre = B[i];
B[i] = mp[B[i]]+cnt2[B[i]];
cnt2[pre]++;
}
{
vector<ll> tmp(N);
for (int i = 0; i < N; i++) {
tmp[B[i]] = i;
}
for (int i = 0; i < N; i++) {
A[i] = tmp[A[i]];
}
}
ll ans = 0;
BIT bit(N);
for (ll i = 0; i < N; i++) {
ans += i - bit.getsum(A[i]);
bit.add(A[i], 1);
}
cout << ans << endl;
return 0;
} | // code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;
#define REP(i,N) for(int i = 0;i < N;i++)
#define rng(i,a,b) for(int i = a;i < b;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a,b) cout<<"["<<#a<<","<<#b<<"] = "<<"["<<a<<","<<b<<"]\n"
#define debug3(a,b,c) cout<<"["<<#a<<","<<#b<<","<<#c<<"] = "<<"["<<a<<","<<b<<","<<c<<"]\n"
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
cout << "{"; for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i]; cout << "}";
return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
cout << "{\n"; for (auto& vec : arr)cout << " " << vec << ",\n"; cout << "}";
return out;
}
template<class S,class T> ostream &operator << (ostream& out, const pair<S,T>& p){
cout << "{" << p.first << "," << p.second << "}" << '\n';
return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
for (auto& i : arr)cin >> i; return in;
}
template<class S,class T> istream &operator >> (istream& in,pair<S,T>& p){
cin >> p.first >> p.second; return in;
}
template<class T> void debug_a(T *a , int N){
cout << "debug array : {";
for(int i = 0;i < N;i++){
cout << *(a + i) << (i < N-1 ? ", " : "}\n");
}
}
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
template<class T> bool chmin(T& a,T b){ if(a > b){ a = b;return true;}else{return false;} }
template<class T> bool chmax(T& a,T b){ if(a < b){ a = b;return true;}else{return false;} }
template<class T> T __ceil(T a,T b){return (a + b - 1) / b;}
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
//cout << fixed << setprecision(20);
string s;cin >> s;
string t = "ZONe";
int ans = 0;
REP(i,9){
ans += s.substr(i,4) == t;
}
cout << ans << endl;
}
|
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
int a,b,w;
cin>>a>>b>>w;
w*=1000;
int x=w/a,y=w/b;
//if (w%a==0 && w%b!=0) cout<<w/a<<" "<<w/a<<endl;
//else if (w%b==0 && w%a!=0) cout<<w/b<<" "<<w/b<<endl;
if (x==y && w%a!=0 && w%b!=0) cout<<"UNSATISFIABLE"<<endl;
else cout<<setprecision(8)<<ceil(double(double(w)/double(b)))<<" "<<floor(double(double(w)/double(a)))<<endl;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <chrono>
#define int long long
#define ld long double
#define db double
#define endl "\n"
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
using namespace __gnu_pbds;
using namespace std;
using namespace chrono;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void deb_out() {
cout << endl;
}
template <typename Head, typename... Tail>
void deb_out(Head H, Tail... T) {
cout << " " << H;
deb_out(T...);
}
#ifdef LOCAL
#define deb(...) cout << "[" << #__VA_ARGS__ << "]:", deb_out(__VA_ARGS__);
#else
#define deb(...) ;
#endif
const long double PI = 3.14159265358979323846264338;
const long long INF = 1000000000000000000;
const long long INF1 = 1000000000;
const long long MOD = 1000000007;
// const long long MOD = 998244353;
inline int cl(int a, int b){
if(a % b)
return 1 + a / b;
return a / b;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int Tests = 1;
// cin >> Tests;
while (Tests--) {
int a, b, w;
cin >> a >> b >> w;
w *= 1000;
// int g = __gcd(a, b);
// deb(g, a, b, w % g)
// if (w < a || w % g) {
// cout << "UNSATISFIABLE" << endl;
// continue;
// }
// int mn = cl(w, b);
// int mx = w / a;
// cout << mx << " " << mn << endl;
int mx = 0, mn = INF;
for (int i = 0 ; a * i <= w ; i++) {
int dn = i * a;
int df = w - dn;
int ex = b - a;
if (df <= i * ex) {
mx = max(mx, i);
// deb(i, df)
// mn = min(mn, i);
}
}
for (int i = 0 ; b * i <= w + 5 * b ; i++) {
// deb(i)
int dn = i * b;
int df = -w + dn;
// deb(df)
int ex = b - a;
if (df <= ex * i && df >= 0) {
mn = min(mn, i);
// mn = min(mn, i);
}
}
if (mx == 0) {
cout << "UNSATISFIABLE" << endl;
continue;
} else {
cout << mn << " " << mx << endl;
}
}
}
|
/*
solution here
*/
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define nl '\n'
#define sp ' '
using ll = long long;
ll inf = 2e18;
const int N = 2e5+10;
ll arr[N];
void solve()
{
int n,w;
cin>>n>>w;
rep(i,n){
int a,b,c; cin>>a>>b>>c;
++a; ++b;
arr[a]+=c; arr[b]-=c;
}
rep1(i,N-10)
{
arr[i]+=arr[i-1];
if(arr[i]>w)
{
cout<<"No";
return;
}
}
cout<<"Yes";
}
int main()
{
ios::sync_with_stdio(!cin.tie(0));
// cout<<fixed;
// cout.precision(12);
solve();
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define float long double
#define pie 3.1415926536
#define pb push_back
#define N 1000000007
#define M 998244353
#define ff first
#define ss second
#define INT_MAX LLONG_MAX
#define pi pair<int,int>
#define pii pair< int, pair<int,int> >
#define all(v) (v).begin(),(v).end()
int parent[200005];
map<int,map<int,int> >m;
void make_set(int v) {
parent[v] = v;
}
int find_set(int v) {
if (v == parent[v])
return v;
return parent[v] = find_set(parent[v]);
}
void union_sets(int a, int b) {
a = find_set(a);
b = find_set(b);
if (a != b) {
if(m[a].size() < m[b].size()){
swap(a,b);
}
parent[b] = a;
map<int,int > :: iterator it;
for(it = m[b].begin(); it!= m[b].end() ;it++){
m[a][it->ff] += it->ss;
}
m[b].clear();
}
}
void solve(){
int n,q;
cin>>n>>q;
int a[n+5];
for(int i=1; i<=n ;i++){
cin>>a[i];
}
for(int i=1; i<=n ;i++){
make_set(i);
m[i][a[i]] = 1;
}
while(q--){
int x,y,z;
cin>>x>>y>>z;
if(x&1){
union_sets(y,z);
}else{
int par = find_set(y);
int val = m[par][z];
cout<<val<<endl;
}
}
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;
// cin>>t;
t = 1;
for(int T=1; T<=t ;T++){
solve();
}
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr long long INF = 1e9+10;
constexpr long long LINF = 1e18+10;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }
double func(int sel, int a, int b, int c){
return (double)(sel)/(a+b+c);
}
double dp[110][110][110];
int memo[110][110][110];
int main(){
int a,b,c; cin >> a >> b >> c;
double res = 0;
dp[a][b][c] = 1;
for(int r=a+b+c; r<=300; r++){
for(int x=a; x<=100; x++){
for(int y=b; y<=100; y++){
for(int z=c; z<=100; z++){
if(x+y+z > r)continue;
if(x==100 or y==100 or z==100){
if(memo[x][y][z])continue;
//cout << "x:" << x << "y:" << y << "z:" << z <<"dp:"<< dp[x][y][z]<< ln;
int cnt = (x+y+z) - (a+b+c);
res += dp[x][y][z] * cnt;
memo[x][y][z] = true;
}else{
if(memo[x][y][z])continue;
//cout << "non:" << " x:" << x << "y:" << y << "z:" << z << ln;
dp[x+1][y][z] += dp[x][y][z] * func(x,x,y,z);
dp[x][y+1][z] += dp[x][y][z] * func(y,x,y,z);
dp[x][y][z+1] += dp[x][y][z] * func(z,x,y,z);
memo[x][y][z] = true;
}
}
}
}
}
cout << fixed << setprecision(12);
cout << res << ln;
}
| #include "bits/stdc++.h"
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define vi vector <int>
#define ff first
#define ss second
#define vp vector <pair<int,int>>
#define vpp vector <pair<int,pair<int,int>>>
#define seti set<int>
#define setbit(x) __builtin_popcountll(x)
#define sov(v) accumulate(all(v),0)
#define fs(it,a) for(auto it=a.begin();it!=a.end();it++)
#define pb push_back
#define pob pop_back
#define mp make_pair
#define pqmax priority_queue <int,vector <int>>
#define pqmin priority_queue <int,vector <int>,greater<int>>
#define dq deque <int>
#define umi unordered_map<int,int>
#define ums unordered_map<string,int>
#define sp(x,y) fixed << setprecision(y) << x
#define out(r,x) cout<<"Case #"<<r<<": "<<x<<ee;
#define all(x) x.begin(),x.end()
#define f(x,y,z) for(x=y;x<z;x++)
#define si size()
#define countdigit(x) floor(log10(x) +1)
#define M 1000000007
#define Z 998244353
#define fill(arr,x) memset(arr,x,sizeof(arr))
//Use (k%M+m)%m always where k is any no
#define PI 3.1415926535
#define lcm(a,b) a*b/(__gcd(a,b))
// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> pdbs;
// // null for set,mapped_type for map;
// //less for assending greater for descending
//ceil(a/b)=(a+b-1)/b
// v.si-1 can never be negative
#define ghadi() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();
#define ee "\n"
#define re return
//Author Rahul Sannigrahi
vector<int> take(int n)
{
int i,j;
vi v;
f(i,0,n)
{
cin>>j;
v.pb(j);
}
return v;
}
int power(int x,int y)
{
int res=1;
while(y>0)
{
if(y&1)
res=((res%M)*(x%M))%M;
y=y>>1;
x=((x%M)*(x%M))%M;
}
re res;
}
bool sortinrev(const pair<int,int> &a, //desc of vp
const pair<int,int> &b)
{
return (a.first > b.first);
}
void show(vector<int>v)
{
int i;
for(i=0;i<v.si;i++)
{
cout<<v[i]<<" ";
}
cout<<ee;
}
int decode()
{
int i,j,k,l,n,a,b,c;
cin>>a>>b>>c;
// double d=(float)b/a;
// cout<<d<<ee;
int ans=b*c/a;
if(ans*a==b*c)
ans--;
cout<<ans<<ee;
re 0;
}
int32_t main()
{
IOS
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
int t=1;
// cin>>t;
while(t--)
decode();
return 0;
} |
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <ostream>
#include <queue>
#include <set>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define all(A) A.begin(), A.end()
typedef long long ll;
int main() {
int n;
cin >> n;
cout << (n + 99) / 100 << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
t=1;
while(t--)
{
int n;
cin>>n;
int ans=n/100;
if(n%100==0)
cout<<ans;
else
cout<<ans+1;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve()
{
ll m, n;
cin >> n >> m;
for(ll i = 1; i * i <= m; i++)
{
if(m % i == 0)
{
if(i + (m / i) == n)
{
cout << "Yes\n";
return;
}
}
}
cout << "No\n";
}
int main()
{
int t = 1;
// cin >> t;
while(t--)
{
solve();
}
return 0;
}
| #include <iostream>
using namespace std;
int main() {
int A, B;
cin >> A >> B;
cout << (double)(A - B)/(double)A * 100.0 << endl;
}
|
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define endl "\n"
#define f first
#define s second
#define ar array
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define sz(X) ((int)(X).size())
#define pcnt __builtin_popcount
#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 all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()
#define ms(c, x) memset(c,x,sizeof c)
#define No(x) cout<<(x?"NO":"No")<<endl;
#define Yes(x) cout<<(x?"YES":"Yes")<<endl;
#define nl cout<<endl;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = l; i <=r; i++)
#define ford(i, n) for (int i = n - 1; i >= 0; --i)
using ld = long double;
using db = double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
template<typename T>
using osl = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using osg = tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
// for greater use greater<T>
template<typename T>
ostream &operator+(ostream &out, const vector<T> &vec) {
for (const auto &x : vec) {
out << x << " ";
}
out << "\n";
return out;
}
template<typename T>
ostream &operator*(ostream &out, const vector<T> &vec) {
for (const auto &x : vec) {
out + x;
}
return out;
}
template<typename T>
istream &operator>>(istream &in, vector<T> &vec) {
for (auto &x : vec) {
in >> x;
}
return in;
}
template<class T>
bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<class T>
bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
#ifdef LOCAL
void debug() { cerr << endl; }
template<class T, class... Args>
void debug(const T &t, const Args &... args) {
cerr << t << " ";
debug(args...);
}
#define dbg(...) {cerr<<__LINE__<<" [[DEBUG]] ";debug(__VA_ARGS__);};
#else
#define dbg(...) void(0)
#endif
const ll mod = 1e9 + 7;
//const int mod = 998244353;
const ll INF = 1e17 + 6;
inline ll power(ll x, ll y) {
ll res = 1;
x = x;
while (y > 0) {
if (y & 1)
res = (res * x);
y = y >> 1;
x = (x * x);
}
return res;
}
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
const int MXN=3e6+5;
void solve() {
int n,m;
cin>>n>>m;
vl h(n);
cin>>h;
vl w(m);
cin>>w;
vi pref((n+1)/2+2);
vi suff((n+1)/2+2);
sort(all(h));
for(int i=0;i<n-1;i+=2) {
pref[i / 2+1] += pref[i / 2] + h[i + 1] - h[i];
}
for(int i=n-2;i>0;i-=2) {
suff[i / 2] += suff[i / 2+1] + h[i+1] - h[i];
}
ll ans=INF;
for(auto i:w){
int pos=get_pos(h,i);
if(pos&1){
pos--;
}
ans=min(pref[pos/2]+suff[pos/2]+abs(i-h[pos]),ans);
}
cout<<ans<<endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1, tc = 1;
// cin >> t;
while (t--) {
// cout<<"Case #"<<tc<<": " ;
solve();
tc++;
}
#ifdef LOCAL
cerr << endl << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
#endif
return 0;
}
//look if it requires ll | #include <bits/stdc++.h>
using namespace std;
int main(){
int N,M;
cin >> N >> M;
vector<long long> H(N),W(M);
for(auto &i:H)cin >> i;
for(auto &i:W)cin >> i;
sort(H.begin(),H.end());
sort(W.begin(),W.end());
if(N==1){
long long ans=99999999999999LL;
for(auto w:W){
ans=min(ans,abs(w-H[0]));
}
cout << ans << endl;
return 0;
}
vector<long long> Lsum(N),Rsum(N);
Lsum[0]=Lsum[1]=H[1]-H[0];
Rsum[N-1]=Rsum[N-2]=H[N-1]-H[N-2];
for(int i=2;i+1<N;i+=2)Lsum[i]=Lsum[i+1]=Lsum[i-1]+H[i+1]-H[i];
for(int i=N-3;i-1>=0;i-=2)Rsum[i]=Rsum[i-1]=Rsum[i+1]+H[i]-H[i-1];
int pos=0;
long long ans=999999999999999999LL;
for(int i=0;i<M;i++){
while(pos<N && W[i]>H[pos])pos++;
long long tmp=0;
if(pos-2>=0)tmp+=Lsum[pos-2];
if(pos+1<=N-1)tmp+=Rsum[pos+1];
if(pos%2)tmp+=W[i]-H[pos-1];
else tmp+=H[pos]-W[i];
ans=min(ans,tmp);
}
cout << ans << endl;
return 0;
} |
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif
void d_err() {
cerr << endl;
}
template <typename H, typename... T>
void d_err(H h, T... t) {
cerr << h << " ";
d_err(t...);
}
template <typename T>
void print(T x) {
cout << x << "\n";
}
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;
ll INF = 1e16;
int inf = 1e9;
//const ll MOD = 1000000007;
const ll MOD = 998244353;
struct mint {
ll x; // typedef long long ll;
mint(ll x=0):x((x%MOD+MOD)%MOD){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= MOD) x -= MOD;
return *this;
}
mint& operator-=(const mint a) {
if ((x += MOD-a.x) >= MOD) x -= MOD;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime MOD
mint inv() const {
return pow(MOD-2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
return mint(*this) /= a;
}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
int n, k;
cin >> n >> k;
vll a(n);
REP(i, n) cin >> a[i];
mint div = 1;
vector<mint> s(k + 1);
s[0] = n;
vector<vector<mint>> p(k + 1, vector<mint>(n, 1));
FOR(i, 1, k + 1) {
div *= i;
REP(j, n) {
p[i][j] = p[i-1][j] * a[j];
s[i] += p[i][j];
}
s[i] /= div;
}
mint f = 2;
FOR(x, 1, k+1) {
mint ans = 0;
mint fact = 1;
REP(i, x + 1) {
ans += s[i] * s[x - i];
if (i > 0) fact *= i;
}
ans *= fact;
REP(i, n) {
ans -= p[x][i] * f;
}
f *= 2;
ans /= 2;
print(ans);
}
}
| //#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a) (a).begin(),(a).end()
#define ALLR(a) (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
template<typename T>void rearrange(vector<ll>&ord, vector<T>&v){
auto tmp = v;
for(int i=0;i<tmp.size();i++)v[i] = tmp[ord[i]];
}
template<typename Head, typename... Tail>void rearrange(vector<ll>&ord,Head&& head, Tail&&... tail){
rearrange(ord, head);
rearrange(ord, tail...);
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int popcount(ll x){return __builtin_popcountll(x);};
int poplow(ll x){return __builtin_ctzll(x);};
int pophigh(ll x){return 63 - __builtin_clzll(x);};
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
ll res=0,buf=0;
bool judge = true;
ll n,m,k;cin>>n>>m>>k;
vector<ll>a(k);
rep(i,0,k)cin>>a[i];
vector<ld>x(n+m+1),y(n+m+1);
ld sx=0,sy=0;
rrep(i,0,n){
if(binary_search(ALL(a),i)){
x[i]=1;
y[i]=0;
}
else{
x[i]=sx/m;
y[i]=sy/m+1;
}
sx+=x[i]-x[i+m];
sy+=y[i]-y[i+m];
}
if(abs(x[0]-1)<=1e-10){
cout<<-1<<endl;
}
else{
lfs<<y[0]/(1-x[0])<<endl;
}
return 0;
} |
#include <bits/stdc++.h>
#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; while(t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
void dbg_out() { cerr << " end.\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
const int N = 1e2+5;
void solve(){
int h, w;
cin >> h >> w;
vector<int> fre(105);
int mn = 1e9;
for(int i = 0; i <h ; ++i)
for(int j= 0, x; j < w; ++j)
cin >> x, fre[x]++, mn = min(mn, x);
LL res = 0;
for(int i = mn; i <= 100; ++i){
res += fre[i]* (i-mn);
}
cout << res;
}
int main()
{
Fast;
//louisfghbvc
solve();
return 0;
}
| #include <iostream>
#include <string>
#include <vector>
int main()
{
int H, W;
std::cin >> H >> W;
std::vector<std::vector<int>> A(H, std::vector<int> (W));
for(int i=0; i < H; i++) {
for(int j=0; j < W; j++) {
std::cin >> A[i][j];
}
}
int min_value = 1000000000;
for(int i=0; i < H; i++) {
for(int j=0; j < W; j++) {
min_value = min_value > A[i][j] ? A[i][j] : min_value;
}
}
int ans = 0;
for(int i=0; i < H; i++) {
for(int j=0; j < W; j++) {
ans += (A[i][j] - min_value);
}
}
std::cout << ans << std::endl;
} |
// // #include<iostream>
// // #include<algorithm>
// // using namespace std;
// // int a[1005],b[1005];
// // int main(){
// // int n;
// // cin>>n;
// // int min3=1e8;
// // for(int i=1;i<=n;i++){
// // cin>>a[i]>>b[i];
// // min3=min(min3,a[i]+b[i]);
// // }
// // sort(a+1,a+n+1);
// // sort(b+1,b+1+n);
// // if(a[1]+b[1]==min3){
// // min3=min({min3,max(b[1],a[2]),max(b[2],a[1]});
// // cout<<min3;
// // }
// // else{
// // cout<<max(a[1],b[1]);
// // }
// // getchar();
// // getchar();
// // return 0;
// // }
// #include<iostream>
// #define int long long
// using namespace std;
// int a[300000+5];
// signed main(){
// int sum=0;
// int ans=0;
// int n;
// cin>>n;
// for(int i=1;i<=n;i++){
// cin>>a[i];
// ans+=(n-1)*a[i]*a[i];
// sum+=a[i];
// }
// for(int i=1;i<=n;i++){
// ans-=a[i]*(sum-a[i]);
// }
// cout<<ans;
// getchar();
// getchar();
// return 0;
// }
#include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std;
double dp[200000+5];
double dfs(int x,int n){
if(x==n)
return 0.0;
if(dp[x]!=0.0)
return dp[x];
double ans=0.0;
ans+=dfs(x+1,n)+1.0*n/(n-x);
return dp[x]=ans;
}
int main(){
int n;
cin>>n;
dp[n]=0.0;
cout<<fixed<<setprecision(10)<<dfs(1,n);
getchar();
getchar();
return 0;
}
| #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
int L;
int comb[200][12];
signed main() {
int i, j;
cin >> L;
comb[0][0] = 1;
for (i = 0; i < L; i++) {
comb[i][0] = 1;
for (j = 1; j <= min(i, 11LL); j++) {
comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
}
}
cout << comb[L - 1][11] << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll mod = 1e9 + 7;
const ll linf = 1LL << 62;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}
int main() {
ll N;
cin >> N;
int cnt = 0;
for (int i = 1; i <= 1000000; i++) {
ll num = i;
ll cp = i;
ll t = 1;
while (cp != 0) {
t *= 10;
cp /= 10;
}
num = t * (ll)i + (ll)i;
if (num <= N) cnt++;
}
cout << cnt << endl;
} | #include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<utility>
#include<algorithm>
#include<functional>
#include<map>
#include<queue>
#include<stack>
#include<set>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
#define LL_INF 1e18+5
#define INT_INF 1e9+5
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
#define LL_INF 1e18+5
#define INT_INF 1e9+5
int main(){
ll N; cin >> N;
int cnt = 0;
ll tmp = 1;
while(tmp < N){
cnt++;
tmp *= 10;
}
if(cnt%2 == 1){
cnt /= 2;
ll ans = 1;
while(cnt > 0){
cnt--;
ans *= 10;
}
cout << ans - 1 << endl;
return 0;
}
else {
cnt /= 2;
ll ans = 1;
while(cnt>0){
ans *= 10;
cnt--;
}
if(N/ans <= N%ans){
cout << N/ans << endl;
return 0;
}
else {
cout << N/ans -1 << endl;
return 0;
}
}
} |
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <string>
#define REP(i,a,b) for(int i=a; i<b; i++)
#define REP1(i,a,b) for(int i=a; i<=b; i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef long long ll;
using namespace std;
int main()
{
//this code makes input and output more efficient:
ios::sync_with_stdio(0);
cin.tie(0);
char s;
set<char>se;
REP1(i,01,3)
{
cin >> s;
se.insert(s);
}
if (se.size()==1) cout << "Won";
else
cout << "Lost";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
if(s[0] == s[1] && s[1] == s[2]) cout << "Won" << endl;
else cout << "Lost" << endl;
} |
//**Anything done in love is beyond good and evil***
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
ll a[201];
vector<ll> v[201];
int main(){
ll n;
cin>>n;
//cout<<c;
forn(i,n) cin>>a[i];
forn(i,n){
vector<ll> temp[200];
forn(j,200) temp[j]=v[j];
for(ll j=0;j<200;j++){
if(v[j].size()==0) continue;
ll sum=0;
for(auto x:v[j]) sum+=a[x];
sum+=a[i];
sum=sum%200;
if(v[sum].size()!=0){
cout<<"Yes"<<endl;
cout<<v[sum].size()<<" ";
for(auto x:v[sum]) cout<<x+1<<" ";
cout<<endl;
cout<<v[j].size()+1<<" ";
for(auto x:v[j]) cout<<x+1<<" ";
cout<<i+1<<endl;
return(0);
}
temp[sum]=v[j];
temp[sum].pb(i);
}
forn(j,200) v[j]=temp[j];
ll sum=a[i]%200;
//cout<<sum<<" "<<v[sum].size()<<endl;
if(v[sum].size()!=0){
cout<<"Yes"<<endl;
cout<<v[sum].size()<<" ";
for(auto x:v[sum]) cout<<x+1<<" ";
cout<<endl;
cout<<"1 "<<i+1<<endl;
return(0);
}
else v[sum].pb(i);
}
cout<<"No";
} | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define sz(x) (int)x.size()
#define fr first
#define sc second
#define all(a) a.begin(), a.end()
#define int long long
const int N = 1e6 + 10;
const int INF = 2e9;
const int MOD = 1e9 + 7;
int dp[213][213][213][2][2], a[211], n;
vector <int> D, C;
int calc(int cur, int A, int B, int At, int Bt) {
if(cur == n + 1)
return dp[cur][A][B][At][Bt] = (A == B && At && Bt);
if(dp[cur][A][B][At][Bt] != -1)
return dp[cur][A][B][At][Bt];
int ans = 0;
ans |= calc(cur + 1, (A + a[cur]) % 200, B, 1, Bt);
ans |= calc(cur + 1, A, (B + a[cur]) % 200, At, 1);
ans |= calc(cur + 1, A, B, At, Bt);
return dp[cur][A][B][At][Bt] = ans;
}
void findAns(int cur, int A, int B, int At, int Bt) {
if(cur == n + 1)
return;
if(A == B && At && Bt) {
return;
}
if(dp[cur + 1][(A + a[cur]) % 200][B][1][Bt] == 1) {
D.pb(cur);
findAns(cur + 1, (A + a[cur]) % 200, B, 1, Bt);
}
else if(dp[cur + 1][A][(B + a[cur]) % 200][At][1] == 1) {
C.pb(cur);
findAns(cur + 1, A, (B + a[cur]) % 200, At, 1);
}
else
findAns(cur + 1, A, B, At, Bt);
}
void solve() {
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
a[i] %= 200;
}
memset(dp, -1, sizeof dp);
if(!calc(1, 0, 0, 0, 0)) {
cout << "No\n";
return;
}
cout << "Yes\n";
findAns(1, 0, 0, 0, 0);
cout << sz(D) << ' ' ;
for(auto u: D) cout << u << ' ';
cout << '\n';
cout << sz(C) << ' ';
for(auto u: C) cout << u << ' ';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1;
// cin >> t;
while(t--) {
solve();
}
} |
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll k,n;
cin >> n >> k;
vll cnt(300009,0);
REP(i,n){
ll a;
cin >> a;
cnt[a+1]++;
}
cnt[0]=k;
ll sum = 0;
for(ll i=1;i<=300001;i++){
if(cnt[i]==0){
sum += cnt[i-1]*(i-1);
break;
}
sum += (i-1)*(max(0LL,cnt[i-1]-cnt[i]));
if(cnt[i]>cnt[i-1])cnt[i] = cnt[i-1];
//cout << sum << endl;
}
cout << sum << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;
int main(){
int a, b;
cin >> a >> b;
int x, y;
cin >> x >> y;
int ans = x;
if(a > b) a--;
int d = abs(a - b);
int add = min(y, 2*x);
ans += d*add;
cout << ans << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define fi(i, l, r) for (int i = l; i < r; i++)
#define cd(a) scanf("%d", &a)
typedef long long ll;
ll getScore(ll s[])
{
ll ans=0;
for(ll i=1;i<10;i++)
{
ans+=i*pow(10,s[i]);
}
return ans;
}
// ll getScore1(ll s[])
// {
// ll ans=0;
// for(ll i=1;i<10;i++)
// {
// printf("s[%lld]=%lld ",i,s[i]);
// ans+=i*pow(10,s[i]);
// printf("i=%lld,1LL<<%lld=%lld\n",i,s[i],(1LL<<s[i]));
// }
// printf("\nreturn:%lld\n",ans);
// return ans;
// }
// int main()
// {
// ll sa[10]={2,3,0,0,0,0,0,0,0};
// ll sb[10]={1,3,0,0,0,0,0,1,0};
// printf("GSa=%lld\nGSb=%lld\n",getScore1(sa),getScore1(sb));
// return 0;
// }
int main()
{
ll k;
cin >> k;
char s[10], t[10];
cin >> s >> t;
ll shengyu[10] = {0};
for (ll i = 1; i < 10; i++)
shengyu[i] = k;
ll suma[10] = {0};
ll sumb[10] = {0};
for (ll i = 0; i < 4; i++)
{
shengyu[s[i] - '0']--;
shengyu[t[i] - '0']--;
suma[s[i]-'0']++;
sumb[t[i]-'0']++;
}
ll canWin=0;
for (ll i = 1; i <= 9; i++)
{
for (ll j = 1; j <= 9; j++)
{
bool sfbx=false;
if(shengyu[i]<=0)sfbx=true;
if(shengyu[j]<=0)sfbx=true;
suma[i]++;
sumb[j]++;
//shengyu[i]--;
//shengyu[j]--;
if(!sfbx)
{
ll sa=getScore(suma);
ll sb=getScore(sumb);
// if(i==2&&j==1)
// {
// cout<<"i="<<i<<",j="<<j<<"!!!"<<endl;
// printf("suma:");
// for(int i=1;i<=9;i++)printf(" %d",suma[i]);
// printf("\nsumb:");
// for(int i=1;i<=9;i++)printf(" %d",sumb[i]);
// printf("\nsa=%lld,sb=%lld\n",sa,sb);
// puts("---------");
// }
if(sa>sb)
{
if(i==j)
{
canWin += shengyu[i] * (shengyu[i]- 1);
}
else
{
canWin += shengyu[i] * shengyu[j];
}
}
// else
// {
// printf("i=%lld,j=%lld,sa=%lld,sb=%lld,Cannot!!!\n",i,j,sa,sb);
// }
}
suma[i]--;
sumb[j]--;
//shengyu[i]++;
//shengyu[j]++;
}
}
ll shengyuAll = k*9-8;
ll canAll = shengyuAll*(shengyuAll-1);
double ans = 1. * canWin / canAll;
printf("%.15lf\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
typedef int64_t ll;
#define PA pair<ll,ll>
#define TU tuple<ll,ll,ll>
#define vi vector<ll>
#define vii vector<vector<ll> >
#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define rep2(i,m,n) for(ll (i)=(m); (i)<(ll)(n); (i)++)
const ll INF = 1ll<<30;
const ll INF2 = 1ll<<32;
int main() {
ll k;
cin >>k;
string s,t;
cin >>s >>t;
//v_t.at(i)=数字i-1の存在個数
vi v_t(9,0),v_a(9,0);
rep(i,4) {
v_t.at(s.at(i)-'1')++;
v_a.at(t.at(i)-'1')++;
}
vi v_remain(9);
rep(i,9) {
v_remain.at(i) = k - (v_t.at(i)+v_a.at(i));
}
//ここでのanspはパターンの数。最終的には(9*k-8)P(2)で割る。
ll ansp =0;
ll pts_t, pts_a;
vi v_tt(9), v_aa(9);
rep(tak,9) {
v_tt = v_t;
v_tt.at(tak)++;
rep(aok,9) {
if(tak==aok && v_remain.at(tak)<2) continue;
else if(v_remain.at(tak)==0 || v_remain.at(aok)==0) continue;
v_aa = v_a;
v_aa.at(aok)++;
pts_t = 0;
pts_a = 0;
rep(i,9) {
pts_t += (i+1) * pow(10,v_tt.at(i));
pts_a += (i+1) * pow(10,v_aa.at(i));
}
if(pts_t>pts_a) {
if(tak==aok) ansp += v_remain.at(tak)*(v_remain.at(tak)-1);
else ansp += v_remain.at(tak)*v_remain.at(aok);
}
}
}
double ans = (double)ansp/((9*k-8)*(9*k-9));
cout << fixed << setprecision(7);
cout << ans << endl;
} |
//IQ134高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007
#define MODB 998244353
template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
for (T& x: vec) { is >> x; }
return is;
}
int main() {
ll ans = 0;
ll tmp = 0;
//int n; cin >> n;
bool now;
int a[2]; cin >> a[0] >> a[1] >> now;
int win;
while(1){
if(a[now] == 0){
win = 1 - now;
break;
}
else a[now]--;
now = 1 - now;
}
if (win == 0) cout << "Takahashi" << endl;
else cout << "Aoki" << endl;
//cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long int
#define f(i,n) for(int i=0;i<n;i++)
#define f(j,n) for(int j=0;j<n;j++)
int32_t main() {
int a,b,c;
cin>>a>>b>>c;
if(c==0)
{
if(a==b)
cout<<"Aoki";
else if(a<b)
cout<<"Aoki";
else
cout<<"Takahashi";
}
else
{
if(a==b)
cout<<"Takahashi";
else if(a<b)
cout<<"Aoki";
else
cout<<"Takahashi";
}
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
void siglo(int a)
{
if (a <= 0)
cout <<0;
else if (a <= 100)
cout <<1;
else if (a % 100 == 0)
cout << a/ 100 ;
else
cout << a/ 100 + 1 ;
}
int main()
{
int a =0;
cin>>a;
siglo(a);
return 0;
}
| #include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli long long int
#define int long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define vi vector<int>
#define vii vector<pi>
#define all(a) a.begin(),a.end()
#define sz(a) (int)a.size()
#define pb push_back
#define ppb pop_back
#define pf push_front
#define fr first
#define sc second
using namespace std;
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
// __builtin_popcountll(x);
// __builtin_clz(x) // Count Leading zeros
// __builtin_ctz(x) // Trailing zeros
const int MM = 998244353;
const int mod = 1e9 + 7;
const int INF = 1e15;
const int N = 5e6 + 4;
// vector<int>pref(N,0);
// vector<int>suff(N,0);
void solve()
{
string s;
cin >> s;
int n = sz(s);
int ans = 0;
int num = stoll(s);
if(num < 1000) {
cout << 0 << "\n";
return;
}
if(num <= 999999) {
ans += num - 999;
}
else if(num > 999999 and num <= 999999999) {
ans += 999999 - 999;
ans += 2 * (num - 999999);
}
else if(num > 999999999 and num <= 999999999999) {
ans += 999999 - 999;
ans += 2 * (999999999 - 999999);
ans += 3 * (num - 999999999);
}
else if(num > 999999999999 and num <= 999999999999999) {
ans += 999999 - 999;
ans += 2 * (999999999 - 999999);
ans += 3 * (999999999999 - 999999999);
ans += 4 * (num - 999999999999);
}
else {
ans += 999999 - 999;
ans += 2 * (999999999 - 999999);
ans += 3 * (999999999999 - 999999999);
ans += 4 * (999999999999999 - 999999999999);
ans += 5 * (num - 999999999999999);
}
cout << ans;
}
signed main()
{
ios;
int t;
t=1;
// cin>>t;
while(t--)
{
solve();
}
} |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define debug(a) { cerr << #a << ':' << a << endl; }
#define endl '\n'
#define fi first
#define se second
using lint = long long;
using P = pair<int,int>;
template<class T> using V = vector<T>;
template<class T> using priq = priority_queue<T>;
template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
template<class T> T ceil(const T &a, const T &b) { return (a+b-1)/b; }
template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;
template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) {
return in >> p.first >> p.second;
}
template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) {
return out << "{ " << p.first << ',' << p.second << " } ";
}
template<class T> istream& operator>>(istream &in, vector<T> &v) {
for(auto &&e: v) in >> e;
return in;
}
template<class T> ostream& operator<<(ostream &out, const vector<T> &v) {
for(const auto &e: v) out << e << ' ';
return out;
}
/*----------------------------------------------------------------------------------------------------*/
int n, m;
V<string> s;
// fstream out("AHC004_out.txt");
int main() {
clock_t start = clock();
cin >> n >> m;
s.resize(m);
cin >> s;
V<P> cnts(m); // pair = (count, index);
V<V<int>> ins(m);
rep(i,m) {
int cnt = 0;
rep(j,m) {
bool isin = ( s[i].find(s[j]) != string::npos );
if(isin) {
cnt++;
ins[i].push_back(j);
}
}
cnts[i] = make_pair(cnt,i);
}
sort(rall(cnts));
V<bool> used(m);
V<string> ans(n);
rep(i,n) { // 初期解生成
string str = "";
rep(j,m) {
int x = cnts[j].se;
if(used[x]) continue;
string plus = s[x];
for(int k = min(sz(str), sz(s[x])); k >= 0; k--) {
if( str.substr(sz(str)-k,k) == s[x].substr(0,k) ) {
plus = s[x].substr(k,sz(s[x])-k);
break;
}
}
if(sz(str) + sz(plus) > n) continue;
str += plus;
for(int y: ins[x]) used[y] = true;
}
str.resize(n,'.');
ans[i] = str;
}
V<int> v(n); iota(all(v), 0);
pair<int,V<int>> mx = make_pair(0,v);
random_device seed_gen;
mt19937 engine(seed_gen());
while(clock() - start < 2980000) {
V<bool> nused = used;
int cnt = 0;
rep(j,n) { // yoko
string ns = "";
rep(i,n) ns += string(1,ans[v[i]][j]);
ns += ns;
rep(i,m) {
if(nused[j]) continue;
if( ns.find(s[j]) != string::npos ) {
cnt++;
nused[j] = true;
}
}
}
chmax(mx, make_pair(cnt, v));
shuffle(all(v), engine);
}
rep(i,n) {
cout << ans[mx.se[i]] << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
int int_n;
int int_m;
int num1 = 0,num2 = 0;
cin >> int_n >> int_m;
while(int_n > 0)
{
num1 += int_n % 10;
int_n /= 10;
}
while(int_m > 0)
{
num2 += int_m % 10;
int_m /= 10;
}
printf("%d",max(num1,num2));
} |
#include <bits/stdc++.h>
#define fir first
#define sec second
#define PB push_back
#define MP make_pair
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i < (int)(n); ++i)
#define foreach(itr, c) for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); ++itr)
template <class T> void chkmax(T& x, T y) { x = (x > y ? x : y); }
template <class T> void chkmin(T& x, T y) { x = (x < y ? x : y); }
typedef long long LL;
typedef pair <int, int> pii;
typedef vector <int> vi;
const int N = 105;
const int M = 1e4 + 5;
int n, m, a[M], b[M], c[N];
vi e[N];
set <int> e2[N];
bool vis[N];
void dfs(int now, int from){
vis[now] = 1;
for (auto u : e[now]) if (u != from && c[u] == c[now]){
if (e2[u].find(now) != e2[u].end()) continue;
e2[now].insert(u);
if (!vis[u]) dfs(u, now);
}
}
int main(){
scanf("%d%d", &n, &m);
rep(i, m){
scanf("%d%d", &a[i], &b[i]), a[i]--, b[i]--;
e[a[i]].PB(b[i]);
e[b[i]].PB(a[i]);
}
rep(i, n) scanf("%d", &c[i]);
rep(i, m){
if (c[a[i]] > c[b[i]]) e2[a[i]].insert(b[i]);
else if (c[a[i]] < c[b[i]]) e2[b[i]].insert(a[i]);
else {
if (e2[a[i]].find(b[i]) != e2[a[i]].end() || e2[b[i]].find(a[i]) != e2[b[i]].end())
continue;
dfs(b[i], a[i]);
}
}
rep(i, m){
if (e2[a[i]].find(b[i]) != e2[a[i]].end()) printf("->\n");
else printf("<-\n");
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<pair<int, int>> edges(m);
vector<vector<int>> g(n);
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
x--, y--;
edges[i] = {x, y};
g[x].emplace_back(i);
g[y].emplace_back(i);
}
vector<int> c(n);
for (int i = 0; i < n; i++) {
cin >> c[i];
}
vector<int> ans(m, -1); // 0 "->" , 1 "<-"
for (int i = 0; i < m; i++) {
if (c[edges[i].first] > c[edges[i].second]) {
ans[i] = 0;
} else if (c[edges[i].first] < c[edges[i].second]) {
ans[i] = 1;
}
}
vector<int> done(n);
for (int i = 0; i < m; i++) {
if (ans[i] == -1) {
if (done[edges[i].first] && done[edges[i].second]) {
continue;
}
set<int> st;
int root = edges[i].first;
if (done[edges[i].second]) {
root = edges[i].second;
}
done[root] = 1;
st.emplace(root);
function<bool(int)> dfs = [&](int v) {
for (int id : g[v]) {
if (ans[id] == -1) {
int to = v ^ edges[id].first ^ edges[id].second;
if (v == edges[id].first) {
ans[id] = 0;
} else {
ans[id] = 1;
}
if (done[to] || dfs(to)) {
st.emplace(v);
done[v] = 1;
return true;
}
ans[id] = -1;
}
}
return false;
};
while (true) {
bool ok = false;
for (int t : st) {
if (dfs(t)) {
ok = true;
}
}
if (!ok) {
break;
}
}
}
}
debug(ans);
for (int i = 0; i < m; i++) {
if (ans[i] == 0) {
cout << "->" << '\n';
} else {
cout << "<-" << '\n';
}
}
return 0;
} |
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;
int64_t solve(int64_t a, int64_t b, int64_t c, int64_t d) {
// TODO: edit here
return b - c;
}
// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
constexpr char endl = '\n';
int64_t a, b, c, d;
cin >> a >> b >> c >> d;
auto ans = solve(a, b, c, d);
cout << ans << endl;
return 0;
}
| //#include <atcoder/all>
#include <bits/stdc++.h>
//using namespace atcoder;
using namespace std;
typedef long long ll;
#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
// 最大公約数
ll gcd(ll a, ll b)
{
if(b == 0) return a;
return gcd(b, a % b);
}
// mod m におけるa の逆元
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
ll s = sqrt(n);
ll r = 0;
for(ll i = 2; i <= s; i++) {
if((n % i) == 0) {
r = 0;
do {
r++;
n = n / i;
} while((n % i) == 0);
prim.push_back({i, r});
}
}
if(n > s) {
prim.push_back({n, 1});
}
}
void solve()
{
ll N; cin >> N;
ll ans = N - 1;
cout << ans << endl;
}
int main(void)
{
// ll t; cin >> t; rep(i, t)
solve();
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
int n,m,x,y;
cin>>n>>m>>x>>y;
x--;
y--;
vector<string>s(n);
for(int i=0;i<n;i++){
cin>>s[i];
}
int c=0;
for(int i=x+1;i<n;i++){
if(s[i][y]=='.'){
c++;
//cout<<i<<" "<<y<<endl;
}
else{
break;
}
}
for(int i=x-1;i>=0;i--){
if(s[i][y]=='.'){
c++;}
else{
break;
}
}
for(int i=y-1;i>=0;i--){
if(s[x][i]=='.'){
c++;
}
else{
break;
}
}
for(int i=y+1;i<m;i++){
if(s[x][i]=='.'){
c++;
}
else{
break;
}
}
cout<<c+1;
return 0;}
| #include <bits/stdc++.h>
using namespace std;
int main(){
int h, w, x, y;
cin >> h >> w >> x >> y;
char s[h][w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> s[i][j];
}
}
int count = 0;
for (int i = x-1; i < h; i++) {
if (s[i][y-1] == '.')
count++;
else
break;
}
for (int i = x-1; i < h && i >= 0; i--) {
if (s[i][y-1] == '.')
count++;
else
break;
}
for (int j = y-1; j < w; j++) {
if (s[x-1][j] == '.')
count++;
else
break;
}
for (int j = y-1; j < w && j >= 0; j--) {
if (s[x-1][j] == '.')
count++;
else
break;
}
cout << count - 3 << endl;
} |
#include<bits/stdc++.h>
using namespace std;
int n;
char s[800008];
int q;
int t,a,b;
int opt=0;
int main(){
cin>>n;
scanf("%s",s+1);
scanf("%d",&q);
while(q--){
scanf("%d%d%d",&t,&a,&b);
if(t==2) opt++;
else if(t==1){
if(opt%2==0){
swap(s[a],s[b]);
}else{
// cout<<"a+n="<<a+n<<" b+n="<<b+n<<endl;
// swap(s[(a+n)%n],s[(b+n)%n]);
if(a<=n&&b<=n) swap(s[a+n],s[b+n]);
if(a>=n+1&&b>=n+1) swap(s[a-n],s[b-n]);
if(a<=n&&b>=n+1) swap(s[a+n],s[b-n]);
}
}
}
if(opt%2==1){
for(int i=n+1;i<=2*n;i++)
cout<<s[i];
for(int i=1;i<=n;i++)
cout<<s[i];
// for(int i=1;i<=2*n;i++)
// cout<<s[i];
}else {
for(int i=1;i<=2*n;i++)
cout<<s[i];
}
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define int long long int
const int MOD = 1e9 + 7;
#define MAX 100005
#define CHAR_SIZE 26
int power(int x, int y){
int res = 1;
while (y > 0){
if (y & 1)
res = (res * x) % MOD;
y = y >> 1;
x = (x * x) % MOD;
}
return res;
}
int modInverse(int n){
return power(n, MOD - 2);
}
int fac[100005];
int cache[100005];
int gcd(int a, int b){
if (b == 0)
return a;
return gcd(b, a % b);
}
int nCrModPFermat(int n, int r){
if (n < r)
return 0;
if (r == 0)
return 1;
return (fac[n] * modInverse(fac[r]) % MOD * modInverse(fac[n - r])) % MOD;
}
void pre_compute(){
fac[0] = 1;
for(int i = 1 ; i < 100005 ; i++){
fac[i] = (fac[i - 1] * i) % MOD;
}
}
void solveEach(){
int n;
cin >> n;
string s;
cin >> s;
int q;
cin >> q;
string a,b;
for(int i = 0 ; i < n ; i++) a += s[i];
for(int i = n ; i < 2*n ; i++) b += s[i];
int a1 = 0;
int op;
int i,j;
while(q--){
cin >> op >> i >> j;
if(op == 2){
if(a1 == 0) a1 = 1;
else a1 = 0;
}else{
i--;
j--;
if(j < n){
if(a1 == 0){
swap(a[i] , a[j]);
}else swap(b[i] , b[j]);
}else if(i >= n){
i -= n;
j -= n;
if(a1 == 1){
swap(a[i] , a[j]);
}else swap(b[i] , b[j]);
}else if(j >= n){
j -= n;
if(a1 == 0){
swap(a[i] , b[j]);
}else swap(a[j] , b[i]);
}
}
}
if(a1 == 0){
cout << a << b ;
}else cout << b << a;
return;
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
//cin >> T;
for(int i = 1 ; i <= T ; i++){
//cout << "Case #" << i << ": ";
solveEach();
}
return 0;
}
/*
AtCoder Beginner Contest 199(Sponsored by Panasonic)
*/
|
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<ll> A(N);
for (auto& a : A) {
cin >> a;
}
ll ans = 0;
rep(i, 0, N) {
ll min_a = A[i];
rep(j, i, N) {
chmin(min_a, A[j]);
chmax(ans, min_a * (ll)(j - i + 1));
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
void printmat(const vector<vector<int>>& mat) {
for (auto row : mat) {
for (int elem : row)
cout << elem << " ";
cout << endl;
}
}
void printv(const vector<long long>& v) {
for (int elem : v)
cout << elem << " ";
cout << endl;
}
void printvp(const vector<pair<int, int>>& vp) {
for (auto row : vp)
cout << row.first << ", " << row.second << " ; ";
cout << endl;
}
int main() {
int T=1, caseIdx=0;
//cin >> T;
while (T--) {
caseIdx++;
string x, ans;
cin >> x;
auto it = x.find('.');
ans = x.substr(0, it);
cout << ans << endl;
//cout << "Case #" << caseIdx << ": " << ans << endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}
int main2() {
ll S = nextLong();
ll P = nextLong();
for (ll a = 1; a * a <= P; a++) {
if (P % a == 0) {
ll b = P / a;
if (a + b == S) {
return 1;
}
}
}
return 0;
}
int main() {
bool ans = main2();
cout << (ans ? "Yes":"No") << endl;
return 0;
} | #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define pb(a) push_back(a)
#define set0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define INF 0x3f3f3f3f
typedef long long ll;
int main(){
int T; cin>>T;
while(T--){
ll n; cin>>n;
int d=0;
while(n%2==0){
n/=2;
d++;
}
if(!d) puts("Odd");
else if(d==1) puts("Same");
else puts("Even");
}
return 0;
} |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main(){
int n, m;
cin>>n>>m;
vector<int> w(n);
rep(i, n) cin>>w[i];
vector<P> lv;
rep(i, m){
int l, v;
cin>>l>>v;
lv.push_back(make_pair(l, v));
}
bool ng=false;
int mnv=INT_MAX;
for(P p : lv) mnv=min(mnv, p.second);
rep(i, n) if(w[i]>mnv) ng=true;
if(ng){
cout<<(-1)<<endl;
return 0;
}
sort(lv.begin(), lv.end());
map<int, int> ma;
for(P p : lv){
int l=p.first, v=p.second;
auto it=ma.lower_bound(v);
vector<map<int, int>::iterator> dl;
for(; it!=ma.end(); it++){
dl.push_back(it);
}
for(auto it : dl) ma.erase(it);
ma[v]=l;
}
// for(P p : ma) cout<<"ma"<< (p.first)<<" "<<(p.second)<<endl;
auto mnl=[&](int w){
auto it=ma.lower_bound(w);
if(it==ma.begin()) return 0;
else{
it--;
return it->second;
}
};
vector<int> inds(n);
rep(i, n) inds[i]=i;
ll mn=LLONG_MAX;
do{
vector<ll> s(n+1);
rep(i, n) s[i+1]=s[i]+w[inds[i]];
// cout<<"w "; rep(i, n) cout<<w[inds[i]]<<" "; cout<<endl;
// cout<<"s "; rep(i, n+1) cout<<s[i]<<" "; cout<<endl;
vector<ll> dp(n);
rep(i, n){
rep(j, i){
ll sw=s[i+1]-s[j];
dp[i]=max(dp[i], dp[j]+mnl(sw));
// cout<<"mn "<<i<<" "<<j<<" "<<mnl(sw)<<endl;
}
}
mn=min(mn, dp[n-1]);
} while(next_permutation(inds.begin(), inds.end()));
cout<<mn<<endl;
return 0;
}
| #include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>
#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i) //coutの浮動小数出力の桁数設定
using namespace std;
int main()
{
int64 ss, pp, ans = 0;
cin >> ss >> pp;
for(int64 ii = 1;ii * ii <= pp;ii++)
{
int64 jj = ss - ii;
if(ii * jj == pp)
{
if(ii == jj)
{
ans--;
}
ans += 2;
}
}
if(ans == 0)
{
cout << "No" << endl;
}
else
{
cout << "Yes" << endl;
}
return 0;
} |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <set>
using namespace std;
long long int N, K;
long long int num(long long int N, long long int k) {
if (k <= N + 2) {
return ((k - 2)*(k - 1)) / 2;
}
else if (k <= N * 2 + 1) {
return ((k - 2)*(k - 1)) / 2 - ((k - 2 - N)*(k - 1 - N) * 3) / 2;
}
else if (k <= N * 3) {
return ((N * 3 - k + 1)*(N * 3 - k + 2)) / 2;
}
return 0;
}
int cnt[10000];
long long int num2(long long int N, long long int m) {
if (m <= N + 1) { return m - 1; }
else if(m<=N*2) { return N * 2 - m + 1; }
return 0;
}
int main(void) {
cin >>N >> K;
/*for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
for (int k = 1; k <= N; k++) {
cnt[i + j + k]++;
}
}
}
for (int k = 3; k <= N*3; k++) {
cout << "k= " << k << " " << num(N, k) << " "<<cnt[k]<< endl;
}*/
int k = 3;
while (K > num(N, k)) {
K -= num(N, k); k++;
}
//cout << "k= " << k << endl;
long long int m = k - 1;
while (K > num2(N, m)) {
K -= num2(N, m); m--;
}
//cout << "m= " << m << endl;
long long int ans1, ans2, ans3;
ans1 = k - m;
//cout << "K= " << K << endl;
vector<pair<long long int, long long int> > V;
for (long long int i = 1; i <= N; i++) {
long long int x = i; long long int y = m - x;
if (1 <= x && x <= N && 1 <= y && y <= N) { V.push_back(make_pair(x, y)); }
}
ans2 = V[K - 1].first;
ans3 = V[K - 1].second;
cout << ans1 << " " << ans2 << " " << ans3 << endl;
return 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 emplace_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(int64_t &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 int64_t &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("[DEBUG] ");W(__VA_ARGS__);}
#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 = 1<<22;
int N;
LL K;
LL dp[4][SIZE];
void solve() {
dp[0][0]=1;
FOR(i,1,3){
REPP(j,1,SIZE){
dp[i-1][j]+=dp[i-1][j-1];
}
REPP(j,1,SIZE){
if(j<=N){
dp[i][j]=dp[i-1][j-1];
}else{
dp[i][j]=dp[i-1][j-1]-dp[i-1][j-N-1];
}
}
for(int j=SIZE-1;j>0;j--){
dp[i-1][j]-=dp[i-1][j-1];
}
}
FOR(i,3,3*N){
if(K<=dp[3][i]){
FOR(j,1,N){
if(K<=dp[2][i-j]){
FOR(k,1,N){
if(i-j-k<=N&&i-j-k>0){
K--;
if(!K){
W(j,k,i-j-k);
exit(0);
}
}
}
}else{
K-=dp[2][i-j];
}
}
}else{
K-=dp[3][i];
}
}
}
void input() {
R(N,K);
}
int main(){
input();
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mt make_tuple
#define x first
#define y second
#define int ll
const int N = 1e6;
int tn, n, p[N];
vector<int> ans;
bool can(int i) {
assert(1 <= i && i < n);
return (int)ans.size() % 2 == (i - 1) % 2;
}
void sh(int i) {
assert(can(i));
ans.emplace_back(i);
swap(p[i - 1], p[i]);
}
// 1 2 3
// 2 1 3
// 2 3 1
// 3 2 1
// 3 1 2
// 1 3 2
void lo(int i) {
assert(!can(i));
if (i >= 2) {
sh(i - 1), sh(i), sh(i - 1), sh(i), sh(i - 1);
} else {
sh(i + 1), sh(i), sh(i + 1), sh(i), sh(i + 1);
}
}
void x2(int i) {
assert(!can(i));
assert(i >= 2);
sh(i - 1), sh(i), sh(i - 1), sh(i);
}
void print() {
for (int j = 0; j < n; ++j) {
cout << p[j] << " ";
}
cout << endl;
}
void solve() {
if (n == 2) {
if (p[0] > p[1]) {
assert(can(1));
sh(1);
}
return;
}
// for (int i = 0; i < n; ++i) {
// cout << p[i] << " ";
// }
// cout << endl;
for (int from = 1; from < n; ++from) {
int i = from;
if (p[i] >= p[i - 1]) {
continue;
}
// cout << "st " << i << endl;
if (!can(i)) {
if (can(n - 1)) {
sh(n - 1);
} else if (from != n - 1) {
assert(can(n - 2));
sh(n - 2);
}
}
// print();
while (i && p[i] < p[i - 1]) {
if (can(i)) {
sh(i);
} else if (i >= 2 && p[i] < p[i - 2]) {
x2(i);
--i;
} else {
lo(i);
}
--i;
}
// print();
}
assert(is_sorted(p, p + n));
assert((int)ans.size() <= n * n);
}
signed main() {
#ifdef LC
assert(freopen("input.txt", "r", stdin));
#endif
ios::sync_with_stdio(0); cin.tie(0);
cin >> tn;
while (tn--) {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> p[i];
}
ans.clear();
solve();
cout << ans.size() << "\n";
for (int e : ans) {
cout << e << " ";
}
cout << "\n";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
// Type alias
using ll=long long;
using ld=double;
using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;
using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;
// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max() / 2;
const ll mod = 1e9+7;
// Macro
#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 REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl
#define ALL(a) a.begin(),a.end()
// Funtcions
ll pow(ll base, ll i, ll mod){
ll a = 1;
while(i){
if (i & 1) {
a *= base;
a %= mod;
}
base *= base;
base %= mod;
i >>= 1;
}
return a;
}
ll gcd(ll a, ll b){
while(b){
ll c = a % b;
a = b;
b = c;
}
return a;
}
ll lcm(ll a, ll b){
return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
if (a > b) return a = b, true; else return false;
}
template<typename T> bool chmax(T& a, const T& b) {
if (a < b) return a = b, true; else return false;
}
void solve(){
int n; cin >> n;
vi p(n);
rep(i, n) cin >> p[i];
vi ans;
int i = 1;
bool isodd = false;
int even = (n - 1) - (n % 2) - 1;
int odd = (n - 1) - !(n % 2) - 1;
while(i < n - 1) {
int idx = find(ALL(p), i) - p.begin();
if(i - 1 == idx) {
i++;
continue;
}
if((idx - 1) % 2 != isodd) {
if(isodd) {
ans.push_back(odd + 1);
swap(p[odd], p[odd+1]);
} else {
ans.push_back(even + 1);
swap(p[even], p[even+1]);
}
} else {
ans.push_back(idx);
swap(p[idx - 1], p[idx]);
}
isodd ^= true;
}
if(p[n - 1] == n - 1) {
if(isodd == (n - 2) % 2) {
ans.push_back(n - 1);
} else {
ans.push_back(n - 2);
ans.push_back(n - 1);
ans.push_back(n - 2);
ans.push_back(n - 1);
ans.push_back(n - 2);
}
}
cout << ans.size() << endl;
rep(i, ans.size()) {
if(i != 0) cout << " ";
cout << ans[i];
}
cout << endl;
}
int main(){
// FastIO
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin >> t;
rep(ghrskj, t) solve();
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
ofstream file("debug.txt");
#define debug(x) file << (#x) << " = " << x << endl << flush
#define sz(x) (int)x.size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef long double ld;
template<typename Int>
ostream& operator<<(ostream &s, const vector<Int> &v) {
s << '[';
for (auto i = v.begin(); i != v.end(); i++) {
s << *i;
if (i != prev(v.end()))
s << ", ";
}
s << ']';
return s;
}
template<typename Int, typename INT>
ostream& operator<<(ostream &s, const map<Int, INT> &mp) {
s << '[';
for (auto &i : mp) {
s << '[' << i.first << ", " << i.second << ']';
if (i != *mp.rbegin())
s << ", ";
}
s << ']';
return s;
}
template<typename Int>
ostream& operator<<(ostream &s, const set<Int> &st) {
s << '[';
for (auto &i : st) {
s << i;
if (i != *st.rbegin())
s << ", ";
}
s << ']';
s << endl;
return s;
}
template<typename Int, typename INt>
ostream& operator<<(ostream &s, const pair<Int, INt> &x) {
s << '[' << x.first << ", " << x.second << ']';
return s;
}
template<typename T>
void print(T *x, int n) {
for (int i = 0; i < n; i++) {
file << x[i] << " \n"[i == n - 1];
}
}
template<typename T>
ostream& operator<<(ostream &s, const complex<T> &a) {
s << '(' << a.real() << ", " << a.imag() << ')';
return s;
}
// Always think of patterns (LCM, GCD)
// Be careful of unsigned
// Think of a solution that gets TLE and optimize it
// Use binary search
// Solve on paper first
// Reverse Thinking
// Monotonic stack/dequeue
// EV is computed using probabilities or number of ways
// E(X + Y) = E(X) + E(Y)
// E(X * Y) = E(X) * E(Y)
// If there's an equation, transform it into an easy one
// READ ALL PROBLEMS
const int N = 3e3 + 5;
const int MOD = 1e9 + 7;
int n, y[N][N], dp[N][N], mods[N];
ll x[N];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
clock_t START_TIME = clock();
#endif
cin >> n;
memset(y, -1, sizeof y);
for (int i = 1; i <= n; i++) {
cin >> x[i];
x[i] += x[i - 1];
y[i][1] = i;
}
for (int i = 2; i <= n; i++) {
memset(mods, -1, i * 4);
for (int j = n; j; j--) {
mods[x[j] % i] = j;
int &tmp = mods[x[j - 1] % i];
if (~tmp)
y[j][i] = tmp;
}
}
/*
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
file << y[i][j] << "\t\n"[j == n];
*/
dp[1][1] = 1;
for (int mod = 1; mod <= n; mod++) // group number
for (int idx = 1; idx <= n; idx++) { // index
int &ret = dp[mod][idx], &ed = y[idx][mod];
dp[mod + 1][ed + 1] += ret;
dp[mod + 1][ed + 1] %= MOD;
if (ed != n) {
dp[mod][ed + 1] += ret;
dp[mod][ed + 1] %= MOD;
}
}
/*
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
file << dp[i][j] << " \n"[j == n];
*/
int ans = 0;
for (int i = 1; i <= n + 1; i++)
ans = (ans + dp[i][n + 1]) % MOD;
cout << ans;
#ifndef ONLINE_JUDGE
printf("\n// Time taken = %.3f ms",
(clock() - START_TIME) * 1e3 / CLOCKS_PER_SEC);
#endif
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define ll long long
#define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr))
#define RF(type, i, a, b, decr) for (type i = a; i >= (type)(b); i -= (type)(decr))
#define sz(a) sizeof(a)
#define deb(a) cerr << " [" << #a << "->" << a << "] "
#define next_line cerr << '\n'
#define all(a) a.begin(), a.end()
#define iter(it, s) for (auto it = s.begin(); it != s.end(); it++)
#define setbits(x) __builtin_popcountll(x)
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
/*
1. If you cannot approach a problem
directly in the way it is proposed
then try to think from backwards
2. Have you checked the implementation
before starting to write the code?
3. Have you read the question carefully ?
4. Keep the names of variable descriptive.
5. Check the types and range of the values properly
6. Erase a iterator in the set or map only after using its value.
7. 1 bitset of 1e9 size only takes 256 mb.
8. Try to use global variables in case of recursion
9. Short and precise exectutes faster
*/
int INF = 1e16;
// graph[i] = stores the vectors of [neighbour, weight]
void DijikstraWithQueue(vector<int> &ans, vector<vector<vector<int> > > &graph, int s, int n)
{
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int>> > frontier;
frontier.push(make_pair(0, s));
ans.assign(n, INF);
ans[s] = 0;
vector<bool> visited(n, false);
while(!frontier.empty())
{
int node = frontier.top().second, dis = frontier.top().first;
frontier.pop();
visited[node] = true;
if(ans[node] != dis)
continue;
if(ans[node] == INF)
break;
for(vector<int> e : graph[node])
{
if(!visited[e[0] ])
{
//ans[e[0] ], e[0]
int nx = (((ans[node] % e[2]) != 0LL) + (ans[node ] / e[2])) * e[2];
if(ans[e[0] ] > nx + e[1])
{
ans[e[0] ] = nx + e[1];
frontier.push(pair<int,int>(ans[e[0] ] , e[0]));
}
}
}
}
}
void solve()
{
int n,m,x,y;
cin >> n >> m >> x >> y;
vector<vector<vector<int> > > graph(n);
F(int, i, 1, m, 1){
int a, b,k,t;
cin >> a >> b >> t >> k;
a--;
b--;
graph[a].push_back(vector<int>{b, t, k});
graph[b].push_back(vector<int>{a, t, k});
}
vector<int> ans(n);
x--;
y--;
DijikstraWithQueue(ans, graph, x, n);
if(ans[y] == INF)
cout << "-1\n";
else
cout << ans[y] << '\n';
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// freopen("Debug.txt", "w", stderr);
#else
#endif
// cout << fixed << setprecision(10);
// int _t;
// cin>>_t;
// while(_t --)
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
typedef int_fast32_t int32;
typedef int_fast64_t int64;
const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;
#define YES(n) cout << ((n) ? "YES\n" : "NO\n" )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n" )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n" )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;
template<class T> inline bool chmax(T& a, T b) {
if (a < b) { a = b; return true; } return false;
}
template<class T> inline bool chmin(T& a, T b) {
if (a > b) { a = b; return true; } return false;
}
template<typename T>
struct SegmentTree{
typedef function<T(T,T)> F;
int n; //要素数
F f; //2項演算
T e; //単位元
vector<T> dat;
SegmentTree(int n_,F f,T e):f(f),e(e){
init(n_);
build();
}
SegmentTree(int n_,F f,T e,vector<T>& v):f(f),e(e){
init(n_);
build(n_,v);
}
void init(int n_){
n=1;
while(n<n_)n<<=1;
dat.clear();
dat.resize(n<<1, e);
}
void build(int n_,const vector<T>& v){
for(int i=0;i<n_;++i)dat[n+i]=v[i];
build();
}
void build(){
for(int i=n-1;i>=1;--i){
dat[i] = f(dat[i<<1],dat[i<<1|1]);
}
}
void update(int k,const T& x){
dat[k+=n]=x;
while(k>>=1){
dat[k] = f(dat[k<<1],dat[k<<1|1]);
}
}
T query(int a,int b){
T l=e,r=e;
for(a+=n,b+=n;a<b;a>>=1,b>>=1){
if(a&1)l=f(l,dat[a++]);
if(b&1)r=f(dat[--b],r);
}
return f(l,r);
}
T operator[](const int &k) const {
return dat[n+k];
}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int64 h,w,m;
cin >> h >> w >> m;
vector<vector<int64>> ys(w),xs(h);
REP(i,m){
int64 y,x;
cin >> y >> x;
--y;--x;
// chmin(ys[x],y);
// chmin(xs[y],x);
ys[x].emplace_back(y);
xs[y].emplace_back(x);
}
REP(i,w){
ys[i].emplace_back(h);
sort(all(ys[i]));
}
REP(j,h){
xs[j].emplace_back(w);
sort(all(xs[j]));
}
int64 ans = 0;
SegmentTree<int64> st(w+1,[](int64 a, int64 b){return a+b;},0);
REP(i,xs[0][0])st.update(i,1);
REP(y,h){
for(auto x : xs[y])
st.update(x,0);
if(y < ys[0][0]){
ans += xs[y][0];
ans += st.query(xs[y][0],w);
}else{
ans += st.query(0,w);
}
}
ANS(ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rng(x) x.begin(), x.end()
#define maxi(x, y) x = max(x, (y))
#define mini(x, y) x = min(x, (y))
#define pb push_back
#define F first
#define S second
#define el '\n'
#define int long long
#define SZ(x) ((int)(x).size())
template<typename T>
istream&operator>>(istream&is,vector<T>&v){for(auto&it:v)is>>it;return is;}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
return os << "(" << P.F << "," << P.S << ")"; }
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
os << "[ "; for(auto v : V) os << v << " "; return os << "]"; }
template<class T> ostream& operator<<(ostream &os, set<T> S){
os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}"; }
#ifndef ONLINE_JUDGE
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define db(...)
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr<<name<<" : "<<arg1<<'\n';}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(names,comma-names)<<" : "<<arg1<<" |";__f(comma+1, args...);}
typedef pair<int,int> pi; typedef vector<int> vi; typedef vector<vi> vvi;
/*-----------------------------Code Begins--------------------------------*/
class BIT{
public :
int n;
vi f;
BIT(int n){
this->n = n + 1000;
f.assign(n, 0);
}
int get(int pos){
int res = 0;
for (; pos >= 0; pos = (pos & (pos + 1)) - 1){
res += f[pos];
}
return res;
}
int get(int l, int r){
return get(r) - get(l - 1);
}
void increase(int pos, int val){
for (; pos < SZ(f); pos = (pos | (pos + 1))) {
f[pos] += val;
}
}
};
void solve(){
int n, m; cin>>n>>m;
vi up(m, n), left(n, m);
vi cols[n];
int b; cin>>b;
int l = m, d = n;
while(b--){
int i, j; cin>>i>>j;
i--, j--;
cols[i].pb(j);
mini(up[j], i);
mini(left[i], j);
if(i == 0){
mini(l, j);
}
if(j == 0){
mini(d, i);
}
}
int ans = 0;
for(int j = 0; j < l; ++j){
ans += up[j];
assert(up[j] > 0);
}
db(ans, d, l);
BIT bit(m);
for(int j = l; j < m; ++j){
bit.increase(j, 1);
}
for(int i = 0; i < d; ++i){
ans += bit.get(0, left[i] - 1);
for(int j : cols[i]){
if(bit.get(j, j)){
continue;
}
db(j);
bit.increase(j, 1);
}
}
cout<<ans<<el;
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int T = 1;
// cin>>T;
while(T--){
solve();
}
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define prime 998244353
#define watch(x) cout << (#x) << " = " << (x) << "\n"
#define printArray(arr,n) for(int i=0;i<n;i++) cout << (#arr) << "[" << i << "]" << " = " << (arr[i]) << "\n"
#define printMatrix(arr,m,n) for(int i=0;i<m;i++) for(int j=0;j<n;j++) cout << (#arr) << "[" << i << "]" << "[" << j << "]" << " = " << (arr[i][j]) << "\n"
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T;
//cin>>T;
T=1;
while(T--){
//Code
ll a,b,c;
cin>>a>>b>>c;
ll ans = 1,A,B,C;
A = (a*(a+1))/2;
A%=prime;
B = (b*(b+1))/2;
B%=prime;
C = (c*(c+1))/2;
C%=prime;
ans = A*B;
ans%=prime;
ans*=C;
ans%=prime;
cout<<ans<<"\n";
}
return 0;
}
| /*** "Bismillahir Rahmanir Raheem" ***/
/*** "ALHAMDULILLAH for Everything" ***/
/*** "Md. Al Asad Nur Riyad" ***/
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
*/
#include<bits/stdc++.h>
using namespace std;
#define fastt ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define debug printf("Come here!")
#define inf 1000000000000000000
#define mem(a,b) memset(a,b,sizeof(a))
#define case(x) cout << "Case " << x <<": "
#define all(qz) qz.begin(),qz.end()
#define rall(qz) qz.rbegin(),qz.rend()
#define Sqr(x) ((x) * (x))
#define mod 998244353
#define pi acos(-1.0)
#define cos(a) cos(a*pi/180)
#define sin(a) sin(a*pi/180)
#define tan(a) tan(a*pi/180)
#define cosi(a) acos(a)/(pi/180)
#define sini(a) asin(a)/(pi/180)
#define tani(a) atan(a)/(pi/180)
#define pql priority_queue<ll>
#define minpql priority_queue<ll,vector<ll>,greater<ll> >
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll Pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}
/** Functions Start **//*
TP inline F setBit(F mask, S pos) { return mask |= ((F)1 << pos) ; }
TP inline bool getBit(F mask, S pos) { return (bool)(mask & ((F)1 << pos)) ; }
TP inline F resetBit(F mask, S pos) { return mask &= (~((F)1 << pos)) ; }
TP inline F toggleBit(F mask, S pos){ return mask ^= ((F)1 << pos) ; }
*/
ll egcd(ll a,ll b,ll &x,ll &y){if(b==0){x=1;y=0;return a;}ll x1,y1;ll gcd=egcd(b,a%b,x1,y1);x=y1;y=x1-y1*(a/b);return gcd;}
ll bigMod(ll a,ll b){a%=mod;ll res=1;while(b>0){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
inline ll MOD(ll a){ return (a%mod + mod) %mod ; }
inline ll modAdd(ll a,ll b){ return MOD( MOD(a) + MOD(b) ) ; }
inline ll modSub(ll a,ll b){ return MOD( MOD(a) - MOD(b) ) ; }
inline ll modMul(ll a,ll b){ return MOD( MOD(a) * MOD(b) ) ; }
inline ll modInv(ll a){ return bigMod(a,mod-2) ; }
/** Functions End **/
/** Direction Array **//*
int dx[]={-1, 0, 0, 1};
int dy[]={0, -1, 1, 0};
int dx1[]={-1, -1, -1, 0, 0, 0, 1, 1, 1};
int dy1[]={-1, 0, 1, -1, 0, 1, -1, 0, 1};
/** Direction Array ends **/
/* mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/
/*-----------------------------------------------------*/
int main()
{
fastt
ll a,b,c;
cin>>a>>b>>c;
a=(a*(a+1))/2;
b=(b*(b+1))/2;
c=(c*(c+1))/2;
cout<<modMul(a,modMul(b,c))<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using Int = long long;
const Int INF=1e18;
int main(){
int n,m;cin>>n>>m;
map<int,pair<int,int>>list;
rep(i,n){
int x;cin>>x;
list[x]=make_pair(1,0);
}
rep(i,m){
int x;cin>>x;
pair<int,int>y=make_pair(1,0);
if(!list.count(x)){
list[x]=make_pair(0,1);
}
else if(list[x]==y){
list[x].second=1;
}
}
pair<int,int>a,b;
a=make_pair(1,0);
b=make_pair(0,1);
for(auto L:list){
if(L.second==a||L.second==b){
cout<<L.first<<" ";
}
}
return 0;
}
| #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stdio.h>
#include<deque>
#include<map>
#include<queue>
#include<cmath>
typedef long long ll;
#define debug(x) cout << #x << '=' << x << endl;
#define debug_arr(a, n) for(ll i = 0; i < n; i++)cout << a[i] << ' '
#define inf 100000000000
#define loop(i,n) for(ll i = 0; i < n; i++)
#define graph vector<vector<ll>>
#define P pair<ll,ll>
using namespace std;
int main(){
ll h,w;
cin >> h >> w;
vector<vector<int>> s(h);
loop(i,h){
loop(j,w){
char c;
cin >> c;
if(c == '#') {
s[i].push_back(1);
}else{
s[i].push_back(0);
}
}
}
ll ans = 0;
loop(i, h - 1){
loop(j, w - 1){
int tmp = s[i][j] + s[i + 1][j] + s[i][j + 1] + s[i + 1][j + 1];
if(tmp == 1 || tmp == 3) ans++;
}
}
cout << ans << endl;
} |
#define TO_BE_SUBMITTED
#include <bits/stdc++.h>
// #include <atcoder/fenwicktree>
// #include <atcoder/segtree>
// #include <atcoder/lazysegtree>
// #include <atcoder/string>
// #include <atcoder/math>
// #include <atcoder/convolution>
// #include <atcoder/modint>
// #include <atcoder/dsu>
// #include <atcoder/maxflow>
// #include <atcoder/mincostflow>
// #include <atcoder/scc>
// #include <atcoder/twosat>
namespace atcoder{};
using namespace atcoder;
using namespace std;
#define fr first
#define sc second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (n); i >= 1; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vlp = vector<LP>;
inline int getInt()
{
int x;
scanf("%d", &x);
return x;
}
template <class T>
bool chmax(T &a, const T &b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T &b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
ll N;
vl T, L, R;
vl Xs;
vl x2LNum, x2ExclusiveLNum, x2RNum, x2ExclusiveRNum;
void solve()
{
cin >> N;
rep(i, N){
ll t, l, r;
cin >> t >> l >> r;
T.pb(t);
L.pb(l);
R.pb(r);
Xs.pb(l);
Xs.pb(r);
}
N = sz(L);
sort(rng(Xs));
uni(Xs);
x2LNum = vl(sz(Xs), 0);
x2ExclusiveLNum = vl(sz(Xs), 0);
x2RNum = vl(sz(Xs), 0);
x2ExclusiveRNum = vl(sz(Xs), 0);
rep(i, N){
L[i] = lower_bound(rng(Xs), L[i]) - Xs.begin();
R[i] = lower_bound(rng(Xs), R[i]) - Xs.begin();
if(T[i] == 1LL){
x2LNum[L[i]]++;
x2RNum[R[i]]++;
}
if(T[i] == 2LL){
x2LNum[L[i]]++;
x2ExclusiveRNum[R[i]]++;
}
if(T[i] == 3LL){
x2ExclusiveLNum[L[i]]++;
x2RNum[R[i]]++;
}
if(T[i] == 4LL){
x2ExclusiveLNum[L[i]]++;
x2ExclusiveRNum[R[i]]++;
}
}
ll cnt = 0;
ll ans = 0;
rep(x, sz(Xs)){
cnt -= x2ExclusiveRNum[x];
rep(_, x2LNum[x]){
ans += cnt;
cnt++;
}
cnt -= x2RNum[x];
rep(_, x2ExclusiveLNum[x]){
ans += cnt;
cnt++;
}
}
cout << ans << "\n";
}
int main()
{
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
solve();
return 0;
} | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn=2000;
int N;
struct Segment{
int t,l,r;
Segment(int at,int al,int ar):t(at),l(al),r(ar){}
};
vector<Segment>segs;
bool comp(Segment a,Segment b){
if(a.l!=b.l){
return a.l<b.l;
}else{
return a.r<b.r;
}
}
long total;
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
while(cin>>N){
segs.clear();
int ct,cl,cr;
for(int i=0;i<N;i++){
cin>>ct>>cl>>cr;
segs.push_back(Segment(ct,cl,cr));
}
sort(segs.begin(),segs.end(),comp);//The left endpoint is sorted
total=0;
for(int i=0;i<N;i++){
for(int j=i+1;j<N;j++){
if(segs[i].r>segs[j].l){//The segment intersects
total++;
}else if(segs[i].r==segs[j].l){//The endpoint is on the same place
//t=1 = []
//t=2 = [)
//t=3 = (]
//t=4 = ()
//1,3 = both ]
//1,2 = both [
if(segs[i].t%2==1 && segs[j].t<=2){//The intersecting endpoints are both included
total++;
}else{
continue;
}
}else{//if segs[i].r < segs[j].l, then i++
break;
}
}
}
//Finished checking segments
cout<<total<<'\n';
}
} |
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;
const ld pi = acosl(-1.0);
ll mod_pow(ll x, ll n, ll m = mod) {
if (n < 0) {
ll res = mod_pow(x, -n, m);
return mod_pow(res, m - 2, m);
}
if (abs(x) >= m)x %= m;
if (x < 0)x += m;
ll res = 1;
while (n) {
if (n & 1)res = res * x % m;
x = x * x % m; n >>= 1;
}
return res;
}
struct modint {
ll n;
modint() :n(0) { ; }
modint(ll m) :n(m) {
if (n >= mod)n %= mod;
else if (n < 0)n = (n % mod + mod) % mod;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
if (n == 0)return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 <<23;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[a - b];
}
void solve() {
int n, m, k; cin >> n >> m >> k;
if (n > m + k) {
cout << 0 << "\n";
return;
}
modint ans = comb(n + m, n);
ans -= comb(n+m, n-k-1);
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(10);
init_f();
//init(); cout << ps.size() << "\n";
//expr();
//int t; cin >> t; rep(i, t)
solve();
return 0;
}
| #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <fstream>
#include <map>
#include <set>
#include <queue>
#include <memory.h>
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> PI;
typedef vector<PI> VPI;
#define FOR(i,a,n) for (int i = (a); i < (n); ++i)
#define FORE(i,a,n) for (int i = (a); i <= (n); ++i)
#define FORD(i,a,b) for (int i = (a); i >= (b); --i)
#define REP(i,n) FOR(i,0,n)
#define REPE(i,n) FORE(i,0,n)
#define LL long long
#define FIR(n) REP(i,n)
#define FJR(n) REP(j,n)
#define ALL(v) v.begin(), v.end()
#define FI FIR(n)
#define FJ FJR(n)
#define FR(i,a) FOR(i,a,n)
#define REPN(i) REP(i,n)
#define GI(n) scanf("%d", &n)
#define GI2(n,m) scanf("%d %d", &n, &m)
LL a[300500];
int main() {
#ifdef LOCALF
freopen("input.txt", "rt", stdin);
#endif
ios::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
int v;
LL s = 0;
FI{
cin >> v; a[i] = v;
s += v;
}
LL res = 0;
FI res += (n-1)*a[i] * a[i];
FI res -= a[i] * (s - a[i]);
cout << res << endl;
}
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e2+8, inf = 1e18+9, mod = 998244353;
int n, k, a[maxn][maxn], fac[maxn], fa[maxn], sz[maxn];
int find(int u) { return u == fa[u] ? u : fa[u] = find(fa[u]); }
void solve() {
int i, j, x, y, ans = 1;
cin >> n >> k;
for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) cin >> a[i][j];
for (fac[1] = 1, i = 2; i <= n; i++) fac[i] = (fac[i - 1] * i) % mod;
for (i = 1; i <= n; i++) fa[i] = i, sz[i] = 1;
for (i = 1; i <= n; i++) for (j = i + 1; j <= n; j++) {
int ok = 1;
for (x = 1; x <= n; x++) if (a[i][x] + a[j][x] > k) { ok = 0; break; }
if (ok) {
int fi = find(i), fj = find(j);
if (fi != fj) { fa[fi] = fa[fj]; sz[fj] += sz[fi]; }
}
}
for (i = 1; i <= n; i++) if (fa[i] == i) ans = (ans * fac[sz[i]]) % mod;
for (i = 1; i <= n; i++) fa[i] = i, sz[i] = 1;
for (i = 1; i <= n; i++) for (j = i + 1; j <= n; j++) {
int ok = 1;
for (x = 1; x <= n; x++) if (a[x][i] + a[x][j] > k) { ok = 0; break; }
if (ok) {
int fi = find(i), fj = find(j);
if (fi != fj) { fa[fi] = fa[fj]; sz[fj] += sz[fi]; }
}
}
for (i = 1; i <= n; i++) if (fa[i] == i) ans = (ans * fac[sz[i]]) % mod;
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); //cout << fixed << setprecision(15);
int t = 1; //cin >> t;
while (t--) solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const long long MOD=998244353;
int N, K;
long long modmypower(long long a, long long b){
if(b==1){
return a;
}else if(b%2==0){
long long c=modmypower(a,b/2);
return (c*c)%MOD;
}else{
long long c=modmypower(a,(b-1)/2);
return (((c*c)%MOD)*a)%MOD;
}
}
long long modfactorial(long long x){
if(x<=1) x=1;
else for(int i=x-1; i>0; i--) x=((x*i)%MOD);
return x;
}
long long modinv(long long x){
return modmypower(x,MOD-2);
}
long long fn(vector<vector<int>>& mat){
// 交換できる行のグラフをつくる
vector<vector<int>> g(N, vector<int>());
for(int i=0; i<N-1; i++){
for(int j=i+1; j<N; j++){
bool c=true;
for(int k=0; k<N; k++) if(mat[i][k]+mat[j][k]>K) c=false;
if(c){
g[i].push_back(j);
g[j].push_back(i);
}
}
}
long long result=1;
//連結成分ごとに見る
vector<int> visited(N, 0);
for(int i=0; i<N; i++){
//連結成分を抽出
if(visited[i]==1) continue;
visited[i]=1;
queue<int> q;
q.emplace(i);
vector<int> group;
group.push_back(i);
while(!q.empty()){
int a=q.front();
q.pop();
for(auto dest:g[a]){
if(visited[dest]==1) continue;
visited[dest]=1;
q.emplace(dest);
group.push_back(dest);
}
}
//ベクトルが一致するかどうか
int s=group.size();
vector<int> d(s, 0);
for(int j=0; j<s; j++){
for(int k=0; k<s; k++){
if(mat[j]==mat[k]) d[j]++;
}
}
map<int, int> dlist;
for(int j=0; j<s; j++) dlist[d[j]]++;
long long tmp=modfactorial(s);
for(auto kv: dlist){
int k=kv.first;
int v=kv.second/k;
if(k==1) continue;
tmp=(tmp*modinv(modfactorial(v)))%MOD;
}
result=(result*tmp)%MOD;
}
return result;
}
int main(){
cin >> N >> K;
vector<vector<int>> A(N, vector<int>(N));
for(int i=0; i<N*N; i++) cin >> A[i/N][i%N];
long long result=fn(A);
vector<vector<int>> B(N, vector<int>(N));
for(int i=0; i<N*N; i++) B[i/N][i%N]=A[i%N][i/N];
result*=fn(B);
cout << result%MOD << endl;
} |
#include<bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
long long f(long long x)
{
return x * (x+1)/2 % MOD;
}
void solve()
{
long long a,b,c;
cin >> a >> b >> c;
cout << ((f(a) * f(b))%MOD * f(c))%MOD;
}
int main()
{
int t=1;
//cin >> t;
while (t--) solve();
}
/*
1
6
1 2 6 5 3 4
*/
| #include <bits/stdc++.h>
using namespace std;
long long a, b, c;
int main() {
cin >> a >> b >> c;
if (a * a + b * b < c * c) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define Mod 998244353
#define MOD 1000000007
using namespace std;
using lint = long long;
using vi = vector<lint>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<lint, lint>;
lint zero = 0;
lint modpow(lint a, lint n, lint m = Mod){
lint ans = 1;
while(n>0){
if(n%2==1) ans *= a;
ans %= m; a *= a; a %= m; n /= 2;
}
return ans;
}
lint inv(lint a, lint m = Mod){
return modpow(a, m-2, m);
}
lint gcd(lint a, lint b){
if (a%b == 0) return(b);
else return(gcd(b, a%b));
}
vi soinsu(lint n){
vi primes(0); // 素因数
vi nums(0); // 指数
vector<bool> nonzero(n, false);
lint p=2; lint m = n;
while(p*p<=n){
while(m%p==0){
if(nonzero[p]){ nums[nums.size()-1]++; m /= p;}
else{nonzero[p]=true; primes.PB(p); nums.PB(1); m /= p;}
}
p++;
}
if(m>1){primes.PB(m); nums.PB(1);}
return nums; // 適宜必要なものを取り出す
}
// cout << fixed << setprecision(12);
//////////////////////
////////////////////
int main(){
lint n; cin>>n;
vi acnt(n,0);
for(lint i=0; i<n; i++){
lint a; cin>>a; a--;
acnt[a]++;
}
vi bs(n);
vi bcnt(n,0);
for(lint i=0; i<n; i++){
cin>>bs[i]; bs[i]--;
}
for(lint i=0; i<n; i++){
lint c; cin>>c; c--;
bcnt[bs[c]]++;
}
lint ans = 0;
for(lint i=0; i<n; i++){
ans += acnt[i]*bcnt[i];
}
cout << ans << endl;
}
| #include "bits/stdc++.h"
using namespace std;
#define int long long
#define forn(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define sz(x) ((int) (x).size())
#define dbg(x) cerr << #x << "->" << x << "\n";
int gcd(int a, int b) {if (b == 0) return a; return gcd(b, a % b);}
int mod = (int)1e9 + 7;
void solve() {
int n; cin >> n;
vector<int> a(n), b(n), c(n);
forn(i, n)cin >> a[i];
forn(i, n)cin >> b[i];
forn(i, n)cin >> c[i];
vector<int> bc;
forn(i, n) {
bc.pb(b[c[i] - 1]);
}
map<int, int> ma, mb;
forn(i, n) ma[a[i]]++;
forn(i, sz(bc)) mb[bc[i]]++;
int ans = 0;
for (auto i : ma) {
ans += i.second * mb[i.first];
}
cout << ans;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
// cin >> t;
forn(i, t)
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef std::vector<bool> vb;
typedef std::vector<std::vector<bool>> vvb;
typedef std::vector<string> vstr;
typedef std::pair<long long, long long> pll;
#define INF 1999999999
#define INFLL std::numeric_limits<long long>::max()
#define MODA 1000000007
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define rep1(i,n) for (long long i = 1; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define errv1(x) cerr << #x <<" "<< x << endl;
#define errv2(x, y) cerr << #x <<" "<< x <<" "<< #y <<" "<< y << endl;
#define errv3(x, y, z) cerr << #x <<":"<< x <<" "<< #y <<":"<< y <<" "<< #z <<":"<< z << endl;
#define errv4(x, y, z, a) cerr << #x <<":"<< x <<" "<< #y <<":"<< y <<" "<< #z <<":"<< z <<" "<< #a <<":"<< a << endl;
int main() {
ll H, W;
cin >> H >> W;
vvll A(H, vll(W));
rep(i,H){
rep(j,W){
cin >> A[i][j];
}
}
ll mini = INFLL;
rep(i,H){
rep(j,W){
mini = min(mini, A[i][j]);
}
}
ll ans =0;
rep(i,H){
rep(j,W){
ans += A[i][j] - mini;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
inline long long read(){
long long s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9'){
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9'){
s = s * 10 + ch - '0';
ch = getchar();
}
return s * w;
}
long long n, ans, a, b;
int main(){
n = read();
for (int i = 1; i <= n; i++)
a = read(), b = read(), ans += ((a+b) * (b-a+1) / 2);
printf("%lld\n", ans);
return 0;
} |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))
typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;
pll operator+(pll a,pll b){
return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
a=abs(a);
b=abs(b);
if(a==0)return b;
if(b==0)return a;
if(a < b) return gcd(b, a);
ll r;
while ((r=a%b)) {
a = b;
b = r;
}
return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
if(a<b){
a=b;
return true;
}
return false;
}
template<class T>
bool chmin(T& a,const T& b){
if(a>b){
a=b;
return true;
}
return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
os << "(" << a.first << "," << a.second << ")";
return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
os << "[ ";
REP(a.size()){
os<< a[i] << " ";
}
os<< " ]";
return os;
}
void solve(long long N, std::vector<long long> a, std::vector<long long> b, std::vector<long long> p){
REP(N){
if(i!=p[i]&&a[i]<=b[p[i]]){
cout<<-1<<endl;
return;
}
}
auto cmp=[&](ll x,ll y){
if(b[p[x]]>b[p[y]]){
return true;
}else if(b[p[x]]<b[p[y]]){
return false;
}else{
return p[x]>p[y];
}
};
set<ll,decltype(cmp)> notyet(cmp);
REP(N){
if(i!=p[i]){
if(i==12660)dump(i);
notyet.insert(i);
if(notyet.count(i)==0)abort();
}
}
vector<pll> ans;
while(!notyet.empty()){
ll cur1=*(notyet.begin());notyet.erase(cur1);
if(cur1==12660)dump(cur1);
ll cur2=p[cur1];
if(cur2==12660)dump(cur2);
if(notyet.count(cur2)==0)abort();
notyet.erase(cur2);
ans.push_back(pll(cur1,cur2));
swap(p[cur1],p[cur2]);
if(cur2!=p[cur2])abort();
if(p[cur1]!=cur1){
if(cur1==12660)dump(cur1);
notyet.insert(cur1);
}
}
REP(N){
if(p[i]!=i)abort();
}
cout<<ans.size()<<endl;
REP(ans.size()){
cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl;
}
}
int main(){
cout<<setprecision(1000);
long long N;
scanf("%lld",&N);
std::vector<long long> a(N);
for(int i = 0 ; i < N ; i++){
scanf("%lld",&a[i]);
}
std::vector<long long> b(N);
for(int i = 0 ; i < N ; i++){
scanf("%lld",&b[i]);
}
std::vector<long long> p(N);
for(int i = 0 ; i < N ; i++){
scanf("%lld",&p[i]);
--p[i];
}
solve(N, std::move(a), std::move(b), std::move(p));
return 0;
}
| #include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,b,a) for(int i=b;i>=a;i--)
#define efo(i,u,v) for(int i=BB[u],v=B[BB[u]][1];i;v=B[i=B[i][0]][1])
#define mset(a,x) memset(a,x,sizeof(a))
template<typename T> bool chkmin(T &a,const T &b) {return b<a?a=b,1:0;}
template<typename T> bool chkmax(T &a,const T &b) {return b>a?a=b,1:0;}
using namespace std;
typedef long long ll;
typedef double db;
char ch;
int read(){int n=0,p=1;for(ch=getchar();ch<'0' || '9'<ch;ch=getchar())if(ch=='-') p=-1;for(;'0'<=ch && ch<='9';ch=getchar()) n=n*10+ch-'0';return n*p;}
int main()
{
//freopen("a.in","r",stdin);
int a,b,x,y;
a=read(),b=read(),x=read(),y=read();
y=min(y,x+x);
int t=a>b?a-b-1:b-a;
printf("%d\n",t*y+x);
return 0;
}
|
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
inline int read(){
int res=0;
bool zf=0;
char c;
while(((c=getchar())<'0'||c>'9')&&c!='-');
if(c=='-')zf=1;
else res=c-'0';
while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
if(zf)return -res;
return res;
}
const int maxn=2e5+5,P=998244353;
int f[maxn],g[maxn];
int p[maxn],r;
int v[maxn],inv[25];
signed main(){
int n=read(),m=read(),ans=1;
inv[1]=1;
for(register int i=2;i<=20;++i){
inv[i]=1ll*inv[P%i]*(P-P/i)%P;
}
for(register int i=2,t;i<=m;++i){
if(!v[i]){
f[i]=n,g[i]=1,p[++r]=i;
}
for(register int j=1;j<=r&&(t=i*p[j])<=m;++j){
v[t]=1;
if(i%p[j]){
f[t]=1ll*f[i]*n%P,g[t]=1;
}
else{
f[t]=1ll*f[i]*(n+g[i])%P*inv[g[i]+1]%P,g[t]=g[i]+1;
break;
}
}
ans+=f[i];
(ans>=P)&&(ans-=P);
}
printf("%d\n",ans);
return 0;
} | #include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#include <cassert>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 998244353;
const ll INF = (1ll << 60);
template <typename T>
bool chmax(T &a, const T &b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
class eratosthenes_sieve
{
private:
int n;
vector<int> f;
public:
vector<int> primes;
eratosthenes_sieve(int n) : f(n + 1)
{
f[0] = f[1] = -1;
for (ll i = 2; i <= n; i++)
{
if (!f[i])
{
f[i] = i;
primes.emplace_back(i);
for (ll j = i * i; j <= n; j += i)
{
if (!f[j])
{
f[j] = i;
}
}
}
}
}
map<ll, ll> prime_factor(int x)
{
map<ll, ll> res;
while (x != 1)
{
res[f[x]]++;
x /= f[x];
}
return res;
}
};
class factorial
{
private:
vector<ll> fac, finv, inv;
public:
factorial(ll n) : fac(2, 1), finv(2, 1), inv(2, 1)
{
for (ll i = 2; i <= n; i++)
{
fac.push_back(fac[i - 1] * i % MOD);
inv.push_back(MOD - inv[MOD % i] * (MOD / i) % MOD);
finv.push_back(finv[i - 1] * inv[i] % MOD);
}
}
ll comb(ll n, ll k)
{
if (n < k || n < 0 || k < 0)
{
return 0;
}
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll perm(ll n, ll k)
{
if (n < k || n < 0 || k < 0)
{
return 0;
}
return fac[n] * finv[n - k] % MOD;
}
};
int main(void)
{
ll n, m;
cin >> n >> m;
eratosthenes_sieve e(m);
factorial f(400000);
ll ans = 0;
for (ll i = 1; i <= m; i++)
{
ll tmp = 1;
for (auto &&j : e.prime_factor(i))
{
tmp *= f.comb(n - 1 + j.second, n - 1) % MOD;
tmp %= MOD;
}
ans += tmp % MOD;
ans %= MOD;
}
cout << ans << endl;
} |
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll>
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++)
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
ll x, y, z;
cin>>x>>y>>z;
if(y%x==0)
{
cout<<((y/x)*z)-1<<endl;
}
else
{
ll low=0, high=(ll)1e8;
double eps=1.0/1e6;
ll ans=0;
ll count=0;
while(count++<=100)
{
ll mid=low+(high-low)/2;
double hump=(1.0*mid)/z;
double bump=(1.0*y)/x;
if(bump-hump>eps)
{
ans=mid;
low=mid;
}
else
{
high=mid;
}
}
cout<<ans<<endl;
}
}
int main()
{
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll test=1;
//cin>>test;
while(test--)
{
solve();
}
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
} | #line 1 "A.cpp"
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;
#if defined(DONLINE_JUDGE)
#define NDEBUG
#elif defined(ONLINE_JUDGE)
#define NDEBUG
#endif
template<typename T> std::vector<T> make_v(size_t a){return std::vector<T>(a);}
template<typename T, typename... Ts> auto make_v(size_t a, Ts... ts){
return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
int main() {
int x, y, z; scanf("%d%d%d", &x, &y, &z);
for(int i = 1e6; i >= 0; i--) {
if(y * z <= x * i) continue;
printf("%d\n", i);
return 0;
}
#ifndef NDEBUG
cout << "test" << endl;
#endif
return 0;
}
|
#pragma GCC optimize("Ofast")
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define mod (int)(1e9+7)
#define mod2 998244353
#define flush fflush(stdout);
#define PI 3.1415926535897932384626433832795
void solve() {
int n; cin>>n;
int a[n],b[n];
for(auto &it:a)
cin>>it;
for(auto &it:b)
cin>>it;
map<int,int> m;
for(int i=0;i<n;i++){
for(int j=min(a[i],b[i]);j<=max(a[i],b[i]);j++)
m[j]++;
}
int ans=0;
for(auto &it:m){
if(it.second==n)ans++;
}
cout<<ans;
}
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = 0; i <= (n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
struct UnionFind {
vector<int> d;
UnionFind(int n=0): d(n,-1) {}
int find(int x) {
if (d[x] < 0) return x;
return d[x] = find(d[x]);
}
bool unite(int x, int y) {
x = find(x); y = find(y);
if (x == y) return false;
if (d[x] > d[y]) swap(x,y);
d[x] += d[y];
d[y] = x;
return true;
}
bool same(int x, int y) { return find(x) == find(y);}
int size(int x) { return -d[find(x)];}
};
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i,n) cin >> a[i];
if (n <= 1) {
cout << 0 << endl;
return 0;
}
const int M = 200005;
UnionFind uf(M);
rep(i,n) uf.unite(a[i], a[n-1-i]);
int ans = 0;
rep(i,M) {
if (uf.find(i) != i) continue;
ans += uf.size(i) - 1;
}
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,sum=0;
cin>>n;
for(int i=1;i<n;i++)
sum++;
cout<<sum;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll n,x,ans,i;
set<ll>s;
cin>>n;
for(i=2;i*i<=n;i++)
{
x=i*i;
while(x<=n)
{
s.insert(x);
x=x*i;
}
}
ans=n-s.size();
cout<<ans<<endl;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 2e5+5;
ll bit[N], row[N], col[N];
vector<ll> tt[N];
void update(int pos, int val){
while(pos < N){
bit[pos] += val;
pos += pos&-pos;
}
}
int query(int pos){
int res = 0;
while(pos){
res += bit[pos];
pos -= pos&-pos;
}
return res;
}
signed main(){
fastio
ll h,w,m;
cin >> h >> w >> m;
fill(row,row+N,w);
fill(col,col+N,h);
while(m--){
ll x,y;
cin >> x >> y;
x--,y--;
row[x] = min(row[x],y);
col[y] = min(col[y],x);
tt[y].push_back(x);
}
ll ans = 0;
for(ll i = 0;i < col[0];i++) ans += row[i];
ll ok[h];
fill(ok,ok+h,1);
for(ll i=col[0];i < h;i++) ok[i] = 0, update(i,1);
for(ll i = 0;i < row[0];i++){
for(ll j : tt[i]){
if(ok[j]) ok[j] = 0, update(j,1);
}
ans += query(col[i]-1);
}
cout << ans <<endl;;
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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;}
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
int f(int b,int r,int c){
return b*500*500+r*500+c;
}
int main(){
int R,C; cin >> R >> C;
vvi g(500*500*2);
vvi co(500*500*2);
rep(r,R) rep(c,C-1){
int in; cin >> in;
g[f(0,r,c)].pb(f(0,r,c+1));
g[f(0,r,c+1)].pb(f(0,r,c));
co[f(0,r,c)].pb(in);
co[f(0,r,c+1)].pb(in);
}
rep(r,R-1) rep(c,C){
int in; cin >> in;
g[f(0,r,c)].pb(f(0,r+1,c));
co[f(0,r,c)].pb(in);
}
rep(r,R-1) rep(c,C){
g[f(1,r+1,c)].pb(f(1,r,c));
co[f(1,r+1,c)].pb(1);
}
rep(r,R) rep(c,C){
g[f(0,r,c)].pb(f(1,r,c));
co[f(0,r,c)].pb(1);
g[f(1,r,c)].pb(f(0,r,c));
co[f(1,r,c)].pb(0);
}
vector<int> D(500*500*2, -1);
vector<bool> used(500*500*2, false);
priority_queue<pair<int,int>,
vector<pair<int,int>>,
greater<pair<int,int>>> q;
q.push({(int)0,f(0,0,0)});
while(!q.empty()){
int d = q.top().first; int to = q.top().second; q.pop();
if(used[to]) continue;
used[to] = true; D[to] = d;
rep(i,sz(g[to])){
int nxt=g[to][i];
if(D[nxt] != -1 && D[nxt] <= D[to] + co[to][i]) continue;
q.push({D[to] + co[to][i], nxt});
}
}
int ans = D[f(0,R-1,C-1)];
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())a
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
const int inf = 0x3f3f3f3f;
int mod = 1000000007;
bool remender(ll a , ll b){return a%b;}
void solve(){
int m , h;
cin>>m>>h;
cout<<(h % m != 0 ? "No\n" : "Yes\n");
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t;cin >> t;while(t--)
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
ll X, Y;
map<ll, ll> mp;
ll solve(ll y) {
if (mp.count(y) > 0) return mp[y];
if (y == 1) {
mp[y] = abs(X-y);
} else if (y%2 == 1) {
mp[y] = min(min(abs(X-y), solve((y+1)/2)+2), solve((y-1)/2)+2);
} else {
mp[y] = min(abs(X-y), solve(y/2)+1);
}
return mp[y];
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> X >> Y;
cout << solve(Y) << "\n";
} |
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#include <random>
typedef long double ld;
ll n;
vector<ll> x, y, r;
const ll LIM = 10000 - 1;
const int INF = 1000000000;
struct STATE {
vector<P> loc;
vector<P> area;
ll score;
};
ll calc_score(STATE &state){
ld score = 0;
rep(i,n){
ll R = state.area[i].first * state.area[i].second;
ld tmp = (ld)(min(r[i], R)) / (ld)(max(r[i], R));
score += (ld)1 - ((ld)1 - tmp) * ((ld)1 - tmp);
}
score *= (ld)(1000000000);
score = floor(score);
ll ret = score;
ret /= n;
return ret;
}
void isOverlapped(STATE &state, ll j, ll X, ll Y){
vector<P> now(4);
now[0] = P(y[j], x[j]);
now[1] = P(y[j], x[j] + X);
now[2] = P(y[j] + Y, x[j] + X);
now[3] = P(y[j] + Y, x[j]);
rep(i,n){
if(i == j) continue;
ll L = x[i];
ll R = x[i] + state.area[i].second;
ll U = y[i];
ll D = y[i] + state.area[i].first;
bool ok = true;
rep(k,4){
if(now[k].first < U) continue;
if(D < now[k].first) continue;
if(now[k].second < L) continue;
if(R < now[k].second) continue;
ok = false;
break;
}
if(x[j] <= L && R <= x[j] + X && !(D <= y[j]) && !(y[j] + Y <= U)) ok = false;
if(y[j] <= U && D <= y[j] + Y && !(R <= x[j]) && !(x[j] + X <= L)) ok = false;
if(!ok){
state.loc[i] = P(LIM, i);
state.area[i] = P(1, 1);
}
}
return;
}
void modify(STATE &state){
std::random_device rnd;
std:: mt19937 mt(rnd());
std::uniform_int_distribution<> randN(0,n-1);
int j = randN(mt);
std::uniform_int_distribution<> randH(1,r[j]);
ll h = randH(mt);
if(y[j] + h > LIM) return;
ll w = r[j] / h;
if(x[j] + w > LIM) return;
isOverlapped(state, j, w, h);
state.loc[j] = P(y[j], x[j]);
state.area[j] = P(h, w);
state.score = calc_score(state);
}
void init(STATE &state){
state.loc.resize(n);
state.area.resize(n);
rep(i,n){
state.loc[i] = P(LIM, i);
state.area[i] = P(1, 1);
}
state.score = calc_score(state);
}
void solve(){
std::random_device rnd;
std:: mt19937 mt(rnd());
std::uniform_int_distribution<> randINF(1,INF);
STATE state;
init(state);
const ld TL = 4.8;
const ld start_temp = 1000000000;
const ld end_temp = 10;
//int cnt = 0;
while(true){
//++cnt;
ld terminal = (ld)clock() / (ld)CLOCKS_PER_SEC;
if(terminal >= TL) break;
STATE new_state = state;
ll pre_score = state.score;
modify(new_state);
ll new_score = new_state.score;
ld temp = start_temp + (end_temp - start_temp) * terminal / TL;
ld prob = exp((new_score - pre_score) / temp);
if(prob > (randINF(mt) % INF)/(double)INF){
state = new_state;
}
}
rep(i,n){
ll y = state.loc[i].first;
ll x = state.loc[i].second;
ll dy = state.area[i].first;
ll dx = state.area[i].second;
cout << x << " " << y << " " << x+dx << " " << y+dy << endl;
}
//cout << cnt << endl;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
rep(i,n){
ll X, Y, R;
cin >> X >> Y >> R;
x.push_back(X);
y.push_back(Y);
r.push_back(R);
}
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
// template {{{
#define range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)
#define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
constexpr i32 mod = 1e9 + 7;
// constexpr i32 mod = 998244353;
constexpr i32 inf = 1001001001;
constexpr i64 infll = 1001001001001001001ll;
constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1};
constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;
template <typename T = i64> T input() { T x; cin >> x; return x; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}
void solve() {
int n = input();
vector< string > ans;
ans.emplace_back("AB");
range(i, 1, n) {
vector< string > na;
for (auto &a : ans) {
auto b = a;
na.emplace_back(a + b);
for (auto &c : b) {
if (c == 'A') c = 'B';
else c = 'A';
}
na.emplace_back(a + b);
}
na.emplace_back(string(ans[0].size(), 'A') + string(ans[0].size(), 'B'));
ans = na;
}
cout << ans.size() << endl;
for (auto &a : ans) cout << a << endl;
}
signed main() {
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
#define rrep(i, a, b) for (int i = (int)(b) - 1; (i) >= (int)(a); (i)--)
#define all(v) v.begin(), v.end()
typedef long long ll;
template <class T> using V = vector<T>;
template <class T> using VV = vector<V<T>>;
/* 提出時これをコメントアウトする */
// #define LOCAL true
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif
struct P{
int x, y, r, id;
P(int x=0, int y=0, int r=0, int id=0) : x(x), y(y), r(r), id(id) {}
bool operator <(const P& other) const {
return r < other.r;
}
};
struct S{
int a,b,c,d,id;
S(int a=0, int b=0, int c=0, int d=0, int id=0) :a(a),b(b),c(c),d(d),id(id) {}
};
struct Point {
int x, y;
Point(int x=0, int y=0) : x(x),y(y) {}
bool operator <(const Point& other) const {
if (y != other.y) return y < other.y;
return x < other.x;
}
};
auto solve (int n, V<P>& v) -> V<S> {
// 面積が小さいほうから見る
sort(all(v));
V<S> ret(n);
set<Point> st;
// version 1: (x,y), (x+1,y+1)
rep(i,0,n) {
ret[i] = S(v[i].x,v[i].y,v[i].x+1,v[i].y+1,v[i].id);
st.insert(Point(v[i].x,v[i].y));
}
// version 2: 横だけに伸ばす
// => cをできるだけ大きくする
rep(i,0,n) {
int c = ret[i].c;
int d = ret[i].d;
while (!st.count(Point(c,d-1)) && c < 10000) {
if (c - ret[i].a >= v[ret[i].id].r) break;
c++;
}
ret[i].c = c;
}
return ret;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
constexpr char endl = '\n';
// input
int n;
cin >> n;
V<P> v(n);
rep(i,0,n) {
cin >> v[i].x >> v[i].y >> v[i].r;
v[i].id = i;
}
// solve
auto ans = solve(n, v);
// output
V<int> a(n),b(n),c(n),d(n);
rep(i,0,n) {
a[ans[i].id] = ans[i].a;
b[ans[i].id] = ans[i].b;
c[ans[i].id] = ans[i].c;
d[ans[i].id] = ans[i].d;
}
rep(i,0,n) {
cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
int n; cin >> n; int x[n], y[n], r[n];
REP(i, n){ cin >> x[i] >> y[i] >> r[i]; }
vector<int> X, Y; unordered_map<int, int> kshtX, kshtY;
REP(i, n){
if(!kshtX[x[i]]){ X.push_back(x[i]); kshtX[x[i]]++; }
if(!kshtY[y[i]]){ Y.push_back(y[i]); kshtY[y[i]]++; }
}
sort(X.begin(), X.end()); sort(Y.begin(), Y.end());
int xl=X.size(), yl=Y.size();
map<int, vector< pair<int, int> > > onX, onY;
REP(i, n){ onX[x[i]].push_back(make_pair(y[i], i)); onY[y[i]].push_back(make_pair(x[i], i)); }
REP(i, n){ sort(onX[x[i]].begin(), onX[x[i]].end()); sort(onY[y[i]].begin(), onY[y[i]].end()); }
const int cs=2;
int a[cs][n], b[cs][n], c[cs][n], d[cs][n];
REP(k, cs){ REP(i, n){ a[k][i]=x[i]; b[k][i]=y[i]; c[k][i]=x[i]+1; d[k][i]=y[i]+1; } }
int mae=0;
REP(i, xl){
mae=0;
REP(j, onX[X[i]].size()){
int e=0, v=onX[X[i]][j].second;
b[0][v]=max(d[0][v]-r[v], mae);
if(j==(int)onX[X[i]].size()-1){ e=10000; }else{ e=b[0][onX[X[i]][j+1].second]; }
d[0][v]=min(b[0][v]+r[v], e); mae=d[0][v];
}
}
mae=0;
REP(i, xl){
int sub=0;
REP(j, onX[X[i]].size()){
int e=0, v=onX[X[i]][j].second, h=d[0][v]-b[0][v], w=r[v]/h;
a[0][v]=max(c[0][v]-w, mae);
if(i==xl-1){ e=10000; }else{ e=X[i+1]; }
c[0][v]=min(a[0][v]+w, e); sub=max(sub, c[0][v]);
}
mae=max(mae, sub);
}
REP(i, yl){
mae=0;
REP(j, onY[Y[i]].size()){
int e=0, v=onY[Y[i]][j].second;
a[1][v]=max(c[1][v]-r[v], mae);
if(j==(int)onY[Y[i]].size()-1){ e=10000; }else{ e=a[1][onY[Y[i]][j+1].second]; }
c[1][v]=min(a[1][v]+r[v], e); mae=c[1][v];
}
}
mae=0;
REP(i, yl){
int sub=0;
REP(j, onY[Y[i]].size()){
int e=0, v=onY[Y[i]][j].second, w=c[1][v]-a[1][v], h=r[v]/w;
b[1][v]=max(d[1][v]-h, mae);
if(i==yl-1){ e=10000; }else{ e=Y[i+1]; }
d[1][v]=min(b[1][v]+h, e); sub=max(sub, d[1][v]);
}
mae=max(mae, sub);
}
int l=0, ans=0;
REP(k, cs){
long double s, t, p, q, sc=0;
REP(i, n){
s=(d[k][i]-b[k][i])*(c[k][i]-a[k][i]); t=r[i]; q=min(s, t)/max(s, t); p=1-(1-q)*(1-q);
sc+=(1e9*p)/n;
}
if(ans<round(sc)){ ans=round(sc); l=k; }
}
REP(i, n){ cout << a[l][i] << " " << b[l][i] << " " << c[l][i] << " " << d[l][i] << "\n"; }
} |
// omae wa mou shindeiru
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define float double
#define ll long long
#define int long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define all(v) v.begin(),v.end()
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define endl "\n"
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvl vector<vl>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define tr(it, l) for(auto it = l.begin(); it != l.end(); it++)
#define max(a, b) ((a < b) ? b : a)
#define min(a, b) ((a > b) ? b : a)
#define ps(x,y) fixed<<setprecision(y)<<x
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define PI 3.1415926535897932384626433832795
#define eps 1e-9
#define mod 1000000007
#define inf 1e18
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T, typename T1>T amax(T &a, T1 b) {if (b > a)a = b; return a;}
template<typename T, typename T1>T amin(T &a, T1 b) {if (b < a)a = b; return a;}
template<typename T>
using pbds = tree<T , null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>;
void runtime()
{
int n,q;
cin >> n >> q;
vi a(n+1);
rep(i,1,n+1)
cin >> a[i];
vi pre(n+1);
pre[1] = a[1] - 1;
for(int i=2;i<=n;i++)
{
pre[i] = pre[i-1] + (a[i]-a[i-1]-1);
}
while(q--)
{
int k;
cin >> k;
int p = lower_bound(all(pre),k) - pre.begin();
// cout << p << " ";
int s = k - pre[p-1];;
cout << a[p-1] + s<<endl;
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int TESTS = 1; // one input
// cin >> TESTS;
while (TESTS--) {
runtime();
cout << "\n";
}
return 0;
} | /*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define vi vector<ll>
#define pii pair<ll,ll>
#define bc __builtin_popcountll
#define vvi vector<vi>
#define vpii vector<pair<ll,ll>>
#define mll unordered_map<ll,ll>
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define fo(i,a,b) for(ll i=a;i<=b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define CASES ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()-->returns an iterator to the k-th largest element (counting from zero)
//X.order_of_key()-->the number of items in a set that are strictly smaller than our item.
struct cmp
{
bool operator() (ll a,ll b){
return (a>b);
}
};
ll ceil(const ll &a, const ll &b)
{
if(a%b == 0)
return a/b;
return a/b +1;
}
ll mod=1000000007;
const ll N=100005;
int main()
{
fast;
ll n,m;
cin>>n>>m;
char s[n][m];
f(i,n)
{
f(j,m)
{
cin>>s[i][j];
}
}
ll ans=0;
f(i,n)
{
f(j,m)
{
if(s[i][j]=='.')
{
if(j==m-1 && i==n-1)
{
continue;
}
else if(j==m-1)
{
if(s[i+1][j]=='.')
ans++;
}
else if(i==n-1)
{
if(s[i][j+1]=='.')
ans++;
}
else
{
if(s[i+1][j]=='.')
ans++;
if(s[i][j+1]=='.')
ans++;
}
}
}
}
cout<<ans;
return 0;
} |
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 100005;
const int inf = 1e9 + 5;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k) print the k-th smallest number in os(0-based)
int v, t, s, d;
int main()
{
ios::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
cin >> v >> t >> s >> d;
if(v * t > d || v * s < d)cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
/**
// probati bojenje sahovski ili slicno
**/
| #include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<=n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}
int main(void){
ll X,Y;
cin>>X>>Y;
if(ABS(X-Y)<3) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
} |
# include <bits/stdc++.h>
using namespace std;
# define endl "\n"
# define io_boost std::ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
typedef unsigned long long int ulli;
typedef long long int lli;
typedef unsigned int ui;
int N, K, m[805][805], bm[805][805], s[805][805];
int query(int a, int b, int c, int d){
int res = s[c][d];
if(a > 0) res -= s[a - 1][d];
if(b > 0) res -= s[c][b - 1];
if(a > 0 && b > 0) res += s[a - 1][b - 1];
return res;
}
int get_sum(int mid){
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
if(m[i][j] <= mid) bm[i][j] = 1;
else bm[i][j] = 0;
if(i == 0) s[i][j] = bm[i][j];
}
}
for(int i = 0; i < N; i++)
for(int j = 1; j < N; j++)
s[j][i] = s[j - 1][i] + bm[j][i];
for(int i = 1; i < N; i++)
for(int j = 0; j < N; j++)
s[j][i] += s[j][i - 1];
int maxi = 0;
for(int i = 0; i + K - 1 < N; i++)
for(int j = 0; j + K - 1 < N; j++){
//cout << query(i, j, i + K - 1, j + K - 1) << endl;
maxi = max(query(i, j, i + K - 1, j + K - 1), maxi);
}
return maxi;
}
int main(){
cin >> N >> K;
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
cin >> m[i][j];
get_sum(0);
int lo = 0, hi = 1e9 + 5;
while(lo < hi){
int mid = (lo + hi) / 2;
int sum = get_sum(mid);
//cout << mid << " " << sum << endl;
if(sum < (K * K + 1) / 2) lo = mid + 1;
else hi = mid;
}
cout << lo << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<ll>vec;
vector<ll>ans;
int main()
{
ll a,b,c,d,e,i,j,k,l,n,m,x,y,t,p;
cin>>n>>m;
if(m==0)
{
printf("1\n");
return 0;
}
x=n;
for(i=0;i<m;i++)
{
cin>>a;
vec.push_back(a);
}
sort(vec.begin(),vec.end());
if(vec[0]!=1)
{
ans.push_back(vec[0]-1);
x=min(x,vec[0]-1);
}
if(vec[m-1]!=n)
{
ans.push_back(n-vec[m-1]);
x=min(x,n-vec[m-1]);
}
for(i=1;i<m;i++)
{
a=vec[i]-vec[i-1];
a--;
if(a>0)
{
ans.push_back(a);
x=min(x,a);
}
}
l=ans.size();
y=0;
//cout<<x<<endl;
for(i=0;i<l;i++)
{
a=ans[i];
//cout<<"aa: "<<a<<endl;
c=a/x;
if(a%x!=0)
{
c++;
}
y+=c;
}
cout<<y<<endl;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int main() {
int N;
cin >> N;
if (N == 0) {
cout << "Yes\n";
return 0;
}
while (N % 10 == 0) N /= 10;
string S = to_string(N), ans = "Yes\n";
int l = S.size();
rep(i, l) if (S[i] != S[l - 1 - i]) ans = "No\n";
cout << ans;
} | #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
double const PI=3.141592653589793;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;
ll K;
int main(){
cin>>K;
ll ans=0;
repn(i,K){
repn(j,K/i){
ans+=K/(i*j);
}
}
cout<<ans<<endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define mod 1000000007
#define decimal(k) cout<<fixed<<setprecision(k)<<endl
#define LL_MAX LLONG_MAX
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
int gcd(int a, int b){if (b == 0)return a; return gcd(b, a % b);}
int Log2n( int n){ return (n > 1) ? 1 + Log2n(n / 2) : 0;}
int fac[100009];int ncr_mod(int n,int k){int ans=fac[n];ans*=modinv(fac[k]);ans%=mod;ans*=modinv(fac[n-k]);ans%=mod;return ans;}
vector<int>v_prime;void Sieve(int n){bool prime[n + 1];memset(prime,true,sizeof(prime));for (int p = 2; p*p <=n;p++){if(prime[p] ==true) {for(int i = p*p; i<= n; i += p)prime[i]=false;}}for(int p = 2;p<= n;p++)if (prime[p])v_prime.pb(p);}
vector<int>v_factor;void factors(int n){ for (int i=1; i<=sqrt(n); i++) {if (n%i == 0) {if (n/i == i) v_factor.pb(i);else { v_factor.pb(i),v_factor.pb(n/i);};} } sort(all(v_factor)); }
void out(vector<int>&a){for(int i=0;i<a.size();i++) cout<<a[i]<<" "; cout<<endl;}
// s.top().second;
signed main()
{
run;
/*
open for mod factorial
fac[0]=1;
for(int i=1;i<100009;i++)
{
fac[i]=fac[i-1]*i;
fac[i]%=mod;
}
*/
/*
for sieve open this and use v_prime
int pp=pow(10,6)+100000;
Sieve(pp);
*/
// USE v_factor For calculating factors
int t=1;
//cin>>t;
while(t--)
{
// vector< pair <int,int> > vp;
// map<int,int>mp; // x.second-->frequency
// set<int>st;
int n,i,x,y,ok=0,sum=0,ans=0,j,k,cnt=0,m,c=0;
int h[100009]={0};
cin>>n>>k;
if(k==0)
{
cout<<n<<endl;
return 0;
}
string s=to_string(n);
sort(all(s));
x=stoi(s);
//cout<<x<
reverse(all(s));
y=stoi(s);
vector<int>a(k+2,0);
for(i=1;i<=k;i++)
{
a[i]=y-x;
string s1=to_string(a[i]);
sort(all(s1));
x=stoi(s1);
reverse(all(s1));
y=stoi(s1);
}
cout<<a[k]<<endl;
}
} | #include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
//#define int long long
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PI = pair<pair<int,int>,int>;
using PL = pair<long long, long long>;
using PLL = pair<pair<long long, long long>, long long>;
using Pxy = pair<long double, long double>;
using Tiib = tuple<int, int, bool>;
const int INF = 1001001007;
const int modd = 1000000007;
const long long modl = 1000000007LL;
const long long mod = 998244353LL;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
rep(i,ar.size()-1) cout << ar[i] << " ";
cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
rep(i,ar.size()){
rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
cout << ar[i][ar[0].size()-1] << endl;
}
}
template <typename S>
bool range(S a, S b, S x){
return (a <= x && x < b);
}
void yes(){
cout << "Yes" << endl;
}
void no (){
cout << "No" << endl;
}
ll cel (ll a, ll b){
if (a % b == 0) return a / b;
else return a / b + 1;
}
ll gcds(ll a, ll b){
ll c = a % b;
while (c != 0){
a = b;
b = c;
c = a % b;
}
return b;
}
int main(){
int n; cin >> n;
ll w; cin >> w;
vector<vector<ll>> ar(n,vector<ll>(3));
rep(i,n) rep(j,3) cin >> ar[i][j];
vector<ll> imo(200010,0LL);
rep(i,n){
imo[ar[i][0]] += ar[i][2];
imo[ar[i][1]] -= ar[i][2];
}
bool t = true;
ll rui = 0LL;
rep(i,200010){
rui += imo[i];
if (rui > w) t = false;
}
if (t) yes();
else no();
} |
#include <iostream>
int main() {
int x, y, z;
std::cin >> x >> y;
if (x == y) z = x;
else z = 3 - x - y;
std::cout << z << std::endl;
return 0;
} | #include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#define ll long long
#define pb push_back
#define forn(i,x,n) for(int i=x;i<=n;++i)
#define forr(i,x,n) for(int i=n;i>=x;--i)
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;
const int maxn=20000050;
int main()
{
int x,y;
cin>>x>>y;
if(x==y)
cout<<x<<endl;
else cout<<3-x-y<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod = 1e9 + 7;
const ll maxn = 5e6 + 5;
#define endl '\n'
#define ld long double
#define int ll
#define all(x) (x).begin(),(x).end()
const ll md = (ll) 1e9 + 7;
inline ll add(ll a, ll b) {
a += b;
if (a >= md) a -= md;
return a;
}
inline ll sub(ll a, ll b) {
a -= b;
if (a < 0) a += md;
return a;
}
inline ll mul(ll a, ll b) {
return (ll) ((long long)((a%md) * (b%md)) % md);
}
inline ll power(ll a, long long b) {
ll res = 1;
while (b > 0) {
if (b & 1) {
res = mul(res, a);
}
a = mul(a, a);
b >>= 1;
}
return res;
}
inline ll inv(ll a) {
a %= md;
if (a < 0) a += md;
ll b = md, u = 0, v = 1;
while (a) {
ll t = b / a;
b -= t * a; swap(a, b);
u -= t * v; swap(u, v);
}
assert(b == 1);
if (u < 0) u += md;
return u;
}
vector<int> fact(maxn+5);
void init (int n)
{
fact[0] = 1;
for(int i = 1;i<=n;i++)
{
fact[i] = mul(i,fact[i-1]);
}
}
int nck(int n,int k)
{
return mul(fact[n],mul(inv(fact[k]),inv(fact[n-k])));
}
int32_t main(){
IOS
init(5000000);
int n, m;
cin >> n >> m;
vector<int> a(n);
int k = 1;
for(int i = 0;i<n;i++){
cin >> a[i];
m -= a[i];
k += a[i] + 1;
}
if(m < 0){
cout << 0 << endl;
return 0;
}
int num = k - 1 + m;
int den = k - 1;
int ans = 1;
for(int i = 0;i<den;i++){
ans = mul(ans, num - i);
}
ans = mul(ans, inv(fact[den]));
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll> pql;
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {return (a % b + b) % b;}
ll quo(ll a, ll b) {return (a - mod(a, b)) / b;}
template <typename T, typename U> bool chmin(T &a, const U b) {if(a > b) {a = b; return 1;} return 0;}
template <typename T, typename U> bool chmax(T &a, const U b) {if(a < b) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 2e5;
const ld eps = 1e-9;
const char newl = '\n';
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll a, b, ans;
cin >> a >> b;
if(a+b >= 15 && b >= 8) ans = 1;
else if(a+b >= 10 && b >= 3) ans = 2;
else if(a+b >= 3) ans = 3;
else ans = 4;
cout << ans << newl;
return 0;
} |
#include<bits/stdc++.h>
#define pu push
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define rrep(i,x) for(int i=1;i<=x;i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define BITSC(x,v) (binary_search(x.begin(),x.end(),v)
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}
const double eps =1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
int main(){
int n,m,k;cin>>n>>m;
vi a(m);
vi kukan;
ll ans=0;
if(m!=0){
rep(i,m){
int temp;cin>>temp;
temp--;
a[i]=temp;
}
sort(rng(a));
if(a[0]==0)k=n+20;
else {
k=a[0];
kukan.pb(a[0]);
}
rep(i,m-1){
if(a[i+1]-a[i]==1)continue;
k=min(k,a[i+1]-a[i]-1);
kukan.pb(a[i+1]-a[i]-1);
}
if(n-1-a[m-1]>0){
k=min(k,n-1-a[m-1]);
kukan.pb(n-1-a[m-1]);
}
rep(i,kukan.size()){
ans+=dup(kukan[i],k);
}
}
if(k==n+20)ans=0;
if(m==0)ans=1;
cout<<ans<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int h, w, x, y; cin >> h >> w >> x >> y;
x--; y--;
vector<string> S(h); rep(i, h) cin >> S[i];
int ans = 1;
for(int i=x+1; i<h; i++) {
if(S[i][y] == '#') break;
ans++;
}
for(int i=x-1; i>=0; i--) {
if(S[i][y] == '#') break;
ans++;
}
for(int j=y+1; j<w; j++) {
if(S[x][j] == '#') break;
ans++;
}
for(int j=y-1; j>=0; j--) {
if(S[x][j] == '#') break;
ans++;
}
cout << ans << endk;
return 0;
}
|
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0)
#define sz(a) (ll)(a).size()
#define triple pair<pill, ll>
#define pinode pair<node*, node*>
#define quadra pair<pill, pill>
#define ld long double
using namespace std;
const ll N = 500 + 10;
const ll M = 1e14;
const ll big = 1e14;
const ll hsh2 = 1964325029 ;
const long long mod = 1e9 + 7;
const long double EPS = 1e-20;
const ll block = 500;
const ll shift = 2e3;
const ld pi = acos(-1.0);
ll n, m;
vector<int> g[N];
ll ans = 0;
ll glo = 1;
ll c[N];
vector<ll> cmp;
void solve(int pos) {
if(pos == cmp.size()) {
ans++;
return;
}
bool can[4] = {0};
for(auto u : g[cmp[pos]]) {
if(u > cmp[pos])
break;
can[c[u]] = 1;
}
if(!can[1])
c[cmp[pos]] = 1,
solve(pos + 1);
if(!can[2])
c[cmp[pos]] = 2,
solve(pos + 1);
if(!can[3])
c[cmp[pos]] = 3,
solve(pos + 1);
c[cmp[pos]] = 0;
}
bool us[N];
void dfs(ll v) {
us[v] = 1;
for(auto u : g[v])
if(!us[u])dfs(u);
cmp.pb(v);
}
int main() {
speed;
cin >> n >> m;
for(int i = 1; i <= m; i++) {
ll a, b;
cin >> a >> b;
g[b].pb(a);
g[a].pb(b);
}
for(int i = 1; i <= n; i++)
sort(all(g[i]));
for(int i = 1; i <= n; i++) {
if(!us[i]) {
dfs(i);
sort(all(cmp));
cmp.erase(unique(all(cmp)), cmp.end());
solve(0);
glo = glo * ans;
ans = 0;
cmp.clear();
}
}
cout << glo;
}
/*
4
4 6 1 9
2 5 3 2
*/ | #include <bits/stdc++.h>
using namespace std;
//#include <atcoder/segtree>
//using namespace atcoder;
using ll = long long int;
using P = pair<int, int>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) int(x.size())
#define endl '\n'
const int INF = 1001001001;
const ll mod = 1000000007;
const ll INFL = 10000000010000000;
int main() {
int h, w; cin >> h >> w;
vector<string> s(h); rep(i,h) cin >> s[i];
int sx, sy, gx, gy;
vector<pair<int, int>> tp[26];
rep(i,h) rep(j,w) {
if (s[i][j] == 'S') {
sx = i;
sy = j;
}
else if (s[i][j] == 'G') {
gx = i;
gy = j;
}
int d = s[i][j]-'a';
if (0 <= d && d <= 25) tp[d].push_back({i, j});
}
vector<vector<int>> dist(h, vector<int>(w, INF));
vector<pair<int,int>> dxdy = {{1,0}, {0,1}, {-1,0}, {0,-1}};
queue<pair<int,int>> que;
dist[sx][sy] = 0;
que.push({sx, sy});
while (que.size()) {
pair<int,int> p = que.front(); que.pop();
int cx = p.first, cy = p.second;
for (int i = 0; i < 4; i++) {
int nx = cx+dxdy[i].first, ny = cy+dxdy[i].second;
if (!(0 <= nx && nx < h && 0 <= ny && ny < w)) continue;
if (s[nx][ny] == '#') continue;
if (dist[nx][ny] == INF) {
dist[nx][ny] = dist[cx][cy]+1;
que.push({nx, ny});
}
}
int d = s[cx][cy]-'a';
if (d < 0 || 25 < d) continue;
for (auto pn : tp[d]) {
if (dist[pn.first][pn.second] == INF) {
dist[pn.first][pn.second] = dist[cx][cy]+1;
que.push({pn.first, pn.second});
}
}
tp[d].clear();
}
if (dist[gx][gy] == INF) puts("-1");
else cout << dist[gx][gy] << endl;
return 0;
} |
#include <iostream>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm>
using ll = long long;
#define fast_io \
ios::sync_with_stdio(false); \
cin.tie(0)
using namespace std;
int dx[4] = { 0,0,1,-1 };
int dy[4] = { 1,-1,0,0 };
void solve(ll t) {
ll a,b,c;
cin >> a>>b>>c;
ll ans = 0;
if (a * a + b * b < c * c) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
//cout << ans << endl;
}
int main(void)
{
ll t = 0;
//cin >> t; for (ll i = 1; i <= t; i++) {solve(i);}
solve(t);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using ll = long long;
const int INF = 1001001001;
const ll LINF = 1002003004005006007ll;
void solve(){
double n,D,H;
cin >> n >> D >> H;
vector<double> d(n),h(n);
double ans = INF;
rep(i,n){
cin >> d[i] >> h[i];
chmin(ans,(H-h[i])/(D-d[i]));
}
double aa = H-ans*(D);
if(aa<=0)aa = 0;
cout << aa << endl;
return;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(16);
solve();
return 0;
} |
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;
#define R (long long)(1e9 + 7)
string s;
bool valid(int a, int b, int c, int d) {
return (s[a] != 'x' && s[b] != 'x' && s[c] != 'x' && s[d] != 'x');
}
int main() {
cin >> s;
set<int> definite;
for(int i = 0; i < 10; i++) {
if(s[i] == 'o')
definite.insert(i);
}
set<vector<int>> ans;
for(int a = 0; a < 10; a++) {
for(int b = 0; b < 10; b++) {
for(int c = 0; c < 10; c++) {
for(int d = 0; d < 10; d++) {
if(valid(a, b, c, d)) {
set<int> temp = definite;
temp.erase(a);
temp.erase(b);
temp.erase(c);
temp.erase(d);
if(temp.empty())
ans.insert({a, b, c, d});
}
}
}
}
}
cout << ans.size() << '\n';
} | #include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define vec vector
using namespace std;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef LOCAL
// freopen("in1.txt", "r", stdin);
// freopen("in1.txt", "w", stdout);
#endif
string s;
cin >> s;
int a = 0, b = 0, c = 0;
for (int i=0; i<s.size(); i++) {
if (s[i] == 'o') a++;
if (s[i] == 'x') b++;
if (s[i] == '?') c++;
}
if (a > 4) {
cout << 0 << '\n';
return 0;
}
int res = 0;
for (int p=0; p<10000; p++) {
vec<bool> use(10);
for (int x=p, i=0; i<4; i++, x/=10) {
use[x%10] = 1;
}
bool poss = 1;
for (int i=0; i<10; i++) {
if (s[i] == 'o' && !use[i]) poss = 0;
if (s[i] == 'x' && use[i]) poss = 0;
}
res += poss;
}
cout << res << '\n';
} |
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int a1, a2, a3;
int main() {
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(false);
cin >> a1 >> a2 >> a3;
cout << (a1 - a2 == a2 - a3 || a1 - a3 == a3 - a2 || a2 - a1 == a1 - a3 || a2 - a3 == a3 - a1 || a3 - a1 == a1 - a2 || a3 - a2 == a2 - a1 ? "Yes" : "No") << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define SZ(x) ((int)(x).size())
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
void solve(istream& cin, ostream& cout) {
vector<int> a(3);
REP(i, 3) cin >> a[i];
SORT(a);
if (a[2] - a[1] == a[1] - a[0]) cout << "Yes" << endl;
else
cout << "No" << endl;
}
#ifndef TEST
int main() {
OPTIMIZE_STDIO;
solve(cin, cout);
return 0;
}
#endif
|
#include<bits/stdc++.h>
#define PI 3.141592653589793238462
#define eps 1e-20
#define fi first
#define se second
using namespace std;
using cd = complex<double>;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdd;
int main(){
ll n,ans=2e18;cin>>n;
for(ll i=0;i<=60;i++){
ll v=((ll)1<<i);
ll a=n/v,c=n%v;
ans=min(ans,a+c+i);
}
cout<<ans<<endl;
} | #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <functional>
using namespace std;
using ll = long long;
using Graph = vector<vector<int> >;
using P = pair<int, int>;
#define INF 2000000000
int main(){
int n;
cin>>n;
if((int)(n*1.08) < 206) cout<<"Yay!"<<endl;
else if((int)(n*1.08) == 206) cout<<"so-so"<<endl;
else cout<<":("<<endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define ri register int
#define ll long long
#define ui unsigned int
il ll read(){
bool f=true;ll x=0;
register char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f=false;ch=getchar();}
while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
if(f) return x;
return ~(--x);
}
il int read(char *s){
int len=0;
register char ch=getchar();
while(ch==' '||ch=='\n') ch=getchar();
while(ch!=' '&&ch!='\n'&&ch!=EOF) s[++len]=ch,ch=getchar();
return len;
}
il void write(const ll &x){if(x>9) write(x/10);putchar(x%10+'0');}
il void print(const ll &x) {x<0?putchar('-'),write(~(x-1)):write(x);putchar('\n');}
il ll max(const ll &a,const ll &b){return a>b?a:b;}
il ll min(const ll &a,const ll &b){return a<b?a:b;}
ll n,ans;
struct hmap{
static const int P=2e6+3,M=3e6+10;
int hed[M],nxt[M],cnt;ll val[M];ll as[M];
bool count(ll x){
int c=hed[x%P];
while(c){
if(val[c]==x) return 1;
c=nxt[c];
}return 0;
}
ll& operator [](ll x){
int c=hed[x%P];
while(c){
if(val[c]==x) return as[c];
c=nxt[c];
}
++cnt;val[cnt]=x;nxt[cnt]=hed[x%P];hed[x%P]=cnt;
return as[cnt];
}
int size(){return cnt;}
}M;
int main(){
ans=n=read();
for(ll i=2;i*i<=n;++i){
ll res=i*i;
while(res<=n){
if(!M[res]) M[res]=1,--ans;
res*=i;
}
}
print(ans);
return 0;
} | #pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
#define int long long
//#define double long double
#define eps 1e-8
//#define mod 1e9+7
using namespace std;
const int mod=1e9+7;
const int M=2e3+5;
const int N=2*1e5+5;//?????????? 4e8
int n,m;
int prime[N],v[N];
int ans;
map < int , bool > mp;
signed main()
{
// ios::sync_with_stdio(false);
cin>>n;
m=sqrt(n);
for(int i=1;i<=m;i++)
{
if(mp[i]) continue;
int j=i;
mp[i]=1;
if(i==1) continue;
while(j<=n)
{
j=i*j;
if(j>n) break;
ans++;
mp[j]=1;
}
}
cout<<n-ans;
return 0;
} |
#include <bits/stdc++.h>
#define pb push_back
#define INF 1<<30
#define all(x) x.begin(),x.end()
#define ms(a,v) memset(a,v,sizeof a)
#define II ({int a; scanf("%d", &a); a;})
#define LL ({ll a; scanf("%lld", &a); a;})
#define EPS 1e-10
#define pi acos(0.0)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef vector<int> vi ;
typedef vector<ll> vl;
#define FOR(i,n) for( __typeof(n)i = 0 ; i < n ; i++)
#define FORL(i,a, b) for( __typeof(a)i = a ; i <= b ; i++)
#define FORR(i,a, b) for( __typeof(a)i = a ; i >= b ; i--)
#define For(i,n) for( __typeof(n)i = 1 ; i <= n ; i++)
#define forstl(i,n) for(__typeof(n.begin())i = n.begin();i!=n.end();i++)
#define forab(i,a,b) for( __typeof(b) i = a ; i <= (b) ; i++ )
#define forba(i,b,a) for( __typeof(b) i = b ; i >= (a) ; i-- )
#define sz(v) ((int)((v).size()))
const ll OO = 1e8;
int x[4] = {0 , 0 , -1, 1};
int y[4] = {1, -1, 0 , 0};
ll dp[3005][3005];
ll count(ll n , ll k)
{
if (k < 0 || n < k) return 0LL;
if (n <= 0 || k <= 0)
{
if (n == 0 && k == 0)
{
return 1LL;
}
return 0LL;
}
if (dp[n][k] >= 0)
return dp[n][k];
dp[n][k] = (count(n - 1, k - 1) + count(n , 2 * k) ) % 998244353LL;
return (dp[n][k]);
}
void solve()
{
ll n, k;
cin >> n >> k;
FOR(i, n + 3)
{
FOR(j, n + 3)
{
dp[i][j] = -1;
}
}
cout << count(n, k) << endl;
}
int main()
{
int T = 1;
//cin >> T;
// cin.ignore(); must be there when using getline(cin, s)
//freopen("input.txt", "r", stdin);
// Printing the Output to output.txt file
//freopen("output.txt", "w", stdout);
while (T--)
{
solve();
}
return 0;
}
| #include <bits/stdc++.h>
#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
using ll = long long;
using namespace std;
const double PI = acos(-1);
// const int M = 1000000007;
const int M = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int mod(int n, int m = M) {
int ret = n % m;
if (ret < 0) ret += m;
return ret;
}
int exp(int n, int k, int m = M) {
if (k == 0) return 1;
if (k == 1) return n;
int ax = exp(n, k / 2, m);
ax = mod(ax * ax, m);
if (k % 2) ax = mod(ax * n, m);
return ax;
}
int gcd(int a, int b) {
if (a == 0)
return b;
else
return gcd(b % a, a);
}
int dp[3123][3123];
//#define MULTIPLE_TEST_CASE
void solution() {
int n, k;
cin >> n >> k;
memset(dp, 0, sizeof dp);
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = i; j >= 1; j--) {
dp[i][j] = dp[i - 1][j - 1] + (2 * j <= n ? dp[i][2 * j] : 0);
dp[i][j] = mod(dp[i][j]);
// cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
}
}
cout << dp[n][k] << endl;
}
int32_t main() {
DESYNC;
int t = 1;
#ifdef MULTIPLE_TEST_CASE
cin >> t;
#endif
while (t--) solution();
}
|
/**
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀
* author: Daredevil666
* institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define F(i,a,b) for(i=a;i<b;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781641;
const ll M=1e16;
const ll MAXN=200200;
ll i,j,mask;
void solve()
{
ll x,y;
cin>>x>>y;
if(x>=y)
{
cout<<x-y;
return ;
}
queue<ll> q;
q.push(y);
ll lvl=-1;
ll ans=y-x;
set<ll> st;
st.insert(y);
while(!q.empty())
{
lvl++;
if(lvl>=ans)break;
ll s=q.size();
F(i,0,s)
{
ll p=q.front();
q.pop();
if(p<=x)
{
ans=min(ans,lvl+x-p);
}
else
{
ans=min(ans,lvl+p-x);
if(p%2)
{
if(st.count(p+1)==0)
{st.insert(p+1);q.push(p+1);}
if(st.count(p-1)==0)
{st.insert(p-1);q.push(p-1);}
}
else
{
if(st.count(p/2)==0)
{st.insert(p/2);q.push(p/2);}
}
}
}
}
cout<<ans;
}
int main()
{
IOS
/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#*/
/*ll t,test;
cin>>test;
F(t,1,test+1)
{
//cout<<"Case #"<<t<<": ";
solve();
nl
}*/
solve();
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
#define int long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define sz(x) (int)((x).size())
#define fr first
#define sc second
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define ppc __builtin_popcount
#define ppcll __builtin_popcountll
template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;
const int N=2005;
int vis[N + 100][N + 100];
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
void solve(){
int h,w;
cin >> h >> w;
string s[h];
int x,y;
vector<pii> v[26];
for(int i = 0; i < h; i++){
cin >> s[i];
for(int j = 0; j < w; j++){
if(s[i][j] == 'S'){
x = i;
y = j;
}
if(s[i][j] >= 'a' && s[i][j] <= 'z'){
v[s[i][j] - 'a'].pb({i,j});
}
}
}
set<pair<int, pii>> q;
q.insert({0,{x,y}});
while(!q.empty()){
auto tmp = *q.begin();
q.erase(tmp);
int X = tmp.sc.fr, Y = tmp.sc.sc;
if(X == N+5){
if(vis[X][Y]){
continue;
}
vis[X][Y] = 1;
// we are on a character
for(pii z:v[Y]){
q.insert({tmp.fr+1,z});
}
continue;
}
if(X < 0 || Y < 0 || X >= h || Y >= w || vis[X][Y] || s[X][Y] == '#'){
continue;
}
vis[X][Y] = 1;
if(s[X][Y] == 'G'){
cout << tmp.fr / 2;
return;
}
for(int i = 0; i < 4; i++){
q.insert({tmp.fr + 2, {X+dx[i], Y+dy[i]}});
}
if(s[X][Y] >= 'a' && s[X][Y] <= 'z'){
q.insert({tmp.fr+1,{N+5,s[X][Y] - 'a'}});
}
}
cout << -1;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#ifdef SIEVE
sieve();
#endif
#ifdef NCR
init();
#endif
int t=1;
//cin>>t;
while(t--) solve();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
/**templates**/
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sull(x) scanf("%llu",&x)
#define sf(x) scanf("%lf",&x)
#define ss(x) scanf(" %s",x)
#define sc(x) scanf(" %c",&x)
#define pi acos(-1.0)
#define pb push_back
#define aa first
#define bb second
#define sz(x) (ll)(x).size()
#define cas printf("Case %lld: ",++t)
#define casline printf("Case %lld:\n",++t)
//#define cas cout<<"Case "<<++t<<": "
//#define casline cout<<"Case "<<++t<<":"<<endl;
#define distance(x1,y1,x2,y2)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
#define endl "\n"
#define bug cout<<"bugggggggggggg "<<endl;
#define fast ios_base::sync_with_stdio(0);cin.tie(nullptr); ///no printf/scanf
#define clean fflush(stdout)
const ll mod = 1000000007;
const ll inf = 1LL<<62;
const ll mx = 100005;
const double eps = 1e-10;
ll dx[10]={1,0,-1,0};
ll dy[10]={0,-1,0,1};
///ll dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; /// 8 Direction
///ll dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; /// Knight Direction
ll power(ll a,ll b)
{
if(b==0)return 1;
ll x=power(a,b/2);
x=x*x;
if(b%2)x=x*a;
return x;
}
ll bigmod(ll a,ll b)
{
if(b==0)return 1;
ll x=bigmod(a,b/2)%mod;
x=(x*x)%mod;
if(b%2)x=(x*a)%mod;
return x;
}
ll Set(ll N,ll pos){return N=N | (1LL<<pos);}
ll reset(ll N,ll pos){return N= N & ~(1LL<<pos);}
bool check(ll N,ll pos){return (bool)(N & (1LL<<pos));}
/**
...ENDING OF TEMPLATE...
*/
ll egcd(ll a,ll b,ll &x,ll &y)
{
if(a == 0)
{
x = 0;
y = 1;
return b;
}
ll x1,y1;
ll d = egcd(b%a,a,x1,y1);
x = y1-(b/a)*x1;
y = x1;
return d;
}
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// fast; ///no printf/scanf
/** Use "long double"(%Lf) instead of double for precision safety*/
ll tst,a,b,c,k,s,n,m,mm,res=0,ans=0,t=0;
sl(tst);
while(tst--)
{
sl(n),sl(s),sl(k);
c=__gcd(k,n);
if(c!=1)
{
if(s%c)
{
cout<<-1<<endl;
continue;
}
}
s/=c;
n/=c;
k/=c;
egcd(k,n,res,ans);
if(res<0)
res+=n;
res=(res*(n-s))%n;
cout<<res<<endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#pragma region DEBUG
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef
tree<
pair<lli,lli>,
null_type,
less<pair<lli,lli>>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {lli f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#pragma endregion DEBUG
#define MOD 1000000007
#define MAX 500005
#define endl "\n"
vector <lli> fact(MAX,1);
vector <lli> invfact(MAX,1);
lli gcd(lli a, lli b, lli& x, lli& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
lli x1, y1;
lli d = gcd(b, a % b, x1, y1);
x = y1;
y = x1 - y1 * (a / b);
return d;
}
bool find_any_solution(lli a, lli b, lli c, lli &x0, lli &y0, lli &g) {
g = gcd(abs(a), abs(b), x0, y0);
if (c % g) {
return false;
}
x0 *= c / g;
y0 *= c / g;
if (a < 0) x0 = -x0;
if (b < 0) y0 = -y0;
return true;
}
void solve(){
lli n,s,k;
cin>>n>>s>>k;
lli x,y,g;
g = __gcd(n,s);
if(find_any_solution(n,-k,s,x,y,g)){
// debug(y,n/g);
cout<<(y%(n/g)+(n/g))%(n/g)<<endl;
}
else{
cout<<"-1"<<endl;
}
}
int main(){
/* freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout); */
ios_base::sync_with_stdio(false);
cin.tie(NULL);
/* for(lli i = 1; i<MAX-5; i++){
fact[i] = i*fact[i-1]%MOD;
invfact[i] = binpow(fact[i],MOD-2);
} */
lli t;
t = 1;
cin>>t;
while(t--)
solve();
} |
#include <bits/stdc++.h>
using namespace std;
template <int MOD=998'244'353>
struct Modular {
int value;
static const int MOD_value = MOD;
Modular(long long v = 0) { value = v % MOD; if (value < 0) value += MOD;}
Modular(long long a, long long b) : value(0){ *this += a; *this /= b;}
Modular& operator+=(Modular const& b) {value += b.value; if (value >= MOD) value -= MOD; return *this;}
Modular& operator-=(Modular const& b) {value -= b.value; if (value < 0) value += MOD;return *this;}
Modular& operator*=(Modular const& b) {value = (long long)value * b.value % MOD;return *this;}
friend Modular mexp(Modular a, long long e) {
Modular res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
return res;
}
friend Modular inverse(Modular a) { return mexp(a, MOD - 2); }
Modular& operator/=(Modular const& b) { return *this *= inverse(b); }
friend Modular operator+(Modular a, Modular const b) { return a += b; }
friend Modular operator-(Modular a, Modular const b) { return a -= b; }
friend Modular operator-(Modular const a) { return 0 - a; }
friend Modular operator*(Modular a, Modular const b) { return a *= b; }
friend Modular operator/(Modular a, Modular const b) { return a /= b; }
friend std::ostream& operator<<(std::ostream& os, Modular const& a) {return os << a.value;}
friend bool operator==(Modular const& a, Modular const& b) {return a.value == b.value;}
friend bool operator!=(Modular const& a, Modular const& b) {return a.value != b.value;}
};
int main(){
Modular<998244353> a, b, c, ans;
int a1, b1, c1;
cin >> a1 >> b1 >> c1;
a = a1; b = b1; c = c1;
ans = (a * (a + 1))/2 * (b * (b + 1))/2 * (c * (c + 1))/2;
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;
template <typename _T>
inline void read(_T &f) {
f = 0; _T fu = 1; char c = getchar();
while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); }
while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
f *= fu;
}
template <typename T>
void print(T x) {
if (x < 0) putchar('-'), x = -x;
if (x < 10) putchar(x + 48);
else print(x / 10), putchar(x % 10 + 48);
}
template <typename T>
void print(T x, char t) {
print(x); putchar(t);
}
const int N = 1e5 + 5;
int a[N], b[N], f[2][N];
int n, len[2];
ll ans;
int main() {
memset(f, -0x3f, sizeof(f));
read(n);
for (int i = 1; i <= n; i++) read(a[i]), ans += a[i];
for (int i = 1; i <= n; i++) read(b[i]), b[i] -= a[i];
for (int i = 1; i <= n; i++) f[i & 1][++len[i & 1]] = b[i];
sort(f[0] + 1, f[0] + len[0] + 1); reverse(f[0] + 1, f[0] + len[0] + 1);
sort(f[1] + 1, f[1] + len[1] + 1); reverse(f[1] + 1, f[1] + len[1] + 1);
for (int i = 1; i <= n / 2; i++) {
if (f[0][i] + f[1][i] < 0) break;
ans += f[0][i] + f[1][i];
}
print(ans, '\n');
return 0;
} |
#include <bits/stdc++.h>
#define f first
#define s second
#define loop(i, n) for (int i = 0; i < n; ++i)
#define read(a, n) loop($, n) cin >> a[$];
#define show(a, n) \
loop($, n) cout << a[$] << " "; \
cout << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
/* // RANDOM NUMBER GENERATOR
// rng() generates u.a.r. from [0, 2^32 - 1]
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
*/
/* // TIME
auto start = chrono::high_resolution_clock::now();
// ...
auto stop = chrono::high_resolution_clock::now();
auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
cout << duration.count() << endl;
*/
struct con{
ull d, k, t;
};
void dijkstra(int n, int s, vector<con> G[], ll d[]){
priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > H;
H.push({0, s});
while(n && !H.empty()){
int v = H.top().s;
ll t = H.top().f;
H.pop();
if(d[v] == -1){
--n;
d[v] = t;
for(con c : G[v]){
if(d[c.d] == -1){
H.push({t + (c.k - t % c.k) % c.k + c.t, c.d});
}
}
}
}
}
int main(){
/* // IO
ios_base::sync_with_stdio(false); // unsync C- and C++-streams (stdio, iostream)
cin.tie(NULL); // untie cin from cout (no automatic flush before read)
*/
int n, m, s, t;
cin >> n >> m >> s >> t;
--s; --t;
vector<con> G[n];
loop(i, m){
int u, v, l, k;
cin >> u >> v >> l >> k;
G[u - 1].push_back({v - 1, k, l});
G[v - 1].push_back({u - 1, k, l});
}
ll d[n];
loop(i, n){
d[i] = -1;
}
dijkstra(n, s, G, d);
cout << d[t] << endl;
return 0;
} | #include<bits/stdc++.h>
#define MAX 100000
#define MOD 1000000007
using namespace std;
vector<pair<int,pair<int,int>>> v[MAX+10];
long long sp[MAX+10];
set<pair<long long,int>> st;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m,x,y;
cin>>n>>m>>x>>y;
while(m--)
{
int a, b,t,k;
cin>>a>>b>>t>>k;
v[a].push_back({b,{t,k}});
v[b].push_back({a,{t,k}});
}
for(int i=1;i<=n;++i)
sp[i] = LLONG_MAX;
sp[x] = 0;
st.insert({0,x});
while(!st.empty())
{
pair<long long,int> p = *(st.begin());
st.erase(st.begin());
for(pair<int,pair<int,int>> x:v[p.second])
{
long long tm = x.second.first;
if(sp[p.second]%x.second.second)
tm += x.second.second*1LL-1LL*(sp[p.second]%x.second.second);
if(tm+sp[p.second]<sp[x.first])
{
set<pair<long long,int>>::iterator it = st.find({sp[x.first],x.first});
if(it!=st.end())
st.erase(it);
sp[x.first] = tm+sp[p.second];
st.insert({sp[x.first],x.first});
}
}
}
cout<<(sp[y]==LLONG_MAX?-1:sp[y])<<endl;
return 0;
} |
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int n,m;
int sa;
int ans1,ans2;
int ksm(ll ta,int tp){
int s=1;
for(;tp;ta=ta*ta%mod,tp>>=1) if(tp&1) s=ta*s%mod;
return s;
}
int main(){
scanf("%d %d",&n,&m);
m+=n;
for(int i=1,a;i<=n;i++){
scanf("%d",&a); sa+=a;
}
sa+=n;
ans1=ans2=1;
if(m<sa){
printf("0\n");
return 0;
}
for(int i=1;i<=sa;i++) ans1=1ll*ans1*i%mod;
for(int i=1;i<=sa;i++) ans2=1ll*ans2*(m-i+1)%mod;
printf("%lld\n",1ll*ans2*ksm(ans1,mod-2)%mod);
return 0;
}
| #include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
const int mod=1e9+7;
#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,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first
#define S second
#define PB push_back
#define MP make_pair
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl=vector<long long>;
using vvl = vector<vl>;
using vp =vector<pair<int,int>>;
typedef pair<int,int> P;
string s;
int k;
ll INF = 1000000000000;
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
int main(){
ll N;
cin >>N;
vl A(N);
ll ans=0;
rep(i,N){
cin >>A[i];
}
sort(all(A));
ll pas=0;
rep(i,N){
ans = ans + ( (A[i]*A[i])%998244353+ (A[i]*pas)%998244353)%998244353;
ans %=998244353;
pas = (pas*2+A[i])%998244353;
}
cout<<ans<<endl;
}
|
/**
* author: otera
**/
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < n; ++ i)
#define per(i,n) for(int i=n-1;i>=0;i--)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
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 n, m;
vector<int> ans;
vector<vector<P>> g;
void dfs(int v, int p, int k) {
ans[v] = k;
for(auto e: g[v]) {
int nv = e.fr, c = e.sc;
if(nv == p) continue;
if(ans[nv] != -1) continue;
if(k == c) {
dfs(nv, v, (k == n ? 1 : k + 1));
} else {
dfs(nv, v, c);
}
}
}
void solve() {
cin >> n >> m;
g.assign(n, vector<P>());
rep(i, m) {
int u, v, c; cin >> u >> v >> c;
-- u, -- v;
g[u].push_back({v, c});
g[v].push_back({u, c});
}
ans.assign(n, -1);
dfs(0, -1, 1);
rep(i, n) {
if(ans[i] == -1) {
cout << "No" << endl;
return;
}
}
rep(i, n) {
cout << ans[i] << "\n";
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
//cout << fixed << setprecision(20);
//int t; cin >> t; rep(i, t)solve();
solve();
return 0;
} | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> parent, rk;
void make_set(ll v) {
parent[v] = v;
rk[v] = 0;
}
ll find_set(ll v) {
if (v == parent[v]) return v;
return parent[v] = find_set(parent[v]);
}
void union_sets(ll a, ll b) {
a = find_set(a);
b = find_set(b);
if (a != b) {
if (rk[a] < rk[b]) swap(a, b);
parent[b] = a;
if (rk[a] == rk[b]) rk[a]++;
}
}
struct Edge {
ll u, v, weight;
bool operator<(Edge const& other) {
return weight < other.weight;
}
};
vector<pair<ll, ll> > adj[100010];
ll vis[100010], a[100010];
ll n, m;
vector<Edge> edges;
vector<Edge> result;
void dfs(ll x){
vis[x] = 10;
for(auto &i: adj[x]) if(!vis[i.first]) {
if(a[x] == i.second) a[i.first] = (a[x]+1)%n;
else a[i.first] = i.second;
dfs(i.first);
}
}
void solve(){
cin >> n >> m;
for(ll i = 0; i < m; i++){
Edge x;
cin >> x.u >> x.v >> x.weight;
--x.u, --x.v, --x.weight;
edges.push_back(x);
}
parent.resize(n);
rk.resize(n);
for (ll i = 0; i < n; i++) make_set(i);
sort(edges.begin(), edges.end());
for (Edge e : edges) {
if (find_set(e.u) != find_set(e.v)) {
//cost += e.weight;
result.push_back(e);
union_sets(e.u, e.v);
}
}
//cout << "here " << endl;
for(ll i = 0; i < n; i++) a[i] = -1;
for(Edge e: result){
//cout << e.u << " - " << e.v << e.weight << endl;
adj[e.u].push_back({e.v, e.weight});
adj[e.v].push_back({e.u, e.weight});
}
a[0] = 1;
dfs(0);
for(ll i = 0; i < n; i++) cout << a[i] + 1 << endl;
}
int main(){
ll t = 1;
//cin >> t;
while(t--)
solve();
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5+10;
int n,f[N],p=998244353,fa[N],ans;
ll quickpow(ll a,ll b)
{
ll ans = 1;
while(b){
if(b&1) ans *= a;
a *= a;
ans %= p; a %= p;
b>>=1;
}
return ans;
}
int find_fa(int x)
{
if(fa[x] == x) return x;
else return fa[x] = find_fa(fa[x]);
}
void merge(int x,int y)
{
int fx=find_fa(x),fy=find_fa(y);
if(fx != fy){
fa[x] = y; ans--;
}
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++){
scanf("%lld",&f[i]);
fa[i] = i;
}
ans = n;
for(int i=1;i<=n;i++){
merge(i,f[i]);
}
cout<<quickpow(2,ans)-1;
return 0;
} | #pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
bool flag=1;
int x=0;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
flag=0;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=(x<<1)+(x<<3)+c-'0';
c=getchar();
}
return (flag?x:~(x-1));
}
int n,ans=1,fa[200001],sz[200001];
int find(int x)
{
return fa[x]==x?x:fa[x]=find(fa[x]);
}
signed main()
{
n=read();
for(int i=1;i<=n;i++)
fa[i]=i;
for(int i=1;i<=n;i++)
{
int x=read();
fa[find(i)]=find(x);
}
for(int i=1;i<=n;i++)
sz[(find(i))]++;
for(int i=1;i<=n;i++)
if(sz[i])
ans=(ans<<1)%998244353;
cout<<(ans+998244352)%998244353;
return 0;
}
|
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
struct Init { Init(){
cin.tie(0); ios::sync_with_stdio(false);
} } init;
//}}}
ll n, x;
vector<ll> as;
unordered_map<ll, ll> memo[50];
ll solve(int idx, ll rem){
if(idx == n - 1){
return 1;
}
if(memo[idx].count(rem)){ return memo[idx][rem]; }
ll rem2 = rem / as[idx + 1] * as[idx + 1];
ll rem3 = (rem + as[idx + 1] - 1) / as[idx + 1] * as[idx + 1];
// ll rem2 = rem - rem % as[idx + 1];
ll ret = 0;
if(rem != rem2){
ret += solve(idx + 1, rem2);
}
ret += solve(idx + 1, rem3);
printde(idx, rem, ret);
return memo[idx][rem] = ret;
// return ret;
}
int main(){
cin >> n >> x;
as.resize(n); cin >> as;
ll ans = solve(0, x);
cout << ans << '\n';
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
int a[maxn];
int b[maxn];
ll pre[maxn];
int main()
{
ios::sync_with_stdio(0);cin.tie(0);
int n,m;cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=m;i++)cin>>b[i];
sort(a+1,a+1+n);
sort(b+1,b+1+m);
for(int i=n;i;i--){
if(i&1)pre[i]=pre[i+1]-a[i];
else pre[i]=pre[i+1]+a[i];
}
int po=0;
ll ans=LLONG_MAX,sum=0;
for(int i=1;i<=m;i++){
while(a[po+1]<=b[i]&&po<n){
if(po&1)sum+=a[po+1];
else sum-=a[po+1];
po++;
// cout<<po<<' '<<sum<<endl;
}
if(po&1)ans=min(sum+b[i]+abs(pre[po+1]),ans);
else ans=min(sum-b[i]+abs(pre[po+1]),ans);
}
cout<<ans<<endl;
return 0;
}
|
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <math.h>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#define ll long long
#define pii pair<ll, ll>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define INF 1e15+7
#define eps 1e-8
#define DIV 998244353
#define pi 3.14159265
using namespace std;
double sx, sy, gx, gy, res;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> sx >> sy >> gx >> gy;
gy = -gy;
res = -sy * (sx - gx) / (sy - gy) + sx;
printf("%.6lf", res);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main()
{
double Sx,Sy,Gx,Gy;
cin >> Sx >> Sy >> Gx >> Gy;
double ans=double((Gx*Sy+Gy*Sx)/(Sy+Gy));
cout << setprecision(10) << double(ans) << endl;
} |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
int main(){
ll n;
cin >> n;
ll ans = 0;
if(n<1000)
cout << 0 << endl;
else if(n<1000000)
cout << n - 999 << endl;
else if(n<1000000000)
cout << n - 999 + n - 999999 << endl;
else if(n<1000000000000)
cout << n - 999 + n - 999999 + n - 999999999 << endl;
else if(n<1000000000000000)
cout << n - 999 + n - 999999 + n - 999999999 + n - 999999999999 << endl;
else
cout << n - 999 + n - 999999 + n - 999999999 + n - 999999999999 + n - 999999999999999 << endl;
return 0;
} | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string n;
cin >> n;
ll count = 0;
int len = n.length();
size_t sz = 0;
count = stoll(n, &sz, 10);
int maxcom = (len - 1) / 3;
ll x = 1;
for (int i = 0; i < maxcom; i++) x *= 1000;
count = count - x + 1;
count *= maxcom;
x = 1;
for (int i = 0; i < maxcom; i++) {
count += 999 * x * i;
x *= 1000;
}
cout << count << '\n';
return 0;
}
|
#line 2 "/home/defineprogram/Desktop/Library/template/template.cpp"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<ll,ll>
#define len(s) (ll)s.size()
template<class T,class U> inline bool chmin(T &a, U b){
if(a>b){a=b;return true;}
return false;
}
template<class T,class U> inline bool chmax(T &a, U b){
if(a<b){a=b;return true;}
return false;
}
constexpr ll inf = 3e18;
#line 2 "main.cpp"
int main(){
cin.tie(0);ios::sync_with_stdio(false);
ll S,p;cin>>S>>p;
for(ll i=1;i*i<=p;i++){
if(p%i)continue;
ll j=p/i;
if(i+j==S){
cout<<"Yes\n";return 0;
}
}
cout<<"No\n";
}
| #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e3+5;
const int mod=1e9+7;
int a[N];
ll sum;
ll power(ll a,ll b){
ll ans=1;
while(b){
if(b&1){
ans=ans*a%mod;
}
a=a*a%mod;
b>>=1;
}
return ans%mod;
}
ll C(ll n,ll m){
ll ans=1;
n=min(n,m-n);
for(int i=1;i<=n;i++){
ll res=power(i,mod-2);
ans=ans*res%mod;
}
for(ll i=m-n+1;i<=m;i++){
ans=ans*i%mod;
}
return ans;
}
int main(){
ll n,m;cin>>n>>m;
for(ll i=0;i<n;i++){
cin>>a[i];
sum+=a[i];
}
if(sum>m){
cout<<"0"<<endl;
}
else cout<<C(sum+n,n+m)%mod<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define x first
#define y second
#define bg begin()
#define ed end()
#define pb push_back
#define mp make_pair
#define sz(a) int((a).size())
#define R(i,n) for(int i(0);i<(n);++i)
#define L(i,n) for(int i((n)-1);~i;--i)
const int iinf=0x3f3f3f3f;
const ll linf=0x3f3f3f3f3f3f3f3f;
//Data
const int N=2e5;
int n,m; ll c[N+5];
//Main
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>m;
R(i,n){
int s,t,v;
cin>>s>>t>>v;
c[s]+=v,c[t]-=v;
}
R(i,N+3){
if(c[i]>m) cout<<"No\n",exit(0);
c[i+1]+=c[i];
}
cout<<"Yes\n";
return 0;
} | #include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<iterator>
#include<string>
#include<sstream>
#include <unordered_map>
#include<cmath>
using namespace std;
#define ll long long
int __gcd(int a,int b){return b==0 ? a : __gcd(b,a%b);}
ll __gcd(ll a,ll b){return b==0 ? a : __gcd(b,a%b);}
const int maxn=5100;
int a[maxn],t[maxn],c[maxn],g[maxn];
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
int _=1;
while(_--){
int n; cin>>n;
string s; cin>>s;
if(s[0]=='A') a[0]++;
else if(s[0]=='T') t[0]++;
else if(s[0]=='C') c[0]++;
else if(s[0]=='G') g[0]++;
for(int i=1;i<n;++i){
a[i]=a[i-1]; t[i]=t[i-1]; c[i]=c[i-1]; g[i]=g[i-1];
if(s[i]=='A') a[i]++;
else if(s[i]=='T') t[i]++;
else if(s[i]=='C') c[i]++;
else if(s[i]=='G') g[i]++;
}
int ans=0;
//cout<<t]<<endl;
for(int i=0;i<n;++i){
for(int j=i+1;j<n;++j){
int A=0,T=0,C=0,G=0;
if(i>0){
A=a[j]-a[i-1]; T=t[j]-t[i-1]; C=c[j]-c[i-1]; G=g[j]-g[i-1];
} else{
A=a[j]; T=t[j]; C=c[j]; G=g[j];
}
// if(i==1&&j==3) cout<<A<<" "<<T<<" "<<C<<" "<<G<<endl;
if(A==T&&C==G) ++ans;
}
}
cout<<ans<<"\n";
}
} |
// 2021-02-20 21:59:14
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
// clang-format on
const ll inf = 1e18;
int n;
ll x, ans;
vector<ll> a;
ll solve(ll k) {
vector<vector<ll> > dp(n + 1, vector<ll>(k, -1));
dp[0][0] = 0;
rep(i, n) {
vector<vector<ll> > p = dp;
repc(j, i) {
rep(ki, k) {
if (p[j][ki] >= 0) {
int nk = (ki + a[i] % k) % k;
chmax(dp[j + 1][nk], p[j][ki] + a[i]);
}
}
}
}
ll res = inf;
if (dp[k][x % k] > 0) {
res = ((x - dp[k][x % k]) / k);
}
return res;
}
void answer() {
cin >> n >> x;
a.resize(n);
{
ll mx = 0;
rep(i, n) {
cin >> a[i];
chmax(mx, a[i]);
}
ans = x - mx;
}
REPC(k, 2, n) chmin(ans, solve(k));
cout << ans << '\n';
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
answer();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define mod 1000000007
#define M 1000000007
#define pb push_back
#define take(a,b,c) for(int b=0;b<c;b++) cin>>a[b]
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mx 1000005
#define fiint(a,b) memset(a,b,sizeof(a))
#define bitcount __builtin_popcount
#define fori(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define debug(x) cout<<x<<endl;
#define cases(t) int t; cin>>t; while(t--)
#define inf1 INT_MAX
#define all(a) a.begin(),a.end()
#define vec vector<int>
#define pii pair<int,int>
#define plii pair<int,int>
#define pint pair<int,int>
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mp make_pair
#define sz(x) (int)x.size()
#define PI 3.14159265359
int factorial[10000001]={0};
int gcd(int a, int b){
if (b == 0)
return a;
return gcd(b, a % b);
}
int powerFunction(int x,int y){
int res = 1;
int p = mod;
x = x;
while (y > 0){
if (y & 1)
res = (res*x)%p ;
y = y>>1;
x = (x*x)%p ;
}
return res;
}
void factorialFunction(int maxLimit){
factorial[0]=1;
for(int i=1 ; i <= maxLimit ; i++)
factorial[i]=(factorial[i-1]*i)%MOD;
return;
}
int nCr(int n, int r)
{
if(r < 0 || r > n){
return 0;
}
int temp = factorial[n];
temp *= (powerFunction(factorial[r], MOD-2)%MOD);
temp %= MOD;
temp *= (powerFunction(factorial[n-r], MOD-2)%MOD);
temp %= MOD;
return temp;
}
vec v(200);
int n,x;
int le ;
int dp[105][105][105];
int find(int i , int j , int k )
{
if(i == 0)
{
if(v[i] % le == k && j == 0 )
return v[i];
else if(k == 0 && j == -1 ) return (int)0;
else return INT_MIN;
}
if(j == -1 )
{
if(k == 0 ) return 0;
else return INT_MIN;
}
if(dp[i][j][k] != INT_MAX)
return dp[i][j][k];
int a = find(i - 1 , j , k);
int re = v[i] % le;
if(re <= k )
re = k - re;
else { re = le - re + k ; }
int b = INT_MIN;
if(j >= 0)
b = v[i] + find(i - 1 , j - 1 , re );
dp[i][j][k] = max(a , b);
// cout<<i<<" " << j <<" "<<k <<" "<< le + 1 <<" " << a <<" " << b <<endl;
return max( a , b );
}
signed main()
{
cin>>n>>x;
for(int i = 0 ; i < n ;i++) cin>>v[i];
int ans = x;
for(int i = 0 ; i < n ;i++)
{
le = (i+1);
for(int i = 0 ; i < 105 ;i++)
for(int j = 0 ; j < 105 ;j++)
for(int k = 0 ; k < 105 ;k++ )
dp[i][j][k] =INT_MAX;
int a = find(n-1 , i , x % (i+1) );
if(a <= 0 ) continue;
// cout<<a<<endl;
ans = min(ans , (x - a) / (i+1) );
}
cout<<ans<<endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define PrintArray(a,n) for(int i=0;i<n;i++) cout << a[i] << " "; cout << endl;
#define CopyArray(a,temp,n) for(int i=0;i<n;i++) temp[i]=a[i];
#define InputArray(a,n) for(int i=0;i<n;i++) cin >> a[i];
#define MAX(a,b,c) max(max(a,b),c)
#define SumInRange(a,b) ((b*(b+1))/2)-(((a-1)*(a))/2)
#define Different_Random srand(time(NULL))
#define Random(a,b) (rand()%((b+1)-a))+a
#define __delete(v,n) v.erase(remove(v.begin(),v.end(),n),v.end())
#define Cases cout << "Case " << ++Case << ": ";
#define __test int tt; int Case=0; cin >> tt; while(tt--)
#define newline cout << "\n";
#define read(x) freopen(#x, "r", stdin)
#define write(x) freopen(#x, "w", stdout)
#define all(x) x.begin(), x.end()
#define dbg(args...) {string sss(#args);sss+=',';cerr<<"-->";debugger::call(all(sss), args);cerr<<"\n";}
#define dbgA(A, n) {cerr<<"-->"<<#A<<"=(";forn(i, n)cerr<<A[i]<<" ";cerr<<")\n";}
#define dbgA2(A, n, m) {cerr<<"-->"<<#A<<"=\n";forn(i, n){forn(j, m){cerr<<setw(4)<<A[i][j]<<" ";}cerr<<"\n";}cerr<<"\n";}
struct debugger
{
typedef string::iterator si;
static void call(si it, si ed) {}
template<typename T, typename ... aT>
static void call(si it, si ed, T a, aT... rest)
{
string b;
for(; *it!=','; ++it) if(*it!=' ')b+=*it;
cerr << b << " = " << a << " ";
call(++it, ed, rest...);
}
};
template<typename T>
T Max(T a)
{
return a;
}
template<typename T, typename... Args>
T Max(T a, Args... args)
{
return a > Max(args...)? a : Max(args...);
}
template<typename T>
T Min(T a)
{
return a;
}
template<typename T, typename... Args>
T Min(T a, Args... args)
{
return a < Min(args...)? a : Min(args...);
}
//int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
//int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
//int knight_x[] = {2, 2, -2, -2, 1, 1, -1, -1};
//int knight_y[] = {1, -1, 1, -1, 2, -2, 2, -2};
/*
cout.precision(x);
cout << fixed;
*/
typedef long long int ll;
typedef unsigned long long int ull;
const double GOLD = (1.0 + sqrt(5.0))/2.0;
const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
const double PI = 3.141592653589793;
const double E = 2.718281828459045;
ll expo(ll a, ll n)
{
ll result = 1;
while(n)
{
if(n%2) result*=a;
a*=a;
n/=2;
}
return result;
}
ll mod_expo(ll x,ll y,ll p)
{
ll res = 1;
x = x % p;
while (y > 0)
{
if (y & 1) res = (res*x) % p;
y = y>>1;
x = (x*x) % p;
}
return res;
}
const int MOD = 1e9+7;
int main()
{
#ifdef TarekHasan
read(input.txt);
#endif // TarekHasan
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
string str; cin >> str;
reverse(str.begin(),str.end());
for(char &c : str)
{
if(c=='6')
c='9';
else if(c=='9')
c='6';
}
cout << str << "\n";
return 0;
}
| #include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<functional>
#include<utility>
using namespace std;
int main(void){
int n;
cin >> n;
vector<pair<double, double> > a(n);
for(auto& [x, y] : a){
cin >> x >> y;
}
int cnt = 0;
for(int i = 0; i < n; ++i){
for(int j = i + 1; j < n; ++j){
double katamuki = (a[j].second - a[i].second) / (a[j].first - a[i].first);
if(-1 <= katamuki && katamuki <= 1){
cnt++;
}
}
}
cout << cnt << endl;
} |
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define N 200100
#define MOD 1000000007 //998244353
#define ll long long
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
#define eb emplace_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
int main() {
ll ans;
ll n, m, x, k, s, y;
cin >> n >> m;
s = 0;
rep(i, n) {
cin >> x;
s = (s + x) % MOD;
}
ans = 1;
x = m + n;
rep(i, s + n) {
ans = (ans*x) % MOD;
x--;
}
x = 1;
rep(i, s + n)x = (x*(i + 1)) % MOD;
y = MOD - 2;
k = 1;
while (y > 0) {
if (y % 2 == 1) {
k = (k*x) % MOD;
}
x = (x*x) % MOD;
y /= 2;
}
ans = (ans*k) % MOD;
cout << ans << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
void fast(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
}
int main() {
fast();
long long N;
cin>>N;
vector<int> v;
int cnt[3]={0};
int x=0;
while(N){
cnt[(N%10)%3]++;
x++;
N=N/10;
}
if(cnt[0] || (cnt[1] && cnt[2])){
int ans=0;
for(int i=0;i<=cnt[1];i++){
for(int j=0;j<=cnt[2];j++){
if((2*j+i)%3==0){
ans=max(j+i,ans);
}
}
}
cout<<cnt[1]+cnt[2]-ans<<"\n";
}else{
cout<<-1<<"\n";
}
} |
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;
//for debugging
/*
g++ -D_GLIBCXX_ASSERTIONS -DDEBUG -ggdb3 -std=c++14
*/
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os, const Cont& v){
os<<"[";
for(auto& x:v){os<<x<<", ";}
return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os, const pair<Ts...>& p){
return os<<"{"<<p.first<<", "<<p.second<<"}";
}
// debugging ends here
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int mod = 1e9 + 7;
void addSelf(int &a, int b) {
a = (a+b)%mod;
}
void mulSelf(int &a , int b) {
a = (long long )a*b%mod;
}
int binpow(int a, int b) {
int res =1;
while(b>0) {
if(b&1) {
mulSelf(res,a);
}
mulSelf(a,a);
b>>=1;
}
return res;
}
const ll mxn = 100;
ll cache[mxn][2];
ll vis[mxn][2];
vector<ll> base(mxn,0);
vector<ll> lim(mxn,0);
ll n;
ll dp(ll i ,ll carry) {
if(vis[i][carry])
return cache[i][carry];
vis[i][carry] = 1;
if(i == n-1) {
cache[i][carry] = 1;
return cache[i][carry];
}
cache[i][carry] = 0;
ll val = lim[i] + carry;
if(val == 2) { // you will shift the carry further
cache[i][carry] = dp(i+1,carry);
} else {
// i can shift the carry futher only if it is none zero
cache[i][carry] = dp(i+1,0);
if(base[i] + carry !=0) {
cache[i][carry] += dp(i+1,1);
}
}
return cache[i][carry];
}
void solve() {
ll x;
cin >> n >> x;
ll a[n];
for(ll i =0;i<n;i++)
cin >> a[i];
ll cpy = x;
for(ll i = n-1;~i;--i) {
if(cpy>=a[i]) {
base[i] = cpy/a[i];
cpy%=a[i];
if(i!=n-1) {
if(base[i]==(a[i+1]/a[i]) - 1)
lim[i] = 1;
}
}
}
cout << dp(0,0) << endl;
}
int main(){
fast;
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
// ll t;cin >> t;while(t--)
solve();
}
| #include<bits/stdc++.h>
long long n,x;
long long ans[2],k[2],a,b,c,now;
int main()
{
scanf("%lld%lld",&n,&x);
scanf("%lld",&b);
ans[0]=1;ans[1]=0;
for(int i=1;i<n;++i)
{
scanf("%lld",&a);
c=a/b;b=a;
now=x%c;
x/=c;
k[0]=ans[0],k[1]=ans[1];
if(now)k[1]+=ans[0];
if(++now!=c)k[0]+=ans[1];
ans[0]=k[0];ans[1]=k[1];
}
printf("%lld",ans[0]+ans[1]);
return 0;
} |
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main(){
ll n ; cin>>n ;
vector<ll> A(n) ;
rep(i,n) cin>>A[i] ;
ll ans= gcd(A[0],A[1]) ;
rep(i,n-2){
ans= gcd(ans,A[i+2]) ;
}
cout<<ans<<endl ;
return 0 ;
}
| #include <iostream>
#include <iomanip>
using namespace std;
int main(){
int a=0;
int b=0;
int c=0;
int d=0;
int x=0;
int y=0;
int z=0;
int n=0;
int m=0;
int i,j,k;
int te=0;
int A[100] ={0};
int B[100] = {0};
int AA[101][101];
int BB[3][10];
int CC[3][10];
int DD[3][10];
char op;
char OP[100];
long sum=0;
double f1=0;
double f2=0;
cin >> x >>y >>z;
//cin >> a;
//cin >> a >> b;
//cin >> a >> b >> c;
//cin >> a>> b >> x >> y >> z;
f1 = (double )y/x;
b=(int)z*f1;
f2 = (double)b/z;
if(f2<f1){
cout << b << endl;
return 0;
}
if(f2 >= f1){
for(i=b;i>=0;i--){
f2 = (double)i/z;
if(f2 < f1){
break;
}
}
}
cout << i << endl;
return 0;
}
|
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
inline int readint(){
int a = 0; char c = getchar(), f = 1;
for(; c<'0'||c>'9'; c=getchar())
if(c == '-') f = -f;
for(; '0'<=c&&c<='9'; c=getchar())
a = (a<<3)+(a<<1)+(c^48);
return a*f;
}
int main(){
int a = readint(), b = readint();
int w = readint()*1000;
int k = (w-1)/b+1; // b*k >= w
if(a*k > w){
puts("UNSATISFIABLE");
return 0;
}
printf("%d ",k);
k = w/a; // a*k <= w
printf("%d\n",k);
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//turn on extra precision
//#pragma GCC target("fpmath=387")
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef string str;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define watch(x) cout << (#x) << " is : " << (x) << newl
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
vi dirx = {0,0,1,-1};
vi diry = {1,-1,0,0};
char to_upper (char x){
if( 97 <= int(x) && int(x) <= 122) return char(x-32);
if( 65 <= int(x) && int(x) <= 90) return x;
return -1;
}
char to_lower (char x){
if( 97 <= int(x) && int(x) <= 122) return x;
if( 65 <= int(x) && int(x) <= 90) return char(x+32);
return -1;
}
int numerize (char x){
if(48 <= int(x) && int(x) <= 57) return int(x-'0');
if(97 <= int(x) && int(x) <= 122) return int(x-96);
if(65 <= int(x) && int(x) <= 90) return int(x-64);
return -1;
}
bool isect (int l1, int r1, int l2, int r2){ return max(l1,l2) <= min(r1,r2); }
ll quickpow (ll num1, ll num2, ll MOD){
if(num2==0)return 1%MOD;
else if(num2==1)return num1%MOD;
else{
ll temp = quickpow (num1,num2>>1LL,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
if(num2&1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
}
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
int a,b,w;
bool validate(){
int take = w / a;
int rem = w % a;
int p = (rem / take) + !!(rem % take);
if(a + p > b) return false;
return true;
}
int main(){
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> a >> b >> w; w *= 1000;
if(!validate()) return cout << "UNSATISFIABLE\n", 0;
int mx = w / a;
int mn = w / b + !!(w % b);
cout << mn << ' ' << mx << newl;
return 0;
}
|
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
#include <cstdio>
#include <string>
#include <cassert>
#include <climits>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define abs(x) ((x) > 0 ? (x) : -(x))
#define FOREACH(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e)
typedef long long LL;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << a * d - b * c << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int main()
{
int n, init;
cin>>n>>init;
string s;
cin>>s;
for(int i=0; i<n; i++){
if(s[i]=='o') init++;
else init = max(init-1, 0);
}
cout<<init;
}
|
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<climits>
#include<stdio.h>
#include<queue>
#include<list>
#include<stack>
#include<random>
#include<chrono>
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
#define COL 31
#define ROW 31
#define ll long long int
#define ull unsigned long long int
#define mp make_pair
#define pb push_back
#define mem memset
#define inf 1e18
#define mod 1000000007
#define ff first
#define ss second
#define ipair pair<int,int>
int main()
{
ull l,i,j,k;
cin>>l;
ull dp[l+1][13];
for(i=0;i<=l;i++)
for(j=0;j<=12;j++)
dp[i][j]=0;
for(i=0;i<=12;i++)
{
dp[0][i]=0;
dp[1][i]=0;
}
dp[1][1]=1;
dp[0][0]=1;
for(i=1;i<=l;i++)
dp[i][0]=0;
for(i=2;i<=l;i++)
{
for(j=1;j<=12;j++)
{
ull sum=0;
for(k=1;k<=i;k++)
sum+=dp[i-k][j-1];
dp[i][j]=sum;
}
}
cout<<dp[l][12]<<'\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vi = vector<int>;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
#define F first
#define S second
#define allv(v) v.begin(), v.end()
#define alla(a, N) a, a + N
#define np next_permutation
inline void fastIO() {
cin.tie(nullptr) -> sync_with_stdio(false);
}
/** Interface */
inline int readChar();
template <class T = int> inline T readInt();
template <class T> inline void writeInt( T x, char end = 0 );
inline void writeChar( int x );
inline void writeWord( const char *s );
inline void flush();
const ll MOD1 = 1000000007;
const ll MOD2 = 998244353;
const int arraysize = 205;
bool vis[arraysize][arraysize];
int dis[arraysize][arraysize];
vector<pii> adj[arraysize];
ll a[arraysize];
ll b[arraysize];
ll c[arraysize];
string s, t;
ll N, M, Q, K, H, W, R, C;
int u, v, d;
inline string YNEOS(bool b) {
return b ? "YES" : "NO";
}
inline string YNeos(bool b) {
return b ? "Yes" : "No";
}
// Template by https://usaco.guide/gold/PURS?lang=cpp
template<class T> struct SegTree { // comb(ID,b) = b
const T ID = 0; int n; vector<T> seg;
T comb(T a, T b) { return a ^ b; }
void init(int _n) { n = _n; seg.assign(2*n,ID); }
void pull(int p) { seg[p] = comb(seg[2*p],seg[2*p+1]); }
void upd(int p, T val) { // set val at position p
seg[p += n] = val; for (p >>= 1; p; p >>= 1) pull(p); }
T query(int l, int r) { // min on interval [l, r]
T ra = ID, rb = ID; // ----- blank space -----
for (l += n, r += n+1; l < r; l >>= 1, r >>= 1) {
if (l&1) ra = comb(ra,seg[l++]);
if (r&1) rb = comb(seg[--r],rb);
} return comb(ra,rb);
}
};
/* n choose k [possibly mod m] */
ll choose(ll n, ll k) {
ll P = 1;
for (int i = 0; i < k; ++i) P *= n-i;
for (int i = 1; i <= k; ++i) P /= i;
return P;
}
void solve() {
ll N = readInt(), ans = 1;
for (ll i = 1; i <= 11; ++i)
ans *= N - i, ans /= i;
writeInt(ans, '\n');
}
int main() {
// int T; cin >> T;
// while (T--) solve();
solve();
flush();
}
/** Fast Input/Output (IO) */
/** Read */
static const int buf_size = 1 << 14;
inline int getChar() {
static char buf[buf_size];
static int len = 0, pos = 0;
if (pos == len)
pos = 0, len = fread(buf, 1, buf_size, stdin);
if (pos == len)
return -1;
return buf[pos++];
}
inline int readChar() {
int c = getChar();
while (c <= 32)
c = getChar();
return c;
}
template <class T>
inline T readInt() {
int s = 1, c = readChar();
T x = 0;
if (c == '-')
s = -1, c = getChar();
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getChar();
return s == 1 ? x : -x;
}
/** Write */
static int write_pos = 0;
static char write_buf[buf_size];
inline void writeChar( int x ) {
if (write_pos == buf_size)
flush();
write_buf[write_pos++] = x;
}
template <class T>
inline void writeInt( T x, char end ) {
if (x < 0) writeChar('-'), x = -x;
char s[24];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--) writeChar(s[n]);
if (end) writeChar(end);
}
inline void writeWord( const char *s ) {
while (*s) writeChar(*s++);
}
inline void flush() {
fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
} |
#include<bits/stdc++.h>
//#include <atcoder/all>
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int)x.size())
using namespace std;
//using namespace atcoder;
using ld = long double;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> bool chmin(T& a, const T& b) { if(a > b){ a = b; return 1;} return 0; }
template<typename T> bool chmax(T& a, const T& b) { if(a < b){ a = b; return 1;} return 0; }
const ll ZER = 0;
const ll MOD = 998244353;
const ll INF = 1e18;
//bit全探索
vector<ll>bitSearch(int bit,int n){
vector<ll>S;
rep(i,n)if(bit&(1<<i))S.push_back(i);
// S.push_back(1e9);
return S;
}
//最大公約数
ll gcd(ll a, ll b){
if(a % b == 0)return b;
else return gcd(b, a % b);
}
int main(){
int n;
cin >> n;
vector<int> x(n);
rep(i, n)cin >> x[i];
vector<int> A{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
int siz = sz(A);
ll res = 1e18;
for(int bit = 0; bit < (1 << siz); bit++){
auto S = bitSearch(bit, siz);
ll y = 1;
for(auto s : S)y *= A[s];
// cout << y << endl;
bool f = true;
rep(i, n){
if(gcd(x[i], y) == 1)f = false;
}
if(f)chmin(res, y);
}
cout << res << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
double pi = acos(-1);
#define tezi ios_base::sync_with_stdio(false);\
cin.tie(0);\
cout.tie(0);
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORR(i,b,a) for(int i=b;i>=a;i--)
#define fill(a,b) memset(a,b,sizeof(a))
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(),a.end()
#define rev(a) reverse(all(a))
#define reva(a,n) reverse(a,a+n)
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll powerm(ll a,ll b,ll m){
if(b==0) return 1;
if(b&1) return a*powerm(a*a%m,b/2,m)%m;
return powerm(a*a%m,b/2,m);
}
ll power(ll a,ll b){
if(b==0) return 1;
if(b&1) return a*power(a*a,b/2);
return power(a*a,b/2);
}
ll sqroot(ll number){
ll x = sqrt(number);
while(x*x<number)x++;
while(x*x>number)x--;
return x;
}
ll cbroot(ll number){
ll x = cbrt(number);
while(x*x*x<number)x++;
while(x*x*x>number)x--;
return x;
}
const int maxn=1e5+5;
//bool prime[maxn];
map<ll,ll> mm;
ll ans=1e18;
void recur(ll x,ll y,ll move){
if(y<=x){
ans = min(ans,abs(x-y)+move);
return;
}
if(mm[y] && mm[y]<move)return;
mm[y] = move;
ans = min(ans,abs(x-y)+move);
if(y&1){
recur(x,y+1,move+1);
recur(x,y-1,move+1);
}else{
recur(x,y/2,move+1);
}
}
int main(){
tezi
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
//sieve
//memset(prime,true,sizeof(prime));
//for(ll p=2;p*p<maxn;p++)if(prime[p]==true)for(ll i=p*p;i<maxn;i+=p)prime[i]=false;
ll x,y;
cin >> x >> y;
if(x>=y){
cout << x-y;
return 0;
}
recur(x,y,0);
cout << ans;
return 0;
}
/*
###### ####### # # ### # # # ####### ####### ######
# # ###### # # # # ## ## # ## # # # # # # # #
# # # ## # # # # # # # # # # # # # # # # # #
# # ##### # # # # # # # # # # # # # # # # # ######
# # # # # # # # # # # # # # ####### # # # # #
# # # # ## # # # # # # ## # # # # # # #
###### ###### # # ####### # # ### # # # # # ####### # #
*/ |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int read()
{
char c;
int w=1;
while((c=getchar())>'9'||c<'0')if(c=='-')w=-1;
int ans=c-'0';
while((c=getchar())>='0'&&c<='9')ans=(ans<<1)+(ans<<3)+c-'0';
return ans*w;
}
int n;
int a[20];
int b[20];
int tot1;
int tot2;
int main(){
n=read();
tot1=1;
tot2=1;
a[1]=1;
b[1]=1;
int res=0;
for(int i=1;i<=n;i++)
{
int vis=1;
for(int j=1;j<=tot1;j++)if(a[j]==7) vis=0;
for(int j=1;j<=tot2;j++)if(b[j]==7) vis=0;
res+=vis;
a[1]++;
int now=1;
while(a[now]==10)
{
a[now]=0;
a[now+1]++;
now++;
}
b[1]++;
tot1=max(tot1,now);
now=1;
while(b[now]==8)
{
b[now]=0;
b[now+1]++;
now++;
}
tot2=max(tot2,now);
}
cout<<res<<'\n';
return 0;
} | #include<bits/stdc++.h>
using namespace std;
bool f(int x) {
while(x) {
int mod = x % 10;
if(mod == 7) {
return 1;
}
x /= 10;
}
return 0;
}
bool g(int x) {
while(x) {
int mod = x % 8;
if(mod == 7) {
return 1;
}
x /= 8;
}
return 0;
}
void solve() {
//TODO:
int n;
cin >> n;
int cnt = 0;
for(int i = 1; i <= n; i++) {
if(f(i) || g(i)) {
cnt++;
}
}
cout << n - cnt;
}
int main() {
solve();
return 0;
} |
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"
using namespace std;
constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;
//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;
void Solve() {
cin >> N;
string s, t, u;
cin >> s >> t >> u;
cout << string(N, '0') + string(N, '1') + string(1, '0') << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> T;
while (T--) {
Solve();
}
}
| #include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 5;
int n, a[N];
void code() {
cin >> n;
set<pair<int, int>> se;
for (int i = 0; i < n; i++) cin >> a[i], se.insert({a[i], i});
sort(a, a + n);
int mn = a[0];
for (int i = n - 1; i >= 0; i--) {
mn = __gcd(mn, a[i]);
}
cout << mn << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
// cin>>t;
while (t-- > 0) {
code();
}
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.