output stringlengths 52 181k | instruction stringlengths 296 182k |
|---|---|
#include <bits/stdc++.h>
int main() {
int h1, h2;
scanf("%d %d", &h1, &h2);
int a, b;
scanf("%d %d", &a, &b);
if (h2 - h1 < a * 8) {
printf("0");
return 0;
}
if ((h2 - h1 > a * 8) && (a <= b)) {
printf("-1");
return 0;
}
int day = 0;
int dayend, nightend;
while (1) {
if (day ==... | ### Prompt
Develop a solution in cpp to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpill... |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
using LL = int64_t;
using pii = pair<int, int>;
const double PI = 2 * asin(1);
int g_h1, g_h2, g_a, g_b;
void pretreat() {}
void input() { cin >> g_a >> g_b; }
void solve() {
int t = g_h1 + g_a * 8;
if (t >= g_h2) {
puts("0");
ret... | ### Prompt
In Cpp, your task is to solve the following problem:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpillar wa... |
#include <bits/stdc++.h>
using namespace std;
int h1, h2, a, b, k, day, delta;
int main() {
scanf("%d %d", &h1, &h2);
scanf("%d %d", &a, &b);
delta = a - b;
if (delta <= 0) {
if (a * 8 + h1 >= h2)
printf("0\n");
else
printf("-1\n");
} else {
k = h2 - h1 - a * 8;
if (k > 0) {
... | ### Prompt
Develop a solution in Cpp to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the caterpill... |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 1e18;
vector<int> adj[100005], adj1[100005];
ll cnt, ans;
bool vis[100005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int h1, h2, a, b, diff, av, res;
cin >> h1 >> h2 >> a >> b;
diff = h2 - h1;
if (a <=... | ### Prompt
Please provide a CPP coded solution to the problem described below:
The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h1 cm from the ground. On the height h2 cm (h2 > h1) on the same tree hung an apple and the... |
#include <bits/stdc++.h>
using namespace std;
int treas[310][310];
long long dp[310][310];
long long d[310][310];
vector<pair<int, int> > G[110000];
vector<pair<long long, pair<int, int> > > lst;
queue<pair<long long, pair<int, int> > > bfs;
int dir[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
long long n, m;
long long ... | ### Prompt
Develop a solution in CPP to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
vector<int> Adj[301];
vector<int> Col[301];
vector<pair<int, int> > To[301 * 301];
inline int dist(pair<int, int> A, pair<int, int> B) {
return abs(A.first - B.first) + abs(A.second - B.second);
}
int D[301][301];
const int INF = (int)1e9;
int main() {
int N, M, i, j, P... | ### Prompt
Develop a solution in Cpp to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 305, Inf = 0x3f3f3f3f;
const int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
queue<pair<int, int> > Q;
vector<pair<int, int> > Chest[MaxN * MaxN];
int n, m, p;
int dp[MaxN][MaxN], mat[MaxN][MaxN], Distance[MaxN][MaxN];
inline void ClearQ() {
while (Q.... | ### Prompt
Please formulate a CPP solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
struct data {
int x, y, val, minVal, rMin;
data(int X, int Y) {
x = X;
y = Y;
val = 0;
minVal = 1e9;
rMin = 1e9;
}
};
vector<data> a[int(1e5 + 100)];
int Small, n, m, p;
bool cmp(data x, data y) { return x.val < y.val; }
bool cmp2(data x, data y) {... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)4e2;
const int INF = (int)1e9;
int n, m, a[N][N], p;
int dyn[N][N], last[N];
vector<pair<int, int> > q[N * N];
int len[N][N];
int main() {
cin >> n >> m >> p;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> a[i][j];
... | ### Prompt
Generate a CPP solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ty... |
#include <bits/stdc++.h>
using namespace std;
struct s {
int x, y, v;
bool operator<(const s &a) const { return v < a.v; }
};
int n, m, p, x, ans = 1e9;
vector<s> dp[309 * 309];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> m >> p;
for (int i = 0; i < n; i++)
for (int... | ### Prompt
Develop a solution in CPP to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N = 100010;
const int MAX = 2000000000;
const int mod = 100000000;
const int MOD1 = 1000000007;
const int MOD2 = 1000000009;
const double EPS = 0.00000001;
const long long MOD = 1000000007;
const int INF = 1000... | ### Prompt
Please create a solution in Cpp to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
int r, c;
const int INF = 1000000009;
int g;
int ans;
int vis[333][333];
int dis[333][333];
vector<pair<int, int> > e[90004];
vector<pair<int, int> > cc[90004];
int p;
int main() {
scanf("%d %d %d", &r, &c, &p);
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
long long readi() {
long long input = 0;
char c = ' ';
while (c < '-') {
c = getchar();
}
bool negative = false;
if (c == '-') {
negative = true;
c = getchar();
}
while (c >= '0') {
input = 10 * input + (c - '0');
c = getchar();
}
if ... | ### Prompt
In cpp, your task is to solve the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of... |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int A[500][500];
int D[500][500];
int Dist[310][310];
vector<pair<int, int> > B[250000];
int dist(int x1, int ewrgrg, int x2, int y2) {
return abs(x1 - x2) + abs(ewrgrg - y2);
}
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int main(int... | ### Prompt
Create a solution in cpp for the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ... |
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int32_t x;
scanf("%d", &x);
return x;
}
inline string get() {
char ch[1001000];
scanf("%s", ch);
return ch;
}
template <class P, class Q>
inline P smin(P &a, Q b) {
if (b < a) a = b;
return a;
}
template <class P, class Q>
inline P smax(P &... | ### Prompt
Generate a cpp solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ty... |
#include <bits/stdc++.h>
using namespace std;
int n, m, p, dp[303][303];
vector<pair<int, int> > G[303 * 303];
int main() {
int x, y, z, i, j, k, px, py;
scanf("%d%d", &n, &m);
scanf("%d", &p);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
scanf("%d", &x);
dp[i][j] = 2000000010;
... | ### Prompt
Please create a solution in cpp to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
int n, m, p;
int table[301][301];
int dist[301][301];
bool mark[301][301];
vector<vector<pair<int, int> > > vvpii;
int CalcDist(pair<int, int> u, pair<int, int> v) {
return fabs((u.first) - (v.first)) + fabs((u.second) - (v.second));
}
int dir[4][2] = {{1, 0}, {0, 1}, {-1... | ### Prompt
Please provide a cpp coded solution to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const int nax = 305;
int type[nax][nax];
vector<int> col[nax];
int dp[nax][nax];
vector<pair<int, int>> odw[nax * nax];
bool vis[nax];
int n, m, p;
void pr() {}
int main() {
scanf("%d%d%d", &n, &m, &p);
for (int i = 0; i < n; ++i)
for (int j... | ### Prompt
Please provide a CPP coded solution to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const double PI = acos(-1.0);
const int inf = 0x3f3f3f3f;
template <class T>
void read(T& num) {
char CH;
bool F = false;
for (CH = getchar(); CH < '0' || CH > '9'; F = CH == '-', CH = getchar())
;
for (num = 0; CH >= '0' && CH <= ... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
int dR[] = {-1, 0, 0, +1};
int dC[] = {0, -1, +1, 0};
int n, m, p, x, grid[303][303], dp[303][303], vis[303][303];
vector<pair<int, int> > a[300 * 300 + 3];
void brute(int x) {
for (int i = 0; i < a[x - 1].size(); i++) {
pair<int, int> u = a[x - 1][i];
for (int j ... | ### Prompt
Create a solution in cpp for the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ... |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, pair<int, int> > > v[300 * 300 + 1];
int main() {
int n, m, p, x;
cin >> n >> m >> p;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
scanf("%d", &x);
v[x].push_back({(int)1e9, {i, j}});
}
v[0].push_back({0, {1, 1}});... | ### Prompt
Please provide a cpp coded solution to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T& num) {
char CH;
bool F = false;
for (CH = getchar(); CH < '0' || CH > '9'; F = CH == '-', CH = getchar())
;
for (num = 0; CH >= '0' && CH <= '9';
num = num * 10 + CH - '0', CH = getchar())
;
F && (num = -num);
}
int s... | ### Prompt
Please create a solution in CPP to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
int i, j, n, h, x, y, glob, k, m, p, fx, fy;
int a[505][505], dp[505][505], d[505][505], t[4][2005][2005];
int dir[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
vector<pair<int, int> > g[250505];
vector<pair<int, pair<int, int> > > lst, bfs;
int Abs(int x) { return x > 0 ? x ... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1 + 300 + 5;
const int MAX_M = 1 + 300 + 5;
const int MAX_P = MAX_N * MAX_M;
const int MAX_INF = 0x3fffffff;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const int dSize = 4;
int a[MAX_N][MAX_M];
int dmin[MAX_N][MAX_M];
int N, M, P;
vect... | ### Prompt
In Cpp, your task is to solve the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of... |
#include <bits/stdc++.h>
using namespace std;
void bad(string mes = "Impossible") {
cout << mes;
exit(0);
}
template <typename... T>
void shit(T&... x) {}
template <typename... T>
void dec(T&... x) {
shit(--x...);
}
template <typename... T>
void inc(T&... x) {
shit(++x...);
}
template <typename T>
string bin(T ... | ### Prompt
Create a solution in CPP for the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ... |
#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
puts(f ? "Yes" : "No");
exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
x += y;
if (x >= mod) x -= mod;
}... | ### Prompt
Your task is to create a cpp solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open a... |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 305;
int arr[MAXN][MAXN], cnt[MAXN * MAXN], dp[MAXN][MAXN], dis[MAXN][MAXN];
vector<pair<int, int> > cell[MAXN * MAXN];
int n, m;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
bool valid(int x, int y) { return 1 <= x && x <= n && 1 <= y && y <= m; }... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y, d;
node() { x = 0, y = 0, d = 0; }
node(int a, int b, int c) { x = a, y = b, d = c; }
bool operator<(const node &other) const { return d < other.d; }
};
vector<node> dp[305 * 305];
int n, m, p, x;
int main() {
scanf("%d%d%d", &n, &m, &p);
... | ### Prompt
Create a solution in CPP for the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ... |
#include <bits/stdc++.h>
using namespace std;
int ver[] = {0, 1, 0, -1};
int hor[] = {1, 0, -1, 0};
int main() {
int n, m, p;
cin >> n >> m >> p;
vector<vector<int> > grid;
grid.assign(n + 10, vector<int>(m + 10, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf("%d", &grid[i][j... | ### Prompt
Generate a CPP solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ty... |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const long long INF64 = (long long)1e18;
const long double eps = 1e-9;
const long double pi = 3.14159265358979323846;
const int MAXN = 300;
int n, m, p, d[MAXN][MAXN], dist[MAXN][MAXN];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
vector<v... | ### Prompt
Please formulate a CPP solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e2 + 1, INF = 2e9;
int n, m, pm, d[MAX][MAX];
vector<pair<int, int>> t[MAX * MAX];
int val[MAX][MAX];
int delta[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
bool go(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); }
int main() {
scanf("%d%d%d",... | ### Prompt
Generate a Cpp solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ty... |
#include <bits/stdc++.h>
using namespace std;
const int N = 301, inf = 1e9 + 5;
int dp[N][N];
int a[N][N];
vector<pair<int, int> > positions[N * N];
int n, m, p;
int dis(pair<int, int> a, pair<int, int> b) {
return abs(a.first - b.first) + abs(a.second - b.second);
}
void read() {
cin >> n >> m >> p;
for (int i =... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 300 + 5;
int n, m, p;
int atlas[maxn][maxn];
vector<pair<int, int> > v[maxn * maxn];
int dp[maxn][maxn], dis[maxn][maxn];
bool vis[maxn][maxn];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int solve() {
for (int i = 1; i... | ### Prompt
Develop a solution in cpp to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200001;
int dp[305][305], a[305][305];
int dist[305][305];
int n, m, k;
vector<pair<int, int> > v[90001];
int dy[4] = {0, 0, 1, -1};
int dx[4] = {1, -1, 0, 0};
struct Node {
int y, x, v;
bool operator<(const Node &nd) const { return v > nd.v; }
};
int m... | ### Prompt
Generate a cpp solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ty... |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
int ex[300000], ey[300000], nxt[300000], first[300000];
int ux[300000], uy[300000], uxt[300000], uirst[3000];
int c[300000], d[600][600], e[600][600];
int i, j, k, l, m, n, o, r, s, t, x, y, sum_edge, sum_udge;
inline vo... | ### Prompt
Develop a solution in cpp to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
const int mod1 = 1e9 + 7, mod2 = 998244353, maxn = 305, maxlog = 20, K = 26;
const long long infll = 1e18;
const double pi = acos(-1);
int n, m, p, a[maxn][maxn], fin_dist[maxn][maxn], dist[maxn][maxn];
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
vector<pair<int, in... | ### Prompt
Your task is to create a CPP solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open a... |
#include <bits/stdc++.h>
using namespace std;
int i, j, n, h, x, y, cur_h, k, m, p, fx, fy;
int a[505][505], dp[505][505], d[505][505];
int dir[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
vector<pair<int, int> > g[250505];
vector<pair<int, pair<int, int> > > lst, bfs;
int Abs(int x) { return x > 0 ? x : -x; }
int find_... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
int n, m, p, from[333];
vector<pair<int, int> > a[333 * 333], d[2][3333];
int main() {
scanf("%d%d%d", &n, &m, &p);
int J = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int k;
scanf("%d", &k);
a[k - 1].push_back({i, j});
i... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
void in(int &x);
const int N = 305;
const int INF = 1e9 + 50;
const int MOD = 1e9 + 7;
int n, m, p;
int grid[N][N], dp[N][N], dst[N][N];
vector<ii> pos[N * N];
int dr[] = {-1, 1, 0, 0};
int dc[] = {0, 0, -1, 1};
struct State ... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
int ar[305][305];
vector<pair<int, int> > poss[90005];
int dp[305][305];
vector<int> col[305];
int vis[305];
int n, m, p;
void pr() {}
void solve() {
memset(dp, 127, sizeof(dp));
;
scanf("%d %d %d", &n, &m, &p);
for (int i = 0; i < (int)(n); i++) {
for (int j = ... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
template <class T, class L>
bool smax(T &x, L y) {
return x < y ? (x = y, 1) : 0;
}
template <class T, class L>
bool smin(T &x, L y) {
return y < x ? (x = y, 1) : 0;
}
const int maxn = 3e2 + 17, maxp = maxn * maxn, inf = 2e9;
struct st {
int x, y, d;
};
inline int sin... | ### Prompt
Please provide a cpp coded solution to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
using Point = pair<int, int>;
template <typename T>
using Matrix = vector<vector<T>>;
const array<Point, 4> directions = {{{-1, 0}, {0, 1}, {1, 0}, {0, -1}}};
void bfs(int R, int C, const vector<Point>& source, const vector<Point>& target,
Matrix<int>& global_dista... | ### Prompt
Construct a Cpp code solution to the problem outlined:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest ... |
#include <bits/stdc++.h>
using namespace std;
class Point {
public:
int route;
short int x, y;
Point(int _r, short int _x, short int _y) {
route = _r;
x = _x, y = _y;
}
};
bool comp(const Point &a, const Point &b) {
return a.route < b.route || a.route == b.route && a.x < b.x ||
a.route == b.... | ### Prompt
Construct a CPP code solution to the problem outlined:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest ... |
#include <bits/stdc++.h>
using namespace std;
int n, m, p;
int A[310][310];
int C[310][310];
int d[310][310];
list<pair<int, int> > L[300 * 300 + 100];
int Dist(pair<int, int> a, pair<int, int> b) {
return abs(a.first - b.first) + abs(b.second - a.second);
}
class comp {
public:
bool operator()(const pair<int, int... | ### Prompt
Create a solution in CPP for the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ... |
#include <bits/stdc++.h>
int n, m, k, mp[305][305];
std::vector<std::pair<int, int> > garden[90005];
int dis[305][305], dis2[305][305];
bool vis[305][305];
int dist(std::pair<int, int> a, std::pair<int, int> b) {
return abs(a.first - b.first) + abs(a.second - b.second);
}
void refresh(int lev) {
for (int i = 0; i <... | ### Prompt
Generate a cpp solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ty... |
#include <bits/stdc++.h>
using namespace std;
int m, n, p;
int grid[305][305];
int visit[305][305];
queue<pair<pair<int, int>, int> > q;
struct node {
int x, y, val;
node(int x1, int x2, int x3) {
x = x1;
y = x2;
val = x3;
}
node() {}
};
vector<node> v[90005];
int dirx[4] = {0, 1, 0, -1};
int diry[4... | ### Prompt
Develop a solution in Cpp to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f7f7f7f;
const int MAXN = 305;
const double eps = 1e-10;
int maze[MAXN][MAXN];
int dis[2][MAXN * MAXN];
int n, m, p;
struct node {
int x, y, len, id;
node(int x = 0, int y = 0, int len = 0, int id = 0)
: x(x), y(y), len(len), id(id) {}
};
vector... | ### Prompt
Construct a CPP code solution to the problem outlined:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest ... |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const int N = 305;
const int M = 1e9 + 7;
int n, m, k, p;
int d[N][N];
vector<vector<pair<int, int>>> vec;
vector<pair<int, int>> dist[3][N];
inline int getDIST(int x, int y, int xx, int yy) {
return abs(x - xx) + abs(y - yy);
}
int main() {
io... | ### Prompt
Develop a solution in Cpp to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
const int N = 300;
const int M = 3e6;
const int inf = 1e9;
using namespace std;
int n, m, p, a[N + 5][N + 5], dis[N + 5][N + 5], id[N + 5][N + 5], idc,
q[N * N + 5], dd[N + 5][N + 5], c[N * N + 5], cnt, X[N * N + 5],
Y[N * N + 5];
int dx[5] = {0, 1, -1, 0, 0}, dy[5] = {0, 0, 0, 1, -1};
... | ### Prompt
Your task is to create a CPP solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open a... |
#include <bits/stdc++.h>
using namespace std;
struct __s {
__s() {
srand(time(NULL));
if (1) {
ios_base::Init i;
cin.sync_with_stdio(0);
cin.tie(0);
}
}
~__s() {
if (!1)
fprintf(stderr, "Execution time: %.3lf s.\n",
(double)clock() / CLOCKS_PER_SEC);
int n... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > V[310 * 310];
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
int a[310][310];
int dp[310][310];
int dis[310][310];
int vis[310][310];
int main() {
int n, m, p;
cin >> n >> m >> p;
memset(dp, (127), sizeof(dp));
for (int i = 1; i <= n; ... | ### Prompt
Develop a solution in Cpp to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e2;
const long long INF = 4e18;
int n, m, p;
long long matrix[N][N], ans[N][N], bfs[N][N];
bool used[N][N];
struct Coord {
int x, y;
Coord() {}
Coord(long long x, long long y) {
this->x = x;
this->y = y;
}
} bg(0, 0);
vector<pair<int, int> > d... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 87654321;
class Fenwick {
public:
vector<int> tree;
int length;
int Rmq(int i) {
int ret = INF;
while (i) {
ret = min(ret, tree[i]);
i -= i & -i;
}
return ret;
}
void Update(int i, int val) {
while (i <= length)... | ### Prompt
Your task is to create a CPP solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open a... |
#include <bits/stdc++.h>
using namespace std;
const int fx[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const int fxx[8][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0},
{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
template <typename T, typename TT>
ostream& operator<<(ostream& s, pair<T, TT> t) {
return s << "... | ### Prompt
Construct a cpp code solution to the problem outlined:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest ... |
#include <bits/stdc++.h>
using namespace std;
int mat[303][303], n, m, p = 2;
int dp[303][303];
vector<pair<int, int> > all[303 * 303];
vector<int> v[303];
bool vis[303];
int main() {
int i, j;
scanf("%d", &n);
scanf("%d", &m);
scanf("%d", &p);
if (p == 1) return cout << 0 << endl, 0;
memset(dp, 0x3f3f3f3f,... | ### Prompt
Create a solution in cpp for the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ... |
#include <bits/stdc++.h>
using namespace std;
struct IO {
char buf[(1 << 20)], *p1, *p2;
char pbuf[(1 << 20)], *pp;
IO() : p1(buf), p2(buf), pp(pbuf) {}
inline char gc() {
return getchar();
if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, (1 << 20), stdin);
return p1 == p2 ? ' ' : *p1++;
}
inline b... | ### Prompt
Create a solution in CPP for the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ... |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 8;
const double eps = 0.1;
const int N = 305;
const int M = 304 * 305;
vector<pair<int, int> > g[M];
int n, m, p;
vector<pair<int, int> > v[690];
int ans;
pair<int, int> p1, p2;
int dp[N][N], dp1[N][N];
int a[N][N];
int val, q, w;
void go(int first, in... | ### Prompt
Create a solution in Cpp for the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300 + 5;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
int n, m, p;
int g[maxn][maxn], d[maxn][maxn];
int dis[maxn][maxn], inq[maxn][maxn];
vector<pair<int, int> > rec[maxn * maxn];
queue<pair<int, int> > que;
int main() {
memset(d, 63... | ### Prompt
Develop a solution in CPP to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 301, Mo = 1e9 + 7, INF = INT_MAX;
int n, m, p;
vector<int> xx[Maxn * Maxn], yy[Maxn * Maxn];
vector<int> w[Maxn];
int d[Maxn][Maxn], a[Maxn][Maxn];
string st;
int main() {
cin >> n >> m >> p;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)... | ### Prompt
Please create a solution in cpp to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:667772160")
template <class T1>
void deb(T1 e1) {
cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
co... | ### Prompt
Your task is to create a cpp solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open a... |
#include <bits/stdc++.h>
#pragma GCC target("sse4,avx")
const int64_t inf = 1LL << 60;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
void run(std::istream& in, std::ostream& out) {
int n, m, p;
in >> n >> m >> p;
std::vector<std::vector<int>> graph(n, std::vector<int>(m, 0));
std::vector<std... | ### Prompt
Create a solution in Cpp for the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ... |
#include <bits/stdc++.h>
using namespace std;
struct data {
int x, y, val;
data(int X, int Y) {
x = X;
y = Y;
val = 1e9;
}
};
vector<data> a[int(1e5 + 100)];
int Small, n, m, p;
bool cmp(data x, data y) { return x.val < y.val; }
bool cmp2(data x, data y) { return x.x < y.x; }
int dist(data x, data y) ... | ### Prompt
Please create a solution in cpp to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int32_t x;
scanf("%d", &x);
return x;
}
inline string get() {
char ch[1001000];
scanf("%s", ch);
return ch;
}
template <class P, class Q>
inline P smin(P &a, Q b) {
if (b < a) a = b;
return a;
}
template <class P, class Q>
inline P smax(P &... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
const long long OO = 1e9;
const int MAX = 305;
vector<pair<int, pair<int, int> > > a[MAX * MAX];
int main() {
int n, m, p;
cin >> n >> m >> p;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
int x;
scanf("%d", &x);
a[x].push_back(make_p... | ### Prompt
Please formulate a CPP solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
template <class T>
inline T readint(T& a) {
a = 0;
char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') {
a = (a << 3) + (a << 1) + c - '0';
c = getchar();
}
return a;
}
struct BIT {
int v[... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXH = 300;
const int MAXW = 300;
const int MAXVAL = 300 * 300;
const int MAXD = MAXH + MAXW - 2;
const int DX[] = {-1, 0, +1, 0}, DY[] = {0, +1, 0, -1};
int h, w, nval, dmx;
int t[MAXH... | ### Prompt
Please formulate a Cpp solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 305;
int n, m, p;
int arr[MAXN][MAXN];
vector<pair<int, int> > pos[MAXN * MAXN];
int ma[MAXN * MAXN];
int cnt = 0;
int dist[MAXN][MAXN][MAXN];
int xx[4] = {-1, 1, 0, 0};
int yy[4] = {0, 0, -1, 1};
int dp[MAXN][MAXN];
int di[MAXN][MAXN];
int ur[MAXN][MAXN];
... | ### Prompt
In CPP, your task is to solve the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of... |
#include <bits/stdc++.h>
using namespace std;
const int z = 300;
struct cool {
int x, y, d;
};
vector<cool> a[z * z + 1];
int n, m, p;
bool comp(cool a, cool b) { return (a.d < b.d); }
int main() {
cin >> n >> m >> p;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
int x;
cool c;
c... | ### Prompt
Please create a solution in cpp to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
const int N = 303;
const int P = N * N;
const int OO = P * N * 2;
int val[N][N];
int new_val[N][N];
int last[N][N];
vector<pair<int, int>> pos[P];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, m, p;
cin >> n >> m >> p;
for (int i = 0; i ... | ### Prompt
Please create a solution in cpp to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
const int N = 305;
int dp[N][N], d[N][N], a[N][N], n, m, p;
class Grid {
public:
int row, col;
Grid(int row, int col) {
this->row = row;
this->col = col;
}
};
class Data {
public:
int val, row, col;
Data(int val, int row, int col) {
this->val = val;
... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > in[300 * 300 + 1];
int dp[300][300];
void smin(int &a, int b) { a = min(a, b); }
int main() {
for (int i = 0; i < 300; i++) fill(dp[i], dp[i] + 300, 1e9);
int n, m, p;
cin >> n >> m >> p;
for (int i = 0; i < n; i++) {
for (int j = 0; j < ... | ### Prompt
Create a solution in cpp for the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ... |
#include <bits/stdc++.h>
using namespace std;
const int N = 600005;
const long long mod = (long long)1e9 + 7;
int a[305][305], n, m;
int dist[305][305], val[100000], tmpdist[305][305];
int di[4] = {0, 1, 0, -1};
int dj[4] = {1, 0, -1, 0};
vector<vector<pair<int, int> > > l;
int diff(pair<int, int> u, pair<int, int> v) ... | ### Prompt
Create a solution in Cpp for the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ... |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 6, inf = 1e18, mod = 1e9 + 7;
long long n, m, p, dis[305][305], a[305][305], tmp[305][305];
vector<pair<int, int> > vec[305 * 305], V;
bool mark[305][305];
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> m >> p... | ### Prompt
Generate a CPP solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ty... |
#include <bits/stdc++.h>
using namespace std;
const int N = 310;
const int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};
vector<pair<int, int> > g[N * N];
int n, m, p, gx, gy;
int f[N][N], d[N][N];
queue<pair<int, pair<int, int> > > q;
vector<pair<int, pair<int, int> > > gg;
bool valid(int x, int y) {
return (x <= n ... | ### Prompt
Create a solution in CPP for the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ... |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const int N = 305;
const int M = 1e9 + 7;
int n, m, k, p;
int d[N][N];
vector<vector<pair<int, int>>> vec;
vector<pair<int, int>> dist[3][N];
inline int getDIST(int x, int y, int xx, int yy) {
return abs(x - xx) + abs(y - yy);
}
int main() {
io... | ### Prompt
Construct a Cpp code solution to the problem outlined:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest ... |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 300 + 5;
int n, m, p;
int grid[MAX][MAX];
int dp[MAX][MAX];
vector<pair<int, int> > pos[MAX * MAX];
vector<int> col[MAX];
int main() {
scanf("%d %d %d", &n, &m, &p);
for (int i = int(0); i < int(n); i++) {
for (int j = int(0); j < int(m); j++) {
... | ### Prompt
In CPP, your task is to solve the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of... |
#include <bits/stdc++.h>
using namespace std;
struct Point {
int x, y, c;
Point() {}
Point(int x, int y, int c) : x(x), y(y), c(c) {}
};
const int INF = 1e9;
int n, m, p;
vector<vector<Point> > pt;
vector<vector<int> > dp;
vector<vector<int> > a;
inline int dist(const Point& p1, const Point& p2) {
return abs(p1... | ### Prompt
Please create a solution in cpp to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int SIZE = 1e6 + 5;
const long long INF = 1LL << 58;
const double eps = 1e-13;
int v[309][309];
vector<pair<int, int> > c[90009];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int dist[309][309];
int main() {
int n, m, p;
sca... | ### Prompt
In CPP, your task is to solve the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of... |
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int n, m, x;
long long dis[400][400];
long long d[400][400];
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
vector<pair<int, int> > v[N];
bool in(int i, int j) { return 1 <= i && i <= n && 1 <= j && j <= m; }
int main() {
for (int i = 0; i < 400... | ### Prompt
Develop a solution in cpp to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > V[310 * 310];
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
int a[310][310];
int dp[310][310];
int dis[310][310];
int vis[310][310];
int main() {
int n, m, p;
cin >> n >> m >> p;
memset(dp, (127), sizeof(dp));
for (int i = 1; i <= n; ... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
int a[302][302], tmp[302][302], dis[302][302];
int dx[] = {0, 0, 1, -1};
int dy[] = {-1, 1, 0, 0};
vector<pair<int, int> > v[(int)9e4 + 3];
int main() {
int t, i, j, n, q, k, l, r, c, fnl;
scanf("%d %d %d", &r, &c, &fnl);
for (i = 1; i <= r; i++) {
for (j = 1; j <... | ### Prompt
Construct a cpp code solution to the problem outlined:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest ... |
#include <bits/stdc++.h>
using namespace std;
int n, m, p;
int ans[301][301];
vector<pair<int, int>> kub[900001];
vector<int> kubb[900001];
int counter;
int ind[90001][301];
int dist(pair<int, int>& a, pair<int, int>& b) {
return abs(a.first - b.first) + abs(a.second - b.second);
}
pair<int, int> getL(int i, int l, i... | ### Prompt
Create a solution in Cpp for the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ... |
#include <bits/stdc++.h>
struct Point {
int x, y;
};
struct State {
int x, y, dis;
};
std::vector<Point> V[330 * 330];
int dp[330][330], n, m, p, a[330][330];
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
bool vis[330][330];
State q[1000010];
bool cmp(Point &A, Point &B) { return dp[A.x][A.y] < dp[B.x][B.... | ### Prompt
Create a solution in CPP for the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ... |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int N = 500;
const int P = N * N;
const int DIFF = N + N;
vector<int> x[P], y[P];
int n, m, p, a[N][N], dp[N][N], bfs[N][N];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int abs(int x) { return x >= 0 ? x : -x; }
void bfsSolve(int lvl) {
... | ### Prompt
Construct a Cpp code solution to the problem outlined:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest ... |
#include <bits/stdc++.h>
using namespace std;
int n, m, p;
int t[333][333];
vector<pair<int, int>> z[333 * 333];
long long d[333][333];
int rr[333][333];
long long rx[333][333];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> p;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; ... | ### Prompt
Please formulate a Cpp solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
struct node {
int dis, pos;
} b[3050000], now;
int a[310][310];
int dp[310][310];
bool cmp(node a, node b) { return a.dis < b.dis; }
vector<node> mp[310 * 310];
int main() {
int n, m, p;
scanf("%d%d%d", &n, &m, &p);
for (int i = 1; i <= n; i++)
for (int j = 1; j... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
const int N = 305;
int n, m, p;
int dp[N][N], visited[N][N], specialdp[N][N];
map<int, vector<pair<int, int> > > color;
struct node {
int r, c, cost;
bool operator<(const node &t) const { return cost < t.cost; }
};
bool open(int r, int c) {
if (r < 1 || c < 1 || r > n... | ### Prompt
In cpp, your task is to solve the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of... |
#include <bits/stdc++.h>
using namespace std;
int n, m, p, k, a;
vector<pair<int, int> > G[90002];
int dp[2][302][302];
int main() {
memset(dp[1], -1, sizeof(dp[1]));
cin >> n >> m >> p;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
cin >> a;
G[a].push_back({i, j});
if (a == 1)... | ### Prompt
Generate a cpp solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ty... |
#include <bits/stdc++.h>
using namespace std;
int ar[305][305];
vector<int> col[305];
int dp[305][305];
vector<pair<int, int> > poss[90005];
bool vis[305];
int n, m, p;
void pr() {}
int main() {
scanf("%d%d%d", &n, &m, &p);
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j) {
scanf("%d", &ar[i][j]);
... | ### Prompt
Your task is to create a CPP solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open a... |
#include <bits/stdc++.h>
typedef long long LL;
const double INF = 1e100;
const int oo = ~0u >> 2;
const double pi = acos(-1.0);
const double EPS = 1e-8;
const int MAXN = 100033;
int dp[303][303];
int map[303][303];
std::vector<std::pair<int, int> > s[90003];
std::vector<int> c[303];
int vis[303];
int n, m, p;
int main(... | ### Prompt
Please create a solution in Cpp to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T SQR(T x) {
return x * x;
}
template <typename T>
inline T MIN(T x, T y) {
return (x < y) ? x : y;
}
template <typename T>
inline T MAX(T x, T y) {
return (x > y) ? x : y;
}
template <typename T>
inline T ABS(T x) {
return (x > 0) ? x :... | ### Prompt
Generate a Cpp solution to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ty... |
#include <bits/stdc++.h>
using namespace std;
struct data {
int x, y, val, minVal, rMin;
data(int X, int Y) {
x = X;
y = Y;
val = 0;
minVal = 1e9;
rMin = 1e9;
}
};
vector<data> a[int(1e5 + 100)];
int Small, n, m, p;
bool cmp(data x, data y) { return x.val < y.val; }
bool cmp2(data x, data y) {... | ### Prompt
Create a solution in CPP for the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of ... |
#include <bits/stdc++.h>
using namespace std;
struct point {
int x, y;
int64_t time;
int dist(const point& p) const { return abs(x - p.x) + abs(y - p.y); }
bool operator<(const point& p) const { return time > p.time; }
};
int n, m, p;
vector<point> s[300 * 300 + 1];
int64_t t[300][300];
int main() {
cin >> n ... | ### Prompt
In cpp, your task is to solve the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of... |
#include <bits/stdc++.h>
using namespace std;
const int MOD(1000000007);
const int INF((1 << 30) - 1);
const int MAXN(305);
struct cell {
int x, y, v;
cell(){};
cell(int x, int y, int v) : x(x), y(y), v(v){};
bool operator<(const cell &other) const { return v < other.v; }
};
vector<cell> a[MAXN * MAXN];
int cnt... | ### Prompt
Please provide a cpp coded solution to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can op... |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 3e2 + 5;
queue<pair<int, int> > q;
vector<pair<int, int> > v[N * N];
int n, m, p;
int a[N][N], f[N][N];
int *ans;
int dis(int x, int y, int a, int b) { return abs(x - a) + abs(y - b); }
void init() {
for (int i = 0; i <= n * m; i+... | ### Prompt
Develop a solution in Cpp to the problem described below:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
struct data {
int x, y, val;
data(int X, int Y) {
x = X;
y = Y;
val = 1e9;
}
};
vector<data> a[int(1e5 + 100)];
int Small, n, m, p;
bool cmp(data x, data y) { return x.val < y.val; }
bool cmp2(data x, data y) { return x.x < y.x; }
int dist(data x, data y) ... | ### Prompt
In CPP, your task is to solve the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of... |
#include <bits/stdc++.h>
using namespace std;
int INF = 310 * 310 * 310;
int n, m, p;
int dp[310][310];
int a[310][310];
vector<pair<int, int> > s[310 * 310];
int d_x[] = {0, 0, 1, -1};
int d_y[] = {1, -1, 0, 0};
void bfs(int node) {
queue<pair<int, int> > q;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j... | ### Prompt
In cpp, your task is to solve the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest of... |
#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 87654321;
class Fenwick {
public:
vector<int> tree;
int length;
int Rmq(int i) {
int ret = INF;
while (i) {
ret = min(ret, tree[i]);
i -= i & -i;
}
return ret;
}
void Update(int i, int val) {
while (i <= length)... | ### Prompt
Please create a solution in Cpp to the following problem:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any che... |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int K = 777;
int n, m, p;
int a[321][321];
int dp[321][321];
int ndp[321][321];
vector<pair<int, int> > wh[MaxN], q[MaxN];
int main() {
scanf("%d%d%d", &n, &m, &p);
for (int i = 1; i <= n; ++... | ### Prompt
Construct a CPP code solution to the problem outlined:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest ... |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
int arr[512][512], cnt[102400];
int dp[512][512], dis[512][512];
vector<pair<int, int> > pos[102400];
int main() {
int n, m, p, enx, eny;
scanf("%d%d%d", &n, &m, &p);
for (int i = 0; i < n; i++) {
for (int j = 0; j <... | ### Prompt
Construct a Cpp code solution to the problem outlined:
Vanya is in the palace that can be represented as a grid n Γ m. Each room contains a single chest, an the room located in the i-th row and j-th columns contains the chest of type aij. Each chest of type x β€ p - 1 contains a key that can open any chest ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.