solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long v[11];
signed main() {
long long n, m;
cin >> n >> m;
for (long long i = (0); i < (n); i++) {
long long a;
cin >> a;
v[a - 1]++;
}
long long ans = 0;
for (long long i = (0); i < (m); i++) {
for (long long j = (i + 1); j < (m); j++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005] = {0};
int b[100005] = {0};
int c[100005] = {0};
int main() {
int n, m, l;
cin >> n >> m >> l;
for (int i = 1; i <= n; ++i) cin >> a[i];
a[0] = l + 1;
a[n + 1] = l + 1;
int j = 1;
bool b;
int sum = 0;
while (j <= n) {
while (j <= n ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int a[10005], b[10005], n, c;
long long int check(long long int x) {
long long int s = 0, i;
for (i = 1; i <= n; i++) {
s += (a[i] * x / b[i]);
}
return s;
}
int main() {
long long int i, s = 0;
cin >> n >> c;
for (i = 1; i <= n; i++) {
cin >... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int P = 10, N = 1e5 + 10;
int inverse(int a, int m) {
if (a <= 1) return a;
int ans = (1 - (long long int)inverse(m % a, a) * m) / a;
if (ans < 0) ans += m;
return ans;
}
int fact[N], ifact[N], pot[N][P];
vector<int> primes(int n) {
vector<int> ans;
for (i... | 4 |
#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c[12][12],i,j,k,m,d=0;
scanf("%d%d",&a,&b);
for(i=0;i<a;i++)
{
for(j=0;j<b;j++)
scanf("%d",&c[i][j]);
}
for(k=0;k<a-1;k++)
{
for(i=k+1;i<a;i++)
{ float t=0;
for(j=0;j<b;j++)
{t=t+(c[k][j]-c[i][j])*(c[k][j]-c[i][j]);
}
m=sqrt(t);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void get_int(T &x) {
char t = getchar();
bool neg = false;
x = 0;
for (; (t > '9' || t < '0') && t != '-'; t = getchar())
;
if (t == '-') neg = true, t = getchar();
for (; t <= '9' && t >= '0'; t = getchar()) x = x * 10 + t - '0';
if ... | 5 |
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 6e8;
const int maxn = 1005;
int dp[5][maxn][maxn];
char g[maxn][maxn];
int n, m;
int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
void bfs(char ch) {
queue<pair<int, int> > q;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (g[i][j]... | 3 |
#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, long long> m;
long long a[1000000], b[1000000];
long long n, q, x, y, z, ans = 0;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
ans += a[i];
}
cin >> q;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long d[1048576];
int main() {
int N, M, B;
cin >> N >> M >> B;
int x[100], k[100], g[100] = {};
for (int i = 0; i < N; ++i) {
int u, v, w;
cin >> u >> v >> w;
x[i] = u;
k[i] = v;
for (int j = 0; j < w; ++j) {
int y;
cin >> y;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class L>
bool smax(T& x, L y) {
return x < y ? (x = y, 1) : 0;
}
template <class T, class L>
bool smin(T& x, L y) {
return y < x ? (x = y, 1) : 0;
}
const int maxn = 2e5 + 17;
int n;
set<string> s;
string p[maxn];
int main() {
ios::sync_with_stdio(0... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool isNumber(string s) {
for (int i = 0; i < s.length(); i++)
if (isdigit(s[i]) == false) return false;
return true;
}
int main() {
int n;
cin >> n;
vector<int> res;
vector<string> temp = {"ABSINTH", "BEER", "BRANDY", "CHAMPAGNE",
... | 1 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k;
cin>>n>>k;
int a[n+2];
for(int i=0;i<n;i++)cin>>a[i];
vector<int>v(n,INT_MAX);
v[0]=0;
for(int i=0;i<=n-1;i++){
for(int j=i+1;j<=i+k;j++){
if(j<n)v[j]=min(v[j],v[i]+abs(a[j]-a[i]));
}
}
cout<<v[n-1]<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(vector<T> &arr) {
for (auto &x : arr) cin >> x;
}
template <class T>
void read2d(vector<vector<T>> &arr) {
for (auto &x : arr)
for (auto &y : x) cin >> y;
}
template <class T>
void write(const T &t) {
cout << t << "\n";
}
template <cla... | 3 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string S,T;
int mn;
int main(){
cin>>S>>T;
mn=0xE869120;
for(int i=0;i<=S.size()-T.size();i++){
int c=0;
for(int j=0;j<T.size();j++){
if(S[i+j]!=T[j])c++;
}
mn=min(mn,c);
}
cout<<mn<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename _T>
inline void read(_T &f) {
f = 0;
_T fu = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') {
fu = -1;
}
c = getchar();
}
while (c >= '0' && c <= '9') {
f = (f << 3) + (f << 1) + (c & 15);
c = getch... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
os << "[";
for (auto vv : V) os << vv << ",";
return os << "]";
}... | 5 |
#include <bits/stdc++.h>
const int INF = 1e9 + 7;
void setmin(int& x, int y) { x = std::min(x, y); }
int dp[1005][1005];
std::string S, T;
void recover(int i, int j) {
if (i == 0 && j == 0) return;
if (i > 0 && dp[i][j] == dp[i - 1][j] + 1) {
recover(i - 1, j);
printf("DELETE %d\n", j + 1);
} else if (j >... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = acos(-1.0);
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie();
int n;
while (cin >> n) {
int cnt = 0;
for (int i = 1; i < n; i++)
if ((n... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int N, A, B;
ll v[51];
ll comb[51][51];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(10);
cin >> N >> A >> B;
for (int i = 0; i < N; i++) {
cin >> v[i];
}
fo... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, pcnt, mcnt, ans, cnt[100001], pri[100001], mob[100001];
bool isnp[100001];
inline long long read() {
long long q = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = 0;
ch = getchar();
}
while (isdigit(ch)) q = (q << 3) +... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int sz = 5002;
long long s;
int n, m, i1, i2, i3;
pair<int, int> a[sz * 2], b[sz * 2];
long long cmp(pair<int, int> a, pair<int, int> b, pair<int, int> o) {
return (1ll * o.first - 1ll * a.first) * (1ll * b.second - 1ll * a.second) -
(1ll * o.second - 1ll *... | 5 |
#include <bits/stdc++.h>
using namespace std;
int m, n, j, k, l, i, o, p, __t, A[200000], where[200000];
char ch;
void read(int &a) {
for (ch = getchar(); (ch < '0' || ch > '9') && (ch != '-'); ch = getchar())
;
if (ch == '-')
a = 0, __t = -1;
else
a = ch - '0', __t = 1;
for (ch = getchar(); ch >= '... | 4 |
#include <bits/stdc++.h>
using namespace std;
const string rk[13] = {"2", "3", "4", "5", "6", "7", "8",
"9", "T", "J", "Q", "K", "A"};
const string st[4] = {"C", "D", "H", "S"};
int n, m, x1, x2, y11, y2;
bool j11, j2;
string s[55][55];
set<string> ss;
bool ok(int a, int b, string x, string y) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
const int INF = 1e9 + 5;
const int BUCKET = 333;
vector<int> bucket[2][BUCKET];
vector<long long> sum[2][BUCKET];
int mins[2][BUCKET];
int val[2][N + 5];
bool udah[N + 5];
set<int> active[2];
int q;
void update_bucket(int id) {
for (int i = 0; i < 2; i+... | 6 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
int gcd(int a, int b) {
while (b) {
a %= b;
if (b > a) swap(a, b);
}
return a;
}
int main() {
string s, ans;
int k;
cin >> k >> s;
map<char, int> m;
for (int i = 0; i < s.length(); i++) m[s[i]]++;
for (map... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 100005, M = 1e9 + 7;
long long n, k, ans[N], sum[N], phi[N], b[N / 10], flag[N];
inline long long ksm(long long x, long long y) {
long long ans = 1;
for (; y; y >>= 1, x = x * x % M)
if (y & 1) (ans *= x) %= M;
return ans;
}
signed main() {
s... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2005;
const long long MOD = 1e9 + 7;
long long fact[N], invfact[N];
long long pow(long long a, long long b, long long m) {
long long ans = 1;
a = a % MOD;
while (b) {
if (b & 1) ans = (ans * a) % m;
b /= 2;
a = (a * a) % m;
}
return... | 1 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long int n, k;
cin >> n >> k;
long long int* arr = new long long int[n];
for (long long int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
long long int l = 0;
for (long long int i = 0; i < n; i++) {
cout << 1 << " " << arr[i] <... | 3 |
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int rev(int k, int siz) {
int sol = 0, log = log2(siz) - 1;
while (k) {
if (k & 1) sol += 1 << log;
k >>= 1;
log--;
}
return sol;
}
complex<double> aux[2100000];
void FFT(complex<double> *coef, bool inverse) {
int siz = 1 << ((int)ceil(log2(n + ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long oo = 1LL << 50;
long long N, M, K, ans;
namespace solution {
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
void exgcd(long long a, long long b, long long &x, long long &y) {
if (!b) {
x = 1;
y = 0;
return;
}
exg... | 3 |
#include <bits/stdc++.h>
template<typename T> T gcd(T a, T b) {
if(!b) return a;
return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
return a * b / gcd(a, b);
}
template<typename T> void chmin(T& a, T b) { a = (a > b) ? b : a; }
template<typename T> void chmax(T& a, T b) { a = (a < b) ? b : a; ... | 0 |
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,int>pi;
const int N=100005;
int n,m,st[N],tp,col[N],cnum[2];
vector<int>e[N],vcr;
bool ist[N],in[N],vis[N];
void dfs(int x,int fa){
if(ist[x]){
int p=tp;
while(st[p]!=x)vcr... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, a, b, c, p, q, m, n, l, ma, mi, d, e, z, mai, mii;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a >> b >> c >> p >> q;
if (p > q) {
ma = p;
mi = q;
mai = b;
mii = c;
} else {
ma = q;
mi = p;
... | 1 |
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
const int N=20;
typedef long long ll;
map<pair<int,int>,int>sum;
ll ans[N];
int n,m;
void Paint(int x,int y){
for(int i=-1;i<=1;i++)
for(int j=-1;j<=1;j++){
int a=x+i,b=y+j;
if(a<=1||b<=1||a>=n|... | 0 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> xmap, ymap;
map<pair<int, int>, int> xymap;
int main() {
int n, x, y;
long long ans = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d%d", &x, &y);
xmap[x]++;
ymap[y]++;
xymap[make_pair(x, y)]++;
}
for (auto v : xmap) {
... | 3 |
#include <bits/stdc++.h>
#define loop for(;;)
typedef std::vector<long> LI;
template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
te... | 0 |
#include<iostream>
using namespace std;
const int r[6][6] = {
{-1, 2, 4, 1, 3,-1},
{ 3,-1, 0, 5,-1, 2},
{ 1, 5,-1,-1, 0, 4},
{ 4, 0,-1,-1, 5, 1},
{ 2,-1, 5, 0,-1, 3},
{-1, 3, 1, 4, 2,-1}
};
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int d[6];
cin>>d[0]>>d[1]>>d[2]>>d[3]>>d[4]>>d[5];
int n, t, ... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> a(300100);
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long int n;
cin >> n;
vector<long long int> b(n + 1);
for (long long int i = 1; i <= n; i++) {
cin >> b[i];
}
for (long long int i = 1; i <= n; i++) {
bitset<... | 2 |
#include <bits/stdc++.h>
using namespace std;
void setup() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout.precision(15);
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(con... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > V[100003];
pair<long long, long long> all[100003][2];
long long cnt[100003][2];
map<int, int> FT;
int TF[100003], N;
int add(int i) {
if (FT.find(i) != FT.end()) return FT[i];
int sz = FT.size();
FT[i] = sz;
TF[sz] = i;
return s... | 5 |
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>
using namespace std;
typedef long long LL;
typedef vector<int... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
if (n <= 1) return false;
for (int i = 2; i < n; i++)
if (n % i == 0) return false;
return true;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long q;
cin >> q;
while (q--) {
long long n, p, k, su = -1;
cin >... | 2 |
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
string s[8];
r(i,8)cin>>s[i];
cout<<90<<endl;
r(i,8){r(j,8)cout<<s[7-j][i];cout<<endl;}
cout<<180<<endl;
r(i,8){r(j,8)cout<<s[7-i][7-j];cout<<endl;}
cout<<270<<endl;
r(i,8){r(j,8)cout<<s[j][7-i];cout<<endl;}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
void f(int set[][501],int m)
{
int ss[100][100]={};
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
ss[j][(m-1)-i]=set[i][j];
}
}
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
set[i][j]=ss[i][j];
}
}
}
void log(int set[][501],int m,int setcount)
{... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<long long> input;
vector<long long> output;
pair<long long, long long> getRoots(long long lowestRoot,
long long squareDiff) {
long long l = lowestRoot;
long long r = l + 1;
while (l < r && r <= 10LL * 10000LL * 1000LL)... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool inside(int x, int y, int x1, int x2, int y1, int y2) {
return x1 < x && x < x2 && y1 < y && y < y2;
}
int main() {
ios_base::sync_with_stdio(false);
int n;
int x1[5], y1[5], x2[5], y2[5];
cin >> n;
for (int _n(n), i(0); i < _n; i++) cin >> x1[i] >> y1[i] >>... | 1 |
#include <cstdio>
#include <algorithm>
int read()
{
int x=0,f=1;
char ch=getchar();
while((ch<'0')||(ch>'9'))
{
if(ch=='-')
{
f=-f;
}
ch=getchar();
}
while((ch>='0')&&(ch<='9'))
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
const int maxn=50... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int NMax = 203;
int n, m, first_i, first_j;
char x[NMax][NMax];
int main() {
cin >> n >> m;
cin.get();
for (int i = 0; i < n; ++i) {
cin.getline(x[i], NMax);
}
int ok = 0;
for (int i = 0; i < n && ok == 0; ++i) {
for (int j = 0; j < m && ok == 0; +... | 1 |
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll pans(int lv, ll n) {
if (lv == 0) {
return 1;
}
if (n == 1) {
return 0;
}
ll all = (1LL << (lv + 2)) - 3;
ll mid = all / 2 + 1;
if (n < mid) {
return pans(lv - 1, n - 1);
} else if (n == mid) {
return pans(lv - 1, n - 2) + 1;
} else... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, i, j, y, s, ans;
char a[2222][2222];
int l[2222][2222], r[2222][2222], u[2222][2222], d[2222][2222];
pair<pair<int, int>, int> st[2444444];
bool f[2222][2222];
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> m;
for (i = 1; i <= n; i++)
for (... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void pv(T a, T b) {
for (T i = a; i != b; ++i) cout << *i << " ";
cout << endl;
}
template <class T>
void pvp(T a, T b) {
for (T i = a; i != b; ++i)
cout << "(" << i->first << ", " << i->second << ") ";
cout << endl;
}
void chmin(int &t, int f... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
int n, k;
scanf("%d%d", &(n), &(k));
static int p[int(1e6 + 5)];
for (int i = 1, __R = n; i <= __R; i++) scanf("%d", &(p[i]));
static bool vis[int(1e6 + 5)];
static int cnt[int(1e6 + 5)];
int ev = 0, od = 0;
f... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
vector<int> E[N];
map<pair<int, int>, int> h;
int dp[N];
int ans[N], p[N];
int cnt = 0;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n - 1; i++) {
ans[i] = -1;
int first, second;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000;
long long f[maxn + 10][2][2], g[maxn + 10][2][2];
long long a[maxn + 10], b[maxn + 10], c[maxn + 10], d[maxn + 10], x[maxn + 10];
int n, s, e;
inline void upd(long long &x, long long y) {
if (y < x) x = y;
}
int main() {
scanf("%d%d%d", &n, &s, &e... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
template <typename S, typename T>
inline bool Min(S &a, const T &b) {
return a > b ? a = b, true : false;
}
template <typename S, typename T>
inline bool Max(S &a, const T &b) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long n;
cin >> n;
vector<long> arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
long ans = 0;
int a = 1;
long cnt = 0, a1;
vector<long> b;
for (int i = 0; i < n; i++) {
if (i == 0) {
a1 = arr[i];
cnt++;
} else... | 3 |
#include <bits/stdc++.h>
using namespace std;
float mod = pow(10, -10);
int32_t main() {
long long T = 1;
for (long long t = 1; t <= T; t++) {
long long i, ans = 0, a, b, c, q, j = 0, k = 0, n, g, x = 0, y = 0;
string s, ss, s1;
cin >> n;
long long A[15] = {4, 7, 44, 47, 74, 77, 444,
... | 1 |
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream &operator << (ostream &os, const vector<T> &);
template<size_t n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, const tuple<T...> &){}
template<size_t n, class...T> t... | 0 |
#include <bits/stdc++.h>
using namespace std;
namespace IO {
inline bool read() { return true; }
template <class T1, class... T2>
bool read(T1 &a, T2 &...rest) {
return (cin >> a) ? read(rest...) : 0;
}
template <class... T>
bool read(char *a, T &...rest) {
return (cin >> a) ? read(rest...) : 0;
}
template <class..... | 6 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
bool indicator;
vector<vector<int>> arr;
vector<int> price;
vector<bool> visited;
int dfs(int x) {
if (visited[x]) {
if (pr... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long sumc[2000], sumr[2000];
int c[2000][2000];
pair<long long, int> solve(int n, long long *sum) {
long long bestv = 1LL << 60;
int bestp = -1;
long long cur, len;
for (int i = 0; i <= n; i++) {
cur = 0;
for (int j = 0; j < n; j++) {
if (j < i)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long long x[1010] = {0}, y[1010] = {0}, t[1010] = {0};
scanf("%d", &n);
double p[1010] = {0}, f[1010] = {0};
for (int i = 0; i < n; i++)
scanf("%I64d %I64d %I64d %lf", &x[i], &y[i], &t[i], &p[i]);
for (int i = 0; i < n; i++) {
for (in... | 3 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define int long long
signed main() {
int n; string s; cin >> n >> s;
int cnt = 0, ans = n;
for (int i = 1; i < n; i++)if (s[i] == 'E')cnt++;
ans = min(ans, cnt);
for (int i = 1; i < n; i++) {
if (s[i - 1] == 'W')cn... | 0 |
#include<bits/stdc++.h>
using namespace std;
int a, b, c, d;
int main(){
cin>>a>>b>>c>>d;
if(abs(c-a)<=d) return cout<<"Yes", 0;
if(abs(a-b)<=d && abs(b-c)<=d) cout<<"Yes";
else cout<<"No";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
template <typename first, typename second>
ostream &operator<<(ostream &os, const pair<first, second> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
int arr[n];
for (auto &i : arr) cin >> i;
sort(arr, arr + n);
vector<int> prime;
int cnt[5001]{};
for (int i = 2; i <= 5000; ++i) {
int tmp = i;
for (int j = 2; j *... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 20;
const int MOD = 1000000007;
struct Sum {
Sum(int up = 0, int down = 0) : up(up), down(down) {}
int up, down;
};
int N, sol, add = 1;
int used_up[MaxN], up[MaxN];
int used_down[MaxN], down[MaxN];
int k = 0;
vector<Sum> P[MaxN];
void back() {
++k;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long K, KK;
long long get_sum(long long x) {
if (x == 0) return K * (K + 1) / 2;
long long low_sum = get_sum(x / K);
long long changed_group = (low_sum - 1) % KK / K;
long long changed_index = (low_sum - 1) % KK % K;
long long group = x % K;
long long sum =... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j;
cin >> n;
string a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
int c = 0;
for (i = 1; i < n - 1; i++) {
for (j = 1; j < n - 1; j++) {
int p = i + 1;
int q = j + 1;
int r = i - 1;
int l = j - 1;
i... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int r, g, b;
cin >> r >> g >> b;
int outer = max(r, max(g, b));
int sum = r + b + g;
int inner = sum - outer;
int flag = 0;
if (inner >= outer - 1) {
flag = 1;
}
cout << (flag ? "Yes... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long comb[1005][1005];
int main() {
ios::sync_with_stdio(false);
for (int i = 0; i < 1004; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0 || i == j)
comb[i][j] = 1;
else
comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % 10000000... | 3 |
#include <bits/stdc++.h>
using namespace std;
int A[100005], x[100005], ans[100005];
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
return x * f;
}
inline bool check(int k, int N) {
... | 2 |
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,popcnt,abm,fma,mmx,avx,tune=native")
using namespace std;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) *... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long M = (long long)1e9 + 7;
int Int() {
int x;
scanf("%d", &x);
return x;
}
long long Long() {
long long x;
scanf("%lld", &x);
return x;
}
void Char(char *ch) { scanf("%s", ch); }
template <typename t>
inline t abs(t a) {
if ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int lef[505][505];
int up[505][505], maxm[505][505];
int lefsum[505][505], upsum[505][505];
long long a[100005];
set<int> s[4005];
vector<int> adj[4005];
int rec[4005];
int main() {
int ans = 1000000009;
int n, m;
scanf("%d", &n);
scanf("%d", &m);
int a, b;
int ... | 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
int a, b, c, d, n, m, k;
int beg[5], cur[5];
int solve(int f) {
int t = (m - f * 4) / 3;
memmove(cur, beg, sizeof(cur));
int ans = 0;
int d = min(f, cur[4]);
f -= d;
cur[4] -= d;
d = min(f, min(cur[3], cur[1]));
f -... | 3 |
#include <bits/stdc++.h>
using namespace std;
void rs(int &x) { scanf("%d", &x); }
void rsl(long long &x) { scanf("%I64d", &x); }
void rsd(double &x) { scanf("%lf", &x); }
void rss(char *str) { scanf("%s", str); }
void ws(int &x) { printf("%d ", x); }
void wsl(long long &x) { printf("%I64d ", x); }
void wsd(double &x) ... | 2 |
#include <iostream>
using namespace std;
int main()
{
long long A, B, C;
cin >> A >> B >> C;
cout << (A ^ B ^ C) << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int DEBUG = 0;
char dp3[301][301][301];
char dp2[301][301];
void pr2(int i, int j) {
if (DEBUG) {
printf("dp2[%d][%d]= %c\n", i, j, dp2[i][j]);
}
}
void pr3(int i, int j, int k) {
if (DEBUG) {
printf("dp3[%d][%d][%d]= %c\n", i, j, k, dp3[i][j][k]);
}
}
int m... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5;
pair<int, int> o[maxn];
char s[10], d[maxn];
int pos[maxn], p[maxn], f[maxn];
long long t, sh;
int n, m, i, j, x, y;
int main() {
scanf("%d%d%I64d", &n, &m, &t);
for (i = 1; i <= n; i++) {
scanf("%d%s", &pos[i], s + 1);
d[i] = s[1];
pos... | 6 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
//グラフの隣接リスト
map<int, vector<int>> g;
//頂点の入次数を管理
int h[100010];
int main()
{
//頂点数v、辺の数e
int v, e;
cin >> v >> e;
REP(i, e) {
... | 0 |
#include<bits/stdc++.h>
using namespace std;
int a,b,c,n,ANS[200005],Ne[400005],E[400005],HEAD[200005],m,s,e;
void ADD(int s,int e) {
Ne[++b]=HEAD[s],HEAD[s]=b,E[b]=e;
}
void DFS(int i,int f) {
for(int z=HEAD[i]; z; z=Ne[z])
if(E[z]!=f)ANS[E[z]]+=ANS[i],DFS(E[z],i);
}
int main() {
scanf("%d %d",&n,&m);
for(int i=... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
bool vis[55];
vector<long long> base;
long long ans[55];
const long long mod = 998244353LL;
void dfs(long long mask, int d) {
if (d == base.size()) {
++ans[__builtin_popcountll(mask)];
return;
}
dfs(mask, d + 1);
dfs(mask ^ base[d], d + 1);
}
void ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int small_lucks[10] = {0, 0, 0, 0, 0, 1, 1, 1, 2, 2};
const int small_unlucks[10] = {0, 1, 2, 3, 4, 4, 5, 6, 6, 7};
const int is_luck[10] = {0, 0, 0, 0, 1, 0, 0, 1, 0, 0};
int lucks[10];
long long count(int sum, int number) {
if (number =... | 2 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
int n; cin>>n;
vector<string> s(n);
vector<pair<int,int>> a(n);
rep(i,n){
cin>>s[i];
int cnt=0,mn=0;
for(char c:s[i]){
if(c=='(') cnt++;
else cnt--, mn=min(mn,cnt);
}
a[i]={cnt,min(0,cnt)-mn};
... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cerr << v << " ";
return *this;
}
} dbg;
enum OP { ADD, MUL };
struct info {
vector<long long> a;
vector<OP> ops;
vector<int> start;
vector<int> end;
};
info parse(string s) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class D>
class Range {
class It {
public:
It(const T& v, const T& e, const D& s) : v_(v), e_(e), s_(s), end_(false) {
checkEnd();
};
T operator*() { return v_; }
It& operator++() {
if (!end_) {
v_ += s_;
ch... | 4 |
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(void) {
int num, i, j, a, ok, ans = 0;
cin >> num;
vector<string> s(num);
for (i = 0; i < num; i++) {
cin >> s[i];
s[i] += s[i];
}
for (a = 0; a < num; a++) {
ok = true;
for (i = 0; i < num; i++) {
for (j = i + 1; j... | 0 |
#include <bits/stdc++.h>
int main() {
char ch, map[10][10];
long i, x;
while (gets(map[0])) {
if (map[0][0] == '\0') break;
gets(map[1]);
gets(map[2]);
if (map[0][1] == '>') {
ch = map[0][0];
map[0][0] = map[0][2];
map[0][2] = ch;
}
if (map[1][1] == '>') {
ch = map[... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, r;
while (cin >> a >> b >> r) {
if (2 * r > a || 2 * r > b)
printf("Second\n");
else
printf("First\n");
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5, mod = 1e9 + 9;
struct node {
long long x, y;
} a[N];
long long n, deg[N], influ[N][6], ans[N], seq[N], res;
bool vis[N], isin[N];
map<pair<long long, long long>, long long> e;
priority_queue<long long, vector<long long>, less<long long> > st1;... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 111;
const int inf = 1 << 30;
int id[N][N], h[N][N], nxt[N];
double f[N];
int main() {
for (int i = 1; i <= 10; i++)
for (int j = 1; j <= 10; j++) {
cin >> h[i][j];
}
int now = 0;
for (int i = 1; i <= 10; i++) {
if (i % 2 == 1)
fo... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
long long a[maxn], res[maxn], vis[maxn];
int n;
long long dfs(int pre, int now, int next) {
if (next == n) return 0;
int res = now - pre;
if (abs(res + now - a[next]) > 1) return 0x3f3f3f3f;
return dfs(now, now + res, next + 1) + abs(res +... | 4 |
#include <bits/stdc++.h>
using namespace std;
int vis[4005];
int main() {
int k, x, div;
int num1, num2;
while (cin >> x >> k) {
int min = 0, max = 0;
memset(vis, 0, sizeof(vis));
for (int i = 0; i < k; i++) {
cin >> div;
if (div == 2) {
cin >> num2;
vis[num2] = 1;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long x = 0, y = 0, n, b, cur, pre;
void get(long long &a) {
scanf("%lld%lld", &n, &b);
for (int i = 0; i < n; ++i) scanf("%lld", &pre), a = a * b + pre;
}
int main() {
get(x), get(y);
printf("%c\n", (x > y) ? '>' : ((x == y) ? '=' : '<'));
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c, j, i, l;
cin >> n;
int x[n][2];
for (i = 0; i < n; i++) {
for (j = 0; j < 2; j++) {
cin >> x[i][j];
}
}
c = 0;
for (l = 0; l < n; l++) {
for (i = 0; i < n; i++) {
if (x[l][0] == x[i][1]) c += 1;
}
}
cout <... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void PV(T x) {
for (__typeof__((x).begin()) i = (x).begin(); i != (x).end(); ++i)
cout << *i << " ";
cout << endl;
}
template <typename S, typename T>
ostream &operator<<(ostream &os, pair<S, T> p) {
return os << "(" << p.first << "," << p.secon... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.