solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
struct FastIO{
FastIO(){
cin.tie(0);
ios::sync_with_stdio(0);
}
}fastio_beet;
//I... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int Max_N = 1e3;
int n, fir, tot, lst[Max_N + 5], bln[Max_N + 5], nxt[Max_N + 5], vis[Max_N + 5],
ans[Max_N + 5][Max_N + 5];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &nxt[i]);
for (int i = 1; i <= n; i++) lst[nxt[i]] = i;
for ... | 5 |
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int a,b,c,d;
cin >> a >> b >> c >> d;
if((a==b&&c==d)||(a==c&&b==d)||(a==d&&b==c)){
cout << "yes" << endl;
}else{
cout << "no" << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 5, M = 1e9 + 7;
long long a[N];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
long long n, m = 0;
cin >> n;
for (long long i = 1; i <= n; i++)
cin >> a[i], m = max(m, a[i]), a[i] ^= a[i - 1];
for (long long i = 1; i <= n; i++)
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double eps(1e-8);
int n, k;
char s[4][410];
int sx, sy;
queue<pair<int, int> > Q;
int dp[100][4][400];
void solve() {
for (int i = 0; i < 3; i++)
for (int j = 0; j < n; j++)
if (s[i][j] == 's') {
sx = i, sy = j;
break;
}
s[sx][sy] =... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, dl, nv, l, r, z, t, ves, ans;
string s, sn;
map<pair<long long, long long>, long long> a;
char el;
int main() {
cin >> z;
for (int i = 1; i <= z; i++) {
cin >> t;
if (t == 1) {
cin >> l >> r >> ves;
while (l != r) {
if (l > r) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline void Boost() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main() {
Boost();
int a, b, n;
cin >> a >> b >> n;
for (int i = 0; i <= 9; ++i) {
int x = a * 10 + i;
if (x % b == 0) {
cout << a << i;
for (int j = 0; ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1E-6;
const int MOD = 1000000007;
const int LEN = 2010;
int dp[LEN][1 << 12], n, m, num[LEN];
void debug() {
for (int j = 0; j <= n; j++) {
for (int i = 0; i <= (1 << (m - 1)); i++) cout << dp[j][i] << ' ';
cout << en... | 4 |
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
int D,N,M;
while(cin>>D,D)
{
cin >> N >> M;
vector<int> v;
v.push_back(0);
while(--N)
{
int d;
cin >> d;
v.push_back(d);
}
v.push_back(D);
sort(v.begin(), v.end());
int a = 0;
while(M--)
{... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 256;
int cnt[N];
string s, t;
bool dfs(string& s, int pos, bool large) {
if (pos == t.length()) return large || ::s.length() > t.length();
if (large == false) {
if (cnt[t[pos]]) {
cnt[t[pos]]--;
s += t[pos];
if (!dfs(s, pos + 1, 0)) {... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
vector<long long int> v(n);
if (n == 1) {
cout << "no" << endl;
return 0;
}
for (long long int i = 0; i < n; i++) {
cin >> v[i];
}
vector<pai... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 200005;
const int MD = 998244353;
void add(int& a, int b) {
a += b;
if (a >= MD) a -= MD;
}
void sub(int& a, int b) {
a -= b;
if (a < 0) a += MD;
}
int mod_mult(long long a, long long b) { return (a * b) % MD; }
int h[MX];
int fact[MX];
int inv_fact[M... | 4 |
#include <bits/stdc++.h>
const int maxn = 3000 + 3;
int a[maxn];
int b[maxn];
std::bitset<maxn> C[maxn];
int main() {
std::vector<std::pair<int, std::pair<int, int> > > Edge;
int n;
std::cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d%d", &a[i], &b[i]);
}
for (int i = 1; i <= n - 1; i++) {
for (i... | 5 |
#include <iostream>
#include <string>
#define MAX 10
#define INF 1 << 29
using namespace std;
int cost[MAX][MAX];
void warshall_floyd() {
for (int k = 0; k < MAX; k++) {
for (int i = 0; i < MAX; i++) {
for (int j = 0; j < MAX; j++) {
cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
}
}
}
}
int ... | 0 |
#include<cstdio>
typedef long long LL;
int N,i,j,x,A[200000],here[200000],town[200000];LL K;
int main(void)
{
i=scanf("%d %lld",&N,&K);
for(i=0;i<N;i++)here[i]=-scanf("%d",&A[i]);
for(i=0,j=0;;i=A[i]-1,j++)if(here[i]<0)here[i]=j,town[j]=i;else{x=here[i];break;}
if(K>=j)K=(K-x)%(x-j)+x;
return printf("%d\n",to... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v[105];
pair<pair<int, int>, double> edge[105];
void dfs(int first, int f, double d) {
double ti = 2.0 / (v[first].size());
double now = fmod(d + ti, 2);
for (auto it : v[first]) {
if (it.first != f) {
dfs(it.first, first, fmod(now + ... | 6 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
int N;
cin >> N;
cout << "?";
for (int i = 1; i <= N; i++) cout << " " << i;
cout << endl;
string s;
cin >> s;
int l = 1;
int r = N+1;
while (r - l > 1) {
int c = (l+r)/2;
cout <<... | 0 |
/* #region header */
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
// types
using ll = long long;
using ull = unsigned long long;
using ld = long double;
typedef pair<ll, ll> Pl;
typedef pair<int, int> Pi;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vc;
template <t... | 1 |
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<set>
using namespace std;
char A[310000];
char B[310000];
int p[310000];
int q[310000];
int bit[310000];
set<int>zero;
set<int>two;
set<int>bb;
int sum(int a,int b){
if(a)return sum(0,b)-sum(0,a-1);
int ret=0;
for(;b>=0;b=(b&(b+1))-1)ret+=bit[b];
ret... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5, lg = 20;
long long cnt[maxn][lg], c[maxn], mod = 1e9 + 7;
int par[maxn][lg], h[maxn], p[maxn];
vector<int> adj[maxn], nei[maxn];
bool mark[maxn];
void dfs(int v) {
mark[v] = true;
for (int u : adj[v]) {
if (!mark[u]) {
h[u] = h[v] + 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 10e5 + 500;
const long long md = 1000000007;
const int iINF = 0x7f7f7f7f;
long long mypow(long long a, long long e) {
return e ? (e & 1 ? mypow(a, e - 1) * a % md : mypow(a * a % md, e >> 1)) : 1;
}
long long gcd(long long a, long long b) { return b ? gc... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return (!b ? a : gcd(b, a % b)); }
long long lcm(const long long &a, const long long &b) {
return a / gcd(a, b) * b;
}
const int N_MAX = 1e4;
long long arr[N_MAX];
long long pwr(long long a, long long p, const long long &mod) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int visited[200001];
char c[1000][1000];
long long int leaf[200001], leafc;
long long int dp[200001], ind[200001], dist[200001];
vector<pair<long long int, long long int>> at_leaf(200001);
int32_t main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.ti... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 1;
int a[6];
int n;
int b[MAXN];
int ptr[MAXN];
int f[MAXN][6];
int main() {
for (int i = 0; i < 6; ++i) cin >> a[i];
cin >> n;
for (int i = 0; i < n; ++i) cin >> b[i];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 6; ++j) {
f[i]... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010, mod = 1e9 + 7;
const long long inf = 1e18;
vector<int> v[maxn], va, vb, vc, vd, vv;
int pr[maxn];
bitset<maxn> bs;
void fnd(int a, int &A) {
while (a != 1) {
A = a;
a = pr[a];
}
}
int dfs(int u) {
int ans = (int((v[u]).size()) == 0);
f... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int fuck(int a) {
long long int sum = 1;
for (int i = 1; i <= a; i++) sum *= 2;
return sum;
}
int main() {
int sum = 0;
long long int a, b, x, y;
cin >> x >> y;
sum = 0;
for (int i = 2; i <= 60; i++) {
a = fuck(i) - 2;
if (a >= x && a <= y)... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 5;
const int LOG = 21;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long modP(long long a, long long b) {
return (!b ? 1 : (modP(a, b / 2) * modP(a, b / 2)... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[111111];
int v[111111], good[111111];
int main() {
int n;
int m;
cin >> n;
cin >> m;
int s;
int t;
for (int i = 0; i < m; i++) {
cin >> s;
cin >> t;
adj[s].push_back(t);
adj[t].push_back(s);
}
for (int i = 0; i < n; i++) v[i... | 5 |
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;
int main() {
bool flag = true;
int N, M, ans = 0, a[50] = {}, b[50] = {}, C[50] = {}, k = 0;
cin >> N >> M;
for (int i = 0; i < M; i++)
{
cin >> a[i] >> b[i];
C[a[i]-1]++;
C[b[i]-1]++;
}
w... | 0 |
#include<iostream>
using namespace std;
int main(){
long long int A;
float B;
cin>>A>>B;
int C=(int)(100*B+0.1);
cout<<A*C/100;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
vector<long long> v(n + 1);
for (long long i = 1; i <= n; i++) cin >> v[i];
long long f = 0;
for (long long i = 1; i <= n; i++) {
if (v[v[v[v[i]]]] == v[i]) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int const N = 2e5 + 10;
int n, T, m;
int main() {
cin >> T;
while (T--) {
int a, b, c;
cin >> a >> b >> c;
cout << (long long)a + b + c - 1 << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
bool mycomp(const pair<int, int>& A, const pair<int, int>& B) {
return A.first < B.first;
}
int main() {
int n, v;
cin >> n >> v;
vector<pair<int, int> > P;
set<int> ss;
int hash[3003];
memset(hash, 0, sizeof(hash));
pair<int, int> a;
for (int i = 0; i < n... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2020;
const double eps = 1e-8;
int n, a, b, opt[maxn][maxn];
double dp[maxn][maxn], pa[maxn], pb[maxn], pab[maxn];
int solve(double mid) {
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= a; j++) {
double &d = dp[i][j];
int &o = opt[i][... | 5 |
#include <iostream>
#include <tuple>
#include <queue>
#include <cmath>
#include <iomanip>
using namespace std;
constexpr double eps = 1e-10;
using data = tuple<int, double, double, double>;
int main() {
int K;
double R, L;
double P, E, T;
cin >> K >> R >> L >> P >> E >> T;
queue<data> que;
qu... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int mx = 200100;
const int md = 1000000007;
const double EULER = 2.71828182845904523536;
int n, arr[1000100] = {}, x, belum = 0, ans = 0;
int main() {
scanf("%d", &n);
ans = n;
for (int i = 0; i < n; i += 1) {
scanf("%d", &x);
arr[max(0, i - x)]++;
a... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if (a >= b) {
cout << b << " ";
a = a - b;
cout << a / 2;
} else {
cout << a << " ";
b = b - a;
cout << b / 2;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
const long double pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
char c;
int flag = 1;
while ((c = getchar()) < '0' || c > '9')
if (c == '-') flag *= -1;
x = c - '0';
while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
x *= flag;
return;
}
inline void read(long long &x) {
char c... | 5 |
#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, h, m;
string s, c, t;
bool Check() {
if (m == 60) m = 0, ++h;
if (h == 24) h = 0;
c = "";
t = "";
char f;
f = h / 10 + 48;
c = f;
f = h % 10 + 48;
c += f;
f = m / 10 + 48;
t = f;
f = m % 10 + 48;
t += f;
if (c[0] == t[1] && t[0] =... | 1 |
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
vector<int> nex[214514];
int bg[214514],pa[214514];
int modpow(int x,int k){
// x ^ k mod inf
int res = 1;
while(k>0){
if(k%2)r... | 0 |
#include <bits/stdc++.h>
enum ops { NONE, AND, OR, XOR };
struct Variable {
bool isExpr;
std::string value;
std::string lArgName;
Variable *lArg;
ops op;
std::string rArgName;
Variable *rArg;
Variable() {}
Variable(bool isExpr, const std::string &value, const std::string &lArgName,
ops op, ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string a;
cin >> n >> a;
int D[n];
D[0] = 1;
for (int i = 1; i < n; i++) {
if (a[i] != a[i - 1]) {
D[i] = D[i - 1] + 1;
} else {
D[i] = D[i - 1];
}
}
int ans = D[n - 1];
cout << min(n, ans + 2);
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int n, m, vis[101][101], cnt;
string s[101];
int dfs(int x, int y) {
if (x < 0 || x >= n || y < 0 || y >= m || vis[x][y] || s[x][y] == '.')
return 0;
vis[x][y] = 1;
for (int i = 0; i < 4; i++) dfs(x + dx[i], y + ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 405;
struct Edge {
int from, to, nxt, cap, flw;
double cost;
} e[N * N * 4];
int x[N], y[N], n, edgeCnt, head[N << 1], flw[N << 1], vis[N << 1], p[N << 1],
src, snk;
double dist[N << 2], d[N][N];
void addEdge(int u, int v, int cap, double cost) {
e[e... | 5 |
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int A[200005] , T[200005];
int main() {
int N;
cin >> N;
ll ans = 0;
for(int i = 0; i < N; i++){
cin >> A[i];
ans+=T[A[i]];
T[A[i]]++;
}
for(int i = 0; i < N; i++){
cout << ans - T[A[i]] + 1 << en... | 0 |
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
string s;
cin >> s;
int fn='A';
int cou=0;
//cout << fn << endl;
for(int i=0;i<s.size();i++){
if(s[i] <= fn )cou++;
fn=s[i];
}
cout << cou << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 205;
vector<int> adj[N], mem[N];
int cap[N][N], edge[N][N], visit[N], p[N], n, source, sink, a[N], cnt, max_flow;
int is_prime(int a) {
for (int i = 2; i * i <= a; i++)
if (a % i == 0) return 0;
return 1;
}
void add(int u, int v, int _cap) {
adj[u].p... | 3 |
#include<iostream>
using namespace std;
int a[301][301];
bool ok[301][301];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
}
}
for(int k=1;k<=n;k++)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i!=j&&i!=k&&j!=k)
{
if(a[i][j]>a[i][... | 0 |
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = double;
const ld eps = 1e-9;
//
//using Graph = vector<vector<int>>;
//
//int dfs(const Graph&g, const int now, vector<int>&ch_cnts) {
// ch_cnts[now]++;
// for (auto&& e : g[now]) {
... | 0 |
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<assert.h>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typed... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, a, b;
long long val;
cin >> t;
while (t--) {
cin >> a >> b;
if (!(a % b)) {
puts("0");
} else if (b > a) {
cout << b - a << endl;
} else {
val = a / b + 1;
cout << b * val - a << endl;
}
}
return 0;... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sum = 0;
cin >> n;
while (n--) {
int a, b, c, d = 0, e = 0, f = 0;
cin >> a >> b >> c;
if (a + b == 2) {
d += 1;
}
if (b + c == 2) {
e += 1;
}
if (a + c == 2) {
f += 1;
}
if (d + e + f > 0) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long freq[n], arr[n];
for (long long i = 1; i <= n; i++) {
cin >> arr[i];
freq[arr[i]] = i;
}
long long ans = 0;
for (long long i = 1; i < n; i++) {
ans += abs(freq[i] - freq[i + 1]);
}
cout << ans << en... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, k, i, x, j, v[10], nr, ok;
int main() {
cin >> n;
cin >> k;
for (i = 1; i <= n; i++) {
cin >> x;
for (j = 0; j <= 9; j++) v[j] = 0;
do {
v[x % 10] = 1;
x /= 10;
} while (x);
ok = 1;
for (j = 0; j <= k; j++) {
if (v[j] =... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int n, m, K, a[N];
struct data {
long long ans;
vector<pair<int, int> > l, r;
data() {
l.clear();
r.clear();
ans = 0;
}
data(int x) {
l.clear();
r.clear();
l.emplace_back(x, 1);
r.emplace_back(x, 1);
ans = (x >... | 6 |
// Created by liszt on 2019/07/21.
#include<bits/stdc++.h>
using namespace std;
int main(){
string s; cin>>s;
int a=0,b=0;
for(int i=0;i<s.size();i++){
if((i%2)^(s[i]=='1'))a++;
else b++;
}
cout<<(a<b ? a : b)<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[(int)(2 * 1e5 + 10)];
long long pa[(int)(2 * 1e5 + 10)];
long long sa[(int)(2 * 1e5 + 10)];
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
pa[i] = 1ll * a[i] + pa[i - 1];
}
for (int i = n; i >= 1; --i) {
sa[i] = 1ll * a[i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a[100010], n, x, ans = 0, mini = 20000000000;
scanf("%lld%lld", &n, &x);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
mini = min(mini, a[i]);
}
while (a[x] != mini) {
a[x]--;
ans++;
x--;
if (x == 0) x = n;
}... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
const int inf = 0x3f3f3f3f, Inf = 0x7fffffff;
const long long INF = 0x7fffffffffffffff;
const double eps = 1e-8;
unsigned int seed = 19260817;
const unsigned int _RAND_MAX_ = 4294967295u;
__inline__ __attribute__((always_inline)) unsigned int Rand() {
return seed = see... | 5 |
#include <bits/stdc++.h>
using namespace std;
const char radix[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
const... | 3 |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
int N, M;
cin >> N >> M;
vector<ll> a[3];
for (int i = 0; i < N; i++) {
for (int j = 0; j < 3; j++) {
ll n; cin >> n;
a[j].push_back(n);
}
}
ll res=0;
for (int bit = 0; bit < (1 << 3); bit++) {
vector<ll> b;
for (int... | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N;
vector<ll> par;
void initialize(){
for(ll i = 1; i < 10000000; i++){
par[i] = i;} //始めは任意のノードの親が自分自身
}
ll root(ll x){
if(par[x] == x){ return x;}
else{ return par[x] = root(par[x]);}}
void unite(ll x, ll y){
if( root(x) == root(y)){ return;}
els... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long n;
long long k, a[107], f[107][107] = {}, res[107][107] = {}, result = 0;
void mul(long long a[107][107], long long b[107][107]) {
long long res[107][107] = {};
for (long long i = 0; i < n; i++)
for (long long j = 0; j < n; j... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int pw[100005], mn[35];
vector<int> bit[35];
int idx[35];
int main() {
pw[0] = 1;
for (int i = 1; i <= 100000; i++) pw[i] = (pw[i - 1] * 2) % mod;
for (int i = 0; i <= 21; i++) mn[i] = 1e9, idx[i] = 1;
mn[0] = 0;
int n, q;
scanf("%d%d", ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5100;
int dp[N][N], x[N], n, m;
void read() {
string junk;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> x[i] >> junk;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
read();
for (int i = 1; i <= n; i++)
for (int ... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b; cin>>a>>b;
cout<<(a-1)*(b-1);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
long long dp[N][2][2];
int arr[N];
int n;
long long solve(int idx, bool take, int sign) {
if (idx == n) return 0;
long long& cur = dp[idx][take][sign + 1];
if (cur != -1) return cur;
if (take) {
return cur = max(0l... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
template <class T>
bool cmn(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool cmx(T &a, T b) {
return a < b ? (a = b, true) : false;
}
int main() {
ios_base::sync_with... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int a;
cin >> n >> a;
double angleone = 180.0 / n;
double min = 180;
int minn = 0;
for (int i = 1; i <= n - 2; i++) {
if (abs(i * angleone - a) < min) {
min = abs(i * angleone - a);
minn = i;
}
}
cout << "2 1 " << mi... | 2 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int c, int n) {
int mi = min(c, n);
int xm = max(c, n);
if (mi == 0) return xm;
while (xm % mi != 0) {
int m = mi;
mi = xm % mi;
xm = m;
}
return mi;
}
int main() {
string s;
getline(cin, s);
bool b[125];
int ans = 0;
memset(b, fals... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
const int sqrtN = 512;
const ll inf = (1LL<<31)-1;
int n, q;
cin >> n >> q;
int bucket_sz = (n+sqrtN-1)/sqrtN;
vector<ll> a(n, inf);
vector<ll> bucketMin(bucket_sz, inf);
vector<ll> bucketUp(bucket_sz, 0);
vector<bool>... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c;
cin >> n >> c;
vector<int> a(n), b(n);
for (int i = 1; i < n; i++) {
cin >> a[i];
}
for (int i = 1; i < n; i++) {
cin >> b[i];
}
int dp[n][2];
memset(dp, 0, sizeof(dp));
dp[0][1] = c;
for (int i = 1; i < n; i++) {
dp[... | 5 |
#include <bits/stdc++.h>
using namespace std;
double a, b, c;
double A, B, C;
double S;
double R;
const double pi = acos(-1);
void getAngle() {
A = acos((b * b + c * c - a * a) / (2 * b * c));
B = acos((a * a + c * c - b * b) / (2 * a * c));
C = acos((b * b + a * a - c * c) / (2 * b * a));
}
double getArea() { re... | 3 |
#include <bits/stdc++.h>
using namespace std;
int power[32] = {0};
bool compar(vector<int> &v1, vector<int> &v2) { return v1 < v2; }
void solve() {
int n;
cin >> n;
vector<pair<vector<int>, int>> v1, v2;
vector<int> p(n + 1);
for (int j = 1; j <= n; j++) {
cin >> p[j];
}
for (int i = 0; i < power[15];... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, d, i, j, h, k, ans, cnt, f, mans = -1;
int a[105][105];
int main() {
scanf("%d%d%d", &n, &m, &d);
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
scanf("%d", &a[i][j]);
}
}
for (h = 1; h <= n; h++) {
for (k = 1; k <= m; k++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int binarySearch(int arr[], int l, int r, int x) {
while (l <= r) {
int m = l + (r - l) / 2;
if (arr[m] == x) return m;
if (arr[m] < x)
l = m + 1;
else
r = m - 1;
}
return -1;
}
int main() {
string n;
getline(cin, n);
n.erase(remove(n... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (a < b) a = b;
}
template <typename T>
inline void gn(T &first) {
char c, sg = 0;
while (c = getchar(), (c > '9' ||... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
long long n, m, a[maxn], ans, d[maxn];
pair<long long, long long> b[maxn];
vector<long long> g[maxn];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (long long i = 1; i <= n; i++) {
cin >> a[i];
b[i] = make_pair(a... | 3 |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long Mode = 1e9 + 7;
void Modulo(unsigned long long &x) { x = ((x % Mode + Mode) % Mode); }
unsigned long long Pow(unsigned long long x, unsigned long long y) {
unsigned long long res = 1;
for (unsigned long long i = 0; (1ULL << i) <= y; i++, x *= x,... | 3 |
#include <bits/stdc++.h>
char str1[1001], str2[1001];
int main() {
gets(str1);
gets(str2);
int len1 = strlen(str1);
int len2 = strlen(str2);
int cnt1 = 0, cnt2 = 0;
int i;
for (i = 0; i < len1; i++)
if (str1[i] == '1') cnt1++;
for (i = 0; i < len2; i++)
if (str2[i] == '1') cnt2++;
if (cnt1 & 1... | 3 |
#include <iostream>
using namespace std;
int a[200005],n;
bool b[200005];
inline bool pd(int x){
for(int i=1;i<=n*2-1;i++)
b[i]=(a[i]>=x);
b[0]=b[1];
for(int i=n;i<=n+n-1;i++){
if(b[i]==b[i+1]) return b[i];
if(b[n+n-i]==b[n+n-i-1]) return b[n+n-i];
}
return b[1];
}
int main(int argc, char** argv) {
cin >> n... | 0 |
#include <bits/stdc++.h>
int n;
int cnt, first[200010];
struct edge {
int v, nx;
} o[500010];
void add(int u, int v) { o[++cnt].v = v, o[cnt].nx = first[u], first[u] = cnt; }
int f[200010], du[200010], size[200010], fac[200010];
void dfs(int x, int fa) {
f[x] = size[x] = 1;
du[x] = 0;
for (int i = first[x]; i; ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long m, ans, a[110], k;
long long Div(long long x, long long y) { return (x + y - 1) / y; }
int main() {
long long i, last, sum, cnt;
int j;
scanf("%d%I64d", &n, &k);
for (j = 1; j <= n; j++) scanf("%I64d", &a[j]), m = max(m, a[j] + k);
for (i = m; i; ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
if (s.find('B') == -1)
cout << 0;
else {
int a[100] = {0}, k = 0, l = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == 'B')
k++;
else if (s[i - 1] == 'B') {
a[l++] = k... | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
constexpr int MAXN = 400;
ll dp[MAXN + 2][MAXN + 2];
ll a[MAXN + 2];
int main() {
int N;
cin >> N;
for(int i = 1; i <= N; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
for(int i = 2; i <=... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a, b, n;
int main() {
cin >> a >> b;
if (b == 10 && a == 1)
cout << -1;
else {
if (b == 10) {
for (n = 1; n < a; n++) cout << 1;
cout << 0;
} else
for (n = 1; n <= a; n++) cout << b;
}
cout << endl;
}
| 1 |
#include <cstdio>
int main(int argc, char *argv[]) {
int sum;
while (true) {
fscanf(stdin, "%d", &sum);
if (sum==0) break;
int tmp, hits=0;
for (int i = 0; i < sum/4; i++) {
scanf("%d", &tmp);
hits+=tmp;
}
printf("%d\n", hits);
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int n7 = 1201234;
const long long mo = 998244353;
int n, m, a[n7];
long long g[n7];
int rd() {
int shu = 0;
char ch = getchar();
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) shu = (shu << 1) + (shu << 3) + (ch ^ 48), ch = getchar();
return shu;
}... | 5 |
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
int a,b,x;
int i,j;
cin>>a>>b>>x;
int mn=10000007;
for(i=0;i<=x/1000+1;i++){
for(j=0;j<=x/500+1;j++){
if(1000*i+500*j>=x && mn>a*i+b*j){
mn=a*i+b*j;
}
}
}
cout<<mn<<endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
ios::sync_with_stdio(false);
long long p, k;
cin >> p >> k;
if (k == 0) {
long long res = 1;
for (long long i = 1; i < p; i++) {
res = (res * p) % mod;
}
cout << res << endl;
} else if (k == 1) {... | 4 |
#include <iostream>
using namespace std;
int main(){
int n, l, a[100000] = {}, pre = 0;
long long int max = -1, sum = 0;
cin >> n >> l;
for(int i = 0;i<n;i++){
cin >> a[i];
a[i] = l - a[i];
}
pre = 0;
sum = 0;
for(int i = 0;i<n;i++){
if(pre < a[i]) {
pre = a[i];
sum = a[i];
}
else sum += a[i];
... | 0 |
#include<iostream>
#include<cstring>
using namespace std;
int x[1180][118][118], n, m, p, a, b, c;
int main() {
while (true) {
memset(x, 0, sizeof(x));
cin >> n >> m >> p; if (!n) { break; }
for (int i = 0; i < m; i++) {
cin >> a >> b >> c;
x[a][b][c] = 1; x[a][c][b] = 1;
}
for (int i = 1000; i > 0; i-... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 101;
int a[N][N];
int main() {
int n, m, k;
cin >> n >> m >> k;
int sum = 0, cnt = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) cin >> a[i][j];
for (int j = 1; j <= m; j++) {
int maxscore = 0, one = 0, tt = 0;
for (int i =... | 3 |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("AAtest.in.txt");
double a, b, p, first, c = 0.000000001, vas = -1;
double arv(double alfa) {
return ((b - (p * sin(alfa) - a) / tan(alfa)) * sin(alfa));
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cerr.tie(0);
cin >> a >> b >> ... | 5 |
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000
using namespace std;
int main(){
int n,k,s;
while(cin >> n >> k >> s){
if(n == 0 && k == 0 && s == 0) break;
int dp[30][30][200]={};
for(int i=0; i<=n; i++) dp[i][0][0] = 1;
for(int i=1; i<=n; i... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
string s;
int ans;
signed main(){
while (cin >> s && s > "0"){
ans = 0;
for (int i = 0; i < s.length(); i++){
ans += s[i] - '0';
}
cout << ans << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, m;
cin >> x >> y >> m;
bool is = false;
vector<vector<int>> v(x + 2, vector<int>(y + 2, 0));
for (int i = 0; i < m; i++) {
int xt, yt;
cin >> xt >> yt;
v[xt][yt] = 1;
if ((v[xt + 1][yt] == 1 && v[xt][yt + 1] == 1 && v[xt + 1]... | 1 |
#include <iostream>
using namespace std;
double x[5], y[5];
bool check() {
double xa[3], ya[3], s[3];
bool in[2], b[3];
for (int i=0; i<3; i++) {
xa[i] = y[(i+1)%3] - y[i];
ya[i] = -x[(i+1)%3] + x[i];
s[i] = xa[i]*x[i] + ya[i]*y[i];
}
for (int i=0; i<2; i++) {
for (int j=0; j<3; j++) {
... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.