code_file1
stringlengths 87
4k
| code_file2
stringlengths 82
4k
|
---|---|
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int i,n,ed=0,md=0;
long double dd;
cin>>n;
long long int a[n];
for(i=0;i<n;i++){
cin>>a[i];
if(a[i]<0) a[i]=-a[i];
md+=a[i];
ed+=a[i]*a[i];
}
sort(a,a+n);
cout<<md<<endl;
dd=sqrt(ed);
cout<<fixed<<setprecision(15);
cout<<dd<<endl;
cout<<a[n-1]<<endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
ll sum(const vector<ll>& vec) {
ll ans = 0;
for (ll v: vec) ans += v;
return ans;
}
void solve(long long N, std::vector<long long> x){
vector<ll> absX(N);
rep(i, N) absX.at(i) = abs(x.at(i));
vector<ll> absXQ(N);
rep(i, N) absXQ.at(i) = absX.at(i) * absX.at(i);
cout << sum(absX) << endl;
cout << fixed << setprecision(9) << sqrt(double(sum(absXQ))) << endl;
cout << *max_element(all(absX)) << endl;
}
int main(){
long long N;
scanf("%lld",&N);
std::vector<long long> x(N);
for(int i = 0 ; i < N ; i++){
scanf("%lld",&x[i]);
}
solve(N, std::move(x));
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;
static const LL INF = 1LL << 60;
LD solve(long long A, long long B) {
LD ans = 100.0 * LD(A - B) / A;
return ans;
}
int main() {
cout.precision(20);
long long A, B;
std::cin >> A >> B;
cout << solve(A, B) << endl;
return 0;
}
| #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include <functional>
#include <iomanip>
#include<cmath>
#include<deque>
#include <math.h>
#include <queue>
#include <sstream>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265359
using namespace std;
using ll = long long;
int GetDigit(ll num) {
int a = 0;
while (num) {
num /= 10;
a++;
}
return a;
}
ll Get_keta_num(ll num) {
ll z = 0;
while (num) {
z += num % 10;
num /= 10;
}
return z;
}
void print(set<int> s) {
for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
cout << *it << " ";
}
cout << endl;
}
ll count_num_2(ll num) {
ll data = 0;
while (true) {
ll m = num % 1000;
ll k = num % 100;
if ((m % 8) == 0) {
data += 3;
num /= 8;
continue;
}
else if ((k % 4) == 0) {
data += 2;
num /= 4;
continue;
}
else if ((k % 2) == 0) {
data++;
num /= 2;
continue;
}
break;
}
return data;
}
ll facctorialMethod(int k) {
ll sum = 1;
for (int i = 1; i <= k; ++i)
{
sum *= i;
}
return sum;
}
//" "
ll Get_num_in_string(string s) {
int n = s.length(), z;
ll sur = 0;
for (int i = 0; i < n; i++) {
z = int(s[i] - '0');
if (z < 10) {
sur *= 10;
sur += z;
}
}
return sur;
}
ll ll_pow(int num, int zyousuu) {
ll ans = 1;
for (int i = 0; i < zyousuu; i++) {
ans *= num;
}
return ans;
}
string substrBack(std::string str, size_t pos, size_t len) {
const size_t strLen = str.length();
return str.substr(strLen - pos, len);
}
ll ll_gcd(ll x, ll y) {
if (x < y) {
ll a = x;
x = y;
y = a;
}
while (y > 0) {
ll r = x % y;
x = y;
y = r;
}
return x;
}
using Graph = vector<vector<int>>;
ll ll_lcm(ll a, ll b) {
return a * b / ll_gcd(a, b);
}
string get_words_from_end(string word, int num) {
return word.substr(word.size() - num, num);
}
string binary(ll bina) {
string ans = "";
if (bina == 0) {
ans = "0";
return ans;
}
if (bina == 1) {
ans = "1";
return ans;
}
while (bina != 0) {
int a = bina % 2;
char c = '0' + a;
ans += c;
bina -= a;
bina /= 2;
}
reverse(ans.begin(), ans.end());
return ans;
}
void YES() {
cout << "YES" << endl;
}
void NO() {
cout << "NO" << endl;
}
void Yes() {
cout << "Yes" << endl;
}
void No() {
cout << "No" << endl;
}
ll comb(ll N, ll i) {
vector<vector<long long int> > v(N + 1, vector<long long int>(N + 1, 0));
for (int i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (int k = 1; k < v.size(); k++) {
for (int j = 1; j < k; j++) {
v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
}
}
return v[N][i];
}
bool is_prime(long long N) {
if (N == 1) return false;
for (long long i = 2; i * i <= N; ++i) {
if (N % i == 0) return false;
}
return true;
}
bool divisor(long long n) {
vector<long long> ret;
for (long long i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n) ret.push_back(n / i);
}
}
sort(ret.begin(), ret.end()); // 昇順に並べる
bool x = false;
if (ret.size() == 8)x = true;
return x;
}
vector<bool> seen(100005, false);
vector<int> ans;
int count = 0;
void dfs(const Graph& G, int v) {
seen[v] = true; // v を訪問済にする
ans.push_back(v + 1);
// v から行ける各頂点 next_v について
for (auto next_v : G[v]) {
if (seen[next_v]) continue; // next_v が探索済だったらスルー
dfs(G, next_v); // 再帰的に探索
}
}
void cout_data(ll x) {
cout << x << endl;
}
int main() {
int A, B; cin >> A >> B;
int ans = 1;
for (int i = 2; i <= B;i++) {
int a_1 = (A + i - 1) / i;
int b_1 = B / i;
if (a_1 > b_1)continue;
if ((a_1 == 0) || (b_1 == 0))continue;
if (a_1 != b_1) {
if ((a_1 * i >= A) && (b_1 * i <= B)) {
if (a_1 * i < b_1 * i)ans = i;
}
}
}
cout << ans << endl;
return 0;
}
//std::cout << std::setprecision(2) << 3.141; // "3.1" |
//Starting in the name of Lord
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define Yes cout<<"Yes"<<endl
#define yes cout<<"yes"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define no cout<<"no"<<endl
#define YES cout<<"YES"<<endl
#define asort(x) sort((x).begin(),(x).end())
#define rsort(x) reverse(x.begin(),x.end())
#define ll long long
#define deciset(x) cout <<setprecision(x) <<fixed;
#define endl "\n"
#define pb push_back
#define mp make_pair
#define jotokkjon while
#define PI 2*acos(0.0)
#define boost ios::sync_with_stdio(false);cin.tie(0)
void solve()
{
ll a,b;
cin>>a>>b;
if( b % a) No;
else Yes;
}
int main()
{
boost;
#ifndef ONLINE_JUDGE
freopen("C:/Users/User/Desktop/C/input.txt", "r", stdin);
freopen("C:/Users/User/Desktop/C/output.txt", "w", stdout);
#endif
ll t=1;
// cin>>t;
while(t--)
{
solve();
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int M, H;
cin >> M >> H;
cout << ((H % M == 0) ? "Yes" : "No") << endl;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> Pair;
typedef tuple<int,int,int> tpl;
#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)
#define en "\n"
constexpr double EPS = 1e-9;
constexpr double PI = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;
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;}
void Main(){
int a,b; cin >> a >> b;
int c = a+b;
int d = b;
int ans;
if(c>=15 && d>=8) ans = 1;
else if(c>=10 && d>=3) ans = 2;
else if(c>=3) ans = 3;
else ans = 4;
cout << ans << en;
return;
}
int main(void){
cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
int t=1; //cin>>t;
REP(_,t) Main();
return 0;
} | #include<iostream>
using namespace std;
int main(){
int x,n,i;
char v;
cin >> n >> x;
for(i=1;i<=n;i++){
cin >> v;
if(v=='x'&&x>0)
x--;
else if(v=='o')
x++;
}
cout << x;
}
|
#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<cstring>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<deque>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<string>
#include<sstream>
#include<chrono>
#include<random>
#include<unordered_map>
#include<ctype.h>
#include<cassert>
#include<numeric>
#include<functional>
using namespace std;
typedef long long ll; typedef std::pair<ll, ll> pll; typedef std::pair<int, int> pii; typedef unsigned long long ull; typedef long double ldb; typedef double db;
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
template <class output_type, class input_type>
output_type Convert(const input_type& input) {
stringstream ss; output_type result;
ss.clear(); ss << input; ss >> result;
return result;
}
const double Pi = acos(-1.0); const int inf = 1 << 29, Mod = 1e9 + 7, N = 1e5 + 3; const ll INF = 1ll << 60;
inline ll qpow(ll a, ll b, ll mod = Mod, ll ans = 1) {
while (b) {
if (b & 1)ans = ans * a % mod;
a = a * a % mod; b >>= 1;
}return ans;
}
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }; ll lcm(ll a, ll b) { return a * b / (gcd(a, b)); }
pii EXgcd(int x, int y) { //return.first ny
if (!y) { return { 1,0 }; }pii a = EXgcd(y, (x + y) % y);
return { a.second, a.first - a.second * (x / y) };
}
inline bool Ezisprime(int n) {
if (n <= 1)return 0; if (n <= 3)return 1;
vector<int> ezp{ 5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 };
for (int i = 0; i < ezp.size(); i++)if (n == ezp[i])return 1;
for (int i = 2; i <= sqrt(n); i++)if (n % i == 0)return 0;
return 1;
}
inline int LIS(const vector<int> Origins, const int n) {
if (!n || !Origins.size()) return 0;
int len = 0; vector<int> d(n, 0); d[0] = Origins[0];
for (int i = 1; i < n; i++)
if (Origins[i] >= d[len])d[++len] = Origins[i];
else d[upper_bound(d.begin(), d.begin() + len, Origins[i]) - d.begin()] = Origins[i];
return len + 1;
}
inline int Alptonum(const char& a) { if (a <= 'z')return int(a - 'a'); else return int(a - 'A'); }
inline char Numtoalp(const int& n, bool& t) { if (!t)return char('a' + n); else return char('A' + n); }
inline bool cmp(const pii& a, const pii& b) { //default more and more larger
if (a.second == b.second)return a.first < b.first;
return a.second > b.second;
}
struct cmpstl { //reverse
inline bool operator()(const pii& a, const pii& b) {
if (a.second == b.second)return a.first > b.first;
return a.second < b.second;
}
};
//partial_sum(begin,end,place,minus<int>()) adjacent_differece(begin,end,place)
//count(begin(),end(),char=='x') count_if(begin(),end(),boolcmp) vector<int> p(n);iota(p.begin(), p.end(), 0);
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Code follows ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\\
//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV Code follows VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVII
int main()
{
ios::sync_with_stdio(0); cout.tie(0), cin.tie(0);
int n, m, q; cin >> n >> m >> q;
vector<pii>bags(n); vector<int>boxes(m);
for (auto& i : bags)cin >> i.first >> i.second;
for (auto& i : boxes)cin >> i;
sort(all(bags),cmp);
while (q--)
{
int l, r; cin >> l >> r; --l, --r;
vector<int> tboxes;
for (int i = 0; i < l; ++i)tboxes.emplace_back(boxes[i]);
for (int i = r + 1; i < m; ++i)tboxes.emplace_back(boxes[i]);
sort(all(tboxes));
// for (auto& box : tboxes)cout << box << ' ' << '\n';
ll ans = 0;
for (auto &bag:bags)
for (auto &box:tboxes)
if (box >= bag.first)
{
box=-1, ans += bag.second;
break;
}
cout << ans << "\n";
}
}
/*
3 4 3
1 9
5 3
7 8
1 8 6 9
4 4
1 4
1 3
*/ | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int,int>P;
//int v[50];
//int w[50];
int x[50];
int y[50];//クエリ作業用
int main(){
int n,m,q;
cin>>n>>m>>q;
vector<P>vec;
rep(i,n){
int w,v;
cin>>w>>v;
vec.push_back({v,w});
}
sort(vec.begin(),vec.end());
/*for(auto e:vec){
cout<<e.first<<" "<<e.second<<endl;
}*/
rep(i,m) cin>>x[i];
int ans=0;
//クエリ
rep(i,q){
ans=0;
int l,r;
cin>>l>>r;
l--;
r--;
for(int j=0;j<m;j++){
if(l<=j && j<=r){
y[j]=0;
}
else{
y[j]=x[j];
}
}
sort(y,y+m);
for(int k=n-1;k>=0;k--){
for(int l=0;l<m;l++){
if(vec[k].second<=y[l]){
ans+=vec[k].first;
y[l]=0;
break;
}
}
}
cout<<ans<<endl;
}
}
|
/// BISMILLA HIRRAHMANIR RAHIM
/// ALLAH IS ALMIGHTY
/// ALLAH IS MUCH MORE CREATIVE
#include<bits/stdc++.h>
#define faster ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define mem(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(), (a).end()
#define pii pair<ll,ll>
#define ci(X) cin>>X
#define cii(X, Y) cin>>X>>Y
#define ciii(X, Y, Z) cin>>X>>Y>>Z
#define ciiii(W, X, Y, Z) cin>>W>>X>>Y>>Z
#define co(x) cout << x<< "\n"
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define dbg(x) cout<<#x<<"="<<(x)<<endl;
#define dbg2(x,y) cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<endl;
#define dbg3(x,y,z) cout<<#x<<"="<<(x)<<" "<<#y<<"="<<(y)<<" "<<#z<<"="<<(z)<<endl;
#define pq priority_queue<ll, vector<ll>, greater<ll>>
using namespace std;
using ll = int64_t;
using ii= pair<ll,ll>;
const double PI = acos(-1.0);
const int mx = 2e5+5;
const int M= 1e9+7;
int dr[]= {0,-1,0,1,-1,-1,1,1}; /// first 4 are right,up,left,bottom
int dc[]= {1,0,-1,0,1,-1,-1,1};
int kx[]= {-1,-2,-2,-1,1,2,2,1}; /// knight move
int ky[]= {2,1,-1,-2,-2,-1,1,2};
bool valid(int row,int col){
return (row>=1) && (row<=8) && (col>=1) && (col<=8);
}
ll gcd(ll a,ll b){
if(b==0) return a;
return gcd(b, a % b);
}
bool sq(ll x){
ll y= sqrt(x);
if(y*y==x) return true;
return false;
}
void Solve()
{
ll i,j,x,y,z,sum=0,ans=0,n,m=0,k=0,l=0,p=0,q=0;
cin>>n;
ll a[n+2];
rep(i,n) cin>>a[i];
vector<ll>b; ll mini= 1e18;
for(i=0; i<(1<<(n-1)); i++){ /// (1 <<(n-1)) why?? can't understand;
ll total=0;
for(j=0; j<n; j++){ /// all possible subset
total= total | a[j];
if(i & (1<<j)){
b.pb(total); //dbg2(total,i);
total=0;
}
}
if(total) b.pb(total);
ll cal=0;
for(j=0; j<b.size(); j++)
cal= cal ^ b[j];
b.clear();
mini= min(mini,cal);
}
cout<< mini<< "\n";
return;
}
int main()
{
faster;
int TC=1;
//cin >> TC;
while(TC--){
Solve();
}
return 0;
}
/**
*/
| #include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
// @@ !! LIM()
int main(/* int argc, char *argv[] */) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << setprecision(20);
ll N; cin >> N;
vector<ll> A(N);
for (ll i = 0; i < N; i++) cin >> A[i];
ll ans = 1LL << 40;
for (ll x = 0; x < (1LL<<(N-1)); x++) {
ll y = x | (1LL<<(N-1));
ll val = 0;
ll cur = 0;
for (ll i = 0; i < N; i++) {
cur |= A[i];
if ((y >> i) & 1) {
val ^= cur;
cur = 0;
}
}
ans = min(ans, val);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
struct UnionFind {
vector<int> par, siz;
UnionFind(int n) : par(n), siz(n, 1) {
iota(par.begin(), par.end(), 0);
}
int root(int x) {
if (par[x] == x)
return x;
else
return par[x] = root(par[x]);
}
void unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y) return;
if (siz[x] < siz[y]) swap(x, y);
siz[x] += siz[y];
par[y] = x;
}
bool same(int x, int y) {
return root(x) == root(y);
}
int size(int x) {
return siz[root(x)];
}
};
signed main() {
int n, m;
cin >> n >> m;
ll a[n], b[n];
rep(i, n) {
cin >> a[i];
}
rep(i, n) {
cin >> b[i];
}
UnionFind uf(n);
int c, d;
rep(i, m) {
cin >> c >> d;
c--;
d--;
uf.unite(c, d);
}
map<int, ll> suma, sumb;
rep(i, n) {
suma[uf.root(i)] += a[i];
sumb[uf.root(i)] += b[i];
}
for (auto i : suma) {
if (i.second != sumb[i.first]) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
struct Edge {
int to, nxt;
} E[N << 1];
int n, m, cnt, head[N], a[N], b[N];
long long sum;
bool vis[N];
void addedg(int u, int v) {
E[++cnt] = (Edge){v, head[u]};
head[u] = cnt;
}
void dfs(int u) {
vis[u] = true;
sum += a[u] - b[u];
for (int i = head[u]; i; i = E[i].nxt) {
int v = E[i].to;
if (vis[v]) continue;
dfs(v);
}
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
for (int i = 1; i <= m; i++) {
int u, v;
scanf("%d%d", &u, &v);
addedg(u, v);
addedg(v, u);
}
for (int i = 1; i <= n; i++)
if (!vis[i]) {
sum = 0;
dfs(i);
if (sum) {
puts("No");
return 0;
}
}
puts("Yes");
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;
void Main() {
ll n;
R n;
ll c[n][n];
rep(i,n)rep(j,n) R c[i][j];
set<vector<ll> > s1,s2;
rep(i,n) {
vector<ll> a,b;
rep(j,n-1) {
a.pb(c[i][j+1]-c[i][j]);
b.pb(c[j+1][i]-c[j][i]);
}
s1.in(a);
s2.in(b);
}
if(s1.size()>1||s2.size()>1) {
pr("No");
return;
}
vector<ll> v=*s1.begin();
ll M=0,x=0;
rep(i,v.size()) {
x+=v[i];
M=min(M,x);
}
vector<ll> b;
x=-M;
b.pb(x);
rep(i,v.size()) {
x+=v[i];
b.pb(x);
}
vector<ll> a;
rep(i,n) a.pb(c[i][0]-b[0]);
pr("Yes");
PR(a,n);
PR(b,n);
}
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
| ///Bismillahir Rahmanir Rahim
/*
Author: Tanzin Ahammad
*/
#include<bits/stdc++.h>
#define u64 uint64_t
#define ll long long
#define endl "\n"
#define PI acos(-1)
#define fi first
#define si second
#define pb push_back
#define set0(arr) memset(arr, 0, sizeof(arr))
#define setinf(arr) memset(arr, 126, sizeof(arr))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define all(x) (x).begin(),(x).end()
#define sz(v) ((ll)(v).size())
#define mem(a,b) memset(a, b, sizeof(a))
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define mchk(mask,pos) (mask & (1<<pos))
#define mset(mask,pos) (mask bitor (1<<pos))
#define munset(mask,pos) (mask ^ (1<<pos))
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using pll = pair<ll, ll> ;
using vl = vector<ll> ;
using vpll = vector<pll> ;
using mll = map<ll, ll> ;
using mcl = map<char, ll> ;
using msl = map<string,ll> ;
using sl = set<ll> ;
using sc = set<char> ;
const int N = 1e6+5;
const int mod = (int) 1e9 + 7;
ll arr[N];
ll sumd(ll a,ll b){return (((a%mod)+(b%mod))%mod);}
ll muld(ll a,ll b){return (((a%mod)*(b%mod))%mod);}
ll subd(ll a,ll b){return (((a%mod)-(b%mod)+mod)%mod);}
int main()
{
IOS;
ll tc,n,x,i,j;
cin>>n;
ll M[n][n];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin>>M[i][j];
}
}
for(i=0;i<n;i++)
{
vl vt1,vt2;
for(j=0;j<n;j++)
{
vt2.pb(M[i][j]);
x=M[j][j]-M[i][j];
if(x<0) break;
vt1.pb(x);
}
if(sz(vt1)<n) continue;
ll f=0;
for(ll i1=0;i1<n;i1++)
{
for(ll j1=0;j1<n;j1++)
{
if((vt1[i1]+vt2[j1])!=M[i1][j1])
{
f=1;break;
}
}
}
if(f==0)
{
cout<<"Yes"<<endl;
for(auto p:vt1) cout<<p<<" ";
cout<<endl;
for(auto p:vt2) cout<<p<<" ";
cout<<endl;
return 0;
}
}
cout<<"No"<<endl;
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; }
//}}}
int main(){
cin.tie(0); ios::sync_with_stdio(false);
int n; cin >> n;
vector<int> inout(2 * n);
auto no = [&](){
cout << "No" << '\n';
exit(0);
};
for(int i = 1; i <= n; i++){
int a, b;
cin >> a >> b;
a--; b--;
if(a >= 0 && b >= 0 && a >= b){
no();
}
if(a >= 0){
if(inout[a]){ no(); }
inout[a] = i;
}
if(b >= 0){
if(inout[b]){ no(); }
inout[b] = - i;
}
}
printde(inout);
vector<int> dp(2 * n + 1);
dp[0] = 1;
for(int i = 0; i < 2 * n; i++){
if(!dp[i]){ continue; }
for(int j = 1; i + j * 2 <= 2 * n; j++){
bool ok = true;
for(int k = 0; k < j; k++){
if(inout[i + k] < 0){
ok = false;
}else if(inout[i + k] > 0){
ok &= inout[i + j + k] == 0 || inout[i + j + k] == - inout[i + k];
}
}
for(int k = 0; k < j; k++){
if(inout[i + j + k] > 0){
ok = false;
}else if(inout[i + j + k] < 0){
ok &= inout[i + k] == 0 || inout[i + k] == - inout[i + j + k];
}
}
if(ok){
printde(i, j, dp);
dp[i + j * 2] = 1;
}
}
}
if(!dp[2 * n]){
no();
}
cout << "Yes" << '\n';
}
| //#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9+7; //998244353;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}
//using mint = atcoder::modint1000000007;
ll max_rectangle(const vector<int>& vec) {
ll rtn = 0;
stack<pii> stk;
auto calstk = [&](int ps, int ht){
int t = ps;
for( ;!stk.empty() && stk.top().second >= ht; stk.pop()){
if(stk.top().second == ht) return;
t = stk.top().first;
rtn = max(rtn, 1LL * (ps-t) * stk.top().second);
}
if(ht >0 ) stk.push(pii(t, ht));
};
rep(i, sz(vec)) calstk(i, vec[i]);
calstk(sz(vec), 0);
return rtn;
}
int main(){
cin.tie(0); ios_base::sync_with_stdio(false);
int n;
cin >>n;
VI a(n);
rep(i, n) cin >>a[i];
ll ans = max_rectangle(a);
cout << ans <<"\n";
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f;
const double pi=3.1415926535897932384626;
inline ll read(){
ll x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
int a,b,c;
int main(){
a=read(),b=read(),c=read();
if(c){
if(a<b) printf("Aoki\n");
else printf("Takahashi\n");
}
else{
if(a>b) printf("Takahashi\n");
else printf("Aoki\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 ll long long
#define ff first
#define ss second
#define INF 1000000000000000000
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define vll vector<pair<ll,ll>>
#define vi vector<int>
#define sz(a) (int)a.size()
#define all(v) v.begin(), v.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define PI 3.141592653589793
#define o_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setpll tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, 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 getRand(int l, int r)
{
uniform_int_distribution<int> uid(l, r);
return uid(rng);
}
ll power(ll b, ll e, ll m) {
if (e == 0) return 1;
if (e & 1) return b * power(b * b % m, e / 2, m) % m;
return power(b * b % m, e / 2, m);
}
ll power( ll b, ll e)
{
if (e == 0) return 1;
if (e & 1) return b * power(b * b, e / 2);
return power(b * b, e / 2);
}
ll modI(ll a, ll m)
{
ll m0 = m, y = 0, x = 1;
if (m == 1)return 0;
while (a > 1) {
ll q = a / m;
ll t = m; m = a % m;
a = t; t = y;
y = x - q * y; x = t;
}
if (x < 0) {x += m0;}
return x;
}
void solve() {
// possibly pick the largest prime ?
ll a, b, c, d;
cin >> a >> b >> c >> d;
for (ll x = 0; x <= 1e5 + 5; x++) {
if (a + x * b <= d * x * c) {
cout << x; return;
}
}
cout << "-1";
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("lcm.in", "r", stdin);
// freopen("test_output.txt", "w", stdout);
int t = 1;
// cin >> t;
for (int ntc = 1; ntc <= t; ntc++) {
// cout << "Case #" << ntc << ": ";
solve();
}
return 0;
} |
#include <iostream>
#define MOD 1000000007
int main()
{
int n = 0;
long long t = 0, a = 0, b = 0;
std::cin >> n;
for(int i = 0; i < n; ++i)
{
long long result = 0, x1 = 0, x2 = 0, x3 = 0, x4 = 0;
long long tmp1 = 0, tmp2 = 0;
std::cin >> t >> a >> b;
if((t - a - b) >= 0)
{
x4 = ((t - a - b) + 2)*((t - a - b) + 1) / 2;
}
else
{
x4 = 0;
}
x4 %= MOD;
x3 = (2 * x4) % MOD;
x2 = ((t - a + 1)) * ((t - b + 1)) % MOD - x3;
x1 = (x2) * (x2) % MOD;
tmp1 = ((t - a + 1)) * ((t - a + 1)) % MOD;
tmp2 = ((t - b + 1)) * ((t - b + 1)) % MOD;
result = (tmp1 * tmp2) - x1;
result %= 1000000007;
std::cout << result << std::endl;
}
return 0;
} | /*ॐ नमो भगवते वासुदेवाय नमः*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9 + 7;
const double pi = 3.14159265359;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
int binpow(int a, int b, int m) {
a %= m;
int res = 1;
while (b > 0) {
if (b & 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
int inverse(int x){
return binpow(x, MOD - 2, MOD);
}
void solve()
{
int n, ako = 0;
cin >> n;
vector<int> a(n), b(n), c;
for(int i = 0; i < n; i++){
cin >> a[i] >> b[i];
c.push_back(2 * a[i] + b[i]);
ako -= a[i];
}
sort(c.rbegin(), c.rend());
int cnt = 0;
for(int i = 0; i < n; i++){
ako += c[i];
cnt++;
if(ako > 0) break;
}
cout << cnt << endl;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
solve();
cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n ";
} |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int m;
cin>>m;
vector<int> arr(20,0);
for(int i=0;i<n;i++){
string s;
cin>>s;
int size=0;
for(int j=0;j<m;j++){
if(s[j]=='1'){
size++;
}
}
arr[size]++;
}
long long answer=0;
long long kentebi=0;
long long luwebi=0;
for(int i=0;i<=20;i++){
if(i%2==0){
luwebi+=arr[i];
}else{
kentebi+=arr[i];
}
}
for(int i=0;i<=20;i++){
if(i%2==0){
answer+=(arr[i]*kentebi);
}else{
answer+=(arr[i]*luwebi);
}
}
cout<<answer/2<<endl;
return 0;
} | #include <iostream>
using namespace std;
typedef long long ll;
int main()
{
int n, m;
cin >> n >> m;
string s[100005];
for(int i = 0; i < n; i++) cin >> s[i];
ll c[2]{0};
for(int i = 0; i < n; i++){
int d = 0;
for(int j = 0; j < m; j++) d += s[i][j] - '0';
c[d % 2]++;
}
cout << c[0] * c[1] << endl;
}
|
#include <iostream>
#include <vector>
#include <stdexcept>
#include <string>
#include <strstream>
#include <sstream>
int main(){
int N;
scanf("%d\n",&N);
int num=0;
for (int i=1; i<=N; i++) {
std::string S;
std::string V;
S = std::to_string(i);
std::stringstream ss;
ss << std::oct << i;
V = ss.str();
for (int j=0; j<V.size(); j++) {
if (S[j]=='7' || V[j]=='7') {
num++;
break;
}
}
}
printf("%d\n",N-num);
} |
//#include <atcoder/maxflow.hpp>
#include <memory>
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
#include <complex>
#include <thread>
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
typedef long long ll;
using namespace std;
//using namespace atcoder;
ll modd = (1000LL * 1000LL * 1000LL + 7LL);
//ll modd = 998244353;
int main() {
ios_base::sync_with_stdio(false);
cout.precision(17);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<int> rand_gen(0, modd); // rand_gen(rng) gets the rand no
auto start = chrono::steady_clock::now();
// readint(test_cases);
int test_cases = 1;
forr(t, 1, test_cases) {
readint(n);
int ct = 0;
forr(i,1,n) {
bool has7 = false;
int nn = i;
while (nn>0) {
if (nn%10==7) {has7=true;}
nn/=10;
}
nn = i;
while (nn>0) {
if (nn%8==7) {has7=true;}
nn/=8;
}
if (!has7) {
++ct;
}
}
cout << ct << endl;
}
// auto stop = chrono::steady_clock::now();
// auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
// cout << "Duration: " << duration.count() << endl;
return 0;
}
|
/*
** author : Dhiraj Govindvira
** date : 19 June 2021 ~ Saturday
** time : 05:32:38 PM
*/
#include <bits/stdc++.h>
using namespace std;
#ifdef DHIRAJ
#include "D:/dhiraj/Programming/debug.h"
#else
#define dbg(...) 1
#define cerr if(0) cerr
#endif
using ll = long long int;
#define endl '\n'
template <typename T, typename U>
inline istream & operator >> (istream &in, pair<T, U> &p) {
in >> p.first >> p.second;
return in;
}
template <typename T>
inline istream & operator >> (istream &in, vector<T> &v) {
for(T &x : v) in >> x;
return in;
}
void solve(ll &tc)
{
ll n;
cin >> n;
ll day = 0;
ll x = 0, y = 1;
while(x < n) {
day++;
x += y;
y++;
}
cout << day << endl;
}
int main()
{
#ifdef DHIRAJ
freopen("D:/dhiraj/Programming/i1.txt", "r", stdin);
freopen("D:/dhiraj/Programming/o1.txt", "w", stdout);
freopen("D:/dhiraj/Programming/e1.txt", "w", stderr);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
ll rep = 2;
while(rep--) {
ll tc = 1;
for(ll i = 1; i <= tc; i++) {
// cout << "Case #" << i << ": ";
cerr << "Case #" << i << "\n";
solve(i);
}
if(dbg()) break;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
int a[N];
void solve()
{
int n;
cin>>n;
int ans = 0 ;
for(int i=1;i<=N;i++)
{
a[i] =i;
a[i]+=a[i-1];
if(a[i]>=n)
{
cout<<i<<endl;
return ;
}
}
}
int main()
{
ios::sync_with_stdio(false);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define bs binary_search
#define fi first
#define se second
using pii = pair<int,int>;
using ll = long long;
const int maxn = 4e5;
const int inf = 1e9;
const int mod = 1e9+7;
void open_io() { freopen("in","r",stdin); freopen("out","w",stdout); }
void fast_io() { ios::sync_with_stdio(0); cout.tie(0); cin.tie(0); }
int n,ans;
vector<int> adj[maxn+5];
set<int> num;
set<int> s;
int dfs(int u)
{
int ret = adj[u].size();
s.insert(u);
for(int v : adj[u])
if(not s.count(v))
ret += dfs(v);
return ret;
}
int32_t main ()
{
//open_io();
fast_io();
cin >> n;
for(int i=1;i<=n;i++)
{
int x,y;
cin >> x >> y;
adj[x].pb(y);
adj[y].pb(x);
num.insert(x);
num.insert(y);
}
for(int x : num)
if(not s.count(x))
{
int tmp = s.size();
int edge = dfs(x)/2;
int sze = s.size() - tmp;
ans += min(sze,edge);
}
cout << ans << endl;
}
| #pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
using pii = pair<int, int>;
template<typename T>
using Prior = std::priority_queue<T>;
template<typename T>
using prior = std::priority_queue<T, vector<T>, greater<T>>;
#define X first
#define Y second
#define eb emplace_back
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int getRand(int L, int R) {
if (L > R) swap(L, R);
return (int)(rng() % ((uint64_t)R - L + 1) + L);
}
template<typename T1, typename T2>
ostream& operator << (ostream &os, pair<T1, T2> &p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template<typename T>
ostream& operator << (ostream &os, vector<T> &vec) {
for (int i = 0; i < vec.size(); ++i) {
if (i) os << " ";
os << vec[i];
}
return os;
}
const int maxn = 2E5 + 5;
vector<int> adj[maxn], dep(maxn);
vector<pii> timestamp(maxn);
vector<int> st[maxn]; /// record timestamp in st[depth]
void dfs(int now) {
static int tok = 0;
st[dep[now]].eb(timestamp[now].X = ++tok);
for (auto x : adj[now]) dfs(x);
timestamp[now].Y = ++tok;
}
void solve() {
int N; cin >> N;
for (int i = 2, par; i <= N; ++i) cin >> par, adj[par].eb(i), dep[i] = dep[par] + 1;
dfs(1);
int Q; cin >> Q;
while (Q--) {
int u, d; cin >> u >> d;
/// query how many x \in st[d] \cap [in_u, out_u] ///
cout << upper_bound(ALL(st[d]), timestamp[u].Y)
- lower_bound(ALL(st[d]), timestamp[u].X) << "\n";
}
}
int32_t main() {
fastIO();
int t = 1; // cin >> t;
for (int _ = 1; _ <= t; ++_) {
// cout << "Case #" << _ << ": ";
solve();
}
return 0;
} |
#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;
}
/*----------------------------------------------------------------------------------------------------*/
long long Modpow(long long a, int n, long long mod){
if(n == 0) return 1;
if(n%2 == 0){
long long res = Modpow(a, n/2, mod);
return res * res % mod;
}
return a * Modpow(a, n-1, mod) % mod;
}
const int MX = 1e6+5;
int main() {
int n;
cin >> n;
string s;
cin >> s;
V<int> a(n);
rep(i,n) {
if(s[i] == 'B') a[i] = 0;
if(s[i] == 'W') a[i] = 1;
if(s[i] == 'R') a[i] = 2;
}
V<int> fact(MX);
V<int> cnt(MX);
fact[0] = 1;
Rep(i,MX-1) {
fact[i] = fact[i-1];
cnt[i] = cnt[i-1];
if(i%3 == 0) {
int j = i;
while(j%3 == 0) cnt[i]++, j /= 3;
fact[i] *= j, fact[i] %= 3;
}
else fact[i] *= i, fact[i] %= 3;
}
int d = n-1;
lint tot = 0;
rep(i,n) { // dCi % 3
int cnt3 = cnt[d]-(cnt[i]+cnt[d-i]);
if(cnt3) continue;
tot += fact[d]*fact[i]*fact[d-i] % 3 * a[i];
// cout << fact[d]*fact[i]*fact[d-i] % 3 << endl;
}
if(d % 2 == 1) tot = (3-tot) % 3;
tot = ((tot % 3) + 3) % 3;
if(tot == 0) cout << 'B' << endl;
if(tot == 1) cout << 'W' << endl;
if(tot == 2) cout << 'R' << endl;
} | #pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
const int mod = 1e9 + 7;
int dp[2][100][100];
int AB[200], *A = AB, *B = AB + 100;
constexpr ll modpow(ll A, ll B) {
ll kotae = 1;
while (B > 0) {
if (B & 1) kotae = kotae * A % mod;
A = A * A % mod;
B >>= 1;
}
return kotae;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M, K;
cin >> N >> M >> K;
rep(i, N) {
cin >> A[i];
}
auto mae = dp[0], ato = dp[1];
int are = modpow(2 * M, mod - 2);
rep(i, M) {
int x, y;
cin >> x >> y;
x--;
y--;
if (x < y) swap(x, y);
mae[x][x]--;
mae[x][y]++;
mae[y][y]--;
}
rep(x, N) rep(y, x + 1) {
mae[x][y] = (ll(mae[x][y] + mod) * are + (x == y)) % mod;
mae[y][x] = mae[x][y];
}
const ll ma = (1ll << 32) - 1;
rep(i, 30) {
if (K >> i & 1) {
rep(i, N) {
ll t1 = 0, t2 = 0;
rep(j, N) {
auto tmp = (ll)mae[i][j] * A[j];
t1 += tmp >> 32;
t2 += tmp & ma;
}
B[i] = ((t1 % mod << 32) + t2) % mod;
}
swap(A, B);
}
if (!K | i >= 31 - __builtin_clz(K)) break;
rep(x, N) rep(y, x + 1) {
auto tmp1 = mae[x];
auto tmp2 = mae[y];
ll t1 = 0, t2 = 0;
rep(z, N) {
auto tmp = *tmp1++ * (ll)*tmp2++;
t1 += tmp >> 32;
t2 += tmp & ma;
}
ato[y][x] = (ato[x][y] = ((t1 % mod << 32) + t2) % mod);
}
swap(mae, ato);
}
rep(i, N) co(A[i]);
Would you please return 0;
} |
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long INF=1e18;
long long mod=1e9+7;
#define debug 0
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main(){
long long n,m;
cin>>n>>m;
cout<<(modpow(10,n,m*m)/m)%m<<endl;
}
/*
*/
| #include <bits/stdc++.h>
using namespace std;
int main()
{
long long int b,c;
cin>>b>>c;
if(c==1 && b!=0)
cout<<"2\n";
else if(c<=2*b)
cout<<2*c-1<<"\n";
else
{
if(b>0)
cout<<c+2*b-1<<"\n";
else
cout<<c+abs(b)*2<<"\n";
}
}
|
#include<bits/stdc++.h>
#define FULL(x,y) memset(x,y,sizeof(x))
#define ll long long
#define SZ(x) (int)x.size()
#define pb push_back
using namespace std;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
const int N = 1000006;
const ll mod = 1e9 + 7;
ll n, m, k;
ll inv[N];
ll cal_inv(ll x) {
ll ans = 1, p = mod - 2;
while(p) {
if (p & 1) ans = (ans * x) % mod;
x = (x * x) % mod;
p >>= 1;
}
return ans;
}
ll cal(ll a, ll b) {
ll ans = 1;
for(ll i = a - b + 1; i <= a; ++i) ans = (ans * i) % mod;
for(ll i = 1; i <= b; ++i) ans = (ans * inv[i]) % mod;
return ans;
}
int main() {
cin >> n >> m >> k;
if (n > m + k) {
cout << 0;
return 0;
}
for(int i = 1; i <= n; ++i) {
inv[i] = cal_inv(i);
}
ll ans1 = cal(n + m, n);
ll tmp = n - k - 1 < 0 ? 0 : cal(n + m, n - k - 1);
ans1 = (ans1 - tmp + mod) % mod;
cout << ans1 << endl;
return 0;
}
| #include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
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 all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;
int H, W;
char nap[2020][2020];
ll memo[2020][2020];
ll sum_tate[2020][2020];
ll sum_yoko[2020][2020];
ll sum_naname[2020][2020];
ll solve(int i, int j){
if(memo[i][j] != -1) return memo[i][j];
if(i == H && j == W) return 1;
ll res = 0;
if(i < H && nap[i+1][j] == '.'){
ll tate = solve(i+1, j);
sum_tate[i][j] = sum_tate[i+1][j] + tate;
sum_tate[i][j] %= MOD;
}
if(j < W && nap[i][j+1] == '.'){
ll yoko = solve(i, j + 1);
sum_yoko[i][j] = sum_yoko[i][j+1] + yoko;
sum_yoko[i][j] %= MOD;
}
if(i < H && j < W && nap[i+1][j+1] == '.'){
ll naname = solve(i + 1, j + 1);
sum_naname[i][j] = sum_naname[i+1][j+1] + naname;
sum_naname[i][j] %= MOD;
}
return memo[i][j] = (sum_yoko[i][j] + sum_tate[i][j] + sum_naname[i][j]) % MOD;
}
int main(){
cin >> H >> W;
REP(i,H)REP(j,W)cin >> nap[i][j];
rep(i,2020)rep(j,2020)memo[i][j] = -1, sum_naname[i][j] = 0, sum_tate[i][j] = 0, sum_yoko[i][j] = 0;
cout << solve(1,1) << endl;
//REP(i,H){REP(j,W)cout << memo[i][j] << ' '; cout << endl;}
return 0;
}
|
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <=(int)(n); i++)
#define all(V) V.begin(),V.end()
#define pi 3.1415926535897932384626
#define fi fixed<<setprecision(10)
#define MOD 1000000007
#define ll long long
using namespace std;
//lower_bound(a+l, a+r, x) - a a[l] から a[r-1] までの中で初めて x 以上となるようなインデックスを返します。
//count(a + l, a + r, x)/find(a + l, a + r + 1, x)
int gcd(ll m,ll n){
if(n==0) return m;
return gcd(n,m%n);
}
int fact(ll n){
ll x=1;REP(i,n)x*=i;
return x;
}
const ll M = pow(10,9)+7;
vector<ll> fac(1000001); //n!(mod M)
vector<ll> ifac(1000001); //k!^{M-2} (mod M)
ll mpow(ll x, ll n){ /*x^n(mod M)*/
ll ans = 1;
while(n!=0){
if(n&1) ans = ans*x % MOD;
x = x*x % MOD;n=n>>1;
}
return ans;
}
ll comb(ll a, ll b){
fac[0] = 1;ifac[0] = 1;
for(ll i = 0; i<1000000; i++){
fac[i+1] = fac[i]*(i+1) % MOD;ifac[i+1] = ifac[i]*mpow(i+1, MOD-2) % MOD;
}
if(a==0&&b==0)return 1;
if(a<b||a<0)return 0;
ll tmp=ifac[a-b]*ifac[b]%MOD;
return tmp*fac[a]%MOD;
}
ll nck(ll a,ll b){
ll s=1,x=1;
rep(i,b){
s=(s*(a-i))/x;
x++;
}
return s;
}
ll perm(ll a, ll b){
fac[0] = 1;ifac[0] = 1;
for(ll i = 0; i<1000000; i++){
fac[i+1] = fac[i]*(i+1) % MOD;ifac[i+1] = ifac[i]*mpow(i+1, M-2) % MOD;
}
if(a < b) return 0;
ll tmp = ifac[a-b] % MOD;
return tmp * fac[a] % MOD;
}
ll dupc(ll a,ll b){
fac[0] = 1;ifac[0] = 1;
for(ll i = 0; i<1000000; i++){
fac[i+1] = fac[i]*(i+1) % MOD;ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M;
}
if(a == 0 && b == 0)return 1;
if(a < 0 || b == 0)return 0;
ll tmp = ifac[a-1]* ifac[b] % MOD;
return tmp * fac[a+b-1] % MOD;
}
void make_prime(){
vector<int> prime;
prime.push_back(2);
for(int i=3;i<=pow(10,5);i++){
bool pri=true;
rep(j,prime.size()) if(i%prime[j]==0){ pri=false; break;}
if(pri) prime.push_back(i);
}
}
int main(){
int n;cin>>n;
vector<ll> a(n);
rep(i,n) cin>>a[i];
sort(a.begin(),a.end());
vector<ll> vec(n+1);
vec[0]=0;
rep(i,n) vec[i+1]=vec[i]+a[i];
ll ans=0;
rep(i,n){
ans+=(vec[n]-vec[i])-a[i]*(n-i);
}
cout<<ans<<endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2 * 100010;
int a[N];
int presum[N];
bool cmp(int &a,int &b){
return a > b;
}
signed main(){
#ifndef ONLINE_JUDGE
freopen("sumofdiff.txt","r",stdin);
#endif
ios::sync_with_stdio(false);
int n;cin >> n;
for(int i = 1 ; i <= n ; i++) {
cin >> a[i];
}
sort(a + 1,a+n+1,cmp);
for(int i = 1 ; i <= n; i++){
presum[i] = presum[i-1] + a[i];
}
// for(int i = 1; i <= n ; i++) cout << a[i] <<",";
// cout << endl;
int ans = 0;
for(int i = 1; i <= n ; i++){
//(long long )
ans += (((n-i) * a[i] )- (presum[n] - presum[i]));
}
cout << ans;
}
|
//2021-04-18 12:10:11
/*折半枚舉*/
#include <bits/stdc++.h>
using namespace std;
int n,a[100],id[2];
long long t;
vector<long long>re[2];//re[0]是小的那部分枚舉出來的東東,re[1]是大的那部分枚舉出來的東東
bool d[100]={0};
int target,from;//紀錄正在枚舉的頭和尾
bool big=false;//現在是否在枚舉大的
void f(int id){
if(id==target){
long long ans=0;
for(int i=from;i<target;i++)ans+=d[i]*a[i];
re[big].emplace_back(ans);
return;}
f(id+1);
d[id]=1;
f(id+1);
d[id]=0;
return;}
int main(){
//輸入
scanf("%d %lld",&n,&t);
for(int i=0;i<n;i++)scanf("%d",&a[i]);
sort(a,a+n);
//枚舉小堆的
from=0,target=(n+1)/2;
f(0);
//枚舉大堆的
from=target,target=n,big=true;
f(from);
//整理枚舉出來的東東
sort(re[0].begin(),re[0].end());
sort(re[1].begin(),re[1].end());
//雙指針求解
long long ans=0;
int l1=re[0].size(),l2=re[1].size(),j=0;
for(int i=0;i<l1;i++){
if(re[0][i]>t)break;
ans=max(re[0][i],ans);
while(j<l2-1&&(re[1][j]+re[0][i])<t)j++;
while(j>=0&&(re[1][j]+re[0][i])>t)j--;
if(j>=0&&(re[1][j]+re[0][i])<=t)ans=max(re[0][i]+re[1][j],ans);
if(ans==t)break;}
printf("%lld\n",ans);
return 0;} | #include<cstdio>
#include<algorithm>
#define Q 200005
using namespace std;
#define gc() getchar()
inline bool ig(char c){return c>='0'&&c<='9';}
inline void read(int &oi){char c;int f=1,res=0;while(c=gc(),(!ig(c))&&c^'-');c^'-'?res=(c^48):f=-1;while(c=gc(),ig(c))res=res*10+(c^48);oi=f*res;}
inline void print(int oi){if(oi<0)putchar('-'),oi=~oi+1;if(oi>9)print(oi/10);putchar(oi%10+48);}
int l,r,ans;
inline int gcd(int x,int y){return !y?x:gcd(y,x%y);}
inline int maxx(int x,int y){return x>y?x:y;}
inline void solve(int tim){
for(int i=2;i*i<=tim;++i){
if(tim%i)continue;
if(tim-(tim/i)>=l)ans=maxx(ans,tim/i);
if(tim-i>=l)ans=maxx(ans,i);
}
}
int main(){
read(l);read(r);ans=gcd(l,l+1);
for(int i=l+2;i<=r;++i)solve(i);print(ans);putchar('\n');
return 0;
} |
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define mkpr make_pair
#define ins insert
#define sb substr
#define con continue
#define ub upper_bound
#define lb lower_bound
#define bp __builtin_popcountll
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define take(v,n) for(i=0;i<n;i++) cin>>v[i];
#define print(any) for(auto i:any) cout<<i<<" ";
#define ee endl
#define pb push_back
#define vll vector<ll>
#define vld vector<ld>
#define vvll vector< vector<ll> >
#define vvld vector< vector<ld> >
#define mll map<ll,ll>
#define umll unordered_map<ll,ll>
#define f(i,x,y) for(ll i=x;i<y;i++)
#define INF LLONG_MAX
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define p2(n,x) cout << fixed << setprecision(x) <<n<<" ";
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define mod 1000000007
using namespace std;
ll power(ll x, ll y);
ll mpower(ll x, ll y, ll p);
ll modInv(ll a, ll m);
ll gcdExtended(ll a, ll b, ll *x, ll *y);
bool isPrime(ll n);
void slv()
{
ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,t,u,w,x,y,z;
string s,s1,s2;
char ch;
cin>>n;
vll ar={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
mll mp;
vll num(n);
take(num,n);
k=1;
ll ans=INF;
while(k<(1<<16))
{
p=k;
c=1;
f(i,0,15)
{
if(p&1) c*=ar[i];
p=p>>1;
}
a=1;
f(i,0,n)
{
if(__gcd(c,num[i])==1)
{
a=0;
break;
}
}
if(a) ans=min(ans,c);
k++;
}
cout<<ans<<ee;
}
int main()
{
fast
ll t;
t=1;
//cin>>t;
//fun();
while(t--)
{
slv();
}
return 0;
}
/*
*/
ll modInv(ll a, ll m){
ll x, y;
ll g = gcdExtended(a, m, &x, &y);
ll res = (x%m + m) % m;
return res;
}
ll gcdExtended(ll a, ll b, ll *x, ll *y){
if (a == 0){
*x = 0, *y = 1;
return b;
}
ll x1, y1;
ll gcd = gcdExtended(b%a, a, &x1, &y1);
*x = y1 - (b/a) * x1;
*y = x1;
return gcd;
}
ll mpower(ll x, ll y, ll p){
ll res = 1;
x = x % p;
while(y > 0){
if(y & 1) res = (res*x) % p;
y = y>>1;
x = (x*x) % p;
}
return res;
}
ll power(ll x, ll y){
ll res = 1;
while (y > 0){
if (y & 1) res = res*x;
y = y>>1;
x = x*x;
}
return res;
}
bool isPrime(ll n){
if (n <= 1) return false;
if (n <= 3) return true;
if (n%2 == 0 || n%3 == 0) return false;
ll p=sqrt(n);
for(int i=5;i<=p;i=i+6)
if (n%i == 0 || n%(i+2) == 0)
return false;
return true;
}
| #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b){
if(a<b)swap(a,b);
if(b==0)return a;
return gcd(b,a%b);
}
int main(){
int n;
scanf("%d",&n);
long long arr[n];
for(int i=0;i<n;i++)scanf("%lld",&arr[i]);
long long p[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
long long ans=1012345678012345678LL;
for(int i=0;i<(1<<15);i++){
long long prod=1;
int bm=i;
while(bm&(-bm)){
prod*=p[__builtin_ctz(bm)];
bm-=(bm&(-bm));
}
bool poss=1;
for(int j=0;j<n;j++){
if(gcd(prod,arr[j])==1){poss=0;break;}
}
if(poss)ans=min(ans,prod);
}
printf("%lld",ans);
}
|
#include <bits/stdc++.h>
using namespace std;
int main(){
long double X, Y, R;
cin >> X >> Y >> R;
X = abs(X) + abs(ceil(R));
Y = abs(Y) + abs(ceil(R));
long long answer = 0;
for(long long x = ceil(X - R); x <= X + R; ++x){
long double dx = abs(X - x);
long double dy = sqrt(R * R - dx * dx);
long long y1 = floor(Y + dy);
long long y2 = ceil(Y - dy);
answer += (y1 - y2 + 1);
}
cout << answer;
return 0;
} | #include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
#define CC(_...) fprintf(stderr,_)
using namespace std;
typedef long long LL;
enum{N=200007};
int n,A[N],C[N];
map<int,vector<int> > G;
void upd(int u,int k=-1) {
for(;u<=n;u+=u&-u) C[u]+=k;
}
int sum(int u) {
int r=0;
for(;u;u&=u-1) r+=C[u];
return r;
}
int main() {
scanf("%d",&n);
For(i,1,n) scanf("%d",&A[i]),upd(i,1);
Dor(i,n,1) G[A[i]+i].push_back(i);
LL ans=0;
For(i,1,n) {
int x;
scanf("%d",&x);
if(G[x+i].empty()) puts("-1"),exit(0);
ans+=sum(G[x+i].back())-1;
upd(G[x+i].back()),G[x+i].pop_back();
}
cout<<ans;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}
int nt[5005];
int na[5005];
int ng[5005];
int nc[5005];
int sum(int* ar, int l, int r) {
--l;
return ar[r] - ar[l];
}
int main() {
fastio;
ll ans=0;
ll N;
string s;
cin >> N >> s;
rep1(i,N) {
nt[i] = nt[i-1];
na[i] = na[i-1];
ng[i] = ng[i-1];
nc[i] = nc[i-1];
if (s[i-1] == 'A') ++na[i];
if (s[i-1] == 'T') ++nt[i];
if (s[i-1] == 'C') ++nc[i];
if (s[i-1] == 'G') ++ng[i];
}
rep(j,N) rep(i,j) {
int l = i+1, r = j+1;
if (sum(nt, l, r) < sum(na, l, r))
continue;
if (sum(na, l, r) < sum(nt, l, r))
continue;
if (sum(nc, l, r) < sum(ng, l, r))
continue;
if (sum(ng, l, r) < sum(nc, l, r))
continue;
++ans;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define vll vector<long long>
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL);
int lcm(int a, int b) { return (a / __gcd(a, b)) * b; }
ll bigMod(ll b, ll e, ll mod) {
if (e == 0) return 1 % mod;
if (e % 2 == 0) {
ll half = bigMod(b, e / 2, mod);
return half * half % mod;
} else return bigMod(b, e - 1, mod) * b % mod;
}
void factors(ll n) {
int i, j;
vll arr;
for (i = 1; i <= sqrt(n); i++)
if (n % i == 0) {
j = n / i;
arr.push_back(i);
if (i != j)
arr.push_back(i);
}
}
#define pi acos(-1)
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl "\n"
#define decimal(p) fixed<<setprecision(p)
#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define vd vector<double>
#define pfd(x) printf("%d\n", x)
#define pfc(x) printf("%c\n", x)
#define pfs(x) printf("%s\n", x)
#define scd(x) scanf("%d", &x)
#define scc(x) scanf("%c", &x)
#define scf(x) scanf("%f", &x)
#define scs(x) scanf("%s", x)
#define msi map<string, int>
#define msc map<string, char>
#define msf map<string, double>
#define msd map<string, double>
#define mx 100000000000
int main() {
vi arr;
int x;
for (int i = 0; i < 4; ++i) {
cin>>x;
arr.push_back(x);
}
sort(all(arr));
cout<<arr[0]<<endl;
return 0;
} |
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end
int C[5][5];
int nCr(int n,int r){
if(C[0][0]==0){
rep(i,0,5){
C[i][0]=C[i][i]=1;
rep(j,1,i){
C[i][j]=(C[i-1][j-1]+C[i-1][j])%3;
}
}
}
int res=1;
rep(_,0,30){
res*=C[n%3][r%3];
n/=3,r/=3;
}
return res;
}
int main(){
int n;
cin>>n;
string s;
cin>>s;
int res=0;
rep(i,0,n){
if(s[i]=='R')continue;
if(s[i]=='W')res=(res+nCr(n-1,i))%3;
if(s[i]=='B')res=(res+nCr(n-1,i)*2)%3;
}
if(!(n&1))res=(3-res)%3;
if(res==0)puts("R");
if(res==1)puts("W");
if(res==2)puts("B");
return 0;
} | // give up
#include <bitset>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <list>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
// alias, using declaration
using llint = long long; using ldouble = long double;
template <class T = llint> using vector = std::vector<T>;
template <class T = llint> using deque = std::deque<T>;
template <class T = llint> using list = std::list<T>;
template <class T = llint, class U = llint> using umap = std::unordered_map<T, U>;
template <class T = llint, class U = llint> using ummap = std::unordered_multimap<T, U>;
template <class T = llint> using uset = std::unordered_set<T>;
template <class T = llint> using umset = std::unordered_multiset<T>;
template <class T = llint, class U = T> using pair = std::pair<T, U>;
template <class T = llint> using varray = std::valarray<T>;
template <class T = llint, class U = vector<T>, class V = std::less<class U::value_type>> using pqueue = std::priority_queue<T, U, V>;
using std::array; using std::bitset; using std::string; using std::tuple;
// constant
constexpr llint INF = 0x7FFFFFFFFFFFFFFF;
constexpr llint INVALID = 0x8000000000000000;
namespace io {
// in
template <class... T, size_t... S> auto in(std::index_sequence<S...>) {tuple<T...> t; (..., (std::cin >> std::get<S>(t))); return t;}
template <class... T, size_t... S> auto in(std::index_sequence<S...>, size_t n) {tuple<vector<T>...> t{vector<T>(n)...}; for (size_t i = 0; i < n; i++) (..., (std::cin >> std::get<S>(t)[i])); return t;}
template <size_t N, class T = llint, class... U> auto in() {static_assert(N >= 1); if constexpr (N > 1) return in<N - 1, T, T, U...>(); else return in<T, U...>(std::index_sequence_for<T, U...>());}
template <size_t N, class T = llint, class... U> auto in(size_t n) {static_assert(N >= 1); if constexpr (N > 1) return in<N - 1, T, T, U...>(n); else return in<T, U...>(std::index_sequence_for<T, U...>(), n);}
template <size_t N, class T = llint> auto in(size_t n, size_t m) {static_assert(N == 1); vector<vector<T>> v(n, vector<T>(m)); for (auto&& vi : v) for (auto&& vij : vi) std::cin >> vij; return std::make_tuple(v);}
// out
template <class T, class... U> void out(const T& a, const U&... b) {std::cout << a << (sizeof...(b) ? " " : "\n"); if constexpr (sizeof...(b)) out(b...);}
template <class T, class U = const char*> void out(const vector<T>& a, U d = " ") {for (auto&& b : a) std::cout << b << (&b != &a.back() ? d : "\n");}
}
int main() {
// input
auto [N, c] = io::in<1, llint, string>();
// solve
umap<char> c2n = {{'B', 0}, {'W', 1}, {'R', 2}};
vector<> f(N), g(N);
g[0] = 1;
for (llint i = 1; i < N; i++) {
g[i] = i;
}
for (llint i = 3; i < N; i *= 3) {
for (llint j = i; j < N; j += i) {
f[j]++;
g[j] /= 3;
}
}
for (llint i = 1; i < N; i++) {
f[i] += f[i - 1];
g[i] = (g[i - 1] * g[i]) % 3;
}
auto bc_mod3 = [&f, &g](llint n, llint r) {
return f[n] - f[r] - f[n - r] > 0 ? 0 : (g[n] * g[r] * g[n - r]) % 3;
};
llint n_top = 0;
for (llint i = 0; i < N; i++) {
n_top += c2n[c[i]] * bc_mod3(N - 1, i);
}
n_top %= 3;
if (~N & 1) {
n_top = (3 - n_top) % 3;
}
char result = array<char, 3>{'B', 'W', 'R'}[n_top];
// output
io::out(result);
} |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p, a, b) for (ll p = a; p < b; p++)
#define F first
#define S second
using namespace std;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll, ll> pll;
int main()
{
ll t, i, j, k, ans, n, m, sum = 0;
//cin>>t;
t = 1;
while (t--)
{
cin >> n >> k >> m;
rep(p, 0, n - 1)
{
cin >> i;
sum += i;
}
ll mi = m * n - sum;
if (mi > k)
cout << "-1";
else
cout << max(0LL, mi);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
int N,K,M; cin >> N >> K >> M;
vector<int> v(N-1);
int A = 0;
for(int i = 0; i< N-1; i++){
cin >> v.at(i);
A += v.at(i);
}
if(K >= N * M - A){
cout << max(0,N * M - A) << endl;
}else{
cout << "-1" << endl;
}
} |
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long int li;
typedef long long ll;
typedef long double ld;
typedef vector<lli> vlli;
typedef vector<li> vli;
typedef vector<int> vi;
typedef vector<ld> vld;
#define all(x) (x).begin(),(x).end()
lli MOD=1e9+7;
/*vlli fun(lli q)
{
vlli ret;
for(lli i = 2; i*i <= q; i++)
{
if( q % i==0)
{
if(i<=q/i)
{
ret.push_back(i);
break;
}
else
break;
}
}
sort(ret.rbegin(),ret.rend());
return ret;
}*/
/*int prime(int a)
{
for(lli i=2; i<=sqrt(a); i++)
{
if(a%i==0)
return 0;
}
return 1;
}*/
/*
lli fac[300001] ;
lli power(lli x, lli y, lli MOD)
{
if(y == 0) return 1 ;
lli p = power(x, y/2, MOD) % MOD ;
p = (p * p) % MOD ;
return (!(y & 1))? p : (x * p) % MOD ;
}
lli modInverse(lli a, lli MOD)
{
return power(a, MOD - 2, MOD) ;
}
lli nCr(lli n,lli r)
{
if(n < r) return 0 ;
else if(r == 0) return 1 ;
lli ret{fac[n]%MOD} ;
ret *= modInverse(fac[r], MOD) ;
ret %= MOD ;
ret *= modInverse(fac[n-r], MOD) ;
ret %= MOD ;
return ret ;
}*/
/*lli n=50000000;/range of number;
vlli c;
void sieve()
{
vector<bool>is_prime(n+1,true);
for(lli i=2; i<=n; i++)
{
if(is_prime[i]==true)
{
is_prime[i]=false;
c.push_back(i);
for(lli j=i*i; j<=n; j+=i)
{
is_prime[j]=false;
}
}
}
}
*/
int main()
{
cin.tie(nullptr)->sync_with_stdio(false) ;
lli t{1};
//cin >> t;
cout<<setprecision(15);
/*fac[0] = 1;
for(lli i{1} ; i <= 300000 ; i++)
fac[i] = (fac[i-1]*i)%MOD ;*/
while(t--)
{
lli a{},b{};
cin >> a >> b;
lli sum{};
for(lli i = 1; i<a; i++)
{
cout << i<<" ";
sum+=i;
}
cout << 100000000<<" ";
sum+=100000000;
for(lli i=1; i <=b-1; i++)
{
cout << -i << " ";
sum-=(i);
}
cout << (-sum);
}
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
int ans[3000];
int a,b;
void work(){
int tot=0;
if(a==b){
for(int i=1;i<=a;i++)ans[++tot]=i,ans[++tot]=-1*i;
return ;
}
if(a>b){
int fro=1001,sum=0;
while(a>b){
ans[++tot]=fro++;
sum+=ans[tot];
a--;
}
ans[++tot]=fro++;
sum+=ans[tot];
a--;
ans[++tot]=-1*sum;
b--;
}
else{
int en=-1001,sum=0;
while(b>a){
ans[++tot]=en--;
sum+=ans[tot];
b--;
}
ans[++tot]=en--;
sum+=ans[tot];
b--;
ans[++tot]=-1*sum;
a--;
}
for(int i=1;i<=a;i++)ans[++tot]=i,ans[++tot]=-1*i;
}
int main(){
scanf("%d%d",&a,&b);
int len=a+b;
work();
for(int i=1;i<len;i++)printf("%d ",ans[i]);
cout<<ans[len]<<endl;
return 0;
} |
#include<iostream>
#include<math.h>
using namespace std;
int main() {
long s, p;
cin >> s >> p;
long limit = sqrt(p);
for(long n = 1; n <= limit; ++n) {
if(p % n == 0 && n + (p / n) == s) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
}
| ///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll gcd(int a,int b)
{
if(b==0)
return a;
return gcd(b,a%b);
}
long long binpow(long long base,long long power)
{
long long result=1;
while (power>0)
{
if (power%2==1)
result = (result*base);
base = (base*base);
power/=2;
}
return result;
}
#define in(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld %lld",&x,&y)
#define in3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define out(x) printf("%lld\n",x)
#define cy printf("YES\n")
#define cn printf("NO\n")
#define inf 1e18
#define neg -1e18
#define mx 2111111
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fi first
#define si second
#define ce cout<<endl
#define pb push_back
#define vc(x) x.begin(),x.end()
#define pb push_back
#define pii pair<ll,ll>
#define debug printf("ok\n");
#define pvg pii, vector<pii>, greater<pii>;
#define mod 1000000007
int main(){
//freopen("test.txt","r",stdin);
//fast
ll t;
ll i,p,j,ans=0,sum=0,s=0,n,m;
in2(p,s);
bool f=false;
for(i=1;i*i<=s;i++)
{
if(s%i==0)
{
if(i+(s/i)==p) {f=true;break;}
}
}
if(f) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
cin >> x >> y;
if(x == 0 && y == 1) {
cout << '2';
} else if(x == 1 && y == 0) {
cout << '2';
} else if(x == 1 && y == 2) {
cout << '0';
} else if(x == 0 && y == 2) {
cout << '1';
} else if(x == 2 && y == 1) {
cout << '0';
} else if(x == 2 && y == 0) {
cout << '1';
} else {
cout << x;
}
} | #include<bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
using namespace std;
int main () {
FASTIO;
int n,m;
cin>>n>>m;
int ans=0;
if(n==m) {
cout<<m;
}
else {
cout<<3-n-m;
}
} |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a * a + b * b < c * c) cout << "Yes";
else cout << "No";
} | #include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif
// $ cp-batch SquareInequality | diff SquareInequality.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address SquareInequality.cpp && ./a.out
/*
4/24/2021
5:00-
*/
int A,B,C;
bool solve() {
return A*A+B*B<C*C;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout<<setprecision(12)<<fixed;
cin>>A>>B>>C;
cout<<(solve()?"Yes":"No")<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// THINGS TO REMEMBER
// ENDL is slow, '\n' is fast
// Clear everything (including graphs) between test cases
// use anti-anti-hash: https://codeforces.com/blog/entry/62393
// pb-ds: https://codeforces.com/blog/entry/11080
// check when to use LLONG_MAX/LLONG_MIN vs INT_MAX or INT_MIN
// You frequently suffer from confirmation bias - you trust your initial solution and miss simple things.
// When you hit a roadblock, remember to rethink the solution ground up, not just try hacky fixes
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47
vector<ll> primes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
ll ans=LLONG_MAX;
ll tot = 1<<(15);
for(int i=0;i<tot;i++){
ll currNum=1;
ll tt = i;
for(int j=0;j<15;j++){
if(tt&1){
currNum*=primes[j];
}
tt>>=1;
}
// cerr<<i<<endl;
// cerr<<currNum<<endl;
bool works=true;
for(int j=0;j<n;j++){
if(__gcd(currNum, (ll)arr[j])==1){
works=false;
break;
}
}
cerr<<i<<endl;
if(works){
ans=min(ans,currNum);
}
}
cout<<ans<<endl;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <sstream>
#define fileio \
freopen("C:\\Users\\PRISM17\\Desktop\\in.txt", "r", stdin); \
freopen("C:\\Users\\PRISM17\\Desktop\\out.txt", "w", stdout);
#define fastio \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define dbg(x) cout << #x << " : " << x << endl;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define lson (id << 1)
#define rson (id << 1 | 1)
#define mid (st[id].l + st[id].r >> 1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const int inf = 0x3f3f3f3f;
int prime[60], v[60], tot;
ll ans = -1;
int a[60];
int n;
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a % b);
}
void dfs(int cur, ll prod) {
if (cur == tot + 1) {
int f = true;
for (int i = 1; i <= n; i++) {
if (gcd(a[i], prod) == 1) {
f = false;
break;
}
}
if (f) {
if (ans == -1) ans = prod;
else ans = min(ans, prod);
}
return;
}
dfs(cur + 1, prod * prime[cur]);
dfs(cur + 1, prod);
}
int main() {
for (int i = 2; i <= 50; i++) {
if (!v[i]) {
prime[++tot] = i;
for (int j = i * i; j <= 50; j += i) {
v[j] = true;
}
}
}
cin >> n;
rep(i, 1, n) cin >> a[i];
dfs(1, 1);
cout << ans << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
const int N=(1<<20)+10;
int primes[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
long long f[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
long long a,b;
cin>>a>>b;
f[0]=1;
for(long long i=a;i<=b;++i){
int res=0;
for(int j=0;j<20;++j){
if(i%primes[j]==0)res|=(1<<j);
}
for(int j=0;j<(1<<20);++j){
if(!(res&j))f[res|j]+=f[j];
}
}
long long ans=0;
for(int i=0;i<(1<<20);++i)ans+=f[i];
cout<<ans<<"\n";
return 0;
} | #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
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 gcd(ll a,ll b){
return b==0?a:gcd(b,a%b);
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll A,B;
cin>>A>>B;
vector<ll> v;
for(ll i=A;i<=B;i++) v.push_back(i);
int V=v.size();
vector<vector<int>> g(V);
rep(i,V){
for(int j=i+1;j<V;j++){
if(gcd(v[i],v[j])!=1){
g[i].push_back(j);
g[j].push_back(i);
}
}
}
ll ast=0,bst=0;
rep(k,V){
if(k<60) ast+=(1ll<<k);
else bst+=(1ll<<(k-60));
}
map<tuple<int,ll,ll>,ll> dp;
auto solve = [&](auto &&solve,int now,ll ast,ll bst)->ll{
if(dp.count(mkt(now,ast,bst))) return dp[mkt(now,ast,bst)];
if(now==V) return 1;
ll res=0;
{
ll nexast=ast,nexbst=bst;
if(now<60&&((1ll<<now)&ast)) nexast^=(1ll<<now);
if(now>=60&&((1ll<<(now-60))&bst)) nexbst^=(1ll<<(now-60));
res+=solve(solve,now+1,nexast,nexbst);
}
//res+=solve(solve,now+1,ast,bst);
if(now<60&&((1ll<<now)&ast)){
ll nexast=ast,nexbst=bst;
nexast^=(1ll<<now);
for(auto j:g[now]){
if(j<60&&(ast&(1ll<<j))) nexast^=(1ll<<j);
if(j>=60&&(bst&(1ll<<(j-60)))) nexbst^=(1ll<<(j-60));
}
res+=solve(solve,now+1,nexast,nexbst);
}
if(now>=60&&((1ll<<(now-60))&bst)){
ll nexast=ast,nexbst=bst;
nexbst^=(1ll<<(now-60));
for(auto j:g[now]){
if(j<60&&(ast&(1ll<<j))) nexast^=(1ll<<j);
if(j>=60&&(bst&(1ll<<(j-60)))) nexbst^=(1ll<<(j-60));
}
res+=solve(solve,now+1,nexast,nexbst);
}
return dp[mkt(now,ast,bst)]=res;
};
ll ans=solve(solve,0,ast,bst);
cout<<ans<<endl;
return 0;
}
|
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define float long double
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define g(t, n) get<n>(t)
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;
const int M = (int)2e5+5;
const int mod = (int)1e9+7;
int cnt[M], p[M];
void solve()
{
int n, j = 0;
cin>>n;
f(i, 0, n)
{
cin>>p[i];
cnt[p[i]]++;
while(cnt[j]) j++;
cout<<j<<endl;
}
}
int32_t main()
{
IOS
int t = 1;
// cin>>t;
f(tno, 1, t+1)
{
// cout<<"Case #"<<tno<<": ";
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
template <class T = ll> using V = vector<T>;
#define loop(n) while(n--)
#define rep(i,n) for(int i=0; i<(n);++i)
#define repp(i, l, r) for(int i = (l); i < (r); ++i)
#define all(v) (v).begin(), (v).end()
#define LL(n) int n;cin >> n
int main()
{
LL(n);
V<ll> a(n);
rep(i, n) cin >> a[i];
sort(all(a));
ll MIN = accumulate(all(a), 0);
if(MIN%2==1) MIN = MIN/2 + 1;
else MIN = MIN/2;
int K = 100000;
vector<vector<bool>> dp(n + 1, vector<bool>(K, false));
// 初期化
for (int i = 0; i <= n; i++) {
dp[i][0] = true;
}
// 更新
for (int i = 0; i < n; i++) {
for (int k = 0; k <= K; k++) {
if (k - a[i] >= 0) dp[i + 1][k] = dp[i + 1][k] | dp[i][k - a[i]];
dp[i + 1][k] = dp[i + 1][k] | dp[i][k];
}
}
rep(i, 100000){
if(dp[n][i+MIN]) {
cout << i+MIN << endl;
break;
}
}
return 0;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main() {
int N; cin >> N;
vector<ll> A(N);
for (int i = 0; i < N; i++) cin >> A[i];
sort(A.begin(), A.end());
vector<ll> S(N+1);
for (int i = 0; i < N; i++) S[i+1] = S[i] + A[i];
ll ans = 0;
for (int i = 1; i < N; i++) ans += A[i] * i - S[i];
cout << ans << endl;
return 0;
} | // Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long
/*
*/
void run_case() {
int n;
cin >> n;
int a[n], b[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
int res = 0;
for (int i = 0; i < n; i++) {
res += a[i] * b[i];
}
cout << (res == 0 ? "Yes" : "No") << '\n';
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int T = 1;
// cin >> T;
for (int t = 1; t <= T; t++) {
// cout << "Case #" << t << ": ";
run_case();
}
return 0;
} |
#include <bits/stdc++.h>
#include <random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef long double ld; typedef pair<lint, lint> plint; typedef pair<ld, ld> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;++i)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;--i)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
#define fi first
#define se second
struct fast_ios { fast_ios() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_;
template<class T> auto add = [](T a, T b) -> T { return a + b; };
template<class T> auto f_max = [](T a, T b) -> T { return max(a, b); };
template<class T> auto f_min = [](T a, T b) -> T { return min(a, b); };
template<class T> using V = vector<T>;
using Vl = V<lint>; using VVl = V<Vl>;
template< typename T > ostream& operator<<(ostream& os, const vector< T >& v) {
for (int i = 0; i < (int)v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : "");
return os;
}
template< typename T >istream& operator>>(istream& is, vector< T >& v) {
for (T& in : v) is >> in;
return is;
}
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; }
lint gcd(lint a, lint b) { if (b == 0) return a; else return gcd(b, a % b); }
lint ceil(lint a, lint b) { return (a + b - 1) / b; }
lint digit(lint a) { return (lint)log10(a); }
lint e_dist(plint a, plint b) { return abs(a.fi - b.fi) * abs(a.fi - b.fi) + abs(a.se - b.se) * abs(a.se - b.se); }
lint m_dist(plint a, plint b) { return abs(a.fi - b.fi) + abs(a.se - b.se); }
void Worshall_Floyd(VVl& g) { REP(k, SZ(g)) REP(i, SZ(g)) REP(j, SZ(g)) chmin(g[i][j], g[i][k] + g[k][j]); }
const lint MOD1000000007 = 1000000007, MOD998244353 = 998244353, INF = 2e18;
lint dx[8] = { 1, 0, -1, 0, 1, -1, 1, -1 }, dy[8] = { 0, 1, 0, -1, -1, -1, 1, 1 };
bool YN(bool flag) { cout << (flag ? "YES" : "NO"); return flag; } bool yn(bool flag) { cout << (flag ? "Yes" : "No") << endk; return flag; }
struct Edge {
lint from, to;
lint cost;
lint idx;
Edge() {
}
Edge(lint u, lint v, lint c, lint i) {
cost = c;
from = u;
to = v;
idx = i;
}
bool operator<(const Edge& e) const {
return cost < e.cost;
}
};
struct WeightedEdge {
lint to;
lint cost;
WeightedEdge(lint v, lint c = 1) {
to = v;
cost = c;
}
bool operator<(const WeightedEdge& e) const {
return cost < e.cost;
}
};
using WeightedGraph = V<V<WeightedEdge>>;
typedef pair<plint, lint> tlint;
typedef pair<plint, plint> qlint;
typedef pair<char, lint> valchar;
lint N, X;
int main() {
cin >> N >> X;
Vl arr(N);
cin >> arr;
lint minv = INF;
FOR(m, 1, N + 1) {
V<VVl> dp(N + 1, VVl(N + 1, Vl(N + 1, -1)));
dp[0][0][0] = 0;
REP(i, N) {
REP(j, N + 1) {
REP(k, N) {
if (dp[i][j][k] == -1) continue;
chmax(dp[i + 1][j + 1][(dp[i][j][k] + arr[i]) % (m)], dp[i][j][k] + arr[i]);
chmax(dp[i + 1][j][k], dp[i][j][k]);
}
}
}
REP(j, N + 1) {
if (dp[N][m][j] == -1) continue;
if ((X - dp[N][m][j]) % m != 0) continue;
chmin(minv, (X - dp[N][m][j]) / m);
}
}
cout << minv << endk;
}
| #include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define debug(typ...) fprintf(stderr, typ)
using namespace std;
int fastin() {
reg int x = 0, ch = getchar(), f = 0;
while(!isdigit(ch)) (ch == '-') && (f = 1), ch = getchar();
while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
const int MAXN = 110;
int n, ma[MAXN << 1], dp[MAXN][MAXN];
int match(reg int d, reg int u) {
int fl = 1;
if(ma[d]) {
if(ma[d] <= n * 2) fl &= (ma[d] == u);
else fl &= (ma[d] == n * 2 + 1);
}
if(ma[u]) {
if(ma[u] <= n * 2) fl &= (ma[u] == d);
else fl &= (ma[u] == n * 2 + 2);
}
if(ma[d] == n * 2 + 1 && ma[u] == n * 2 + 2) fl = 0;
return fl;
}
int dfs(reg int l, reg int r) {
if(~dp[l][r]) return dp[l][r];
int len = r - l + 1, fl = 1;
for(reg int i = l; i <= r && fl; ++i) fl &= match(l + i - 1, l + i + len - 1);
if(fl) return dp[l][r] = 1;
for(reg int i = l; i < r && !fl; ++i) fl |= dfs(l, i) && dfs(i + 1, r);
return dp[l][r] = fl;
}
void work() {
n = fastin();
bool flag = 1;
for(reg int i = 1; i <= n && flag; ++i) {
int a = fastin(), b = fastin();
if(a != -1 && b != -1 && a >= b) flag = 0;
else {
if(a == -1 && b == -1) continue;
else if(a == -1) {
if(ma[b]) flag = 0;
else ma[b] = n * 2 + 2;
} else if(b == -1) {
if(ma[a]) flag = 0;
else ma[a] = n * 2 + 1;
} else {
if(ma[a] || ma[b]) flag = 0;
else ma[a] = b, ma[b] = a;
}
}
}
memset(dp, -1, sizeof(dp));
if(!flag) puts("No");
else puts(dfs(1, n) ? "Yes" : "No");
}
signed main() {
int _ = 1;
// _ = fastin();
while(_--) {
work();
}
return 0;
}
|
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma optimize("JARU SOSISONI")
using namespace std;
#define int long long
#define fast cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define geometry cout.setf(ios::fixed); cout.precision(15);
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
const ll INF = 2e18 + 100;
const int MOD1 = 998244353;
const int MOD = 1e9 + 7;
const int N = 135000;
const int SIZE = 30100;
const int LOG = 21;
const int K = 18;
vector<vector<int> > gr;
vector<vector<int> > dist;
vector<int> c;
int n, m, k;
void bfs(int st, int ind) {
queue<int> q;
vector<int> d(n, INF);
d[st] = 0;
q.push(st);
while (!q.empty()) {
int v = q.front();
q.pop();
for (int u : gr[v]) {
if (d[u] == INF) {
d[u] = d[v] + 1;
q.push(u);
}
}
}
for (int i = 0; i < k; i++) {
dist[ind][i] = d[c[i]];
}
}
int dp[K][N];
signed main() {
#ifdef hedgehog
freopen("A.in", "r", stdin);
#endif // parasha
fast;
cin >> n >> m;
gr.resize(n);
for (int i = 0; i < m; i++) {
int v, u;
cin >> v >> u;
v--; u--;
gr[v].push_back(u);
gr[u].push_back(v);
}
cin >> k;
c.resize(k);
for (int &i : c) cin >> i;
for (int &i : c) i--;
dist.resize(k, vector<int>(k));
for (int i = 0; i < k; i++) {
bfs(c[i], i);
}
for (int i = 0; i < k; i++) {
for (int j = 0; j < N; j++) {
dp[i][j] = INF;
}
}
for (int i = 0; i < k; i++) {
dp[i][1 << i] = 1;
}
for (int mask = 1; mask < (1 << k); mask++) {
for (int v = 0; v < k; v++) {
if (dp[v][mask] == INF) continue;
//cout << v << ' ' << mask << '\n';
for (int u = 0; u < k; u++) {
if (((mask >> u) & 1) == 0) {
//cout << v << ' ' << u << ' ' << dist[v][u] << '\n';
dp[u][mask + (1 << u)] = min(dp[u][mask + (1 << u)], dp[v][mask] + dist[v][u]);
}
}
}
}
int ans = INF;
for (int i = 0; i < k; i++) {
ans = min(ans, dp[i][(1 << k) - 1]);
}
if (ans == INF) cout << -1 << '\n';
else cout << ans << '\n';
}
| #include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
vector <int> dy = {0, 1, 0, -1};
vector <int> dx = {1, 0, -1, 0};
const int INF = 1000000000;
const ll INFLL = 100000000000000000;
int main(){
int n; cin >> n;
int m; cin >> m;
vector <vector<int>> G(n);
rep(i, m){
int a, b; cin >> a >> b;
a --;
b --;
G.at(a).push_back(b);
G.at(b).push_back(a);
}
int k; cin >> k;
vector <int> is_v(n);
vector <int> is_zip(n, -1);
rep(i, k){
int c; cin >> c;
c --;
is_v.at(c) = 1;
is_zip.at(c) = i;
}
//各i,jについてc_i ~ c_jの最短距離を求める
vector <vector <int>> dist(k, vector<int>(k, INF));
for(int i = 0; i < n; i ++){
if(is_v.at(i) == 0) continue;
deque <pair<int, int>> d; d.push_back(make_pair(i, 0));
vector <int> seen(n, -1); seen.at(i) = 1;
while(d.size()){
auto p = d.front();
d.pop_front();
int now = p.first;
int cost = p.second;
if(is_v.at(now) != 0){
dist.at(is_zip.at(i)).at(is_zip.at(now)) = min(dist.at(is_zip.at(i)).at(is_zip.at(now)), cost);
}
for(auto next: G.at(now)){
if(seen.at(next) != -1) continue;
int next_cost = cost + 1;
seen.at(next) = 1;
d.push_back(make_pair(next, next_cost));
}
}
}
// for(int i = 0; i < k; i ++){
// rep(j, k){
// //dist.at(i).at(j) ++;
// cout << dist.at(i).at(j) << " ";
// }
// cout << endl;
// }
//求めた距離から巡回セールスマンを行う
vector <vector <int>> dp((1 << k), vector<int>(k, INF));
rep(i, k){
dp.at((1 << i)).at(i) = 1;
}
rep(s, (1 << k)){
if(s == 0) continue;
rep(i, k){
if(!((s >> i) & 1)) continue;
int tmp = INF;
rep(j, k){
tmp = min(tmp, dp.at(s ^ (1 << i)).at(j) + dist.at(j).at(i));
}
//cout << tmp << endl;
dp.at(s).at(i) = min(dp.at(s).at(i), tmp);
}
}
int ans = INF;
for(auto tmp: dp.at((1 << k) - 1)) ans = min(ans, tmp);
if(ans == INF){
cout << -1 << endl;
return 0;
}
cout << ans << endl;
// insert into Johnnys (name, team, bornIn, bloodType, birthYear) VALUES ('joshima', 'tokio', 'nara', 'o',1970);
// insert into Johnnys (name, team, bornIn, bloodType, birthYear) VALUES ('kokubun', 'tokio', 'tokyo', 'o',1974);
// insert into Johnnys (name, team, bornIn, bloodType, birthYear) VALUES ('matsuoka', 'tokio', 'hokkaido', 'a',1977);
// insert into Johnnys (name, team, bornIn, bloodType, birthYear) VALUES ('nagase', 'tokio', 'kanagawa', 'o',1978);
// insert into Johnnys (name, team, bornIn, bloodType, birthYear) VALUES ('ohno', 'arashi', 'tokyo', 'a',1980);
// insert into Johnnys (name, team, bornIn, bloodType, birthYear) VALUES ('sakurai', 'arashi', 'tokyo', 'a',1982);
// insert into Johnnys (name, team, bornIn, bloodType, birthYear) VALUES ('aiba', 'arashi', 'chiba', 'ab',1982);
// insert into Johnnys (name, team, bornIn, bloodType, birthYear) VALUES ('ninomiya', 'arashi', 'tokyo', 'a',1983);
// insert into Johnnys (name, team, bornIn, bloodType, birthYear) VALUES ('matsumoto', 'arashi', 'tokyo', 'a',1983);
} |
#include <iostream>
#include <vector>
#include <cstring>
#define int long long
using namespace std;
const int maxn = 2e5 + 1;
const int mod = 1e9 + 7;
int N;
struct edge{
int to, w;
};
vector<edge > G[maxn];
int dis[maxn];
void dfs(int u, int f) {
for(auto& e :G[u]) {
if(e.to == f) continue;
dis[e.to] = dis[u] ^ e.w;
dfs(e.to, u);
}
}
void init() {
cin >> N;
for(int i = 1; i < N; ++i) {
int u, v, w;
cin >> u >> v >> w;
G[u].push_back(edge{v, w});
G[v].push_back(edge{u, w});
}
}
signed main() {
init();
dfs(1, 0);
int ans = 0;
for(int c = 0; c < 60; ++c) {
int cnt[2] = {0, 0};
for(int i = 1; i <= N; ++i) {
cnt[(dis[i] >> c) & 1] ++;
}
ans += ((1ll << c) % mod) * (cnt[0] * cnt[1] % mod);
ans %= mod;
}
cout << ans;
return 0;
} | #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
ll n,q;
vector<int> g[200010];
int a[200010],b[200010];
vector <int> depth;
void dfs(int a,int d){
depth[a]=d;
for(int i :g[a]){
if(depth[i]==-1)dfs(i,d+1);
}
}
ll ans[200010];
int main(){
cin >> n;
depth.resize(n,-1);
rep(i,n-1){
cin >> a[i] >> b[i];
a[i]--;b[i]--;
g[a[i]].emplace_back(b[i]);
g[b[i]].emplace_back(a[i]);
}
dfs(0,0);
cin >> q;
rep(i,q){
ll t,e,x;
cin >> t >> e >> x;
e--;
int k=a[e],l=b[e];
if(t==2)swap(k,l);
if(depth[k]>depth[l]){
ans[k]+=x;
}
else{
ans[0]+=x;
ans[l]-=x;
}
}
vector <ll> q;
q.push_back(0);
while(!q.empty()){
ll cnt=q.back();
q.pop_back();
for(int i:g[cnt]){
if(depth[i]>depth[cnt]){
ans[i]+=ans[cnt];
q.push_back(i);
}
}
}
rep(i,n)cout << ans[i] << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> 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 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; }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.precision(10);
cout << fixed;
#ifdef LOCAL_DEFINE
freopen("input.txt", "rt", stdin);
#endif
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
map<int, int> cnt;
forn(i, n) {
int x;
cin >> x;
++cnt[x];
}
bool first;
if (n % 2 == 1) first = false;
else {
first = false;
for (auto w: cnt) first |= w.se % 2;
}
cout << (first ? "First" : "Second") << '\n';
}
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
| #include<cstdio>
#include<algorithm>
#include<ctype.h>
#define int long long
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int Mod=1e9+7,N=3005;
int n,dp[N][N],sum[N],ans;
signed main()
{
n=read();
for(int i=1;i<=n;i++)
{
int x=read();
sum[i]=sum[i-1]+x;
}
dp[1][0]=1;
for(int i=1;i<=n;i++)
for(int j=n+1;j>=2;j--)
{
dp[j][sum[i]%j]=(dp[j][sum[i]%j]+dp[j-1][sum[i]%(j-1)])%Mod;
if(i==n)
{
ans=(ans+dp[j-1][sum[i]%(j-1)])%Mod;
}
}
printf("%lld\n",ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;
signed main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout<<fixed<<setprecision(15);
vi a(4);
rep(i,4) cin>>a[i];
sort(all(a));
yn(a[0]+a[3]==a[1]+a[2] || a[0]+a[1]+a[2]==a[3]);
} | /*
Author : Ritesh Singh
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
#define lct long long int t;cin>>t;while(t--)
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define el '\n'
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL)
const int mod = 1e9+7;
typedef long long ll;
typedef tree<string, null_type, less<string>, rb_tree_tag,
tree_order_statistics_node_update>
new_data_set;
int32_t main()
{
IOS;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll a[4];
rep(i,0,4)
cin>>a[i];
sort(a,a+4);
if(((a[0]+a[3]) == (a[1]+a[2])) or ((a[0]+a[1]+a[2])==a[3]))
cout<<"Yes";
else
cout<<"No";
} |
#include<bits/stdc++.h>
using namespace std;
int N;
long long a;
int t;
int Q;
long long x;
long long mi=0x3f3f3f3f3f3f3f3f;
long long ma=0xcfcfcfcfcfcfcfcf;
long long add;
int main()
{
scanf("%d",&N);
while(N--)
{
scanf("%lld %d",&a,&t);
if(t==2)
{
ma=max(ma,a);
mi=max(mi,a);
continue;
}
if(t==3)
{
ma=min(ma,a);
mi=min(mi,a);
continue;
}
mi+=a;
ma+=a;
add+=a;
}
scanf("%d",&Q);
while(Q--)
{
scanf("%lld",&x);
printf("%lld ",max(min(mi,x+add),ma));
}
printf("\n");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
//.define
// #define FILE_IN_OUT
#define RET(_x) cout << (_x) << '\n'; return;
#define all(_obj) (_obj).begin(), (_obj).end()
#define loop(_n) for (int i = 0; i < (_n); ++i)
#define sz(_obj) static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x) std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x) {}
#endif
#define endl "\n"
template <typename P, typename Q>
P CeilDiv(P _dividend, Q _divider) {
return static_cast<P>((_dividend - 1LL + _divider) / _divider);
}
template <typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
for (Tp current = _begin; current != _end; ++current) {
std::cout << *current << _delim;
}
std::cout << '\n';
}
//.constant
using ll = int64_t;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<int>(1e9 + 7);
//.data
//.code
void SolveTask() {
int n;
cin >> n;
vector<ll> arr(n);
vector<ll> trr(n);
loop(n) {
cin >> arr[i] >> trr[i];
}
ll sum = 0;
vector<pair<ll, ll>> vec;
for (int i = 0; i < n; ++i) {
if (trr[i] == 1) {
sum += arr[i];
} else {
arr[i] -= sum;
if (vec.empty() || vec.back().second != trr[i]) {
vec.emplace_back(arr[i], trr[i]);
} else {
if (trr[i] == 2) {
vec.back().first = max(vec.back().first, arr[i]);
} else {
vec.back().first = min(vec.back().first, arr[i]);
}
}
}
}
ll lo = LLONG_MAX;
ll hi = LLONG_MIN;
int j = -1;
for (int i = sz(vec) - 1; i >= 0; --i) {
if (vec[i].second == 2) {
hi = max(hi, vec[i].first);
} else {
lo = min(lo, vec[i].first);
}
if (lo <= hi) {
j = i + 1;
break;
}
}
ll ans = -1;
if (j != -1) {
ans = vec[j].first;
for (int i = j + 1; i < sz(vec); ++i) {
if (vec[i].second == 2) {
ans = max(ans, vec[i].first);
} else {
ans = min(ans, vec[i].first);
}
}
}
int q;
cin >> q;
loop(q) {
ll x;
cin >> x;
if (j == -1) {
cout << max(hi, min(lo, x)) + sum << endl;
} else {
cout << ans + sum << endl;
}
}
}
int main() {
#ifdef FILE_IN_OUT
std::ifstream cin("input.txt", std::ios::in);
std::ofstream cout("output.txt", std::ios::out);
#else
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
#endif
int test_cases = 1;
// cin >> test_cases;
for (int yt = 1; yt <= test_cases; ++yt) {
SolveTask();
}
#ifdef FILE_IN_OUT
cin.close();
cout.close();
#endif
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
int main(){
int n, m;
cin >> n >> m;
int num = 0;
int ans = 0;
int hanko = INF;
vector<int> an(m);
for(int i=0; i<m; ++i) cin >> an[i];
sort(an.begin(),an.end());
for(int i=0; i<=m; ++i){
int ai;
if(i != m) ai = an[i];
else ai = n +1;
int nhanko = ai -(i? an[i-1]:0) -1;
if(nhanko != 0) hanko = min(hanko, nhanko);
}
//cout << "hanko:" << hanko << endl;
for(int i=0; i<=m; ++i){
int ai;
if(i != m) ai = an[i];
else ai = n +1;
ans += (ai -(i? an[i-1]:0) +hanko -2) /hanko;
//cout << i << ":" << ans << endl;
}
cout << ans << endl;
} | #include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define ll long long
#define ss second
#define ff first
#define mod 1000000007
#define w(x) ll x; cin>>x; while(x--)
#define ps(x,y) fixed<<setprecision(y)<<x;
#define fo(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define re(i, j) fo(i, 0, j, 1)
#define pi acos(-1)
#define all(cont) cont.begin(), cont.end()
#define countbit(x) __builtin_popcount(x)
#define mod 1000000007
#define de(n) ll n;cin>>n;
#define def(a,n) ll n;cin>>n;ll a[n];re(i,n){cin>>a[i];}
#define defi(a,n,k) ll n;cin>>n; ll k;cin>>k;ll a[n];re(i,n){cin>>a[i];}
#define deb(x) cout<<#x<<"="<<x<<endl;
#define tr(it,a) for(auto it=a.begin();it!=a.end();it++)
#define nl cout<<endl;
using namespace std;
void cp()
{
ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
//18-1326D1 1208B 845C 912B 1009B 1350C 20C 1333C 1234D 1327C 1305B 1304B (or in matrix)
int main()
{
//cp();
de(n);
de(m);
ll a[m];
for(ll i=0;i<m;i++)
cin>>a[i];
sort(a,a+m);
vector<ll>ans;
if(m==0)
cout<<1;
else
{
if(a[0]-1!=0)
ans.push_back(a[0]-1);
for(ll i=1;i<m;i++)
{
if(i>0)
{
if(a[i]-a[i-1]-1!=0)
ans.push_back(a[i]-a[i-1]-1);
}
}
if(n-a[m-1]!=0)
ans.push_back(n-a[m-1]);
if(ans.size()==0)
cout<<"0";
else
{
sort(ans.begin(),ans.end());
ll d=ans[0];
ll an=0;
ll ht=ans.size();
for(ll i=0;i<ht;i++)
{
an+=(ans[i]/d);
if(ans[i]%d!=0)
an++;
}
cout<<an;
}
}
} |
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s;cin>>s;
ll n = s.size();
reverse(ALL(s));
vi cnt(33);
ll ans = 0;
s.pb('!');
s.pb('#');
for(int i=0;i<=n-2;i++){
// cout<<i<<" "<<i+1<<" "<<i+2<<endl;
//cout<<s[i]<<" "<<s[i+1]<<" "<<s[i+2]<<endl;
if(s[i+1] == s[i+2] && s[i] != s[i+2]){
//cout<<i+1<<" "<<cnt[s[i+1]-'a']<<endl;
ans += i+1-cnt[s[i+1]-'a'];
for(int j=0;j<26;j++){
cnt[j] = 0;
}
cnt[s[i+1]-'a'] = i+3;
i++;
//cout<<s[i+1]<<" "<<s[i+1]<<" "<<s[i+2]<<endl;
if(!(s[i+2] == s[i+3] && s[i+1] != s[i+3]))i++;
}else{
cnt[s[i]-'a']++;
}
}
cout<<ans<<endl;
return 0;
}
| #include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////
int main() {
int h, w; cin >> h >> w;
vector<string> s(h);
rep(i,h) cin >> s[i];
int ans = 0;
rep(i,h) rep(j,w-1) {
if (s[i][j] == '.' && s[i][j+1] == '.') ans++;
}
rep(i,h-1) rep(j,w) {
if (s[i][j] == '.' && s[i+1][j] == '.') ans++;
}
cout << ans << endl;
return 0;
} |
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define SZ(a) (int)((a).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> Pii;
typedef pair <ll, int> Pli;
typedef unsigned long long ull;
const double eps = 1e-8;
const int mod = (int)(1e9) + 7;
const int inf = 0x7fffffff;
const int N = (int)(2e5) + 7;
ll a, b, c, d;
int main() {
// freopen("in.in", "r", stdin);
scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
if (c * d - b <= 0) puts("-1");
else {
ll x = c * d - b;
printf("%lld\n", (a + x - 1) / x);
}
return 0;
} | #include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll a,b,c,d;
cin>>a>>b>>c>>d;
ll count=0;
ll cyan=a;
ll red=0;
while(cyan>red)
{
if(count>100000)
{
cout<<-1<<endl;
return 0;
}
cyan+=b;
red+=c;
count++;
if(cyan<=red*d)
break;
}
cout<<count<<endl;
} |
#include<bits/stdc++.h>
#define EB emplace_back
#define int long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
const int N = 2e5 + 10;
map < int, int > mp[N];
struct ufds{
vector < int > par, len;
ufds(int n){
par.resize(n);
len.resize(n, 1);
for(int i = 0; i < n; i++){
par[i] = i;
}
}
int find(int u){
if(u == par[u]){
return u;
}
return par[u] = find(par[u]);
}
void join(int u, int v){
u = find(u);
v = find(v);
if(u == v){
return;
}
if(len[u] < len[v]){
swap(u, v);
}
len[u] += len[v];
par[v] = u;
for(auto x : mp[v]){
mp[u][x.first] += x.second;
}
}
void clear(){
par.clear(), len.clear();
}
};
void test_case(){
int n, qq; cin >> n >> qq;
int A[n];
for(int i = 0; i < n; i++){
cin >> A[i];
A[i]--;
mp[i][A[i]]++;
}
ufds dsu(n);
while(qq--){
int type, a, b; cin >> type >> a >> b;
type--, a--, b--;
if(!type){
dsu.join(a, b);
}
else{
cout << mp[dsu.find(a)][b] << endl;
}
}
}
int32_t main(){
IOS;
int tt = 1;
//cin >> tte;
while(tt--){
test_case();
//cout << endl;
}
return 0;
}
| #include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
const int maxn=4e5+10;
int n,m,cnt;
int used[maxn];
struct sb{
int now,pre,to,va;
}e[maxn*3];
inline void add(int a,int b,int c){e[++cnt].pre=e[a].now;e[cnt].va=c;e[cnt].to=b;e[a].now=cnt;}
void dfs(int u){
for(int i=e[u].now;i;i=e[i].pre){
int v=e[i].to,va=e[i].va;
if(!used[v]){
if(used[u]==va){used[v]=(va+1)%(n+1);}
else{used[v]=va;}
dfs(v);
}
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1,x,y,c;i<=m;i++){
scanf("%d%d%d",&x,&y,&c);
add(x,y,c);add(y,x,c);
}
used[1]=1;
dfs(1);
bool flag=false;
for(int i=1;i<=n;i++){
if(!used[i]){
puts("No");
flag=true;break;
}
}
if(!flag){for(int i=1;i<=n;i++){printf("%d\n",used[i]);}}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define Laylo cin.tie(0), cout.tie(0), cin.sync_with_stdio(0), cout.sync_with_stdio(0);
#define lli long long int
#define ll long long
int main() {
Laylo
int x;
cin >> x;
cout << ((x < 0) ? 0 : x) << endl;
}
| #include<bits/stdc++.h>
using namespace std;
int main()
{
int s;
cin>>s;
if(s%100==0)
{
if(s<=10) cout<<0;
else if(s<=100) cout<<s/10;
else if(s<=3000) cout<<s/100;
}
else
{
if(s<=10) cout<<1;
else if(s<=100) cout<<s/10+1;
else if(s<=3000) cout<<s/100+1;
}
return 0;
} |
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
#include <tuple>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <array>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>
#include <chrono>
#include <valarray>
#include <bitset>
using ll = long long;
using std::cin;
using std::cout;
using std::endl;
std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;
std::tuple<int, int, int, int> input()
{
int si, sj, ti, tj;
cin >> si >> sj >> ti >> tj;
return std::make_tuple(si, sj, ti, tj);
}
const int H = 30;
const int W = 30;
int ch[H][W];
int cw[H][W];
inline int cost(int sh, int sw, int th, int tw)
{
if(sh == th)
{
if(sw > tw)
std::swap(sw, tw);
return cw[sh][sw];
}
else
{
if(sh > th)
std::swap(sh, sw);
return ch[sh][sw];
}
}
void solve()
{
auto [sh, sw, th, tw] = input();
using T = std::tuple<int, int, int>;
std::priority_queue<T, std::vector<T>, std::greater<>> pq;
std::array<std::array<int, W>, H> d;
std::array<std::array<int, W>, H> b;
for (int i = 0; i < H; ++i)
{
for (int j = 0; j < W; ++j)
{
d[i][j] = inf;
b[i][j] = -1;
}
}
d[sh][sw] = 0;
pq.emplace(0, sh, sw);
const int dh[] = {1, 0, -1, 0};
const int dw[] = {0, 1, 0, -1};
const std::string dir = "DRUL";
while(not pq.empty())
{
auto [dist, h, w] = pq.top();
pq.pop();
if(dist > d[h][w])
continue;
if(h == th and w == tw)
break;
for (int i = 0; i < 4; ++i)
{
const int nh = h + dh[i];
const int nw = w + dw[i];
if(nh < 0 or nh >= H or nw < 0 or nw >= W)
continue;
if(chmin(d[nh][nw], d[h][w] + cost(h, w, nh, nw)))
{
pq.emplace(d[nh][nw], nh, nw);
b[nh][nw] = i;
}
}
}
int cnt = 0;
std::string res;
int curh = th, curw = tw;
while(curh != sh or curw != sw)
{
const int idx = b[curh][curw];
cnt += 1;
res += dir[idx];
curh -= dh[idx];
curw -= dw[idx];
}
std::reverse(res.begin(), res.end());
cout << res << endl;
ll len; cin >> len;
len /= cnt;
curh = sh, curw = sw;
for(const auto &c : res)
{
if(c == 'R')
{
ch[curh][curw] = len;
curw += 1;
}
if(c == 'L')
{
ch[curh][curw - 1] = len;
curw -= 1;
}
if(c == 'U')
{
ch[curh - 1][curw] = len;
curh -= 1;
}
if(c == 'D')
{
ch[curh][curw] = len;
curh += 1;
}
}
}
int main()
{
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
const int INIC = 5000;
for (int i = 0; i < H - 1; ++i)
{
for (int j = 0; j < W; ++j)
{
ch[i][j] = INIC;
}
}
for (int i = 0; i < H; ++i)
{
for (int j = 0; j < W - 1; ++j)
{
cw[i][j] = INIC;
}
}
int kkt = 1000;
//cin >> kkt;
while(kkt--)
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> Point;
typedef pair<Point, Point> Path;
map<Path, double> cost;
Point get_next(Point cur, Point goal) {
double min_cost = 1e14;
Point next = make_pair(-1, -1);
if (cur.first < goal.first) {
next = make_pair(cur.first + 1, cur.second);
min_cost = cost[make_pair(cur, next)];
} else if (cur.first > goal.first) {
next = make_pair(cur.first - 1, cur.second);
min_cost = cost[make_pair(cur, next)];
}
if (cur.second < goal.second) {
Point tmp_next = make_pair(cur.first, cur.second + 1);
double tmp_min_cost = cost[make_pair(cur, tmp_next)];
if (tmp_min_cost < min_cost) {
min_cost = tmp_min_cost;
next = tmp_next;
}
} else if (cur.second > goal.second) {
Point tmp_next = make_pair(cur.first, cur.second - 1);
double tmp_min_cost = cost[make_pair(cur, tmp_next)];
if (tmp_min_cost < min_cost) {
min_cost = tmp_min_cost;
next = tmp_next;
}
}
return next;
}
void print_path(vector<Point> in_path) {
for (int i = 0 ; i < in_path.size() - 1; i++) {
Point cur = in_path[i];
Point next = in_path[i+1];
if (cur.first < next.first) {
cout<<'D';
} else if (cur.first > next.first) {
cout<<'U';
} else if (cur.second < next.second) {
cout<<'R';
} else {
cout<<'L';
}
}
cout<<endl<<flush;
}
void update_cost(vector<Point> in_path, long long dist) {
double avg_cost = 1.0 * dist / (in_path.size() - 1);
for (int i = 0; i < in_path.size() - 1; i++) {
Point cur = in_path[i];
Point next = in_path[i+1];
double cur_cost = cost[make_pair(cur, next)];
if (cur_cost == 0) {
cost[make_pair(cur, next)] = avg_cost;
} else {
cost[make_pair(cur, next)] = min(avg_cost, cur_cost);
}
}
}
void calc(Point s, Point t) {
char c1;
vector<Point> result;
Point cur = s;
result.push_back(cur);
while (true) {
Point next = get_next(cur, t);
result.push_back(next);
cur = next;
if (cur == t) {
break;
}
}
print_path(result);
long long dist;
cin>>dist;
update_cost(result, dist);
}
int main() {
for (int i = 0; i < 1000; i++) {
Point s, t;
cin>>s.first>>s.second>>t.first>>t.second;
calc(s, t);
}
} |
#include <bits/stdc++.h>
using namespace std;
int main(){
int T;
cin >> T;
while(T--){
long long N;
cin >> N;
int cnt = 0;
while(N % 2 == 0){
N /= 2;
cnt++;
}
if(cnt == 0) cout << "Odd" << endl;
else if(cnt == 1) cout << "Same" << endl;
else cout << "Even" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define repr(i,n) for (int i = (n)-1; i >= 0; --i)
#define rep1r(i,n) for (int i = (n); i > 0; --i)
#define bit(n,k) ((n>>k)&1) //nのk bit目
#define vec(T) vector<T>
#define vvec(T) vector<vector<T>>
using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,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 ll llINF = 1LL << 60;
const int iINF = 1e9;
//------------------------------------------------
struct Solver{
void solve(){
ll N;
cin >> N;
vec(bool) used(N+1);
rep(i,N){
ll ai;
cin >> ai;
if(used[ai]){
cout << "No" << endl;
return;
}
used[ai]=true;
}
cout << "Yes" << endl;
}
};
int main(){
int testcasenum=1;
//cin >> testcasenum;
rep1(ti,testcasenum){
Solver solver;
solver.solve();
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int M,sum=0;
cin>>M;
int ar[M];
for(int i=0;i<M;i++){
cin>>ar[i];
if(ar[i]>=10){
sum+=(ar[i]-10);
}
}
cout<<sum<<endl;
return 0;
} | #include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define in(i,a,n) for(i=a;i<n;i++)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define ll long long
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define vi vector<int>
#define vll vector<long long>
void solve();
int main(){
ll t=1;
// cin>>t;
while(t--){
solve();
}
}
void solve(){
int n,ans=0,i=0;
cin>>n;
vector<int> a;
in(i,0,n){
int y;
cin>>y;
a.push_back(y);
;
}
in(i,0,n){
if(a[i]>10){
ans=ans+(a[i]-10);
}
}
cout<<ans<<endl;
} |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
double ans = N;
double tmp = 0.0;
for (int i=1;i<=N;i++) {
tmp += 1.0/i;
}
ans *= tmp;
ans -= 1;
cout << fixed << setprecision(15) << ans << "\n";
return 0;
} | #pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)
int N;
int A[211];
VI B, C;
VI D[211];
VI stk;
bool rec(int I, int s) {
if (I == N) {
if (stk.empty()) return false;
if (!D[s].empty()) {
B = D[s];
C = stk;
return true;
}
D[s] = stk;
return false;
} else {
bool b = rec(I+1, s);
if (b) return true;
stk.push_back(I+1);
b = rec(I+1, (s+A[I]) % 200);
stk.pop_back();
if (b) return true;
return false;
}
}
void MAIN() {
scanf("%d", &N);
REP (i, N) scanf("%d", A+i);
if (rec(0, 0)) {
puts("Yes");
REP (t, 2) {
printf("%d ", (int)B.size());
rprintf("%d", B.begin(), B.end());
swap(B, C);
}
} else {
puts("No");
}
}
int main() {
int TC = 1;
// scanf("%d", &TC);
REP (tc, TC) MAIN();
return 0;
}
|
#include <iostream>
using namespace std;
int main()
{
int N;
cin>>N;
int result=N*1.08;
if(result<206)
cout << "Yay!"<<endl;
else if(result==206)
cout << "so-so"<<endl;
else if(result>206)
cout << ":("<<endl;
} | #include <iostream>
#include <vector>
#include <cmath>
#include <ostream>
#include <list>
#include <map>
#include <algorithm>
#include <climits>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <bitset>
#include <cstring>
#include <deque>
#include <set>
#include <stack>
#include <queue>
#include <chrono>
#include <deque>
#include <string>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define mod 1000000007
#define cbit __builtin_popcountll
#define pl pair<long, long>
#define pqp priority_queue<pl>
#define mkp make_pair
#define vl vector<ll>
#define vvl vector<vl >
#define pb push_back
#define inf 1000000000000000000
#define all(v) v.begin(), v.end()
long long gcd(long long int a, long long int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
long long lcm(ll a, ll b)
{
return (a / gcd(a, b)) * b;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t = 1;
// cin >> t;
while (t--)
{
ll n;
cin>>n;
if((n*108)/100<206)
{
cout<<"Yay!";
}
else if((n*108)/100==206)
{
cout<<"so-so";
}
else{
cout<<":(";
}
}
return 0;
}
// ll mod_power(ll a,ll b)
// {
// if(b==0)
// {
// return 1;
// }
// ll temp=mod_power(a,b/2);
// temp%=mod;
// temp*=temp;
// temp%=mod;
// if(b%2==1)
// {
// temp*=a;
// temp%=mod;
// }
// return temp;
// }
// struct compare {
// bool operator()(const pair<ll,ll > &a,const pair<ll,ll > &b)
// {
// return a.first>b.first;
// }
// };
// bool comp(const pair<ll,ll > &a,const pair<ll,ll > &b)
// {
// if(a.first==b.first)
// {
// return a.second<b.second;
// }
// return a.first<b.first;
// } |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int N;
cin >> N;
long sum = 0;
for (int i = 0; i < N; i ++)
{
int A;
cin >> A;
if (A > 10) sum += A - 10;
}
cout << sum << endl;
return 0;
} | //#include <tourist>
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> p;
const int INF = 1e9;
const double eps = 1e-7;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const long double pi = 4 * atan(1);
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) \
cout << #v << ":"; \
for (auto x : v) \
{ \
cout << x << ' '; \
} \
cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
if (a < b)
{
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
if (b < a)
{
a = b;
return 1;
}
return 0;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
for (T &x : v)
is >> x;
return is;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//g++ yarudake.cpp -std=c++17 -I .
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()
{
cin.tie(0);
ios::sync_with_stdio(false);
ll n, m;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
rep(i,n){
a[i] = max(0,a[i]-10);
}
int ans =0;
rep(i,n)ans+=a[i];
cout<<ans<<"\n";
}
|
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define GR(a,n,m) vector<vector<int>> a(n, vector<int>(m, 0));
const int N = 505;
int A[N][N], B[N][N], n, m;
bool vis[N][N];
int dist[N][N];
vector<pair<pair<int,int>,int>> adj[N][N];
void solve()
{
cin >> n >> m;
for(int i = 0;i < n;i++)
{
for(int j = 0;j < m - 1;j++){
cin >> A[i][j];
}
}
for(int i = 0;i < n - 1;i++){
for(int j = 0;j < m;j++){
cin >> B[i][j];
}
}
for(int i = 0;i < n;i++)
{
for(int j = 0;j < m;j++)
{
if(i + 1 < n){
adj[i][j].pb({{i + 1,j},B[i][j]});
}
if(j + 1 < m){
adj[i][j].pb({{i,j + 1},A[i][j]});
}
if(j - 1 >= 0){
adj[i][j].pb({{i,j - 1}, A[i][j - 1]});
}
}
}
for(int r = 0;r < n;r++)
{
for(int c = 0;c < m;c++)
{
for(int i = 1;i <= r;i++)
{
adj[r][c].pb({{r - i, c}, i + 1});
}
}
}
for(int i = 0;i < n;i++)
for(int j = 0;j < m;j++)
dist[i][j] = INT_MAX;
dist[0][0] = 0;
int k = 1000;
queue<pair<int,int>> q[k + 5];
int cnt = 1, pos = 0;
q[0].push({0,0});
while(cnt > 0)
{
while(q[pos % (k + 1)].empty())++pos;
int x = q[pos % (k + 1)].front().first, y = q[pos % (k + 1)].front().second;
q[pos % (k + 1)].pop();
--cnt;
if(vis[x][y])continue;
vis[x][y] = true;
for(auto v : adj[x][y])
{
int i = v.first.first, j = v.first.second, w = v.second;
if(dist[x][y] + w < dist[i][j])
{
dist[i][j] = dist[x][y] + w;
q[dist[i][j] % (k + 1)].push({i,j});
++cnt;
}
}
}
cout << dist[n - 1][m - 1] << "\n";
}
int32_t main()
{
fastio;
int t = 1;
//cin >> t;
for(int tt = 0;tt < t;tt++)
{
solve();
}
} | #pragma GCC optimize("O2")
#pragma GCC target("avx")
#include <cstdio>
#include <functional>
#include <queue>
#include <tuple>
using namespace std;
inline int_fast32_t get_digit() {
int_fast32_t x = 0, f = 1;
char c = getchar();
while(c > '9' || c < '0') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
x = (x * 10) + (c ^ 48);
c = getchar();
}
return x * f;
}
int main() {
int_fast32_t R, C;
scanf("%d%d", &R, &C);
int_fast32_t A[250000], B[250000];
int_fast32_t dist[500000], seen[500000] = {0}, cost, pt, to_hide = R * C;
priority_queue<pair<int_fast32_t, int_fast32_t>, vector<pair<int_fast32_t, int_fast32_t>>,
greater<pair<int_fast32_t, int_fast32_t>>>
queue;
for(int_fast32_t i = 0; i < R * C; ++i)
if(i % C != C - 1) A[i] = get_digit();
for(int_fast32_t i = 0; i < (R - 1) * C; ++i) B[i] = get_digit();
for(int_fast32_t i = 1; i < to_hide + to_hide; ++i) dist[i] = 10000000;
queue.emplace(pair<int_fast32_t, int_fast32_t>(0, 0));
while(!queue.empty()) {
tie(cost, pt) = queue.top();
if(pt == to_hide - 1) break;
queue.pop();
seen[pt] = true;
if(pt < to_hide) {
if(!seen[pt + 1] && pt % C != C - 1) {
if(cost + A[pt] < dist[pt + 1]) {
dist[pt + 1] = cost + A[pt];
queue.emplace(pair<int_fast32_t, int_fast32_t>(dist[pt + 1], pt + 1));
}
}
if(!seen[pt - 1] && pt % C != 0) {
if(cost + A[pt - 1] < dist[pt - 1]) {
dist[pt - 1] = cost + A[pt - 1];
queue.emplace(pair<int_fast32_t, int_fast32_t>(dist[pt - 1], pt - 1));
}
}
if(!seen[pt + C] && pt < to_hide - C) {
if(cost + B[pt] < dist[pt + C]) {
dist[pt + C] = cost + B[pt];
queue.emplace(pair<int_fast32_t, int_fast32_t>(dist[pt + C], pt + C));
}
}
if(!seen[pt + to_hide] && cost + 1 < dist[pt + to_hide]) {
dist[pt + to_hide] = cost + 1;
queue.emplace(pair<int_fast32_t, int_fast32_t>(dist[pt + to_hide], pt + to_hide));
}
} else {
if(to_hide < pt - C && !seen[pt - C] && cost + 1 < dist[pt - C]) {
dist[pt - C] = cost + 1;
queue.emplace(pair<int_fast32_t, int_fast32_t>(cost + 1, pt - C));
}
if(!seen[pt - to_hide] && cost < dist[pt - to_hide]) {
dist[pt - to_hide] = cost;
queue.emplace(pair<int_fast32_t, int_fast32_t>(cost, pt - to_hide));
}
}
}
printf("%d\n", dist[to_hide - 1]);
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;ver<(n);ver++)
#define loop while(true)
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"
typedef long long ll;
typedef pair<int, int> P;
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;
}
int main(){
int n;
cin>>n;
cout<<n-1;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
cout << n - 1 << endl;
} |
#include <bits/stdc++.h>
#include <stdlib.h>
#define sz(x) (int)(x).size()
using namespace std;
int64_t strtoll(string &s) {
int64_t res = 0;
for (int i = 0; i < sz(s); i++) {
res *= 10;
res += s[i] - '0';
}
return res;
}
vector<int64_t> convertToInts(vector<string> &arr, vector<int> &inds) {
vector<string> results = arr;
for (int i = 0; i < 3; i++) {
for (auto &c : results[i]) {
c = inds[c - 'a'] + '0';
}
}
vector<int64_t> int_results(3);
for (int i = 0; i < 3; i++) {
int_results[i] = strtoll(results[i]);
}
return int_results;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
vector<string> arr(3);
for (int i = 0; i < 3; i++) {
cin >> arr[i];
}
vector<int> inds(26, -1);
int cur = 0;
for (int i = 0; i < 3; i++) {
for (char c : arr[i]) {
if (inds[c - 'a'] == -1) {
inds[c - 'a'] = cur++;
}
}
}
if (cur > 10) {
cout << "UNSOLVABLE\n";
return 0;
}
int index = 0;
while (cur != 10) {
if (inds[index] == -1) {
inds[index] = cur++;
}
index++;
}
vector<int> reverse_inds(cur, -1);
for (int i = 0; i < 26; i++) {
if (inds[i] == -1) {
continue;
}
reverse_inds[inds[i]] = i;
}
sort(reverse_inds.begin(), reverse_inds.end());
do {
for (int i = 0; i < cur; i++) {
inds[reverse_inds[i]] = i;
}
if (inds[arr[0][0] - 'a'] == 0) {
continue;
}
if (inds[arr[1][0] - 'a'] == 0) {
continue;
}
if (inds[arr[2][0] - 'a'] == 0) {
continue;
}
vector<int64_t> results = convertToInts(arr, inds);
if (results[0] + results[1] == results[2]) {
for (int i = 0; i < 3; i++) {
cout << results[i] << "\n";
}
return 0;
}
} while(next_permutation(reverse_inds.begin(), reverse_inds.end()));
cout << "UNSOLVABLE\n";
return 0;
}
| //
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const ll MOD = 1000000007;
void solve_test()
{
int n;
cin >> n;
ll T;
cin >> T;
vector<ll> a(n);
for(int i=0; i<n; i++)
{
cin >> a[i];
}
if(n == 1)
{
if(T >= a[0])
{
cout << a[0];
}
else
{
cout << 0;
}
return;
}
vector<ll> s1, s2;
for(int i=0; i<(1<<(n/2)); i++)
{
ll t = 0;
for(int j=0; j<n/2; j++)
{
if((1<<j)&i)
{
t += a[j];
}
}
s1.PB(t);
}
for(int i=0; i<(1<<(n-n/2)); i++)
{
ll t = 0;
for(int j=0; j<(n-n/2); j++)
{
if((1<<j)&i)
{
t += a[j+n/2];
}
}
s2.PB(t);
}
s1.PB(0);
sort(s2.begin(), s2.end());
ll ans = 0;
for(ll x : s1)
{
if(x <= T)
{
ans = max(ans, x);
}
auto a = upper_bound(s2.begin(), s2.end(), T-x);
if(a != s2.begin())
{
a--;
// what_is(x);
// what_is((*a));
ans = max(ans, x + (*a));
}
}
cout << ans;
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int tests;
tests = 1;
//cin >> tests;
while(tests--)
{
solve_test();
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <math.h>
#include <cmath>
#include <string>
#include <string.h>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
#include <functional>
#include <time.h>
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
#define rep(i, N) for (int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000000
#define MAX 200001
#define PI 3.141592653589793
const ll MOD = 1000000007;
/*clock_t start = clock();
clock_t end = clock();
const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
cout << time << endl;*/
template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};
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; }
void solve(ll now,map<ll,ll> &mp){
if(now == 1) return;
if(now % 2 == 0){
if(mp.find(now/2) == mp.end()){
mp[now/2] = mp[now] + 1;
solve(now/2,mp);
}
else if(mp[now/2] > mp[now] + 1){
mp[now/2] = mp[now] + 1;
solve(now/2,mp);
}
}
else{
ll a = now/2*2;
if(mp.find(a/2) == mp.end()){
mp[a/2] = mp[now] + 2;
solve(a/2,mp);
}
else if(mp[a/2] > mp[now] + 2){
mp[a/2] = mp[now] + 2;
solve(a/2,mp);
}
a += 2;
if(mp.find(a/2) == mp.end()){
mp[a/2] = mp[now] + 2;
solve(a/2,mp);
}
else if(mp[a/2] > mp[now] + 2){
mp[a/2] = mp[now] + 2;
solve(a/2,mp);
}
}
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll X,Y;
cin >> X >> Y;
map<ll,ll> mp;
mp[Y] = 0;
solve(Y,mp);
ll ans = INF;
for(auto m:mp){
ans = min(ans,abs(m.first-X) + m.second);
}
cout << ans << endl;
}
| #include<ctime>
#include<cstdio>
#include<cctype>
#include<algorithm>
#define ll long long
using namespace std;
const ll N=1e5+7;
ll read() {
char c;
ll x=0,f=1;
while(!isdigit(c=getchar()))
f-=2*(c=='-');
while (isdigit(c)){
x=x*10+(c-48)*f;
c=getchar();
}
return x;
}
struct node{
ll i,k;
node(ll i=0,ll k=0):i(i),k(k){}
friend bool operator <(node a,node b){
return a.k<b.k;
}
}c[N];
ll n,q,cur,p,a[N],ans[N];
int main() {
#ifndef ONLINE_JUDGE
freopen("D.in","r",stdin);
freopen("D.out","w",stdout);
#endif
clock_t t1=clock();
//--------
n=read();
q=read();
for(ll i=1;i<=n;++i)
a[i]=read();
a[n+1]=5e18;
for(ll i=1;i<=q;++i)
c[i]=node(i,read());
sort(c+1,c+q+1);
for(ll i=1;i<=q;++i){
ll qi=c[i].i;
ll qk=c[i].k;
while(a[p+1]-a[p]-1<qk-cur){
cur+=a[p+1]-a[p]-1;
++p;
}
ans[qi]=a[p]+qk-cur;
}
for(ll i=1;i<=q;++i)
printf("%lld\n",ans[i]);
//--------
clock_t t2=clock();
fprintf(stderr,"time:%0.3lfs",1.0*(t2-t1)/CLOCKS_PER_SEC);
return 0;
} |
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
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);
}
/*-------------------------------------------*/
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int k, n, m;
cin >> k >> n >> m;
vector<ll> a(k);
rep(i, k) {
cin >> a[i];
a[i] *= m;
}
vector<int> x(k);
int sum = m;
rep(i, k) {
x[i] = a[i] / n;
a[i] %= n;
sum -= x[i];
}
vector<int> p(k);
iota(ALL(p), 0);
sort(ALL(p), [&](int i, int j) { return a[i] > a[j]; });
rep(i, sum) x[p[i]]++;
rep(i, k) cout << x[i] << " \n"[i + 1 == k];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using LD = long double;
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; }
template <typename T> void coutall(T v) { if(v.empty()){cout << endl; return;} for(auto i = v.begin(); i != --v.end(); i++){cout << *i << " ";} cout << *--v.end() << endl; }
template <typename T> void DEBUGall(T v) { if(v.empty()){cerr << endl; return;} for(auto i = v.begin(); i != --v.end(); i++){cerr << *i << " ";} cerr << *--v.end() << endl; }
inline void IN(void){ return; }
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return; }
inline void OUT(void){ cout << "\n"; return; }
template <typename First, typename... Rest> void OUT(First first, Rest... rest){ cout << first << " "; OUT(rest...); return; }
inline void DEBUG(void){ cerr << "\n"; return; }
template <typename First, typename... Rest> void DEBUG(First first, Rest... rest){ cerr << first << " "; DEBUG(rest...); return; }
void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; }
void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; }
void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; }
ll myceil(ll a, ll b) { return a >= 0 ? (a+b-1)/b : -((-a)/b); }
ll myfloor(ll a, ll b) { return a >= 0 ? a/b : -myceil(-a, b); }
void Main(){
int n; IN(n);
vi a(n);
rep(i, n) {
IN(a[i]);
a[i] %= 200;
}
map<int, int> mp;
n = min(n, 10);
rep(bit, 1<<n){
if(bit == 0) continue;
int tmp = 0;
rep(i, n){
if(bit>>i & 1){
tmp = (tmp + a[i]) % 200;
}
}
if(mp.find(tmp) != mp.end()){
int bit0 = mp[tmp];
Yes();
cout << __builtin_popcount(bit0) << " ";
vi v;
rep(i, n) {
if(bit0>>i & 1) v.pb(i+1);
}
coutall(v);
cout << __builtin_popcount(bit) << " ";
v = vi();
rep(i, n) {
if(bit>>i & 1) v.pb(i+1);
}
coutall(v);
return;
}
mp[tmp] = bit;
}
Yes(0);
return;
}
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
} |
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
// avoid unordered_map and unordered_set!!!
#include <vector>
#include <utility>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using i32 = int32_t;
using pi64 = pair<i64, i64>;
#define vec vector
#define let const
#define DRi64(x) i64 x; cin >> x;
#define DRS(x) string x; cin >> x;
#define DRVi64(v, n) vec<i64> v(n); { for (i64 i = 0; i < n; ++i) { cin >> v[i]; }}
#define DRpi64(x) pi64 x; cin >> x.first >> x.second;
#ifdef DEBUG
#define P(x) cerr << x << "\n"
#else
#define P(x)
#endif
constexpr i64 MAXN = 3*100*1000LL+5LL;
constexpr i64 MOD = 1000000007LL;
constexpr i64 INF64 = MOD * MOD;
constexpr double EPS = 1e-9;
int
main()
{
ios_base::sync_with_stdio(false);
// fast io: see 1423K
cin.tie(nullptr);
cout.tie(nullptr);
DRi64(R); DRi64(X); DRi64(Y);
let i64 d2_from_orig = X * X + Y * Y;
let i64 R2 = R * R;
if (d2_from_orig < R2)
{
cout << "2\n";
return 0;
}
let i64 q = d2_from_orig / R2;
let double sqrt_q = sqrt(q);
if (d2_from_orig % R2 == 0 && q == i64(sqrt_q) * i64(sqrt_q))
{
cout << i64(sqrt_q) << "\n";
return 0;
}
cout << i64(sqrt_q + 1) << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vc = vector<T>;
template<class T> using vvc = vc<vc<T>>;
template<class T> using vvvc = vc<vvc<T>>;
template<class T> using vvvvc = vvc<vvc<T>>;
template<class T> using PQ = priority_queue<T>;
template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>;
using IP = pair<int, int>;
using LP = pair<ll, ll>;
#define mp make_pair
#define pb push_back
#define all(x) begin(x), end(x)
#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 repr(i, n) for (int i = n; (i) >= 0; i--)
#define rep3r(i, m, n) for (int i = (n); (i) >= (int)(m); 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; }
constexpr int INF = 1070000000;
constexpr long long LINF = 4611686015206162431;
vector<int> sieve(int n) {
vector<bool> mem(n+1, true);
mem[0] = false; mem[1] = false;
for (int i = 2; i*i <= n; i++) {
if (mem[i]) {
for (int j = i*2; j <= n; j += i) {
mem[j] = false;
}
}
}
vector<int> res;
rep (i, n+1) if (mem[i]) res.push_back(i);
return res;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll A, B;
cin >> A >> B;
int N = B - A + 1, d = B - A;
vc<int> primes = sieve(d);
vc<int> fac(N);
for (ll a = A; a <= B; a++) {
rep (i, primes.size()) {
fac[a-A] *= 2;
if (a % primes[i] == 0) {
fac[a-A]++;
}
}
}
vvc<ll> dp(N+1, vc<ll>(1 << primes.size()));
dp[0][0] = 1;
rep (i, N) {
rep (j, 1 << primes.size()) {
if (!(j&fac[i])) dp[i+1][j|fac[i]] += dp[i][j];
dp[i+1][j] += dp[i][j];
}
}
ll ans = 0;
rep (i, 1 << primes.size()) {
ans += dp[N][i];
}
cout << ans << endl;
} |
#include <cstdio>
int main() {
int N, X, i;
int V[1000] = {};
int P[1000] = {};
scanf("%d %d", &N, &X);
X *= 100;
for (i = 0; i < N; i++) scanf("%d %d", V + i, P + i);
int s = 0;
for (i = 0; i < N; i++) {
s += V[i] * P[i];
if (s > X) break;
}
if (i == N) printf("-1");
else printf("%d", i + 1);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P=pair<int,int>;
int main() {
int n,k;
cin>>n>>k;
int z=0;
int x=0;
rep(i,n+1) z+=i;
rep(i,k+1) x+=i;
ll ans =z*k*100+x*n;
cout<<ans<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD (ll)1000000007
#define pii pair<int,int>
#define pll pair<ll,ll>
#define UNIQUE(v) sort(v.begin(),v.end()),v.erase(unique(v.begin(),v.end()),v.end());
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll power(ll a,ll b){ll ret=1;while(b){if(b%2)ret=ret*a%MOD;a=a*a%MOD;b/=2;}return ret;}
const int sz = 1<<17;
int main()
{
int a,b,c,d;scanf("%d %d %d %d",&a,&b,&c,&d);
printf("%d",b-c);
return 0;
} | #include <bits/stdc++.h>
int main() {
const long long int MOD = 998244353;
long long int A, B, C;
std::cin >> A >> B >> C;
long long int sum_a = (A + 1) * A / 2 % MOD;
long long int sum_b = (B + 1) * B / 2 % MOD;
long long int sum_c = (C + 1) * C / 2 % MOD;
std::cout << ((sum_a * sum_b) % MOD) * sum_c % MOD << std::endl;
}
|
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << min({a, b, c, d}) << endl;
return 0;
} | #include<bits/stdc++.h>
#define ll long long int
#define vt vector
#define f(i,n) for((i)=0;(i)<(n);(i)++)
#define fd(i,n) for((i)=n-1;(i)>=0;(i)--)
#define pb push_back
using namespace std;
int main(){
ll t=1;
//cin>>t;
while(t--){
ll a,b,c,x,y,z;
cin>>a>>b>>c;
if (a==1)
x=6;
else if(a==2)
x=5;
else if(a==3)
x=4;
else if(a==4)
x=3;
else if(a==5)
x=2;
else
x=1;
if (b==1)
y=6;
else if(b==2)
y=5;
else if(b==3)
y=4;
else if(b==4)
y=3;
else if(b==5)
y=2;
else
y=1;
if (c==1)
z=6;
else if(c==2)
z=5;
else if(c==3)
z=4;
else if(c==4)
z=3;
else if(c==5)
z=2;
else
z=1;
cout<<x+y+z<<endl;
}
return 0;
} |
// Code Written by Pinaki Bhattacharjee (pinakipb2)
#include<bits/stdc++.h>
using namespace std;
// typedef
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
// #define
#define LOCAL
#define endl "\n"
#define PI 2*acos(0.0)
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mpr make_pair
#define all(x) (x).begin(),(x).end()
#define ppc __builtin_popcountll
#define pinakipb2 ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// constants
const int MAX = 1e7 + 10;
const int MOD = (int) 1e9 + 7;
int main()
{
pinakipb2;
ll n;
cin>>n;
ll ans = 0,ele;
for(int i=0;i<n;i++)
{
cin>>ele;
if(ele>10) ans+=(ele-10);
}
cout<<ans<<endl;
return 0;
} | # include <bits/stdc++.h>
# ifndef ngng628_library
# define ngng628_library
# define int long long
# define float long double
# define fi first
# define se second
# define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i,n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i,n) for(int i=((int)(n)); i>0; --i)
# define repr(i,b,e) for(int i=(b), i##_len=(e); i<i##_len; ++i)
# define reprs(i,b,e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define all(x) std::begin(x), std::end(x)
# define rall(x) std::rbegin(x), std::rend(x)
# define pb push_back
# define eb emplace_back
# define len(x) ((int)(x).size())
# define lb(v,x) distance(std::begin(v), lower_bound(all(v), (x)))
# define ub(v,x) distance(std::begin(v), upper_bound(all(v), (x)))
using namespace std;
template<class T> using vec = vector<T>;
using pii = pair<int, int>;
using vi = vec<int>;
using vb = vec<bool>;
using vvb = vec<vb>;
using vvvb = vec<vvb>;
using vs = vec<string>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
constexpr int INF = (1LL<<62)-(1LL<<31);
constexpr float EPS = 1e-10;
template<class T> istream& operator>>(istream& is, vec<T>& v) { for (auto& x : v) is >> x; return is; }
template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.fi >> p.se; }
template<class T> T scan() { T ret; cin >> ret; return ret; }
template<class T> string join(const vec<T> &v){ stringstream s; rep (i, len(v)) s<<' '<<v[i]; return s.str().substr(1); }
template<class T> ostream& operator<<(ostream& os, const vec<T>& v){ if (len(v)) os << join(v); return os; }
template<class T> ostream& operator<<(ostream& os, const vec<vec<T>>& v){ rep (i, len(v)) { if (len(v[i])) os << join(v[i]) << (i-len(v)+1 ? "\n" : ""); } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ os << p.fi << " " << p.se; return os; }
template<class T, class U, class V> ostream& operator<<(ostream& os, const tuple<T, U, V>& t){ os << get<0>(t) << " " << get<1>(t) << " " << get<2>(t); return os; }
void print(){ cout << "\n"; }
template<class T, class... A>void print(const T& v, const A&...args){cout << v; if(sizeof...(args))cout << " "; print(args...);}
void eprint() { cerr << "\n"; }
template<class T, class... A>void eprint(const T& v, const A&...args){cerr << v; if(sizeof...(args))cerr << " "; eprint(args...);}
void drop(){ cout << "\n"; exit(0); }
template<class T, class... A>void drop(const T& v, const A&...args){cout << v; if(sizeof...(args))cout << " "; drop(args...);}
template<class T> inline constexpr bool chmax(T &a, const T& b) { return a < b && (a = b, true); }
template<class T> inline constexpr bool chmin(T &a, const T& b) { return a > b && (a = b, true); }
constexpr int ctoi(const char c) { return ('0' <= c and c <= '9') ? (c - '0') : -1; }
const char* yn(bool b) { return b ? "Yes" : "No"; }
# endif // ngng628_library
struct Ad {
int x, y, r;
int id;
Ad() = default;
Ad(int _x, int _y, int _r, int _id) : x(_x), y(_y), r(_r), id(_id) {}
};
ostream& operator<<(ostream& os, const Ad& a){
printf("%4lld | %4lld %4lld %7lld", a.id, a.x, a.y, a.r);
return os;
}
int32_t main() {
int n;
cin >> n;
vec<Ad> ads(n);
rep (i, n) {
cin >> ads[i].x >> ads[i].y >> ads[i].r;
ads[i].id = i;
}
rep (i, n) {
auto& ad = ads[i];
printf("%lld %lld %lld %lld\n", ad.x, ad.y, min(ad.x + 2LL, 10000LL), min(ad.y + 2LL, 10000LL));
}
} |
/* _
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||_ \
| | \\\ - /'| | |
| \_| `\`---'// |_/ |
\ .-\__ `-. -'__/-. /
___`. .' /--.--\ `. .'___
."" '< `.___\_<|>_/___.' _> \"".
| | : `- \`. ;`. _/; .'/ / .' ; |
\ \ `-. \_\_`. _.'_/_/ -' _.' /
===========`-.`___`-.__\ \___ /__.-'_.'_.-'================
Please give me AC.
*/
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <chrono>
#include <random>
using namespace std;
using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#ifdef ONLINE_JUDGE
#define debug(x)
#define debug2(x, y)
#define debug3(x, y, z)
#define dbg(v)
#else
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
#endif
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;
template<typename T> T gcd(T a, T b) {
if (a < b) return gcd(b, a);
T r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
template<typename T> T lcm(const T a, const T 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;
}
// End of template.
int dp[280000][18];
int main() {
cout << fixed << setprecision(15);
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
int n, x[20], y[20], z[20];
int d[20][20];
cin >> n;
rep(i, n) cin >> x[i] >> y[i] >> z[i];
rep(i, n) rep(j, n) d[i][j] = abs(x[i] - x[j]) + abs(y[i] - y[j]) + max(0, z[j] - z[i]);
rep(bit, 1 << n) {
rep(i, n) dp[bit][i] = INF;
}
dp[0][0] = 0;
rep(bit, 1 << n) {
rep(u, n) {
rep(v, n) {
chmin(dp[bit | (1 << v)][v], dp[bit][u] + d[u][v]);
}
}
}
print(dp[(1 << n) - 1][0]);
int ans = INF;
for (int i = 1; i < n; ++i) chmin(ans, dp[(1 << n) - 1][i] + d[i][0]);
// print(ans);
return 0;
}
/*
___ ___ _ __ _ __
/ _ \ / __| '_ \| '_ \
| __/| (__| |_) | |_) |
\___(_)___| .__/| .__/
|_| |_|
*/
| // RedStone
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
const int N = 1e5 + 5;
const int Mod = 1e9 + 7;
int n;
int arr[N];
int dp[N][2];
int count(int i, int last) {
if(i <= 0) return 1;
int& r = dp[i][last];
if(r != -1) return r;
r = count(i - 1, 0);
if(!last) r = (r + count(i - 1, 1)) % Mod;
return r;
}
int main()
{
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%d", arr + i);
}
memset(dp, -1, sizeof dp);
int ans = 0;
for(int i = 0; i < n; i++) {
int cur = 1LL * arr[i] * count(n - 1 - i, 0) % Mod * count(i - 1, 0) % Mod;
if(i > 0) {
cur += -1LL * arr[i] * count(n - 1 - i, 1) % Mod * count(i - 1, 1) % Mod;
cur %= Mod;
}
ans = (ans + cur) % Mod;
}
ans = (ans + Mod) % Mod;
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#include <vector>
#include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n-1,0)
// #define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9+5;
const int mod = 1e9+7;
#define ll long long
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 { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
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, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
vector<mint> fac(MX);
vector<mint> ifac(MX);
mint comp(ll a, ll b) {
return fac[a]/fac[b]/fac[a-b];
}
mint pow2[4000002];
signed main(){
int h,w;
cin>>h>>w;
vector<vector<char> > a(h);
vector<vector<int> > u(h);
vector<vector<int> > d(h);
vector<vector<int> > l(h);
vector<vector<int> > r(h);
int clean = 0;
pow2[0]=1;
FOR(i,1,4000002) {
pow2[i]=pow2[i-1]*(mint)2;
}
rep(i,h) {
string s;
cin>>s;
rep(j,w) a[i].push_back(s[j]);
rep(j,w) if(a[i][j]=='.') clean++;
rep(j,w) {
u[i].push_back(0);
d[i].push_back(0);
l[i].push_back(0);
r[i].push_back(0);
}
}
mint cl = clean;
mint ans = cl * pow2[clean];
//u
rep(i,h) {
rep(j,w) {
u[i][j]=l[i][j]=0;
if(a[i][j]=='#')continue;
if(i>0) u[i][j]=u[i-1][j];
if(j>0) l[i][j]=l[i][j-1];
u[i][j]++;
l[i][j]++;
}
}
rrep(i,h) {
rrep(j,w) {
d[i][j]=r[i][j]=0;
if(a[i][j]=='#')continue;
if(i<h-1) d[i][j]=d[i+1][j];
if(j<w-1) r[i][j]=r[i][j+1];
d[i][j]++;
r[i][j]++;
}
}
rep(i,h) {
rep(j,w) {
if(a[i][j]=='#')continue;
int don = u[i][j]+d[i][j]+r[i][j]+l[i][j]-3;
// cout << don << endl;
ans-= pow2[clean-don];
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int64_t solve(int64_t N, string S, string T) {
// TODO: edit here
ll count(0);
for (size_t i = 0; i < N; ++i) {
if (S[i] == '1') ++count;
if (T[i] == '1') --count;
}
if (count != 0) return -1;
for (size_t i = 0; i < N; ++i) {
if (S[i] != T[i]) {
// cerr << S[i] << ", " << T[i] << endl;
if (S[i] == '1') {
for (auto j = i + 1; j < N; ++j) {
if (S[j] == '0') {
// cerr << i << ", " << j << endl;
S[i] = '0';
S[j] = '1';
++count;
break;
}
}
} else {
for (auto j = i + 1; j < N; ++j) {
if (T[j] == '0') {
// cerr << i << ", " << j << endl;
T[i] = '0';
T[j] = '1';
++count;
break;
}
}
}
}
}
return count;
}
// 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 N;
string S, T;
cin >> N >> S >> T;
auto ans = solve(N, S, T);
cout << ans << endl;
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<ll, ll>;
struct edge {
int to;
long long c;
long long d;
};
ll get_cost(ll c, ll d, ll t_now) {
ll t = sqrt(d);
ll dt = max(0LL, t - t_now);
ll res = c + (d / (t_now + dt + 1)) + dt;
res = min(res, c + (d / (t_now + dt + 1 + 1)) + dt + 1);
if (dt) res = min(res, c + (d / (t_now + dt - 1 + 1)) + dt - 1);
return res;
}
const long long INF = 10e16;
// 0-indexed
vector<long long> dijkstra(int start, vector<vector<edge>> &G) {
int N = G.size();
vector<long long> dist(N, INF);
priority_queue<P, vector<P>, greater<P>> pq;
dist.at(start) = 0;
pq.emplace(P{dist.at(start), start});
while (!pq.empty()) {
P p = pq.top();
pq.pop();
int cur = p.second;
ll t_now = p.first;
if (dist.at(cur) < p.first) continue;
for (auto &x : G.at(cur)) {
ll cost = get_cost(x.c, x.d, t_now);
if (dist.at(x.to) <= dist.at(cur) + cost) continue;
dist.at(x.to) = dist.at(cur) + cost;
pq.emplace(P{dist.at(x.to), x.to});
}
}
return dist;
}
int main() {
int n, m;
cin >> n >> m;
vector<vector<edge>> G(n);
rep(i, m) {
ll a, b, c, d;
cin >> a >> b >> c >> d;
a--, b--;
G[a].emplace_back(edge{(int)b, c, d});
G[b].emplace_back(edge{(int)a, c, d});
}
const auto &res = dijkstra(0, G);
if (res[n - 1] == INF) {
cout << -1 << endl;
} else {
cout << res[n - 1] << endl;
}
} | #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int mod = 1'000'000'007;
int main() {
int r1, c1, r2, c2, ans;
cin >> r1 >> c1 >> r2 >> c2;
int r_diff = r1 - r2, c_diff = c1 - c2;
if (r1==r2 && c1==c2) ans=0;
else if (r1+c1==r2+c2 || r1-c1==r2-c2 || abs(r1-r2)+abs(c1-c2)<=3) ans=1;
else if (r1-r_diff+c1-r_diff==r2+c2) ans=2;
else if (r1-c1==r2-c2) ans=2;
else if (abs(c1+r_diff-c2)<=3) ans=2;
else if (abs(r1-r_diff-r2)+abs(c1-r_diff-c2)<=3) ans=2;
else if (abs(r1-r2)+abs(c1-c2)<=6) ans=2;
else if ((r1+c1)%2==(r2+c2)%2) ans=2;
else ans=3;
cout << ans << endl;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
/*long long gcd(long long a,long long b){
if(b==0){
return a;
}
return(gcd(b,a%b));
}
bool prime(long long n){
if(n<2){
return false;
}else{
for(int i=2;i*i<=n;i++){
if(n%i==0){
return false;
}
}
}
return true;
}*/
/* PRIME FACTOR ARRAY
vector<int> pfactor(long long n){
vector<int>f;
for(int i=2;i*i<=n;i++){
while(n%i==0){
f.push_back(i);
n/=i;
}
}if(n>1){
f.push_back(n);
}
return f;
}*/
//SIEVE OF ERSATHANOS
/*bool Sieve(long long 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;
}
}
bool a=false;
for (int p=2; p<=n; p++){
if (prime[p] && n%p==0)
a= true;
break;
}
return a;
}
long long Xor(int x,int y){
return (x | y) & (~x | ~y);
}
string dbinary(long long n){
string a;
for (int i = 64; i >= 0; i--) {
int k = n >> i;
if (k & 1)
a+='1';
else
a+='0';
}
return a;
}*/
/*long long gcd(long long a,long long b){
if(b==0){
return a;
}
return(gcd(b,a%b));
}
bool prime(long long n){
if(n<2){
return false;
}else{
for(int i=2;i*i<=n;i++){
if(n%i==0){
return false;
}
}
}
return true;
}*/
/* PRIME FACTOR ARRAY
vector<int> pfactor(long long n){
vector<int>f;
for(int i=2;i*i<=n;i++){
while(n%i==0){
f.push_back(i);
n/=i;
}
}if(n>1){
f.push_back(n);
}
return f;
}*/
//SIEVE OF ERSATHANOS
/*bool Sieve(long long 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;
}
}
bool a=false;
for (int p=2; p<=n; p++){
if (prime[p] && n%p==0)
a= true;
break;
}
return a;
}
long long Xor(int x,int y){
return (x | y) & (~x | ~y);
}
string dbinary(long long n){
string a;
for (int i = 64; i >= 0; i--) {
int k = n >> i;
if (k & 1)
a+='1';
else
a+='0';
}
return a;
}*/
long long octo(long long deciNum)
{
int octalNum = 0, countval = 1;
int dNo = deciNum;
while (deciNum != 0) {
// decimals remainder is calculated
int remainder = deciNum % 8;
// storing the octalvalue
octalNum += remainder * countval;
// storing exponential value
countval = countval * 10;
deciNum /= 8;
}
return octalNum;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin>>n;
long long count=0;
long long j=1;
while(j<=n){
string a=to_string(j);int c=0;
for(int i=0;i<a.length();i++){
if(a.at(i)=='7'){
c=1;
count+=1;
break;
}
}
if(c==0){
long long ans=octo(j);
string d=to_string(ans);
for(int i=0;i<d.length();i++){
if(d.at(i)=='7'){
count+=1;
break;
}
}
}
j++;
}
cout<<n-count<<"\n";
return 0;
}
| #include <bits/stdc++.h>
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
using namespace std;
signed main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n;
cin >> n;
int ans = 0;
for(int i = 1;i <= n;i++){
int temp = i;
bool flag = true;
while(temp){
if(temp%10 == 7) flag = false;
temp /= 10;
}
temp = i;
while(temp){
if(temp%8 == 7) flag = false;
temp /= 8;
}
ans += flag;
}
cout << ans;
} |
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define ll long long
#define dl long double
#define all(arr) arr.begin(), arr.end()
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pie 3.14159265358979323846264338327950L
#define mid(l, r) l + (r - l) / 2
#define mem0(arr) memset(arr, 0,sizeof(arr));
#define mem1(arr) memset(arr,-1,sizeof(arr));
#define vec vector<int>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
#define int long long
#define sz(x) (int)x.size()
#define template_array_size (int)1e6 + 6
#define INF (int)1e18
#define trace1(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
using namespace std;
int gcd(int a,int b){ if(!a)return b;return gcd(b%a,a);}
int lcm(int a, int b) { return (a*b)/ gcd(a,b);}
const int MOD = 1e9 + 7;
const int mod = 1e9 + 7;
void sout(){
cout<<endl;
}
template <typename T,typename... Types>
void sout(T var1,Types... var2){
cout<<var1<<" ";
sout(var2...);
}
template<typename T>
void sout(vector<T> arr) {
for(auto it : arr) {
cout<<it<<" ";
}
sout();
}
int n,m;
int temp;
int cnt;
int ans;
int ind;
int i,j;
int a,b;
vector<int> arr;
vector<int> brr;
int k;
void test_case () {
int n;
cin>>n;
int sum = (n+1);
int l = 1;
int r = 1e10;
int ans = 1;
while(l<=r) {
int mid =mid(l,r);
int cnt = (mid) * (mid + 1);
cnt= cnt / 2;
if(cnt <= sum) {
l = mid + 1;
ans = max(ans, mid);
} else {
r = mid - 1;
}
}
int fin = n - ans + 1;
cout<<fin;
}
int32_t main ()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cout << fixed << setprecision(10);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
int t = 1;
// cin >> t;
while (t--)
{
test_case();
}
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/ | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t n;
cin >> n;
int64_t bound = 2*(n+1);
int64_t m = sqrt(n);
while((m+1)*(m+2)<=bound){ //次のやつが上界を超えない
m++;
}
cout << n+1-m;
} |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int n, m;
vector<ll> a, b;
vector<vector<int>> g;
vector<bool> check;
ll dfs(int v) {
check[v] = true;
ll ret = b[v] - a[v];
for (auto nv : g[v]) {
if (check[nv]) continue;
ret += dfs(nv);
}
return ret;
}
int main() {
cin >> n >> m;
a.resize(n);
b.resize(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
g.resize(n);
rep(i, m) {
int c, d;
cin >> c >> d;
c--, d--;
g[c].push_back(d);
g[d].push_back(c);
}
check.resize(n);
bool ok = true;
for (int i = 0; i < n; i++) {
if (check[i]) continue;
if (dfs(i) != 0) ok = false;
}
if (ok) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
} | #define ll long long
#define mod 1000000007
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200000;
ll n, m;
ll a[maxn], b[maxn];
ll ss, st; // ssはグラフの実際の合計, stはグラフの理想の合計(ss=stなら"Yes")
ll mark[maxn]; // すでに見た点か判断する
vector<int> adj[maxn]; // グラフ
// 深さ優先探索
void dfs(int v) {
ss += a[v];
st += b[v];
mark[v] = 1;
for (auto u : adj[v]) {
if (!mark[u]) dfs(u);
}
}
int main()
{
// 入力処理
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 1; i <= n; i++) {
// 一つの島(隣接ノードの和)ごとに判定する
// 一つでもss!=stの島があれば"No"
if (!mark[i]) {
ss = 0;
st = 0;
dfs(i);
if (ss != st) {
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool checkValidStr(int N, string T) {
string startsWith = T.substr(0, 3);
if(startsWith == "110") {
for(int i = 0; i < N; i++) {
char c = T.at(i);
int rest = i % 3;
if(rest == 0 || rest == 1) {
if(c != '1') {
return false;
}
} else {
if(c != '0') {
return false;
}
}
}
}else if(startsWith == "101") {
for(int i = 0; i < N; i++) {
char c = T.at(i);
int rest = i % 3;
if(rest == 0 || rest == 2) {
if(c != '1') {
return false;
}
} else {
if(c != '0') {
return false;
}
}
}
} else if(startsWith == "011") {
for(int i = 0; i < N; i++) {
char c = T.at(i);
int rest = i % 3;
if(rest == 1 || rest == 2) {
if(c != '1') {
return false;
}
} else {
if(c != '0') {
return false;
}
}
}
}
return true;
}
int64_t count110(int N, string T) {
if(N == 1) {
if(T == "0") {
return pow(10, 10);
} else {
return pow(10, 10) * 2;
}
}
if(N == 2) {
if(T == "00") {
return 0;
} else if(T == "01") {
return pow(10, 10) - 1;
} else {
return pow(10, 10); // "11"のみ
}
}
if(!checkValidStr(N, T)) {
return 0;
}
string startsWith = T.substr(0, 3);
int64_t result = 0;
if(startsWith == "110") {
int rest = (N - 1) / 3;
result = pow(10,10) - rest;
}else if(startsWith == "101") {
int rest = (N - 3) / 3;
result = pow(10,10) - 1 - rest;
} else if(startsWith == "011") {
int rest = (N - 2) / 3;
result = pow(10,10) - 1 - rest;
}
return result;
}
int main()
{
int N;
cin >> N;
string T;
cin >> T;
int64_t count = count110(N, T);
cout << count << endl;
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 998244353
#define all(a) a.begin(),a.end()
#define dbg(n) cout<<#n<<' '<<n<<endl;
#define dbg_v(v) cout<<#v<<":";for(auto x:v) cout<<" "<<x; cout<<endl;
ll power(ll x,ll y){ll res = 1;while(y>0){if(y&1)res = (res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin>>n;
string s;
cin>>s;
ll tmp=1e10;
if(n==1){
if(s=="1")
cout<<tmp*2<<endl;
else
cout<<tmp<<endl;
return 0;
}
if(n==2){
if(s=="01"){
cout<<tmp-1<<endl;
}
else if(s=="10")
cout<<tmp<<endl;
else if(s=="11")
cout<<tmp<<endl;
else
cout<<0<<endl;
return 0;
}
int f=0;
string t=s.substr(0,3);
for(int i=0;i<n-3;i+=3){
if(s.substr(i,3)!=t)
f=1;
}
ll ans=1e10;
ans*=3LL;
string end=s.substr(n-2,2);
if(t=="011"&&!f){
ans-=2;
}
else if(t=="101"&&!f){
ans-=1;
}
else if(t=="110"&&!f){
}
else{
cout<<0<<endl;
return 0;
}
if(end=="01"){
ans-=2;
}
else if(end=="11"){
ans-=1;
}
else{
}
ans=(ans-n)/3LL;
ans++;
cout<<ans<<endl;
}
|
#include "bits/stdc++.h"
#include <chrono>
#include <random>
#define INF 1000000007
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i < b; i++)
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,fma,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef unordered_map<int,int> umi ;
typedef unordered_set<int> usi ;
typedef pair<int,int> pi;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
bool ldequal(ld a ,ld b){
return abs(a-b) < 1e-9 ;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// shuffle(permutation.begin(), permutation.end(), rng); for permute
// uniform_int_distribution<int>(0, i)(rng) for rand
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
const int N =2e5+1 ;
bool tests= false ;
void gen(){} ;
void solve(){
double a,b ;
cin>>a>>b ;
cout<<(a*b)/100 ;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
gen() ;
long long test =1 ;
if(tests) cin>>test ;
REP(i,1,test+1){
debug(i) ;
//cout<<"Case #"<<i<<": " ;
solve() ;
cout<<"\n" ;
}
return 0 ;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
int main(){
int n; cin>>n;
vector<P> a(n),b(n);
rep(i,n) {
int x,y; cin>>x>>y;
a[i] = {x,i};
b[i] = {y,i};
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int ans = 1e9;
if (a[0].second == b[0].second) ans = a[0].first + b[0].first;
else{
ans = max(a[0].first, b[0].first);
}
ans = min({ans, max(a[0].first,b[1].first), max(a[1].first, b[0].first)});
cout << ans << endl;
return 0;
} |
/*
Bismillahir Rahmanir Rahim
Read in the name of Allah, who created you!
Al Mashruf Tonoy
Department of CSE, Daffodil Internatinal University.
*/
/*
Bismillahir Rahmanir Rahim
Read in the name of Allah, who created you!
Al Mashruf Tonoy
Department of CSE, Daffodil Internatinal University.
*/
#include <bits/stdc++.h>
using namespace std;
int d(int n)
{
if(n==1)
{
return 6;
}
else if(n==6)
{
return 1;
}
else if(n==2)
{
return 5;
}
else if(n==5)
{
return 2;
}
else if(n==3)
{
return 4;
}
else if(n==4)
{
return 3;
}
}
int main()
{
for(int i=0; i<3; i++)
{
int a,b,c;
cin>>a>>b>>c;
cout<<d(a)+d(b)+d(c);
return 0;
}
} | #include<bits/stdc++.h>
using namespace std;
int main()
{
int arr[7] = {0,6,5,4,3,2,1};
int a ,b,c;
cin >> a >> b >> c;
cout << (arr[a]+arr[b]+arr[c]) << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define debug(x) cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugvec(v) rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v) cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;
typedef long long ll; /* 10^18 くらいまでいける */
int main(){
char c1, c2, c3;
cin >> c1 >> c2 >> c3;
if (c1 == c2 && c2 == c3)
cout << "Won" << endl;
else
cout << "Lost" << endl;
}
| #include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
const int maxn=1e6+5;
int main(){
char s[5];
cin>>s+1;
if(s[1]==s[2]&&s[3]==s[2]){
cout<<"Won"<<endl;
}
else{
cout<<"Lost"<<endl;
}
return 0;
}
|
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;
//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 = 998244353;
int gcd(int a, int b) {
return (b?gcd(b,a%b):a);
}
int gcdExtended(int a,int b, int *x , int *y) {
if(a==0) {
*x = 0;*y=1;
return b;
}
int x1, y1;
int g = gcdExtended(b%a,a,&x1,&y1);
*x = y1- (b/a)*x1;
*y = x1;
return g;
}
void solve() {
int n,s,k;
cin >> n >> s >> k;
int g = gcd(n,k);
if(s%g !=0) {
cout << -1 << endl;
return;
}
s = n-s;
n/=g,s/=g,k/=g;
int x,y;
g = gcdExtended(k,n,&x,&y);
x = (x+n)%n;
int ans = (long long )(s)*x%n;
cout << ans << endl;
}
int main(){
fast;
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int t;cin >> t;while(t--)
solve();
}
| #pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define ll long long
#define all(x) x.begin(),x.end() //vector
#define rep(i,n) for(ll i=0; i<n; ++i)
#define REP(i,n) for(ll i=1; i<=n; ++i)
#define Rep(i,s,n) for(ll i=s; i<n; ++i)
using namespace std;
//最大公約数
ll gcd (ll a, ll b){
if (b==0) return 0;
return gcd(b,a%b);
}
//最小公倍数
ll lcm (ll a, ll b){
return (ll)a/gcd(a,b)*b;
}
//入力はすべて正とする
//素数判定
bool is_prime (ll n){
for (ll i=2; i*i<=n; i++){
if (n%i==0) return false;
}
return true;
}
int main(){
int n;
cin >> n;
vector<string> s(n);
vector<ll> t(n);
vector<ll> cp(n);
rep(i,n){
cin >> s.at(i) >> t.at(i);
cp.at(i)=t.at(i);
}
sort(t.begin(), t.end());
reverse(t.begin(), t.end());
rep(i,n){
if (t.at(1)==cp.at(i)){
cout << s.at(i) << endl;
return 0;
}
}
} |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
#define pb push_back
int a[300005];
signed main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
int cur=0;
int ans=0;
for(int i=0;i<n;i++)
{
if(!i||a[i]==a[i-1])
{
cur++;
}
else
{
ans+=cur*(n-cur);
cur=1;
}
}
ans+=cur*(n-cur);
ans/=2;
cout<<ans<<endl;
return 0;
}
| /**
* author: Ayush
* From: Earth
**/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define dbg(x) cerr << #x << ": "<< x <<endl
#define dbg2(x,y) cerr<< #x <<": "<< x <<" || "<< #y << ": " << y << endl
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n;
cin >> n;
ll ans = 0;
ll a[n];
for (ll i = 0 ; i < n ; ++i) {
cin >> a[i];
}
map <ll, ll> mp;
for (ll i = 0 ; i < n ; ++i) {
ans += (i) - (mp[a[i]]);
mp[a[i]]++;
}
cout << ans;
return 0;
} |
#include<bits/stdc++.h>
using namespace std;
int K;
char S[233],T[233];
int a[233],b[233];
double Ans = 0.0;
int Ten[10] = {1,10,100,1000,10000,100000};
int CountS(int x)
{
int Sum = 0;
a[x]++;
for(int i = 1;i<=9;i++)
Sum += Ten[a[i]]*i;
a[x] --;
return Sum;
}
int CountT(int x)
{
int Sum = 0;
b[x]++;
for(int i = 1;i<=9;i++)
Sum += Ten[b[i]]*i;
b[x] --;
return Sum;
}
int main()
{
scanf("%d%s%s",&K,S,T);
for(int i=0;i<4;i++)
{
a[S[i]-'0'] ++;
b[T[i]-'0'] ++;
}
for(int i=1;i<=9;i++)
for(int j=1;j<=9;j++)
{
if(a[i] + b[i] == K) break;
if(CountS(i) > CountT(j))
{
Ans += 1.0 * (K - a[i] - b[i]) / (K * 9 - 8) * 1.0 * (K - a[j] - b[j] - (i==j?1:0)) / (K * 9 - 9);
}
}
printf("%.10lf",Ans);
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;
typedef pair<int,int> Pai;
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;}
void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
int main() {
int k;
string s, t;
cin >> k >> s >> t;
map<int, int> mp;
for (int i = 1; i <= 9; i++) mp[i] = k;
rep(i, 4) {
mp[s[i] - '0']--;
mp[t[i] - '0']--;
}
vector<Pai> couple;
for (int i = 1; i <= 9; i++) { // takahashi card
mp[i]--;
if (mp[i] < 0) {
mp[i]++;
continue;
}
vector<int> v(10);
rep (ti, 4) v[s[ti] - '0']++;
v[i]++;
ll tScore = 0;
rep (ti, 10) tScore += ti * pow(10, v[ti]);
for (int j = 1; j <= 9; j++) { // aoki card
mp[j]--;
if (mp[j] < 0) {
mp[j]++;
continue;
}
vector<int> v(10);
rep (ti, 4) v[t[ti] - '0']++;
v[j]++;
ll aScore = 0;
rep (ti, 10) aScore += ti * pow(10, v[ti]);
if (tScore > aScore) {
couple.push_back(make_pair(i, j));
}
mp[j]++;
}
mp[i]++;
}
// rep (i, couple.size()) {
// cout << couple[i].first << " / " << couple[i].second << endl;
// }
// return 0;
double ans = 0;
ll total = 9 * k - 8;
rep (i, couple.size()) {
double one = mp[couple[i].first];
mp[couple[i].first]--;
ans += (one * mp[couple[i].second]);
mp[couple[i].first]++;
}
ans = ans / (total * (total - 1));
printf("%.10f\n", ans);
return 0;
} |
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++)
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
char buf[1<<23],*p1=buf,*p2=buf;
inline int read(){
int x=0,f=1;char c=gc();
for (;!isdigit(c);c=gc()) f^=c=='-';
for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
return f?x:-x;
}
template <typename mitsuha>
inline bool read(mitsuha &x){
x=0;int f=1;char c=gc();
for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
if (!~c) return 0;
for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
return x=f?x:-x,1;
}
template <typename mitsuha>
inline int write(mitsuha x){
if (!x) return 0&pc(48);
if (x<0) pc('-'),x=-x;
int bit[20],i,p=0;
for (;x;x/=10) bit[++p]=x%10;
for (i=p;i;--i) pc(bit[i]+48);
return 0;
}
inline char fuhao(){
char c=gc();
for (;isspace(c);c=gc());
return c;
}
}using namespace chtholly;
using namespace std;
const int yuzu=1e6;
typedef int fuko[yuzu|10];
fuko vis;
int main() {
ll n,m,i;
auto kasumi=[&](ll a,ll b,int mod) {
ll zw=1;
for (;b;b>>=1,a=a*a%mod) if (b&1) zw=zw*a%mod;
return zw;
};
read(n),read(m);
printf("%lld\n",kasumi(10,n,m*m)/m%m);
} | #include <cstdio>
int po(int a, long long b, int m)
{
int r = 1;
while (b) {
if (b & 1) r = (long long)r * a % m;
a = (long long)a * a % m;
b >>= 1;
}
return r;
}
int m;
long long n;
int main()
{
scanf("%lld%d", &n, &m);
printf("%d\n", (po(10, n, m * m) - po(10, n, m)) / m);
return 0;
}
|
/*
Written By mafailure
*/
#define ill
//In the name of God
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace std;
using namespace __gnu_pbds;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#ifdef ill
#define int long long
#endif
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 T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) 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 << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef AATIF_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
//#define int long long
// int dx[]={-1,1,0,0}; int dy[]={0,0,1,-1};
// int dx[]={2,2,-2,-2,1,1,-1,-1}; int dy[]={1,-1,1,-1,2,-2,2,-2};
const long long mod = 1e9 + 7;
const double eps=1e-9;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef vector< pair< int, int > > vii;
typedef map<int, int> mii;
typedef pair<int, ii> pip;
typedef pair<ii, int> ppi;
#define arrinp(arr,init,final,size,type) type* arr=new type[size];for(int i=init;i<final;i++)cin>>arr[i];
#define cr2d(arr,n,m,t) t**arr=new t*[n];for(int i=0;i<n;i++)arr[i]=new t[m];
#define w(t) int t;cin>>t; while(t--)
#define takeInp(n) int n;cin>>n;
#define fr(i,init,final) for(int i=init;i<final;i++)
#define frr(i,init,final) for(int i=init;i>=final;i--)
#define Fr(i,final) for(int i=0;i<final;i++)
#define Frr(i,first) for(int i=first;i>=0;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define debug(x) cerr<<">value ("<<#x<<") : "<<x<<endl;
#define setb __builtin_popcount
#define lsone(n) (n&(-n))
#define rlsone(n) (n&(n-1))
#define clr(a,b) memset(a,b,sizeof(a))
const int inf= INT_MAX;
//struct point_i{int x,y;};
struct point_i{int x,y;
point_i(){ x=0; y=0;}
point_i(int x_,int y_){x=(x_);y=(y_) ;}
};
struct point
{
float x,y;
point (){x=y=0.0;}
point (float x_,float y_){x=(x_); y=(y_);}
bool operator < (point other) const{
if(fabs(x-other.x)>eps)return x<other.x;
return y<other.y;
}
bool operator == (point other) const {
return fabs(other.x-x)<=eps&& fabs(other.y-y)<=eps;
}
} ;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
vi init(string s)
{
istringstream sin(s);
int n;
vi arr;
while(sin>>n)arr.push_back(n);
return arr;
}
int power(int x, int y)
{
if(y==0)return 1;
int u=power(x,y/2);
u=(u*u)%mod;
if(y%2)u=(x*u)%mod;
return u;
}
int gcd(int a,int b)
{
if(a<b)return gcd(b,a);
return (b==0?a:(a%b?gcd(b,a%b):b));
}
int gcd_e(int a,int b,int &x,int &y)
{
if(b==0){x=1; y=0; return a;}
int x1,y1;
int p=gcd_e(b,a%b,x1,y1);
x=y1;
y=x1-(a/b)*y1;
return p;
}
void solve()
{
int n; cin>>n;int t; cin>>t; vi a(n); fr(i,0,n)cin>>a[i];
vector<int> v;
int d1=n/2; int d2=n-d1;
fr(i,0,(1LL<<d1))
{
int s=0;
fr(j,0,d1+1){if((i>>j)&1)s+=a[d2+j];}
v.pb(s);
}
sort(all(v));
int ans=0;
fr(i,0,(1LL<<d2))
{
int s=0;
fr(j,0,d2+1)
{
if((i>>j)&1)s+=a[j];
}
auto id=upper_bound(all(v),t-s)-v.begin();
if(id)ans=max(s+v[--id],ans);
}
cout<<ans<<endl;
}
signed main()
{
IOS
solve();
}
| #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int Szukaj(vector<ll>& a, ll x)
{
int l = 0, p = a.size() - 1, s, r = -1;
while (l <= p)
{
s = (l + p) / 2;
if (a[s] <= x)
{
r = s;
l = s + 1;
}
else
p = s - 1;
}
return r;
}
int main()
{
ios_base::sync_with_stdio(0);
int N, T;
cin >> N >> T;
vector<ll> t(N);
for (int i = 0; i < N; ++i)
cin >> t[i];
int n = N / 2;
int m = N - n;
vector<ll> a, b;
for (int i = 0; i < N; ++i)
{
if (i < n)
a.push_back(t[i]);
else
b.push_back(t[i]);
}
vector<ll> sumy;
for (int mask = 0; mask < (1 << m); ++mask)
{
ll s = 0;
for (int j = 0; j < m; ++j)
if ((mask & (1 << j)) > 0)
s += b[j];
sumy.push_back(s);
}
sort(sumy.begin(), sumy.end());
ll odp = 0;
for (int mask = 0; mask < (1 << n); ++mask)
{
ll s = 0;
for (int j = 0; j < n; ++j)
if ((mask & (1 << j)) > 0)
s += a[j];
int g = Szukaj(sumy, T - s);
if (g != -1)
odp = max(odp, s + sumy[g]);
}
cout << odp;
return 0;
}
|
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <limits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <tuple>
#include <stack>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <type_traits>
/* This header mainly deals while taking input
*/
#include <cstdint>
// namespace Rangers
#include <ios>
#include <istream>
#include <utility>
namespace Inputs {
inline std::string readString1(std::istream &in) {
// string input when first taken
std::string s;
std::getline(in, s);
return s;
}
} // namespace Inputs
#include <sstream>
#include <iomanip>
using namespace Inputs;
using namespace std;
// Powered by caide (code generator, tester, and library code inliner)
// @author Dj
class Solution {
public:
void solve(std::istream &in, std::ostream &out) {
string s = readString1(in);
out << (s[0] == s[1] && s[1] == s[2] && s[0] == s[2] ? "Won" : "Lost");
}
};
void solve(std::istream& in, std::ostream& out)
{
out << std::setprecision(12);
Solution solution;
solution.solve(in, out);
}
#include <fstream>
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
istream& in = cin;
ostream& out = cout;
solve(in, out);
return 0;
}
| #include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define PI acos(-1.0)
#define GCD(a,b) __gcd(a , b)
#define LCM(a,b) ((a/__gcd(a,b))*b)
#define READ(f) freopen(f,"r",stdin)
#define WRITE(f) freopen(f,"w",stdout)
#define test cout<<"\n*************\n"
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define precise(c) fixed(cout);cout<<setprecision(c)
#define valid(x,y) (x>=1 && x<=row && y>=1 && y<=column)
#define fast ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main(){
string str;
cin>>str;
if(str[0]==str[1] && str[1]==str[2]){
cout<<"Won";
} else{
cout<<"Lost";
}
return 0;
} |
#include <bits/stdc++.h>
#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 pb push_back
#define eb emplace_back
using namespace std;
template <class T = int>
using V = vector<T>;
template <class T = int>
using VV = V<V<T>>;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<ld,ld>;
const int INF = 1e9;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
VV<int> g(n);
rep(i,m){
int a, b;
cin >> a >> b;
a--, b--;
g[a].eb(b);
g[b].eb(a);
}
int k;
cin >> k;
V<int> c(k);
rep(i,k) cin >> c[i], c[i]--;
VV<int> dist(k, V<int>(n, -1));
rep(i,k){
queue<int> que;
dist[i][c[i]] = 0;
que.push(c[i]);
while(!que.empty()){
int v = que.front();
que.pop();
for(int nv : g[v]){
if(dist[i][nv] != -1) continue;
dist[i][nv] = dist[i][v] + 1;
que.push(nv);
}
}
}
rep(i,k) if(dist[0][c[i]] == -1){
cout << -1 << endl;
return 0;
}
VV<int> dp(1<<k, V<int>(k, INF));
rep(i,k) dp[0][i] = 0;
rep(i,(1<<k)-1){
rep(j,k){
rep(l,k){
if(!(i>>l&1)){
dp[i|(1<<l)][l] = min(dp[i|(1<<l)][l], dp[i][j] + dist[j][c[l]]);
}
}
}
}
int ans = INF;
rep(i,k) ans = min(ans, dp[(1<<k)-1][i]+1);
cout << ans << endl;
} | #include<bits/stdc++.h>
#define loop(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define ll long long int
#define vi vector<int>
#define pi pair<int, int>
#define W(t) int t; cin >> t; while(t--)
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff first
#define ss second
#define rep(i, a, b)for(ll i = a; i <= b; i++)
#define dep(i, a, b)for(ll i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.14159265
using namespace std;
const ll mod = (ll)(998244353);
ll test = 1;
vector<ll> read(int n){
vector<ll> v(n);
loop(i, n)
cin >> v[i];
return v;
}
std::vector<ll> v;
ll OR(ll i, ll j){
ll left = v[i];
if(i+1 <= j-1){
rep(k, i+1, j-1){
left = left|v[k];
}
}
return left;
}
ll calculate(std::vector<ll> cnt){
std::vector<ll> k;
rep(i, 0, cnt.size()-1){
if(cnt[i] == 1)k.pb(i);
}
ll ans = OR(k[0], k[1]);
rep(i, 1, k.size()-2){
ans ^= OR(k[i], k[i+1]);
}
return ans;
}
void solve(){
ll i, j, k, m,n, cnt = 0, ans = 0, sum = 0;
cin >> n;
v.resize(n);
for(auto &it : v)cin >> it;
ans = INT_MAX;
for(ll i = 0; i < 1LL<<(n-1); i++){
ll t = i;
std::vector<ll> cnt(n+1, 0);
cnt[n] = 1;
cnt[0] = 1;
rep(j, 0, n-2){
if(t&1LL){
cnt[j+1] = 1;
}
else{
cnt[j+1] = 0;
}
t/=2;
}
ans = min(ans, calculate(cnt));
}
cout <<ans << "\n";
test++;
}
int main(){
FIO
#ifndef ONLINE_JUDGE
freopen("C:/Codeforces/input.txt", "r", stdin);
freopen("C:/Codeforces/output.txt", "w", stdout);
#endif
ll i = 1;
//W(t)
solve();
return 0;
} |
// atcoder/hhkb2020/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/
#include <bits/stdc++.h>
#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))
using namespace std;
template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }
template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }
using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;
constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;
// from: https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
template<int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0) val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator - () const noexcept {
return val ? MOD - val : 0;
}
constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
constexpr Fp& operator += (const Fp& r) noexcept {
val += r.val;
if (val >= MOD) val -= MOD;
return *this;
}
constexpr Fp& operator -= (const Fp& r) noexcept {
val -= r.val;
if (val < 0) val += MOD;
return *this;
}
constexpr Fp& operator *= (const Fp& r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp& operator /= (const Fp& r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
val = val * u % MOD;
if (val < 0) val += MOD;
return *this;
}
constexpr bool operator == (const Fp& r) const noexcept {
return this->val == r.val;
}
constexpr bool operator != (const Fp& r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0) return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1) t = t * a;
return t;
}
};
// constexpr lli mod = 1e9 + 7;
using mint = Fp<mod>;
int main(int argc, char *argv[])
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.setf(ios_base::fixed);
cout.precision(15);
int _;
cin >> _;
lli _n, _a, _b;
while (cin >> _n >> _a >> _b) {
if (_n - _a - _b < 0) {
cout << 0 << endl;
continue;
}
mint n(_n);
mint a(_a);
mint b(_b);
mint x = (n - a + 1) * (n - b + 1);
mint y = n - a - b + 1;
mint z = (y + 1) * y / 2;
cout << (x * z * 4) - (z * z * 4) << endl;
}
return 0;
}
| #include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
#include <istream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
using namespace std;
int max(int, int);
int min(int, int);
int positiveNum(int);
unsigned long long factorial(int);
unsigned long long combination(int, int);
long long power(int, int);
bool between(int, int, int);
vector<string> split(string, char);
int digit_sum(int);
vector<long long> divisors(long long);
//cout << fixed << setprecision(15) << y << endl;
int main()
{
long long n;
cin >> n;
vector<long long> div = divisors(n*2);
long long count = 0;
for(long long i = 0; div[i] * div[i] <= n*2; i++)
{
if((n*2/div[i] - div[i]) % 2 == 1)
{
count++;
}
}
cout << count*2 << endl;
return 0;
}
//2つの整数のうち大きい方を返す
int max(int a, int b)
{
if(a > b)
{
return a;
}
else
{
return b;
}
}
//2つの整数のうち小さい方を返す
int min(int a, int b)
{
if(a < b)
{
return a;
}
else
{
return b;
}
}
//入力が正ならその値,負なら0を返す
int positiveNum(int x)
{
if(x >= 0)
{
return x;
}
else
{
return 0;
}
}
//階乗
unsigned long long factorial(int n)
{
unsigned long long ans = 1;
for(int i = 1; i <= n; i++)
{
ans *= i;
}
return ans;
}
//mの中からn取る組み合わせの数
unsigned long long combination(int m, int n)
{
if(m == n)
{
return 1;
}
else if(n == 0)
{
return 1;
}
else
{
return combination(m-1, n-1) + combination(m-1, n);
}
}
//cがaとbの間にあるか
bool between(int a, int b, int c)
{
if(a > b)
{
int swap;
swap = a;
a = b;
b = swap;
}
if(a <= c && c <= b)
{
return true;
}
else
{
return false;
}
}
//累乗(long long版)
long long power(int x, int y)
{
long long num = 1;
for(int i = 0; i < y; i++)
{
num *= x;
}
return num;
}
//カンマ等で区切られた文字列を要素で分ける
vector<string> split(string s, char c)
{
vector<string> v;
stringstream ss{s};
string buf;
while(getline(ss, buf, c))
{
v.push_back(buf);
}
return v;
}
//各桁の和を求める
int digit_sum(int x)
{
int sum = 0;
while(x > 0)
{
sum += x % 10;
x /= 10;
}
return sum;
}
//Nの約数を求める
vector<long long> divisors(long long N)
{
vector<long long> a;
for (long long i = 1; i * i <= N; i++)
{
if (N % i == 0)
{
a.push_back(i);
if (N/i != i)
{
a.push_back(N/i);
}
}
}
sort(a.begin(), a.end());
return a;
} |
#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>
#define it register int
#define ct const int
#define il inline
using namespace std;
typedef long long ll;
#define rll register ll
#define cll const ll
typedef double db;
#define rdb register db
#define cdb const db
typedef long double ldb;
typedef unsigned long long ull;
#define pb push_back
#define mkp make_pair
#define pl pair<ll,int>
#define pi pair<int,int>
#define fir first
#define sec second
namespace io{
il char nc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
template <class I>
il void fr(I &num){
num=0;register char c=nc();it p=1;
while(c<'0'||c>'9') c=='-'?p=-1,c=nc():c=nc();
while(c>='0'&&c<='9') num=num*10+c-'0',c=nc();
num*=p;
}
char obuf[1000001],*os=obuf, *ot=obuf+1000001;
il void flush(){fwrite(obuf,1,os-obuf,stdout),os=obuf;}
il void ptc(const char x){*os++=x,os==ot?flush():void();}
template<class I>
il void wr(I x){
x<0?ptc('-'),x=-x:0;
static char qu[65];
char *tmp=qu;
do *tmp++=(x%10)^'0';while(x/=10);
while(tmp--!=qu) ptc(*tmp);
}
struct flusher{ ~flusher() { flush(); } }_;
template <class I>
il I Max(I p,I q){return p>q?p:q;}
template <class I>
il I Min(I p,I q){return p<q?p:q;}
template <class I>
il I A(I x){return x<0?-x:x;}
template <class I>
il void sp(I&p,I&q){I x=p;p=q,q=x;}
template <class I>
il void ckMax(I&p,I q){p=(p>q?p:q);}
template <class I>
il void ckMin(I&p,I q){p=(p<q?p:q);}
};
using io :: fr;
using io :: nc;
using io :: wr;
using io :: ptc;
using io :: Max;
using io :: Min;
using io :: A;
using io :: sp;
using io :: ckMax;
using io :: ckMin;
const int N=1000005;
int h[N],nxt[N],adj[N],x[N],y[N],t=1,u,v,dfn[N],a[N],fa[N],tag[N],ans[N],ti,n,m,d[N],s[N],top,ins[N],id[N];
il void add(ct u,ct v,ct i){nxt[++t]=h[u],h[u]=t,adj[t]=v,id[t]=i,nxt[++t]=h[v],h[v]=t,adj[t]=u,id[t]=i;}
il void dfs(ct x){
dfn[x]=++ti;//s[++top]=x,d[x]=top,ins[x]=1;
//printf("x=%d\n",x);
for(it i=h[x],j;i;i=nxt[i])
if((j=adj[i])^fa[x]){
if(dfn[j]) tag[id[i]]=x;
if(!dfn[j]) tag[id[i]]=j,fa[j]=x,dfs(j);
// printf("x=%d x[i]=%d y[i]=%d tag[i]=%d\n",x,::x[i>>1],y[i>>1],tag[i>>1]);
// if(tag[i>>1]==1&&(!ans[i>>1])) (::x[i>>1]==x)?ans[i>>1]=1:ans[i>>1]=-1;
// if(tag[i>>1]==2&&(!ans[i>>1])) (::x[i>>1]==x)?ans[i>>1]=1:ans[i>>1]=-1;
}
//--top,ins[x]=0;
}
int main(){
scanf("%d%d",&n,&m);it i;
for(i=1;i<=m;++i) scanf("%d%d",&x[i],&y[i]);
for(i=1;i<=n;++i) scanf("%d",&a[i]);
for(i=1;i<=m;++i) if(a[x[i]]==a[y[i]]) add(x[i],y[i],i);
for(i=1;i<=n;++i) if(!dfn[i]) ti=0,dfs(i);
for(i=1;i<=m;++i){
if(a[x[i]]>a[y[i]]){puts("->");continue;}
if(a[x[i]]<a[y[i]]){puts("<-");continue;}
// printf("tag[i]=%d x[i]=%d y[i]=%d %d %d\n",tag[i],x[i],y[i],d[x[i]],d[y[i]]);
//if(tag[i]==1) (dfn[x[i]]<dfn[y[i]])?puts("->"):puts("<-");
//if(tag[i]==2) (dfn[x[i]]>dfn[y[i]])?puts("->"):puts("<-");
if(tag[i]==x[i]) puts("<-");
else puts("->");
//if(ans[i]>0) puts("->");
//else puts("<-");
}
return 0;
}
|
// (n+1,r) = (n,r)+(n,r-1)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll l;
cin >> l;
ll dp[l][12];
for(int i = 0;i <= l-1;i++){
for(int j = 0;j <= 11;j++){
if(j == 0 || i == j){
dp[i][j] = 1LL;
continue;
}
if(i < j){
dp[i][j] = 0LL;
continue;
}
dp[i][j] = dp[i-1][j]+((j)?(dp[i-1][j-1]):0);
}
}
cout << dp[l-1][11];
} | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll l;
cin>>l;
__int128 a=1,b=1,c=1;
for(int i=1;i<=11;i++){
a*=(l-i);
}
for(int i=1;i<=11;i++){
b*=i;
}
c=a/b;
cout<<ll(c)<<endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
int N, Q;
int A[200010], T[200010];
int unit(int x)
{
rep(i, N)
{
if(T[i] == 1)x = x + A[i];
if(T[i] == 2)x = max(x, A[i]);
if(T[i] == 3)x = min(x, A[i]);
}
return x;
}
signed main()
{
cin >> N;
rep(i, N)cin >> A[i] >> T[i];
int LL = -1e15, RR = 1e15;
LL = unit(LL);
RR = unit(RR);
int ll, rr;
int lv, rv;
{
int l = -1e9 - 10, r = 1e9 + 10;
rep(_, 60)
{
int mid = (l + r) / 2;
int mid_val = mid_val = unit(mid);
if(LL == mid_val)l = mid;
else r = mid;
}
ll = l;
lv = unit(ll);
l = -1e9 - 10, r = 1e9 + 10;
rep(_, 60)
{
int mid = (l + r) / 2;
int mid_val = unit(mid);
if(mid_val == RR)r = mid;
else l = mid;
}
rr = r;
rv = unit(rr);
}
cin >> Q;
rep(i, Q)
{
int x;
cin >> x;
if(x <= ll)cout << lv << endl;
else if(rr <= x)cout << rv << endl;
else cout << lv + (x - ll) << endl;
}
return 0;
} | // Bismillahir Rahmanir Rahim
//============================
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define infL LLONG_MAX
#define infI INT_MAX
#define pb push_back
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo2(i,a,b) for(int i=a;i<=b;i++)
#define rfo(i,a,b) for(int i=a; i>=b;i--)
#define precise(x,y)cout<<fixed<<setprecision(y)<<x<<endl;
#define MAX 100010
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define bye return 0
#define debug cout<<"\nDebug\n";
#define debug2 cout<<"\nDebug2\n";
#define PEREGRINE_FALCON {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
typedef pair<ll,ll>PII;
double epsilon = 0.0000001f;
ll mod=1e9+7;
double Pi =acos(-1);
void print(vector<ll>V)
{
cout<<"\n---------------Vector checking start-------------------\n";
ll sz=V.size();
fo(i,0,sz){cout<<V[i]<<" ";}
cout<<"\n----------------Vector checking end--------------------\n";
}
void print(ll arr[], ll n)
{
cout<<"\n---------------Array checking start-------------------\n";
fo(i,0,n){cout<<arr[i]<<" ";}
cout<<"\n----------------Array checking end--------------------\n";
}
int main()
{
PEREGRINE_FALCON
//freopen("inputNew.txt", "r", stdin);
ll testCase=1;
//cin>>testCase;
while(testCase--){
ll n,m,k,x,y,z,a,b,c,d,mn,mx,temp,cnt,ans,sum,sz,len;
ll arr[3];
fo(i,0,3){cin>>arr[i];}
sort(arr,arr+3);
if(arr[2]-arr[1] == arr[1]-arr[0]) yes;
else no;
}
bye;
}
|
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <typeinfo>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
template <class T>
using Tree =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; // check the limits, dummy
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T>
void print(const vector<T> v) {
cout << "[ ";
F0R(i, v.size()) { cout << v[i] << ' '; }
cout << "]" << '\n';
}
int mod(int i, int j) {
return (i % j) < 0 ? (i % j) + 0 + (j < 0 ? -j : j) : (i % j + 0);
}
// --------------------------------------------------------
// This is tool
// --------------------------------------------------------
void Main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll S, P, ans = 0;
cin >> S >> P;
// cout << sqrt(P);
for (ll i = 1; i < (sqrt(P)) + 1; i++) {
if (P % i == 0) {
if (i + P / i == S) {
ans++;
}
}
}
// cout << ans << endl;
if (ans != 0) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
Main();
} | #include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
typedef long long ll;
int main() {
ll s, p;
cin >> s >> p;
for (ll i = 0; i <= sqrt(p); ++i) {
if (i * (s - i) == p) {
cout << "Yes";
return 0;
}
}
cout << "No";
} |
#include<bits/stdc++.h>
#define PB emplace_back
#define MP make_pair
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
template<typename T>
void read(T &x){
int ch = getchar(); x = 0; bool f = false;
for(;ch < '0' || ch > '9';ch = getchar());
for(;ch >= '0' && ch <= '9';ch = getchar()) x = x * 10 + ch - '0';
if(f) x = -x;
}
template<typename T>
bool chmax(T &a, const T &b){if(a < b) return a = b, 1; return 0;}
template<typename T>
bool chmin(T &a, const T &b){if(a > b) return a = b, 1; return 0;}
int n, lim;
int main(){
read(n); lim = 1<<n; printf("%d\n", lim-1);
for(int k = 1;k < lim;++ k){
for(int i = 0;i < lim;++ i)
putchar((__builtin_popcount(i&k) & 1) + 'A');
putchar('\n');
}
} | #include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> solve(int n){
if(n==1){
vector<vector<int>> v;
v.resize(1);
v[0].push_back(0); v[0].push_back(1);
return v;
}
vector<vector<int>> u = solve(n - 1);
vector<vector<int>> v;
int x = (1<<n) - 1;
v.resize(x);
int s = 0;
for(int i=0;i<u.size();i++){
for(int k=0;k<2;k++){
for(int j=0;j<u[i].size();j++){
v[s].push_back(u[i][j]);
}
for(int j=0;j<u[i].size();j++){
v[s].push_back(u[i][j]^k);
}
s++;
}
}
for(int i=0;i<(1<<n);i++){
if(i<(1<<(n - 1))) v[s].push_back(0);
else v[s].push_back(1);
}
return v;
}
int main(){
int i,n; cin >> n;
vector<vector<int>> v = solve(n);
cout << (1<<n) - 1 << endl;
for(i=0;i<(1<<n) - 1;i++){
for(int j: v[i]){
if(j==0) cout << "A";
else cout << "B";
}
cout << endl;
}
} |
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
typedef vector<int> vi;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin() \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
void solve()
{
int n;
cin >> n;
vi arr(n), b(n);
forn(i, n)
{
cin >> arr[i];
}
forn(i, n)
{
cin >> b[i];
}
map<int, int> m;
forn(i, n)
{
int x;
cin >> x;
--x;
int val = b[x];
m[val]++;
}
ll cnt = 0;
forn(i, n)
{
if (m.find(arr[i]) != m.end())
{
cnt += m[arr[i]];
}
}
cout << cnt << ln;
}
int main()
{
fast_cin();
ll t = 1;
// cin >> t;
for (int it = 0; it < t; it++)
{
// cout << "Case #" << it + 1 << ": ";
solve();
}
return 0;
} | #include <iostream>
#include <map>
using namespace std;
const int MAX = 1e5;
int main() {
int N; cin >> N;
map<int, long long> a, bc;
int B[MAX], C[MAX];
for (int i = 0; i < N; i++) {
int A; cin >> A;
a[A]++;
}
for (int i = 0; i < N; i++) {
cin >> B[i];
}
for (int i = 0; i < N; i++) {
int C; cin >> C;
bc[B[--C]]++;
}
long long ans = 0;
for (int i = 1; i <= N; i++) {
ans += a[i] * bc[i];
}
cout << ans << endl;
}
|
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
int K;
ll N,M,count=0;
cin>>K>>N>>M;
vector<ll> A(K+10);
//vector<ll> B(K+10);
vector<ll> C(K+10);
vector<ll> D(K+10);
vector<ll> E(K+10);
for(int i=0;i<K;i++){
int X;
cin>>X;
A[i]=M*X;
C[i]=A[i]/N*N;
count+=C[i]/N;
}
count=M-count;
for(int i=0;i<K;i++){
D[i]=abs(A[i]-C[i]);
E[i]=D[i];
}
sort(D);
reverse(D);
for(int j=0;j<count;j++){
for(int i=0;i<K;i++){
if(D[j]==E[i]){
C[i]+=N;
E[i]=abs(E[i]-N);
break;
}
}
}
for(int i=0;i<K;i++){
cout<<C[i]/N<<" ";
}
return 0;}
| #include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
t=0; char ch=getchar(); int f=1;
while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const ll INF=1e18;
const int maxn=(1e5)+10;
int K;
ll n,m,a[maxn],L[maxn],R[maxn];
ll UP(ll x,ll y) {
if (x%y==0) return x/y;
return x/y+1;
}
ll suf[maxn];
bool solve(ll mid,bool flag) {
ll s1=0,s2=0;
for (int i=1;i<=K;i++) {
L[i]=UP(max(0LL,m*a[i]-mid),n);
R[i]=(mid+m*a[i])/n;
if (L[i]>R[i]) return 0;
s1+=L[i],s2+=R[i];
}
if (!flag) return s1<=m&&m<=s2;
for (int i=K;i>=1;i--) {
suf[i]=suf[i+1]+R[i];
suf[i]=min(suf[i],INF);
}
ll sum=0,tmp;
for (int i=1;i<=K;i++) {
if (sum+suf[i+1]+L[i]>=m) tmp=L[i];
else tmp=m-(sum+suf[i+1]);
printf("%lld ",tmp);
sum+=tmp;
}
puts("");
return 1;
}
int main() {
// freopen("1.txt","r",stdin);
read(K);
read(n),read(m);
for (int i=1;i<=K;i++) read(a[i]);
ll l=0,r=INF,res,mid;
while (l<=r) {
mid=(l+r)>>1;
if (solve(mid,0)) res=mid,r=mid-1;
else l=mid+1;
}
solve(res,1);
return 0;
}
/*
REMEMBER:
1. Think TWICE, Code ONCE!
Are there any counterexamples to your algo?
2. Be careful about the BOUNDARIES!
N=1? P=1? Something about 0?
3. Do not make STUPID MISTAKES!
Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/ |
// Problem: D - Kth Excluded
// Contest: AtCoder - AtCoder Beginner Contest 205
// URL: https://atcoder.jp/contests/abc205/tasks/abc205_d
// Memory Limit: 1024 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll power(ll x,ll y,ll m){if(y==0)return 1;ll p=power(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());int get_rand(int l, int r){uniform_int_distribution<int> uid(l,r);return uid(rng);}
vector<ll> Fac(1,1);int Last_Index = 0;
ll nCr(ll n,ll r,ll m){if(r>n) return 0;if(n>Last_Index){for(ll i=Last_Index+1;i<=n;++i){Fac.push_back(Fac[i-1]*i);Fac[i]%=m;}Last_Index=n;}return (((Fac[n]*power(Fac[r],m-2,m))%m)*power(Fac[n-r],m-2,m))%m;}ll gcd(ll a, ll b) {return (b ? gcd(b, a % b) : a);}
#define Test int t;cin>>t;while(t--)
#define endl '\n'
int Google_Test;
#define int ll
void solve()
{
// cout << "Case #" << ++Google_Test << ": ";
int n,q;
cin >> n >> q;
vector<int> v(n);
for(int i=0;i<n;++i)
cin >> v[i];
map<int,int> mp;
sort(v.begin(),v.end());
int last = 0;
for(int i=0;i<n;++i)
{
mp[v[i]]=last+1;
last++;
}
while(q-->0)
{
int k;
cin >> k;
auto it = mp.lower_bound(k+1);
if(it==mp.begin())
{
cout << k << endl;
continue;
}
--it;
k+= (*it).second;
int temp = (*it).second;
auto it2 = mp.lower_bound(k+1);
--it2;
while(it != it2)
{
it = it2;
k += (*it).second - temp;
temp = (*it).second;
it2 = mp.lower_bound(k+1);
--it2;
}
cout << k << endl;
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//Test
solve();
return 0;
}
| /*
ID: tazhiba1
TASK: test
LANG: C++
*/
// author: IskhakKutBilim
#include <bits/stdc++.h>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
long long Sumofn(long long x){
long long sum = 0;
while(x > 0){
sum+= x % 10;
x = x / 10;
}
return sum;
}
long long gcd(long long a, long long b){
while(b){
a %= b;
swap(a,b);
}
return a;
}
long long isprime(long long n){
if( n < 2 )
return false;
int res = n / 2;
while (n % res )
res--;
if( res > 1)
return false;
else
return true;
}
long long lcm(long long a, long long b){
return a / gcd(a,b)*b;
}
int f(int n){
int i = 1;
long long fc = 0;
while(i <= n){
fc = fc * i;
i++;
}
return fc;
}
int main(int argv, char** argc){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
int a[n];
int b[m];
set<int> s;
vector<int> res;
vector<int> v;
for(int i = 0;i < n; i++){
cin >> a[i];
v.push_back(a[i]);
s.insert(a[i]);
}
for(int i = 0;i < m; i++){
cin >> b[i];
s.insert(b[i]);
v.push_back(b[i]);
}
int cnt = 0;
for(set<int>::iterator it = s.begin(); it != s.end(); it++){
for(int i = 0;i < v.size(); i++){
if(*it == v[i]){
cnt++;
}
}
if(cnt < 2){
res.push_back(*it);
}
cnt = 0;
}
if(!v.empty())
for(int i = 0;i < res.size(); i++) cout << res[i] << " ";
return 0;
}
|
#include<bits/stdc++.h>
#define lcm(a,b) (a/__gcd(a,b))*b
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define F first
#define S second
#define mp make_pair
//salida rapida "\n"
//DECIMALES fixed<<sp(n)<<x<<endl;
//gcd(a,b)= ax + by
//lCB x&-x
using namespace std;
int P[505];
vector<pair<double,double> >v;
int n;
double y,x;
void init(){
for(int i=0;i<505;i++){
P[i]=i;
}
}
int _find(int x){
if(P[x]==x){
return x;
}
return P[x]=_find(P[x]);
}
void _union(int x, int y){
x=_find(x);
y=_find(y);
P[x]=y;
}
bool f(double r){
for(int i=0;i<n;i++){
for(int l=i+1;l<n;l++){
if(sqrt(abs(v[i].F-v[l].F)*abs(v[i].F-v[l].F)+abs(v[i].S-v[l].S)*abs(v[i].S-v[l].S))<r){
_union(i,l);
}
}
}
for(int i=0;i<n;i++){
if(100-v[i].S<r){
//cout<<"hrera"<<endl;
// cout<<100<<" - "<<v[i].S<<" "<<r<<endl;
_union(i,500);
}
if(v[i].S+100<r){
_union(i,501);
}
}
if(_find(500)==_find(501)){
return false;
}
return true;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++){
cin>>x>>y;
v.pb({x,y});
}
double b=0.000001,e=100;
double res;
while(e-b>0.00000001){
init();
double mid=(b+e)/2;
if(f(mid*2)){
res=mid;
b=mid+0.00000001;
}else{
e=mid-0.00000001;
}
}
cout<<res<<endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
using namespace std;
using LL = long long;
using P = pair<int,int>;
class UnionFind {
public:
vector <LL> par;
vector <LL> siz;
UnionFind(LL sz_): par(sz_), siz(sz_, 1LL) {
for (LL i = 0; i < sz_; ++i) par[i] = i;
}
void init(LL sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL);
for (LL i = 0; i < sz_; ++i) par[i] = i;
}
LL root(LL x) {
while (par[x] != x) {
x = par[x] = par[par[x]];
}
return x;
}
bool unite(LL x, LL y) {
x = root(x);
y = root(y);
if (x == y) return false;
if (siz[x] < siz[y]) swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool same(LL x, LL y) {
return root(x) == root(y);
}
LL size(LL x) {
return siz[root(x)];
}
};
int main(){
int N;
cin >> N;
vector<P> T(N);
rep(i,N){
int x, y;
cin >> x >> y;
T[i] = P(x,y);
}
rep(i,N){
int x = T[i].first;
if(i == 0 or T[i].first != T[i-1].first){
T.emplace_back(x,100);
T.emplace_back(x,-100);
}
}
sort(T.begin(),T.end());
int siz = T.size();
//rep(i,siz) cout << T[i].second << endl;
for(int r = 1; r <= 40000; r++){
UnionFind uf(siz);
rep(i,siz){
for(int j=i+1; j<siz; j++){
int dx = T[j].first - T[i].first;
if(dx * dx >= r) break;
int dy = T[j].second - T[i].second;
if(dx*dx+dy*dy < r) uf.unite(i,j);
}
}
rep(i,siz){
if(T[i].second == 100){
rep(j,siz){
if(T[j].second != -100) continue;
if(uf.same(i,j)){
double ans = r - 1;
cout << setprecision(15);
cout << sqrt(ans)/2 << endl;
return 0;
}
}
}
else if(T[i].second == -100){
rep(j,siz){
if(T[j].second != 100) continue;
if(uf.same(i,j)){
double ans = r - 1;
cout << setprecision(15);
cout << sqrt(ans)/2 << endl;
return 0;
}
}
}
else continue;
}
}
return 0;
} |
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
int main(){
int N, K, M;
cin >> N >> K >> M;
int tmp, sum = 0;
int target = M * N;
rep(i,N-1){
cerr << "target " << target << endl;
cin >> tmp;
target -= tmp;
}
int ans;
if(target <= 0){
ans = 0;
} else if(target <= K){
ans = target;
} else {
ans = -1;
}
cout << ans << endl;
} | #include<iostream>
#include<algorithm>
using namespace std;
int main(){
int N,K,M,A,sum=0;
cin>>N>>K>>M;
for(int i=0;i<N-1;i++){
cin>>A;
sum+=A;
}
if(N*M-sum<=K)cout<<max(N*M-sum,0);
else cout<<-1;
return 0;
} |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
typedef pair<int, int> P;
typedef long long ll;
int dp[300][300];
int n;
vector<int> bucket;
bool valid(vector<int> x, vector<int> y)
{
if (x.size() == 0 || y.size() == 0)
{
return false;
}
if (x.size() != y.size())
{
return true;
}
rep(i, x.size())
{
if (x[i] != y[i])
{
return true;
}
}
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
rep(i, n)
{
int t;
cin >> t;
bucket.push_back(t % 200);
}
dp[0][0] = 1;
rep(i, n)
{
rep(j, 200)
{
if (dp[i][j] > 0)
{
dp[i + 1][j] += dp[i][j];
dp[i + 1][(j + bucket[i]) % 200] += dp[i][j];
}
}
}
while (true)
{
int s = 0, t = 0;
bool cant = true;
rep(i, n + 1)
{
rep(j, 200)
{
if (j == 0 && dp[i][j] > 2)
{
s = i;
t = j;
cant = false;
}
if (j > 0 && dp[i][j] > 1)
{
s = i;
t = j;
cant = false;
}
}
}
if (cant)
{
cout << "No" << endl;
return 0;
}
int i = s;
int j = t;
vector<int> x;
while (i != 0 && j != 0)
{
if (dp[i - 1][(j + 200 - bucket[i - 1]) % 200] > 0)
{
j = (j + 200 - bucket[i - 1]) % 200;
x.push_back(i);
i--;
}
else
{
i--;
}
}
i = s;
j = t;
vector<int> y;
while (i != 0 && j != 0)
{
if (y.empty() && dp[i - 1][j] > 1)
{
i--;
}
else if (y.empty() && dp[i - 1][(j + 200 - bucket[i - 1]) % 200] > 1)
{
j = (j + 200 - bucket[i - 1]) % 200;
y.push_back(i);
i--;
}
else if (dp[i - 1][j] > 0)
{
i--;
}
else
{
j = (j + 200 - bucket[i - 1]) % 200;
y.push_back(i);
i--;
}
}
if (valid(x, y))
{
reverse(x.begin(), x.end());
reverse(y.begin(), y.end());
cout << "Yes" << endl;
cout << x.size();
for (auto xi : x)
{
cout << ' ' << xi;
}
cout << endl;
cout << y.size();
for (auto yi : y)
{
cout << ' ' << yi;
}
cout << endl;
return 0;
}
else
{
dp[s][t] = 0;
}
}
} | #include <bits/stdc++.h>
#define pb(x) push_back(x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F(w,x,y) for(ll w=x; w<y; w++)
#define endl "\n"
#define mod 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;
void play()
{
ll n;
cin>>n;
vector <ll> v(n);
F(i,0,n)
cin>>v[i];
map <ll,ll> mp;
ll total=1<<(min(n,9LL));
ll ans=-1;
F(i,1,total)
{
ll sum=0;
F(j,0,(min(n,9LL)))
{
if(i&(1<<j))
{
sum+=v[j];
}
}
mp[sum%200]++;
if(mp[sum%200]>1)
{
ans=(sum%200);
break;
}
}
if(ans==-1)
{
cout<<"No\n";
return;
}
cout<<"Yes\n";
ll f=0;
F(i,1,total)
{
ll sum=0, c=0;
F(j,0,(min(n,9LL)))
{
if(i&(1<<j))
{
sum+=v[j];
c++;
}
}
if(ans==sum%200)
{
cout<<c<<" ";
F(j,0,(min(n,9LL)))
{
if(i&(1<<j))
{
cout<<j+1<<" ";
}
}
cout<<endl;
f++;
if(f==2)
break;
}
}
}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
t=1;
//cin>>t;
F(i,1,t+1)
{
//cout<<"Case #"<<i<<": ";
play();
}
return 0;
}
|
#include <bits/stdc++.h>
#define int long long
#define lowbit(x) x & (-x)
using namespace std;
constexpr int maxn = 1000010;
int tr[maxn];
bool vis[maxn];
struct Point {
int x, y;
bool operator < (const Point &W) const {
if (x == W.x) return y < W.y;
else return x < W.x;
}
bool operator == (const Point &W) const {
return x == W.x && y == W.y;
}
} p[maxn];
void add(int x, int n) {
for (int i = x; i <= n; i += lowbit(i)) tr[i]++;
}
int query(int x) {
int ans = 0;
for (int i = x; i > 0; i -= lowbit(i)) ans += tr[i];
return ans;
}
void work() {
int H, W, M;
cin >> H >> W >> M;
int x_min = maxn, y_min = maxn;
for (int i = 1; i <= M; i++) {
cin >> p[i].x >> p[i].y;
if (p[i].x == 1) x_min = min(x_min, p[i].y);
if (p[i].y == 1) y_min = min(y_min, p[i].x);
}
// cout << M << endl;
for (int i = x_min + 1; i <= W; i++) p[++M] = {1, i};
for (int i = y_min + 1; i <= H; i++) p[++M] = {i, 1};
sort(p + 1, p + 1 + M);
M = unique(p + 1, p + M + 1) - (p + 1);
// for (int i = 1; i <= M; i++) cout << p[i].x << " " << p[i].y << endl;
int tmp = 0, h = 1;
for (int i = 1; i <= M; i++) {
if (!vis[p[i].y]) {
vis[p[i].y] = 1;
add(p[i].y, W);
// cout << "---" << endl;
}
if (i == M || p[i].x != p[i + 1].x) {
tmp += query(W) - query(p[h].y - 1);
h = i + 1;
}
}
cout << 1ll * H * W - tmp << endl;
}
int32_t main() {
work();
} | #include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int N = 105;
int A[N], B[N], C[N], D[N];
int solve(int n, int m, int k){
int i,j,ans=0;
unordered_map<int, int> um;
for(i=0;i<(1 << k);i++){
um.clear();
int cnt=0;
for(j=0;j<k;j++){
if(i & (1 << j)){
um[D[j]]++;
}else{
um[C[j]]++;
}
}
for(j=0;j<m;j++){
if(um[A[j]] > 0 && um[B[j]] > 0){
cnt++;
}
}
ans = max(ans, cnt);
}
return ans;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
t=1;
//cin>>t;
while(t--){
int i,n,m,k;
cin>>n>>m;
for(i=0;i<m;i++){
cin>>A[i]>>B[i];
}
cin>>k;
for(i=0;i<k;i++){
cin>>C[i]>>D[i];
}
cout<<solve(n, m, k)<<endl;
}
}
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define ZERO {puts("0"); return 0;}
#define NO {puts("No"); return 0;}
#define ALL(obj) begin(obj), end(obj)
#define pb push_back
template<class T> void chmin(T& a, T b) { if (a > b) a = b; }
template<class T> void chmax(T& a, T b) { if (a < b) a = b; }
// {g,x,y}: ax+by=g
tuple<ll,ll,ll> extgcd(ll a, ll b)
{
if (b == 0) return {a,1,0};
ll g, x, y;
tie(g,x,y) = extgcd(b, a%b);
return {g, y, x-a/b*y};
}
void solve()
{
ll n, s, k;
cin >> n >> s >> k;
ll g, x, y;
tie(g,x,y) = extgcd(k,n);
if (s%g != 0) {
cout << -1 << endl;
return;
}
n /= g;
s /= g;
k /= g;
ll ans = ((x*-s)%n+n)%n;
cout << ans << endl;
}
int main()
{
int t; cin >> t;
rep(i,t) solve();
}
| /* -*- coding: utf-8 -*-
*
* e.cc: E - Throne
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
/* typedef */
typedef long long ll;
/* global variables */
/* subroutines */
void exgcd(ll x, ll y, ll &a, ll &b, ll &c) {
ll r0 = x, r1 = y;
ll a0 = 1, a1 = 0;
ll b0 = 0, b1 = 1;
while (r1 > 0) {
ll q1 = r0 / r1;
ll r2 = r0 % r1;
ll a2 = a0 - q1 * a1;
ll b2 = b0 - q1 * b1;
r0 = r1, r1 = r2;
a0 = a1, a1 = a2;
b0 = b1, b1 = b2;
}
c = r0;
a = a0;
b = b0;
}
/* main */
int main() {
int tn;
scanf("%d", &tn);
while (tn--) {
int n, s, k;
scanf("%d%d%d", &n, &s, &k);
// s + ik == 0(mod n) -> s+ik=jn -> jn-ik=s
ll a, b, c;
exgcd(n, k, a, b, c);
//printf("%d*%lld+%d*%lld=%lld\n", n, a, k, b, c);
if (s % c != 0) puts("-1");
else {
b *= -s / c;
ll d = n / c;
while (b < 0) b = b % d + d;
while (b >= d) b %= d;
printf("%lld\n", b);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < n; i++)
vector<vector<int>> to;
vector<int> used;
vector<int> col;
vector<int> vs;
ll now;
int n;
void dfs(int v) {
if (used[v]) return;
used[v] = 1;
vs.push_back(v);
for (int u: to[v]) dfs(u);
}
void dfs2(int i) {
if (i == vs.size()) { now++; return; }
int v = vs[i];
rep(c, 3) {
col[v] = c;
bool ok = true;
for (int u: to[v]) {
if (col[u] == c) ok = false;
}
if (!ok) continue;
dfs2(i+1);
}
col[v] = -1;
}
int main() {
int m;
cin >> n >> m;
to = vector<vector<int>>(n);
rep(i, m) {
int a,b;
cin >> a >> b;
--a, --b;
to[a].push_back(b);
to[b].push_back(a);
}
ll ans = 1;
used = vector<int>(n);
col = vector<int>(n, -1);
rep(i,n) {
if (used[i]) continue;
vs = vector<int>();
dfs(i);
col[vs[0]] = 0;
now = 0;
dfs2(1);
ans *= 3 * now;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<vector<int>> adj(n, vector<int>(n));
for (int i = 0, u, v; i < m; i++) {
cin >> u >> v, --u, --v;
adj[u][v] = adj[v][u] = 1;
}
vector<int> is_independent(1 << n, 1);
for (int mask = 1; mask < (1 << n); mask++) {
int &f = is_independent[mask];
int msb = 32 - __builtin_clz(mask) - 1;
f = is_independent[mask ^ (1 << msb)];
for (int i = 0; i < msb; i++) {
if (mask >> i & 1) {
f &= !adj[i][msb];
}
}
}
long long ans = 0;
const int all = (1 << n) - 1;
for (int mask = 0; mask < (1 << n); mask++) {
vector<int> col(n, -1);
auto dfs = [&](int x, const auto &self) -> void {
for (int i = 0; i < n; i++) {
if ((mask >> i & 1) && adj[x][i] && col[i] == -1) {
col[i] = 1 ^ col[x];
self(i, self);
}
}
};
int comps = 0;
for (int i = 0; i < n; i++) {
if ((mask >> i & 1) && col[i] == -1) {
col[i] = 0;
dfs(i, dfs);
comps += 1;
}
}
bool is_bipartite = true;
for (int i = 0; i < n; i++) {
if ((mask >> i & 1)) {
for (int j = 0; j < i; j++) {
if ((mask >> j & 1) && adj[i][j]) {
is_bipartite &= col[i] != col[j];
}
}
}
}
ans += is_bipartite * is_independent[all ^ mask] * (1ll << comps);
}
cout << ans << '\n';
return 0;
} |
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
#define vecout(V) for(int i=0;i<V.size();i++) {cout<<V[i]<<endl;}
typedef long long ll;
int main(void){
int n, k, m;
cin>>n>>k>>m;
vector<int> v(n-1);
rep(i, n-1) cin>>v[i];
int sum=accumulate(v.begin(), v.end(), 0);
int ans=n*m-sum;
if(ans<=k) cout<<max(0, ans)<<endl;
else cout<<-1<<endl;
return 0;
} | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int N, K, M;
cin >> N >> K >> M;
vector<int> A(N);
int ans = 0, sum = 0;
for (int i = 0; i < N - 1; i++)
{
cin >> A[i];
sum += A[i];
}
ans = M * N - sum;
if (ans > K) {
cout << "-1" << endl;
}
else if (ans <= 0) {
cout << "0" << endl;
}
else {
cout << ans << endl;
}
} |
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
return S.find(key) != S.end();
}
template<typename T>
vector<T> sieve(T max) {
if(max < 2) {
return {};
}
using flag_type = unsigned char;
vector<flag_type> is_prime(max+1, 1);
// 2
vector<T> primes = {2};
int q = 4;
while(q <= max) {
is_prime[q] = 0;
q += 2;
}
// 3 or more
for(int p=3;p<=max;p+=2) {
if(is_prime[p]) {
primes.push_back(p);
int q = p * 3;
while(q <= max) {
is_prime[q] = 0;
q += p * 2;
}
}
}
return primes;
}
int main(int argc, char *argv[]) {
i64 i, j, k;
i64 N; cin >> N;
vi primes = sieve(N + 1);
vi ans(N+1, 0);
ans[1] = 1;
REP(1, N+1, i) {
for(auto &p: primes) {
if(i*p > N) {
break;
}
i64 n = ans[i] + 1;
if(ans[i*p] == 0) {
ans[i*p] = n;
}
else {
assert(ans[i*p] >= n);
}
}
}
REP(1, N+1, i) {
if(i != 1) {
printf(" ");
}
printf("%lld", ans[i]);
}
printf("\n");
return 0;
}
| //a.9
#include<bits/stdc++.h>
#define ll long long
#define all(x) x.begin(),x.end()
#define CASE(t) cout<<"Case #"<<(t)<<": ";
#define endll endl
#define endl '\n'
#define mod 1000000007
#define INF 1e18
#define maxN 500005
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
ll ceill(ll a,ll b){return a/b+bool(a%b);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b, a % b);}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll power(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x)%mod;x=(x*x)%mod;y>>=1;}return res;}
bool isPrime(ll n)
{
if(n<=1)return false;if(n<=3)return true;if(n%2==0 || n%3==0)return false;
for(ll i=5;i*i<=n;i=i+6)if(n%i==0 || n%(i+2)==0) return false; return true;
}
void primeFactors(ll n, vector<ll> &vec)
{
while(n%2==0)vec.push_back(2),n/=2;
for(ll i=3;i<=sqrt(n);i+=2)while(n%i==0)vec.push_back(i),n/=i;
if(n>2)vec.push_back(n);
}
//vector<ll>fact(maxN);
//void factpre(){fact[0]=1;for(ll i=1;i<maxN;i++)fact[i]=(fact[i-1]*1LL*i);}
//ll mul(ll a,ll b){return (a*1LL*b)%mod;}
//ll nCr(ll n,ll k){return mul(fact[n],power(mul(fact[k],fact[n-k]),mod-2));}
bool chk(ll n)
{
return n&&(!(n&(n-1)));
}
void solve()
{
ll n;cin>>n;
ll tmp=0;
for(ll i=1;i<=n;i++)
{
if(i==1 || chk(i))cout<<(++tmp)<<" ";
else cout<<tmp<<" ";
}
cout<<endl;
}
signed main()
{
ios;
ll tc=1; //cin>>tc;
for(ll TTT=1;TTT<=tc;TTT++)
{
//CASE(TTT);
solve();
}
}
|
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map> //http://vivi.dyndns.org/tech/cpp/map.html
#include <set> //http://vivi.dyndns.org/tech/cpp/set.html
#include <vector>
#include <deque>
#include <queue>
#include <numeric> //gcd,lcm c++17
#include <tuple>
#include <iomanip> //setprecision
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define ALL(a) (a).begin(), (a).end()
#define sz(x) (int)(x).size()
template <class T1, class T2, class Pred = std::less<T2>>
struct sort_pair_second
{
bool operator()(const std::pair<T1, T2> &left, const std::pair<T1, T2> &right)
{
Pred p;
return p(left.second, right.second);
}
};
int MOD = 1e9 + 7;
double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
int main()
{
double A, B;
cin >> A >> B;
cout << (1.0 - B / A) * (double)100 << endl;
} | #include<bits/stdc++.h>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define T int t, q=0; scanf("%d", &t); while(q++<t)
#define ll long long
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll x,y,z,a=0,b=0,c=0,d=0,sum,ans,total,cnt,n,m,k,p,kase,i;
string s1,s2;
#define N 100001
#define MX 1000000001
vector <ll> v;
map<ll,ll> mp;
set<ll> s;
map<ll,ll> :: iterator itr1, ptr1;
set<ll> :: iterator itr, ptr;
ll tow(ll a, ll b) {
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);
}
//SET PRECIOSION cout << fixed ; cout << setprecision(n) << ans << endl;
int main()
{
ll n;
cin>>n;
ll ans=1;
ll p[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
for(int i=0;i<10;i++)
{
ll temp=1;
while(temp*p[i]<=n) temp*=p[i];
ans*=temp;
}
cout<<ans+1<<endl;
}
// Happy Coding (:
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s; cin >> s;
int n = s.size();
if(n == 1){
if(s=="8") {
cout << "Yes" << endl;
return 0;
}
}
if(n == 2) {
int a = s[0] - '0', b = s[1] - '0';
if((a * 10 + b) % 8 == 0 || (b * 10 + a) % 8 == 0) {
cout << "Yes" << endl;
return 0;
}
}
vector<int> cnt(10);
for(int i = 0; i < n; ++i) {
++cnt[s[i] - '0'];
}
for(int i = 0; i < 1000; i += 8) {
int a = i / 100, b = i / 10 % 10, c = i % 10;
--cnt[a]; --cnt[b]; --cnt[c];
if(cnt[a] >= 0 && cnt[b] >= 0 && cnt[c] >= 0) {
cout << "Yes" << endl;
return 0;
}
++cnt[a]; ++cnt[b]; ++cnt[c];
}
cout << "No" << endl;
return 0;
} | #include <iostream>
using namespace std;
string Save[3][125];
string erase(string n,int index){
string a,b;
a=b="";
for(int i=0;i<index;i++){
a+=n[i];
}
for(int i=index+1;i<n.length();i++){
b+=n[i];
}
return a+b;
}
int main() {
int c1,c2,c3;
c1=c2=c3=0;
for(int i=8;i<1000;i+=8){
if(to_string(i).length()==3){
Save[2][c3]=to_string(i);
c3++;
}else if(to_string(i).length()==2){
Save[1][c2]=to_string(i);
c2++;
}else{
Save[0][c1]=to_string(i);
c1++;
}
}
string S;
cin>>S;
string temp;//Temporary S, we need S!
int find_i;//Finding the # index of the chart
if(S.length()>=3){//If S has 3 or more digits
for(int i=0;i<c3;i++){
temp=S;
find_i=0;
for(int j=0;j<temp.length() and find_i<3;j++){
if(temp[j]==Save[2][i][find_i]){
find_i++;
temp=erase(temp,j);
j=-1;
}
}
if(find_i==3){
cout<<"Yes";
break;
}
if(i==c3-1){
cout<<"No";
break;
}
}
}else if(S.length()==2){//If S has 2 digits
for(int i=0;i<c2;i++){
temp=S;
find_i=0;
for(int j=0;j<temp.length() and find_i<2;j++){
if(temp[j]==Save[1][i][find_i]){
find_i++;
temp=erase(temp,j);
j=-1;
}
}
if(find_i==2){
cout<<"Yes";
break;
}
if(i==c2-1){
cout<<"No";
break;
}
}
}else{//If S has 1 digit
if(S=="8"){
cout<<"Yes";
}else{
cout<<"No";
}
}
} |
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<deque>
#include<list>
using namespace std;
using P = pair<int,int>;
using ll = long long;
const long double EPS = 1e-10;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
int main(){
string S;
list<char> T;
bool rev = false;
cin >> S;
for(int i = 0 ; i < S.size() ; i++){
if(S[i] == 'R')
rev = !rev;
else{
if(rev){
if(T.front() == S[i])
T.pop_front();
else
T.push_front(S[i]);
}
else{
if(T.back() == S[i])
T.pop_back();
else
T.push_back(S[i]);
}
}
}
string ans;
for(auto x : T)
ans += x;
if(rev)
reverse(ans.begin(),ans.end());
cout << ans << endl;
}
| //红太阳zhouakngyang txdy!
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
using namespace std;
//#define int long long
inline int read()
{
int sum=0,nega=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')nega=-1;ch=getchar();}
while(ch<='9'&&ch>='0')sum=sum*10+ch-'0',ch=getchar();
return sum*nega;
}
int n,L=500001,R=500000,flag,top;
char a[500009],ans[1000009],res[1000009];
char out[1000009];
int main()
{
scanf("%s",a+1);n=strlen(a+1);
for(int i=1;i<=n;i++)
{
if(a[i]=='R')flag^=1;
else
{
if(flag)L--,res[L]=a[i];
else R++,res[R]=a[i];
}
}
if(!flag)
for(int i=1;i<=R-L+1;i++)ans[i]=res[i+L-1];
else
for(int i=1;i<=R-L+1;i++)ans[i]=res[R+1-i];
for(int i=1;i<=R-L+1;i++)
{
out[++top]=ans[i];
while(top!=0&&out[top]==out[top-1])top-=2;
}
for(int i=1;i<=top;i++)putchar(out[i]);
return 0;
}
|
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
const int SIZE = 200005;
const int BLOCK = 200005;
class SegTree{
public:
int v[SIZE*4];
SegTree(){
memset(v,0,sizeof(v));
}
int get(int node, int L, int R, int LQ, int RQ){
if(R<LQ || RQ<L) return 0;
if(LQ<=L && R<=RQ) return v[node];
int s = get(node*2+1,L,(L+R)/2,LQ,RQ);
int t = get(node*2+2,(L+R)/2+1,R,LQ,RQ);
return s+t;
}
int update(int node, int L, int R, int Q, int chVal){
if(R<Q || Q<L) return v[node];
if(L==R) return v[node] = chVal;
int s = update(node*2+1,L,(L+R)/2,Q,chVal);
int t = update(node*2+2,(L+R)/2+1,R,Q,chVal);
return v[node] = s+t;
}
};
int row, col;
int nBlock, blockPos[BLOCK][2];
void read() {
cin >> row >> col >> nBlock;
for (int i = 0; i < nBlock; ++i) {
cin >> blockPos[i][0] >> blockPos[i][1];
--blockPos[i][0];
--blockPos[i][1];
}
}
void work() {
static vector<int> row2col[SIZE], col2row[SIZE];
for (int i = 0; i < SIZE; ++i) {
row2col[i].clear();
col2row[i].clear();
}
for (int i = 0; i < nBlock; ++i) {
row2col[blockPos[i][0]].push_back(blockPos[i][1]);
col2row[blockPos[i][1]].push_back(blockPos[i][0]);
}
for (int i = 0; i < SIZE; ++i) {
sort(row2col[i].begin(), row2col[i].end());
sort(col2row[i].begin(), col2row[i].end());
}
long long sum = 0;
// Add horizontal line
for (int r = 0; r < (col2row[0].size() > 0 ? col2row[0][0] : row); ++r) {
sum += row2col[r].size() > 0 ? row2col[r][0] : col;
}
// Add vertical line
static SegTree stree;
stree = SegTree();
for (int c = 0; c < (row2col[0].size() > 0 ? row2col[0][0] : col); ++c) {
int until = col2row[c].size() > 0 ? col2row[c][0] - 1 : row - 1;
if (until >= 0)
sum += stree.get(0, 0, row - 1, 0, until);
if (c == 0) {
for (int r = (col2row[0].size() > 0 ? col2row[0][0] : row); r < row; ++r) {
stree.update(0, 0, row - 1, r, 1);
}
} else {
for (int i = 0; i < col2row[c].size(); ++i) {
stree.update(0, 0, row - 1, col2row[c][i], 1);
}
}
}
cout << sum << endl;
}
int main() {
read();
work();
return 0;
}
| #include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF = 4e18;
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);}
void print() { print0("\n"); }
template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);}
// clang-format on
string a, b, c;
ll na, nb, nc;
vector<ll> aa, bb, cc;
ll nmp[10];
inline ll getnum(char c) {
if (nmp[0] == c) return 0;
if (nmp[1] == c) return 1;
if (nmp[2] == c) return 2;
if (nmp[3] == c) return 3;
if (nmp[4] == c) return 4;
if (nmp[5] == c) return 5;
if (nmp[6] == c) return 6;
if (nmp[7] == c) return 7;
if (nmp[8] == c) return 8;
if (nmp[9] == c) return 9;
return -1;
}
inline ll getchar(ll n) {
return nmp[n];
}
void fail() {
print("UNSOLVABLE");
exit(0);
}
void success() {
for (ll i = 0; i < na; i++) {
print0(aa[na - i - 1]);
}
print();
for (ll i = 0; i < nb; i++) {
print0(bb[nb - i - 1]);
}
print();
for (ll i = 0; i < nc; i++) {
print0(cc[nc - i - 1]);
}
print();
exit(0);
}
void rec(ll i, ll kuri, ll abc, vector<ll> &nvec, string &ts) {
if (abc == 0 || abc == 1) {
ll nn = ts.size();
if (i >= nn) {
rec(i, kuri, abc + 1, bb, b);
return;
}
char d = ts[i];
if (getnum(d) < 0) {
for (ll j = 0; j < 10; j++) {
if (nmp[j] >= 0) continue;
nmp[j] = d;
nvec.push_back(getnum(d));
rec(i, kuri, abc + 1, bb, b);
nvec.pop_back();
nmp[j] = -1;
}
} else {
nvec.push_back(getnum(d));
rec(i, kuri, abc + 1, bb, b);
nvec.pop_back();
}
}
if (abc == 2) {
char d = c[i];
ll cv = kuri;
if (i < na) cv += aa[i];
if (i < nb) cv += bb[i];
ll nkuri = 0;
if (cv >= 10) {
nkuri = 1;
cv -= 10;
}
bool change = false;
if (getnum(d) < 0) {
if (getchar(cv) >= 0) {
return;
}
nmp[cv] = d;
change = true;
}
if (getnum(d) != cv) {
return;
}
if (i == nc - 1) {
cc.push_back(cv);
if (!(nkuri > 0 || aa.back() == 0 || bb.back() == 0 || cc.back() == 0)) {
success();
}
cc.pop_back();
} else {
cc.push_back(cv);
rec(i + 1, nkuri, 0, aa, a);
cc.pop_back();
}
if (change) {
nmp[cv] = -1;
}
}
}
int main() {
cin >> a >> b >> c;
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
reverse(c.begin(), c.end());
na = a.size();
nb = b.size();
nc = c.size();
if (na > nc || nb > nc || nc > max(na, nb) + 1) {
fail();
}
{
set<char> chars;
for (char x : a) {
chars.insert(x);
}
for (char x : b) {
chars.insert(x);
}
for (char x : c) {
chars.insert(x);
}
if (chars.size() > 10) {
fail();
}
}
for(ll i=0;i<10;i++){
nmp[i]=-1;
}
rec(0, 0, 0, aa, a);
fail();
}
|
/*
このコード、と~おれ!
Be accepted!
∧_∧
(。・ω・。)つ━☆・*。
⊂ ノ ・゜+.
しーJ °。+ *´¨)
.· ´¸.·*´¨) ¸.·*¨)
(¸.·´ (¸.·'* ☆
*/
#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define repeat(i, n, m) for(int i = n; i < (m); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()
using ll = long long;
using ull = unsigned long long;
constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);
using namespace std;
void scans(string& str) {
char c;
str = "";
scanf("%c", &c);
if (c == '\n')scanf("%c", &c);
while (c != '\n' && c != -1 && c != ' ') {
str += c;
scanf("%c", &c);
}
}
void scanc(char& str) {
char c;
scanf("%c", &c);
if (c == -1)return;
while (c == '\n') {
scanf("%c", &c);
}
str = c;
}
double acot(double x) {
return PI / 2 - atan(x);
}
ll LSB(ll n) { return (n & (-n)); }
template<typename T>
inline T chmin(T& a, const T& b) {
if (a > b)a = b;
return a;
}
template<typename T>
inline T chmax(T& a, const T& b) {
if (a < b)a = b;
return a;
}
//atcoder library
//#include <atcoder/all>
//using namespace atcoder;
/*-----------------------------------------ここからコード-----------------------------------------*/
int main() {
string s;
scans(s);
int sum = 0, one = 0, two = 0;
for (const auto& aa : s) {
sum += aa - '0';
if ((aa - '0') % 3 == 1)++one;
else if ((aa - '0') % 3 == 2)++two;
}
sum %= 3;
if (sum == 0)puts("0");
else if (sum == 1) {
if (one and s.length() > 1)puts("1");
else if (two > 1 and s.length() > 2)puts("2");
else puts("-1");
}
else {
if (two and s.length() > 1)puts("1");
else if (one > 1 and s.length() > 2)puts("2");
else puts("-1");
}
Please AC;
} | /*input
11
*/
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define fr first
#define sc second
#define eps 1e-9
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define sni(x) scanf("%d",&x)
#define snl(x) scanf("%lld", &x)
#define snc(x) scanf("%c", &c);
#define rep(n) for(int i = 0 ; i < n ;i ++)
#define repc(i, n) for(int i = 0 ; i < n ; i ++)
#define FOR(i, x, y) for(int i = x ; i < y ; i ++)
#define DEC(i, x, y) for(int i = x ; i >= y ; i --)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b,c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a+n
using namespace std;
typedef long long ll;
const ll INF = 1e18;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
string s;
ll go(ll i, ll sum)
{
if (i == s.length())
{
if (sum % 3 == 0 and sum != 0)
return 0;
else
return INT_MIN;
}
ll res = INT_MIN;
res = max(go(i + 1, sum + (s[i] - '0')) + 1, go(i + 1, sum));
return res;
}
int main()
{
cin >> s;
ll res = 0;
FOR(i, 0, s.length())
res += s[i] - '0';
if (res % 3 == 0)
{
cout << 0;
return 0;
}
ll ans = go(0, 0);
if (ans < 0)
cout << -1;
else
cout << ((ll)s.length() - ans);
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout << "(" << #x << ": " << x << ")" << endl;
void solve() {
int x,y;
cin >> x >> y;
bool flag=0;
if(x<y) {
if(x+3>y)
flag=1;
}
else {
if(y+3>x)
flag=1;
}
cout << (flag==1? "Yes\n":"No\n");
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t=1;
while (t--)
{
solve();
}
} | #include <bits/stdc++.h>
#define loop(n) for(ll i=0;i<n;i++)
#define loopj(n) for(ll j=0;j<n;j++)
#define loopR(i,a,b,c) for(ll i=a;i>=b;i-=c)
#define rng(i,a,b,c) for(ll i = a; i<b;i+=c)
#define loop2(i,a,b) for(long long i = a; i>=b;i--)
#define loop3(j,a,b) for(int j = a; j<b;j++)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long
#define ld long double
#define SET set<ll>
#define pb push_back
#define mp make_pair
#define gc getchar_unlocked
#define in ll n;cin>>n;
#define all(s) s.begin(),s.end()
ll mod=pow(10,9)+7;
using namespace std;
//--------------------------\\
//code once think twice
ll gcd(ll a,ll b)
{
if(b==0)
return a;
return gcd(b,a%b);
}
void go()
{
ll a,b;
cin>>a>>b;
if(min(a,b)+3>max(a,b))
cout<<"Yes";
else
cout<<"No";
}
int main()
{
int t;
fast;
//cin>>t;
//
//loop(t)
go();
} |
Subsets and Splits