code1
stringlengths 54
12k
| code2
stringlengths 65
12k
| similar
int64 0
1
| __index_level_0__
int64 1
101M
|
|---|---|---|---|
#include <iostream>
#include <ios>
#include <list>
#include <iomanip>
#include <math.h>
using namespace std;
#define FOR(it) for(Points::iterator it = list.begin(); it != list.end(); ++it)
struct Point
{
Point(double _x, double _y) :x(_x), y(_y){}
double x;
double y;
};
typedef list<Point> Points;
void CreatePoints(const Point& p1, const Point& p2, Points& ps)
{
double x1, x2, x3, y1, y2, y3;
x1 = p1.x + (p2.x - p1.x) / 3;
x3 = p1.x + 2 * (p2.x - p1.x) / 3;
y1 = p1.y + (p2.y - p1.y) / 3;
y3 = p1.y + 2 * (p2.y - p1.y) / 3;
double r3 = sqrt(3);
x2 = ((x3 - x1) - r3 * (y3 - y1))/2 + x1;
y2 = (r3 * (x3 - x1) + (y3 - y1))/2 + y1;
ps.push_back(Point(x1, y1));
ps.push_back(Point(x2, y2));
ps.push_back(Point(x3, y3));
}
void KochCurve(int n, Points& list)
{
if (0 == n) return;
Points::iterator it, preit;
for (it = list.begin(); it != list.end(); ++it){
if (it == list.begin()){
preit = it;
continue;
}
Points addPs;
CreatePoints(*preit, *it, addPs);
list.insert(it, addPs.begin(), addPs.end());
preit = it;
}
return KochCurve(n - 1, list);
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
Points list;
list.push_back(Point(0., 0.));
list.push_back(Point(100., 0.));
KochCurve(n, list);
FOR(it)
cout << fixed << std::setprecision(5) << it->x << " " << it->y << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define NMAX 2010
const ll mod = 1000000000 + 7;
ll n, m;
ll dp[NMAX][NMAX];
ll s[NMAX], t[NMAX];
void init() {
rep(i, 0, NMAX) {
rep(j, 0, NMAX) dp[i][j] = 0;
}
}
int main(){
cin >> n >> m;
rep(i, 0, n) cin >> s[i];
rep(i, 0, m) cin >> t[i];
init();
rep(i, 1, n+1) {
rep(j, 1, m+1) {
if(s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
dp[i][j] += (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]) % mod;
dp[i][j] += mod;
dp[i][j] %= mod;
}
}
cout << (dp[n][m]+1) % mod << endl;
return 0;
}
| 0
| 72,949,252
|
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <utility>
#define dprintf(s,...) printf("%s:%d" s,__func__,__LINE__,__VA_ARGS__)
using namespace std;
typedef pair<int,int> P;
typedef long long int ll;
class Edge{
public:
int to,cost;
Edge(int t,int c){
to = t;
cost = c;
}
};
int n,k;
int d[10][10];
vector<Edge> G[10];
void dijekstra(int s){
priority_queue<P, vector<P>, greater<P> > qu;
qu.push(P(0,s));
d[s][s]=0;
while(!qu.empty()){
P p = qu.top();
int v = p.second;
qu.pop();
if(d[s][v] < p.first) continue;
for(int i=0; i<G[v].size(); i++){
Edge e = G[v][i];
if(d[s][v]+e.cost < d[s][e.to]){
d[s][e.to] = d[s][v]+e.cost;
qu.push(P(d[s][e.to], e.to));
}
}
}
}
void solve(){
for(int i=0;i<k;i++)
for(int j=0;j<k;j++){
d[i][j]=INT_MAX/3;
}
for(int i=0;i<k;i++){
dijekstra(i);
}
}
int main(){
ios_base::sync_with_stdio(false);
while(1){
k=0;
cin>>n;
if(n==0) break;
for(int i=0;i<n;i++){
int a,b,c;
cin>>a>>b>>c;
Edge e1(a,c),e2(b,c);
G[a].push_back(e2);
G[b].push_back(e1);
k = max(k,max(a,b));
}
k++;
solve();
int sum[10];
int ans, min_cost=INT_MAX/3;
fill(sum,sum+10,0);
for(int i=k-1;i>=0;i--){
for(int j=0; j<k; j++){
sum[i] += d[i][j];
}
if(sum[i] <= min_cost){
ans = i;
min_cost = sum[i];
}
}
cout<<ans<<" "<<min_cost<<endl;
for(int i=0;i<10;i++){
G[i].erase(G[i].begin(), G[i].end());
}
}
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
const int maxn = 4005;
char s[maxn];
int p[maxn], p1[maxn], p2[maxn];
int main(int argc, char const *argv[])
{
int n;
scanf("%d", &n);
scanf("%s", s);
for(int i = 0; i < n; ++i){
if(s[i] == 'R'){
p[i] = 1;
}else if(s[i] == 'G'){
p1[i] = 1;
}else {
p2[i] = 1;
}
}
for(int i = 1; i < n; ++i){
p[i] += p[i - 1]; p1[i] += p1[i - 1]; p2[i] += p2[i - 1];
}
long long ans = 0;
for(int i = 0; i < n; ++i){
for(int j = i + 1; j < n; ++j){
int dis = j - i;
if(s[i] == 'R' && s[j] == 'G'){
ans += p2[n - 1] - p2[j];
if(j + dis < n){
if(s[j + dis] == 'B')ans--;
}
}
if(s[i] == 'R' && s[j] == 'B'){
ans += p1[n - 1] - p1[j];
if(j + dis < n){
if(s[j + dis] == 'G')ans--;
}
}
if(s[i] == 'B' && s[j] == 'R'){
ans += p1[n - 1] - p1[j];
if(j + dis < n){
if(s[j + dis] == 'G')ans--;
}
}
if(s[i] == 'G' && s[j] == 'R'){
ans += p2[n - 1] - p2[j];
if(j + dis < n){
if(s[j + dis] == 'B')ans--;
}
}
if(s[i] == 'G' && s[j] == 'B'){
ans += p[n - 1] - p[j];
if(j + dis < n){
if(s[j + dis] == 'R'){
ans--;
}
}
}
if(s[i] == 'B' && s[j] == 'G'){
ans += p[n - 1] - p[j];
if(j + dis < n){
if(s[j + dis] == 'R')ans--;
}
}
}
}
cout << ans << endl;
return 0;
}
| 0
| 45,439,781
|
#include <bits/stdc++.h>
const int N = 100005;
int read()
{
int 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 * 10 + ch - '0'; ch = getchar();}
return x * f;
}
int a[N],b[N];
int main()
{
int n = read(), L = read(), T = read();
int s = 1;
for (int i = 1; i <= n; i++)
{
int x = read(), w = read();
if (w == 1)
{
a[i] = (x + T) % L;
if (T >= L - x)
(s -= (T - L + x) / L + 1) %= n;
}
else
{
a[i] = ((x - T) % L + L) % L;
if (T >= x + 1)
(s += (T - x - 1) / L + 1) %= n;
}
}
s = (s % n + n - 1) % n + 1;
std::sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++)
b[(s + i - 2) % n + 1] = a[i];
for (int i = 1; i <= n; i++)
printf("%d\n",b[i]);
}
|
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define fi first
#define se second
using pii = pair<int,int>;
using ll = long long;
using vi = vector<int>;
int V, E;
vi G[100010];
int indeg[100010];
void topologicalSort(vi &ans)
{
memset(indeg, 0, sizeof(indeg));
ans.reserve(V+1);
rep(i, V) {
for (const auto &to : G[i]) {
++indeg[to];
}
}
{
queue<int> que;
rep(i, V) {
if (indeg[i] == 0) que.push(i);
}
while ( !que.empty()) {
int u = que.front(); que.pop();
ans.push_back(u);
for (const auto &e: G[u]) {
--indeg[e];
if (indeg[e] == 0) que.push(e);
}
}
}
return;
}
int main()
{
vi ans;
cin.tie(0), ios::sync_with_stdio(false);
cin >> V>> E;
rep(i, E) {
int s, t;
cin >> s >> t;
G[s].push_back(t);
}
topologicalSort(ans);
for (const auto &e: ans)
outl(e);
return (0);
}
| 0
| 15,888,577
|
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';
const int mx=100010;
const ll mod=1e9+7;
int main(){
int n,m,k;
cin >> n >> m >> k;
rep(i,m+1)rep(j,n+1){
if(i*n+j*m-i*j*2 == k){
cout << "Yes" << ln; return 0;
}
}
cout << "No" << ln;
return 0;
}
|
#include<stdio.h>
int main(void){
int n,x,i,j,k,c;
int a[1024]={0};
c=0;
while(1){
scanf("%d %d",&n,&x);
if(n==0 && x==0){
break;
}
for(i=1;i<=n-2;i++){
for(j=i+1;j<=n-1;j++){
for(k=j+1;k<=n;k++){
if(i+j+k==x){
a[c]++;
}
}
}
}
c=c+1;
}
for(i=0;i<c;i++){
printf("%d\n",a[i]);
}
return 0;
}
| 0
| 4,488,291
|
#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>;
void Yes() {
cout << "Yes" << endl;
}
void No() {
cout << "No" << endl;
}
int main(void) {
string s; cin >> s;
sort(s.begin(), s.end());
bool ok = false;
do {
if(s == "abc") ok = true;
} while (next_permutation(s.begin(), s.end()));
if(ok) Yes();
else No();
}
|
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;
int main()
{
for(;;){
int n, m, p;
cin >> n >> m >> p;
if(n == 0)
return 0;
vector<int> x(n);
for(int i=0; i<n; ++i)
cin >> x[i];
if(x[m-1] == 0){
cout << 0 << endl;
}else{
int ret = accumulate(x.begin(), x.end(), 0);
ret *= 100 - p;
ret /= x[m-1];
cout << ret << endl;
}
}
}
| 0
| 15,584,180
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template <class T>
void print_vect(std::vector<T> v){
for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
cout << endl;
}
void solve(){
int n;
cin >> n;
vi d(n);
for(int i = 0 ; i < n ; i++){
cin >> d[i];
}
sort(d.begin(), d.end());
int lb = d[(n-1)/2] + 1;
int rb = d[n/2];
int ans = rb - lb + 1;
cout << ans << endl;
}
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
#ifdef DEBUG
int TEST_CASES = 2;
while(TEST_CASES--){
#endif
solve();
#ifdef DEBUG
}
#endif
return 0;
}
|
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll nCr(int n, int r){
ll num = 1;
for(int i = 1; i <= r; i++){
num = num * (n - i + 1) / i;
}
return num;
}
int main(){
int N;
cin >> N;
vector<int> A(N);
for(int i = 0; i < N; i++) cin >> A[i];
map<int,int> M;
for(int a : A) M[a]++;
ll ans = 0;
for(auto p : M){
ans += nCr(p.se, 2);
}
for(int a : A){
cout << ans - nCr(M[a], 2) + nCr(M[a] -1, 2) << endl;
}
}
| 0
| 100,877,872
|
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <string>
using namespace std;
int main() {
long long L,R;
cin >> L>>R;
long long min = 2019;
for(long long i = L;i<=R;i++){
for(long long j = L;j<=R;j++){
if(i==j) continue;
if((i*j)%2019== 0){
cout<<0;
return 0;
}
if(min >= (i*j)%2019) min = (i*j)%2019;
}
}
cout<<min;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;
ll dp[110][110];
int main(){
ll h,w;cin>>h>>w;
char c[110][110];
rep(i,0,h)rep(j,0,w)cin>>c[i][j];
ll x[2]={-1,0},y[2]={0,-1};
rep(i,0,h)rep(j,0,w)dp[i][j]=1e7;
if(c[0][0]=='#')dp[0][0]=-1;
else dp[0][0]=0;
rep(i,0,h){
rep(j,0,w){
rep(k,0,2){
if(i+x[k]<0||j+y[k]<0)continue;
if(c[i][j]=='#'&&dp[i+x[k]][j+y[k]]<0)dp[i][j]=(-1)*min(abs(dp[i][j]),(-1)*dp[i+x[k]][j+y[k]]);
else if(c[i][j]=='#'&&dp[i+x[k]][j+y[k]]>=0)dp[i][j]=(-1)*min(abs(dp[i][j]),dp[i+x[k]][j+y[k]]+1);
else if(c[i][j]=='.'&&dp[i+x[k]][j+y[k]]<0)dp[i][j]=min(dp[i][j],(-1)*dp[i+x[k]][j+y[k]]);
else if(c[i][j]=='.'&&dp[i+x[k]][j+y[k]]>=0)dp[i][j]=min(dp[i][j],dp[i+x[k]][j+y[k]]);
}
}
}
cout<<abs(dp[h-1][w-1])<<endl;
}
| 0
| 76,334,094
|
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include<map>
#include<cmath>
#include<set>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a) for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
ll ret = 1;
for(; e > 0; e >>= 1)
{
if(e & 1) ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
ll ret = 0;
for(; e > 0; e >>= 1)
{
if(e & 1) ret = (ret + p) ;
p = (p + p) ;
if(ret>=M)ret-=M;
if(p>=M)p-=M;
}
return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
if(b == 0)return a;
return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
ll ret = 1;
for(; e > 0; e >>= 1)
{
if(e & 1) ret = (ret * p);
p = (p * p);
}
return (T)ret;
}
template <class T>bool ISLEFT(T a, T b, T c)
{
if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;
else return 0;
}
#define mx 200004
#define base 193ll
typedef pair<int,int >P;
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX 1000007
#define md 1000000007ll
int main(){
string a, b;
cin>>a>>b;
string k;
for(int i = 0; i < a.size(); i++) {
string l;
for(int j=i; j<a.size(); j++)l+=a[j];
if(l+k ==b) {
cout<<"Yes"<<endl;
return 0;
}
k+= a[i];
}
cout<<"No"<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void){
int x,flag=0;
cin>>x;
std::deque<int> deq{105,104,103,102,101,100};
for (int i=0;i<6;i++) {
if (x%deq[i]==0) {
cout<<1<<endl;
flag=1;
break;
} else {
int tmp=x/deq[i];
for (int j=tmp;j>=1;j--) {
for (int k=i+1;k<6;k++) {
if ((x-deq[i]*j)%deq[k]==0) {
cout<<1<<endl;
flag=1;
break;
}
}
if (flag==1) {
break;
}
}
}
if (flag==1) {
break;
}
}
if (flag==0) {
cout<<0<<endl;
}
}
| 0
| 33,029,819
|
#include <iostream>
using namespace std;
int n,y,m,d;
int ax,ay,b,c;
int sum;
int main(){
cin >>n;
for(int i=0;i<n;i++){
cin >>y >>m >>d;
sum=1;
ax=999/3-y/3;
ay=(999-y)-ax;
sum+=ax*200+ay*195;
b=10-m;
if(y%3==0){
sum+=b*20+(20-d);
}else{
sum+=(b/2)*39+(b%2)*19;
if(b%2==0){
sum+=(19-d);
}else{
sum+=(20-d);
}
}
cout <<sum <<endl;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
map<int,int> mp;
for(int i = 0; i < 3; i++){
int a; cin >> a; mp[a]++;
}
for(auto i : mp){
if(i.second == 1){
cout << i.first << endl;
return 0;
}
}
}
| 0
| 90,702,224
|
#include <bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<n;++i)
#define repe(i,k,n) for(int i=k;i<=n;++i)
using namespace std;
int main()
{
cin.tie(0);cout.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> a(n);
rep(i,0,n)
{
cin >> a[i];
}
int res = 1e9;
repe(i,1,100)
{
int temp=0;
for (auto c:a){
temp += (c-i)*(c-i);
}
res = min(temp,res);
}
cout << res;
return 0;
}
|
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;
ll expo(ll a, ll b){
ll ex = 1;
rep(i, b){
ex *= a;
}
return ex;
}
ll fact(ll a){
ll fc = 1;
REP(i, 1, a+1){
fc *= i;
}
return fc;
}
int main() {
ll r;
cin >> r;
if(r<1200) {
cout << "ABC" << endl;
}
else if(r<2800) {
cout << "ARC" << endl;
}
else {
cout << "AGC" << endl;
}
}
| 0
| 73,637,706
|
#include <iostream>
#include <string>
using namespace std;
const int N_MAX = 100;
int main(int argc, char *argv[])
{
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
int G[100][100] = { 0 };
for (int i = 0; i< n; i++)
{
int u, k;
cin >> u;
cin >> k;
for (int i = 0; i < k; i++)
{
int v;
cin >> v;
G[u-1][v-1] = 1;
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cout << G[i][j];
if (j != n - 1)
cout << " ";
}
cout << 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;
int main(void){
int N;
cin>>N;
string FW,W;
map<string,int> check;
cin>>FW;
bool judge=true;
int len=FW.size()-1;
char lw=FW[len];
check[FW]++;
rep(i,N-1){
cin>>W;
len=W.size()-1;
if(lw!=W[0]){
judge=false;
break;
}
lw=W[len];
check[W]++;
if(check[W]==2){
judge=false;
break;
}
}
if(judge==true){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}
| 0
| 46,428,317
|
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
int n;
cin >> n;
priority_queue<pair<ll,pair<ll,ll>>> que;
ll sum1 = 0;
ll sum2 = 0;
for(int i = 0;i < n;i++){
ll a,b;
cin >> a >> b;
que.push(make_pair(a+b,make_pair(a,b)));
}
for(int i = 0;i < n;i++){
pair<ll,pair<ll,ll>> p = que.top();
que.pop();
if(i % 2 == 0)sum1 += p.second.first;
else sum2 += p.second.second;
}
cout << sum1 - sum2 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using Graph = vector<vector<int>>;
using Edge = map<pair<int,int>,int>;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
ll gcd(ll a,ll b){
if (a%b == 0) return(b);
else return(gcd(b, a%b));
}
ll lcm(ll a, ll b){
return a*b/gcd(a, b);
}
int main()
{
cout << fixed << setprecision(15);
ll N, M, X, Y;
cin >> N >> M >> X >> Y;
ll maxx = X;
ll miny = Y;
REP(i, N){
ll x;
cin >> x;
maxx = max(maxx, x);
}
REP(i, M){
ll y;
cin >> y;
miny = min(miny, y);
}
if(maxx < miny){
cout << "No War" << endl;
}
else{
cout << "War" << endl;
}
return 0;
}
| 0
| 264,182
|
#include<iostream>
#include<vector>
int main()
{
std::vector<bool>result;
while (true)
{
double x1, y1, x2, y2, x3, y3, xp, yp;
std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp;
if (!std::cin)
{
break;
}
double k = ((x2 - x3)*(y3 - y1) - (x3 - x1)*(y2 - y3)) / ((x2 - x3)*(yp - y1) - (xp - x1)*(y2 - y3));
double s = ((x1 - x3)*(yp - y1) - (xp - x1)*(y1 - y3)) / ((x2 - x3)*(yp - y1) - (xp - x1)*(y2 - y3));
result.push_back(1 < k && 0 < s && s < 1);
}
for (auto i : result)
{
std::cout << (i ? "YES" : "NO") << std::endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++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 irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
#define pqasc priority_queue<long long, vector<long long>, greater<long long>>
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ul = unsigned long;
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; }
class UnionFind{
private:
vector<int> Parent;
public:
UnionFind(int N){
Parent = vector<int>(N, -1);
}
int root(int A){
if(Parent[A] < 0) return A;
return Parent[A] = root(Parent[A]);
}
int size(int A){
return -Parent[root(A)];
}
bool connect(int A, int B){
A = root(A);
B = root(B);
if(A == B){
return false;
}
if(size(A) < size(B)) swap(A, B);
Parent[A] += Parent[B];
Parent[B] = A;
return true;
}
bool isSame(int A, int B){
return root(A) == root(B);
}
};
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
inline bool inside(int y, int x, int H, int W) {
return (y >= 0 && x >= 0 && y < H && x < W);
}
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
signed main()
{
cin.tie( 0 ); ios::sync_with_stdio( false );
int n; cin>>n;
vll a(n), b(n);
rep(i,n) cin>>a[i];
rep(i,n) cin>>b[i];
ll c=0, d=0;
rep(i,n){
if(a[i]<b[i]) c+=(b[i]-a[i])/2;
else d+=a[i]-b[i];
}
if(c>=d) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
| 0
| 89,264,106
|
#include <iostream>
using namespace std;
struct Card {
char suit, value;
};
void printList(Card C[], int n){
for(int i=0; i<n-1; i++){
cout << C[i].suit << C[i].value << ' ';
}
cout << C[n-1].suit << C[n-1].value << endl;
}
void bubbleSort(Card C1[], int n){
int flag = 1;
for(int i=0; flag; i++){
flag = 0;
for (int j=n-1; j>i; j--){
if(C1[j].value < C1[j-1].value){
Card t = C1[j];
C1[j] = C1[j-1];
C1[j-1] = t;
flag = 1;
}
}
}
printList(C1, n);
}
void selectionSort(Card C2[], int n){
for(int i=0; i<n; i++){
int minj = i;
for(int j=i; j<n; j++){
if(C2[j].value < C2[minj].value)
minj = j;
}
if(minj != i){
Card t = C2[i];
C2[i] = C2[minj];
C2[minj] = t;
}
}
printList(C2, n);
}
void isStable(Card C1[], Card C2[], int n){
for(int i=0; i<n; i++){
if(C1[i].suit != C2[i].suit){
cout << "Not stable" << endl;
return;
}
}
cout << "Stable" << endl;
}
int main() {
Card C1[100], C2[100];
int n;
cin >> n;
for(int i=0; i<n; i++){
cin >> C1[i].suit >> C1[i].value;
C2[i] = C1[i];
}
bubbleSort(C1, n);
cout << "Stable" << endl;
selectionSort(C2, n);
isStable(C1, C2, n);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;
const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
if(m == 0)return 0;
if(m == 1)return 1;
long long ans = 1;
long long tmp = m;
for(int i=0;i<=30;i++){
if(n & (1<<i)){
ans *= tmp;
ans %= MOD;
}
tmp *= tmp;
tmp %= MOD;
}
return ans;
}
long long kaizyou(long long x){
if(x == 0)return 1;
return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
long long bunsi = kaizyou(x);
long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
return bunsi * ruizyou((int)bunbo,MOD-2) % MOD;
}
struct unionfind{
vector<int> par;
vector<int> hukasa;
unionfind(int n){
par = vector<int>(n);
hukasa = vector<int>(n,0);
for(int i=0;i<n;i++){
par.at(i) = i;
}
}
int root(int x){
if(par.at(x) == x)return x;
return root(par.at(x));
}
void unite(int x,int y){
int rx = root(x);
int ry = root(y);
if(rx == ry)return;
if(hukasa.at(rx) >= hukasa.at(ry)){
par.at(ry) = rx;
hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
}
else{
par.at(rx) = ry;
}
}
bool same(int x,int y){
return root(x) == root(y);
}
};
int ctoi(char a){
return a - '0';
}
long long gcd(long long a,long long b){
long long c = max(a,b);
long long d = min(a,b);
if(d % c == 0)return c;
return gcd(c,d%c);
}
long long lcm(long long a,long long b){
return a * b / gcd(a,b);
}
int main(){
int n,k;
cin >> n >> k;
long long ans = 0;
for(long long i=k;i<=n+1;i++){
long long a,b;
a = i*(i-1)/2;
b = i*(2*n-i+1)/2;
ans += b-a+1;
ans %= MOD;
}
cout << ans << endl;
}
| 0
| 44,267,274
|
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
const long long int Z = 1000000007;
const long long int INF = 1 << 30;
int flag = 0;
using ll = long long;
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
int main() {
std::string s;
int n;
std::cin >> s >> n;
for (int i = 0;i < n;i++) {
std::string t;
std::cin >> t;
if (t == "print") {
int a, b;
std::cin >> a >> b;
for (int j = a;j <= b;j++) {
std::cout << s[j];
}
std::cout << std::endl;
}
if (t == "reverse") {
int a, b;
std::cin >> a >> b;
std::reverse(s.begin() + a, s.begin() + b + 1);
}
if (t == "replace") {
int a, b;
std::string p;
std::cin >> a >> b >> p;
int k = 0;
for (int j = a;j <= b;j++) {
s[j] = p[k];
k++;
}
}
}
return 0;
}
|
#include<iostream>
using namespace std;
int main() {
int datas[100] = { 0 };
int num,biggest_num=0;
while (cin >> num) {
datas[num-1]++;
}
for (int i = 0; i < 100; i++) {
if (biggest_num < datas[i]) {
biggest_num = datas[i];
}
}
for (int i = 0; i < 100; i++) {
if (biggest_num == datas[i]) {
cout << i + 1<<endl;
}
}
return 0;
}
| 0
| 89,757,932
|
#include <bits/stdc++.h>
#include <climits>
#ifdef atclib
#include <atcoder/all>
#endif
#ifdef local
#include "dbg-macro/dbg.h"
#endif
#ifdef boost
#include <boost/multiprecision/cpp_int.hpp>
#endif
#define p std::pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define vi std::vector<int>
#define pi std::pair<int, int>
#define mp std::make_pair
#define stdabs std::abs
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
#define npm next_permutation
#define Yes std::cout << "Yes" << std::endl
#define No std::cout << "No" << std::endl
#define YES std::cout << "YES" << std::endl
#define NO std::cout << "NO" << std::endl
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy8[8] = {0, 1, 0, -1, 1, -1, 1, -1};
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;
}
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
ll extgcd(ll a, ll b, ll& x, ll& y);
ll nCr(ll n__, ll r__);
void stat();
template <typename T> T fact(T num__);
unsigned long long modpow(int x__, int n__, long long mod__);
template <typename T> void debug(const T& t__);
constexpr ll mod10_9p7 = 1000000000 + 7;
int main()
{
stat();
int n;
cin >> n;
int cur = 0, cx = 0, cy = 0;
rep(i, n)
{
int t, x, y;
cin >> t >> x >> y;
if (abs(cx - x) + abs(cy - y) > t - cur) {
No;
return 0;
}
else {
int sub = t - cur;
int temp=abs(cx-x)+abs(cy-y);
if ((sub-temp) % 2 != 0) {
No;
return 0;
}
cur=t;
cx=x;
cy=y;
}
}
Yes;
return 0;
}
ll extgcd(ll a, ll b, ll& x, ll& y)
{
if (b == 0) {
x = 1, y = 0;
return a;
}
ll d = extgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
std::vector<bool> is_prime(N + 1);
for (unsigned ll i = 0; i <= N; i++) {
is_prime[i] = true;
}
std::vector<unsigned ll> P;
for (unsigned ll i = 2; i <= N; i++) {
if (is_prime[i]) {
for (unsigned ll j = 2 * i; j <= N; j += i) {
is_prime[j] = false;
}
P.emplace_back(i);
}
}
return P;
}
void stat(){
#ifdef local
rep(i__, 2){std::cout << "local" << std::endl;
}
#endif
#ifdef hacks
rep(i__, 2) { std::cout << "boost" << std::endl; }
#endif
}
ll nCr(ll n__, ll r__)
{
ll num__ = 1;
for (ll i__ = 1; i__ <= r__; i__++) {
num__ = num__ * (n__ - i__ + 1) / i__;
}
return num__;
}
template <typename T> T fact(T num__)
{
if (num__ == 1) { return 1; }
return num__ * fact(num__ - 1);
}
unsigned long long modpow(int x__, int n__, long long mod__)
{
long long ret__ = 1;
for (long long i__ = 0; i__ < n__; ++i__) {
ret__ = ret__ * x__ % mod__;
}
return ret__;
}
template <typename T> void debug(const T& t__)
{
#ifdef local
dbg(t__);
#endif
}
|
#include<iostream>
using namespace std;
int main(){
int64_t Lo = 2,Li = 1;
int n;
cin >> n;
int64_t L = 3;
if(n>=3){
for(int i=3;i<=n;i++){
Lo = Li;
Li = L;
L = Li + Lo;
}
}
if(n==1){
cout << 1 << endl;
}else if(n==2){
cout << 3 << endl;
}else{
cout << L << endl;
}
}
| 0
| 26,397,497
|
#include<iostream>
#include<string>
using namespace std;
int main(){
string str[9];
str[0] = ".,!? ";
str[1] = "abc";
str[2] = "def";
str[3] = "ghi";
str[4] = "jkl";
str[5] = "mno";
str[6] = "pqrs";
str[7] = "tuv";
str[8] = "wxyz";
string a;
int h,t = 0;
cin >> h;
while (t < h) {
cin >> a;
int i = 0;
do {
int n = 0,m = 0;
while (a[i] != '0') {
m = a[i] - '0';
n++;
i++;
}
int j;
if (m == 7 || m == 9) {
j = n%4 - 1;
if (j == -1) {
j = 3;
}
cout << str[m-1][j];
}
else if (m == 1) {
j = n%5 - 1;
if(j == -1){
j = 4;
}
cout << str[m-1][j];
}
else if (m == 0) {
}
else{
j = n%3 - 1;
if (j == -1) {
j = 2;
}
cout << str[m-1][j];
}
if (a[i+1]) {
i++;
}
}while(a[i+1]);
cout << endl;
t++;
}
}
|
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
constexpr int DEBUG = 0;
constexpr int NUM_BITS = 60;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int64> xs(n);
for (int i = 0; i < n; i++) {
cin >> xs[i];
}
int64 xor_all = 0;
for (int64 x : xs) {
xor_all ^= x;
}
for (int i = 0; i < n; i++) {
xs[i] &= ~xor_all;
}
int c = 0;
for (int b = NUM_BITS - 1; b >= 0; b--) {
int pivot_i = -1;
for (int i = c; i < n; i++) {
if (xs[i] & (1L << b)) {
pivot_i = i;
break;
}
}
if (pivot_i < 0) continue;
swap(xs[pivot_i], xs[c]);
for (int i = 0; i < n; i++) {
if (i == c) continue;
if (xs[i] & (1L << b)) {
xs[i] ^= xs[c];
}
}
c++;
}
int64 xor_all_2 = 0;
for (int i = 0; i < n; i++) {
xor_all_2 ^= xs[i];
}
cout << xor_all + xor_all_2 * 2 << endl;
}
| 0
| 46,428,499
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
char s;
cin >> s;
if(isupper(s)) cout << 'A';
else cout << 'a';
}
|
#include <stdio.h>
int main()
{
int n, x, i, j, k, count;
while (true) {
count = 0;
scanf("%d %d", &n, &x);
if (n == 0 && x == 0) break;
if (n >= 3 && n <= 100) {
if (x >= 0 && x <= 300) {
for (i = 1; i <= n; i++) {
for (j = i + 1; j <= n; j++) {
for (k = j + 1; k <= n; k++) {
if (i + j + k == x) count++;
}
}
}
}
printf("%d\n", count);
}
}
}
| 0
| 69,020,842
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
int main() {
char b;
cin>>b;
if(b=='A'){
cout<<"T"<<endl;
}
if(b=='T'){
cout<<"A"<<endl;
}
if(b=='G'){
cout<<"C"<<endl;
}
if(b=='C'){
cout<<"G"<<endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans) cout << ans << endl;
int main(){
map<int,int> ac;
map<int,int> wa;
int n,m;
cin >> n >> m;
rep(i,m){
int p;
string s;
cin >> p >> s;
if(s=="AC"){
ac[p]++;
}else{
if(!ac.count(p))
wa[p]++;
}
}
int ans_wa(0);
for(auto a : wa){
if(ac.count(a.first))
ans_wa += a.second;
}
cout << ac.size() << " " << ans_wa << endl;
return 0;
}
| 0
| 83,356,680
|
#include <iostream>
using namespace std;
using ll = long long;
int main() {
const ll MOD = 1e9 + 7;
int n, m;
cin >> n >> m;
const int MAXN = 200000;
const int MAXM = 200000;
static ll x[MAXN], y[MAXM];
static ll cumx[MAXN], cumy[MAXM];
for (int i = 0; i < n; i++) {
cin >> x[i];
cumx[i] = x[i];
if (i > 0) cumx[i] += cumx[i - 1];
cumx[i] = (cumx[i] + MOD * MOD) % MOD;
}
for (int i = 0; i < m; i++) {
cin >> y[i];
cumy[i] = y[i];
if (i > 0) cumy[i] += cumy[i - 1];
cumy[i] = (cumy[i] + MOD * MOD) % MOD;
}
ll xterm = 0,
yterm = 0;
for (int i = 0; i < n; i++) {
xterm += ((i + 1) * x[i] - cumx[i] + MOD * MOD) % MOD;
xterm %= MOD;
}
for (int i = 0; i < m; i++) {
yterm += ((i + 1) * y[i] - cumy[i] + MOD * MOD) % MOD;
yterm %= MOD;
}
cout << (xterm * yterm) % MOD << endl;
return 0;
}
|
#include <bits/stdc++.h>
#include <ext/rope>
#define VALHALLA cin.tie(0);ios_base::sync_with_stdio(false);cout<<fixed<<setprecision(13);cerr<<fixed<<setprecision(5);
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define debug(x) std::cerr << #x << ": " << (x) << '\n';
#define sz(x) (int)x.size()
#define fast(map_name) map_name.reserve(1024);map_name.max_load_factor(0.25);
using namespace std;
using namespace __gnu_cxx;
typedef long long int ll;
typedef pair<int,int> ii;
typedef complex<double> point;
const double epsilon=1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;
int globe[int(1e6)];
double dot(point a,point b){ return (conj(a)*b).real() ; }
double cross(point a,point b){ return (conj(a)*b).imag() ; }
double dist(point a, point b){ return abs(a-b); }
struct neal {
static uint64_t splitmix64(uint64_t x)
{
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const
{
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
struct HASH{
size_t operator()(const pair<int,int>&x)const{
return (size_t) x.first * 37U + (size_t) x.second;
}
};
bool isprime(ll n) {
if (n == 2 || n == 3) return true;
if (n < 2 || n % 2 == 0 || n % 3 == 0) return false;
for (ll i = 6; (i - 1) * (i - 1) <= n; i += 6) {
if (n % (i - 1) == 0 || n % (i + 1) == 0) {
return false;
}
}
return true;
}
inline ll exp(ll a, ll b, ll mod) {
ll n = 1;
ll p = a;
while (b > 0) {
if (b % 2 == 1) {
n *= p;
n %= mod;
}
p *= p;
p %= mod;
b /= 2;
}
return n;
}
inline bool comp(double a,double b)
{
return (fabs(a-b)<epsilon);
}
ll gcd(ll u, ll v) {
ll r;
while (0 != v) {
r = u % v; u = v; v = r;
}
return u;
}
int main()
{
VALHALLA
int cnt=0;
string s;cin>>s;
for(int i=0;i+1<sz(s);++i)
{
if(s[i]!=s[i+1])
cnt++;
}
cout<<cnt<<endl;
}
| 0
| 23,936,347
|
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
using ll = long long;
class Stream{
public:
Stream(){
}
void read(){
}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
cin >> first;
read(rest...);
}
template<typename T>
void write_vec(vector<T>& v, char divider){
for(size_t i = 0; i < v.size(); i++){
cout << v[i] << divider;
}
}
};
int main(){
Stream io;
int A, B, C;
io.read(A, B, C);
map<int, int> mp;
mp[A]++;
mp[B]++;
mp[C]++;
for(auto i = mp.begin(); i != mp.end(); i++){
if(i->second == 1){
cout << i->first;
break;
}
}
return 0;
}
|
#include "bits/stdc++.h"
#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second
using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};
ll mod(ll a, ll mod){
ll res = a%mod;
if(res<0)res=res + mod;
return res;
}
ll modpow(ll a, ll n, ll mod){
ll res=1;
while(n>0){
if(n&1) res=res*a%mod;
a=a*a%mod;
n>>=1;
}
return res;
}
ll modinv(ll a, ll mod){
return modpow(a, mod-2, mod);
}
ll gcd(ll a, ll b){
ll r = a%b;
if(r==0) return b;
else return gcd(b, a%b);
}
bool is_prime(ll n){
ll i = 2;
if(n==1)return false;
if(n==2)return true;
bool res = true;
while(i*i <n){
if(n%i==0){
res = false;
}
i = i+1;
}
if(n%i==0)res=false;
return res;
}
struct UnionFind{
ll N;
llvec p;
llvec cnt;
UnionFind(ll n){
N = n;
p=llvec(N);
cnt=llvec(N, 0);
rep(i, N){
p[i] = i;
cnt[i] = 1;
}
}
void con(ll a, ll b){
P at = root(a);
P bt = root(b);
if(at.second!=bt.second){
if(at.first>bt.first){
swap(at, bt);
swap(a, b);
}
p[at.second] = bt.second;
cnt[bt.second]+=cnt[at.second];
p[a]=bt.second;
}
}
P root(ll a){
ll atmp = a;
ll c=0;
while(atmp!=p[atmp]){
atmp = p[atmp];
c++;
}
p[a] = atmp;
return {c, atmp};
}
bool is_con(ll a, ll b){
P at=root(a);
P bt=root(b);
return at.second == bt.second;
}
};
struct dijkstra{
ll N;
llvec d;
vector<vector<edge>> e;
dijkstra(ll n){
N = n;
e = vector<vector<edge>>(N);
}
void add_edge(ll from, ll to, ll cost){
e[from].push_back({to, cost});
}
void run(ll start){
priority_queue<P, vector<P>, greater<P>> que;
que.push({0, start});
d = llvec(N, 1e18);
d[start]=0;
while(!que.empty()){
P q = que.top();que.pop();
ll dc = q.first;
ll x = q.second;
if(dc>d[x]){
continue;
}else{
for(auto ip: e[x]){
if(d[ip.x]<=d[x]+ip.c){
continue;
}else{
d[ip.x]= d[x]+ip.c;
que.push({d[ip.x], ip.x});
}
}
}
}
}
};
int main(){
ll N, K;
cin >> N >> K;
vector<P> p(N);
llvec x, y;
rep(i, N){
cin >> p[i].fi >> p[i].se;
x.push_back(p[i].fi);
y.push_back(p[i].se);
}
sort(ALL(x));
sort(ALL(y));
x.erase(unique(ALL(x)), x.end());
y.erase(unique(ALL(y)), y.end());
ll nx = x.size();
ll ny = y.size();
vector<llvec> m(nx, llvec(ny, 0));
rep(i, N){
ll ix = lower_bound(ALL(x), p[i].fi) - x.begin();
ll iy = lower_bound(ALL(y), p[i].se) - y.begin();
m[ix][iy]++;
}
vector<llvec> S(nx+1, llvec(ny+1, 0));
rep(i, nx){
rep(j, ny){
S[i+1][j+1]=S[i+1][j]+S[i][j+1]-S[i][j]+m[i][j];
}
}
x.insert(x.begin(), -1e18);
y.insert(y.begin(), -1e18);
ll ans = 5e18;
rep(i, nx){
rep(j, ny){
ll tmp=5e18;
for(ll ii=i+2; ii<=nx; ii++){
for(ll jj=j+2; jj<=ny; jj++){
if(S[ii][jj] -S[ii][j] - S[i][jj]+ S[i][j]>=K){
tmp = min(tmp, (x[ii]-x[i+1])*(y[jj]-y[j+1]));
}
}
}
ans = min(ans, tmp);
}
}
cout << ans;
return 0;
}
| 0
| 10,947,360
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int> pii;
typedef pair<char, int> pci;
typedef pair<char, char> pcc;
typedef vector<pii> vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007
bool check_prime(long long n)
{
int flag = 0;
for (long long i = 2; i * i <= n; i++)
{
if (n % i == 0)
{
flag = 1;
break;
}
}
if (n == 1)
return false;
else if (flag == 0 || n == 2 || n == 3)
{
return true;
}
else
{
return false;
}
}
int BE(int x, int n, int m)
{
int result = 1;
while (n > 0)
{
if (n % 2 == 1)
result = result * x % m;
x = x * x % m;
n = n / 2;
}
return result;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
#ifndef ONLINE_JUDGE
if (fopen("input.txt", "r"))
{
freopen ("input.txt" , "r" , stdin);
freopen ("output.txt" , "w" , stdout);
}
#endif
string s;
cin >> s;
int n = s.size();
map<char, int>mt;
zip(i, 0, n)
{
mt[s[i]] = i + 1;
}
int a, b, c;
if (n == 26)
{
int flag = 0;
zip(i, 1, n)
{
if (s[i] < s[i - 1])
{
if (i == n - 1 && flag == 0)
{
cout << -1 << en;
return 0;
}
}
else
{
break;
}
}
flag = 25;
for (int i = n - 1; i >= 0; i--)
{
if (s[i] < s[i - 1])
{
flag = i - 1;
}
else
{
break;
}
}
char ch = 'z';
if (flag == 1)
{
ch = s[0] + 1;
cout << ch << en;
return 0;
}
zip(i, 0, flag - 1)
{
cout << s[i];
}
int j = flag - 1;
ch = 'z';
zip(i, flag, n)
{
if (s[i] > s[j])
{
ch = min(ch, s[i]);
}
}
cout << ch << en;
return 0;
}
char a1;
for (char x = 'a'; x <= 'z'; x++)
{
if (mt[x] == 0)
{
a1 = x;
break;
}
}
cout << s << a1 << en;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, q;
int main() {
while(cin >> n, n) {
map<char, char> conversion;
for(int i = 0; i < 128; i++) conversion[i] = i;
string c, d;
while(n--) cin >> c >> d, conversion[c[0]] = d[0];
cin >> q;
while(q--) cin >> c, cout << conversion[c[0]];
cout << endl;
}
}
| 0
| 61,741,544
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-9;
int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); }
void od(double x) { printf("%.15f ", x); }
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}}
void br() { putchar('\n'); }
#define gcd __gcd
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end()
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size)
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
int len = v.size();
for (int i = 0; i < len; ++i) {
s << v[i]; if (i < len - 1) s << " ";
}
return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
int len = vv.size();
for (int i = 0; i < len; ++i) {
s << vv[i] << endl;
}
return s;
}
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
int main(){
ll N = il();
string S = is();
ll excess_lbr = 0;
ll excess_rbr = 0;
ll stock_lbr = 0;
ll legitimate = 0;
for (char c : S){
if (c == '('){
stock_lbr++;
}
else{
if (stock_lbr != 0){
stock_lbr--;
legitimate += 2;
}
else{
continue;
}
}
}
excess_lbr = stock_lbr;
excess_rbr = S.size() - legitimate - stock_lbr;
cout << string(excess_rbr, '(') << S << string(excess_lbr, ')') << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll 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;
cout << u << endl;
return u;
}
ll paty_counter(ll level, ll x){
ll size = pow(2, level+2) - 3;
ll pmi = pow(2, level) - 1;
if(x == 0){
return 0;
}else if(level == 0){
return 1;
}else{
if(x <= (size - 1)/2){
return paty_counter(level-1, x-1);
}else{
return pmi + 1 + paty_counter(level-1, x - pow(2, level+1) + 3 - 2);
}
}
}
int main() {
ll n, x;
cin >> n >> x;
cout << fixed << paty_counter(n, x) << endl;
}
| 0
| 31,442,907
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
if (a < b) return euclidean_gcd(b, a);
unsigned r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
ll ll_gcd(ll a, ll b) {
if (a < b) return ll_gcd(b, a);
ll r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
struct UnionFind {
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 merge(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 issame(ll x, ll y) {
return root(x) == root(y);
}
ll size(ll x) {
return siz[root(x)];
}
};
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;
}
long long modinv(long long a, long long mod) {
return modpow(a, mod - 2, mod);
}
vector<int> tpsort(vector<vector<int>>& G) {
int V = G.size();
vector<int> sorted_vertices;
queue<int> que;
vector<int> indegree(V);
for (int i = 0; i < V; i++) {
for (int j = 0; j < G[i].size(); j++) {
indegree[G[i][j]]++;
}
}
for (int i = 0; i < V; i++) {
if (indegree[i] == 0) {
que.push(i);
}
}
while (que.empty() == false) {
int v = que.front();
que.pop();
for (int i = 0; i < G[v].size(); i++) {
int u = G[v][i];
indegree[u] -= 1;
if (indegree[u] == 0) que.push(u);
}
sorted_vertices.push_back(v);
}
return sorted_vertices;
}
struct Point
{
double x;
double y;
};
struct LineSegment
{
Point start;
Point end;
};
double tenkyori(const LineSegment& line, const Point& point)
{
double x0 = point.x, y0 = point.y;
double x1 = line.start.x, y1 = line.start.y;
double x2 = line.end.x, y2 = line.end.y;
double a = x2 - x1;
double b = y2 - y1;
double a2 = a * a;
double b2 = b * b;
double r2 = a2 + b2;
double tt = -(a * (x1 - x0) + b * (y1 - y0));
if (tt < 0)
return sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
else if (tt > r2)
return sqrt((x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0));
double f1 = a * (y1 - y0) - b * (x1 - x0);
return sqrt((f1 * f1) / r2);
}
int main() {
ll n;
cin >> n;
vector<ll> z(101);
for (ll i = 0; i < n; i++) {
ll k = i + 1;
for (int j = 2; j <= n; j++) {
while (k % j == 0) {
z[j]++;
k /= j;
}
}
}
ll ans = 0;
for (int i = 0; i < 101; i++) {
if (z[i] >= 74)ans++;
}
ll a = 0;
ll b = 0;
for (int i = 0; i < 101; i++) {
if (z[i] >= 24)a++;
if (z[i] >= 2)b++;
}
ans += a * (b - 1);
a = 0;
b = 0;
for (int i = 0; i < 101; i++) {
if (z[i] >= 14)a++;
if (z[i] >= 4)b++;
}
ans += a * (b - 1);
a = 0;
b = 0;
for (int i = 0; i < 101; i++) {
if (z[i] >= 4)a++;
if (z[i] >= 2)b++;
}
ans += a * (a - 1) * (b - 2) / 2;
cout << ans << endl;
}
|
#include <iostream>
#include <vector>
int main(){
int N;
std::cin >> N;
struct T{
int t;
int x;
int y;
};
std::vector<T> v(N);
for (int i=0; i<N; i++){
int t, x, y;
std::cin >> t >> x >> y;
v.at(i).t = t;
v.at(i).x = x;
v.at(i).y = y;
}
int t = 0, x = 0, y = 0;
bool flag = true;
for (int i=0; i<N; i++){
int abst = v.at(i).t - t;
int absr = abs(v.at(i).x - x) + abs(v.at(i).y - y);
if (abst < absr){
flag = false;
break;
} else if ((abst % 2 == 0) && (absr % 2 == 1)){
flag = false;
break;
} else if ((abst % 2 == 1) && (absr % 2 == 0)){
flag = false;
break;
} else{
t = v.at(i).t;
x = v.at(i).x;
y = v.at(i).y;
}
}
if (flag){
std::cout << "Yes" << std::endl;
} else{
std::cout << "No" << std::endl;
}
}
| 0
| 69,760,819
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a,b,c,x;
cin >> a >> b >> c;
x = a+b;
if(c<=x) cout << "Yes"<< endl;
else cout << "No" << endl;
}
|
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string Tc, Hc;
int n = 0, t = 0, h = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> Tc >> Hc;
unsigned int j = 0;
for (j = 0; j < max(Tc.size(), Hc.size()); j++){
if (Tc[j] > Hc[j]) {
t += 3;
break;
}
else if (Tc[j] < Hc[j]) {
h += 3;
break;
}
}
if ((j == Tc.size()) && (Tc.size() == Hc.size())) {
t++;
h++;
}
}
cout << t << " " << h << endl;
return 0;
}
| 0
| 19,104,666
|
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>
const int N=15;
int dp[N][N];
int m,a,b,c;
int main()
{
while (true) {
scanf("%d",&m);
if (m==0) break;
memset(dp,INF,sizeof(dp));
for (int i=1;i<=m;i++) {
scanf("%d%d%d",&a,&b,&c);
dp[a][b]=dp[b][a]=c;
}
for (int k=0;k<10;k++) {
for (int i=0;i<10;i++) {
for (int j=0;j<10;j++) {
if (k!=i&&k!=j&&i!=j) {
if (dp[i][k]!=INF&&dp[k][j]!=INF)
dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
}
}
}
}
int val=INF,idx=-1;
for (int i=0;i<10;i++) {
int tmp=0;
for (int j=0;j<10;j++) {
if (dp[i][j]!=INF) tmp+=dp[i][j];
}
if (tmp>0) {
if (tmp<val) {
idx=i;
val=tmp;
}
}
}
printf("%d %d\n",idx,val);
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const long long MOD = 1e9 + 7;
#define INPUT(x) freopen(x,"r",stdin)
#define OUTPUT(x) freopen (x,"w",stdout)
#define pb push_back
#define endl '\n'
#define LCM(a,b) (a/__gcd(a,b))*b
#define GCD(a,b) __gcd(a,b)
#define SP(x,y) fixed<<setprecision((y))<<(x)
#define PI acos(-1.0)
#define distance(x1,y1,x2,y2) sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define MAX 1e9 + 9
#define taratari ios_base::sync_with_stdio(0);cin.tie(NULL);
int main()
{
taratari
string a;
cin >> a;
int x=0;
int y=0;
for(int i=0;i<a.size();i++)
{
if(i%2==0 && a[i]=='0')
{
x++;
}
if(i%2==1 && a[i]=='1')
{
x++;
}
if(i%2==0 && a[i]=='1')
{
y++;
}
if(i%2==1 && a[i]=='0')
{
y++;
}
}
cout << min(x,y);
return 0;
}
| 0
| 81,631,041
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
int r,g,b,n;
cin >> r >> g >> b >> n;
int cnt=0;
for(int R=0; R<=n; R++){
for(int G=0; G<=n; G++){
int B = (n-(r*R + G*g))/b;
if(R*r + G*g + B*b == n && B >=0 ) cnt++;
}
}
cout << cnt <<endl;
}
|
#include <iostream>
#define INF 1000000
using namespace std;
int main(){
int n;
while(cin >> n,n){
int r[10][10];
int m = 0;
for(int i = 0; i < 10;++i)for(int j = 0; j < 10; ++j){
r[i][j] = INF;
}
for(int i = 0; i < n; ++i){
int a,b,c;
cin >> a >> b >> c;
r[a][b] = r[b][a] = c;
m = max(max(a,b),m);
}
++m;
for(int i = 0; i < m; ++i)r[i][i] = 0;
for(int k = 0; k < m; ++k){
for(int i = 0; i < m; ++i){
for(int j = 0; j < m; ++j){
r[i][j] = min(r[i][k]+r[k][j],r[i][j]);
}
}
}
int ans = INF;
int t = 0;
for(int i = 0; i < m; ++i){
int tmp = 0;
for(int j = 0; j < m; ++j){
tmp += r[i][j];
}
if(ans > tmp){
ans = tmp;
t = i;
}
}
cout << t << " " << ans << endl;
}
}
| 0
| 65,036,410
|
#include <iostream>
#include <algorithm>
using namespace std;
void solve() {
int a,b,c;
cin >> a >> b >> c;
long long t = 0;
for (long long i=1; i <= b; ++i) {
t +=a ;
if (t % b == c) {
cout << "YES";
return;
}
}
cout << "NO";
}
int main() {
solve();
return 0;
}
|
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
int N;
scanf("%d", &N);
int t, x, y;
int t_pre = 0, x_pre = 0, y_pre = 0;
for(int i = 0; i < N;i++){
scanf("%d %d %d", &t, &x, &y);
if(!((t - t_pre >= abs(x - x_pre)+ abs(y -y_pre)) && ((t - t_pre - (x-x_pre) - (y-y_pre)) % 2 == 0))){
printf("No");
return 0;
}
t_pre = t;
x_pre = x;
y_pre = y;
}
printf("Yes");
return 0;
}
| 0
| 1,945,000
|
#include <iostream>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
cout<<(a*3+b)/2;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using Graph = vector<vector<int>>;
using Edge = map<pair<int,int>,int>;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
ll gcd(ll a,ll b){
if (a%b == 0) return(b);
else return(gcd(b, a%b));
}
ll lcm(ll a, ll b){
return a/gcd(a, b) * b;
}
int main()
{
cout << fixed << setprecision(15);
ll A, B;
cin >> A >> B;
if(A == 1){
if(B==1){
cout << "Draw" << endl;
return 0;
}
else{
cout << "Alice" << endl;
return 0;
}
}
if(B == 1){
cout << "Bob" << endl;
return 0;
}
if(A>B){
cout << "Alice" << endl;
return 0;
}
if(A<B){
cout << "Bob" << endl;
return 0;
}
if(A==B){
cout << "Draw" << endl;
return 0;
}
}
| 0
| 67,203,631
|
#include<bits/stdc++.h>
using namespace std;
int solve(vector<int>&a){
map<int,int>kazu;
for(int i=0;i<a.size();i++){
kazu[a.at(i)]++;
kazu[a.at(i)-1]++;
kazu[a.at(i)+1]++;
}
int ans=0;
for(auto i:kazu){
ans=max(ans,i.second);
}
return ans;
}
int main(){
int n;
cin >> n;
vector<int>a(n);
for(int i=0;i<n;i++)
cin >> a.at(i);
cout << solve(a) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ull x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
int main(){
cin.tie(0); ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
ll n;
cin >> n;
vp ab(n);
rep(i, n){
cin >> ab[i].first >> ab[i].second;
}
{
bool f = 1;
rep(i, n){
if(ab[i].first != ab[i].second){
f = 0;
break;
}
}
if(f){
cout << 0 << endl;
return 0;
}
}
sort(ALL(ab), [&](pll x, pll y){return x.first-x.second < y.first-y.second;});
dump(ab);
ll mi = INF;
ll ans = 0;
rep(i, n){
ans += ab[i].first;
if(ab[i].first > ab[i].second){
chmin(mi, ab[i].second);
}
}
cout << ans-mi << endl;
return 0;
}
| 0
| 81,968,111
|
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main() {
double W, H, x, y;
cin >> W >> H >> x >> y;
cout << fixed << setprecision(6) << W * H / 2.0;
cout << " " << (x == W / 2.0 && y == H / 2.0 ? 1 : 0) << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int maxN = 1e5+5;
const int mod = 1e9+7;
void solve(){
int H,W;
cin>>H>>W;
vector<string> grid(H);
for(int i=0;i<H;i++){
cin>>grid[i];
}
int mat[H+1][W+1];
mat[0][0] = 1;
for(int i=1;i<H;i++){
if(grid[i][0]!='#')
mat[i][0] = mat[i-1][0];
else
mat[i][0] = 0;
}
for(int i=1;i<W;i++){
if(grid[0][i]!='#')
mat[0][i] = mat[0][i-1];
else
mat[0][i] = 0;
}
for(int i=1;i<H;i++){
for(int j=1;j<W;j++){
if(grid[i][j]=='#') mat[i][j] = 0;
else mat[i][j] = (mat[i-1][j]+mat[i][j-1])%mod;
}
}
cout<<mat[H-1][W-1]<<endl;
}
int main()
{
FASTIO
int t = 1;
while(t--){
solve();
}
return 0;
}
| 0
| 39,631,772
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> s(N);
for (int i = 0; i < N; i++) cin >> s.at(i);
int M;
cin >> M;
vector<string> t(M);
for (int i = 0; i < M; i++) cin >> t.at(i);
int score = 0;
for (int i = 0; i < N; i++) {
string target = s.at(i);
int count = 0;
for (int j = 0; j < N; j++) {
if (target == s.at(j)) count++;
}
for (int j = 0; j < M; j++) {
if (target == t.at(j)) count--;
}
if (count > score) score = count;
}
cout << score;
}
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, s, maxn, minn;
while(1){
scanf("%d", &n);
if(n==0) break;
maxn=0;
minn=1000;
int x=0;
for(int i=0;i<n;i++){
scanf("%d", &s);
x+=s;
maxn=max(s,maxn);
minn=min(s,minn);
}
printf("%d\n",(x-maxn-minn)/(n-2) );
}
return 0;
}
| 0
| 36,592,659
|
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <cstring>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
io()
{
ios::sync_with_stdio(false);
cin.tie(0);
}
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
int main(void)
{
ll k, n;
cin >> k >> n;
vll a(n);
ll r = 0;
ll r2 = 10000000;
rep(i, n) cin >> a[i];
rep (i, n) {
r = a[(n-1+i)%n]-a[i];
if (r < 0) r += k;
if (r < r2) r2 = r;
}
cout << r2;
}
|
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;
#define vec vector<int>
#define vecll vector<ll>
#define vec2 vector<vector<int>>
#define vec2ll vector<vector<ll>>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst vector<string>
#define vecb vector<bool>
#define rep(i,n) for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n) vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n) vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n) vecst var(n); rep(i,n){cin >> var[i];}
#define all(var) (var).begin(), (var).end()
#define sortall(var) sort(all(var))
#define uniqueall(v) v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var) accumulate(all(var), 0)
#define f_sumll(var) accumulate(all(var), 0LL)
#define chmin(v1, v2) v1 = min(v1, v2)
#define chmax(v1, v2) v1 = max(v1, v2)
#define mpair(v1, v2) make_pair(v1, v2)
#define pb(var) push_back(var)
#define prt(var) cout << var << "\n"
#define prtd(n, var) cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var) cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2) cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v) rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
int main(void) {
int n;
cin >> n;
arrll(a,n);
ll ans=1e14;
REP(i,-100,101){
ll tmp=0;
rep(j,n){
tmp+=(a[j]-i)*(a[j]-i);
}
chmin(ans, tmp);
}
prt(ans);
}
| 0
| 60,277,973
|
#include <cstdio>
using namespace std;
int main()
{
int n;
scanf("%d", &n);
int c[10000];
for(int i = 0; i < n; ++i){
scanf("%d", &c[i]);
}
int min = c[0];
int max = c[0];
for(int i = 1; i < n; ++i){
if(min > c[i]) min = c[i];
if(max < c[i]) max = c[i];
}
long long int sum = 0;
for(int i = 0; i < n; ++i){
sum += c[i];
}
printf("%d %d %lld\n", min, max, sum);
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;
int main() {
ll n, ans = 0;
string s;
vector<char> c;
cin >> s;
rep(i, s.size()) if (s[i] != 'x') c.push_back(s[i]);
bool ok = false;
for (int i = 0; i < c.size() / 2; ++i) {
if (c[i] == c[c.size() - 1 - i])
continue;
else
ok = true;
}
if (s.size() == 1) {
puts("0");
return 0;
}
if (ok) {
puts("-1");
return 0;
}
int i = 0, j = s.size() - 1;
do {
if (s[i] == s[j]) {
i++, j--;
} else {
if (s[i] == 'x') {
i++;
ans++;
} else {
j--;
ans++;
}
}
} while (i <= j);
cout << ans << endl;
return 0;
}
| 0
| 13,135,464
|
#include <bits/stdc++.h>
using namespace std;
int f(int N){
int cnt = 0;
while(N>0){
cnt++;
N /= 10;
}
return cnt;
}
int main() {
int N; cin >> N;
int ans = 0;
for(int i = 1; i <= N;i++){
if(f(i)%2==1) ans++;
}
cout << ans << endl;
}
|
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int check(int j){
if (j==2 || j==4 ||j==3)
return j;
else
return 3;
}
int main(){
int board[22][22];
int w,h;
char t;
while(1){
cin >>w >>h;
if(w==0 && h==0) break;
for(int i=0;i<=21;i++){
for(int j = 0;j<=21;j++){
board[j][i]=4;
}
}
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
cin >> t ;
if(t == '.')board[j][i] = 1;
else if(t=='#')board[j][i]=2;
else board[j][i] = 3;
}
}
int cmem = 2000;
int c = 0;
while(cmem-c !=0){
cmem = c;
for(int i=1;i<=h;i++){
for (int j= 1;j<=w;j++){
if(board[j][i] ==3){
board[j-1][i] =check(board[j-1][i]);
board[j+1][i] =check(board[j+1][i]);
board[j][i-1] =check(board[j][i-1]);
board[j][i+1] =check(board[j][i+1]);
}
}
}
c = 0;
for(int i=1;i<=h;i++){
for (int j= 1;j<=w;j++){
if (board[j][i] ==3) c+=1;
}
}
}
cout <<c << endl;
}
return 0;
}
| 0
| 61,570,813
|
#include <bits/stdc++.h>
using namespace std;
vector<int> factor(100 + 1);
void prime_factor(int n) {
for (int i = 2; i * i <= n; i++)
while (n % i == 0) {
factor[i]++;
n /= i;
}
if (n != 1) factor[n] += 1;
}
int num(int n) {
int ret = 0;
for (auto x:factor) {
if (x >= n - 1) ret++;
}
return ret;
}
int main() {
int N;
cin >> N;
for (int i = 2; i <= N; i++) {
prime_factor(i);
}
cout << num(75) +
num(25) * (num(3) - 1) +
num(15) * (num(5) - 1) +
num(5) * (num(5) - 1) * (num(3) - 2) / 2
<< endl;
return 0;
}
|
#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 rap(p,a,b) for(ll p=a ; p<=b ; p++)
#define per(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;
t=1;
while(t--)
{
ll h,sum=0;
cin>>h>>n;
rep(p,0,n)
{
cin>>k;
sum+=k;
}
sum>=h?cout<<"Yes":cout<<"No";
}
return 0;
}
| 0
| 21,246,577
|
#include<iostream>
#include<cstdint>
int main() {
std::cin.tie(0); std::ios::sync_with_stdio(false);
int r, D, x; std::cin >> r >> D >> x;
for(int i = 0; i < 10; ++i) {
x = r*x - D;
std::cout << x << "\n";
}
return 0;
}
|
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define MOD 1000000007
#define oo 1000000000000000000
#define forr(i,n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define pb push_back
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
using namespace std;
ll valueOfIndex(ordered_set&s , ll i){ return *(s.find_by_order(i)); }
ll indexOfValue(ordered_set&s , ll x){ return s.order_of_key(x); }
ll add(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a+b + p)%p;}
ll mul(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a*b + p)%p;}
ll power(ll x,ll n,ll p=MOD){ if(x==0) return 0; if(n==0 || x==1) return 1LL;
ll r = (power(x,n/2,p))%p; if(n&1) return mul(mul(r,r,p) , x,p); else return mul(r,r,p);
}
ll inv(ll x){return power(x,MOD-2);}
void __sol(){
ll mx = 1e18;
ll n; cin >> n;
vector<ll> v(n); forr(i,n) cin >> v[i];
sort(all(v));
ll ans = 1;
forr(i,n){
ll x = v[i];
if(x==0){
cout << 0;
return;
}
else if( x<=mx/ans ) ans*=x;
else{
cout << -1;
return;
}
}
cout << ans;
return;
}
int main(){
fastio
ll tc=1;
while(tc--) __sol();
return 0;
}
| 0
| 4,845,628
|
#include <bits/stdc++.h>
using namespace std;
int main()
{int N; cin >> N;
cout << (N + 110) / 111 * 111;}
|
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
using namespace std;
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
int fact(int n) {
if (n == 0) return 1;
else return n * fact(n-1);
}
void solve30(int n, int s) {
int cnt = 0;
vector<int> data = {0,1,2,3,4,5,6,7,8,9};
int skip = fact(10 - n);
int i = 0;
do {
if (i % skip == 0) if (accumulate(data.begin(), data.begin() + n, 0) == s) {
cnt++;
}
i++;
}while (next_permutation(data.begin(), data.end()));
cout << cnt / fact(n) << endl;
}
int main() {
int n, s;
while(cin >> n >> s, n + s) {
solve30(n, s);
}
return 0;
}
| 0
| 74,981,330
|
#include <stdio.h>
#include <string.h>
int main(void)
{
int n, hanako_p=0, taro_p=0,i;
char hanastr[101], tarostr[101];
scanf("%d", &n);
for(i=0;i<n;i++) {
scanf("%s", tarostr);
scanf("%s", hanastr);
if(strcmp(tarostr,hanastr)==0) {
hanako_p++;taro_p++;
}
else if(strcmp(tarostr, hanastr)>0){
taro_p += 3;
}
else if(strcmp(tarostr, hanastr)<0){
hanako_p +=3;
}
}
printf("%d %d\n", taro_p, hanako_p);
return 0;
}
|
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;
template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }
constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion
void solve() {
int n, z, w;
cin >> n >> z >> w;
vector<int> a(n);
for (int i=0; i<n; i++) cin >> a.at(i);
if (n == 1) {
cout << abs(w - a.back()) << '\n';
} else {
cout << max(abs(w - a.back()), abs(a.at(n-1) - a.at(n-2))) << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
solve();
return 0;
}
| 0
| 37,333,518
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
int main()
{
fast;
ll n,d,cnt=0,sum;
cin>>n>>d;
ll arr[n][d];
for(int i=0;i<n;i++)
for(int j=0;j<d;j++)
cin>>arr[i][j];
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
sum=0;
for(int k=0;k<d;k++)
sum+=(arr[i][k] - arr[j][k])*(arr[i][k] - arr[j][k]);
if(floor(sqrt(sum))==ceil(sqrt(sum)))
cnt++;
}
}
cout<<cnt;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()
const ll mod = 1e9+7;
const ll INF = 1e9;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
return lx<=x&&x<ux&&ly<=y&&y<uy;
}
ll power(ll x,ll p){
if(p==0)return 1;
ll res=power(x*x%mod,p/2);
if(p%2==1)res=res*x%mod;
return res;
}
int main()
{
int n;
cin>>n;
cout<<(n-1)/2<<endl;
return 0;
}
| 0
| 11,110,972
|
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
int n, k; cin >> n >> k;
int cnt = 0;
rep(i, n){
int a; cin >> a;
if(a>=k)cnt++;
}
cout << cnt << ln;
}
|
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}
int INF = 1001001001;
int main() {
int n;
int p[110];
int dp[110][110];
cin >> n;
for(int i = 1;i<=n;i++) cin >> p[i-1] >> p[i];
for(int i = 0;i<=n;i++) dp[i][i] = 0;
for(int l = 2;l<=n;l++) {
for(int i = 1;i <= n-l+1;i++) {
int j = i+l-1;
dp[i][j] = INF;
for(int k = i;k<j;k++) {
chmin(dp[i][j],dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j]);
}
}
}
cout << dp[1][n] << endl;
}
| 0
| 24,951,447
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a,b,c,d;
cin>>a>>b>>c>>d;
if(b<=c||d<=a) {cout<<0<<endl; return 0;}
vector<int> x(4);
x[0]=a;x[1]=b;x[2]=c;x[3]=d;
sort(x.begin(),x.end());
cout<<x[2]-x[1]<<endl;
}
|
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
#define int long long
#define INF 1000000000000000000LL
#define MOD 1000000007LL
#define infile "../test/sample-1.in"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template<class T, size_t N> size_t sza(const T (&array)[N]) { return N; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T=int> T in() {T x; cin>>x; return (x);}
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
#ifdef PCM
#include "dump.hpp"
#else
#define dump(...) 42
#define dump_1d(...) 42
#define dump_2d(...) 42
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second
int solve(){
int k;cin>>k;
int n=50;
int x=k/n;
int y=k%n;
vi res;
rep(i, n+1){
if (i!=n-y) res.pb(i+x);
}
cout << n << endl;
rep(i, sz(res)) cout << res[i] << (i!=sz(res)-1 ? " " : "\n");
return 0;
}
signed main() {
#ifdef INPUT_FROM_FILE
std::ifstream in(infile);
std::cin.rdbuf(in.rdbuf());
#endif
solve();
return 0;
}
| 0
| 4,938,989
|
#include <stdio.h>
int main(){
long N,A[100000],i,x,a=1;
scanf("%ld",&N);
x=1;
for(i=0;i<N;i++){
scanf("%ld",&A[i]);
if(A[i]==0){
puts("0");
return 0;
}
if((long)1e18/x/A[i]<1){
a=0;
}
else x=x*A[i];
}
if(a==0)puts("-1");
else printf("%ld\n",x);
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;
long long GCD(long long a, long long b) {
if (b == 0) return a;
else return GCD(b, a % b);
}
int main()
{
int N;
cin >> N;
vector<int> a(N, 0);
rep(i, N) cin >> a[i];
int search = 1;
int cnt = 0;
for (int i = 0; i < N; ++i)
{
if (a[i] == search) {
search += 1;
cnt++;
}
}
if (cnt != 0) {
cout << N - cnt << endl;
}
else {
cout << "-1" << endl;
}
return 0;
}
| 0
| 90,896,662
|
#include<bits/stdc++.h>
using namespace std;
vector<int> g[200005];
vector<int> ans;
bool vis[200005];
void dfs(int s,int& cnt){
if(vis[s]) return;
vis[s] = true;
cnt++;
for(int i=0;i<g[s].size();i++){
if(vis[g[s][i]]) continue;
dfs(g[s][i],cnt);
}
}
int main(int argc, char * argv[])
{
int n,m,a,b;
cin>>n>>m;
for(int i=0;i<m;i++){
cin>>a>>b;
a--;b--;
g[a].push_back(b);
g[b].push_back(a);
}
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++){
if(!vis[i]){
int cnt = 0;
dfs(i,cnt);
ans.push_back(cnt);
}
}
int realAns = ans[0];
for(int i=0;i<ans.size();i++)
realAns = max(realAns,ans[i]);
cout<<realAns<<endl;
return 0;
}
|
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#pragma region header
using namespace std;
using ll = long long;
using lint = long long;
using ld = long double;
using ulint = unsigned long long;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr lint mod = 1000000007;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
#define INF (lint)10000000000000000
#define mod = (int)1000000007;
#pragma endregion
lint n;
vector<lint> d;
void input() {
cin >> n;
d.resize(n);
for (int i = 0; i < n; i++)
cin >> d[i];
return;
}
unsigned long long gcd(unsigned long long a, unsigned long long b) {
if (a % b == 0)
return b;
else
return gcd(b, a % b);
}
ulint lcm(ulint a, ulint b) {
return a / gcd(a, b) * b;
}
unsigned long long solve() {
if (n == 1) return d[0];
unsigned long long ans;
ans = lcm(d[0], d[1]);
for (int i = 2; i < n; i++) {
ans = lcm(ans, d[i]);
}
return ans;
}
int main(void) {
input();
printf("%llu\n", solve());
return 0;
}
| 0
| 51,644,041
|
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#define _USE_MATH_DEFINES
#include<math.h>
#include<unordered_map>
#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)
using namespace std;
int main()
{
string str;
int n;
cin >> str >> n;
for (int i = 0; i < n; i++)
{
string command;
cin >> command;
if (command == "replace")
{
int f, t;
string newStr;
cin >> f >> t >> newStr;
str.replace(f, t - f + 1, newStr.c_str());
}
else if (command == "reverse")
{
int f, t;
cin >> f >> t;
reverse(str.begin() + f, str.begin() + t + 1);
}
else if (command == "print")
{
int f, t;
cin >> f >> t;
for (int j = f; j <= t; j++)
{
printf("%c", str[j]);
}
printf("\n");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int main() {
string s, t;
cin >> s;
rep (i, 0, s.size()) {
if (s[i] == 'x') continue;
t += s[i];
}
rep (i, 0, t.size()) {
if (t[i] != t[t.size() - 1 - i]) {
cout << -1 << "\n";
return 0;
}
}
int nl = 0, nr = s.size() - 1;
int ans = 0;
while (nl < nr) {
int cntl = 0, cntr = 0;
while (s[nl] == 'x') {
nl++;
cntl++;
}
while (s[nr] == 'x') {
nr--;
cntr++;
}
nl++, nr--;
ans += abs (cntr - cntl);
}
cout << ans << "\n";
}
| 0
| 90,508,402
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<ll, ll>P;
int main(){
ll N,K,S;
cin>>N>>K>>S;
rep(i,K){cout<<S<<' ';}
if(S!=1000000000){
rep(i,N-K){cout<<S+1ll<<' ';}
}
else{
rep(i,N-K){cout<<1<<' ';}
}
}
|
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using st = string;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using pcc = pair<char, char>;
const ll INF = 1e9;
const ll MOD = 1e9+7;
const vl dx = {1,0,-1,0,1,0,-1,0};
const vl dy = {0,1,0,-1,0,1,0,-1};
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define rrep(i,n) for(ll i = (ll) n - 1; i >= 0;i--)
#define REP(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define RREP(i,x,n) for(ll i = (ll) n - 1; i >= x; i--)
#define each(i,A) for(ll i: (vl) A)
#define all(A) A.begin(), A.end()
#define Size(A) ll(A.size())
template<typename T> T input() {T x; cin >> x; return x;}
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}
ll ceil(ll a,ll b) {return (a + b - 1) / b;}
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;}
ll gcd(ll a,ll b){if(a<b)swap(a,b); if(a%b==0)return b; return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll modPow(ll x,ll n,ll mod){if(n==0)return 1; if(n%2==0)return modPow(x*x,n/2,mod)%mod; return x%mod*modPow(x,n-1,mod)%mod;}
int main() {
ll n, m;
cin >> n >> m;
cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}
| 0
| 54,004,788
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main(int argc, char const *argv[]) {
int n,m; cin >> n >> m;
vector<vector<int>> jobs(m); REP(i,n) {
int a, b; cin >> a >> b;
if (a > m) continue;
jobs[m-a].PB(b);
}
ll ans = 0;
priority_queue<int> que;
REPD(i,m) {
for(auto j : jobs[i]) que.push(j);
if (!que.empty()) {
int top_item = que.top(); que.pop();
ans+=top_item;
}
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
int main() {
ios_base::sync_with_stdio(false);
string o,e;
cin >> o >> e;
string ans;
rep(i,e.size()) {
ans.push_back(o[i]);
ans.push_back(e[i]);
}
if (o.size()>e.size()) ans.push_back(o[o.size()-1]);
cout << ans << endl;
return 0;
}
| 0
| 12,970,994
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pi acos(-1)
#define eps 1e-8
pair<int,int> a[100001];
bool cmp(pair<int,int> a,pair<int,int> b)
{
return atan2(1.0*a.second,1.0*a.first)<
atan2(1.0*b.second,1.0*b.first);
}
signed main()
{
int n;
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld%lld",&a[i].first,&a[i].second);
if(a[i].first==a[i].second&&a[i].first==0)
n--,i--;
}
sort(a+1,a+n+1,cmp);
int ans=0;
for(int i=1;i<=n;i++)
a[n+i]=a[i];
for(int i=1;i<=n;i++)
{
int sumx=0,sumy=0;
for(int j=i;j<i+n;j++)
{
sumx+=a[j].first;
sumy+=a[j].second;
ans=max(ans,sumx*sumx+sumy*sumy);
}
}
printf("%.20lf",sqrt(1.0*ans));
return 0;
}
|
#include<iostream>
using namespace std;
#include<vector>
int main() {
int n, m, res = 0;
cin >> n >> m;
int lb[m][n], p[m], k[m];
for(int i = 0; i < m; i++) {
cin >> k[i];
for(int j = 1; j <= k[i]; j++) {
cin >> lb[i][j];
}
}
for(int i = 0; i < m; i++) {
cin >> p[i];
}
bool flag;
int sw = 0 , temp;
for(int bit = 0; bit < (1<<n); bit++) {
flag = true;
vector<int> S;
for(int i = 0; i < n; i++) {
if(bit & (1<<i)) {
S.push_back(i);
}
}
for(int i = 0; i < m; i++) {
sw = 0;
for(int j = 1; j <= k[i]; j++) {
if(bit & (1<<(lb[i][j]-1))) sw++;
}
if(sw%2 != p[i]) {
flag = false;
break;
}
}
if(flag) res++;
}
cout << res << endl;
}
| 0
| 53,133,390
|
#define _GLIBCXX_DEBUG
#include <iostream>
using namespace std;
int main(void){
int a, b, c, k;
cin >> a >> b >> c >> k;
if(k <= a) cout << k << '\n';
else if(k <= a+b) cout << a << '\n';
else cout << a-(k-a-b) << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<p> xy(N);
for(int i = 0; i < N; i++) {
ll x, y;
cin >> x >> y;
xy[i] = make_pair(x, y);
}
sort(xy.begin(), xy.end());
ll ans = 4000000000000000005;
for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++) {
ll y1 = xy[i].second;
ll x1 = xy[j].first;
for(int k = 0; k < N; k++) {
ll y2 = xy[k].second;
if(y1 > y2) continue;
ll x2;
int c = 0;
for(int l = j; l < N; l++) {
if(y1 <= xy[l].second && xy[l].second <= y2) {
c++;
if(c == K) {
x2 = xy[l].first;
break;
}
}
}
if(c < K) continue;
ans = min(ans, (x2 - x1) * (y2 - y1));
}
}
}
cout << ans << endl;
}
| 0
| 93,501,667
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main() {
ll n; cin >> n;
ll asum=0,bsum=0;
vector<ll> a(n),b(n);
rep(i,n){
cin >> a[i]; asum+=a[i];
}
rep(i,n){
cin >> b[i]; bsum+=b[i];
}
if(asum<bsum){
cout << -1 << endl;
return 0;
}
vector<ll> dif(n);
ll fsum=0, cnt=0;
rep(i,n){
dif[i]=a[i]-b[i];
if(dif[i]<0){
fsum+=dif[i]*(-1); cnt++;
}
}
if(fsum==0){
cout << 0 << endl;
return 0;
}
sort(dif.begin(),dif.end());
ll psum=0;
for(ll i=n-1;n>=0;i--){
psum+=dif[i];cnt++;
if(psum>=fsum){
break;
}
}
cout << cnt << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll a, ll b) {
return (a ? gcd(b%a, a) : b);
}
ll lcm(ll a, ll b) {
return a * b / gcd(a, b);
}
int main() {
ios::sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<ll> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
ll ans = 1;
for (auto x : a) ans = lcm(ans, x);
bool ok = true;
for (auto x : a) {
if (not ( (ans / x) & 1 ) ) ok = false ;
}
if (ok) {
ans = int((double)m/ans + 0.5);
} else
ans = 0;
cout << ans << "\n";
return 0;
}
| 0
| 86,988,736
|
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define si set <ll>
#define vi vector <ll>
#define popcount(x) __builtin_popcountll(x)
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define mem0(a) memset(a,0,sizeof(a))
#define rep(i,a,n) for( ll i=a ; i<n ; i++)
#define ld long double
#define rall(a) (a).rbegin(),(a).rend()
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);
}
bool isPowerOfTwo(ll x)
{
return (x && !(x & (x - 1)));
}
void solve()
{
ll a,b,c,k;
cin>>a>>b>>c>>k;
int x=0,y=0;
while(b<=a)
{
b*=2;
x++;
}
while(c<=b)
{
c*=2;
y++;
}
if(x+y<=k) cout<<"Yes"<<"\n";
else cout<<"No"<<"\n";
}
int main()
{
fastio
ll tt=1;
while(tt--)
{
solve();
cout<<"\n";
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
const long long MOD=998244353;
int main(){
int n;scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++)scanf("%d",&a[i]);
int ans=0,now=101;
for(int i=1;i<n;i++){
if(a[i]==a[i-1]){
ans++;
a[i]=now;
now++;
}
}
printf("%d\n",ans);
return 0;
}
| 0
| 31,660,040
|
#include <iostream>
using namespace std;
int main(void){
int A,B;
cin>>A>>B;
if(A==B){
cout<<"Draw"<<endl;
}
else if(A==1){
cout<<"Alice"<<endl;
}
else if(B==1){
cout<<"Bob"<<endl;
}
else if(A>B){
cout<<"Alice"<<endl;
}
else if(A<B){
cout<<"Bob"<<endl;
}
else{
cout<<"Bob"<<endl;
}
}
|
#include<iostream>
#include<vector>
int main(void){
int h, w;
std::cin >> h >> w;
std::vector<std::string> s(h);
for(int i = 0; i < h; i++){
std::cin >> s[i];
}
std::vector<std::vector<int>> da(h, std::vector<int>(w));
for(int i = 0; i < h; i++){
int cnt = 0;
int start = 0;
for(int j = 0; j < w; j++){
if(s[i][j] == '#'){
for(int k = start; k < j; k++){
da[i][k] += cnt;
}
start = j+1;
cnt = 0;
continue;
}else{
cnt++;
if(j == w - 1){
for(int k = start; k <= j; k++){
da[i][k] += cnt;
}
}
}
}
}
for(int i = 0; i < w; i++){
int cnt = 0;
int start = 0;
for(int j = 0; j < h; j++){
if(s[j][i] == '#'){
for(int k = start; k < j; k++){
da[k][i] += cnt;
}
start = j + 1;
cnt = 0;
continue;
}else{
cnt++;
if(j == h - 1){
for(int k = start; k <= j; k++){
da[k][i] += cnt;
}
}
}
}
}
int max = 0;
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
max = std::max(max, da[i][j]);
}
}
std::cout << max - 1<< std::endl;
return 0;
}
| 0
| 35,440,731
|
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
int cnt[110];
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
int N; cin >> N;
REP(i, 2, N) cnt[i]++;
REP(i, 2, N) {
int n = i;
int j = 2;
while(n > 1) {
while (n % j == 0) {
cnt[j]++;
n /= j;
}
j++;
}
}
int ans = 0;
REP(i, 2, N) {
if (cnt[i] >= 75) ans++;
}
REP(i, 2, N) {
REP(j, i + 1, N) {
if (cnt[i] >= 3 && cnt[j] >= 25) ans++;
if (cnt[i] >= 25 && cnt[j] >= 3) ans++;
}
}
REP(i, 2, N) {
REP(j, i + 1, N) {
if (cnt[i] >= 15 && cnt[j] >= 5) ans++;
if (cnt[i] >= 5 && cnt[j] >= 15) ans++;
}
}
REP(i, 2, N) {
REP(j, i + 1, N) {
REP(k, j + 1, N) {
if (cnt[i] >= 3 && cnt[j] >= 5 && cnt[k] >= 5) ans++;
if (cnt[i] >= 5 && cnt[j] >= 3 && cnt[k] >= 5) ans++;
if (cnt[i] >= 5 && cnt[j] >= 5 && cnt[k] >= 3) ans++;
}
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)
template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif
const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
ll dp[1005][1005];
int main() {
init();
string s, t;
cin >> s >> t;
ll sn = s.size(), tn = t.size();
rep(i, sn + 1) dp[i][0] = i;
rep(i, tn + 1) dp[0][i] = i;
rep(i, sn){
rep(j, tn){
dp[i + 1][j + 1] = min({dp[i][j + 1] + 1, dp[i + 1][j] + 1, dp[i][j] + (s[i] != t[j])});
}
}
cout << dp[sn][tn] << endl;
}
| 0
| 79,341,615
|
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
using namespace std;
const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;
int main(){
int N; cin >> N;
vector <double> T(N + 2), V(N + 2);
int sum = 0;
for (int i = 1; i < N + 1; i++){
double t; cin >> t; sum += t;
T[i] = T[i - 1] + t;
}
T[N + 1] = T[N];
for (int i = 1; i < N + 1; i++){
cin >> V[i];
}
vector <double> ans(sum * 2 + 1);
for (int i = 0; i < sum * 2 + 1; i++){
ans[i] = min(0.5 * i, sum - 0.5 * i);
}
for (int i = 0; i < sum * 2 + 1; i++){
double now = 0.5 * i;
for (int j = 1; j < N + 2; j++){
if (T[j] < now){
ans[i] = min(ans[i], V[j] + abs(now - T[j]));
}else if (T[j - 1] <= now && now <= T[j]){
ans[i] = min(ans[i], V[j]);
}else{
ans[i] = min(ans[i], V[j] + abs(now - T[j]));
}
}
}
for (int i = sum * 2 - 1; i >= 0; i--){
if (ans[i] - ans[i + 1] > 0.5){
ans[i] = ans[i + 1] + 0.5;
}
}
double A = 0;
for (int i = 0; i < sum * 2; i++){
A += 0.25 * (ans[i] + ans[i + 1]);
}
cout << setprecision(32) << A << endl;
return 0;
}
|
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<cstdio>
#include<algorithm>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=2e5+100;
const LL mod=1e9+7;
LL arr[N],ans[N];
LL fac[N],opp[N],op_fa[N];
void preWork(){
fac[0]=fac[1]=1;
opp[0]=opp[1]=1;
op_fa[0]=op_fa[1]=1;
for(int i=2;i<=1e5+100;i++){
fac[i]=((LL)fac[i-1]*i)%mod;
opp[i]=(LL)(mod-mod/i)*opp[mod%i]%mod;
op_fa[i]=(LL)opp[i]*op_fa[i-1]%mod;
}
}
LL C(LL n,LL m){
if(n<m)return 0;
int ans=(LL)fac[n]%mod*(LL)op_fa[n-m]%mod*(LL)op_fa[m]%mod;
return ans%mod;
}
int mak[N];
int main(){
int n;
preWork();
while(cin>>n){
memset(mak,0,sizeof(mak));
int x,pos1=1,pos2=1,tmp1,tmp2,tmp;
for(int i=1;i<=n+1;i++){
cin>>x;
if(mak[x])tmp=n-i+mak[x];
mak[x]=i;
}
ans[1]=n;
for(int i=1;i<=n+1;i++){
ans[i]=((LL)C(n+1,i)-(LL)C(tmp,i-1)+mod)%mod;
}
for(int i=1;i<=n+1;i++){
cout<<ans[i]<<endl;
}
}
return 0;
}
| 0
| 65,568,804
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define ld long double
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define debug(a) cout << #a << ": " << a << endl
#define Flag(n) cout << "here " << n << endl
#define w(x) int x;cin>>x;while(t--)
#define mp make_pair
#define pb push_back
#define endl '\n';
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__);
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif
const int POSITIVE_INFINITY = 9223372036854775807;
const int NEGATIVE_INFINITY = -9223372036854775807;
const int MOD = 1000000007;
const ld PI = acos(-1.0);
const int INF = 1e18;
const int MX = 1000001;
int32_t main() {
io;
string s,t;
cin>>s>>t;
int res= t.size();
for(int i = 0;i<=s.size()-t.size();i++){
int diff= 0;
for(int j = 0;j<t.size();j++){
if(t[j]!=s[i+j])diff++;
}
res= min(res,diff);
}
cout<<res<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(src,dst) for(int i=src; i<dst; i++)
#define rep2(src,dst) for(int j=src; j<dst; j++)
#define INF 1000000000000
#define MOD 10000007
#define PI acos(-1)
#define ll long long
template<typename T> inline void ChMin(T* a, T* b) {if(*a>*b) *a=*b;}
template<typename T> inline void ChMax(T* a, T* b) {if(*a<*b) *a=*b;}
template<typename T> inline int DivUp(T a, T b) {return ((a+b-1)/b);}
int main(){
int n, ans=0; cin >> n;
vector<int> d(n);
rep(0,n) cin >> d[i];
int p = (n*(n-1))/2;
rep(0,n){
rep2(i+1,n){
ans += d[i] * d[j];
}
}
cout << ans << endl;
return 0;
}
| 0
| 28,735,022
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
struct mint {
ll x;
mint(ll x=0):x(x%mod){}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
};
int main()
{
int n,k;
cin>>n>>k;
long long lsum=0;
int left=k-1;
int right=n-k+1;
for(int i=0;i<k;i++)lsum+=i;
long long rsum=0;
for(int i=n;i>(n-k);i--)rsum+=i;
mint ans=0;
ans+=(rsum-lsum+1);
for(int i=k+1;i<=n+1;i++)
{
left++;
lsum+=left;
right--;
rsum+=right;
ans+=(rsum-lsum+1);
}
cout<<ans.x<<endl;
return 0;
}
|
#include <bits/stdc++.h>
#define MOD 1000000007;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
void Main()
{
ll n;
string s;
cin >> n >> s;
unordered_map<char, ll> M;
rep(i, s.size())
M[s.at(i)]++;
ll sum;
sum = 1;
for (auto itr = M.begin(); itr != M.end(); itr++)
{
sum *= (itr->second + 1);
sum %= MOD;
}
sum--;
cout << sum << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
Main();
}
| 0
| 31,575,478
|
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int64_t> A(n), B(n);
vector<array<int64_t, 2>> S(n);
for (int i = 0; i < n; i++){
cin >> A[i] >> B[i];
S[i][0] = A[i] + B[i];
S[i][1] = i;
}
sort(S.begin(), S.end(), greater<array<int64_t, 2>>());
int64_t ans = 0;
for (int i = 0; i < n; i++){
if (i % 2 == 0)
ans += A[S[i][1]];
else
ans -= B[S[i][1]];
}
cout << ans << endl;
}
|
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main(void){
while(1){
string x;
cin >> x;
if(x=="0")break;
int v;
v=0;
for(int i=0;i<(int)x.size();i++){
char ch = x[i];
int n = (int)ch - (int)'0';
v+=n;
}
cout << v << endl;;
}
}
| 0
| 29,610,166
|
#include<iostream>
using namespace std;
int min(int *a, int n)
{
int v = 1000000;
for ( int i = 0; i < n; i++ )
{
if ( v > a[i] )
{
v = a[i];
}
}
return v;
}
int max(int *a, int n)
{
int v = -1000000;
for ( int i = 0; i < n; i++ )
{
if ( v < a[i] )
{
v = a[i];
}
}
return v;
}
long long sum(int *a, int n)
{
long long v = 0;
for ( int i = 0; i < n; i++ )
{
v += a[i];
}
return v;
}
int main()
{
int a[10000];
int n;
cin >> n;
for ( int i = 0; i < n; i++ )
{
cin >> a[i];
}
cout << min(a, n) << " " << max(a, n) << " " << sum(a, n) << endl;
return 0;
}
|
#include <bits/stdc++.h>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0); std::cout.tie(0);
std::string s;
std::getline(std::cin, s);
std::istringstream iss(s);
std::string a;
std::string b;
std::string c;
iss >> a >> b >> c;
if (a[a.size() - 1] == b[0] &&
b[b.size() - 1] == c[0])
std::cout << "YES" << std::endl;
else
std::cout << "NO" << std::endl;
return 0;
}
| 0
| 41,083,869
|
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
return *ci++;
}
inline int getint() {
int A = 0;
if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
return A;
}
pair<int, int> to[200000];
int he[100001], jisuu[100001], A[100001], saidai[100001];
ll goukei[100001];
int main() {
int N = getint();
rep1(i, N) A[i] = getint();
int k = 1;
rep(i, N - 1) {
int a = getint(), b = getint();
jisuu[a]++;
jisuu[b]++;
to[k] = mp(b, he[a]);
he[a] = k++;
to[k] = mp(a, he[b]);
he[b] = k++;
}
if (N == 2) {
if (A[1] == A[2]) printf("YES");
else printf("NO");
return 0;
}
queue<int> q;
rep1(i, N) if (jisuu[i] == 1) jisuu[i] = 0;
rep1(i, N) if (jisuu[i] == 0) {
int p = to[he[i]].first;
goukei[p] += A[i];
chmax(saidai[p], A[i]);
jisuu[p]--;
if (jisuu[p] == 1) q.push(p);
}
bool OK = 1;
while (q.size()) {
int i = q.front();
q.pop();
if (jisuu[i]) {
for (int j = he[i]; j; j = to[j].second) {
int p = to[j].first;
if (jisuu[p]) {
jisuu[p]--;
if (jisuu[p] == 1) q.push(p);
ll tmp = A[i] * 2 - goukei[i];
chmax(saidai[i], int(tmp));
goukei[p] += tmp;
chmax(saidai[p], int(tmp));
if (tmp < 0 || saidai[i] > A[i]) OK = 0;
}
}
jisuu[i] = 0;
}
else if (saidai[i] > A[i] || goukei[i] != A[i] * 2) OK = 0;
}
if (OK) printf("YES");
else printf("NO");
Would you please return 0;
}
|
#include <iostream>
#include <set>
#include <string>
#include <algorithm>
using namespace std;
int main(){
string S;
char rS='a'-1;
cin >> S;
set<char> alp;
set<char> word;
set<char> res;
string resS="";
int flag=0;
for(char s='a';s<='z';s++) alp.insert(s);
while(flag==0){
word.clear();
res.clear();
if (S.empty()) flag=1;
for(auto itr=S.begin();itr!=S.end();itr++) word.insert(*itr);
set_difference(alp.begin(),alp.end(),
word.begin(),word.end(),
inserter(res,res.end()));
for(auto itr=res.begin();itr!=res.end();itr++){
if(*itr>rS){
resS=S;
resS.push_back(*itr);
flag=1;
break;
}
}
if(flag==1) break;
rS = *(S.end()-1);
S.pop_back();
}
if(resS.empty()){cout << -1 << endl;}
else{ cout << resS << endl;}
}
| 0
| 97,193,849
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
int N; cin>>N;
int a[1000001];
rep(i,1000001)a[i]=0;
int ans=0;
rep(i,N){
int x; cin>>x;
if(x>N){
ans++;
continue;
}
a[x]++;
ans++;
if(a[x]==x)ans-=x;
}
cout<<ans<<endl;
return 0;
}
|
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)
#define ALL(x) (x).begin(), (x).end()
int gcd(int a, int b)
{
return b ? gcd(b, a % b) : a;
}
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int main()
{
int N, M;
cin>>N>>M;
vector<int> vi(N);
REP(i, N)
cin >> vi[i];
set<int> si;
REP(i, M)
{
int a, b;
cin >> a >> b;
a--;
b--;
if (vi[a] < vi[b])
si.insert(a);
if (vi[a] > vi[b])
si.insert(b);
if (vi[a] == vi[b]) {
si.insert(a);
si.insert(b);
}
}
cout << N - si.size() << endl;
}
| 0
| 90,471,378
|
#include<iostream>
using namespace std;
int main(){
int x;
cin>>x;
int temp=x;
int sum=0;
while(temp!=0)
{
sum+=temp%10;
temp/=10;
}
if(x%sum==0)
{
cout<<"Yes";
}
else
cout<<"No";
}
|
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
int main(){
ll n,l,t;
cin >> n >> l >> t;
ll x[n], w[n];
REP(i,n) cin >> x[i] >> w[i];
ll x_t[n];
REP(i,n){
if(w[i]==1){
x_t[i] = (x[i] + t)%l;
}else{
x_t[i] = (x[i] - t + t * l)%l;
}
}
ll zero_pos = x_t[0];
sort(x_t,x_t+n);
ll cross_cnt = 0;
for(ll i = 1; i < n; i++){
if(w[0]==1&&w[i]==2){
cross_cnt += floor((t-(x[i]-x[0]+l)%l/2.0)/(l/2.0))+1;
}else if(w[0]==2&&w[i]==1){
cross_cnt -= floor((t-(x[0]-x[i]+l)%l/2.0)/(l/2.0))+1;
}
}
ll zero_ind = cross_cnt>=0 ? cross_cnt%n : n+cross_cnt%n ;
ll zero_ord = lower_bound(x_t,x_t+n,zero_pos) - x_t;
if(x_t[zero_ord]==x_t[(zero_ord+1)%n]){
if(w[0]==1){
zero_ord++;
zero_ord%=n;
}
}
vector<pair<ll,ll> > ants;
ants.push_back(pair<ll,ll>(zero_ind,zero_pos));
REP(i,n-1){
zero_ord++;
zero_ord%=n;
zero_ind++;
zero_ind%=n;
ants.push_back(pair<ll,ll>(zero_ind,x_t[zero_ord]));
}
sort(ants.begin(),ants.end());
REP(i,n){
cout << ants[i].second << endl;
}
return 0;
}
| 0
| 30,281,845
|
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);
int main() {
int A, B, C;
cin>>A>>B>>C;
if(A+B>=C) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
for(int i=0;i<(int)(s.size());++i) {
cout << s[i];
if(i == (int)(s.size())-1) cout << endl;
else cout << " ";
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
vector<string> v = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
int q; cin >> q;
while(q > 0) {
q--;
string s; cin >> s;
vector<pair<int, int>> p;
char now = s[0];
int cnt = 1;
for(int i=1;i<(int)(s.size());++i) {
if(s[i] == now) {
cnt++;
} else {
p.push_back({now-'0', cnt});
now = s[i];
cnt = 1;
}
}
p.push_back({now-'0', cnt});
string ans = "";
for(int i=0;i<(int)(p.size())-1;++i) {
if(p[i].first != 0 && p[i+1].first == 0) {
ans.push_back(v[p[i].first][(p[i].second-1) % (int)(v[p[i].first].size())]);
}
}
cout << ans << endl;
}
}
| 0
| 409,104
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
long long mul=1;
long long a[n];
long long z = 0;
for(int i=0;i<n;i++) {
cin>>a[i];
if(a[i]==0) z =1;
}
if(z==1){
cout<<0;
return 0;
}
for(int i=0;i<n;i++){
if(a[i]<=1000000000000000000/mul){
mul*=a[i];
}
else{
cout<<-1;
return 0;
}
}
cout<<mul;
}
|
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln = '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
int n, k; cin >> n >> k;
vector<ll> A(n); rep(i, n) cin >> A[i];
multiset<ll> mst;
for(int left=0; left<n; left++){
ll sum = 0;
for(int right = left; right < n; right++){
sum += A[right];
mst.insert(sum);
}
}
ll res = 0;
for(ll mask = pow(2,40); mask>0; mask /= 2){
int cnt = 0;
for(auto a: mst){
if(a&mask)cnt++;
}
if(cnt>=k){
res += mask;
for(auto a: mst){
if(!(a&mask))mst.erase(a);
}
}
}
cout << res << ln;
}
| 0
| 511,785
|
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>
using namespace std;
int main(int argc, char** argv) {
ios::sync_with_stdio(false);
cin.tie(0);
int d;
cin >> d;
int cnt = 25 - d;
string res = "Christmas";
for (int i = 0; i < cnt; ++i) {
res += ' ';
res += "Eve";
}
cout << res << '\n';
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define F first
#define S second
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x) (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
if(a==0 || b==0)return 0;
return a/__gcd(a,b)*b;
}
void input(ll ara[],ll n)
{
for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
for(ll i=0; i<n; i++)
cout<<ara[i]<<" ";
cout<<endl;
}
int main()
{
fastread();
ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;
bool flag=false;
string str;
cin>>a>>b>>c;
a-=b;
cout<<c-min(c,a)<<endl;
}
| 0
| 36,953,830
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef pair<ll,ll> pair1;
typedef pair<string,ll> pair2;
typedef pair<ll,string> pair3;
typedef pair<string,string> pair4;
#define fl(i,a,b) for(i=a;i<b;i++)
#define rfl(i,a,b) for(i=b-1;i>=a;i--)
#define f first
#define s second
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
char a;cin>>a;
int b=a;
b+=1;
char c=b;
cout<<c;
return 0;
}
|
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);
int main(){
{rep1(i,61) pw2[i]=2*pw2[i-1];}
{rep1(i,18) pw10[i]=10*pw10[i-1];}
ll N,K; cin>>N>>K;
ll ans=-INF;
vector<ll> A(N);
vector<ll> B(N);
rep(i,N){
cin>>A[i];
B[i]=max(0ll,A[i]);
}
vector<ll> sA(N+1,0);
vector<ll> sB(N+1,0);
rep(i,N){
sA[i+1]=sA[i]+A[i];
}
rep(i,N){
sB[i+1]=sB[i]+B[i];
}
rep(i,N-K+1){
chmax(ans,max(0ll,sA[i+K]-sA[i])+sB[N]-sB[i+K]+sB[i]-sB[0]);
}
cout<<ans<<endl;
}
| 0
| 92,595,567
|
#include<bits/stdc++.h>
using namespace std;
#define DIV 1000000007
#define BLACK 0
#define WHITE 1
long long N;
long long ban[200005];
string S;
int main(){
cin >> N;
cin >> S;
for(long long i = 0; i < 2*N; i++){
if(i%2 == 0){
if(S[i] == 'B'){
ban[i] = WHITE;
}else{
ban[i] = BLACK;
}
}else{
if(S[i] == 'B'){
ban[i] = BLACK;
}else{
ban[i] = WHITE;
}
}
}
long long left = 0;
long long ans = 1;
for(long long i = 0; i < 2*N; i++){
if(ban[i] == WHITE){
left++;
} else {
ans *= left;
ans %= DIV;
left--;
}
}
if(left!=0){
cout << 0 << endl;
return 0;
}
for(long long i = 1; i <= N; i++){
ans *= (i);
ans %= DIV;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}
template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
int l = vv.size();
if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n " ) << vv[i] << (i==l-1 ? " ]" : ""); }
return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;
inline void finput(string filename) {
freopen(filename.c_str(), "r", stdin);
}
int main(){
ios_base::sync_with_stdio(0);
int h,w,m; cin >> h >> w >> m;
vi hcnt(h+1), wcnt(w+1);
set<pii> bomb;
rep(i,m){
int hi,wi;
cin >> hi >> wi;
hi--; wi--;
hcnt[hi]++;
wcnt[wi]++;
bomb.emplace(hi,wi);
}
int hm = *max_element(all(hcnt));
int wm = *max_element(all(wcnt));
vi hmax,wmax;
rep(hi,h) if(hcnt[hi] == hm) hmax.push_back(hi);
rep(wi,w) if(wcnt[wi] == wm) wmax.push_back(wi);
int ans = hm + wm - 1;
for(auto hi : hmax) for(auto wi : wmax){
if(bomb.find({hi,wi}) == bomb.end()){
ans = hm + wm;
cout << ans << endl;
return 0;
}
}
cout << ans << endl;
return 0;
}
| 0
| 12,780,339
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
inline void io()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.precision(10);
cout << fixed;
}
int main()
{
io();
int n;
cin >> n;
int mx = 0;
int ans = 0;
for (int i = 1; i <= n; i++)
{
int h;
cin >> h;
ans += (h >= mx);
mx = max(mx, h);
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 300100;
int n,a,b,ans[maxn];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>a>>b;
if ((n<a+b-1) || (n > 1ll*a*b)) cout<<-1;
else {
int cur = n;
for (int i=b;i>=1;i--) {
if (cur-a > i-1) {
for (int j=cur-a+1;j<=cur;j++) cout<<j<<" ";
cur-=a;
} else {
for (int j=i;j<=cur;j++) cout<<j<<" ";
cur=i-1;
break;
}
}
for (int i=cur;i>=1;i--) cout<<i<<" ";
}
}
| 0
| 98,771,627
|
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;
struct UnionFind{
vector<int> d;
UnionFind(int n=0):d(n,-1){}
int root(int x){
if(d[x]<0)return x;
return d[x]=root(d[x]);
}
bool unite(int x,int y){
x=root(x);y=root(y);
if(x==y)return false;
if(d[x]>d[y])swap(x,y);
d[x]+=d[y];
d[y]=x;
return true;
}
bool same(int x,int y){return root(x)==root(y);}
int usize(int x){return -d[root(x)];}
};
int main(){
int n,m;cin >>n>>m;
UnionFind uni(n);
for (int i = 0; i < m; ++i) {
int a,b;cin >>a>>b;
a--;b--;
uni.unite(a,b);
}
int ans=-1;
for (int i = 0; i < n; ++i) {
ans=max(ans,uni.usize(i));
}
cout <<ans <<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
long long from_1(long long n) {
long long result=0;
n = n + 1;
for (long long i = 1; i <= n; i = i * 2) {
if (i == 1) {
result = (n / 2) % 2;
} else {
result = result + i * (max(n % (i * 2) - i, (long long)0) % 2);
}
}
return result;
}
int main() {
long long A, B;
scanf("%lld %lld", &A, &B);
cout << (from_1(B) ^ from_1(A - 1));
return 0;
}
| 0
| 95,737,022
|
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
cin >> head;
_cin(forward<Tail>(tail)...);
}
#define Cin(T, ...) \
T __VA_ARGS__; \
_cin(__VA_ARGS__)
#define Cins(T, n, xs) \
vector<T> xs(n); \
for (int i = 0; i < n; ++i) cin >> xs[i]
void Main() {
Cin(int, n);
Cins(int, n, a);
int ans = 0;
for (int i = 1; i < n; ++i) {
if (a[i] == a[i - 1]) {
ans++;
a[i] = -1;
}
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
Main();
return 0;
}
|
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<tuple>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef unsigned long long int ull;
const int INF=1e9;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=2e5;
int n,q;
vector<vector<int> > G(MAXN);
vector<bool> visited(MAXN,false);
vector<int> cnt(MAXN,0);
void dfs(int u){
visited[u]=true;
for(auto v:G[u]){
if(!visited[v]){
cnt[v]+=cnt[u];
dfs(v);
}
}
return ;
}
int main(){
cin>>n>>q;
for(int i=0;i<n-1;i++){
int a,b;cin>>a>>b;
a--;b--;
G[a].emplace_back(b);
G[b].emplace_back(a);
}
for(int i=0;i<q;i++){
int p,x;cin>>p>>x;
p--;
cnt[p]+=x;
}
dfs(0);
for(int i=0;i<n;i++){
cout<<cnt[i];
if(i!=n-1) cout<<' ';
}
cout<<endl;
return 0;
}
| 0
| 32,781,392
|
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(!(a%3==0 || b%3==0 || (a+b)%3==0)) cout<<"Imp";
else cout<<"P";
cout<<"ossible";
}
|
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int dx[4] = { 0, 0, 1, -1 };
int dy[4] = { 1, -1, 0, 0 };
int main()
{
int H, W;
cin >> H >> W;
vector<string> s(H);
for (int i = 0; i < H; ++i) {
cin >> s[i];
}
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
if (s[i][j] == '#') {
bool ok = false;
for (int k = 0; k < 4; ++k) {
int x = j + dx[k];
int y = i + dy[k];
if (x < 0 || W <= x || y < 0 || H <= y) {
continue;
}
if (s[y][x] == '#') {
ok = true;
}
}
if (!ok) {
cout << "No" << endl;
return 0;
}
}
}
}
cout << "Yes" << endl;
return 0;
}
| 0
| 89,876,809
|
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
int H1, M1, H2, M2, K;
cin >> H1 >> M1 >> H2 >> M2 >> K;
int time = 60 * (H2 - H1) + M2 - M1 - K;
cout << time << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+23;
vector<pii> g[maxn];
int n,s;
int d[maxn];
bool vis[maxn];
priority_queue<pair<int,int>> q;
void dij(int s)
{
memset(d,0x3f,sizeof(d));
memset(vis,false,sizeof(vis));
q.push({0,s});d[s]=0;
while(!q.empty()){
int x=q.top().second;q.pop();
if(vis[x]) continue;
vis[x]=1;
for(pii t:g[x]){
int y=t.first;
int z=t.second;
if(d[y]>d[x]+z){
d[y]=d[x]+z;
q.push({-d[y],y});
}
}
}
}
int main(){
cin>>n;
s=n;
for(int i=1;i<9;i++) g[s].push_back({i,i});
for(int i=1;i<n;i++){
int k=i*10;
for(int j=0;j<10;j++){
g[i].push_back({(k+j)%n,j});
}
}
dij(s);
cout<<d[0];
}
| 0
| 43,900,330
|
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
int main(){
ll n, res=0L;
cin >> n;
vector<ll> p(n);
rep(i, n){
ll x;
cin >> x;
p[x-1] = i;
}
set<ll> st;
st.insert(p[n-1]);
for(int i=n-2;i>=0;i--){
ll now = p[i], disl, disr;
st.insert(now);
auto l = st.lower_bound(now);
if(l!=st.begin()&&l!=++st.begin()){
disl = *(--l) - *(--l);
}else{
if(l!=st.begin()){
disl = *(--l) + 1;
}else{
disl = 0;
}
}
auto r = st.upper_bound(now);
if (r != st.end()) {
disr = *r - *(--r);
} else {
disr = n - *(--r);
}
res += disl * disr * (i+1);
l = st.lower_bound(now);
if (l != st.begin()) {
disl = *l - *(--l);
} else {
disl = *l + 1;
}
r = st.upper_bound(now);
if (r != st.end() && r != --st.end()) {
disr = *(++r) - *(--r);
} else {
if (r != st.end()) {
disr = n - *r;
} else {
disr = 0;
}
}
res += disl * disr * (i+1);
}
cout << res << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
ll n;
cin >> n;
vector<ll> re;
ll ans=0;
for(ll i=1;i*i<=n;++i){
if(n%i==0){
re.push_back(i);
if(i*i!=n){
re.push_back(n/i);
}
}
}
sort(re.begin(),re.end());
for(int i=1;i<re.size();++i){
if(re[i]==2)continue;
if((n/(re[i]-1))==n%(re[i]-1)){
ans+=re[i]-1;
}
}
cout << ans << endl;
return 0;
}
| 0
| 77,596,307
|
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
string S;
cin >> S;
int N = S.size();
vector<char> s1(N), s2(N);
for(int i = 0; i < N; i++){
if(i % 2 == 0) {
s1[i] = '1';
s2[i] = '0';
}
else{
s1[i] = '0';
s2[i] = '1';
}
}
int cnt1 = 0, cnt2 = 0;
for(int i = 0; i < N; i++){
if(S[i] != s1[i]) cnt1++;
if(S[i] != s2[i]) cnt2++;
}
cout << min(cnt1, cnt2) << endl;
}
|
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
string s, p;
cin >> s >> p;
for (int i = 0; i < s.size(); i++) {
rotate(s.begin(), s.begin() + 1, s.end());
if (s.find(p) != -1) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
}
| 0
| 38,597,103
|
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#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 show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}
int main()
{
int n, h;
cin >> n >> h;
vector<P> attack;
rep(i, n){
int a, b;
cin >> a >> b;
attack.emplace_back(a, 1);
attack.emplace_back(b, 0);
}
sort(attack.begin(), attack.end(), greater<P>());
int ans = 0;
int sum = 0;
for(auto at: attack){
if (at.second == 0){
sum += at.first;
ans++;
} else {
int num = ((h-sum)+at.first-1)/at.first;
ans+=num;
break;
}
if (sum >= h){
break;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int N = S.size();
if (N < 26) {
set<char> s;
for (int i = 0; i < N; i++) s.insert(S[i]);
for (char ch = 'a'; ch <= 'z'; ch++) {
if (!s.count(ch)) {
cout << S << ch << endl;
return 0;
}
}
}
vector<char> t;
for (int i = 25; i > 0; i--) {
t.push_back(S[i]);
if (S[i-1] < S[i]) {
sort(t.begin(), t.end());
for (char ch : t) {
if (ch > S[i-1]) {
S[i-1] = ch;
cout << S.substr(0,i) << endl;
return 0;
}
}
}
}
cout << -1 << endl;
}
| 0
| 16,590,769
|
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
long long a,b,c,d,ac,ad,bc,bd;
cin>>a>>b>>c>>d;
ac=a*c;
ad=a*d;
bc=b*c;
bd=b*d;
cout<<(ac>(ad>(bc>bd?bc:bd)?ad:(bc>bd?bc:bd))?ac:(ad>(bc>bd?bc:bd)?ad:(bc>bd?bc:bd)));
return 0;
}
|
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
string gotiusa;
getline(cin,gotiusa);
string temp;
map<string,int>mp;
string ans1;
rep(i,gotiusa.size()){
if(i==gotiusa.size()-1)temp.push_back(gotiusa[i]);
if(gotiusa[i]==' '||i==gotiusa.size()-1){mp[temp]++;if(ans1.size()<temp.size())ans1=temp;temp.clear();continue;}
temp.push_back(gotiusa[i]);
}
pair<string,int>maxi;
maxi.second=0;
for(auto itr=mp.begin();itr!=mp.end();itr++)if(itr->second>maxi.second)maxi=make_pair(itr->first,itr->second);
cout<<maxi.first<<" "<<ans1<<endl;
}
| 0
| 61,435,055
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());
template <typename T>
void printlnVector(T v)
{
rep(i, v.size())
{
cout << v[i] << endl;
}
}
template <typename T>
void printVector(T v)
{
rep(i, v.size())
{
cout << v[i] << " ";
}
cout << endl;
}
int main()
{
int N;
string S;
cin >> N >> S;
vector<int> alphabet_count(26, 0);
long long mod = 1e9 + 7;
long long ans = 0;
rep(i, S.size())
{
long long temp = 1;
rep(j, 26)
{
int c = S[i] - 'a';
if (alphabet_count[j] == 0 || c == j)
continue;
temp *= alphabet_count[j] + 1;
temp %= mod;
}
ans += temp;
ans %= mod;
alphabet_count[S[i] - 'a']++;
}
cout << ans << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int k, s, cnt = 0;
int main()
{
cin >> k;
cin >> s;
for (int i = 0; i <= k; i++){
for (int j = 0; j <= k; j++){
if (((s - i - j) <= k) && (s - i - j) >= 0){
cnt ++;
}
}
}
cout << cnt << "\n";
return 0;
}
| 0
| 72,744,323
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a;
long long b;
long long c;
cin >> a >> b >> c;
long long sum = (b + c);
if (sum > a) {
cout << (sum - a) << endl;
}
else {
cout << "0" << endl;
}
return 0;
}
|
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#pragma GCC optimize(2)
#define mm(i,v) memset(i,v,sizeof i);
#define mp(a, b) make_pair(a, b)
#define pi acos(-1)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int, int > PII;
priority_queue< PII, vector<PII>, greater<PII> > que;
stringstream ssin;
const int N = 3e5 + 5, M = 2e5 + 5, mod = 1e9 + 9, INF = 0x3f3f3f3f;
char s[N];
int k, n, Max;
int a[N];
inline int read(){
char c=getchar();int x=0,f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1; c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
return x*f;
}
int main()
{
cin >> k >> n;
int Max = -1;
for (int i = 1; i <= n; ++i) a[i] = read();
for (int i = 2; i <= n; ++i) {
int pos = a[i] - a[i - 1];
Max = max(Max, pos);
}
Max = max(Max, a[1] + k - a[n]);
cout << k - Max << endl;
return 0;
}
| 0
| 83,256,993
|
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
const int MAXN = 100000 + 10000;
int n;
int a[MAXN], fa[MAXN];
long long b[MAXN];
vector<int> edg[MAXN];
void yes()
{
cout << "YES" << endl;
exit(0);
}
void no()
{
cout << "NO" << endl;
exit(0);
}
void dfs(int x, int father)
{
fa[x] = father;
b[x] = edg[x].size() > 1 ? 2 * a[x] : a[x];
for(int i = 0; i < edg[x].size(); i++)
if(edg[x][i] != fa[x])
{
int y = edg[x][i];
dfs(y, x);
b[x] -= b[y];
}
}
int main()
{
ios::sync_with_stdio(false);
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 1; i <= n - 1; i++)
{
int x, y;
cin >> x >> y;
edg[x].push_back(y), edg[y].push_back(x);
}
dfs(1, 0);
if(b[1] != 0)
no();
for(int i = 1; i <= n; i++)
if(b[i] < 0)
no();
for(int i = 1; i <= n; i++)
if(edg[i].size() > 1)
{
if(b[i] > a[i]) no();
for(int j = 0; j < edg[i].size(); j++)
if(edg[i][j] != fa[i])
if(b[edg[i][j]] > a[i])
no();
}
yes();
return 0;
}
|
#include <bits/stdc++.h>
#define rp(i,n) for(ll i=0; i<n; i++)
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
using G=vector<vector<int>>;
int main(){
ll n,k;
cin >> n >> k;
priority_queue<P> allque;
vector<priority_queue<ll>> eachque(n);
vector<ll> group(n,0);
priority_queue<P,vector<P>,greater<P>> fireque;
rp(i,n){
ll t,d;
cin >> t >> d;
t--;
allque.push(make_pair(d,t));
eachque[t].push(d);
group[t]++;
}
ll dsum=0ll;
ll kindnum=0ll;
vector<int> used(n,0);
vector<ll> topofloser;
rp(i,k){
P p=allque.top(); allque.pop();
fireque.push(p);
dsum += p.first;
if(used[p.second]==0) kindnum++;
used[p.second]++;
}
ll ans=dsum+kindnum*kindnum;
rp(i,n){
if(group[i]>0&&used[i]==0) topofloser.push_back(eachque[i].top());
}
sort(topofloser.begin(),topofloser.end());
reverse(topofloser.begin(),topofloser.end());
ll restkind=topofloser.size();
ll firing=0ll;
for(ll i=0;i<restkind;){
if(fireque.empty()) break;
P p=fireque.top(); fireque.pop();
if(used[p.second]==1)continue;
firing=p.first;
dsum=dsum-firing+topofloser[i];
ans=max(ans,dsum+(kindnum+i+1ll)*(kindnum+i+1ll));
i++;
}
cout << ans << endl;
return 0;
}
| 0
| 57,160,591
|
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
int N, A;
cin >> N >> A;
cout << (N * N) - A << "\n";
}
|
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define MOD 1000000007
#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define sz(x) ((ll)(x).size())
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popc __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
const ll N = 1e5+5, M = 1e6+5, A = 1e7+5, inf = 1e9;
const long long linf = 1LL << 60;
const double er = 1e-10, pi = 3.141592653589793238463;
const ll lx[4] = {0, 1, -1, 0};
const ll ly[4] = {1, 0, 0, -1};
const ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
const ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
struct fast_io{
fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);}
} fast_io_;
void solve(){
ll n; string s; cin >> n >> s;
ll c = 0, d = 0;
rep(i, n)
{
if(s[i] == '(') c++;
else{
if(c > 0) c--;
else{
d++;
}
}
}
if(c > 0){
while(c--) s += ')';
}
if(d > 0){
while(d--) s.insert(s.begin(), '(');
}
cout << s;
}
int main(int argc, char const* argv[])
{
ll t = 1;
while(t--) {
solve();
}
return 0;
}
| 0
| 85,967,653
|
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;
void solve();
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
solve();
}
void solve(){
ll n;cin>>n;
vl a(n);rep(i,n)cin>>a[i];
vp b;
rep(i,n)b.emplace_back(a[i],i);
sort(all(b));
ll ans=0;
rep(i,n)ans+=b[i].second%2!=i%2;
cout<<ans/2<<endl;
}
|
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)
using namespace std;
typedef vector<int> vi;
int n, t;
string s;
vi TIME;
vi csum;
void solve() {
TIME.assign(24*3600, 0);
csum.assign(24*3600+1, 0);
rep(i,n) {
cin >> s;
t = stoi(s.substr(0, 2))*3600 + stoi(s.substr(3, 2))*60 + stoi(s.substr(6,2));
TIME[t] += 1;
cin >> s;
t = stoi(s.substr(0, 2))*3600 + stoi(s.substr(3, 2))*60 + stoi(s.substr(6,2));
TIME[t] -= 1;
}
rep(i, 24*3600) csum[i+1] += csum[i] + TIME[i];
sort(csum.rbegin(), csum.rend());
cout << csum[0] << '\n';
}
signed main(){
while(cin >> n && n!=0) {
solve();
}
return 0;
}
| 0
| 26,764,623
|
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
#define fi first
#define se second
#define mp make_pair
typedef long long LL;
typedef pair<int, int> PII;
const int N = 100010;
int n;
int a[N], b[N];
LL h, w;
LL res[10];
map<PII, bool> hm;
inline int F(int x, int y) {
return hm[mp(x, y)];
}
int main() {
scanf("%lld%lld%d", &h, &w, &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &a[i], &b[i]);
hm[mp(a[i], b[i])] = 1;
}
for (int i = 1; i <= n; ++i) {
int x = a[i], y = b[i];
if (x + 2 <= h) {
if (y + 2 <= w) ++res[F(x, y) + F(x + 1, y) + F(x + 2, y) + F(x, y + 1) + F(x + 1, y + 1) + F(x + 2, y + 1) + F(x, y + 2) + F(x + 1, y + 2) + F(x + 2, y + 2)];
if (1 <= y - 1 && y + 1 <= w) ++res[F(x, y - 1) + F(x + 1, y - 1) + F(x + 2, y - 1) + F(x, y) + F(x + 1, y) + F(x + 2, y) + F(x, y + 1) + F(x + 1, y + 1) + F(x + 2, y + 1)];
if (1 <= y - 2) ++res[F(x, y - 2) + F(x + 1, y - 2) + F(x + 2, y - 2) + F(x, y - 1) + F(x + 1, y - 1) + F(x + 2, y - 1) + F(x, y) + F(x + 1, y) + F(x + 2, y)];
}
if (1 <= x - 1 && x + 1 <= h) {
if (y + 2 <= w) ++res[F(x - 1, y) + F(x, y) + F(x + 1, y) + F(x - 1, y + 1) + F(x, y + 1) + F(x + 1, y + 1) + F(x - 1, y + 2) + F(x, y + 2) + F(x + 1, y + 2)];
if (1 <= y - 1 && y + 1 <= w) ++res[F(x - 1, y - 1) + F(x, y - 1) + F(x + 1, y - 1) + F(x - 1, y) + F(x, y) + F(x + 1, y) + F(x - 1, y + 1) + F(x, y + 1) + F(x + 1, y + 1)];
if (1 <= y - 2) ++res[F(x - 1, y - 2) + F(x, y - 2) + F(x + 1, y - 2) + F(x - 1, y - 1) + F(x, y - 1) + F(x + 1, y - 1) + F(x - 1, y) + F(x, y) + F(x + 1, y)];
}
if (1 <= x - 2) {
if (y + 2 <= w) ++res[F(x - 2, y) + F(x - 1, y) + F(x, y) + F(x - 2, y + 1) + F(x - 1, y + 1) + F(x, y + 1) + F(x - 2, y + 2) + F(x - 1, y + 2) + F(x, y + 2)];
if (1 <= y - 1 && y + 1 <= w) ++res[F(x - 2, y - 1) + F(x - 1, y - 1) + F(x, y - 1) + F(x - 2, y) + F(x - 1, y) + F(x, y) + F(x - 2, y + 1) + F(x - 1, y + 1) + F(x, y + 1)];
if (1 <= y - 2) ++res[F(x - 2, y - 2) + F(x - 1, y - 2) + F(x, y - 2) + F(x - 2, y - 1) + F(x - 1, y - 1) + F(x, y - 1) + F(x - 2, y) + F(x - 1, y) + F(x, y)];
}
}
LL sum = 0;
for (int i = 1; i <= 9; ++i)
sum += (res[i] /= i);
res[0] = (h - 2) * (w - 2) - sum;
for (int i = 0; i <= 9; ++i)
printf("%lld\n", res[i]);
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll solve(vector<ll>w,vector<ll>v,ll n,ll W,ll**dp){
if(n==0 || W==0)
return 0;
if(dp[n][W]!=-1){
return dp[n][W];
}
if(W-w[n-1]<0)
return dp[n][W]=solve(w,v,n-1,W,dp);
return dp[n][W]=max(v[n-1]+solve(w,v,n-1,W-w[n-1],dp),solve(w,v,n-1,W,dp));
}
int main() {
ll n;
cin>>n;
vector<ll>p(n);
for(ll i=0;i<n;i++) cin>>p[i];
ll m=p[0],x=0;
for(ll i=0;i<n;i++){
if(p[i]<=m){
x++;
m=p[i];}
}
cout<<x;
}
| 0
| 66,255
|
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
int main() {
ll n;
cin>>n;
vector<ll>p,q,a;
for(ll i=0;i<n;i++){
a.push_back(i+1);
}
for(ll i=0;i<n;i++){
ll x;
cin>>x;
p.push_back(x);
}
for(ll i=0;i<n;i++){
ll x;
cin>>x;
q.push_back(x);
}
ll A=0;
ll B=0;
ll j=0;
do{
for(ll i=0;i<n;i++){
if(a[i]!=p[i]){
break;
}
if(i==n-1){
A=j;
}
}
for(ll i=0;i<n;i++){
if(a[i]!=q[i]){
break;
}
if(i==n-1){
B=j;
}
}
j++;
}while(next_permutation(a.begin(),a.end()));
cout << abs(A-B);
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a) / gcd(a,b)) * (b)
#define all(x) x.begin(),x.end()
#define ll long long
#define ull unsigned long long
#define VI vector<int>
#define VLL vector<ll>
#define VS vector<string>
#define MPII map<int, int>
#define SET set<int>
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);
ll MOD = 1e9+7;
ll add(ll a, ll b)
{
a+=b; a%=MOD;
if(a<0) a+=MOD;
return a;
}
ll mult(ll a, ll b)
{
if(a>MOD) a%=MOD;
if(b>MOD) b%=MOD;
ll ans=(a*b)%MOD;
if(ans<0) ans+=MOD;
return ans;
}
ll pw(ll a, ll b)
{
ll r=1;
while(b){
if(b&1) r=mult(r,a);
a=mult(a,a);
b>>=1;
}
return r;
}
void solve(){
ll a,b,c;
cin>>a>>b>>c;
ll d=a;
if(a%2==0 && b%2==0 && c==0) cout<<"YES"<<endl;
else{
ll tmp = a%b;
while(a%b!=c){
a+=d;
if(a%b==tmp){cout<<"NO"<<endl;return;}
}
cout<<"YES"<<endl;
}
}
int main(){
fast_io;
ll t, k=0;
t=1;
while(t--){
solve();
}
}
| 0
| 23,372,469
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std ;
using ll = long long ;
using vll = vector<ll> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
int main(){
ll n ; cin >> n ;
vector<pll> a(100100),b(100100) ;
for(int i=0;i<a.size();i++){
a.at(i).first = b.at(i).first = 0 ;
a.at(i).second = b.at(i).second = i ;
}
for(int i=0;i<n;i++){
ll c ; cin >> c ;
if(i&1) b.at(c).first++ ;
else a.at(c).first++ ;
}
sort(all(a)) ; reverse(all(a)) ;
sort(all(b)) ; reverse(all(b)) ;
if(a.at(0).second!=b.at(0).second) cout << n-a.at(0).first-b.at(0).first << endl ;
else cout << min(n-a.at(0).first-b.at(1).first,n-a.at(1).first-b.at(0).first) << endl ;
}
|
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main(){
ll n,m;cin >> n >>m;
vector<pair<pl,ll>> v(m);
rep(i,m){
cin >> v[i].fi.fi >> v[i].fi.se;
v[i].se=i;
}
sort(all(v));
vector<string> s(m);
int k=1;
rep(i,m){
string res;
if(i!=0){
if(v[i].fi.fi!=v[i-1].fi.fi)k=1;
else k++;
}
res+=to_string(k);
while(res.size()<6){
res='0'+res;
}
string form;
int city=v[i].fi.fi;
form+=to_string(city);
while(form.size()<6){
form='0'+form;
}
s[v[i].se]=form+res;
}
rep(i,m)cout << s[i] <<endl;
}
| 0
| 28,725,135
|
#include<iostream>
#include <sstream>
#define SSTR( x ) static_cast< std::ostringstream & >( ( std::ostringstream() << std::dec << x ) ).str()
using namespace std;
int ci(int n, int s, int min, int max, string str) {
if (s < min || n < 1) return 0;
if (n == 1) {
if (s > max) return 0;
return 1;
}
int r = 0;
for (int i=min; i<s && i<=max; i++) {
r += ci(n - 1, s - i, i + 1, max, str + SSTR(i) + " ");
}
return r;
}
int main() {
while (true) {
int n, s;
cin >> n >> s;
if (!n && !s) break;
cout << ci(n, s, 0, 9, "") << endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
long long solve(long long A, long long B){
if(A > B) swap(A, B);
long long L = 0, R = B;
while(R - L > 1){
long long mid = (L+R)/2;
if(mid * mid < A * B) L = mid;
else R = mid;
}
if(L < A) return 2 * L;
if(L * (L+1) < A * B) return 2 * L - 1;
return 2 * L - 2;
}
int main(){
int Q;
while(cin >> Q){
while(Q--){
long long A, B; cin >> A >> B;
cout << solve(A, B) << endl;
}
}
}
| 0
| 34,833,738
|
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
distance(v.begin(), upper_bound(v.begin(), v.end(), x))
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;
ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
const ll INF = 1LL << 50;
ll const mod = 1000000007;
void prvll(vvll& mp) {
printf(" ");
for (size_t j = 0; j < mp[0].size(); j++)
printf("%4lu%c", j, ((j == mp[0].size() - 1) ? '\n' : ' '));
for (size_t i = 0; i < mp.size(); i++) {
printf("%2lu: ", i);
for (size_t j = 0; j < mp[i].size(); j++)
printf("%4lld%c", mp[i][j], ((j == mp[i].size() - 1) ? '\n' : ' '));
}
cout << endl;
}
int main() {
cout << fixed << setprecision(15);
ll h, w;
cin >> h >> w;
vector<string> mp(h);
rep(i, h) cin >> mp[i];
vvll sayu(h, vll(w, 0)), joge(h, vll(w, 0));
rep(i, h) rep(j, w) {
if (mp[i][j] == '#') continue;
ll tmp = 1;
ll psx = j;
ll px = j + 1;
while (px < w && mp[i][px] == '.') {
tmp++;
px++;
}
repLRE(jj, psx, px - 1) sayu[i][jj] = tmp;
j = px-1;
}
rep(j, w) rep(i, h) {
if (mp[i][j] == '#') continue;
ll tmp = 1;
ll psy = i;
ll py = i + 1;
while (py < h && mp[py][j] == '.') {
tmp++;
py++;
}
repLRE(ii, psy, py - 1) joge[ii][j] = tmp;
i = py-1;
}
ll ans = 0;
rep(i, h) rep(j, w) {
ll tmp = sayu[i][j] + joge[i][j] - 1;
chmax(ans, tmp);
}
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define ld long double
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define fo(i,a) for(i=1;i<=a;i++)
#define fa(i,a) for(auto i:a)
#define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++)
#define en cout<<"\n";
#define ull unsigned long long int
#define o(x) cout<<x<<"\n";
#define o1(x) cout<<x<<" ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout<<fixed<<setprecision(n);
#define gcd(a,b) __gcd(a,b)
#define bs binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define all(x) x.begin(),x.end()
#define re return 0;
ll powerm(ll x, unsigned ll y, ll p)
{
ll res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0)
{
if (y & 1)
res = (res*x) % p;
y = y>>1;
x = (x*x) % p;
}
return res;
}
long long lcm(long long a, long long b){
return a * b / gcd(a, b);
}
int main()
{
fast
ll n,s;
cin>>n;
if(n>=400&&n<=599)
{
s=8;
}
else if(n>=600&&n<=799)
{
s=7;
}
else if(n>=800&&n<=999)
{
s=6;
}
else if(n>=1000&&n<=1199)
{
s=5;
}
else if(n>=1200&&n<=1399)
{
s=4;
}
else if(n>=1400&&n<=1599)
{
s=3;
}
else if(n>=1600&&n<=1799)
{
s=2;
}
else
{
s=1;
}
o(s)
re}
| 0
| 36,010,756
|
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
int ans = 1;
for (int i = 0; i < n - 1; ++i) {
ans += s[i] != s[i + 1];
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
int main(){
ll n;
cin >> n;
vll d(26,1e9);
rep(i,n){
string s;
cin>>s;
vll d2(26,0);
rep(j,s.size()){
d2[s[j]-'a']++;
}
rep(j,26){
d[j]=min(d[j],d2[j]);
}
}
rep(i,26){
rep(j,d[i]){
cout << (char)(i+'a');
}
}
cout<<endl;
}
| 0
| 90,360,040
|
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
int n;cin >> n;
int k;cin >> k;
vector<ll> sum(n+1,0),best(n+1,0);
for (int i = 0; i < n; i++) {
int a;cin >> a;
sum[i + 1] = sum[i] + a;
best[i + 1] = best[i] + max(a,0);
}
ll ans = 0;
for (int i = 0; i < n-k+1; i++) {
ans = max(ans,best[i] + best[n] - best[i+k] + max(0LL,sum[i+k] - sum[i]));
}
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i< (n);i++)
#define rep1(i,n) for(int i=1;i<= (n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const static ll MOD = (1e+9)+7;
ll modpow(ll a,ll n){
if(n==0)return 1;
if(n%2==1)return a*modpow(a,n-1)%MOD;
ll t = modpow(a,n/2) % MOD;
return t*t % MOD;
}
int main(){
string s;cin>>s;
vector<char> s_,s__;
rep(i,s.size()){
if(s[i] == 'x')continue;
s_.push_back(s[i]);
s__.push_back(s[i]);
}
reverse(s__.begin(),s__.end());
for(int i = 0;i < s_.size();i++){
if(s_[i]!=s__[i]){
cout<<-1<<endl;
return 0;
}
}
int i = 0,j = 0;
vector<int> lst(s_.size()+1,0);
while(j < s_.size()){
if(s[i] == s_[j]){
i++;j++;
}else{
lst[j]++;
i++;
}
}
if(i < s.size())lst[s_.size()]=s.size()-i;
auto it_b = lst.begin();
auto it_e = lst.end()-1;
ll ans = 0;
while(it_b < it_e){
ans += abs(*it_b - *it_e);
it_b++;it_e--;
}
cout<<ans<<endl;
return 0;
}
| 0
| 6,351,804
|
#include <bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main(void) {
io;
int N,K,X,Y;
cin >> N >> K >> X >> Y;
long long total = 0;
for (int i = 1; i <= N; i++) {
if (i <= K) {
total += X;
} else {
total += Y;
}
}
cout << total << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
#define rep(i, j, n) for(int i = j; i < (int)(n); i++)
const ll MOD = 1000000007;
const ll INFL = (1LL << 60);
const int INFI = (1 << 30);
int main() {
int N, M; cin >> N >> M;
vector<pii> AB(N);
rep(i, 0, N) cin >> AB.at(i).first >> AB.at(i).second;
sort(AB.begin(), AB.end());
priority_queue<int> pq;
int ans = 0, tmp = 0;
rep(i, 1, M + 1) {
rep(j, tmp, N) {
if (AB.at(j).first == i) pq.push(AB.at(j).second);
else if (AB.at(j).first > i) {
tmp = j;
break;
}
}
if (!pq.empty()) {
ans += pq.top();
pq.pop();
}
}
cout << ans << endl;
}
| 0
| 85,172,599
|
#include <bits/stdc++.h>
using namespace std;
long long A, B , C , K ;
void input() {
cin >> A >> B >> C >> K ;
}
int main() {
input() ;
if( A >= K ){
cout << K << endl;
}
else if( A+B >= K ){
cout << A << endl;
}
else{
cout << 2*A + B - K << endl;
}
}
|
#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 SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct UF
{
vector<int> par;
vector<int> sz;
vector<int> rank;
UF(int n):par(n),sz(n),rank(n){
for(int i = 0; i < n; i++){
par[i] = i;sz[i] = 1;rank[i] = 0;
}
}
int find(int x) {
if (par[x] == x) return x;
else return par[x] = find(par[x]);
}
void merge(int x, int y) {
x = find(x); y = find(y);
if (x == y) return;
if(rank[x] < rank[y]){
par[x] = y;
sz[y] += sz[x];
}
else{
par[y] = x;
sz[x] += sz[y];
if(rank[x] == rank[y])rank[x]++;
}
}
bool same(int x, int y) { return find(x) == find(y); }
int size(int n){return sz[find(n)];}
};
bool isdig(char c){
return '0' <= c && c <= '9';
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string s;cin>>s;
ll a;cin>>a;
for(int i=0;i<s.size();i+=a){
cout<<s[i];
}
cout<<endl;
return 0;
}
| 0
| 70,209,983
|
#include <iostream>
using namespace std;
char S[3];
int main(){
cin >> S;
if(S[0] == S[1] && S[1] == S[2]){
cout << "No";
}
else{
cout << "Yes";
}
}
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
int A[5];
int mod=10;
rep(i,5){
cin>>A[i];
if(A[i]%10==0){
continue;
}
else{
mod=min(mod,A[i]%10);
}
}
int sum=0;
rep(i,5){
if(A[i]%10==0){
sum+=A[i];
}
else{
sum+=A[i]+10-A[i]%10;
}
}
sum-=10-mod;
cout<<sum<<endl;
}
| 0
| 14,967,888
|
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;
vector<string> a;
bool cmp(string s, string t) {
if (s.length() != t.length()) return s.length() < t.length();
return s < t;
}
void sol(string s) {
a.push_back(s);
if (s.length() == 10) return;
if (s.back() != '0') {
s += (s.back() - 1);
sol(s);
s.pop_back();
}
s += (s.back());
sol(s);
s.pop_back();
if (s.back() != '9') {
s += (s.back() + 1);
sol(s);
s.pop_back();
}
}
int main() {
ios::sync_with_stdio(false);
string s;
for (int i = 1; i <= 9; i++) s += (i + '0'), sol(s), s.pop_back();
sort(a.begin(), a.end(), cmp);
int k;
cin >> k;
cout << a[k - 1];
}
|
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <string.h>
#include <limits.h>
using namespace std;
typedef long long ll;
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;
}
const vector<int> ms = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const string NA = "$";
vector<int> as;
vector<string> dp;
inline int match_for(int x) {
return ms[x];
}
int cmp(const string &a, const string &b) {
if ((int) a.size() != (int) b.size()) {
return ((int) a.size() > (int) b.size()) ? 1 : -1;
}
return strncmp(a.c_str(), b.c_str(), (int) a.size());
}
string solve(const int N, const vector<int> &as) {
for (int i = 1; i <= N; i++) {
for (auto a : as) {
int req_match = match_for(a);
if (i - req_match >= 0 && dp[i - req_match] != NA) {
string cand = dp[i - req_match] + to_string(a);
if (cmp(cand, dp[i]) > 0) {
dp[i] = move(cand);
}
}
}
}
return dp[N];
}
int main(void) {
int N, M;
cin >> N >> M;
as.resize(M);
for (int i = 0; i < M; i++) {
cin >> as[i];
}
sort(as.begin(), as.end());
reverse(as.begin(), as.end());
dp.resize(N + 1, NA);
dp[0] = "";
string ans = solve(N, as);
cout << ans << endl;
return 0;
}
| 0
| 27,550,934
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int intA;
int intB;
cin >> intA >> intB;
cout << (intA + intB) / 2 + (intA + intB) % 2 << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
int main()
{
int i,j,status=0,n1,n2,n;
string s,t,f1,f2;
cin>>s>>t;
n=s.length();
f1=s;
f2=t;
sort(f1.begin(),f1.end());
sort(f2.begin(),f2.end());
if(f1.compare(f2)!=0)
{
cout<<"No";
return 0;
}
for(i=0;i<n;i++)
{
if(s.compare(t)==0)
{
cout<<"Yes";
return 0;
}
else
{
char a=s[n-1];
for(j=0;j<n-1;j++)
{
s[n-1-j]=s[n-2-j];
}
s[0]=a;
}
}
if(s.compare(t)!=0)
{
cout<<"No";
}
return 0;
}
| 0
| 61,180,440
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
using namespace std;
typedef long long ll;
template <class T> inline bool dpmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool dpmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
void solve(long long N, vector<long long> H) {
ll ans = 0;
ll ans_max = 0;
for (ll i=0; i<N-1; i++) {
if (H[i]>=H[i+1]) {
ans++;
ans_max = max(ans_max, ans);
} else {
ans = 0;
}
}
cout << ans_max << endl;
}
int main() {
long long N;
cin >> N;
vector<long long> H(N);
for (int i = 0; i < N; i++) {
cin >> H[i];
}
solve(N, move(H));
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
int n;
cin >> n;
int h[n];
rep(i,n)cin >> h[i];
int ans = 0;
rep(i,n){
bool can = true;
rep(j,i){
if(h[i]<h[j])can = false;
}
if(can)ans++;
}
cout << ans;
return 0;
}
| 0
| 87,844,459
|
#include <iostream>
using namespace std;
int main(){
string str, cmd, arg2;
int n, arg0, arg1;
cin >> str >> n;
for(int i = 0; i < n; i++){
cin >> cmd >> arg0 >> arg1;
if(cmd == "print"){
cout << str.substr(arg0, arg1-arg0+1) << endl;
continue;
}
if(cmd == "reverse"){
string tmp1 = str.substr(0, arg0);
string rev = str.substr(arg0, arg1-arg0+1);
string tmp2 = str.substr(arg1+1, str.size()-arg1);
char tmp;
int revSize = rev.size();
for(int i = 0; i < revSize/2; i++){
tmp = rev[i];
rev[i] = rev[revSize-i-1];
rev[revSize-i-1] = tmp;
}
str = tmp1 + rev + tmp2;
}
if(cmd == "replace"){
cin >> arg2;
string tmp1 = str.substr(0, arg0);
string tmp2 = str.substr(arg1+1, str.size()-arg1);
str = tmp1 + arg2 + tmp2;
}
}
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007
int main(){
double W, H, x, y;
cin >> W >> H >> x >> y;
if(W/2 - 0.0001 < x && x < W/2 + 0.0001 && H/2 - 0.0001 < y && y < H/2 + 0.0001) {
printf("%.10f", W * H /2);
cout << " " << 1 << endl;
} else {
printf("%.10f", W * H /2);
cout << " " << 0 << endl;
}
}
| 0
| 35,654,492
|
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<60
#define fs first
#define sc second
#define pb push_back
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) (a)<=(i) && (i)<(b)
#define debug(x) cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int,int> P;
typedef vector<vector<P> > Graph;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int w,h;
cin >> w >> h;
vector<int> p(w);
REP(i,w) cin >> p[i];
vector<int> q(h);
REP(i,h) cin >> q[i];
vector<P> edge(h+w);
REP(i,h+w){
if(i < w) edge[i] = P(p[i],1);
else edge[i] = P(q[i-w],2);
}
sort(edge.begin(),edge.end());
int ans = 0;
int w_cnt = w+1, h_cnt = h+1;
REP(i,h+w){
if(edge[i].sc == 1){
ans += h_cnt*edge[i].fs;
w_cnt--;
}
else{
ans += w_cnt*edge[i].fs;
h_cnt--;
}
}
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second
#define B begin()
#define E end()
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std ;
int main()
{
FASTIO
int r , d , x ;
cin >> r >> d >> x ;
for ( int i = 0 ; i < 10 ; i++ )
{
x = r*x - d ;
cout << x << "\n" ;
}
return 0 ;
}
| 0
| 52,683,960
|
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int main(){
int M; cin >> M; ll a[M], b[M]; ll sum = 0; ll digsum = 0;
rep(i, M){
cin >> a[i] >> b[i];
digsum += a[i]*b[i];
sum += b[i];
}
ll ans = (sum - 1) + ((digsum-1)/9);
cout << ans << endl;
}
|
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
using ll = long long;
using namespace std;
int monmo(char ms){
if(ms=='R')return 3;
else if(ms=='G')return 2;
else if(ms=='B')return 1;
else cout<<ms;
return 0;
}
int main() {
int n;
map<string,int> m,m2;
string s,s2,s3,s4,s5;
string rgb="BGR";
ll count=0;
cin>>n>>s;
for(int i=0;i<n;i++){
s2=s[i];
m[s2]++;
}
for(int i=0;i<n-2;i++){
s3=s[i];
m[s3]--;
m2=m;
for(int j=i+1;j<n-1;j++){
int a=5;
s4=s[j];
m2[s4]--;
if(s[i]==s[j]){continue;}
a-=monmo(s[i]);
a-=monmo(s[j]);
s5=rgb[a];
count+=m2[s5];
if(j*2-i<=n)if(s[j*2-i]==rgb[a])count--;
}
}
cout<<count;
}
| 0
| 50,363,236
|
#include <stdio.h>
int main(){
int H1, H2, M1, M2, K;
H1, H2 >= 0 && H1, H2 <= 23;
M1, M2 >= 0 && M1, M2 <= 60;
int HM1, HM2;
scanf("%d %d %d %d %d", &H1, &M1, &H2, &M2, &K);
HM1 = H1 * 60 + M1;
HM2 = H2 * 60 + M2;
printf("%d", HM2 - HM1 - K);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const ll MOD2=998244353;
const double PI=acos(-1);
const ll INF=1e18;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
vl memo(100001,-1);
ll dfs(ll x){
if(memo[x]!=-1){
return memo[x];
}
if(x==0){
return 0;
}
if(x==1||x==6||x==9){
memo[x]=1;
return 1;
}
ll a=6,b=9;
ll t=x;
while(x>=a){
t=min(dfs(x-a)+1,t);
a*=6;
}
while(x>=b){
t=min(dfs(x-b)+1,t);
b*=9;
}
memo[x]=t;
return t;
}
int main() {
ll n;
cin >> n;
ll x=dfs(n);
cout << x << endl;
}
| 0
| 93,535,252
|
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 10e9+7;
ll mod2 = 998244353;
int main(){
vector<ll> ans;
while (true){
int n,k;cin>>n>>k;
if (n==0 && k==0){
break;
}
vector<ll> a(n);
rep(i,0,n) cin>>a[i];
vector<ll> b(n+1,0);
rep(i,0,n) b[i+1] = b[i] + a[i];
ll num = 0;
rep(i,0,n-k){
num = max(num,b[i+k]-b[i]);
}
ans.push_back(num);
}
for(auto x:ans){
cout<<x<<endl;
}
}
|
#include <bits/stdc++.h>
#define H_MAX 1000
#define W_MAX 1000
#define WALL '#'
#define START 's'
#define GOAL 'g'
constexpr int INF = 1e9;
constexpr int MOVE_COST = 1;
constexpr int WALL_COST = 1e8;
int MAX_WALL = 2;
int MAX_COST = (MAX_WALL + 1) * WALL_COST - 1;
using std::make_pair;
using std::pair;
using std::queue;
using std::vector;
using Grid = vector<std::string>;
using YX = pair<int, int>;
const vector<YX> MOVES = {
make_pair(-1, 0),
make_pair(1, 0),
make_pair(0, -1),
make_pair(0, 1)
};
vector<vector<int>> d(H_MAX + 2, vector<int>(W_MAX + 2, INF));
using BfsRes = pair<int, queue<YX>>;
BfsRes bfs(int h, int w, Grid m, queue<YX> starts, YX goal, int c = 0) {
queue<YX> next;
queue<YX> que;
while (!starts.empty()) {
YX s = starts.front();
starts.pop();
que.push(s);
if (d.at(s.first).at(s.second) == INF) {
d.at(s.first).at(s.second) = c;
}
}
while (!que.empty()) {
YX prev = que.front();
que.pop();
int py = prev.first;
int px = prev.second;
for (YX dm : MOVES) {
int y = py + dm.first;
int x = px + dm.second;
YX curr = make_pair(y, x);
if (y < 0 || x < 0 || y >= h || x >= w) continue;
if (m.at(y).at(x) == WALL) {
if (MAX_WALL == 0) continue;
int wc = d.at(py).at(px) + WALL_COST;
if (wc > MAX_COST) continue;
if (d.at(y).at(x) <= wc) continue;
d.at(y).at(x) = wc;
next.push(curr);
continue;
}
if (curr == goal) {
if (d.at(py).at(px) + MOVE_COST <= MAX_COST)
return make_pair(d.at(py).at(px) + MOVE_COST, next);
else
return make_pair(-1, next);
}
if (d.at(y).at(x) != INF) continue;
d.at(y).at(x) = d.at(py).at(px) + MOVE_COST;
que.push(curr);
}
}
if (next.empty()) return make_pair(-1, next);
return bfs(h, w, m, next, goal);
}
std::istream &operator>>(std::istream &is, YX &p) {
is >> p.first >> p.second;
return is;
}
void agc033_a();
void arc005_c();
void abc007_c();
int main(void) {
agc033_a();
return 0;
}
void agc033_a() {
int h, w;
std::cin >> h >> w;
Grid A(h);
for (int i = 0; i < h; ++i) std::cin >> A.at(i);
queue<YX> blacks;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (A.at(i).at(j) == WALL) blacks.push(make_pair(i, j));
}
}
bfs(h, w, A, blacks, make_pair(h + 2, w + 2), 0);
int ans = 0;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (d.at(i).at(j) != INF) ans = std::max(ans, d.at(i).at(j));
}
}
std::cout << ans << std::endl;
return;
}
void arc005_c() {
int h, w;
std::cin >> h >> w;
Grid grid(h);
for (int i = 0; i < h; ++i) {
std::cin >> grid.at(i);
}
queue<YX> starts;
YX goal;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (grid.at(i).at(j) == START) starts.push(make_pair(i, j));
if (grid.at(i).at(j) == GOAL) goal = make_pair(i, j);
}
}
std::cout << ((bfs(h, w, grid, starts, goal).first != -1) ? "YES\n"
: "NO\n");
return;
}
void abc007_c() {
MAX_WALL = 0;
int R, C;
std::cin >> R >> C;
YX s, g;
std::cin >> s;
std::cin >> g;
s.first--;
s.second--;
g.first--;
g.second--;
queue<YX> starts;
starts.push(s);
Grid c(R);
for (int i = 0; i < R; ++i) {
std::cin >> c.at(i);
}
std::cout << bfs(R, C, c, starts, g).first << std::endl;
return;
}
| 0
| 43,603,770
|
#include<bits/stdc++.h>
using namespace std;
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using ll = long long;
using PAIR = pair<int, int>;
using Graph = vector<vector<int>>;
const double pi=acos(-1.0);
#define debug cout << "line : " << __LINE__ << " debug" << endl
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
map<long long, long long> prime_factorize(long long n) {
map<long long, long long> res;
for (long long p = 2; p * p <= n; ++p) {
while (n % p == 0) { ++res[p]; n /= p; }
}
if (n != 1) res[n] = 1;
return res;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n; cin >> n;
int ans = 0;
for(int i=1; i<=n; i++){
if(i%2==0) continue;
map<ll,ll> mp = prime_factorize(i);
int cnt = 1;
for(auto x: mp){
cnt *= (x.second + 1);
}
if(cnt==8) ans++;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
const ll MOD=1000000007;
ll N,M;
const int MAX_V=100000;
vector <int> G[MAX_V];
int color[MAX_V];
bool dfs(int v,int c){
color[v] = c;
bool t=true;
rep(i, 0, G[v].size()){
if (color[G[v][i]] == c) t=false;
if (color[G[v][i]] == 0 && !dfs(G[v][i], -c)) t=false;
}
return t;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin>>N>>M;
rep(i,0,M){
int u,v;
cin>>u>>v;
u--;
v--;
G[u].pb(v);
G[v].pb(u);
}
ll s=0,t=0,k=0;
rep(i,0,N){
if(color[i]==0){
if(sz(G[i])==0) k++;
else{
if(dfs(i,1)){
s++;
t++;
}
else{
t++;
}
}
}
}
cout <<N*N-(N-k)*(N-k)+t*t+s*s<<"\n";
}
| 0
| 11,052,450
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<cmath>
#include<string>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define eps (double)1e-9
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pdbs;
void __print(int x) {cerr << x;}
void __print(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
int n , bulbs;
map<int,set<int>> m;
vector<int> decision;
int calc(int idx ,vector<int> state){
if(idx == n){
int cnt = 0;
for(int i =0 ; i < (int)state.size(); i++){
if(state[i]%2 == decision[i]){
cnt += 1;
}
}
if(cnt == bulbs){
return 1;
}
else{
return 0;
}
}
int ans = 0;
vector<int> new_state = state;
for(auto it : m[idx]){
new_state[it] += 1;
}
ans += calc(idx+1, state);
ans += calc(idx+1 , new_state);
return ans;
}
signed main() {
ios::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
cin >> n >> bulbs;
for(int i =0 ; i < bulbs; i++){
int k;
cin >> k;
for(int j =0 ; j< k ; j++){
int temp;
cin >> temp;
m[temp-1].insert(i);
}
}
for(int i = 0; i <bulbs ;i++){
decision.pb(-1);
cin>>decision[i];
}
vector<int> state(bulbs ,0);
int ans = calc(0 ,state);
cout<<ans;
return 0;
}
|
#include <iostream>
using namespace std;
int main(void){
int n;
char c[36][3],d[36][3];
cin>>n;
int i,j;
for(i=0;i<n;i++){
cin>>c[i];
for(j=0;j<3;j++)d[i][j]=c[i][j];
}
char swap[3];
for(i=0;i<n;i++){
for(j=n-1;j>i;j--){
if(c[j-1][1]>c[j][1]){
swap[0]=c[j][0];
c[j][0]=c[j-1][0];
c[j-1][0]=swap[0];
swap[1]=c[j][1];
c[j][1]=c[j-1][1];
c[j-1][1]=swap[1];
}
}
}
for(i=0;i<n-1;i++){
cout<<c[i]<<" ";
}
cout<<c[n-1]<<endl;
cout<<"Stable"<<endl;
char min;
for(i=0;i<n-1;i++){
min=i;
for(j=i;j<n;j++){
if(d[min][1]>d[j][1]){
min=j;
}
}
if(min!=i){
swap[0]=d[min][0];
d[min][0]=d[i][0];
d[i][0]=swap[0];
swap[1]=d[min][1];
d[min][1]=d[i][1];
d[i][1]=swap[1];
}
}
bool isstable=1;
for(i=0;i<n;i++){
if(c[i][0]!=d[i][0]){
isstable=0;
}
}
for(i=0;i<n-1;i++){
cout<<d[i]<<" ";
}
cout<<d[n-1]<<endl;
if(isstable)cout<<"Stable"<<endl;
else cout<<"Not stable"<<endl;
}
| 0
| 17,467,111
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.