solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
int main(){
int N;
while(cin>>N,N){
vector<int> card[2];
int ba=-1,in;
bool latte[201]={},turn=0;
for(int i=0;i<N;i++){
cin>>in;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int y, k, n;
cin >> y >> k >> n;
bool ok = false;
for (int i = k; i <= n; i += k) {
if (i - y > 0) {
cout << i - y << " ";
ok = true;
}
}
if (!ok) cout << -1 << endl;
return 0;
}
| 1 |
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
x = 0;
int f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
x *= f;
}
int tb[1010], t[1010], a[1010], usd[1010], n, opt[1010], o... | 5 |
#include<bits/stdc++.h>
#define ll long long
#define N 10010
#define mr make_pair
using namespace std;
int n,g[2],s[N][2],w[N];
string dp[N];
char ch[N];
string que(int l,int r){string no="";for (int i=0;i<2*n;i++)if (w[i]>=l&&w[i]<=r)no+=ch[i];return no;}
int main(){
cin>>n;
for (int i=0;i<2*n;i++){
ch[i]=getchar(... | 0 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
struct DSU {
int nbElem;
vector<int> repr, weight;
DSU(int ta) : nbElem(ta), repr(ta), weight(ta, 1) {
iota(repr.begin(), repr.end(), 0);
}
int get(int x) {
if (repr[x] != x) repr[x] = get(repr[x]);
return repr[x];
}
boo... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n, m, h;
cin >> n >> m >> h;
long long int a[m + 1];
long long int tot = 0;
for (long long int i = 1; i <= m; i++) {
cin >> a[i];
tot += a[i];
}
if (tot < n) {
cout << -1 << "\n";
return;
}
long double n1 = 1;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
struct Segment {
int l, r, id;
friend inline bool operator<(const Segment &a, const Segment &b) {
if (a.l != b.l) return a.l > b.l;
if (a.r != b.r) return a.r < b.r;
return a.id < b.id;
}
} t[N];
namespace BIT {
int c[N];
inline voi... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a, b;
cin >> n >> m >> a >> b;
int cnt1 = n * a, cnt2, cnt3 = 1000000000;
if (n % m == 0) {
cnt2 = (n / m) * b;
} else {
cnt2 = ((n / m) + 1) * b;
cnt3 = (n / m) * b + (n % m) * a;
}
cout << min(cnt1, min(cnt2, cnt3)) << endl... | 1 |
#include <bits/stdc++.h>
using namespace std;
long int ara[999999];
int main() {
ios_base::sync_with_stdio(0);
long int n, t, i, c = 0, s = 0;
cin >> n >> t;
for (i = 1; i <= n; i++) cin >> ara[i];
for (i = 1; i <= n; i++) {
if (c < t) {
c = c + (86400 - ara[i]);
s++;
}
}
cout << s;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int n, m, k, a[1100000], pw2[1100000], sum[1100000];
int main() {
pw2[0] = 1;
for (int i = (1); i <= (1010000); i++)
pw2[i] = (long long)pw2[i - 1] * 2 % MOD;
cin >> n >> m >> k;
for (int i = (1); i <= (m); i++) {
int x, y;
sc... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int sum = 1;
while (n > (sum * 5)) {
n = n - sum * 5;
sum = sum * 2;
}
n = n - 1;
long long int k = n / sum;
switch (k) {
case 0:
cout << "Sheldon";
break;
case 1:
cout << "L... | 1 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> p;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
string s;
cin >> s;
long long ans = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'B') ans = ans + pow(2, i);
}
cout << ans;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chkmax(T &a, T b) {
if (a < b) a = b;
}
template <class T>
inline void chkmin(T &a, T b) {
if (a > b) a = b;
}
inline int read() {
int s = 0, f = 1;
char ch = getchar();
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '... | 5 |
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int main() {
int n;
cin >> n;
cout << n << ":";
for (int i = 2; i * i <= n; i++) {
while (n % i == 0) {
n /= i;
cout << " " << i;
}
}
if (n != 1) cout << " " <... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
void Enter() { cin >> n >> a >> b; }
void Solve() {
int kq = 0;
for (int i = 1; i < n; i++) {
kq = max(kq, min(a / i, b / (n - i)));
}
cout << kq;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
Enter();
Solve();
}
| 2 |
#include<cstdio>
#define MAX 100
int A[MAX][MAX] = {0};
int main()
{
int n,u,k,v;
scanf("%d", &n);
for(int i=0; i<n; i++)
{
scanf("%d%d", &u, &k);
for(int j=0; j<k; j++)
{
scanf("%d", &v);
A[u-1][v-1] = 1;
}
}
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
if(j) printf(" ");
printf("... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, sum, jum, ans;
string s;
map<long long, long long> m, k;
map<long long, bool> b;
vector<long long> v;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s;
sum = 0;
jum = 0;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
int n;
cin >> n;
vector<pair<int, int> > arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i].first >> arr[i].second;
}
if (n % 2) {
cout << "no" << endl;
return 0;
}
vector<int> l1, l2, l3, l4;
for (int i = 0;... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <int D, typename T>
struct dense : public vector<dense<D - 1, T>> {
template <typename... Args>
dense(int n = 0, Args... args)
: vector<dense<D - 1, T>>(n, dense<D - 1, T>(args...)) {}
};
template <typename T>
struct dense<1, T> : public vector<T> {
den... | 3 |
#include<bits/stdc++.h>
using namespace std;
string str , ans[6003]; int L;
string solve(int id){
if(id == 2 * L) return string();
if(ans[id].size()) return ans[id];
if(str[id] == 'a'){
int sum = 0 , pos = id;
while(pos < 2 * L && sum <= 0) sum += str[pos++] == 'a' ? -1 : 1;
if(pos == 2 * L){
queue < int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N, S;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> S;
if (S < 2 * N) {
cout << "NO";
return 0;
}
cout << "YES\n";
for (int i = 1; i < N; i++) {
cout << 2 << ' ';
}
cout << S - 2 * (N - 1)... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int n;
long long a[N];
long long num[N];
bool mark[N];
long long ans;
long long get(long long x) {
long long res = 0;
for (long long i = 2; i * i <= x; i++) {
while (x % i == 0) {
res++;
x /= i;
}
}
if (x > 1) res++;
return re... | 3 |
#include <bits/stdc++.h>
using namespace std;
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
constexpr int dx[] = {1, -1, 0, 0};
constexpr int dy[] = {0, 0, 1, -1};
constexpr int MAX_H = 60;
constexpr int MAX_W = 10... | 0 |
#include<bits/stdc++.h>
using namespace std;
int n;
double x[100],y[100];
double distance(double p){
double sum=0;
for(int i=0;i<n;i++){
double w=abs(x[i]-y[i]);
sum+=pow(w,p);
}
return pow(sum,1.0/p);
}
int main(){
cout<<fixed<<setprecision(12);
cin>>n;
for(int i=0;i<n;i++){
cin>>x[i];
}
for(int i=0;i<n... | 0 |
#include<iostream>
#include<vector>
#include<set>
using namespace std;
typedef vector<int> vec;
int main(){
int n,x,s;
while(cin>>n,n){
vec tab[31];
set<int> have[60];
set<int>::iterator ite;
int now=0;
while(n!=now++){
cin>>x;
for(int i=0;i<x;i++){
cin>>s;
tab[s].push_back(now);
}
}
fo... | 0 |
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<complex>
#include<algorithm>
#include<vector>
int main()
{
int n;
long long a[100000], sum{};
scanf("%d", &n);
for (int i = 0; i < n; ++i)
{
scanf("%lld", a + i);
}
std::sort(a, a + n);
if (n & 1)
{
int les = std::min(a[n ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
long N;
cin>>N;
int x=pow(N,0.5);
for(int i=x;i>0;i--){
if(N%i==0){
cout<<i+(N/i)-2<<endl;
break;
}
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long long l[100001];
long long hv[11];
long long ans = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> l[i];
ans += l[i] * 2;
}
bool hvw = false;
long long pw = 0;
char c = 0;
for (int i = 1; i <= n; i++) {
cin >> c;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string in;
cin >> in;
vector<int> left;
vector<int> rigth;
for (int i = 0; i < in.size(); i++) {
if (in[i] == 'l')
left.push_back(i + 1);
else
rigth.push_back(i + 1);
}
for (int i = 0; i < rigth.size(); i++) {
printf("%i\n"... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p) {
return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc) {
o << "{";
for (const T& v : vc) o << v << ",";
o << "... | 1 |
#include <iostream>
#include <cstdio>
using namespace std;
int n, a, mx, s;
int main() {
cin>>n;
while(n--) {
cin>>a;
s += a;
mx = max(mx, a);
}
cout<<s - mx/2;
return 0;
}
| 0 |
#include <bits/stdc++.h>
int PD(int x1, int y1, int x2, int y2, int x3, int y3);
int main() {
int x1, x2, y1, y2, x3, y3;
while (scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3) != EOF) {
if (PD(x1, y1, x2, y2, x3, y3))
printf("RIGHT\n");
else if (PD(x1 + 1, y1, x2, y2, x3, y3) || PD(x1, y1 + 1, x2... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
const int inf = 0x20202020;
const int N = 1000005;
int n, m;
i... | 6 |
#include <bits/stdc++.h>
char strMas[10010][102];
int results[101][2510], sums[10010], len[10010];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", &strMas[i]);
sums[i] = 0;
len[i] = strlen(strMas[i]);
for (int j = 0; strMas[i][j]; j++) sums[i] += strMas[i][j] - 'a';
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
int arr[205];
while (t--) {
int n, k;
cin >> n >> k;
for (int i = 0; i < 2 * n; i++) arr[i + 1] = -1;
for (int i = 0; i < k; i++) {
int x, y;
c... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[5000];
int gg[5000], g[200][200], ng[200][200];
int f[30][200][200];
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)
if (a[j] >=... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x1fffffffffffffff;
const double INFD = 1e20;
const double EPS = 1e-9;
const double PI = atan(1) * 4;
const long long M = 1000000007;
long long scan() {
long long r;
scanf("%lld", &r);
return r;
}
void scanstr(char *buf) { scanf("%s", buf); }
lon... | 3 |
#include<stdio.h>
int main(){
int n,a,b;
scanf("%d%d",&a,&b);
printf("%d",a-b+1);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void IO(T &x) {
char c = getchar();
T sgn = 1;
while (c < '0' || c > '9') {
if (c == '-') sgn = -1;
c = getchar();
}
x = 0;
while (c >= '0' && c <= '9') {
x = (T)(x << 1) + (x << 3) + c - '0';
c = getchar();
}
x *= s... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(void){
int n;
while (cin>>n) {
if (n==0) {
break;
} else {
char a;
std::vector<vector<char>> vec(n,vector<char>(n));
for (int i=0;i<n;i++) {
for (int j=0;j<n;j++) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
inline long long toll(string s) {
long long v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T>
inline string toString(T x) {
ostringstream sout;
sout << x;
r... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
vector<int> G[maxn];
set<int> S;
bool dfs(int x) {
vector<int> v;
bool ret = 0;
if (G[x].empty() || G[x][0] != 1) ret = 1;
for (set<int>::iterator it = S.begin(); it != S.end(); it++) {
vector<int>::iterator vit = lower_bound(G[x].begi... | 5 |
#include <bits/stdc++.h>
using namespace std;
int dp[5001][501];
int main() {
for (int j = 0; j <= 500; j++) {
dp[0][j] = 0;
}
int n, k;
cin >> n >> k;
int card_count[100005] = {0};
for (int i = 0; i < n * k; i++) {
int z;
cin >> z;
card_count[z]++;
}
int favorite_count[100005] = {0};
... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = (long long)1000000007;
long long gcd(long long a, long long b) { return (!b ? a : gcd(b, a % b)); }
int gcd(int a, int b) { return (!b ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
int pc(long long x) { return ... | 1 |
#include<iostream>
int main()
{
while (true)
{
int n;
std::cin >> n;
if (n == 0)
{
break;
}
int result = 0;
int five_pow = 5;
while (true)
{
const int fives = n / five_pow;
if (fives == 0)
{
break;
}
result += fives;
five_pow *= 5;
}
std::cout << result << std::endl;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define MOD 1000000007
typedef vector<int> vi;
typedef long long int ll;
int main()
{
int N;
ll T;
cin >> N >> T;
vi D(N);
vi DD(N);
rep(i, 0, N) cin >> D[i];
rep(i, 0, N) DD[i] = D[i];
sort(D.begin(), D.end());
sort(DD.b... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long test;
cin >> test;
while (test--) {
long long n, k;
cin >> n >> k;
long long i, j;
long long a[n];
long long maxim = 1e9;
for (i = 0; i < n; i++) {
cin >> a[i];
maxim = min(maxim, a[i]);
}
long long xx... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
vector<vector<char>> grid;
vector<vector<int>> sum;
vector<vector<int>> mx;
int n, m;
int get(int x1, int y1, int x2, int y2) {
return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];
}
bool check(int t) {
vector<vector<int>>... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double INF = 1e6;
const double PI = atan2(0, -1);
const int maxn = 550;
inline int sgn(double x) {
if (fabs(x) < EPS) return 0;
return x < 0 ? -1 : 1;
}
inline int iseq(double x, double y) { return sgn(x - y) == 0; }
struct Point {
doubl... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class TYPE>
TYPE gcd(TYPE x, TYPE y) {
if (y)
return gcd(y, x % y);
else
return x;
}
template <class TYPE>
TYPE lcm(TYPE x, TYPE y) {
TYPE t = gcd(x, y);
return t ? (x / t * y) : 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL)... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, c, i, j;
cin >> r >> c;
char k[r + 2][c + 2];
for (i = 0; i <= r + 1; i++)
for (j = 0; j <= c + 1; j++) k[i][j] = '.';
for (i = 1; i <= r; i++)
for (j = 1; j <= c; j++) cin >> k[i][j];
for (i = 1; i <= r; i++)
for (j = 1; j <= c; ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, pair<int, string> > > crew;
for (int i = 0; i < n; i++) {
string name, priority;
cin >> name >> priority;
int p;
if (priority == "rat")
p = 1;
else if (priority == "woman" || priority == "child... | 1 |
#include <bits/stdc++.h>
void vow(char a) {
if (a >= 'A' && a <= 'Z') a = a + 32;
if (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u' || a == 'y') {
} else {
printf(".%c", a);
}
}
int main(void) {
char x[100];
scanf("%s", x);
int l = strlen(x);
for (int i = 0; i < l; i++) {
vow((x[i]));... | 1 |
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;
const long long int mod=1000000007;
const ... | 0 |
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
long long N,ans;
int main(){
cin>>N;
int A[N][N],B[N][N];
rep(i,N*N){cin>>A[i/N][i%N];B[i/N][i%N]=A[i/N][i%N];}
rep(k,N)rep(i,N)rep(j,N)B[i][j]=min(B[i][j],B[i][k]+B[k][j]);
rep(i,N*N)if(A[i/N][i%N]!=B[i/N][i%N]){co... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct e {
int diff, ind;
} st[1000010];
int n, a[1000010], rez[1000010];
bool srt(e aa, e bb) { return (aa.diff > bb.diff); }
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < n; i++) {
st[i].ind = i;
st[i].di... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int OO = (int)1e9;
int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
long long t, n, sum, lft, rght;
vector<long long> a;
bool ok, upper, lower, digits;
char c;
string second;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout... | 2 |
#include<iostream>
#include<vector>
#include<set>
#include<string>
#include<algorithm>
using namespace std;
vector<string> M;
int H,W;
int c_to_int[26];
char int_to_c[7];
int num;
vector<vector<vector<char> > > E;
bool pre_check(){
E.clear();
E.resize(H,vector<vector<char> > (W,vector<char>()));
for(int k=0;k<nu... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 70;
int n, m, a[N], b[N];
map<double, pair<long long, long long> > mp;
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < m; i++) scanf("%d", &b[i]);
for (int i = 0; i < n; i++) {
for (int j = 0;... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long n, d, a[100000], diff;
long sum = 0;
cin >> n >> d;
for (long i = 0; i < n; i++) cin >> a[i];
for (long i = 1; i < n; i++) {
if (a[i - 1] >= a[i]) {
diff = a[i - 1] - a[i];
a[i] = a[i] + (diff / d + 1) * d;
sum = sum + diff ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, t[10000005], sum, h0;
int a[10000005], b[10000005], inv[10000005];
const int Mxdt = 1000000;
inline char gc() {
static char buf[Mxdt], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, Mxdt, stdin), p1 == p2)
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int a;cin>>a;
cout<<"Christmas ";
for(int i=24;i>=a;i--){
cout<<"Eve ";
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> primes;
void sieve(long long int n) {
vector<bool> check(n + 1, true);
check[0] = false;
check[1] = false;
for (long long int i = 2; i <= n; ++i) {
if (check[i]) {
if (i * i * 1ll <= n)
for (long long int j = i * i; j <= n; j ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, q, dp[26][1505];
string dat;
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> dat;
for (int c = 0; c < 26; ++c) {
for (int i = 0; i < n; ++i) {
int gap = 0;
for (int j = i; j < n; ++j) {
if (dat[j] - 'a' != c) {
++gap;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
char a[120];
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
cin >> a;
vector<int> count_B;
for (int i = 0; i < n; i++) {
while (i < n && a[i] == 'W') i++;
if (i >= n) break;
int count = 0;
while (i < n && a[i] == 'B... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &_p) {
return os << "(" << _p.first << "," << _p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &_V) {
bool f = true;
os << "[";
for (auto v ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long ans = n * n;
ans = (ans * (ans + 1)) / 2;
long long k = ans / n;
k /= n / 2;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n / 2; j++) {
cout << (n / 2 * i + 1 + j) << " " << k - (n / 2 * i + 1 + j) << " ";... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <int MOD>
struct ModInt {
static const int Mod = MOD;
unsigned x;
ModInt() : x(0) {}
ModInt(signed sig) {
int sigt = sig % MOD;
if (sigt < 0) sigt += MOD;
x = sigt;
}
ModInt(signed long long sig) {
int sigt = sig % MOD;
if (sigt < 0)... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (1 << 17) + 10;
int ans, anstag;
vector<int> son[maxn];
int h[maxn], tag[maxn];
inline void dfs(int now, int f) {
tag[now] = 0;
if (27982 > 6886) {
if (25900 > 1900) {
bool EOYODPGAKG;
EOYODPGAKG = 27137;
if (EOYODPGAKG) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
multiset<int> a[35];
long long int s[35];
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
int t;
cin >> t;
int cnt = 0;
for (int z = 1; z <= t; z++) {
char c;
cin >> c;
int x;
cin >> x;
int b = 64 - __builtin_clzll(x) - 1 + 1;
if (c ... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct dri {
string nam;
int win[60];
int poi;
};
map<int, string> is;
map<string, int> si;
int df[60] = {0, 25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
int n, t, sum;
dri ans[1200];
string s;
bool c1(dri x, dri y) {
if (x.poi != y.poi) return x.poi > y.poi;
for (int i = ... | 2 |
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <map>
#include <sstream>
using namespace std;
using Weight = int;
using Capacity = int;
struct Edge {
int src, dst; Weight weight; Capacity cap;
Edge(int s, ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 13;
int q, tree[4 * maxN], lzy[4 * maxN], n, m, a[maxN], b[maxN];
struct seg_tree {
void fix(int id, int val) {
lzy[id] += val;
tree[id] += val;
}
void relax(int id) {
fix(id << 1, lzy[id]);
fix(id << 1 ^ 1, lzy[id]);
lzy[id]... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, d, m, l;
cin >> n >> d >> m >> l;
long long pos, eq, ans;
pos = (n - 1) * m + l;
eq = pos % d;
eq = d - eq;
ans = pos + eq;
for (int i = 1; i <= n; i++) {
pos = (i - 1) * m + l;
eq = pos % d;
eq = d - eq;
if (eq < m ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long dx[4] = {1, 0, -1, 0};
long long dy[4] = {0, -1, 0, 1};
template <class T>
void inputVector(vector<T>& v, long long n) {
v.resize(n);
for (long long i = 0; i < v.size(); i++) cin >> v[i];
}
signed main() {
long long N;
cin >> N;
vector<long long> a;
in... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
std::ios::sync_with_stdio(false);
int n, a, b;
cin >> n >> a >> b;
int used[105];
fill(used, used + 105, 0);
for (int i = 0; i < a; i++) {
int q;
cin >> q;
used[q] = 1;
}
f... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char matrice[105][105];
bool lie[105] = {0};
bool hang[105] = {0};
scanf("%d", &n);
for (int i = 0; i < n; i++) {
getchar();
for (int j = 0; j < n; j++) scanf("%c", &matrice[i][j]);
}
for (int i = 0; i < n; i++) {
for (int j =... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e18 + 9;
const long long MAX_SIZE = 1e7 + 1;
long long _t = 1, _T, csn;
long long max(long long a, long long b) {
if (a < b) return b;
return a;
}
long long min(long long a, long long b) {
if (a > b) return b;
re... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
while (cin >> n) {
if (n % 4 == 1 || n % 4 == 2)
cout << 1 << endl;
else
cout << 0 << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int a[50005], ans[50005], nm[50005];
double b[50005], deg, deg0;
bool cmp(int x, int y) { return b[x] > b[y]; }
double work(int a, int n, int b) {
double l = n / cos(deg) / 2;
double A = a + l, B = b + l;
double C = sqrt(A * A + B * B - 2 * A * B * cos(deg0));
doubl... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
int dp[maxn][maxn][30][2];
char ans[maxn][maxn];
int n, m;
struct node {
int to, val;
node(int a, int b) {
to = a;
val = b;
}
};
vector<node> edge[maxn];
int dfs(int a, int b, int v, int t) {
if (dp[a][b][v][t]) return dp[a][b][v][t];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n, p, q, i, x, k = 1;
cin >> n >> x;
int a[n], b[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
cin >> b[i];
}
sort(a, a + n);
sort(b, b + n, ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[10000];
scanf("%s", a);
int l = strlen(a), i, k = 0, h = 0;
for (i = 0; i < l - 1; i++) {
if (a[i] == a[i + 1])
h++;
else
k++, h = 0;
if (h == 5) k++, h = 0;
}
printf("%d\n", k + 1);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
bool isvalid(long long x, long long y) {
if (max(x, y) <= 3 && min(x, y) >= 1) return true;
return false;
}
int main() {
ios::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
long long i, j, k, m, n, d, t, q, p, c;
long long a[4][4];
long long x[] = {-1, 0, ... | 1 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
const int maxn = 2e5 + 10, maxm = 3e5 + 10, lg = 21, mod = 1e9 + 7, inf = 1e18;
int n, m, q, par[maxn][lg + 1], bus[maxn][lg + 1], A[maxn], B[maxn], h[maxn],
st[maxn], ft[maxn], tt, mn[maxn];
vector<in... | 5 |
#include <bits/stdc++.h>
using namespace std;
int ans = 0;
int isPrime(int n) {
int i;
for (i = 2; i * 1ll * i <= n; i++) {
if (n % i == 0) {
return 0;
}
}
return 1;
}
int main() {
int n, i, j, fl = 0;
scanf("%d", &n);
if (isPrime(n)) {
puts("1");
return 0;
}
if (n == 2) {
pu... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 87;
const long long inf = 1e18;
struct edge {
int u, v, w;
int go(int x) { return u ^ v ^ x; }
} e[N];
vector<int> g[N];
int n, m, q;
void dijk(int s, long long d[], int pr[], vector<int>& tp) {
tp.clear();
fill_n(d, n + 1, inf);
d[s] = 0;
pr... | 6 |
#include <bits/stdc++.h>
using namespace std;
int INF = 1e9 + 7;
vector<vector<int>> par;
struct sp_table {
vector<vector<pair<int, int>>> rmq;
sp_table(vector<int>& v) {
int n = v.size();
rmq = vector<vector<pair<int, int>>>(
n, vector<pair<int, int>>(log2(n) + 1, {-1, -1}));
for (int i = 0; i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PB push_back
#define PPB pop_back
typedef pair<int, int> pii;
static const int INF = 1LL<<61;
static const int MAX_N = 100005;
int n, m, c, d[MAX_N], cumu[MAX_N], visit[MAX_N];
vector<pii> G[MAX_N], res;
void dijkstra() {
fill(d, d + MAX_... | 0 |
#include <bits/stdc++.h>
using namespace std;
int const N = 60, inf = 1e9;
char g[N][N + 1];
int n, m;
void solve() {
scanf("%d%d", &n, &m);
for (int i = 0; i < (int)(n); ++i) scanf("%s", g[i]);
int an = inf;
for (int i = 0; i < (int)(n); ++i)
for (int j = 0; j < (int)(m); ++j)
if (g[i][j] == 'A') {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000;
int n, a[maxn], freq[101];
int solve(int d, int v) {
unordered_map<int, int> presum;
presum[0] = -1;
int ans = 0;
int sum = 0;
int minsum = 0, maxsum = 0;
for (int i = 0; i < n; i++) {
if (a[i] == d) sum++;
if (a[i] == v) sum--;
... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
const long long N = 5e2 + 5;
long long n, a[N][N], b[N][N], d[N][N], vis[N], x, sum;
vector<long long> v, ans;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> n, v.resize(n);
for (long long i = 1; i <= n; i... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long inf = 1e18;
int __FAST_IO__ = []() {
std::ios::sync_with_stdio(0);
std::cin.tie(0);
std::cout.tie(0);
return 0;
}();
int main() {
int t;
cin >> t;
while (t--) {
int N;
cin >> N;
vector<int> v(N);
for (int i = 0; i < (N); ++i) cin >> v... | 4 |
#include <bits/stdc++.h>
using namespace std;
int di[8] = {-1, 1, 0, 0, -1, -1, 1, 1};
int dj[8] = {0, 0, -1, 1, 0, 0, 0, 0};
int A[100000];
int main() {
int n;
cin >> n;
int k;
cin >> k;
for (int i = 0; i < (n); ++i) {
A[i] = i;
}
reverse(A, A + k + 1);
for (int i = 0; i < (n); ++i) {
printf("%... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
char a1[N], a2[N], b1[N], b2[N], t1[N], t2[N];
int main() {
int n;
int a;
char hasSoultuion = true;
cin >> n;
for (int i = 0; i < n - 1; ++i) {
cin >> a;
a1[i] = a & 1, a2[i] = (a >> 1) & 1;
}
for (int i = 0; i < n; ++i) t1[i] = ... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> adj[n + 1];
set<int> s;
vector<int> a;
for (int i = 0; i < n; i++) {
int k;
cin >... | 3 |
#include<iostream>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
if (k == 1) cout << 0;
else cout << n - k;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 4e3 + 10, MOD = 1e9 + 7, INF = 1e15, SQ = 370, LOG = 30;
long long n, m, x, y, x2, y2, z, t, now, d, cur, ptr, answer, q, p, ans,
dp[N][N], c[N][N], sum[N];
int main() {
cin >> n;
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1;... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 5;
const long long mod = 1000000007;
int n;
long long a[maxn], s[maxn], mi[maxn];
long long ans;
long long mult(long long a, long long b) {
if (b == 1) return a;
long long temp = mult(a, b / 2);
temp = (temp + temp) % mod;
if (b % 2 == 1) t... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.