solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k, i, j, ans;
cin >> n >> k;
vector<int> a(n + 1);
int count = 0;
for (i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] < 0) count++;
}
k = k - count;
if (k < 0)
cout... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << end... | 0 |
#include <iostream>
#include <string>
int main()
{
int n, a, b;
std::string s;
std::cin >> n >> a >> b >> s;
int cnt = 0;
int bcnt = 0;
const int max = a + b;
for (char c : s) {
if (c == 'b') bcnt++;
if (cnt >= max || c == 'c' || (c == 'b' && bcnt > b)) {
std::cout << "No\n";
}
else {
std::cout ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
string str1, str2;
cin >> str1 >> str2;
reverse(str1.begin(), str1.end());
reverse(str2.begin(), str2.end());
int first = str2.find("1");
int second = str... | 1 |
#include <bits/stdc++.h>
constexpr int a[] = {1, 0, 0, 0, 1, 0, 1, 0, 2, 1, 1, 2, 0, 1, 0, 0};
int f(int n) { return a[n % 16] + (n >= 16 ? f(n >> 4) : 0); }
int main(void) {
int n;
std::cin >> n;
std::cout << f(n);
return 0;
}
| 2 |
#include<iostream>
#include<vector>
#include<algorithm>
typedef long long ll;
using namespace std;
ll gcd(ll a,ll b){
if(b==0)return a;
return gcd(b, a%b);
}
ll lcm(ll a,ll b){
return a*b/gcd(a,b);
}
ll lcm_n(vector<ll> num){
ll l=num[0];
for(int i=0;i<num.size();i++)l=lcm(l,num[i]);
return l;
}
ll fu... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a, b;
cin >> n >> a >> b;
if (a * b >= 6 * n) {
cout << a * b << endl;
cout << a << " " << b << endl;
} else {
long long ret = (1LL << 60);
long long x, y;
for (long long i = 1; i <= 100000; i++) {
long long j = 6 ... | 2 |
#include <bits/stdc++.h>
constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
t... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[1005];
vector<pair<int, int> > vec[1005];
int f[3][3];
long long go[125][125][32];
long long one[125][125][3];
long long dp[125][2];
long long way[1005][4];
long long DP[1005][4];
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
cin >> m;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
long long x;
long long y;
};
int n;
Point p[1000];
vector<int> adj[1000];
map<long long, vector<pair<long long, int>>> samex, samey;
int vis[1000];
int comp[1000];
vector<array<long long, 5>> hor, vert;
void dfs(int u, int c) {
vis[u] = 1;
comp[u] = c... | 6 |
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
typedef struct{
int from,to,cost;
}edge;
int main(void){
int i,n_node=1,n_2=1,L;
cin >> L;
vector<edge> v;
while(2*n_2<=L&&n_node<20){
v.push_back({n_node,n_node+1,n_2});
n_2*=2;
n_node++;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int k;
vector<pair<int, int>> es[200006];
vector<int> ns(200006, 0);
pair<long long, bool> solveG(int idx, int fa) {
long long res = 0;
bool odd = true;
ns[idx] = 1;
for (int i = 0; i < es[idx].size(); ++i) {
if (es[idx][i].first == fa) continue;
auto tRes =... | 3 |
#include <bits/stdc++.h>
using namespace std;
double dp[201][256][300][2];
int main() {
int x, k, p, i, j, l, r;
double ans = 0;
scanf("%d %d %d", &x, &k, &p);
if (x & (1 << 8)) {
int y = x >> 8, c = 0;
while (y) {
if (y % 2 == 0) break;
y >>= 1;
c++;
}
dp[0][x % 256][c][1] = 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long in;
cin >> in;
long long c = 0;
bool flag = true;
long long out = 1;
while (in > 1 && flag) {
flag = false;
for (long long i = 2; i <= in / i; i++)
if (in % i == 0) {
flag = true;
if (c < 2) out *= i;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
void no() {
cout << -1 << "\n";
exit(0);
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
map<long long, long long> col;
cin >> col[4];
cin >> col[7];
cin >> col[47];
cin >> col[74];
if (abs(col[47] - col[74]) > 1) {
no();
}
string an = ""... | 2 |
#include <bits/stdc++.h>
using namespace std;
void print(vector<int> &v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i] << " ";
}
cout << endl;
}
void div(int a, vector<int> &v) {
int ans = 0;
for (int i = 1; i <= sqrt(a); i++) {
if (a % i == 0) {
if (a / i == i) {
ans++;
} el... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline long long gi() {
long long _x = 0, _tmp = 1;
char _tc = getchar();
while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
if (_tc == '-') _tc = getchar(), _tmp = -1;
while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
r... | 4 |
#include <bits/stdc++.h>
using namespace std;
int m, n, q[int(1e6)], a[int(1e6)];
int main() {
scanf("%i", &m);
int mn = 1e9;
for (int i = 0; i < m; i++) {
scanf("%i", &q[i]);
if (q[i] < mn) mn = q[i];
}
scanf("%i", &n);
for (int i = 0; i < n; i++) scanf("%i", &a[i]);
sort(a, a + n);
long long i... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const long long int MAX = 2e18;
int main() {
int t;
cin >> t;
while (t--) {
int ar[10], cnt = 0;
cin >> ar[0] >> ar[1] >> ar[2];
if (ar[0]) {
ar[0]--;
cnt++;
}
if (ar[1]) {
ar[1]-... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MAXN = 35, MAXK = 50 + 10;
int t, dp[MAXN][MAXN][MAXK];
vector<int> res;
void make_dp() {
for (int i = 0; i < MAXN; i++)
for (int j = 0; j < MAXN; j++)
for (int k = 0; k < MAXK; k++) dp[i][j][k] = INF;
dp[0][0][0] = 0;
dp[1][1]... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000;
int a[MAXN];
int d[MAXN];
void solve() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
d[0] = a[0];
d[1] = a[1];
for (int i = 2; i < n; ++i) d[i] = min(a[i], max(d[i - 1], d[i - 2]));
cout << min(d[n - 1], d[0]) << endl;
}
in... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const long long OO = 1LL << 61;
const long long MOD = 2147483647;
const int maxn = 5005;
long long dp[maxn][3];
struct EDGE {
int v, next;
long long w;
} E[maxn << 1];
int head[maxn], tol;
int U[maxn], V[maxn];
long long C[maxn];
void add_edge... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
long long dp[2][maxn][maxn];
char str[maxn][maxn];
const int mod = 1000000007;
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%s", str[i]);
if (n + m <= 3) {
printf("%d\n", str[0][0] == str[n - 1][m - 1]);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long ii, r, need, pl, ans, d[200000], x, y, i, j, n;
int ch(int x, int y) {
if (x > 0 && x <= n && y > 0 && y <= n)
return 1;
else
return 0;
}
int main() {
cin >> n;
for ((i) = (0); i < (100001); ++i) d[i] = -1;
for ((j) = (0); j < (n); ++j) {
cin... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, r;
cin >> m >> r;
double d0, d1, ans = 0;
d0 = 2 * r;
d1 = r * (2 + sqrt(2));
ans += m * d0 + (2 * m - 2) * d1;
for (int i = 1; i <= m; i++) {
double j = i - 2;
if (j > 0) ans += j * (j + 1) * r + j * 2 * sqrt(2) * r;
}
for (int... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,M;
cin >> N >> M;
int a,b,c,d;
a=1; b=N;
for (int i=0;i<M;i++){
cin >> c >> d;
if (a<c) a=c;
if (d<b) b=d;
}
cout << max(0,b-a+1) << endl;
} | 0 |
#include <bits/stdc++.h>
int main() {
char a[102][102];
int n, m, i, j, d = 0;
scanf("%d %d", &n, &m);
for (i = 0; i < n; i++) {
getchar();
scanf("%s", a[i]);
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (j > 0 && a[i][j] != a[i][j - 1]) {
d++;
break;
}
... | 1 |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void fn0(int n, string a, string b)
{
string s;
int j = 0, k = 0;
while (true) {
if (k >= 2 * n && j >= 2 * n) break;
if (k >= 2 * n) s += a[j++];
else if (j >= 2 * n) s += b[k++];
else if (a[j] == b[k]) s ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long x, y;
long long gcd(long long a, long long b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
int main() {
cin >> x >> y;
if (gcd(x, y) != 1) {
puts("Impossible");
return 0;
}
vector<pair<long long, char> > ans;
while (x > 1 || y > ... | 3 |
#include <bits/stdc++.h>
using namespace std;
using l2 = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
int n, m, k;
cin >> n >> m >> k;
char s[n][m];
vector<int> ans(m, 0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> s[i][j];
if (s[i][j] == 'L') {
... | 2 |
#include <iostream>
using namespace std;
int main(){
string x,y;
cin>>x>>y;
cout<<y<<x;
return 0;}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6;
const long long MOD = 1610612741;
const long long mod = 1e9 + 7;
const long long INF = 1e15 + 5040;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
vector<pair<int, string>> reg[MAXN];
int main() {
int n, m;
cin >> n >> m;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n, x, y;
cin >> n >> x >> y;
string s;
cin >> s;
long long zero = 0, one = 0;
for (long long i = 0; i < n; i++) {
if (s[i] == '1')
one++;
else
zero++;
}
string ans = "... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline bool check(int x) {
for (; x; x /= 10)
if (x % 10 != 4 && x % 10 != 7) return 0;
return 1;
}
const int maxn = 100100;
int head[maxn], nxt[maxn << 1], ver[maxn << 1], val[maxn << 1], tot;
inline void addedge(int a, int b, int c) {
nxt[++tot] = head[a];
ver... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double n, m, a, b, s, t = 500.0;
int num;
cin >> n >> m >> num;
for (int i = 0; i < num; ++i) {
cin >> a >> b >> s;
if (sqrt((a - n) * (a - n) + (b - m) * (b - m)) / s < t)
t = sqrt((a - n) * (a - n) + (b - m) * (b - m)) / s;
}
printf(... | 1 |
#include <bits/stdc++.h>
using namespace std;
double x[2005], y[2005];
double d[2005];
double eps = 1e-11;
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
x[i] = 1.0 * a * c / (a * a + b * b);
y[i] = 1.0 * b * c / (a * a + b * b);
}
... | 4 |
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
map<vector<int>, int>perm_mp;
int main() {
{
vector<int>perms(4);
std::iota(perms.begin(), perms.end(), 0);
int k = 0;
do {
perm_mp[per... | 0 |
#include <bits/stdc++.h>
using namespace std;
long double pie = 3.141592653589793238462643383279;
long long mod = 1e9 + 7;
long long dx[] = {-1, 1, 0, 0};
long long dy[] = {0, 0, 1, -1};
long long fact[2000005];
long long infact[2000005];
long long inv(long long a) {
long long y = mod - 2;
long long r = 1;
while ... | 4 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
struct edge { int to, cap, rev; };
vector<edge>X[100009]; bool used[100009]; string S[200]; int H, W;
class Max_Flow {
public:
void add_edge(int u, int v, int w) {
X[u].push_back(edge{ v, w, (int)X[v].size() });
X[v... | 0 |
#include <bits/stdc++.h>
using namespace std;
void amn(long long &x, long long y) { x = min(x, y); }
void amx(long long &x, long long y) { x = max(x, y); }
const long long INF = 1e18;
const long long N = 3e5 + 5;
long long n, q;
string s;
long long pref[N][2][2];
void solve() {
cin >> n >> q;
cin >> s;
s = "#" + ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> vet(n);
for (int &x : vet) cin >> x;
int l = 0, r = n - 1;
while (l < n - 1 && vet[l] < vet[l + 1]) l++;
while (r >= 1 && vet[r] < vet[r - 1]) r--;
l++;
r = n - r;
if (l % 2 || r % 2)
cout << "Alice";
else
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int n;
cin >> n;
vector<double> v;
while (n--) {
int x, y, vv;
cin >> x >> y >> vv;
long long d = (x - a) * (x - a) + (y - b) * (y - b);
double dd = sqrt(d * 1.000000);
dd /= (vv * 1.00);
v.push_back(... | 1 |
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
int N;
double X[10009], Y[10009];
double getscore(double px, double py) {
double maxn = 0;
for (int i = 1; i <= N; i++) {
double dst = sqrt((px -... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r = 0, c = 0;
string str;
cin >> str;
if (str.length() > 2) {
for (int i = 0; i < str.length() - 2; i++) {
if (str[i] == 'Q') {
for (int j = i + 1; j < str.length() - 1; j++) {
if (str[j] == 'A') r++;
if (r > 0)... | 1 |
#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> m;
vector<long long int> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, k;
cin >> n >> k;
string a;
cin >> a;
long long int max = 0;
string ss = "abcdefghijklmnopqrstuvwxy... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, flag = 0;
cin >> n;
map<string, int> z;
stack<string> e;
stack<string> c;
string s;
for (int i = n - 1; i >= 0; i--) {
cin >> s;
c.push(s);
z[c.top()] = 1;
}
while (!c.empty()) {
if (z[c.top()] == 1) {
cout << c.to... | 2 |
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
cin>>s;
int n=s.size();
for(int i=n-2;i>=0;i--)
{
if((i+1)&1)continue;
int x=(i+1)/2;
if(s.substr(0,x)==s.substr(x,x))
{
printf("%d\n",x*2);
return 0;
}
}
printf("0\n");
} | 0 |
#include <bits/stdc++.h>
using namespace std;
void init_ios() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
const int N = 5 * (int)1e5 + 10;
int n, res[N], ktory;
string s[N];
set<int> se, pom;
int main() {
init_ios();
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> s[i];
res[i] = s[i].size();
if ... | 4 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <casser... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, e, nn;
deque<int> d;
cin >> n;
e = n;
for (int i = 0; i < n; i++) cin >> x, d.push_back(x);
for (int i = 0; i < n - 1; i++)
if (d[i] > d[i + 1]) e = i + 1;
nn = n - e;
while (nn) {
d.push_front(d.back());
d.pop_back();
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long b, d, s, mx, mi = (1LL << 60), r;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> b >> d >> s;
mx = max(b, mx);
mx = max(d, mx);
mx = max(s, mx);
mi = min(b, mi);
mi = min(d, mi);
mi = min(s, mi);
r += max((mx - 1) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, d;
cin >> n >> d;
long long x[n + 1];
for (int i = 0; i < n; i++) cin >> x[i];
x[n] = 2e18;
long long i = 0, j = 0;
long long ans = 0;
while (i < n - 1) {
long long p = abs(x[j] - x[i]);
if (p <= d) {
j++;
} else {
... | 1 |
#include <stdio.h>
int root[1000][1000];
bool right[1000][1000];
int main()
{
int h, w, n, tmp, ax, ay;
while(true) {
scanf("%d%d%d", &h, &w, &n);
if(h == 0 && w == 0 && n == 0) break;
for(int y = 0; y < h; ++y) {
for(int x = 0; x < w; ++x) {
scanf("%d", &tmp);
right[x][y] = tmp;
root[x][y] = ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
float H,W,N;
cin>>H>>W>>N;
cout<<min(ceil(N/H),ceil(N/W));
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n = 0, mov[500500], sum[500500], dp[500500];
bool able[500500];
int main()
{
#define pud(x, y) min((x), abs((x) - (y)))
scanf("%d%d", &n, sum);
for(int i = 1; i <= n; i++)
{
scanf("%d", mov + i);
sum[i] = pud(sum[i - 1], mov[i]);
}
dp[n + 1] = 1;
for(int i = ... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, i, k, a;
int main() {
cin >> n;
k = sqrt(2 * n);
if (k * (k + 1) / 2 == n) a = k;
if (k * (k + 1) / 2 < n) {
a = n - k * (k + 1) / 2;
} else if (k * (k + 1) / 2 > n) {
a = n - k * (k - 1) / 2;
}
cout << a;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n;
cin >> n;
long long arr[n];
for (long long i = 0; i < n; i++) cin >> arr[i];
if (n == 1) {
cout << -1;
return 0;
}
sort(arr, arr + n);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
int ans = 0;
for (int i = 1; i <= t; i++) {
for (int j = i + 1; j <= t; j++) {
int k = j + 1;
if (i + j == k && k <= t) {
ans += i * j * k;
}
}
}
cout << ans << endl;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
int m[5];
int w[5];
int x[5] = {50, 100, 150, 200, 250};
int h1, h2;
for (int32_t i = 0; i < 5; ++i) {
cin >> m[i];
}
for (int32_t i = 0; i < 5; ++i) {
cin >> w[i];
}
cin >> h1 >> h2;
int res = 0;
for (int32_t ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105, M = 1e5 + 7, INF = 0x3f3f3f3f;
int ans = 0, head[N], to[M], nxt[M], val[M], fw[M], cnt = 1, S, T, d[N],
q[N * N * N], pre[N], du[N];
bool v[N];
inline void link(int a, int b, int l, int r, int c) {
to[++cnt] = b, nxt[cnt] = head[a], head[a] = cnt, f... | 4 |
#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 main()
{
string s,t;
cin>>s>>t;
int ans=0;
for(int i=0;i<s.length();i++)
ans+=(s[i]!=t[i]);
cout<<ans;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long k, d, t, cycle, subTimes;
unsigned long long ans = 0, velocity, t2;
scanf("%lld%lld%lld", &k, &d, &t);
k *= 2;
d *= 2;
t *= 2;
subTimes = (k + d - 1) / d;
cycle = subTimes * d;
velocity = k + (cycle - k) / 2;
ans = t / vel... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a, b, p1, p2, g1, g2, now1, now2, k;
string s;
int main() {
cin >> a >> b;
p1 = 0;
p2 = 0;
cin >> s;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == 'U') ++p2;
if (s[i] == 'D') --p2;
if (s[i] == 'L') --p1;
if (s[i] == 'R') ++p1;
}
bool bb ... | 1 |
// 2019/11/20 Tazoe
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 1000000001; // ありえない大きい値
int main()
{
int N, M;
cin >> N >> M;
int D[1001];
for(int i=1; i<=N; i++){
cin >> D[i];
}
int C[1001];
for(int j=1; j<=M; j++){
cin >> C[j];
}
int DP[1001][1001];
for(int i=1;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int M = 998244353;
const int N = 2e5 + 1;
int f[N];
int power(int a, int b)
{
int c = 1;
while (b)
{
if (b & 1)
c = (long long)c * a % M;
b >>= 1;
a = (long long)a * a % M;
}
return c;
}
int choose(int a, int b... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, ans, p_cnt[300005], m_cnt[300005], sp = 0;
char in_s[300005];
int main() {
long long i, j, x, y, len;
scanf("%lld", &n);
for (i = 0; i < n; i++) {
scanf("%s", in_s);
len = strlen(in_s);
x = 0;
for (j = 0; j < len; j++) x += ((in_s[j] - ... | 3 |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cer... | 4 |
#include <bits/stdc++.h>
using namespace std;
set<int> s;
int n, x, y;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> x;
int ans = 0;
while (n--) {
cin >> y;
s.insert(y);
}
for (int i = 0; i < x; ++i)
if (s.count(i) == 0) ans++;
if (s.count(x) == 1) ans++;
cou... | 1 |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
if (n % 2 == 0) {
puts("-1");
return 0;
}
for (int i = 0; i < n; i++) printf("%d ", i);
puts("");
for (int i = 0; i < n; i++) printf("%d ", i);
puts("");
for (int i = 0; i < n; i++) printf("%d ", (i + i) % n);
puts("");
return 0... | 3 |
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf =... | 0 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
string s;
cin >> s;
long long x = 0, y = 0;
for (long long i = 0; i < n; i++) {
if (s[i] == '0')
x++;
else
y++;
}
cout << n - min(x, y) * 2;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int mod = 1073741824;
char isprime[1000001];
memset(isprime, 'y', sizeof(isprime));
vector<int> primes;
for (int i = 2; i < 1000001; i++) {
if (isprime[i] == 'n') continue;
int j = 2 * i;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[11][111], b[11][111], c[11][111];
char str[111];
struct node {
int n, v;
node(int _n, int _v) { n = _n, v = _v; }
node() {}
friend bool operator<(node a, node b) { return a.v > b.v; }
} p[111];
int main() {
int n, m, cc;
while (~scanf("%d%d%d", &n, &m, &cc... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, q, a[N];
namespace Seg {
int si[N << 2];
long double sm[N << 2], mt[N << 2], st[N << 2];
inline void pushup(int v) { sm[v] = sm[v << 1] + sm[v << 1 | 1]; }
inline void pushdown(int v) {
if (mt[v] != 1) {
sm[v] *= mt[v];
if (si[v] > 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5050;
int a[maxn];
struct node {
int l, r;
};
node fuck[maxn];
int have[maxn], tmp[maxn], prefix[maxn];
int main() {
int i, j, k, n, m;
while (scanf("%d%d", &n, &m) != EOF) {
memset(have, 0, sizeof(have));
for (i = 1; i <= m; i++) {
scan... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct Data {
int value;
bool nonzero;
bool use;
Data() {
value = 0;
nonzero = false;
use = false;
}
friend bool operator<(Data a, Data b) { return (a.value > b.value); }
};
vector<Data> Latin_set(10);
void process(string& str) {
int size = str.siz... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
bool check(vector<long long> a) {
for (long long i = 0; i < a.size(); i++) {
if (a[i] == i + 1) {
return false;
}
}
return true;
}
long long coun(long long n) {... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, a[55], sum = 0, p;
long long f[55][55], c[55][55];
double ans = 0.0;
void Build() {
for (int i = 0; i <= n; i++) {
c[i][0] = 1;
for (int j = 1; j <= i; j++) c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
}
}
void Solve(int pos) {
for (int i = 0; i < 55; ++i)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1100;
const long long inf = (int)1e18;
const int infi = (int)1e9 + 1000;
int n, m, L, s, t;
vector<pair<int, int> > graf[MAXN];
vector<pair<pair<int, int>, int> > edgesN, edgesV;
void load() {
scanf("%d%d%d%d%d", &n, &m, &L, &s, &t);
for (int i = 0; i <... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 5;
bool m[maxn];
int a[maxn];
int main() {
int n, sum = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
}
if (n == sum) {
cout << "YES" << endl;
return 0;
}
bool flag = false;
for (int t = 3; t ... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline 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;
}
inline void write(int x... | 6 |
#include <bits/stdc++.h>
using ul = std::uint32_t;
using ull = std::uint64_t;
using li = std::int32_t;
using ll = std::int64_t;
ul n, m;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cin >> n >> m;
if (n > m) {
std::swap(n, m);
}
if (n == 1) {
std::cout << m / 6 * 6 + (m % 6 >... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x;
cin >> n >> m;
map<int, int> mp;
for (int i = 0; i < n; i++) {
cin >> x;
x %= m;
mp[x]++;
}
int res = mp[0];
if (res % 2) res--;
for (int i = 1; i < m; i++) {
if (i != m - i) {
res += min(mp[i], mp[m - i]) * 2;... | 2 |
#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f, Inf = 0x7fffffff;
const long long INF = 0x7fffffffffffffff;
const double eps = 1e-10;
unsigned int seed = 19260817;
const unsigned int _RAND_MAX_ = 4294967295u;
__inline__ __attribute__((always_inline)) unsigned int Rand() {
return seed = seed * 998244353u + 100000... | 2 |
#include <bits/stdc++.h>
using namespace std;
double f[1001][1001];
int a[1001];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) f[i][j] = (a[i] > a[j]);
while (m--) {
int u, v;
cin >> u >> v;
u--;
v--;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long double ep = 0.000001;
const long double PI = 3.14159265359;
const int mod = 998244353;
const int MAX = 300009;
long long n, m, l[4], x, y, t, vis[MAX], po[2 * MAX], color[MAX], visited[MAX],
po3[2 * MAX];
vector<long long> d[MAX];
bool check(long long v) {
... | 4 |
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
using n... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1000000007;
int n;
ll ar[200005];
ll ans = 1e18;
set<ll> mem;
void tes(ll x) {
if (x == 1) return;
if (mem.count(x)) return;
mem.insert(x);
ll tp = 0;
for (int i = (0); i < (n); i++) {
if (ar[i]... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mo = 998244853;
const long long INF = 0x3f3f3f3f;
template <typename _T>
void read(_T &x) {
_T f = 1;
x = 0;
char s = getchar();
while (s > '9' || s < '0') {
if (s == '-') f = -1;
s = getchar();
}
while (s >= '0' && s <= '9') {
x = (x... | 5 |
#include <bits/stdc++.h>
using std::max;
using std::min;
using std::vector;
const int MAXN = 1e6 + 20;
namespace MyIO {
const int MAXB = 1 << 10;
char gbuf[MAXB], *ps = gbuf, *pt = gbuf;
char pbuf[MAXB + 1], *pp = pbuf;
struct Flusher {
~Flusher() { fwrite(pbuf, 1, pp - pbuf, stdout); }
} flusher;
inline char Getchar... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10010, oo = 100000000, T = 1000;
int i, j, k, n, m, x, now, last, fg, Time;
int a[N], b[N];
int main() {
now = -oo;
last = 12211221;
while (now <= oo) {
printf("0 %d %d\n", now, now);
fflush(stdout);
scanf("%d", &x);
if (!x) {
if (n... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC target(sse, sse2, sse3, ssse3, sse4, popcnt, tune = native)
#pragma GCC optimize( ... | 5 |
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int INF = 1e9;
int solve(vector< vector< pair<int, int> > > &G, int C){
int n = G.size();
vector< vector<int> > D(n, vector<int>(n, INF));
priority_queue< pair<int, int> > wait;
wait.emplace(0, 0);
D[0][0] = 0;
while(!wait.em... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
bool f(long long a, long long b) {
if (!a) return 0;
return !(f(b % a, a) && (b / a % (a + 1) % 2));
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
long long a, b;
scanf("%I64d%I64d", &a, &b);
if (a > b) a ^= b, b ^= a, a ^=... | 3 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> mapa;
vector<int> ls;
int tot, ne;
int a[300100], b[300100], c[300100];
int qtd[2 * 300100];
void func(int p, int v) {
qtd[p] += v;
if (v > 0 && qtd[p] == 0) ne++;
if (v < 0 && qtd[p] == -1) ne--;
}
int main() {
int n, m, p;
scanf("%d %d %d", &n, &m,... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int totalCups = 0;
int totalMedals = 0;
for (int i = 0; i < 3; i++) {
int x;
cin >> x;
totalCups += x;
}
for (int i = 0; i < 3; i++) {
int x;
cin >> x;
totalMedals += x;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
string s;
cin >> s >> k;
vector<string> c(k * s.length());
for(int i = 0; i < s.length(); i++)
for(int j = 0; j < k; j++)
c.at(k * i + j) = s.substr(i, j + 1);
sort(c.begin(), c.end());
unique(c.begin(), c.end());
cout << c.at(... | 0 |
#include <bits/stdc++.h>
using namespace std;
using db = double;
using ll = long long;
using ull = unsigned long long;
using pII = pair<int, int>;
using pLL = pair<ll, ll>;
constexpr int mod = 1e9 + 7;
template <class T1, class T2>
inline void chadd(T1 &x, T2 y, int Mod = mod) {
x += y;
while (x >= Mod) x -= Mod;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int cost;
double amount;
cin >> cost;
string s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
}
int counter = 1;
double sum = 1.0;
for (int i = n - 2; i >= 0; i--) {
if (s[i] == "halfplus") {
counter++;
... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.