Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; struct dancer { int g; int p; int t; int id; }; int n, xs, ys; map<int, vector<dancer>> groups; map<int, pair<int, int>> finalPos; bool s1(dancer a, dancer b) { if (a.g != b.g) return a.g > b.g; if (a.g == 1) return a.p < b.p; else return a.p > b.p; } ...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e5 + 10; void file(string s) { freopen((s + ".in").c_str(), "r", stdin), freopen((s + ".out").c_str(), "w", stdout); } long long read() { long long f = 1, a = 0; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f =...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.StringTokenizer; /** * @author Don Li */ public class RooterSong { int N = (int) 1e5; int n, w, h; int[...
JAVA
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
import java.io.*; import java.util.*; public class B { /* 3 5 5 2 1 2 2 2 3 2 3 4 */ static InputStream is; static int X,Y; public static void main(String[] args) throws IOException { is = System.in; int n = ni(); X = ni(); Y = ni(); TreeMap<Integer,ArrayList<d>> tm = new TreeMap<>(); d[] ds ...
JAVA
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
var l1 = readline().split(' '); var n = +l1[0]; var w = +l1[1]; var h = +l1[2]; var src = new Array(n); var dest = new Array(n); for(var i = 0; i < n; i++) { var line = readline().split(' '); var p = +line[1], t = +line[2]; var x1, y1, x2, y2; if(line[0] == '1') { // vertical x1 = p; y1 = -t; ...
JAVA
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; const long long MAX = 1000005; long long n; long long g[MAX], p[MAX], t[MAX], b[MAX]; basic_string<long long> a[2][2 * MAX]; long long w, h; bool cmp(long long i, long long j) { return p[i] < p[j]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; int n, h, w, g[N], p[N], t[N], ansx[N], ansy[N]; vector<int> v[3 * N]; int main() { scanf("%d%d%d", &n, &w, &h); for (int i = 0; i < n; i++) { scanf("%d%d%d", g + i, p + i, t + i); v[p[i] - t[i] + N].push_back(i); } fill(ansx, ansx + N...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; int n, w, h; struct ed1 { int x, y, clas, id, ANSx, ANSy; } p[100099]; struct ed2 { int x, y, clas; } ans[100099]; bool cmp1(const ed1 &A, const ed1 &B) { if (A.clas != B.clas) return A.clas < B.clas; return A.x < B.x; } bool cmp2(const ed2 &A, const ed2 &B) { if ...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
import java.io.*; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.StringTokenizer; public class Codeforces849D { static class DancerComparator implements Comparator<int[]> { public int compare(int[] o1, int[] o2) { int l1 = o1[1] - o1[2]; int l2 = o2[1] - o2...
JAVA
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int sum[maxn], g[maxn], p[maxn], t[maxn], ans[maxn][2]; vector<int> type[maxn << 1]; struct node { int x, y, id; }; struct node tmpans[maxn]; struct node tmpst[maxn]; bool cmp(node t1, node t2) { return t1.y == t2.y ? t1.x > t2.x : t1.y < t2.y; ...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; vector<int> pt[2][maxn + maxn]; int g[maxn], p[maxn], t[maxn], anid[maxn]; pair<int, int> ans[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, w, h; cin >> n >> w >> h; for (int i = 0; i < n; ++i) { cin >> g[i...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > arr1[200100][2]; int arr[100009][3]; int ans[100009][2]; int main() { int n, w, h; cin >> n >> w >> h; int a, b, c; for (int f = 0; f < n; f++) { cin >> a >> b >> c; arr1[c - b + 100000][a - 1].push_back({b, f}); arr[f][0] = a; ...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> 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; } using namespace std; const int maxn = 1e5 + ...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; template <class A, class B> A cvt(B x) { stringstream ss; ss << x; A y; ss >> y; return y; } int n, w, h; int main() { scanf("%d %d %d", &n, &w, &h); map<int, vector<pair<int, int> > > diag, exits; for (int i = 0; i < (int)(n); i++) { int g, p, t; sc...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; } template <typename T1, typename T2> inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; } inline int readChar(); template <class T = int> inline T readInt(); template <class T> inl...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef pair<set<pii>, set<pii> > line; map<int, line> lines; int n, w, h; void insert_dancer(int type, int pos, int t, int i) { int line_number = pos - t; if (type == 1) lines[line_number].first.insert(pii(pos, i)); else if (type == 2)...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 2e5 + 10; map<int, vector<tuple<int, int, int>>> mc[3]; pair<int, int> ans[N]; vector<tuple<int, int, int>> check(const vector<tuple<int, int, int>>& vp1, const vector<tuple<int, int, int>>& vp2...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.io.FilterInputStream; import java.io.BufferedInputStream; import java.io.InputStream; /** * @author khokharnikunj8 */ public class Main { public static void main(...
JAVA
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; vector<int> arr[N][2]; vector<pair<int, int>> mp[2 * N]; vector<array<int, 3>> v; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, w, h; cin >> n >> w >> h; for (int i = 0; i < n; i++) { int g, p, t;...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; const int OO = 1e9; const long long INF = 1e18; const int irand(int lo, int hi) { return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo; } const long long lrand(long long lo, long long hi) { return ((double)rand() / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo; } te...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
import java.io.*; import java.util.*; import java.math.BigInteger; import java.util.Map.Entry; import static java.lang.Math.*; public class D extends PrintWriter { void test(int[] a, int[] b) { int n = a.length; int m = b.length; for (int t = 0; t <= n + m + 4; t++) { for (in...
JAVA
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> static const int MAXN = 100004; static const int MAXW = 100003; static const int MAXT = 100002; int n, w, h; int g[MAXN], p[MAXN], t[MAXN]; std::vector<int> s[MAXW + MAXT]; int ans_x[MAXN], ans_y[MAXN]; int main() { scanf("%d%d%d", &n, &w, &h); for (int i = 0; i < n; ++i) { scanf("%d%d%...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int read() { int s = 0; char c = getchar(), lc = '+'; while (c < '0' || '9' < c) lc = c, c = getchar(); while ('0' <= c && c <= '9') s = s * 10 + c - '0', c = getchar(); return lc == '-' ? -s : s; } void write(int x) { if (x < 0) putchar('...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; struct person { int id, pos; person(int a, int b) : id(a), pos(b) {} bool operator<(const person &o) const { return pos < o.pos; } }; int main() { unordered_map<int, vector<person>> a; int n, w, h; cin >> n >> w >> h; for (int i = 0; i < n; i++) { int g, p...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 100210, A = 100100; int n, w, h; vector<int> ver[maxn], hor[maxn]; vector<int> vid[maxn], hid[maxn]; deque<int> mp[maxn << 1]; vector<int> mpy[maxn << 1]; pair<int, int> ans[maxn]; int main() { cin >> n >> w >> h; for (register int i = 1; i <= n; ++i) {...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; vector<vector<int> > x(400000); int main(void) { int k; int N; int M; scanf("%i %i %i", &k, &M, &N); int a[k][3]; int i; for (i = 0; i < k; i++) { scanf("%i %i %i", &a[i][0], &a[i][1], &a[i][2]); a[i][2] += 150000; x[a[i][2] - a[i][1]].push_back(i)...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; bool comp(const pair<pair<long long, long long>, long long>& a, const pair<pair<long long, long long>, long long>& b) { if (a.first.first == b.first.first) return a.first.second < b.first.second; else return a.first.first < b.first.first; } int main() ...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; ifstream in("file.in"); ofstream out("file.out"); struct om { int p, t, id; } a[100005], b[100005]; int n, w, h, cnt1[200005], cnt2[200005], ans[100005], v[200005], k, m, first, nibab[100005]; pair<int, int> fk[100005]; queue<int> q[200005]; bool comp(om a, om b) { re...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > f[3][200100]; pair<int, int> ans[100100], res[100100]; int g[100100], p[100100], t[100100]; int n, h, w; void work(vector<pair<int, int> > &f, vector<pair<int, int> > &g) { int n = f.size(), m = g.size(); for (int i = 0; i < n; ++i) { if (m >...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 100; const int maxm = 100000 + 10; const int mod = (int)1e9 + 7; const int INF = 0x3f3f3f3f; const long long LINF = (1LL << 60); const double PI = acos(-1.0); struct node { int x, y, id; node() {} bool operator<(const node &r) const { return ...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; const int geta = 100000; int p[100010], x[100010], y[100010]; vector<int> hoge[2][200010]; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, w, h; cin >> n >> w >> h; for (int i = 0; i < n; i++) { int g, t; cin >> g >> p[i] >> t; g--; ho...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; vector<vector<int> > vec1(312345), vec2(312346); int g[123456], p[123456], t[123456]; int cons; int h, w; int computeup(int i) { int val1, val; vector<int>::iterator it; val1 = t[i] - p[i] + cons; it = upper_bound(vec1[val1].begin(), vec1[val1].end(), p[i]); val =...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; const double pi = 3.141592653589793; vector<pair<int, int> > vec[111111][2]; map<int, int> mm; int c; int ara[111111][2]; int ans[111111]; pair<int, int> point[111111]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, w, h; cin >> n >> w >> h; int a, x...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
//package codeforces.constructive_algorithms.cf_848_B_rooster_song; /** * Created by nafee on 2/14/18. */ import java.io.*; import java.util.*; public class Main { static void redirectIO() throws IOException { System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream("...
JAVA
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 100100; struct kk { int g, x, t, id; int z; kk() {} kk(int gg, int xx, int tt, int idd) { g = gg; x = xx; t = tt; id = idd; z = x - t; } }; bool menor(const kk &a, const kk &b) { if (a.z == b.z) { return a.x < b.x; } ...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; const int d = 150000; const int N = 400000; const int M = 102; unsigned long long cs = 1; struct T { int g, p, t, i; T() {} bool operator<(const T &other) const { return make_pair(p, make_pair(g, t)) < make_pair(other.p, make_pair(other.g, other.t)); ...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; int n, w, h; struct rec { int g, p, t, id; } x[111116], y[111116]; bool cmp_x(rec x, rec y) { if (x.p - x.t != y.p - y.t) return x.p - x.t < y.p - y.t; return (2 * x.g - 3) * x.p < (2 * y.g - 3) * y.p; } bool cmp_y(rec x, rec y) { return x.id < y.id; } int read() { ...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 7, M = 2e6; const long long mod = 1e9 + 7; inline int read() { int ret = 0; char ch = getchar(); bool f = 1; for (; !isdigit(ch); ch = getchar()) f ^= !(ch ^ '-'); for (; isdigit(ch); ch = getchar()) ret = (ret << 1) + (ret << 3) + ch - 48; r...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; struct point { int x, y, x_end, y_end, id; point() {} point(int a, int b, int c, int d, int e) { x = a; y = b; x_end = c; y_end = d; id = e; } } number[100005], temp[100005]; void cp(point &a, point &b) { a = point(b.x, b.y, b.x_end, b.y_end, b.i...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
/* Author: Ronak Agarwal */ import java.io.* ; import java.util.* ; import java.math.* ; import static java.lang.Math.min ; import static java.lang.Math.max ; import static java.lang.Math.abs ; /* Thread is created here to increase the stack size of the java code so that recursive dfs can be performed */ public class C...
JAVA
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g = 10.0, eps = 1e-7; const int N = 200000 + 10, maxn = 60000 + 10, inf = 0x3f3f3f; int gg[N], p[N], t[N], x[N]; vector<int> vx[N], vy[N]; pair<int, int> ans[N]; bool comp(int x, int y) { return p[x] < p[y...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
n,w,h = map(int,input().split()) D = [] original = [] for i in range(n): g,p,t = map(int,input().split()) a = p-t p = p if g == 1 else -p original.append(()) D.append((a,p,i)) D.sort() from bisect import bisect res = [None]*n i = 0 while i < len(D): a = D[i][0] j = bisec...
PYTHON3
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; int n, w, h; vector<int> ansx(100000), ansy(100000), g(100000), p(100000), t(100000), x, y; int main() { map<int, vector<int>> s; x.clear(); y.clear(); s.clear(); cin >> n >> w >> h; for (int i = 0; i < n; i++) { cin >> g[i] >> p[i] >> t[i]; s[p[i] - t[i...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > vec[2][200005]; pair<int, int> ans[200005]; int main() { int i, j, n, w, h, opt, p, t, sz1, sz2; cin >> n >> w >> h; for (i = 1; i <= n; i++) { cin >> opt >> p >> t; vec[opt - 1][p - t + 100000].push_back(make_pair(p, i)); } for (i ...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); int n, w, h; cin >> n >> w >> h; map<int, pair<vector<pair<int, int>>, vector<pair<int, int>>>> a; for (auto i = 0; i < n; ++i) { int g, p, t; cin >> g >> p >> t; ...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.HashMap; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; import java.util.Map.Entry; import java.io.BufferedReader...
JAVA
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; int n, w, h; int zsuv = 100001; int g[100000], p[100000], t[100000]; vector<pair<pair<int, int>, int> > groups[250000]; vector<pair<int, int> > finish[250000]; vector<int> ishky[250000]; pair<int, int> res[100000]; int main() { scanf("%d %d %d", &n, &w, &h); for (int i ...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; int N, W, H, g[100009], p[100009], t[100009], ansx[100009], ansy[100009]; vector<int> v[200009]; int main() { cin >> N >> W >> H; for (int i = 0; i < N; i++) { cin >> g[i] >> p[i] >> t[i]; v[p[i] - t[i] + 100000].push_back(i); } for (int i = 0; i <= 200000; ...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; void in(int& a); void in(long long& a); struct no { int x, id; no(int a, int b) { x = a; id = b; } bool operator<(const no& b) const { return x < b.x; } }; int n, m, w, h, t, tt, x, y, an[100010], as[100010]; vector<no> p[100010 << 2]; vector<int> q[100010 <...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; int n, w, h; struct node { int ty, pos, t, id, to; } po[100005] = {{0}}; bool cmp(node x, node y) { if (x.pos - x.t < y.pos - y.t) return true; if (x.pos - x.t > y.pos - y.t) return false; if (x.ty > y.ty) return true; if (x.ty < y.ty) return false; if (x.pos > ...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; vector<pair<int, int> > v[2][2 * MAXN]; vector<int> tmp; pair<int, int> res[MAXN]; int main() { int a, b, c, d, e, f, k, q, m, n, w, h; scanf("%d%d%d", &n, &w, &h); for (a = 0; a < n; a++) { scanf("%d%d%d", &b, &c, &d); v[b - 1][MAXN +...
CPP
848_B. Rooter's Song
Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage. On the sides of t...
2
8
#include <bits/stdc++.h> using namespace std; struct node { int g, p, t, idx; node(){}; node(int g_, int p_, int t_, int idx_) : g(g_), p(p_), t(t_), idx(idx_) {} }; int n, W, H; node A[100007]; vector<node> G[100007 << 1]; pair<int, int> ans[100007]; void work(const vector<node> &E) { vector<int> Pv, Ph; map...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; int ans[55] = {0, 0, 3, 3, 3, 15, 3, 3, 29, 17, 255, 5, 83, 4095, 43, 3, 63, 15, 63, 63, 1023, 63, 3, 63, 27, 15, 4095, 39, 4095, ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> #pragma comment(linker, "/stack:64000000") using namespace std; template <typename first> inline first abs(const first& a) { return a < 0 ? -a : a; } template <typename first> inline first sqr(const first& a) { return a * a; } const long double PI = 3.1415926535897932384626433832795; const ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> int main() { int k; scanf("%d", &k); if (k == 2) printf("1 1\n"); else if (k == 3) printf("1 0 1\n"); else if (k == 4) printf("0 0 1 1\n"); else if (k == 5) printf("0 0 1 0 1\n"); else if (k == 6) printf("0 0 0 0 1 1\n"); else if (k == 7) printf("0 1 0 1 ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; const char *ans[51] = { "", "", "1", "1", "1", "1 2 3", "1 4 5", "2 3 4", "1 2 7", "3 5 6", "2 3 8", "1 8 10", "1 2 10", "3 5 8", "1 11 12", "3 4 12", "10 12 15", "4 12 16", "4 11 16", "3 9 10", ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> long long P[55] = {0, 0, 3, 5, 12, 20, 48, 106, 177, 318, 931, 1757, ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> const long long TAB[51] = {0LL, 0LL, 6LL, 10LL, 24LL, 40LL, 96LL, 212LL, 354LL,...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> int a[] = {0, 0, 1, 1, 1, 2, 1, 1, 14, 8, 4, 2, 41, 13, 21, 1, 22, 4, 19, 19, 4, 2, 1, 16, 13, 4, 35, 19, 4, 2, 41, 4, 87, 41, 115, 2, 59, 31, 49, 8, 28, 4, 31, 44, 50, 13, 151, 16, 91, 56, 14}, n; int main() { scanf("%d", &n); for (int i = ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; struct Matrix { bool X[50][50]; }; int N, M; long long P; long long A[50]; bool C[50]; Matrix G[50]; Matrix operator*(Matrix A, Matrix B) { Matrix C; memset(C.X, 0, sizeof(C.X)); for (int k = 0; k < N; k++) for (int i = 0; i < N; i++) if (A.X[i][k]) ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; const int MAX_K = 50; vector<int> primes; vector<long long> prime_divisors; int PRIMES_COUNT, k; int A[MAX_K][MAX_K], E[MAX_K][MAX_K], T[MAX_K][MAX_K], W[MAX_K][MAX_K]; inline void precalc() { for (int i = 0; i < MAX_K; ++i) { E[i][i] = 1; } const int SIEVE_SIZE =...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; int n; const double eps = 1e-8; int A[55][55], t[55][55]; void mul(int (&a)[55][55], int (&b)[55][55], int (&c)[55][55]) { int t[55][55]; memset(t, 0, sizeof(A)); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (a[i][j]) for (int k = 1; ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; using namespace rel_ops; const double PI = acos((double)-1); int ts, ts2, ts3, ts4; int n, m; long long gcd(long long x, long long y) { long long t; for (; y != 0;) { t = x % y; x = y; y = t; } return x; } double sqr(double x) { return x * x; } long long...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> int a[] = {0, 0, 1, 1, 1, 2, 1, 1, 14, 8, 4, 2, 41, 13, 21, 1, 22, 4, 19, 19, 4, 2, 1, 16, 13, 4, 35, 19, 4, 2, 41, 4, 87, 41, 115, 2, 59, 31, 49, 8, 28, 4, 31, 44, 50, 13, 151, 16, 91, 56, 14}, n; int main() { scanf("%d", &n); for (int i = ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> int k, cnt, c[52]; long long n, divisor[52]; struct matrix { int n, m, mat[52][52]; } result, shift, cur; matrix operator*(const matrix &a, const matrix &b) { matrix ret; memset(ret.mat, 0, sizeof(ret.mat)); for (int i = 0; i < a.n; i++) for (int j = 0; j < b.m; j++) for (int ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 51; int a[maxn], c[maxn]; int N; struct Mat { int mat[maxn][maxn]; Mat operator*(Mat M) { Mat ret; for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) { ret.mat[i][j] = 0; int now = 0; for (int k = 0; k < N; ++k...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; const int P[5] = {2, 3, 7, 61, 24251}; long long N, K, X[100000]; int n, i, j, c[51], a[51], Tot; struct Matrix { int m[51][51]; Matrix operator*(const Matrix &A) const { Matrix C; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { C.m[i][...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; inline void read(int &x) { int v = 0, f = 1; char c = getchar(); while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f = -1; else v = (c & 15); while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15); x = v * f; } inline void read(lo...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; int ans[] = {0, 0, 1, 1, 1, 2, 1, 1, 14, 8, 4, 2, 41, 13, 21, 1, 22, 4, 19, 19, 4, 2, 1, 16, 13, 4, 35, 19, 4, 2, 41, 4, 87, 41, 115, 2, 59, 31, 49, 8, 28, 4, 31, 44, 50, 13, 151, 16, 91, 56, 14}; int main() { ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> int i, K, Cnt; long long N, p, d; long long P[100005]; int A[55][55], B[55][55], C[55], E[55][55], D[55][55][55]; void Mul1() { int i, j, k; for (i = 1; i <= K; ++i) for (j = 1; j <= K; ++j) E[i][j] = 0; for (i = 1; i <= K; ++i) for (j = 1; j <= K; ++j) if (A[i][j]) ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; long long int siguiente(long long int len, long long int n, long long int k) { k &= n; long long int x = 0; while (k) { x ^= k & 1; k >>= 1; } n >>= 1; n |= x << (len - 1); return n; } const int tope = 10000; bool testea(long long int len, long long in...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; typedef int arr[52][52]; arr a; long long step; int b[52], p[1000]; int n, cnt; void matrixmul1(arr a, arr b, arr c) { for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) for (int k = 1; k <= n; k++) c[i][j] = (c[i][j] + a[i][k] * b[k][j]) & 1; } void matr...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> const long long C[51] = {0, 0, 3ll, 5ll, 9ll, 23ll, 54ll, 83ll, 150ll, ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; const long long DIVISORS[][100] = { {}, {}, {}, {}, { 3, 5, }, {}, { 3, 7, }, {}, { 3, 5, 17, }, { 7, 73, }, { 3, 11, ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> long long S, d[55 * 55]; int n, cnt, a[55][55], b[55][55], e[55][55], c[55], res[55]; typedef int arr[55][55], arr1[55]; arr tmp[55]; unsigned int tmpx[55], tmpy[55], tmpx1[55], tmpy1[55]; void mul1(arr1 &res, arr &a) { memset(c, 0, sizeof(c)); for (int i = 0; i < n; i++) for (int j = 0...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; typedef int mat[55][55]; int c[55]; vector<long long> vlist; mat g; int n; void mult(mat &res, mat &a, mat &b) { static mat c; memset(c, 0, sizeof c); for (int i = (1); i <= (n); i++) for (int j = (1); j <= (n); j++) for (int k = (1); k <= (n); k++) ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> long long S, d[55 * 55]; int n, cnt, a[55][55], b[55][55], e[55][55], c[55], res[55]; typedef int arr[55][55], arr1[55]; arr tmp[55]; void mul1(arr1 &res, arr &a) { memset(c, 0, sizeof(c)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) c[i] = (a[i][j] * res[j] + c[i]) & 1; m...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
JAVA
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; int n; const int MAX_N = 50; long long answer[MAX_N + 1]; int main() { answer[2] = 3LL; answer[3] = 5LL; answer[4] = 25LL; answer[5] = 59LL; answer[6] = 97LL; answer[7] = 239LL; answer[8] = 95LL; answer[9] = 119LL; answer[10] = 507LL; answer[11] = 3487LL...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; void Get(int &T) { char C; bool F = 0; for (; C = getchar(), C < '0' || C > '9';) if (C == '-') F = 1; for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0') ; F && (T = -T); } int N; void Init() { Get(N); } int T[55][55]; void Mul(in...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
m={2: '11', 3: '101', 4: '1001', 5: '01001', 6: '100001', 7: '1000001', 8: '01110001', 9: '000100001', 10: '0010000001', 11: '01000000001', 12: '100101000001', 13: '1011000000001', 14: '10101000000001', 15: '100000000000001', 16: '0110100000000001', 17: '00100000000000001', 18: '000000100000000001', 19: '11001000000000...
PYTHON
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; const int maxk = 51; struct matrix { bool e[maxk][maxk]; int sz; void print() { for (int i = 0, _n = (sz); i < _n; i++) { for (int j = 0, _n = (sz); j < _n; j++) { printf("%d", e[i][j]); } printf("\n"); } printf("\n"); } }; matr...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; int n, len = 0; long long m = 1, a[2000]; bool A[60][60], B[60][60], f[60], g[60]; bool c[60]; void find_factor() { for (int i = 1; i <= n; ++i) m <<= 1; --m; long long k = m; for (long long i = 2; i * i <= k; ++i) if (k % i == 0) { a[++len] = m / i; ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> const int Ans[] = {0, 0, 1, 1, 1, 2, 1, 1, 14, 8, 4, 2, 41, 13, 21, 1, 22, 4, 19, 19, 4, 2, 1, 16, 13, 4, 35, 19, 4, 2, 41, 4, 87, 41, 115, 2, 59, 31, 49, 8, 28, 4, 31, 44, 50, 13, 151, 16, 91, 56, 14}; int n; int ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 55; struct matrix_t { bitset<N> row[N], col[N]; int n; void resize(int _n) { n = _n; for (int i = 1; i <= n; ++i) { row[i].reset(); col[i].reset(); } } void output() { for (int i = 1; i <= n; ++i) { for (int j = 1; j...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> long long S, d[55 * 55]; int n, cnt; typedef bool arr[55][55], arr1[55]; arr a, b, e, tmp[55]; arr1 c, res; void mul1(arr1 &res, arr &a) { memset(c, 0, sizeof(c)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) c[i] = ((a[i][j] * res[j]) + c[i]) & 1; memcpy(res, c, sizeof(res...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class SeqGen implements Runnable { private void solve() throws IOException { long[] answer = new long[51]; answer[2] = 3L; answer...
JAVA
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> long long S, d[55 * 55]; int n, cnt, a[55][55], b[55][55], e[55][55], c[55], res[55]; typedef int arr[55][55], arr1[55]; arr tmp[55]; void mul1(arr1 &res, arr &a) { memset(c, 0, sizeof(c)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) c[i] = (a[i][j] * res[j] + c[i]) & 1; m...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; int a[51][6] = { {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {2, 1, 0, 0, 0, 0}, {3, 2, 0, 0, 0, 0}, {4, 3, 0, 0, 0, 0}, {5, 3, 0, 0, 0, 0}, {6, 5, 0, 0, 0, 0}, {7, 6, 0, 0, 0, 0}, {8, 6, 5, 4, 0, 0}, {9, 5, 0, 0, 0, 0}, {10, 7, 0, 0,...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 55; struct Tmat { int v[maxn][maxn]; }; Tmat ans, e, ee; int c[maxn], res[maxn]; long long fac[maxn]; int n, tot; long long p; void mul(Tmat a, Tmat b, Tmat &c) { register int i, j, k; for (i = 0; i < n; ++i) for (j = 0; j < n; ++j) for (k =...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; const int maxn = 55; long long p[maxn]; int c[maxn]; int n, ps; long long len; void init() { scanf("%d", &n); } void mkdivisor() { len = (1LL << n) - 1; ps = 0; long long x = len; for (long long i = 2; i * i <= x; i++) if (x % i == 0) { p[ps++] = len / i; ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
import static java.lang.Math.*; import static java.util.Arrays.*; import java.util.*; public class B { Scanner sc = new Scanner(System.in); int[][] pp = { {1}, {1}, {1}, {2}, {1}, {1}, {1,2,7}, {4}, ...
JAVA
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> int K, n; long long S, q[1005]; struct matrix { bool a[55][55]; matrix(bool x = 0) { memset(a, 0, sizeof(a)); for (int i = 0; i < K; i++) a[i][i] = x; } friend matrix operator*(const matrix& A, const matrix& B) { matrix C; for (int i = 0; i < K; i++) for (int k = 0...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; int n, cnt; long long z[60]; bool c[60]; struct matrix { bool z[52][52]; matrix() { memset(z, false, sizeof(z)); } matrix operator*(const matrix &a) const { matrix ans; for (int b = 1; b <= n; b++) for (int c = 1; c <= n; c++) if (z[c][b]) ...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> long long S, d[55 * 55]; int n, cnt, a[55][55], b[55][55], e[55][55], c[55], res[55]; typedef int arr[55][55], arr1[55]; void mul1(arr1 &res, arr &a) { memset(c, 0, sizeof(c)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) c[i] = (a[i][j] * res[j] + c[i]) & 1; memcpy(res, c,...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; vector<vector<long long> > mul(vector<vector<long long> > a, vector<vector<long long> > b) { vector<vector<long long> > res( ((long long)a.size()), vector<long long>(((long long)b[0].size()), 0)); for (long long i = 0; i < ((long lon...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; vector<long long> a; bool check(int n, const vector<int>& p, long long S) { bool a[n][n], b[n][n], c[n], d[n]; memset(a, 0, sizeof a); memset(b, 0, sizeof b); memset(c, 0, sizeof c); memset(d, 0, sizeof d); for (int i = 0; i < n; i++) c[i] = 1; for (int i = 0;...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; const int N = 60; using ll = long long; inline ll count(ll x) { for (int i = 32; i; i >>= 1) x ^= x >> i; return x & 1; } int n; struct Arr { ll a[N]; Arr operator+(const Arr &b) const { Arr c; for (int i = 0; i < n; i++) { c.a[i] = 0; for (int j...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> using namespace std; const int kMaxK = 50; int k, c[kMaxK]; long long p; vector<long long> fact; struct Matrix { int v[kMaxK][kMaxK]; void clear() { memset(v, 0, sizeof(v)); } Matrix() { clear(); } } e, f, a, b; Matrix operator*(const Matrix &a, const Matrix &b) { Matrix c; for (int i...
CPP
86_E. Long sequence
A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that not all of ci are zeros. Note that such a sequence can be uniquely recovere...
2
11
#include <bits/stdc++.h> long long S, d[55 * 55]; int n, cnt, a[55][55], b[55][55], e[55][55], c[55], res[55]; void mul1() { memset(c, 0, sizeof(c)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) c[i] = (a[i][j] * res[j] + c[i]) & 1; memcpy(res, c, sizeof(res)); } void mul() { memset(b, 0, sizeof(...
CPP