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 |
|---|---|---|---|---|---|
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5;
int n, cnt_edge[maxn];
vector<int> g[maxn];
namespace dsu {
int pa[maxn], size[maxn], rk[maxn];
vector<int> root;
void Init(void) {
root.clear();
for (int i = 0; i < n; ++i) {
pa[i] = i;
size[i] = 1;
rk[i] = 0;
root.push_back(i);
... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int nextInt() {
int x;
scanf("%d", &x);
return x;
}
long long nextLong() {
long long x;
scanf("%I64d", &x);
return x;
}
double nextDouble() {
double x;
scanf("%lf", &x);
return x;
}
const int BUFSIZE = 1000000;
char buf[BUFSIZE + 1];
string nextString() {
... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | import java.io.*;
import java.util.*;
public class Main {
static FastReader in;
static PrintWriter out;
static int g [][];
static int deg [];
static int edges [][];
static ArrayList<ArrayList<Integer>> answer = new ArrayList<ArrayList<Integer>>();
public static void solve () {
i... | JAVA |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.writ... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
set<pair<int, int>> edge;
set<pair<int, int>> v;
int cnt[MAXN];
void dfs(int &V, vector<int> &a) {
a.push_back(V);
vector<int> q;
int now;
for (auto i : v) {
now = i.second;
if (!edge.count({min(V, now), max(V, now)})) {
q.pu... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int n, m;
const int maxn = 5e5 + 10;
vector<int> adj[maxn];
int ind;
bool haveB[maxn];
int tmp[maxn], par[maxn], sz[maxn];
int find(int v) { return (par[v] < 0 ? v : par[v] = find(par[v])); }
void Union(int v, int u) {
v = find(v);
u = find(u);
if (v == u) return;
i... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
long long n, m;
unordered_set<long long> e;
set<long long> s;
vector<vector<long long>> ans;
queue<long long> q;
void bfs(long long node) {
s.erase(node);
q.push(node);
vector<long long> visited;
while (!q.empty()) {
node = q.front();
visited.push_back(node)... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int> > g;
set<int> st;
vector<vector<int> > ans;
vector<int> cur;
bool yes(int v, int u) {
if (g[v].size() == 0) {
return false;
}
int l = 0, r = int(g[v].size()) - 1;
while (l != r) {
int mid = (l + r) / 2;
if (g[v][mid] >= u) {
... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int n, m;
set<int> s;
const int nax = 5e5 + 4;
int link[nax];
set<pair<int, int>> edge;
vector<vector<int>> group;
inline void make_set(int i) { link[i] = i; }
int Find(int a) {
if (link[a] == a) return a;
return (link[a] = Find(link[a]));
}
void Unite(int a, int b) {
... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int ata[(int)(5e5 + 10)], S[(int)(5e5 + 10)], S2[(int)(5e5 + 10)], i, j, k, n,
m, x, y, z;
int s, H[(int)(5e5 + 10)];
vector<int> arr[(int)(5e5 + 10)], v[(int)(5e5 + 10)];
set<int> first;
int atabul(int x) {
if (ata[x] == x) return x;
return ata[x] = atabul(ata[x]);... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int nextInt() {
int x;
scanf("%d", &x);
return x;
}
long long nextLong() {
long long x;
scanf("%I64d", &x);
return x;
}
double nextDouble() {
double x;
scanf("%lf", &x);
return x;
}
const int BUFSIZE = 1000000;
char buf[BUFSIZE + 1];
string nextString() {
... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
std::set<int> not_used;
std::vector<int> comp;
int n;
std::vector<std::pair<int, int>> edges;
int fastscan() {
int number = 0;
register int c = getchar();
for (; c > 47 && c < 58; c = getchar()) number = number * 10 + c - 48;
return number;
}
int have_edge(int a, int b) {
if (a < b) s... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 45;
map<pair<int, int>, bool> mapa;
int n, m;
vector<int> comp[N];
int main() {
scanf("%i%i", &n, &m);
for (int i = 1; i <= m; i++) {
int a, b;
scanf("%i%i", &a, &b);
if (a > b) {
swap(a, b);
}
mapa[pair<int, int>(a, b)] = 1... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 5 * 100 * 1000 + 1000;
vector<int> v[maxn];
vector<int> group[maxn];
int _next[maxn];
bool mark[maxn];
int n;
int find_next(int x) {
if (_next[x] == x) return x;
return _next[x] = find_next(_next[x]);
}
void dfs(int x, int cnt) {
group[cnt].push_back(... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
unordered_set<int> adj[maxn];
unordered_set<int> unvis;
vector<int> c[maxn];
int ctr = 0;
void dfs(int u) {
c[ctr].push_back(u);
vector<int> tovisit;
for (int x : unvis) {
if (adj[u].count(x) == 0) {
tovisit.push_back(x);
}
}
... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10, M = 1e6 + 10;
int n, m, i, j, cnt;
bool mark[N];
vector<int> adj[N], comp[N];
queue<int> q;
unordered_set<int> unmarked;
void bfs() {
while (!q.empty()) {
int u = q.front();
comp[cnt].push_back(u);
q.pop();
for (auto v : adj[u]) {
... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
bool debug;
const int inf = 1e9 + 5;
const int nax = 1e6 + 5;
vector<int> w[nax];
set<int> pozostale;
vector<vector<int> > res;
int first[nax];
void zacznij(int pierwszy) {
vector<int> kol;
kol.push_back(pierwszy);
for (int i = 0; i <= ((int)kol.size()) - 1; ++i) {
... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | // package cf190;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.function.IntConsumer;
import java.util.stream.Collectors;
public class CFE {
private static final long MOD = ... | JAVA |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 5 * 100 * 1000 + 14;
vector<int> comp[MAXN], adj[MAXN];
set<int> res;
int ans = 0;
void dfs(int v) {
comp[ans].push_back(v);
auto it = res.begin();
while (it != res.end()) {
if (find(adj[v].begin(), adj[v].end(), *it) == adj[v].end()) {
int ... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
unordered_set<long long> second[500001];
unordered_set<long long> unvisited;
vector<vector<long long>> ans;
vector<long long> temp;
void dfs(long long node) {
temp.push_back(node);
unvisited.erase(node);
vector<long long> t;
for (auto c : unvisited) {
if (!secon... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long int N = 5e5 + 30, mod = 1e9 + 7, inf = 1e12;
const long double eps = 0.0001;
int n, m;
bool visited[N];
set<pair<int, int> > st;
set<int> ve;
vector<in... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 77, Mod = 1e9 + 7;
int n, m, p[N], t[N], A;
vector<int> a[N], sz[N];
vector<int> s;
int find(int v) { return p[v] < 0 ? v : (p[v] = find(p[v])); }
void merge(int v, int u) {
v = find(v);
u = find(u);
if (u == v) {
return;
}
p[v] += p[u];
... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | import java.util.*;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.io.InputStream;
/**
* TEST
*/
public class Main {
public static void main(String[] args) {
In... | JAVA |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int nextInt() {
int x;
scanf("%d", &x);
return x;
}
long long nextLong() {
long long x;
scanf("%I64d", &x);
return x;
}
double nextDouble() {
double x;
scanf("%lf", &x);
return x;
}
const int BUFSIZE = 1000000;
char buf[BUFSIZE + 1];
string nextString() {
... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 500000 + 1000;
int n, m, ans, par[MAXN];
vector<int> adj[MAXN], out[MAXN];
bool mark[MAXN];
int find(int x) {
if (par[x] == x) return x;
return par[x] = find(par[x]);
}
void dfs(int x) {
mark[x] = 1;
par[x] = x + 1;
for (register int i = 0; i < ad... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
long long int div_floor(const long long int &a, const long long int &b) {
return a / b - (((a ^ b) < 0) and a % b);
}
long long int div_ceil(const long long int &a, const long long int &b) {
return a / b + (((a ^ b) >= 0) and a % b);
}
vector<int> parent;
vector<int> cn... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const int N = 1e6 + 5;
set<int> se;
vector<int> w[N];
int ind[N];
vector<vector<int> > ans;
void go(int n) {
vector<int> v;
v.emplace_back(n);
for (int i = 0; i < v.size(); i++) {
int num = v[i];
se.erase(num);
for (auto ... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 5 * 100 * 1000 + 14;
vector<int> comp[MAXN], adj[MAXN];
set<int> res;
int ans = 0;
void dfs(int v) {
comp[ans].push_back(v);
auto it = res.begin();
while (it != res.end()) {
if (find(adj[v].begin(), adj[v].end(), *it) == adj[v].end()) {
int ... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int num[500050], bel[500050], wz[500050];
int a[500050], dl[500050];
int n, m, top, now;
int fir[500050], en[2000400], nex[2000400], tot;
int get() {
char t = getchar();
while (t < '0' || t > '9') t = getchar();
int x = 0;
while (t >= '0' && t <= '9') {
x *= 10;... | CPP |
190_E. Counter Attack | Berland has managed to repel the flatlanders' attack and is now starting the counter attack.
Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we d... | 2 | 11 | #include <bits/stdc++.h>
const int N = 500005;
int H[N], id;
struct Edge {
int v, nt;
} e[N * 4];
int n, m;
int next[N];
std::vector<int> block[N];
int num, head;
int p[N];
void AddEdge(int u, int v) {
e[id].v = v;
e[id].nt = H[u];
H[u] = id++;
}
int main() {
scanf("%d%d", &n, &m);
id = 1;
num = 0;
int ... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e2 + 10;
const int INF = 1e8 + 100;
int dp[MAXN][MAXN][MAXN];
bool vis[MAXN][MAXN][MAXN];
int a[MAXN][MAXN];
int memo(int r, int d, int R) {
if (vis[r][d][R]) return dp[r][d][R];
vis[r][d][R] = true;
int D = r + d - R;
int &res = dp[r][d][R];
res... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int mx[2] = {1, 0};
const int MAXN = 310;
const int INF = 1e9;
int N;
int A[MAXN][MAXN];
int dp[MAXN][MAXN][MAXN];
void setmax(int& a, int b) {
if (a < b) {
a = b;
}
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> N;
for (int... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int dp[305 << 1][305][305];
int a[305][305], n;
int way[4][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
int main() {
scanf("%d", &n);
int i, j, k;
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
scanf("%d", &a[i][j]);
}
}
memset(dp, 0x81, sizeof(dp))... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int pts[301][301];
int dp[2 * 301][301][301];
inline int _dp(int i, int j, int k) {
if (i < 0 or j < 0 or k < 0) return -100000000;
if (dp[i][j][k] != 1e8) return dp[i][j][k];
long long ans = 0;
ans = max(max(_dp(i - 1, j - 1, k), _dp(i - 1, j - 1, k - 1)),
... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
#pragma warning(disable : 4786)
using namespace std;
int MIN(int a, int b) { return a < b ? a : b; }
int MAX(int a, int b) { return a > b ? a : b; }
int GCD(int a, int b) {
while (b) b ^= a ^= b ^= a %= b;
return a;
}
int LCM(int a, int b) { return... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int n, a[305][305];
bool done[305][305][305];
int memo[305][305][305];
int dr[] = {1, 0}, dc[] = {0, 1};
int solve(int r1, int c1, int r2, int c2) {
if (r1 == n - 1 && c1 == n - 1) return 0;
int &ret = memo[r1][c1][r2];
if (!done[r1][c1][r2]) {
done[r1][c1][r2] = ... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 2e6;
const long long mod = 1e9 + 7;
const long long inf = 1e9;
long long a[610][610], f[2][610][610];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i <= 600... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int dp[606][303][303];
int solve(int n, vector<vector<int>> &vec, int d, int x1, int x2) {
if (d > n + n - 2) {
return 0;
}
if (x1 >= n || x2 >= n) {
return -0x3f3f3f3f;
}
int y1 = d - x1, y2 = d - x2;
if (y1 >= n || y2 >= n) {
return -0x3f3f3f3f;
... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int mod = 1e9 + 7;
int dp[602][302][302], n, a[303][303];
int solve(int dg, int i1, int i2) {
if (i1 > n || i2 > n) return -inf;
int j1 = dg - i1;
int j2 = dg - i2;
if (j1 > n || j2 > n) return -inf;
if (dg == (2 * n)) return a[i1][j1];
... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 310;
const int mod = 1e9 + 7;
const int inf = -1e9;
int a[N][N];
int cache[2 * N][N][N];
int n;
int dp(int diag, int i1, int i2) {
if (i1 > n || i2 > n) return -1e9;
int j1 = diag - i1;
int j2 = diag - i2;
if (j1 > n || j2 > n) return -1e9;
if (diag ... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 300 + 10;
const int INF = 1e9 + 2;
int n;
int cc[MAXN][MAXN];
int d[2 * MAXN][MAXN][MAXN];
bool fit(int a, int b) { return a >= 0 && a < n && b >= 0 && b < n; }
int get(int a, int b, int c) {
if (d[a][b][c] != INF) return d[a][b][c];
if (a == 2 * n - 2)... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class RelayRace {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
int N = sc.nextInt();
int[][] a = new int[N][N];... | JAVA |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e14;
const double eps = 1e-10;
const double pi = acos(-1.0);
int a[305][610];
int dp[305][305][3];
int n;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
scanf("%d", &a[i][j + i]);
}
... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class E {
static int[][] a;
static int[][][] dp;
static int n;
public static void main(String[] args) throws IOException {
InputReader ... | JAVA |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 305;
const int maxint = 999999999;
int dp[2][maxn][maxn];
int a[maxn][maxn];
int n;
bool judge(int x, int y) { return (x >= 1 && y <= n); }
int main() {
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) s... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 301;
int a[N][N];
int f[N * 2 + 2][N][N];
int i, j, n, x, y, t;
int max(int b, int c, int d, int e) { return max(max(b, c), max(d, e)); }
void Main() {
memset(f, -10, sizeof(f));
memset(a, 0, sizeof(a));
for (int i = 1; i <= n; i++)
for (int j = 1; j... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 301, inf = -(1e9 + 1);
int n;
int a[N][N];
int cache[2 * N][N][N];
int dp(int idx, int i1, int i2) {
if (i1 > n || i2 > n) return -1e9;
int j1 = idx - i1;
int j2 = idx - i2;
if (j1 > n || j2 > n) return -1e9;
if (idx == 2 * n) return a[i1][j1];
int... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int n, a[305][305];
int p[2] = {0, 1};
int memo[305][305][305];
int dfss(int x1, int x2, int tot) {
if (memo[x1][x2][tot] != -1) return memo[x1][x2][tot];
if (x1 == n && x2 == n && tot == 2 * n) return 0;
int hsl = -900000;
for (int i = 0; i < 2; i++) {
for (int... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int F[605][305][305], a[305][305], n;
int main() {
if (0) freopen("input.txt", "r", stdin);
;
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) scanf("%d", &a[i][j]);
for (int i = 0; i <= 2 * n; ++i)
for (int j = 0; j <= n; ++j)
... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int mat[300 + 10][300 + 10];
int sol[300 + 10][300 + 10][300 + 10];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
for (int k = 0; k < n; k++) sol[i][j][k] = -100000000;
for (int i = 0; i < n; i++)
for (int... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | import java.io.*;
import java.util.*;
public class relay {
public static void main(String[] args) throws Exception {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(r.readLine());
... | JAVA |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int dp[0x12d * 2][0x12d][0x12d];
int v[0x12d][0x12d];
inline int max(int a, int b, int c, int d) {
if (a < b) a = b;
if (a < c) a = c;
if (a < d) a = d;
return a;
}
int main() {
int N;
cin >> N;
for (int i = 1; i <= N; ++i)
for (int j = 1; j <= N; ++j) sca... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 300 + 2;
const int MAXA = 1e3 + 3;
const int INF = 0x3f3f3f3f;
int n;
int a[MAXN][MAXN];
int dp[MAXN * 2][MAXN][MAXN];
bool outOfRange(int x, int y) { return x < 0 || x >= n || y < 0 || y >= n; }
void upmax(int &x, int v) {
if (x < v) x = v;
}
void solve(... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
long long dp[5][305][305];
long long a[305][305];
long long max(long long a, long long b, long long c, long long d) {
return max(a, max(b, max(c, d)));
}
int main(int argc, char** argv) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const long long MAX = 2005;
int k;
int dp[605][305][305];
int arr[305][305];
bool ok(int dist, int a, int c) {
int b = dist - a;
int d = dist - c;
return ((0 <= a) && (0 <= b) && (0 <= c) && (0 <= d) && (a < k) && (b < k) &&
(c < ... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 2e6;
const long long mod = 1e9 + 7;
const long long inf = 1e9;
long long a[610][610], f[2][610][610];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i <= 600... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int Map[305][305], F[305 << 1][305][305];
int X[4] = {-1, -1, 0, 0};
int Y[4] = {-1, 0, -1, 0};
int main() {
int i, j, k, n, t;
memset(F, 0xCC, sizeof(F));
for (i = scanf("%d", &n); i <= n; i++)
for (j = 1; j <= n; j++) scanf("%d", &Map[i][j]);
for (F[0][i = 1][... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int n, a[303][303], dp[303][303][303], xx[] = {1, 0}, yy[] = {0, 1}, ans;
int f(int x, int y, int z) {
if (x == n - 1 && y == n - 1) return 0 + a[x][y];
if (dp[x][y][z] != -1e9) return dp[x][y][z];
int ans = -1e9, k = (x + y) - z;
fo... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 310;
const int INF = 100000000;
int n, v[N][N], dp[N * 2][N][N];
bool valid(int x, int y) {
if (x <= 0 || x > n || y <= 0 || y > n) return false;
return true;
}
bool same(int x1, int y1, int x2, int y2) {
if (x1 == x2 && y1 == y2) return true;
return f... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int n, a[305][305], dp[2 * 305][305][305];
int f(int r1, int c1, int r2, int c2) {
if (r1 > n || r2 > n || c1 > n || c2 > n) return -100000000;
if (r1 == n && c1 == n) return a[n][n];
int t = r1 + c1 - 1;
if (dp[t][c1][c2] != -1) return dp[t][c1][c2];
int ans = f(... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T>
inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
inline int readInt() {
int x;
scanf("%d", &x);
return x;
}
const double E... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const double eps = 1e-5;
const int inf = (1 << 31) - 1;
const int hinf = 1000000000;
const int mod = 1000000007;
int dat[500][500];
int dp[305][305][305];
int dp2[305][305][305];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
for (int j = 1; j <... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 2e6;
const long long mod = 1e9 + 7;
const long long inf = 1e9;
long long a[610][610], f[2][610][610];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i <= 600... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int dp[0x12d * 2][0x12d][0x12d];
int v[0x12d][0x12d];
int max(int a, int b, int c, int d) {
if (a < b) a = b;
if (a < c) a = c;
if (a < d) a = d;
return a;
}
int main() {
int N;
cin >> N;
for (int i = 1; i <= N; ++i)
for (int j = 1; j <= N; ++j) scanf("%d"... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class PrE {
public static long time;
public static void main(String[] args) throws Exception {
time = System.currentTimeMillis();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
... | JAVA |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int a[307][307];
int f[607][307][307];
int moves[][4] = {{1, 0, 1, 0}, {1, 0, 0, 1}, {0, 1, 1, 0}, {0, 1, 0, 1}};
int main() {
int n;
cin >> n;
for (int(i) = (int)(0); (i) < (int)(n); ++(i))
for (int(j) = (int)(0); (j) < (int)(n); ++(j)) cin >> a[i][j];
fill(&f[... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 305;
const int maxint = 999999999;
int dp[2][maxn][maxn];
int a[maxn][maxn];
int n;
int main() {
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
dp[1][1][1] = a[1][1];
for... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
inline int ADD(int a, int b) {
a += b;
if (a >= 1000000007) a -= 1000000007;
return (int)a;
}
inline void ADDTO(int &a, int b) {
a += b;
if (a >= 1000000007) a -= 1000000007;
}
inline void SUBTO(int &a, int b) {
a -= b;
if (a < 0) a += 1000000007;
}
inline int... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;
public class Round131E {
private static final int LOCAL_ENV = 0;
static int n;
static int[][] a;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
try {
if (LOCAL_ENV =... | JAVA |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int> > v, dp;
int main() {
scanf("%d", &n);
v.resize(n + 1, vector<int>(n + 1, 0));
dp.resize(n + 1, vector<int>(n + 1, -1000000007));
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) scanf("%d", &v[i][j]);
}
dp[1][1] = v[1][1... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class RelayRace {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
int N = sc.nextInt();
int[][] a = new int[N][N];... | JAVA |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int n, dp[301][301][301], vis[301][301][301], a[301][301];
int valid(int x, int y) { return (x >= 1 && x <= n && y >= 1 && y <= n); }
int solve(int x1, int y1, int x2) {
int y2 = x1 + y1 - x2;
if (!valid(x1, y1) || !valid(x2, y2)) return -10000000;
if (x1 == n && y1 =... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | import java.util.*;
public class Relay {
static int[][][] memo;
static int[][] g;
static int N;
public static void main(String[] args){
Scanner reader = new Scanner(System.in);
int n = reader.nextInt(); N = n;
g = new int[n][n];
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
g[i][j] = read... | JAVA |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 305;
int n, a[N][N], dp[N + N][N][N];
int rec(int x1, int y1, int x2, int y2) {
if (x1 > n || y1 > n || x2 > n || y2 > n) return -(int)1e9;
if (x1 == x2 && y1 == y2 && x1 == n && y1 == n) return a[n][n];
if (dp[x1 + y1][x1][x2] != -(int)1e9) return dp[x1... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e14;
const double eps = 1e-10;
const double pi = acos(-1.0);
int a[305][610];
int dp[305][305][610];
int n;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
scanf("%d", &a[i][j + i]);
}
... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
#pragma comment(linker, "/STACK:200000000")
using namespace std;
template <typename T>
inline T Abs(T x) {
return (x >= 0) ? x : -x;
}
template <typename T>
inline T sqr(T x) {
return x * x;
}
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-9;
c... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int dp[2][310][310], tab[310][310];
int n, k;
int main() {
int i, j, tem, mm;
int be, fo;
scanf("%d", &n);
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++) scanf("%d", &tab[i][j]);
memset(dp, -16, sizeof(dp));
dp[0][0][0] = tab[1][1];
be = 0;
for (k = 1... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 2e6;
const long long mod = 1e9 + 7;
const long long inf = 1e9;
long long a[610][610], f[2][610][610];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i <= 600... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e14;
const double eps = 1e-10;
const double pi = acos(-1.0);
long long a[750][750];
long long dp[302][302][3];
int n;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-8;
const long double PI = 3.1415926535897932384626433832795;
const long double E = 2.7182818284;
const int INF = 1000000000;
int main(void) {
int n, i, j, g;
cin >> n;
int a[n][n];
for (int i = 0; i < int(n); i++)
for (int j = 0; j < i... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 2e6;
const long long mod = 1e9 + 7;
const long long inf = 1e9;
long long a[610][610], f[2][610][610];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i <= n; ... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int N, Mat[400][400];
int f[610][310][310];
void Init() {
scanf("%d", &N);
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++) scanf("%d", &Mat[i][j]);
}
void Work() {
for (int i = 0; i <= 2 * N; i++)
for (int j = 0; j <= N; j++)
for (int k = 0; k ... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60777216")
using namespace std;
int n;
int d[300][300];
int dp[300][300][300];
bool was[300][300][300];
int dx[] = {1, 0};
int dy[] = {0, 1};
inline bool valid(int i, int j, int k) {
int l = i + j - k;
if (i >= 0 && i < n && j >= 0 && j < n) {
if (k >= 0 ... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int arr[302][302], n, memory[302][302][302];
int MX(int a, int b) { return (a > b) ? a : b; }
int dp(int r1, int c1, int r2) {
if (r1 == n - 1 && c1 == n - 1) {
return arr[r1][c1];
}
if (memory[r1][c1][r2] != -1) {
return memory[r1][c1][r2];
}
int c2, mx =... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | import java.util.*;
import java.io.*;
public class e
{
public static void main(String[] arg)
{
new e();
}
int[][][] memo;
int[][] g;
int n;
int oo = -123_456_789;
public e()
{
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
n = in.nextInt();
g = new int[n][n];
f... | JAVA |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int ara[303][303], mem[303][303][303], n;
bool vis[303][303][303];
int dx[2] = {0, 1};
int dy[2] = {1, 0};
int dp(int x1, int y1, int x2, int y2) {
if (x1 == x2 && y1 == y2 && x1 == y1 && x1 == n - 1) return ara[n - 1][n - 1];
if (x2 > x1 || y2 < y1 || max({x1, x2, y1, ... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
const int inf = 1000 * 1000 * 1000;
int dp[599][300][300], a[300][300],
shift[4][2] = {{0, 0}, {-1, 0}, {0, -1}, {-1, -1}};
int main() {
int n;
scanf("%d", &n);
int maxt = 2 * n - 1;
for (int i = 0; i < maxt; ++i)
for (int j = 0; j < n; ++j)
for (int k = 0; k < n; ++k) dp[... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int N;
int A[300][300];
int M[600][300][300];
int dx[] = {1, 0}, dy[] = {0, 1};
int main() {
cin >> N;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++) cin >> A[i][j];
memset(M, 128, sizeof(M));
M[0][0][0] = A[0][0];
for (int i = 0; i < 2 * N - 2; i++) ... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int infl = 1e8 + 5;
int n, m, k, q, x, y, f, val, t = 1, i, j;
int ind = -1, cnt, sz, sm, ans, mx = -1, mn = infl;
int a[304][304], dp[304 + 304][304][304];
int rec(int d, int x1, int x2) {
if (d > n + n - 2) return 0;
if (x1 >= n || x2 >= n) return -infl;
int y... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | import java.util.*;
import static java.lang.System.*;
public class E214 {
Scanner sc = new Scanner(in);
public void run() {
int n=sc.nextInt();
int[][] map=new int[n][n];
for(int y=0;y<n;y++)for(int x=0;x<n;x++)
map[x][y]=sc.nextInt();
int[][] dp=new int[n][n];
... | JAVA |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int a[305][305], dp[610][305][305];
int n;
void chu() {
for (int i = 1; i <= n + n - 1; i++)
for (int j = 0; j <= n; j++)
for (int k = 0; k <= n; k++) dp[i][j][k] = -1000000;
}
int main() {
while (scanf("%d", &n) != -1) {
chu();
for (int i = 0; i <= n;... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int n, C[300][300];
int A[2][300][300], now = 0, ans = 0;
int get(int now, int i1, int i2) {
if (i1 < 0 || i2 < 0) return -(int)HUGE_VAL;
return A[now][i1][i2];
}
int main() {
cin >> n;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) cin >> C[i][j];
fo... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
const int N = 3e2 + 5;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int dr4[] = {1, -1, 0, 0};
const int dc4[] = {0, 0, 1, -1};
const int dr8[] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dc8[] = {0, 1, 1, 1, 0, -1, -1, -... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int n, result = 0, f[605][305][305], a[1000][1000];
void readdata() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
}
}
}
void solve() {
for (int d = 0; d <= 2 * n + 1; d++) {
for (int c1 = 0; c1 <= d; c1++... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 2e6;
const long long mod = 1e9 + 7;
const long long inf = 1e9;
long long a[610][610], f[2][610][610];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i <= 310... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int n;
int a[1005][1005];
int dp[605][303][303];
int calc(int t, int c, int cc) {
if (t == 2 * (n - 1)) {
if (c == n && cc == n)
return a[n][n];
else
return -(1e8);
}
if (dp[t][c][cc] != -1) return dp[t][c][cc];
int r = 2 + t - c;
int rr = 2 + ... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
bool valid(long long i, long long j, long long n, long long m) {
if (i >= 0 && i < n && j >= 0 && j < m) return true;
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
vector<vector<long long> > a(n, vector<lo... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 305;
const int maxint = 999999999;
int dp[2][maxn][maxn];
int a[maxn][maxn];
int n;
bool judge(int x, int y) { return (x >= 1 && y <= n); }
int main() {
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) s... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
int m[300][300], dp[2 * 300][300][300];
int main() {
int n, i, j, k, val;
cin >> n;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
cin >> m[i][j];
}
}
dp[0][0][0] = m[0][0];
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
for (k ... | CPP |
214_E. Relay Race | Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n Γ n cells (represented as unit squares), each cell has some number.
At the beginning of the race Furik stands in a cell with coordinates (1, 1), and Rubik stands in a cell wi... | 2 | 11 | #include <bits/stdc++.h>
using namespace std;
const int N = 2e6;
const long long mod = 1e9 + 7;
const long long inf = 1e9;
long long a[610][610], f[2][610][610];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i <= 310... | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.