solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
ifstream in("input.in", ios::in);
ofstream out("output.out", ios::out);
int n, a[400], sum = 0, o1 = 0;
int main() {
int i;
cin >> n;
for (i = 1; i <= 2 * n - 1; i++) {
cin >> a[i];
if (a[i] < 0) o1++;
a[i] = abs(a[i]);
sum += a[i];
}
sort(a + 1, a... | 3 |
#include <bits/stdc++.h>
using namespace std;
int A[1003][1003], M11[1003][1003], M1n[1003][1003], Mm1[1003][1003],
Mmn[1003][1003], m, n, i, j, t, mx;
int main() {
cin >> m >> n;
for (i = 1; i <= m; i++)
for (j = 1; j <= n; j++) {
cin >> A[i][j];
M11[i][j] = max(M11[i - 1][j], M11[i][j - 1]) + ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<long long, int> > d, d2;
int pi[200002];
bool mtch[200002];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
d2.push_back({-1, -1});
d.push_back({-1, -1});
for (int i = 1; i <= n; ++i) {
string s;
cin >> s;
in... | 4 |
#include "bits/stdc++.h"
using namespace std;
long double mlog(const long double base, const long double anti) {return log(anti) / log(base);}
int main() {int N; cin >> N;int a = mlog(3, N)-1e-10;cout << a + 1 << endl;return 0;} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string x;
string y = "1";
bool h;
bool boolb = 1;
int counter = 0;
for (int i = 0; i < n; i++) {
cin >> x;
h = 1;
if (x == "1") continue;
if (x == "0")
boolb = 0;
else {
if (x[0] != '1') {
... | 2 |
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int h,w;
vector<pair<long long,int> >a;
int main()
{
cin>>h>>w;
for(int i=0;i<h;i++)
{
long long x;cin>>x;
a.push_back(make_pair(x,i));
}
for(int i=0;i<w;i++)
{
long long x;cin>>x;
a.push_back(make_pair(x,h+i));
}
sort(a.begin(... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000;
const long long LINF = 1LL * INF * INF;
pair<int, int> arr[300007];
long long ans[300007];
int n, m;
pair<long long, int> a[300007];
long long pref1[300007];
long long pref2[300007];
void calc() {
long long sum = 0;
for (int i = 0; i ... | 5 |
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 1e5 + 5 ;
const ll mod = 1e9 + 7 ;
int n , k ;
ll a[maxn] ;
ll f[maxn] ;
void init()
{
f[0] = 1 ;
for(int i = 1 ; i <= 1e5 ; i ++)
f[i] = f[i - 1] * ll(i) % mod ;
}
ll qpow(ll a , ll b)
{
ll ans = 1 ;
while(b)
{
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int dp[105][200005];
int n, k;
int a[105], b[105];
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> k;
int i, j;
for (i = 1; i <= n; i++) cin >> a[i];
for (i = 1; i <= n; i++) cin >> b[i];
for (i = 0; i < 200005; i++) dp[0][i] = -199999999;
dp[0][100... | 3 |
#include <bits/stdc++.h>
using namespace std;
int k, b, n, x;
int main() {
scanf("%d%d%d%d", &k, &b, &n, &x);
long long sk = 1, ss = 1;
for (int i = 1; i <= n + 1; i++) {
sk *= k;
if (i == n + 1 || ss > x || b * ss + sk > x) {
printf("%d\n", n - i + 1);
break;
} else
ss += sk;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int inf = INT_MAX;
const int MAXN = 10004;
const int modn = 1000000007;
int ans[20][20];
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
void bfs(int n) {
queue<pair<int, int> > q;
q.push(pair<int, int>(n, n));
ans[n][n] = n;
while (q.... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long pos;
char answer;
void In() { cin >> pos; }
int Lentgh(int num) {
int result = 0;
while (num > 0) {
num /= 10;
result++;
}
return result;
}
long long LinearSum(long long start, long long finish, long long num) {
return (start + finish) * num / 2;... | 5 |
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i ++)
#define LL long long
#define mx 105
using namespace std;
const LL mod = 1000000007;
int c[mx], b[mx], n, bb, B[mx];
int st, en;
LL res[300], dp[mx][mx * mx];
LL add[mx * mx];
void Add(LL &x, LL y){
x = (x + y + mod) % mod;
}
void calc(int x)... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n, d;
cin >> n >> d;
long long x = n * (n - 1) / 2;
if (d > x) {
cout << "NO\n";
continue;
}
x = 1;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
bool win(long long s, long long e) {
if (e & 1) return !(s & 1);
if (s * 2 > e) return s & 1;
if (s * 4 > e) return 1;
return win(s, e / 4);
}
bool lose(long long s, long long e) {
if (... | 6 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for(int i = (int)a; i < (int)b; ++i)
#define SORT(v) std::sort(v.begin(), v.end())
#define ALL(v) v.begin(), v.end()
#define cosnt const
using ll = long long;
using std::cin;
using std::cout... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int i, j, k, l, m1, m2, m3, m4, m = 0, n;
int main() {
cin >> n;
m1 = n - 1;
m2 = n * (m1 * (m1 + 1) / 2);
m3 = (m1 * (m1 + 1) * (2 * m1 + 1)) / 6;
m = m2 - m3;
cout << m + n;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int n, ans = 0, v[300005], c[300005], l[300005], r[300005], dp[300005],
fdp[300005], fa[300005];
vector<int> grp[300005], seq;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%d%d%d", v + i, c + i, l + i, r + i);
grp[l[i] + c[i] + r[... | 4 |
#include <bits/stdc++.h>
using namespace std;
char word[13];
int m, pans[5], last;
bool found;
int main() {
scanf("%s", word);
scanf("%d", &m);
vector<int> used;
for (int t = 0; t < 10; t++) {
last = 0;
pans[0] = 0;
pans[1] = 0;
used.clear();
for (int i = 1; i <= m; i++) {
found = fals... | 3 |
#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> aa[100100];
vector<pair<long long, long long> > pp, mm;
const int MAXN = 100010;
long long Plus[100100], Minus[100100];
long long pcnt[100100], mcnt[100100];
int lowbit(int x) { return x & -x; }
long long get_sum(long long *C, int x) {
long long... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3,no-stack-protector")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
struct Counter {
map<int64_t, int> mp;
void Add(int64_t x) { mp[x]++; }
void Del(int64_t x) {
if (mp[x]-- < 2) {
mp.erase(... | 6 |
#include <bits/stdc++.h>
using namespace std;
int x[111];
long double inline get_dis(int ox, double hx, double hy) {
return sqrt((ox - hx) * (ox - hx) + (long double)hy * hy);
}
long double inline get_dis(int ox, int nx) {
return sqrt((long double)(ox - nx) * (ox - nx));
}
int main() {
int n, vb, vs;
while (cin... | 2 |
#include <bits/stdc++.h>
using namespace std;
using VI = std::vector<int>;
using VVI = std::vector<VI>;
vector<int> d_arr_1;
vector<int> d_arr_2;
vector<int> prime_sieve;
vector<int> a_arr;
int n;
void sieve() {
for (int i = 2; i < 1e7 + 1; i += 2) {
prime_sieve[i] = 2;
}
for (int i = 3; i < 1e7 + 1; i += 2) ... | 4 |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include ... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class t>
inline t read(t &x) {
char c = getchar();
bool f = 0;
x = 0;
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
if (f) x = -x;
return x;
}
template <class t>
inline void wr... | 5 |
#include <bits/stdc++.h>
using namespace std;
char str[1005];
int mat[2005][105];
int n = 2000, m;
const int lim = 30;
const long long base = 100000000ll;
const int bit_sz = 8;
long long dig[100];
int main() {
scanf("%d", &m);
for (int i = 0; i < m; ++i) {
int sz;
scanf("%s", str), sz = strlen(str);
rev... | 4 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
typedef pair<int, int> P;
const double EPS = 1e-8;
double dp[51][5001];
int x, y, z, v[4], e[51], a[51];
int main(){
while(cin >> x >> y >> z && (x|y|z)){
fill(dp[0], dp[51], 0.0);
fill(e, e+51... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long int n;
int flag = 0;
cin >> n;
string s1;
cin >> s1;
long long int a[n], i;
set<long long int> s;
for (i = 0; i < n; ++i) cin >> a[i];
for (i = 0; i < n; ++i) {
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
int k, n, tot, Link[200010], tree[201000];
long long ans;
bool visited[201000], U[201000];
struct node {
int v, next;
} edge[400100];
void addEdge(int x, int y) {
tot++;
edge[tot].v = y;
edge[tot].next = Link[x];
Link[x] = tot;
}
void dfs(int x) {
visited[x] = t... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,sum=0,ave,ans=0;
int a[100];
cin>>N;
for(int i=0;i<N;i++){
cin>>a[i];
sum+=a[i];
}
if(sum>=0){
ave=(double)sum/N+0.5;
}else{
ave=(double)sum/N-0.5;
}
for(int i=0;i<N;i++){
ans+=pow(a[i]-ave,2);
}
cout<<ans<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500001;
const int sq = 800;
int A[maxn];
int B[sq][sq];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int q;
cin >> q;
memset(A, 0, sizeof(A));
;
memset(B, 0, sizeof(B));
;
while (q--) {
int Q, x, y;
cin >> Q... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1073741823;
const int maxint = 0x7fffffff;
const long long INF = 1152921504606846976ll;
const long double eps = 1E-9;
const long double pi = acos(-1);
template <class T>
inline T _sqr(T a) {
return (a * a);
}
template <class T>
inline T _abs(T a) {
retur... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int tt = 0; tt < t; ++tt) {
int a, b;
cin >> a >> b;
int sum = abs(a - b);
int cnt = sum / 5;
sum %= 5;
cnt += sum / 2;
sum %= 2;
cnt += sum;
cout << cnt << endl;
}
}
| 1 |
#include<cstdio>
#include<map>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define MAXN 56
using namespace std;
int n;
long long ans;
char a[MAXN];
map<pair<unsigned long long,unsigned long long>,long long> ma;
int main()
{
scanf("%d",&n);
scanf("%s",a);
int Max=1<<n;
for(int s=0;s<Ma... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, a[5001] = {0}, b = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int m;
cin >> m;
if (a[m] == 0)
a[m] = i + 1;
else if (a[m] != i)
b = 1;
}
cout << (b ? "YES" :... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, d = "";
getline(cin, s);
int i, n = s.size(), f = 0;
for (i = 0; i < n; i++) {
if (s[i] == ' ') {
f = 1;
continue;
}
if (s[i] == '.' || s[i] == ',' || s[i] == '!' || s[i] == '?') {
d = d + s[i];
f = 1;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, C;
cin >> A >> B >> C;
cout << ((A <= C && C <= B) ? "Yes" : "No") << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {0, -1, 0, 1, 1, -1, -1, 1};
const int dy[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
const long long mod = 1000000007;
const int base = 311;
long long pw[15];
long long calc(int val) {
long long ans = 0;
for (int i = 1; i <= 10; ++i) {
long long tmp = max(0... | 5 |
#include <bits/stdc++.h>
using namespace std;
int start[100001];
int main() {
for (int i = (0); i < (100001); i++) start[i] = -1;
int N;
cin >> N;
for (int i = (0); i < (N); i++) {
int x, y;
scanf("%d%d", &x, &y);
int idx = i - y;
int ret = 0;
for (int j = 1; j * j <= x; j++) {
if (x %... | 2 |
#include<cstdio>
#include<algorithm>
using namespace std;
int tate[1005][1005];
int yoko[1005][1005];
int dp[1005][1005];
char c[1005][1005];
int main(){
int n;
while(scanf("%d",&n),n!=0){
for(int i=1;i<=n;i++) scanf("%s",c[i]+1);
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
tate[i][j] = 0;
yo... | 0 |
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
using namespace std;
typedef pair<int, int> P;
int W, H, N;
char field[1002][1002];
const int dx[] = {0, 1, 0, -1};
const in... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, t, c = 0, q = -1;
cin >> n >> k;
vector<long long int> a, b;
map<long long int, int> d;
for (int i = 0; i < n; i++) {
cin >> t;
a.push_back(t);
}
sort(a.begin(), a.end());
for (long long int i = 0; i < n; i++) {
i... | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL power(LL x, LL n, LL m) {
LL res = 1;
if (n > 0) {
res = power(x, n/2, m);
if (n % 2 == 0) res = (res * res) % m;
else res = (((res * res) % m) * x) % m;
}
return res;
}
int main() {
int m, n;
cin >> m >> n;
cout << powe... | 0 |
#include<bits/stdc++.h>
using namespace std;
int a[13][13],b[13],c[13];
int main()
{
int n,m,k,ans=1e9;
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++)
{
scanf("%d",&c[i]);
for(int j=1;j<=m;j++)
scanf("%d",&a[i][j]);
}
for(int i=0;i<(1<<n);i++)
{
int cost=0;
for(int j=1;j<=n;j++)b[j]=0;
for(int j=1;... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#de... | 0 |
#include <bits/stdc++.h>
using namespace std;
int p, x, i;
bool ok(int x) {
i = 0;
bool yep = false;
for (i = 2; i * i <= x; ++i) {
if (x % i == 0) {
if (i <= p) return false;
if (x / i <= p) return false;
yep = true;
}
}
if (yep == false && x <= p) return false;
if (i * i == x && ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, R, V, E, C, tot, f[105], s[105], vis[105];
double eps = 1e-5, r[105];
struct point {
double x, y;
int id1, id2;
} a[105], jiao[105];
inline int read() {
int ret = 0, ff = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') ff = -ff;
ch = g... | 5 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int findMaxMid(vector<int> arr, int start, int end, int mid)
{
int maxRight = arr[mid];
int maxLeft = arr[mid];
int i = mid+1;
int sum = arr[mid];
while(i <= end)
{
sum += arr[i];
if(sum > maxRight)... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
int main() {
cin >> n >> m >> k;
long long L = 1, R = n * m;
while (L < R) {
long long mid = (L + R) / 2;
long long tot = 0;
for (int i = 1; i <= n; i++) {
tot += min(m, mid / i);
}
if (tot >= k) {
R = mid;
} else... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
void solve() {
int n, k;
cin >> n >> k;
string str;
cin >> str;
vector<vector<int>> dp(n, vector<int>(2, INF));
vector<int> sumOnes(n);
for (int i = 0; i < n; i++) sumOnes[i] = str[i] == '1';
partial_sum(sumOnes.begin(), sumOnes.end(), s... | 5 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long n, k;
cin >> n >> k;
vector<long long> ans;
for (long long i = 30; i >= 0; --i) {
long long t = (1 << i);
if (n - t >= 0) {
ans.push_back(i);
n -= t;
}
}
if (ans.size() > k) {
cout << "NO" << endl;
return... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, k, x, y, ans, cnt = 0;
cin >> n >> k;
if (n == 1) {
cout << 0 << endl;
return 0;
}
vector<int> v[n + 1];
int sz[n + 1];
memset(sz, 0, sizeof(sz));
for (i = 1; i <= k; i += 1) {
cin >> x;
v[x].push_back(i);
}
for (i ... | 1 |
#include<bits/stdc++.h>
using namespace std;
#define N 1000010
#define ll long long
const ll p = 1e9 + 7;
ll n, m, k, ans;
ll fac[N], inv[N], san[N];
ll fpow(ll a, ll b)
{
ll ans = 1;
while(b)
{
if(b & 1) ans = ans * a % p;
a = a * a % p; b >>= 1;
}
return ans;
}
ll C(ll n, ll m)
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
int x, y, a, b;
scanf("%d%d%d%d", &x, &y, &a, &b);
int lcm = x / gcd(x, y) * y;
a--;
int ans = b / lcm - a / lcm;
printf("%d\n", ans);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 0.000000001;
const int ITER = 100;
int s, a, b, c;
inline double max2(double s, bool flag = false) {
double l = 0, r = s;
int ps = ITER;
while (ps--) {
double d = (r - l) / 3;
double ml = l + d;
double mr = r - d;
if (b * log(ml) + c... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int x = 0, y = 0, dp = 0, tmp;
int sum = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == 'U') {
y++;
if (x < y) {
if (dp == 2) sum++;
dp = 1;
}
}
if (s[i] == ... | 2 |
#include <bits/stdc++.h>
using namespace std;
string decToBinary(long long n) {
string s = "";
for (int i = 31; i >= 0; i--) {
int k = n >> i;
if (k & 1)
s += "1";
else
s += "0";
}
return s;
}
int main() {
long long d, n;
cin >> d >> n;
vector<long long> v(n);
for (long long i = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(){
long long n;
cin>>n;
string s;
while(n){
n--;
s+='a'+n%26;
n/=26;
}
reverse(s.begin(),s.end());
cout<<s<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int w, h;
long long R;
while (cin >> w >> h) {
R = 0;
w--;
h--;
for (int i = w; i > 0; i -= 2) {
for (int k = h; k > 0; k -= 2) {
R += i * k;
}
}
cout << R << endl;
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int n,x,y,ans;
int cnt[10020];
vector<pair<pair<int, int>, int> > a;
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>x>>y;
a.push_back(make_pair(make_pair(x,y),0));
}
for(int i=0;i<n;i++){
cin>>x>>y;
a.push_back(make_pair(ma... | 0 |
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <fstream>
#include <sstream>
#include <queue>
#include <exception>
#include <cmath>
#include <numeric>
#define NN 100
#define SS 1000
using... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int AlphaSize = 26;
const int MaxN = 1e5 + 100;
const int MaxM = 256;
int next_occur[MaxN][AlphaSize];
int dp[MaxM][MaxM][MaxM];
string pattern;
string words[3];
int N, Q;
void CreateLinks() {
for (int i = 0; i < AlphaSize; ++i) {
next_occur[N][i] = next_occur[N... | 4 |
#include <bits/stdc++.h>
using namespace std;
int p[200005];
long long ret[200005];
long long inv[200005], sum[200005];
void update(long long *pen, int ind, int val) {
while (ind < 200005) {
pen[ind] += val;
ind += ind & (-ind);
}
}
long long query(long long *pen, int ind) {
long long ret = 0;
while (in... | 5 |
#include <bits/stdc++.h>
using namespace std;
void check(const std::vector<int>& v) {
int n = v.size();
set<int> s;
int u = 0;
for (int i = 0; i < v.size(); ++i) {
if (s.find(v[i]) == s.end()) {
s.insert(v[i]);
++u;
}
}
std::cout << "unique " << u << " arr size " << v.size() << std::endl... | 5 |
/*
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
int b[] = {2, 3, 1, 2, 1};
cout << b[a - 1] << endl;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T extGcd(T a, T b, T &x, T &y);
template <typename T>
T modInv(T a, T m);
const long long mod = (119 << 23) + 1, root = 62;
void ntt(vector<int> &a, vector<long long> &rt, vector<long long> &rev, int n) {
for (int i = 0; i < n; i++)
if (i < rev[i... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, d[100005];
vector<int> edges[100005];
bool vis[100005];
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d %d", &a, &b);
edges[a].push_back(b);
edges[b].push_back(a);
}
int ans = 0, node;
queue<int> q;
vis[1]... | 3 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long spf[100005];
void sieve() {
spf[1] = 1;
for (long long i = 2; i < 100005; i++) spf[i] = i;
for (long long i = 4; i < 100005; i += 2) spf[i] = 2;
for (long long i = 3; i * i < 100005; i++) {
if (spf[i] == i) {
for (long long j = i * i; j < 100005;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int l, d, v, g, r;
cin >> l >> d >> v >> g >> r;
int cycle = g + r, cv = cycle * v, gv = g * v;
double answer;
if (d % cv < gv) {
answer = static_cast<double>(l) / v;
} else {
answer = static_cast<double>((d / cv + 1) * cycle) +
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long int seed = 50009uLL;
string s[(100010)];
vector<unsigned long long int> h[(100010)];
long long int cnt[(100010)];
unsigned long long int xp[(1000010)];
void init_xp(int n) {
xp[0] = 1;
for (int i = 1; i < n; i++) xp[i] = xp[i - 1] * seed;
}
void... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
long long k;
cin >> n >> m >> k;
long long *arr = new long long[n];
for (int i = 0; i < n; i++) cin >> arr[i];
long long *ans = new long long[n];
for (int i = 0; i < n; i++) {
int ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char a[500];
int ans = 0;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
int x = 0, y = 0;
for (int j = i; j < n; j++) {
if (a[j] == 'U') x++;
if (a[j] == 'R') y++;
if (a[j] == 'L') ... | 1 |
#include <bits/stdc++.h>
long long va = 1e9 + 7;
long long val[200007] = {0};
using namespace std;
long long getmul(long long n) {
long long int k{0};
while (n > 0) {
k += n % 10;
n = n / 10;
}
return k;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t{1};
while (t--) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int MAXN = 1e6 + 9;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-6;
inline int sgn(double x) {
if (x < -EPS) return -1;
return x > EPS;
}
inline int cmp(double x, double y) { return sgn(x - y); }
int n, m;
char a[MAXN], b[MAXN];... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = LLONG_MAX / 10;
const long long MOD = 1e9;
template <typename T>
struct SegmentTree {
using F = function<T(T, T)>;
int n;
F f;
T ti;
vector<T> dat;
SegmentTree(){};
SegmentTree(F f, T ti) : f(f), ti(ti) {}
void init(int n_) {
n = 1;... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 101010;
vector<int> a[N << 1];
pair<int, int> p[N];
int n, q;
long long cross(const pair<int, int>& a, const pair<int, int>& b,
const pair<int, int>& c) {
return (long long)(b.first - a.first) * (c.second - a.second) -
(long long)(c.... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll ans[10];
ll result;
ll sum;
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < 5; ++i) {
ans[i] = (m + i) / 5;
sum += ans[i];
}
result = (ll)n / 5LL * sum;
n %= 5;
for (int i = 1; i <= n; ++i) {
result += ans[i];
}... | 1 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<int> pq;
bool vis[100010];
int main() {
int tc;
cin >> tc;
for (int cs = 1; cs <= tc; cs++) {
int n, r;
scanf("%d%d", &n, &r);
int impact = 0, ans = 0;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
pq.push(x);
... | 2 |
#include <stdio.h>
#include <string.h>
#include <math.h>
#define mpw 10080
#define mpd 1440
double max(double x,double y){
return x>y?x:y;
}
int main(void){
int s, n, t, p, m, i, j, k, w, d, f, e, c;
int rw[8][2] = {{0,mpd*7},{0,mpd*1},{mpd*1,mpd*2},{mpd*2,mpd*3},{mpd*3,mpd*4},{mpd*4,mpd*5},{mpd*5,mpd*6},{mpd*6,m... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int f[maxn][maxn];
int dp[maxn][maxn];
int g[maxn][maxn];
char s[maxn], ss[maxn], ans[5 * maxn];
int K, n, l;
void init() {
int i, j, k;
l = strlen(s);
for (i = 0; i < l; i++) ss[i + 1] = s[i];
memset(f, 0, sizeof(f));
for (k = 2; k <= l; k++... | 4 |
#include <bits/stdc++.h>
using namespace std;
void OJ() {}
void solve() {
string s;
cin >> s;
string temp = "";
int alice = 0, flag = 0, l;
while (1) {
int cnt = 0, mx_cnt = 0, mx_l = -1, mx_r = -1, d_l = -1;
l = s.size();
for (int i = 0; i < l; i++) {
if (s[i] == '0')
cnt = 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<int> A[N];
vector<int> Q[2][N];
bool M[N], IS[N];
vector<int> Nxt[N];
int flag = 0;
void dfs(int No) {
if (IS[No]) {
flag = -1;
return;
}
for (auto i : Nxt[No]) {
if (!M[i]) {
M[i] = true;
dfs(i);
}
}
}
int ... | 5 |
#include <bits/stdc++.h>
const int MAXN = 3e5 + 5;
int color[MAXN]{};
std::vector<int> graph[MAXN]{};
std::vector<int> brt[MAXN]{};
int dis[MAXN]{};
int* low = color;
int* pre = dis;
std::set<std::pair<int, int> > bridges;
int bcc, far, ord, m, n;
std::pair<int, int> make_edge(int u, int v) {
if (u > v) std::swap(u, ... | 5 |
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#define MAXN 200010
using namespace std;
vector<int> E[MAXN];
int n,maxlen=-1,v;
void dfs(int u,int fa,int dep){
if(dep>maxlen){
maxlen=dep;
v=u;
}
for(int i=0;i<E[u].size();i++){
int to=E[u][i];
if(... | 0 |
#include <bits/stdc++.h>
using namespace std;
int N, tmp, p[100010], b[100010];
multiset<int> s;
int main() {
cin >> N;
for (int i = 1; i <= N; i++) scanf("%d", &tmp), p[tmp] = i;
for (int i = 1; i <= N; i++) scanf("%d", b + i), s.insert(i - p[b[i]]);
for (int i = 1; i <= N; i++) {
int ans = 1e9;
multis... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
struct Point {
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
} coordinate[350];
Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); }
Point operator-(Point A, Point B) { return Point(A.x - B.x, A.y - B.y); }
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long x, l = -2000000000, h = 2000000000;
cin >> n;
string s;
char c;
for (int i = 0; i < n; i++) {
cin.ignore();
getline(cin, s, ' ');
cin >> x >> c;
if ((s == ">=" && c == 'Y') || (s == "<" && c == 'N'))
l = max(l, x);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
const long long INF = (long long)1e18;
int val[N + 5], cst[N + 5];
long long pref[N + 5];
long long f(int l, int r) {
if (l > r) return 0;
return pref[r] - pref[l - 1];
}
class ST {
long long suff[4 * N + 5];
int n;
void build(int idx, int l, in... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> v(n + 1);
for (int i = 1; i <= n; i++) cin >> v[i];
for (int i = k; i < n; i++) {
if (v[i] != v[i + 1]) {
cout << "-1";
return 0;
}
}
int val = v[k], i;
for (i = k - 1; i >= 0; i--) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<int> v(m + 1, -1);
int a, b;
for (int i = 0; i < n; i++) {
cin >> a >> b;
if (b <= v[a] || v[a] == -1) v[a] = b;
}
int ans = 0;
for (int i = 1; i <= m; i++) {
if (v[i] == -1) v[i] = 0;
ans ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long int i, j, n, m;
cin >> n >> m;
long int a[n], b[m], c[n], d[m];
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < m; i++) {
cin >> b[i];
}
c[0] = a[0];
for (i = 1; i < n; i++) {
c[i] = c[i - 1] + a[i];
}
d[0] = b[0]... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
string s, t;
int q;
int trailingS[maxn], trailingT[maxn], bS[maxn], bT[maxn], trailingCnt = 0,
bCnt = 0;
int main() {
cin >> s >> t >> q;
for (int i = 0; i < s.size(); i++) {
if (s[... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[1000];
struct p {
int id, num;
} e[1000];
bool com(p x, p y) { return x.num > y.num; }
int max(int x, int y) { return x > y ? x : y; }
int main() {
int i = 0, n = 0, k = 0, ss = 0;
cin >> n >> k;
for (i = 1; i <= 2 * n + 1; i++) {
scanf("%d", &a[i]);
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long tree[1000000];
int flag[1000000];
;
void update(int l, int x, int y, int r, long long v, int n) {
if (l == x && r == y) {
tree[n] = v;
flag[n] = 1;
return;
}
if (flag[n] == 1) {
tree[2 * n] = tree[2 * n + 1] = tree[n];
flag[2 * n] = flag[... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 5;
long long a[maxn];
bool ne[maxn];
int main() {
long long n, k, x;
scanf("%lld %lld %lld", &n, &k, &x);
long long mi = INT_MAX;
long long pos = -1;
bool f = 0;
for (long long i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
if (... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;cin>>s;
if(s.size()==3){
cout<<s[2]<<s[1]<<s[0]<<endl;
} else {
cout<<s<<endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, inch, feet;
int main() {
cin >> n;
inch = int((double)n / 3 + 0.5);
feet = inch / 12;
inch %= 12;
cout << feet << " " << inch << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
long long a[maxn + 10], la[maxn + 10];
int main() {
long long n, num, ans, i;
while (scanf("%lld", &n) != EOF) {
for (i = 1; i <= n; i++) scanf("%lld", &a[i]);
for (i = 0; i <= maxn; i++) la[i] = 0;
ans = 0;
for (i = 1; i <= n; ... | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.