prob_desc_description stringlengths 63 3.8k | prob_desc_output_spec stringlengths 17 1.47k ⌀ | lang_cluster stringclasses 2 values | src_uid stringlengths 32 32 | code_uid stringlengths 32 32 | lang stringclasses 7 values | prob_desc_output_to stringclasses 3 values | prob_desc_memory_limit stringclasses 19 values | file_name stringclasses 111 values | tags listlengths 0 11 | prob_desc_created_at stringlengths 10 10 | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_notes stringlengths 4 3k ⌀ | exec_outcome stringclasses 1 value | difficulty int64 -1 3.5k ⌀ | prob_desc_input_from stringclasses 3 values | prob_desc_time_limit stringclasses 27 values | prob_desc_input_spec stringlengths 28 2.42k ⌀ | prob_desc_sample_outputs stringlengths 2 796 | source_code stringlengths 42 65.5k | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 02433b15b2f6e1ec1eb7f2c474b407e4 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include<stdio.h>
int main()
{
int h, w;
scanf("%d %d", &h, &w);
int i, j;
int r[1003], c[1003];
for (i = 0; i < h; i++)
scanf("%d", &r[i]);
for (i = 0; i < w; i++)
scanf("%d", &c[i]);
int s[1003][1003];
for (i = 0; i < h; i++)
for (j = 0; j < w; j++)
s[i][j] = 0;
for (i = 0; i < h; i++)
{
for (j = 0; j < r[i]; j++)
s[i][j] = 1;
s[i][r[i]] = 2;
}
for (j = 0; j < w; j++)
{
for (i = 0; i < c[j]; i++)
{
if (s[i][j] == 2)
{
printf("0\n");
return 0;
}
s[i][j] = 1;
}
if (s[c[j]][j] == 1)
{
printf("0\n");
return 0;
}
s[c[j]][j] = 2;
}
long long int ans = 1, mod = 1000000007;
for (i = 0; i < h; i++)
for (j = 0; j < w; j++)
if (s[i][j] == 0)
ans = 2 * ans % mod;
printf("%lld\n", ans);
return 0;
} | |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | a9dc1a22dcf09d3a63561187a796514f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include<stdio.h>
int main()
{
int h,w;
scanf("%d %d",&h,&w);
long long int ways=1;
int i,j,r[h],c[w];
for(i=0;i<h;i++)
scanf("%d",&r[i]);
for(i=0;i<w;i++)
scanf("%d",&c[i]);
for(i=0;i<w;i++)
{
for(j=0;j<h;j++)
{
if(i+1>r[j]+1)
{
if(j+1>c[i]+1)
{
ways*=2;
ways=ways%1000000007;
}
}
if((i+1<=r[j] && j==c[i])||(j+1<=c[i] && i==r[j]))
{
ways=0;
break;
}
}
if(ways==0)
break;
}
printf("%lld",ways);
return 0;
}
| |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 0df7caa685b7d3f559de33871821448d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include <stdio.h>
long long BP(long long a, long long b, long long p)
{
long long r = 1;
while (b)
{
if (b & 1)
{
r *= a;
r %= p;
}
a *= a;
a %= p;
b >>= 1;
}
return r;
}
int H[1001];
int W[1001];
int main()
{
int i, j;
int h, w;
long long C = 0;
long long R;
scanf("%d %d", &h, &w);
for (i = 1; i <= h; i++)
{
scanf("%d", &H[i]);
}
for (i = 1; i <= w; i++)
{
scanf("%d", &W[i]);
}
for (i = 1; i <= w; i++)
{
for (j = 1; j <= h; j++)
{
if (H[j] + 1 == i && W[i] >= j)
{
C = -1;
break;
}
else if (H[j] >= i && W[i] + 1 == j)
{
C = -1;
break;
}
else if (H[j] + 1 < i && W[i] + 1 < j)
{
C++;
}
}
if (j <= h)
{
break;
}
}
if (~C)
{
R = BP(2, C, 1000000007);
}
else
{
R = 0;
}
printf("%I64d", R);
return 0;
}
| |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 55eef044ad138bf1f9106f71243656b2 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | /* AUTHOR:AKASH JAIN
* USERNAME:akash19jain
* DATE:06/10/2019
*/
/*#include<algorithm>
#include <bits/stdc++.h>
using namespace std;*/
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
#define SC1(x) scanf("%lld",&x)
#define SC2(x,y) scanf("%lld%lld",&x,&y)
#define SC3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define SCS(x) scanf("\n%s", x)
#define PF1(x) printf("%lld\n",x)
#define PF2(x,y) printf("%lld %lld\n",x,y)
#define PF3(x,y,z) printf("%lld %lld %lld\n",x,y,z)
#define PFN printf("\n")
#define REP(i,n) for(long long i=0;i<(n);i++)
#define FOR(i,a,b) for(long long i=(a);i<=(b);i++)
#define FORD(i,a,b) for(long long i=(a);i>=(b);i--)
#define WHILE(n) while(n--)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define ITOC(c) ((char)(((ll)'0')+c))
#define MID(s,e) (s+(e-s)/2)
#define SZ(a) strlen(a)
#define MOD 1000000007
#define MAX 10000000005
#define MIN -10000000005
#define PI 3.1415926535897932384626433832795
#define DEB(x) printf("The value of \"%s\" is: %d\n",#x,x)
#define CASES ll t;SC1(t);while(t--)
#define ABS(a) ((a>0)?a:-(a))
#define SWAP(a,b) ll z=a;a=b;b=z
#define SWAPC(a,b) char z=a;a=b;b=z
const int INF = 1<<29;
typedef long long ll;
typedef unsigned long long ull;
#define FILEIO(name) \ freopen(name".in", "r", stdin); \ freopen(name".out", "w", stdout);
int cmp(const void * a,const void * b);
long long maxv(long long a,long long b);
long long minv(long long a,long long b);
long long gcd(long long u,long long v);
long long digits(long long n);
bool isPoweroftwo(long long n);
int main()
{
ll h,w;
SC2(h,w);
ll mat[h][w];
REP(i,h)
{
REP(j,w)
{
mat[i][j]=-1;
}
}
REP(i,h)
{
ll r;
SC1(r);
REP(j,r)
mat[i][j]=1;
if(r<w)
mat[i][r]=0;
}
ll f=0;
REP(i,w)
{
ll r;
SC1(r);
REP(j,r)
{
if(mat[j][i]==0)
{
f=1;
break;
}
mat[j][i]=1;
}
if(r<h)
{
if(mat[r][i]==1)
{
f=1;
break;
}
mat[r][i]=0;
}
}
if(f)
printf("0\n");
else
{
ll c=0;
REP(i,h)
{
REP(j,w)
{
if(mat[i][j]==-1)
c++;
}
}
ll ans=1;
REP(i,c)
{
ans=(ans*2)%MOD;
}
PF1(ans);
}
return 0;
}
//qsort(arr,n,sizeof(arr[0]),cmp);
int cmp (const void * a, const void * b)
{
if( *(ll*)a - *(ll*)b < 0 ) return -1;
if( *(ll*)a - *(ll*)b > 0 ) return 1;
return 0;
}
long long maxv(long long a,long long b)
{
if(a>b) return a;
return b;
}
long long minv(long long a,long long b)
{
if(a<b) return a;
return b;
}
long long gcd(long long u,long long v)
{
if (v == 0) return u;
return gcd(v, u%v);
}
long long digits(long long n) //to calculate no of digits in a number
{
return floor(log10(n))+1;
}
bool isPoweroftwo(long long x)
{
return x && (!(x&(x-1)));
} | |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | dad2a16de13ad824ff4c08b7f77aed85 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | a[1111], b[1111], f[1111][1111], p = 1e9 + 7, aa;
pw(x, y) {
int r = 1;
for (; y; y >>= 1, x = 1ll * x * x % p)
if (y & 1) r = 1ll * r * x % p;
return r;
}
main(n, m, i, j) {
memset(f, -1, sizeof f);
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++) {
scanf("%d", a + i);
for (j = 1; j <= a[i]; j++) {
if (f[i][j] != -1 && f[i][j] != 1) return puts("0"), 0;
f[i][j] = 1;
}
if (f[i][a[i] + 1] != -1 && f[i][a[i] + 1]) return puts("0"), 0;
f[i][a[i] + 1] = 0;
}
for (i = 1; i <= m; i++) {
scanf("%d", b + i);
for (j = 1; j <= b[i]; j++) {
if (f[j][i] != -1 && f[j][i] != 1) return puts("0"), 0;
f[j][i] = 1;
}
if (f[b[i] + 1][i] != -1 && f[b[i] + 1][i]) return puts("0"), 0;
f[b[i] + 1][i] = 0;
}
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++) aa += -1 == f[i][j];
printf("%d", pw(2, aa));
} | |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 0ebf0094824f30d917a659510bddfa66 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include <stdio.h>
#include <math.h>
int R,C,i,j,x=0;
int ans=1;
int r[1001]={0},c[1001]={0},a[1002][1002]={0};
int main(int argc, char *argv[]) {
scanf("%d%d",&R,&C);
for(i=1;i<=R;i++){
scanf("%d",&r[i]);
for(j=1;j<=r[i];j++) a[i][j]+=2;
a[i][r[i]+1]+=1;
}
for(i=1;i<=C;i++){
scanf("%d",&c[i]);
for(j=1;j<=c[i];j++) a[j][i]+=2;
a[c[i]+1][i]+=1;
}
for(i=1;i<=R;i++){
for(j=1;j<=C;j++){
if(a[i][j]==0) x++;
else if((a[i][j]%3==0)){
printf("0");
return 0;
}
}
}
while(x>0){
ans*=2;
ans%=1000000007;
x--;
}
printf("%d",ans);
return 0;
} | |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 7ae527d7197ba293d9c72e0e9bcf1567 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include <stdio.h>
int main() {
int h,w;
scanf("%d",&h);
scanf("%d",&w);
int flag=1;
int mat[h][w];//w-количесвто столбцоы h количесвто строк
//-1неопределенный цвет 0 белый 1-черный
for (int i=0;i<w;i++){
for (int j=0;j<h;j++){
mat[j][i]=-1;
}
}
int elem;
for (int p=0;p<h;p++){
scanf("%d",&elem);
for (int k=0;k<elem;k++){
mat[p][k]=1;
if (elem!=w){mat[p][elem]=0;}
}
if (elem==0){mat[p][0]=0;}
}
// for (int j=0;j<h;j++){
// for (int i=0;i<w;i++){
// printf("%d ",mat[j][i]);
// }
// printf("\n");
//}
for (int p=0;p<w;p++) {
scanf("%d", &elem);
for (int k = 0; k < elem; k++) {
if (mat[k][p] != 0) { mat[k][p] = 1; }
else { flag = 0; }
if (elem != h) {
if (mat[elem][p] != 1) { mat[elem][p] = 0; }
else { flag = 0;}
}
}
if (elem==0){
if (mat[0][p]!=1) {mat[0][p]=0;}
else{flag=0;}
}
}
int res=0;
int sum=0;
for (int i=0;i<w;i++){
for (int j=0;j<h;j++){
if (mat[j][i]==-1) {sum=sum+1;};
}
}
if (flag==0) {res=0;}
else{
res=1;
for (int r=0;r<sum;r++){
res=res*2;
res=res%1000000007;
}
}
printf("%d",res);
return 0;
} | |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | ab0096b2f883b23f5762b176d7bbbe9d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include <stdio.h>
int main()
{
int i, j, k, l, h, w, num;
long long int possibility = 1;
scanf("%d %d", &h, &w);
int grid[h][w];
for (i=0; i<h; i++) {
for (j=0; j<w; j++) {
grid[i][j] = 2;
}
}
for (i=0; i<h; i++) {
scanf("%d", &num);
for (j=0; j<=num && j<w; j++) {
if (j==num) {
if (grid[i][j]==1) {
printf("0");
return 0;
}
grid[i][j] = 0;
}
else {
if (grid[i][j]==0) {
printf("0");
return 0;
}
grid[i][j] = 1;
}
}
}
for (j=0; j<w; j++) {
scanf("%d", &num);
for (i=0; i<=num && i<h; i++) {
if (i==num) {
if (grid[i][j]==1) {
printf("0");
return 0;
}
grid[i][j] = 0;
}
else {
if (grid[i][j]==0) {
printf("0");
return 0;
}
grid[i][j] = 1;
}
}
}
for (i=0; i<h; i++) {
for (j=0; j<w; j++) {
if (grid[i][j]==2) {
possibility *= 2;
if (possibility>=1000000007) {
possibility -= 1000000007;
}
}
}
}
printf("%I64d", possibility);
return 0;
}
| |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 03ba27873772a5342cc2ab1ce7ff3ae7 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include <stdio.h>
#define N 1000000007
#define M 1000
long long power(int a, int b){
long long c=1;
for (int i=0; i<b; i++){
c*=a;
if (c>N) c%=N;
}
return c;
}
long long answer(const int *r, const int *c, int h, int w, int matr[][M]){
for (int i=0; i<h; i++){
for (int j=0; j<w; j++){
if (j<r[i]) matr[i][j]=1;
else if (j==r[i]) matr[i][j]=0;
else matr[i][j]=-1;
}
}
int f=1;
for (int i=0; i<w && f==1; i++){
for (int j=0; j<h; j++){
if (j<c[i]){
if (matr[j][i]!=0) matr[j][i]=1;
else{
f=0;
break;
}
}
else if (j==c[i]){
if (matr[j][i]!=1) matr[j][i]=0;
else{
f=0;
break;
}
}
}
}
if (f==0) return 0;
long long answer=1;
for (int i=0; i<h; i++){
int count=0;
for (int j=0; j<w; j++){
if (matr[i][j]!=-1) continue;
count++;
}
answer*=power(2, count);
if (answer>N) answer%=N;
}
return answer%N;
}
int main(){
int h, w, r[M], c[M], matr[M][M];
scanf("%d%d", &h, &w);
for (int i=0; i<h; i++) scanf("%d", &r[i]);
for (int i=0; i<w; i++) scanf("%d", &c[i]);
printf("%lld", answer(r, c, h, w, matr));
return 0;
} | |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 4ffc1abe6e091e07d89af9e32af33491 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include <stdio.h>
int main(void) {
int h,w;
scanf("%d %d\n", &h, &w);
int he[1000];
int we[1000];
for(int i=0;i<h;i++) {
scanf("%d ", &he[i]);
}
scanf("\n");
for(int i=0;i<w;i++) {
scanf("%d ", &we[i]);
}
int grid[1000][1000];
for(int i=0;i<1000;i++) {
for(int j=0;j<1000;j++) {
grid[i][j]=0;
}
}
for(int i=0;i<h;i++) {
for(int j=0;j<he[i];j++) {
grid[i][j]=1;
}
grid[i][he[i]]=-1;
}
for(int i=0;i<w;i++) {
for(int j=0;j<we[i];j++) {
if (grid[j][i]==-1) {
printf("0");
return 0;
}
grid[j][i]=1;
}
if (grid[we[i]][i]==1) {
printf("0");
return 0;
}
grid[we[i]][i]=-1;
}
int to=0;
for(int i=0;i<h;i++) {
for(int j=0;j<w;j++) {
if (grid[i][j]==0) {
to+=1;
}
}
}
int ans=1;
for(int i=0;i<to;i++) {
ans=(ans*2)%1000000007;
}
printf("%d", ans);
return 0;
} | |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 822a29999204fc2d5a47666554ee9a2f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include <stdio.h>
int main(void) {
int h,w;
scanf("%d %d\n", &h, &w);
int he[1000];
int we[1000];
int grid[1000][1000];
for(int i=0;i<1000;i++) {
for(int j=0;j<1000;j++) {
grid[i][j]=0;
}
}
for(int i=0;i<h;i++) {
scanf("%d ", &he[i]);
}
scanf("\n");
for(int i=0;i<w;i++) {
scanf("%d ", &we[i]);
}
for(int i=0;i<h;i++) {
for(int j=0;j<he[i];j++) {
grid[i][j]=1;
}
grid[i][he[i]]=-1;
}
for(int i=0;i<w;i++) {
for(int j=0;j<we[i];j++) {
if (grid[j][i]==-1) {
printf("0");
return 0;
}
grid[j][i]=1;
}
if (grid[we[i]][i]==1) {
printf("0");
return 0;
}
grid[we[i]][i]=-1;
}
int to=0;
for(int i=0;i<h;i++) {
for(int j=0;j<w;j++) {
if (grid[i][j]==0) {
to+=1;
}
}
}
int ans=1;
for(int i=0;i<to;i++) {
ans=(ans*2)%1000000007;
}
printf("%d", ans);
return 0;
} | |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | b31f019ceddf4a7e01afb316caf8c674 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <limits.h>
typedef long long ll;
ll MAX = 100000000000; // 1e11
ll MIN = -100000000000; // -1e11
ll MOD = 1000000007;
ll longlongmax = __LONG_LONG_MAX__;
ll maxormin(ll a,ll b,ll flag){
return flag==1?(a>b?a:b):(a<b?a:b);
}
ll overflowcheck(ll a){
if(a==1){
return 0;
}
else
{
ll temp = a;
ll power = 1;
while( longlongmax/temp>a ){
temp *= a;
power++;
}
return power+1; // Overflow occurs at this power.
}
}
ll merge(ll A[],ll B[],ll left,ll mid,ll right){
ll count = 0;
ll n1 = mid-left+1;
ll n2 = right-mid;
ll LA[n1],LB[n1],RA[n1],RB[n2];
for(ll n=0;n<n1;n++){ LA[n] = A[n+left];LB[n] = B[n+left];}
for(ll n=0;n<n2;n++){ RA[n] = A[n+mid+1];RB[n] = B[n+mid+1];}
ll i=0,j=0,k=left;
while(i<n1&&j<n2){
if(LA[i]<RA[j]){
A[k] = LA[i];
B[k] = LB[i];
i++;
}
else{
A[k] = RA[j];
B[k] = RB[j];
count += n1-i;
j++;
}
k++;
}
while(i<n1){
A[k] = LA[i];
B[k] = LB[i];
i++;
k++;
}
while(j<n2){
A[k] = RA[j];
B[k] = RB[j];
j++;
k++;
}
return count;
}
ll mergesort(ll A[],ll B[],ll left,ll right){
ll total = 0;
if(left<right){
ll mid = (right-left)/2+left;
total += mergesort(A,B,left,mid);
total += mergesort(A,B,mid+1,right);
total += merge(A,B,left,mid,right);
}
return total;
}
ll power(ll x, ll y, ll p)
{
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
res = (res*x) % p;
// y must be even now
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
ll markedarray[2000][2000];
int main(int argc, char const *argv[])
{
ll T = 1;
// scanf("%lld",&T);
for (ll j = 0; j < 2000; j++)
{
for (ll k = 0; k < 2000; k++)
{
markedarray[j][k] = -1;
}
}
for(ll t = 0; t < T; t++)
{
ll h,w ;
scanf("%lld %lld",&h,&w);
ll A[h],B[w];
for(ll n = 0; n < h; n++)
{
scanf("%lld",&A[n]);
}
for (ll n = 0; n < w; n++)
{
scanf("%lld",&B[n]);
}
ll fg = 1;
for (ll n = 0; n < h; n++)
{
// mark first A[n] cells as marked
for (ll g = 0; g < A[n]; g++)
{
markedarray[n][g] = 1;
}
markedarray[n][A[n]] = 0;
}
for (ll n = 0; n < w; n++)
{
for (ll g = 0; g < B[n]; g++)
{
if(markedarray[g][n]!=0)
markedarray[g][n] = 1;
else if(markedarray[g][n]==0)
{
fg = 0;
markedarray[g][n] = 1;
}
}
if(markedarray[B[n]][n]!=1)
markedarray[B[n]][n] = 0;
else
{
fg = 0;
}
}
ll cnt = 0;
for (ll i = 0; i < h; i++)
{
for (ll j = 0; j < w; j++)
{
if(markedarray[i][j]==-1)
{
cnt++;
}
// printf("%lld ",markedarray[i][j]);
}
// printf("\n");
}
ll answer = fg * power(2,cnt,MOD);
printf("%lld\n",answer);
}
return 0;
}
| |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 32c613c357d6b9ca4a04561efb2027eb | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include <stdio.h>
int ar[1000][1000];
int main()
{
int r, c;
r = 0;
while (r < 1000)
{
c = 0;
while (c < 1000)
{
ar[r][c] = 0;
c++;
}
r++;
}
int flag = 1;
scanf("%d %d", &r, &c);
int i = 0;
int rr[r], cc[c];
while (i < r)
{
scanf("%d", &rr[i++]);
}
i = 0;
while (i < c)
{
scanf("%d", &cc[i++]);
}
i = 0;
while (i < r)
{
int j = rr[i] - 1;
while (j >= 0)
{
ar[i][j] = -1;
j--;
}
if (rr[i] != c)
{
ar[i][rr[i]] = 1;
}
i++;
}
i = 0;
while (i < c)
{
int j = cc[i] - 1;
while (j >= 0)
{
if (ar[j][i] == 1)
{
flag = 0;
}
ar[j][i] = -1;
j--;
}
if (cc[i] != r)
{
if (ar[cc[i]][i] == -1)
{
flag = 0;
}
ar[cc[i]][i] = 1;
}
i++;
}
i = 0;
int j = 0;
long long int result = 1;
while (i < r)
{
j = 0;
while (j < c)
{
if (ar[i][j] == 0)
{
result *= 2;
result %= ((long long int)1e9 + 7);
}
j++;
}
i++;
}
if (flag)
printf("%lld", result);
else
printf("0");
return 0;
} | |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | a759b959f9143f0a290d40909c794ab8 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include<stdio.h>
#include<string.h>
char grid[1000][1000];
int main(){
int w, h, i, j, curr;
const long long mod=1000000007;
long long moznosti=1;
memset(grid, -1, sizeof(grid));
scanf("%d %d", &w, &h);
for(i=0;i<w;++i){
scanf("%d", &curr);
for(j=0;j<curr;++j){
grid[i][j]=1;
}
if(curr!=h) grid[i][curr]=0;
}
for(j=0;j<h;++j){
scanf("%d", &curr);
for(i=0;i<curr;++i){
if(grid[i][j]==0){
puts("0");
return 0;
}
grid[i][j]=1;
}
if(curr!=w){
if(grid[curr][j]==1){
puts("0");
return 0;
}
grid[curr][j]=0;
}
}
for(i=0;i<w;++i)
for(j=0;j<h;++j)
if(grid[i][j]==-1)
moznosti=(moznosti*2)%mod;
printf("%I64d\n", moznosti);
return 0;
}
| |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | b87a37dd44b314c7df61c43472afb310 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include<stdio.h>
#define N 1001
#define M 1000000007
int main(){
char grid[N][N];
int i,j;
for(i=0;i<N;i++){
for(j=0;j<N;j++){
grid[i][j]=0;
}
}
int h,w;
scanf("%d%d",&h,&w);
int r[N];
int c[N];
for(i=0;i<h;i++){
scanf("%d",&r[i]);
}
for(i=0;i<w;i++){
scanf("%d",&c[i]);
}
//检查是否出现矛盾
//检查零的个数
//禁止被涂黑的点
for(i=0;i<w;i++){
if(c[i]<h){
grid[c[i]][i]=2;
}
}
for(i=0;i<h;i++){
if(r[i]<w){
grid[i][r[i]]=2;
}
}
int conflict=0;
//要被涂黑的点
for(i=0;i<h;i++){
for(j=0;j<r[i];j++){
if(grid[i][j]==2){
conflict=1;
}else{
grid[i][j]=1;
}
}
}
for(i=0;i<w;i++){
for(j=0;j<c[i];j++){
if(grid[j][i]==2){
conflict=1;
}else{
grid[j][i]=1;
}
}
}
if(conflict){
printf("0\n");
}else{
int zero=0;
for(i=0;i<h;i++){
for(j=0;j<w;j++){
if(grid[i][j]==0){
zero++;
}
}
}
//printf("zero = %d\n",zero);
int answer=1;
while(zero--){
//2*(10^9+7)还在int范围内
//int最大21*10^8
answer=(answer*2)%M;
}
printf("%d\n",answer);
}
return 0;
}
| |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | c7802982348063c1cc8e7257820f8eec | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include<stdio.h>
int main(){
long long int h,w,sum=0,count=0,product=1,j,i,arr[10001],row[10000],col[10000],p=1000000007;
scanf("%lld%lld",&h,&w);
for(i=0;i<h;i++){
scanf("%lld",&row[i]);}
for(i=0;i<w;i++){
scanf("%lld",&col[i]);}
for(i=0;i<h;i++){
if(row[i]==0){
if(col[0]>i)
count++;}
if(row[i]!=0){
for(j=0;j<row[i];j++)
{ if(col[j]==i)
count++;}
if(row[i]!=w){
if(col[row[i]]>i)
count++;}
}
}
if(count>0)
printf("0\n");
else{
for(i=1;i<h;i++){
for(j=row[i]+1;j<w;j++){
arr[col[j]]++;}
for(j=0;j<i;j++){
sum=sum+arr[j];}
for(j=0;j<=10000;j++)
{
arr[j]=0;
}
}
// pow(2,sum);
if(sum==0)
product=1;
else{
for(j=1;j<=sum;j++)
{
product =(product*2)%p;
}
}
printf("%lld\n",product);
}
return 0;
}
| |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 5da41514fd94ad556dd1c0a2f4171271 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define MOD 1000000007
int main()
{
int h,w;
scanf("%d %d",&h,&w);
int mat[h][w];
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
mat[i][j] = -1;
}
int r[h];
int c[w];
for(int i=0;i<h;i++)
{
scanf("%d",(r+i));
}
for(int i=0;i<w;i++)
{
scanf("%d",(c+i));
}
for(int i=0;i<h;i++)
{
int k = r[i];
for(int j=0;j<k;j++)
mat[i][j]=1;
if(k<w)
mat[i][k]=0;
}
int counter=0;
for(int i=0;i<w;i++)
{
int k = c[i];
for(int j=0;j<k;j++)
{
if(mat[j][i]==0)
{
counter = 1;
break;
}
else
mat[j][i]=1;
}
if(k<h)
{
if(mat[k][i]==1)
{
counter = 1;
break;
}
else
mat[k][i]=0;
}
}
if(counter)
printf("0\n");
else
{
int num = 0;
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
if(mat[i][j]==-1)
num++;
}
}
int result = 1;
for(long long i=0;i<num;i++)
{
result = (result*2)%MOD;
}
printf("%d\n",result);
}
} | |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 178685dd315460430ebcb8976d999176 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include <stdio.h>
int main()
{
int i, j, k, l, h, w, num;
long long int possibility = 1;
scanf("%d %d", &h, &w);
int grid[h][w];
for (i=0; i<h; i++) {
for (j=0; j<w; j++) {
grid[i][j] = 2;
}
}
for (i=0; i<h; i++) {
scanf("%d", &num);
for (j=0; j<=num && j<w; j++) {
if (j==num) {
if (grid[i][j]==1) {
printf("0");
return 0;
}
grid[i][j] = 0;
}
else {
if (grid[i][j]==0) {
printf("0");
return 0;
}
grid[i][j] = 1;
}
}
}
for (j=0; j<w; j++) {
scanf("%d", &num);
for (i=0; i<=num && i<h; i++) {
if (i==num) {
if (grid[i][j]==1) {
printf("0");
return 0;
}
grid[i][j] = 0;
}
else {
if (grid[i][j]==0) {
printf("0");
return 0;
}
grid[i][j] = 1;
}
}
}
for (i=0; i<h; i++) {
for (j=0; j<w; j++) {
if (grid[i][j]==2) {
possibility *= 2;
if (possibility>=1000000007) {
possibility -= 1000000007;
}
}
}
}
printf("%I64d", possibility);
return 0;
}
| |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 7d294521bb42e1aa54904260a4841919 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include<stdio.h>
#define MOD 1000000007
int grid[1003][1003], w, h, r[1003], c[1003];
int sol(){
int i, j;
for(i = 0;i < h;i++)for(j = 0;j < w;j++)grid[i][j] = -1;
for(i = 0;i < h;i++){
for(j = 0;j < r[i];j++)grid[i][j] = 1;
if(j < w)grid[i][j] = 0;
}
for(j = 0;j < w;j++){
for(i = 0;i < c[j];i++){
if(grid[i][j] == 0)return 0;
grid[i][j] = 1;
}
if(i < h){
if(grid[i][j] == 1)return 0;
grid[i][j] = 0;
}
}
int ans = 1;
for(i = 0;i < h;i++)for(j = 0;j < w;j++)if(grid[i][j] == -1){
ans <<= 1;
if(ans >= MOD)ans -= MOD;
}
return ans;
}
int main(){
scanf("%d %d", &h, &w);
int i;
for(i = 0;i < h;i++)scanf("%d", r + i);
for(i = 0;i < w;i++)scanf("%d", c + i);
printf("%d\n", sol());
return 0;
}
| |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | b8d27a232ba5e646a70c43c3633c618d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include <stdio.h>
int main() {
int h,w,i,m,p,n=0,q=1000000007;
long long s=1;
scanf("%d %d",&h,&w);
int k[h][w],r[h],c[w];
for (i=0;i<h;i++) {
scanf("%d",&r[i]);
}
for (i=0;i<w;i++) {
scanf("%d",&c[i]);
}
for (m=0;m<h;m++) {
for (i=0;i<w;i++) {
k[m][i]=2;
}
}
for (m=0;m<h;m++) {
p=r[m];
for (i=0;i<p;i++) {
k[m][i]=1;
}
if (p<w) {
k[m][p]=0;
}
}
for (m=0;m<w;m++) {
p=c[m];
for (i=0;i<p;i++) {
if (k[i][m]==0) {
printf("0");
return 0;
} else {
k[i][m]=1;
}
}
if (p<h) {
if (k[p][m]==1) {
printf("0");
return 0;
} else {
k[p][m]=0;
}
}
}
for (m=0;m<h;m++) {
for (i=0;i<w;i++) {
if (k[m][i]==2) {
n++;
}
}
}
if (n==0) {
s=1;
} else {
for (i=1;i<=n;i++) {
s*=2;
if (s>=q) {
s%=q;
}
}
}
printf("%I64d",s);
return 0;
}
| |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 3ce1d9c186f2a3ac9295669b7abdd28f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include <stdio.h>
int main ()
{
long long int h, w, i, k, j = 0, c, num =1, f = 0;
char d = 'c';
scanf("%lld%lld", &h, &w);
long long int a[1000][1000] = {0};
while(d != '\n')
{
scanf("%lld",&c);
for(k = 0; k < c; k++)
{
a[j][k] = 1;
}
a[j][c] = -1;
j++;
scanf("%c",&d);
}
j = 0;
if(f == 0)
{
do
{
scanf("%lld",&c);
for(k = 0; k < c; k++)
{
if(a[k][j] != -1)
{
a[k][j] = 1;
}
else
{
f=1;
break;
}
}
if(a[c][j] == 1)
{
f = 1;break;
}
else
{
a[c][j] = -1;
}
j++;
scanf("%c",&d);
}while(d != '\n');
for(i = 0; i < h; i++)
{
for(j = 0; j < w; j++)
{
if(a[i][j] == 0)
{
num = (num * 2) % 1000000007;
}
}
}
}
if(f == 1)
{
printf("%d\n", 0);
}
else
{
printf("%lld\n", num);
}
return 0;
} | |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | a4c6721ad322fb93143def1f6e8fa5df | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | //
// Created by Pulak on 29-09-2019.
//
// r verified is 0 + 1 = 1
//danger zone of r 0 + 4 = 4
// c verified is 0 + 1 = 1 or 1 + 1 = 2
//danger zone of c 0 + 4 =4, 4 + 4 = 8,
#include <stdio.h>
#include <string.h>
void print_matrix(int a[4][4], int h, int w) {
printf("\n");
for (int k = 0; k < h; ++k) {
for (int i = 0; i < w; ++i) {
printf("%d ", a[k][i]);
}
printf("\n");
}
}
int main() {
int h, w;
scanf("%d %d", &h, &w);
int matrix[h][w];
// int** m = matrix;
memset(matrix, 0, sizeof(matrix));
// print_matrix(matrix, h, w);
for (int i = 0; i < h; ++i) {
int r = 0;
scanf("%d", &r);
for (int j = 0; j < r; ++j) {
matrix[i][j] += 1;
}
if (r < w)
matrix[i][r] += 4;
}
// print_matrix(matrix, h, w);
for (int i = 0; i < w; ++i) {
int c = 0;
scanf("%d", &c);
for (int j = 0; j < c; ++j) {
matrix[j][i] += 1;
}
if (c < h)
matrix[c][i] += 4;
}
int n = 0;
int ans = 1;
int l = 1000000007;
int flag = 0;
// print_matrix(matrix, h, w);
for (int k = 0; k < h; ++k) {
for (int i = 0; i < w; ++i) {
if (!matrix[k][i]) {
n++;
ans = ans * 2 % l;
}
if (matrix[k][i] == 5) {
// printf("here");
flag = -1;
break;
}
}
}
// printf("\nn = %d \n", n);
// int x = power(2, n, 1000000007);
if (flag != -1)
printf("%d", ans);
else
printf("%d", 0);
return 0;
}
| |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | fb9d94bd619a96c5f86bf1d3b7aadb6d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include <stdio.h>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>
long long int power(long long x, long long int y, long long int p)
{
long long int res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0)
{
// If y is odd, multiply x with result
if (y & 1)
res = (res*x) % p;
// y must be even now
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
int main()
{
int T,i,j,row,col,*row_data,*col_data,**mat,imp;
long long int cnt;
//scanf("%d",&T);
cnt =0;
imp= false;
scanf("%d",&row);
scanf("%d",&col);
row_data=(int*)malloc(row*sizeof(int));
col_data=(int*)malloc(col*sizeof(int));
for(i=0;i<row;i++) scanf("%d",&row_data[i]);
for(i=0;i<col;i++) scanf("%d",&col_data[i]);
mat=(int**)malloc(row*sizeof(int*));
for(i=0;i<row;i++)
mat[i]=(int*)malloc(col*sizeof(int));
for(i=0;i<row;i++)
{
for(j=0;j<col;j++) mat[i][j]=-1;
}//initialize matrix
for(i=0;i<row;i++)
{
if(row_data[i]!=0)
{
for(j=0;j<row_data[i];j++)
mat[i][j]=1;
}
if(i<row && row_data[i]<col)
mat[i][row_data[i]]=0;
}
//for(int i = 0; i < row; i++) {for(int j = 0; j < col; j++) printf("%d ", mat[i][j]); printf("\n");}
for(i=0;i<col;i++)
{
if(col_data[i]!=0)
{
for(j=0;j<col_data[i];j++)
{
if(mat[j][i]!=0)
{
mat[j][i]=1;
}
else
{ //printf("Reached\n");
imp=true;
i=col+1;
break;
}
}
}
if(col_data[i]<row && i<col)
{
if(mat[col_data[i]][i]!=1)
{
mat[col_data[i]][i]=0;
}
else
{
imp=true;
i=col+1;
break;
}
}
}
//for(int i = 0; i < row; i++) {for(int j = 0; j < col; j++) printf("%d ", mat[i][j]); printf("\n");}
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
if(mat[i][j]==-1)
cnt++;
}
printf("%I64d\n", imp== true ? 0LL : power(2,cnt,1000000007));
return 0;
}
| |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 1c12173b9a414713bd596a51b19c0f8b | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include <stdio.h>
main()
{
int h, w, i, j, cn=0;
scanf("%d%d",&h,&w);
int r[h+1], c[w+1];
for(i=1;i<=h;i++)
{scanf("%d",&r[i]); r[i]++;}
for(i=1;i<=w;i++)
{scanf("%d",&c[i]); c[i]++;}
for(i=1;i<=w;i++)
{
for(j=1;j<=h;j++)
{
if(c[i]==j && r[j]>i){printf("0"); return 0;}
else if(r[j]==i && c[i]>j){printf("0"); return 0;}
if(c[i]<j && r[j]<i)
cn++;
}
}
long long int total=1;
for(i=1;i<=cn;i++)
{
total*=2;
if(total>1000000007)
total%=1000000007;
}
printf("%lld",total);
}
| |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 68b99158f65faa8f47035e2f2cb25ccb | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | /*
* author : anaksoleh
* 12 okt 2019
* link problem : https://codeforces.com/problemset/problem/1228/B
*/
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
typedef long long ll;
#define max(a,b) (a > b ? a : b)
#define min(a,b) (a < b ? a : b)
#define getI(a) scanf("%d",&a)
const int N = 1e9 + 7;
int arr[1010][1010];
int main()
{
int h,w;
scanf("%d %d",&h,&w);
int row,col;
int val;
int unreserved = 0;
for(row = 1 ; row <= h ; row++){
getI(val);
if(val != 0){
for(col = 1 ; col <= val ; col++){
arr[row][col] = 1;
}
if(val < w){arr[row][col] = -1;}
}else{arr[row][1] = -1;}
}
bool ok = true;
bool possible = true;
for(col = 1 ; col <= w ; col++){
getI(val);
if(val != 0){
for(row = 1 ; row <= val ; row++){
if(arr[row][col] != -1){arr[row][col] = 1;}
else{
printf("%d\n",0);
return 0;
}
}
if(arr[row][col] == 1){possible = false;break;}
if(ok && (val < h)){arr[row][col] = -1;}
}else{
if(arr[1][col] == 1){
possible = false;
break;
}
arr[1][col] = -1;
}
}
if(!possible){
printf("%d\n",0);
return 0;
}
for(row = 1 ; row <= h ; row++){
for(col = 1 ; col <= w ; col++){
if(arr[row][col] == 0){
++unreserved;
}
}
}
int i;
int ans = 1;
for(i = 1 ; i <= unreserved ; i++){
ans *= 2;
ans %= N;
}
printf("%d\n",ans);
return 0;
}
| |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 6aa8c9ebd5131d24a7d163fb8051fda0 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include<stdio.h>
int main() {
int i, j, count = 0;
int m, n;
scanf("%d %d", &m, &n);
int r[m], c[n], a[m + 1][n + 1];
for(i = 0; i <= m; i++){
for(j = 0; j <= n; j++)
a[i][j] = 0;
}
for(i = 0; i < m; i++){
scanf("%d", &r[i]);
a[i][r[i]] = 1;
}
for(i = 0; i < n; i++){
scanf("%d", &c[i]);
if(a[c[i]][i] != 1)
a[c[i]][i] = 2;
}
for(i = 0; i < m; i++){
// printf("i: %d\n", i);
j = 0;
while(a[i][j] != 1){
if(a[i][j] == 2)
break;
j++;
}
// printf("i: %d\n", j);
if(a[i][j] != 1
|| (j != n && c[j] > i)
)
break;
// printf("j: %d", j);
for(j++; j < n; j++){
if(c[j] < i)
count++;
}
}
// printf("\t%d\n", count);
if(i != m)
printf("0");
else{
int res = 1;
for(i = 1; i <= count; i++){
res = (res * 2) % 1000000007;
}
printf("%d", res);
}
return 0;
} | |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 489f77b5a5171a9a814b270860029fdf | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include<stdio.h>
#include<math.h>
long long int N=1e9+7;
int main()
{ long long int h,w,i,j,k=0,l,m=1;
scanf("%lld %lld",&h,&w);
long long int row[h+1];
long long int col[w+1];
for(i=1;i<=h;i++)
{scanf("%lld",&row[i]);}
for(i=1;i<=w;i++)
{scanf("%lld",&col[i]);}
col[0]=0;
row[0]=0;
for(i=1;i<=h;i++)
{ for(j=1;j<=w;j++)
{ if(j<=(row[i]+1)||i<=(col[j]+1))
k=k+1;
if((j<=row[i]&&(j<=row[i-1]||j==1)&&col[j]==(i-1))|| (i<=col[j]&&(i<=col[j-1]||i==1)&&row[i]==(j-1)) || ((j==row[i]+1)&&col[j]==i)||((i==col[j]+1)&&row[i]==j))
{printf("0");return 0;}}
}
l= h*w-k;
for(j=0;j<l;j++)
{m=(m*2)%N;}
printf("%lld",m);
return 0;
}
| |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 78011d9c66bf017490986249e7688668 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include <stdio.h>
int main()
{
int h,w;
scanf("%d%d",&h,&w);
int arh[h];
for(int i=0;i<h;i++)
scanf("%d",&arh[i]);
int arw[w];
for(int i=0;i<w;i++)
scanf("%d",&arw[i]);
int ar1[h][w];
int ar2[h][w];
int temp;
for(int i=0;i<h;i++)
{
int flag=0;
if(arh[i]==w)
{
temp=w;
flag=1;
}
else
temp=arh[i]+1;
for(int j=0;j<w;j++)
{
if(j+1<temp)
{
ar1[i][j]=1;
}
else if(j+1==temp)
{
if(temp==w){
if(flag==1)
{
ar1[i][j]=1;
}
else
ar1[i][j]=0;}
else
{
ar1[i][j]=0;
}
}
else
ar1[i][j]=2;
}
}
for(int i=0;i<w;i++)
{
int flag=0;
if(arw[i]==h)
{
temp=h;
flag=1;
}
else
temp=arw[i]+1;
for(int j=0;j<h;j++)
{
if(j+1<temp)
{
ar2[j][i]=1;
}
else if(j+1==temp)
{
if(temp==h){
if(flag==1)
{
ar2[j][i]=1;
}
else
ar2[j][i]=0;}
else
{
ar2[j][i]=0;
}
}
else
ar2[j][i]=2;
}
}
int flag1=1;
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
int a=ar1[i][j];
int b=ar2[i][j];
if(a!=2 && b!=2 &&a!=b)
flag1=0;
else
{
if(a!=2 &&b==2)
ar1[i][j]=a;
if(a==2 &&b!=2)
ar1[i][j]=b;
}
}
}
if(flag1==0)
{
printf("0");
}
else
{
unsigned long long l1=1000000007;
unsigned long long l=1;
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
if(ar1[i][j]==2)
l=l*2;
l=l%l1;
}
}
l=l%l1;
printf("%lu",l);
}
} | |
Suppose there is a $$$h \times w$$$ grid consisting of empty or full cells. Let's make some definitions: $$$r_{i}$$$ is the number of consecutive full cells connected to the left side in the $$$i$$$-th row ($$$1 \le i \le h$$$). In particular, $$$r_i=0$$$ if the leftmost cell of the $$$i$$$-th row is empty. $$$c_{j}$$$ is the number of consecutive full cells connected to the top end in the $$$j$$$-th column ($$$1 \le j \le w$$$). In particular, $$$c_j=0$$$ if the topmost cell of the $$$j$$$-th column is empty. In other words, the $$$i$$$-th row starts exactly with $$$r_i$$$ full cells. Similarly, the $$$j$$$-th column starts exactly with $$$c_j$$$ full cells. These are the $$$r$$$ and $$$c$$$ values of some $$$3 \times 4$$$ grid. Black cells are full and white cells are empty. You have values of $$$r$$$ and $$$c$$$. Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of $$$r$$$ and $$$c$$$. Since the answer can be very large, find the answer modulo $$$1000000007\,(10^{9} + 7)$$$. In other words, find the remainder after division of the answer by $$$1000000007\,(10^{9} + 7)$$$. | Print the answer modulo $$$1000000007\,(10^{9} + 7)$$$. | C | 907f7db88fb16178d6be57bea12f90a2 | 8725e881d38fc1a8a3fb3bd7f29dd425 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"math"
] | 1569762300 | ["3 4\n0 3 1\n0 2 3 0", "1 1\n0\n1", "19 16\n16 16 16 16 15 15 0 5 0 4 9 9 1 4 4 0 8 16 12\n6 12 19 15 8 6 19 19 14 6 9 16 10 11 15 4"] | NoteIn the first example, this is the other possible case. In the second example, it's impossible to make a grid to satisfy such $$$r$$$, $$$c$$$ values.In the third example, make sure to print answer modulo $$$(10^9 + 7)$$$. | PASSED | 1,400 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h, w \le 10^{3}$$$) — the height and width of the grid. The second line contains $$$h$$$ integers $$$r_{1}, r_{2}, \ldots, r_{h}$$$ ($$$0 \le r_{i} \le w$$$) — the values of $$$r$$$. The third line contains $$$w$$$ integers $$$c_{1}, c_{2}, \ldots, c_{w}$$$ ($$$0 \le c_{j} \le h$$$) — the values of $$$c$$$. | ["2", "0", "797922655"] | #include <stdio.h>
#include <string.h>
const int P = 1e9 + 7;
int r[1003], c[1003], a[1003][1003];
int main()
{
int n, m, i, j;
memset(a, -1, sizeof(a));
scanf("%d%d", &n, &m);
for (i = 0; i < n; ++i) {
scanf("%d", &r[i]);
for (j = 0; j < r[i]; ++j) a[i][j] = 1;
a[i][r[i]] = 0;
}
for (i = 0; i < m; ++i) {
scanf("%d", &c[i]);
for (j = 0; j < c[i]; ++j) {
if (!a[j][i]) return puts("0"), 0;
a[j][i] = 1;
}
if (a[c[i]][i] == 1) return puts("0"), 0;
a[c[i]][i] = 0;
}
long long ans = 1;
for (i = 0; i < n; ++i)
for (j = 0; j < m; ++j)
if (a[i][j] == -1) ans = ans * 2 % P;
printf("%d", ans);
return 0;
} | |
In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an integer that increases when you use this skill. Different character classes are characterized by different skills. Unfortunately, the skills that are uncommon for the given character's class are quite difficult to obtain. To avoid this limitation, there is the so-called transmigration. Transmigration is reincarnation of the character in a new creature. His soul shifts to a new body and retains part of his experience from the previous life. As a result of transmigration the new character gets all the skills of the old character and the skill levels are reduced according to the k coefficient (if the skill level was equal to x, then after transmigration it becomes equal to [kx], where [y] is the integral part of y). If some skill's levels are strictly less than 100, these skills are forgotten (the character does not have them any more). After that the new character also gains the skills that are specific for his class, but are new to him. The levels of those additional skills are set to 0. Thus, one can create a character with skills specific for completely different character classes via transmigrations. For example, creating a mage archer or a thief warrior is possible. You are suggested to solve the following problem: what skills will the character have after transmigration and what will the levels of those skills be? | Print on the first line number z — the number of skills the character will have after the transmigration. Then print z lines, on each of which print a skill's name and level, separated by a single space. The skills should be given in the lexicographical order. | C | 7da1a5c4c76540e1c7dc06e4c908c8b4 | a7a6ce19278287e0e19ea966cc15d08d | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1313247600 | ["5 4 0.75\naxe 350\nimpaler 300\nionize 80\nmegafire 120\nmagicboost 220\nheal\nmegafire\nshield\nmagicboost"] | null | PASSED | 1,700 | standard input | 2 seconds | The first line contains three numbers n, m and k — the number of skills the current character has, the number of skills specific for the class into which the character is going to transmigrate and the reducing coefficient respectively; n and m are integers, and k is a real number with exactly two digits after decimal point (1 ≤ n, m ≤ 20, 0.01 ≤ k ≤ 0.99). Then follow n lines, each of which describes a character's skill in the form "name exp" — the skill's name and the character's skill level: name is a string and exp is an integer in range from 0 to 9999, inclusive. Then follow m lines each of which contains names of skills specific for the class, into which the character transmigrates. All names consist of lowercase Latin letters and their lengths can range from 1 to 20 characters, inclusive. All character's skills have distinct names. Besides the skills specific for the class into which the player transmigrates also have distinct names. | ["6\naxe 262\nheal 0\nimpaler 225\nmagicboost 165\nmegafire 0\nshield 0"] | #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 100
int main()
{
int m,n,i,j,total,mult;
char skill[MAX<<2][MAX],decimal[MAX],temp[MAX];
int level[MAX],crap;
scanf("%d%d %s",&n,&m,decimal);
mult=atoi(decimal+2);
for(i=0;i<n;i++){
scanf(" %s%d",skill[i],&level[i]);
level[i]*=mult;
level[i]/=100;
if(level[i]<100){
// printf("rejecting %s\n",skill[i]);
n--;
i--;
}
}
// puts("");
// printf("total old scanned is %d\n",n);
total=m+n;
for(i=n;i<total;i++){
scanf("%s",skill[i]);
level[i]=0;
}
for(i=0;i<total;i++)
for(j=0;j<i;j++)
if(strcmp(skill[i],skill[j])<0){
strcpy(temp,skill[i]);
strcpy(skill[i],skill[j]);
strcpy(skill[j],temp);
crap=level[i];
level[i]=level[j];
level[j]=crap;
}
for(i=1;i<total;i++)
if(strcmp(skill[i],skill[i-1])==0){
level[i-1]+=level[i];
for(j=i;j<total;j++){
strcpy(skill[j],skill[j+1]);
level[j]=level[j+1];
}
total--;
}
printf("%d\n",total);
for(i=0;i<total;i++)
printf("%s %d\n",skill[i],level[i]);
return 0;
}
| |
In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an integer that increases when you use this skill. Different character classes are characterized by different skills. Unfortunately, the skills that are uncommon for the given character's class are quite difficult to obtain. To avoid this limitation, there is the so-called transmigration. Transmigration is reincarnation of the character in a new creature. His soul shifts to a new body and retains part of his experience from the previous life. As a result of transmigration the new character gets all the skills of the old character and the skill levels are reduced according to the k coefficient (if the skill level was equal to x, then after transmigration it becomes equal to [kx], where [y] is the integral part of y). If some skill's levels are strictly less than 100, these skills are forgotten (the character does not have them any more). After that the new character also gains the skills that are specific for his class, but are new to him. The levels of those additional skills are set to 0. Thus, one can create a character with skills specific for completely different character classes via transmigrations. For example, creating a mage archer or a thief warrior is possible. You are suggested to solve the following problem: what skills will the character have after transmigration and what will the levels of those skills be? | Print on the first line number z — the number of skills the character will have after the transmigration. Then print z lines, on each of which print a skill's name and level, separated by a single space. The skills should be given in the lexicographical order. | C | 7da1a5c4c76540e1c7dc06e4c908c8b4 | 20554d2818a85ffcca429b59905848a5 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1313247600 | ["5 4 0.75\naxe 350\nimpaler 300\nionize 80\nmegafire 120\nmagicboost 220\nheal\nmegafire\nshield\nmagicboost"] | null | PASSED | 1,700 | standard input | 2 seconds | The first line contains three numbers n, m and k — the number of skills the current character has, the number of skills specific for the class into which the character is going to transmigrate and the reducing coefficient respectively; n and m are integers, and k is a real number with exactly two digits after decimal point (1 ≤ n, m ≤ 20, 0.01 ≤ k ≤ 0.99). Then follow n lines, each of which describes a character's skill in the form "name exp" — the skill's name and the character's skill level: name is a string and exp is an integer in range from 0 to 9999, inclusive. Then follow m lines each of which contains names of skills specific for the class, into which the character transmigrates. All names consist of lowercase Latin letters and their lengths can range from 1 to 20 characters, inclusive. All character's skills have distinct names. Besides the skills specific for the class into which the player transmigrates also have distinct names. | ["6\naxe 262\nheal 0\nimpaler 225\nmagicboost 165\nmegafire 0\nshield 0"] | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct {
char s[21];
int num;
} skill;
int cmp(const void *a, const void *b)
{
return strcmp(((skill *)a)->s, ((skill *)b)->s);
}
int main()
{
int n, m, k, z = 0, i, j;
char s1[20][21], s2[20][21];
int a[20];
skill c[40];
scanf("%d %d %*d.%d", &n, &m, &k);
for (i = 0; i < n + m; i++) c[i].num = 0;
for (i = 0; i < n; i++) scanf("%s %d", s1[i], &a[i]);
for (i = 0; i < m; i++) scanf("%s", s2[i]);
for (i = 0; i < n; i++) {
int x = a[i] * k / 100;
if (x >= 100) {
strcpy(c[z].s, s1[i]);
c[z++].num = x;
}
}
for (i = 0; i < m; i++) {
for (j = 0; j < z; j++) {
if (strcmp(s2[i], c[j].s) == 0) break;
}
if (j == z) strcpy(c[z++].s, s2[i]);
}
qsort(c, z, sizeof(skill), cmp);
printf("%d\n", z);
for (i = 0; i < z; i++) printf("%s %d\n", c[i].s, c[i].num);
return 0;
}
| |
In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an integer that increases when you use this skill. Different character classes are characterized by different skills. Unfortunately, the skills that are uncommon for the given character's class are quite difficult to obtain. To avoid this limitation, there is the so-called transmigration. Transmigration is reincarnation of the character in a new creature. His soul shifts to a new body and retains part of his experience from the previous life. As a result of transmigration the new character gets all the skills of the old character and the skill levels are reduced according to the k coefficient (if the skill level was equal to x, then after transmigration it becomes equal to [kx], where [y] is the integral part of y). If some skill's levels are strictly less than 100, these skills are forgotten (the character does not have them any more). After that the new character also gains the skills that are specific for his class, but are new to him. The levels of those additional skills are set to 0. Thus, one can create a character with skills specific for completely different character classes via transmigrations. For example, creating a mage archer or a thief warrior is possible. You are suggested to solve the following problem: what skills will the character have after transmigration and what will the levels of those skills be? | Print on the first line number z — the number of skills the character will have after the transmigration. Then print z lines, on each of which print a skill's name and level, separated by a single space. The skills should be given in the lexicographical order. | C | 7da1a5c4c76540e1c7dc06e4c908c8b4 | fd56e0503a3cc14b148ae1142d5822a1 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1313247600 | ["5 4 0.75\naxe 350\nimpaler 300\nionize 80\nmegafire 120\nmagicboost 220\nheal\nmegafire\nshield\nmagicboost"] | null | PASSED | 1,700 | standard input | 2 seconds | The first line contains three numbers n, m and k — the number of skills the current character has, the number of skills specific for the class into which the character is going to transmigrate and the reducing coefficient respectively; n and m are integers, and k is a real number with exactly two digits after decimal point (1 ≤ n, m ≤ 20, 0.01 ≤ k ≤ 0.99). Then follow n lines, each of which describes a character's skill in the form "name exp" — the skill's name and the character's skill level: name is a string and exp is an integer in range from 0 to 9999, inclusive. Then follow m lines each of which contains names of skills specific for the class, into which the character transmigrates. All names consist of lowercase Latin letters and their lengths can range from 1 to 20 characters, inclusive. All character's skills have distinct names. Besides the skills specific for the class into which the player transmigrates also have distinct names. | ["6\naxe 262\nheal 0\nimpaler 225\nmagicboost 165\nmegafire 0\nshield 0"] | #include<stdio.h>
#include<string.h>
int main(){
char res[41][30],tmp[30],k[10];
int value[41],v,i,j,n,m,s,count,check,K;
scanf("%d%d%s",&n,&m,k);
K=(k[2]-'0')*10+k[3]-'0';
for(i=0,j=0;i<n;i++){
scanf("%s%d",tmp,&v);
s=v*K/100;
if(s>=100){
strcpy(res[j],tmp);
value[j]=s;
j++;
}
}
n=j;
count=j;
for(i=0;i<m;i++){
scanf("%s",tmp);
check=1;
for(j=0;j<n;j++)
if(!strcmp(tmp,res[j])){
check=0;
break;
}
if(check){
strcpy(res[count],tmp);
value[count]=0;
count++;
}
}
printf("%d\n",count);
for(i=0;i<count;i++){
for(j=i+1;j<count;j++){
if(strcmp(res[i],res[j])>0){
strcpy(tmp,res[i]);
strcpy(res[i],res[j]);
strcpy(res[j],tmp);
v=value[i];
value[i]=value[j];
value[j]=v;
}
}
printf("%s %d\n",res[i],value[i]);
}
return 0;
}
| |
In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an integer that increases when you use this skill. Different character classes are characterized by different skills. Unfortunately, the skills that are uncommon for the given character's class are quite difficult to obtain. To avoid this limitation, there is the so-called transmigration. Transmigration is reincarnation of the character in a new creature. His soul shifts to a new body and retains part of his experience from the previous life. As a result of transmigration the new character gets all the skills of the old character and the skill levels are reduced according to the k coefficient (if the skill level was equal to x, then after transmigration it becomes equal to [kx], where [y] is the integral part of y). If some skill's levels are strictly less than 100, these skills are forgotten (the character does not have them any more). After that the new character also gains the skills that are specific for his class, but are new to him. The levels of those additional skills are set to 0. Thus, one can create a character with skills specific for completely different character classes via transmigrations. For example, creating a mage archer or a thief warrior is possible. You are suggested to solve the following problem: what skills will the character have after transmigration and what will the levels of those skills be? | Print on the first line number z — the number of skills the character will have after the transmigration. Then print z lines, on each of which print a skill's name and level, separated by a single space. The skills should be given in the lexicographical order. | C | 7da1a5c4c76540e1c7dc06e4c908c8b4 | 5c18818598956996fe0e4c5fc3577d6b | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1313247600 | ["5 4 0.75\naxe 350\nimpaler 300\nionize 80\nmegafire 120\nmagicboost 220\nheal\nmegafire\nshield\nmagicboost"] | null | PASSED | 1,700 | standard input | 2 seconds | The first line contains three numbers n, m and k — the number of skills the current character has, the number of skills specific for the class into which the character is going to transmigrate and the reducing coefficient respectively; n and m are integers, and k is a real number with exactly two digits after decimal point (1 ≤ n, m ≤ 20, 0.01 ≤ k ≤ 0.99). Then follow n lines, each of which describes a character's skill in the form "name exp" — the skill's name and the character's skill level: name is a string and exp is an integer in range from 0 to 9999, inclusive. Then follow m lines each of which contains names of skills specific for the class, into which the character transmigrates. All names consist of lowercase Latin letters and their lengths can range from 1 to 20 characters, inclusive. All character's skills have distinct names. Besides the skills specific for the class into which the player transmigrates also have distinct names. | ["6\naxe 262\nheal 0\nimpaler 225\nmagicboost 165\nmegafire 0\nshield 0"] | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int n, m, val[41];
char str[41][22];
void sort(void){
int i, j, q;
char s[22];
for (i = 1; i < n + m; i++){
for (j = n + m - 1; j >= i; j--){
if (strcmp(str[j], str[j - 1]) != 1){
strcpy(s, str[j]);
strcpy(str[j], str[j - 1]);
strcpy(str[j - 1], s);
q = val[j];
val[j] = val[j - 1];
val[j - 1] = q;
}
}
}
}
int main(void)
{
int i, j, z = 0, k = 0;
char ch;
scanf("%d%d", &n, &m);
do{
scanf("%c", &ch);
} while (ch != '.');
do{
scanf("%c", &ch);
k = k * 10 + ch - '0';
} while (ch != '\n');
k = k - ch + '0';
k /= 10;
for (i = 0; i < n; i++){
j = 0;
do{
scanf("%c", &ch);
str[i][j] = ch;
j++;
} while (ch != ' ');
str[i][j - 1] = '\n';
scanf("%d\n", &val[i]);
}
for (i = 0; i < m; i++){
j = 0;
do{
scanf("%c", &ch);
str[i + n][j] = ch;
j++;
} while (ch != '\n');
val[i + n] = -1;
}
for (i = 0; i <= n + m; i++)
{
if (val[i] >= 0){
val[i] = val[i] * k;
val[i] /= 100;
if (val[i] < 100){
val[i] = -100;
}
}else{
val[i] = 0;
}
}
sort();
for( i = 1; i < n + m; i++){
if (strcmp(str[i - 1], str[i]) == 0){
if (val[i] > val[i - 1]){
val[i - 1] = -100;
}else{
val[i] = -100;
}
}
}
for( i = 0; i < n + m; i++){
if (val[i] >= 0){
z++;
}
}
printf("%d\n", z);
for( i = 0; i < n + m; i++){
if (val[i] >= 0){
j = 0;
do{
printf("%c", str[i][j]);
j++;
} while (str[i][j] != '\n');
printf(" %d\n", val[i]);
}
}
return 0;
}
| |
In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an integer that increases when you use this skill. Different character classes are characterized by different skills. Unfortunately, the skills that are uncommon for the given character's class are quite difficult to obtain. To avoid this limitation, there is the so-called transmigration. Transmigration is reincarnation of the character in a new creature. His soul shifts to a new body and retains part of his experience from the previous life. As a result of transmigration the new character gets all the skills of the old character and the skill levels are reduced according to the k coefficient (if the skill level was equal to x, then after transmigration it becomes equal to [kx], where [y] is the integral part of y). If some skill's levels are strictly less than 100, these skills are forgotten (the character does not have them any more). After that the new character also gains the skills that are specific for his class, but are new to him. The levels of those additional skills are set to 0. Thus, one can create a character with skills specific for completely different character classes via transmigrations. For example, creating a mage archer or a thief warrior is possible. You are suggested to solve the following problem: what skills will the character have after transmigration and what will the levels of those skills be? | Print on the first line number z — the number of skills the character will have after the transmigration. Then print z lines, on each of which print a skill's name and level, separated by a single space. The skills should be given in the lexicographical order. | C | 7da1a5c4c76540e1c7dc06e4c908c8b4 | b5cd22c99afa4930cf8e779335d5fbe8 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1313247600 | ["5 4 0.75\naxe 350\nimpaler 300\nionize 80\nmegafire 120\nmagicboost 220\nheal\nmegafire\nshield\nmagicboost"] | null | PASSED | 1,700 | standard input | 2 seconds | The first line contains three numbers n, m and k — the number of skills the current character has, the number of skills specific for the class into which the character is going to transmigrate and the reducing coefficient respectively; n and m are integers, and k is a real number with exactly two digits after decimal point (1 ≤ n, m ≤ 20, 0.01 ≤ k ≤ 0.99). Then follow n lines, each of which describes a character's skill in the form "name exp" — the skill's name and the character's skill level: name is a string and exp is an integer in range from 0 to 9999, inclusive. Then follow m lines each of which contains names of skills specific for the class, into which the character transmigrates. All names consist of lowercase Latin letters and their lengths can range from 1 to 20 characters, inclusive. All character's skills have distinct names. Besides the skills specific for the class into which the player transmigrates also have distinct names. | ["6\naxe 262\nheal 0\nimpaler 225\nmagicboost 165\nmegafire 0\nshield 0"] | #include<stdio.h>
#include<string.h>
#include<Stdlib.h>
int n,m,skill_level[100],var_count=0;
double k;
char variables[100][100],**to_sort;
int compare(const void *a, const void *b){
const char **ia = (const char **)a;
const char **ib = (const char **)b;
return strcmp(*ia, *ib);
}
int get_var_num(char *str){
int i,flag;
flag=1;
for(i=0;i<var_count;i++){
if(!strcmp(str,variables[i])){
flag=0;
break;
}
}
if(flag){
strcpy(variables[i],str);
strcpy(to_sort[i],str);
var_count++;
}
return i;
}
int main(){
int i,tmp,new,v_num,mul;
char str[100],fac[6];
to_sort = (char**)malloc(100*sizeof(char*));
for(i=0;i<100;i++){
to_sort[i] = (char*)malloc(100*sizeof(char));
}
for(i=0;i<100;i++)
skill_level[i] = 0;
scanf("%d%d",&n,&m);
scanf("%s",fac);
mul = (fac[2]-'0')*10 + (fac[3]-'0');
//printf("%d %d %lf\n",n,m,k);
for(i=0;i<n;i++){
scanf("%s",str);
scanf("%*c%d",&tmp);
//printf("%s %d\n",str,tmp);
new = tmp*mul;
if(new >=10000){
v_num = get_var_num(str);
skill_level[v_num] = new/100;
}
}
for(i=0;i<m;i++){
scanf("%s",str);
//printf("%s\n",str);
v_num = get_var_num(str);
}
qsort(to_sort,var_count,sizeof(char *),compare);
printf("%d\n",var_count);
for(i=0;i<var_count;i++){
printf("%s %d\n",to_sort[i],skill_level[get_var_num(to_sort[i])]);
}
return 0;
} | |
In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an integer that increases when you use this skill. Different character classes are characterized by different skills. Unfortunately, the skills that are uncommon for the given character's class are quite difficult to obtain. To avoid this limitation, there is the so-called transmigration. Transmigration is reincarnation of the character in a new creature. His soul shifts to a new body and retains part of his experience from the previous life. As a result of transmigration the new character gets all the skills of the old character and the skill levels are reduced according to the k coefficient (if the skill level was equal to x, then after transmigration it becomes equal to [kx], where [y] is the integral part of y). If some skill's levels are strictly less than 100, these skills are forgotten (the character does not have them any more). After that the new character also gains the skills that are specific for his class, but are new to him. The levels of those additional skills are set to 0. Thus, one can create a character with skills specific for completely different character classes via transmigrations. For example, creating a mage archer or a thief warrior is possible. You are suggested to solve the following problem: what skills will the character have after transmigration and what will the levels of those skills be? | Print on the first line number z — the number of skills the character will have after the transmigration. Then print z lines, on each of which print a skill's name and level, separated by a single space. The skills should be given in the lexicographical order. | C | 7da1a5c4c76540e1c7dc06e4c908c8b4 | 77a06ca775a83124db9bf3f3e81bf50d | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1313247600 | ["5 4 0.75\naxe 350\nimpaler 300\nionize 80\nmegafire 120\nmagicboost 220\nheal\nmegafire\nshield\nmagicboost"] | null | PASSED | 1,700 | standard input | 2 seconds | The first line contains three numbers n, m and k — the number of skills the current character has, the number of skills specific for the class into which the character is going to transmigrate and the reducing coefficient respectively; n and m are integers, and k is a real number with exactly two digits after decimal point (1 ≤ n, m ≤ 20, 0.01 ≤ k ≤ 0.99). Then follow n lines, each of which describes a character's skill in the form "name exp" — the skill's name and the character's skill level: name is a string and exp is an integer in range from 0 to 9999, inclusive. Then follow m lines each of which contains names of skills specific for the class, into which the character transmigrates. All names consist of lowercase Latin letters and their lengths can range from 1 to 20 characters, inclusive. All character's skills have distinct names. Besides the skills specific for the class into which the player transmigrates also have distinct names. | ["6\naxe 262\nheal 0\nimpaler 225\nmagicboost 165\nmegafire 0\nshield 0"] | #include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
typedef long long ll;
typedef struct{
char name[99];
int pt;
int use;
} ability;
int cmp(const void *a1, const void *a2){
ability ab1 = *(ability*)a1;
ability ab2 = *(ability*)a2;
return strcmp(ab1.name,ab2.name);
}
int n,m,i,j,s,f,c,K;
double k;
ability ab[99];
main(){
scanf("%d%d%lf",&n,&m,&k);
K = k * 100+1e-5;
for(i=0;i<n;i++){
scanf("%s%d",&ab[i].name,&ab[i].pt);
ab[i].pt *= K;
if(ab[i].pt>9999) ab[i].use=1;
else ab[i].use=ab[i].pt=0;
}
for(i=n;i<n+m;i++){
f=1;
scanf("%s",&ab[i].name);
for(j=0;j<n;j++){
if(strcmp(ab[i].name,ab[j].name)==0){
f=0;
ab[j].use|=1;
}
}
ab[i].pt=0;
ab[i].use=f;
}
qsort(ab,m+n,sizeof(ability),cmp);
for(i=0;i<m+n;i++)
c+=ab[i].use;
printf("%d\n",c);
for(i=0;i<m+n;i++){
if(ab[i].use)
printf("%s %d\n",ab[i].name,ab[i].pt/100);
}
return 0;
}
| |
In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an integer that increases when you use this skill. Different character classes are characterized by different skills. Unfortunately, the skills that are uncommon for the given character's class are quite difficult to obtain. To avoid this limitation, there is the so-called transmigration. Transmigration is reincarnation of the character in a new creature. His soul shifts to a new body and retains part of his experience from the previous life. As a result of transmigration the new character gets all the skills of the old character and the skill levels are reduced according to the k coefficient (if the skill level was equal to x, then after transmigration it becomes equal to [kx], where [y] is the integral part of y). If some skill's levels are strictly less than 100, these skills are forgotten (the character does not have them any more). After that the new character also gains the skills that are specific for his class, but are new to him. The levels of those additional skills are set to 0. Thus, one can create a character with skills specific for completely different character classes via transmigrations. For example, creating a mage archer or a thief warrior is possible. You are suggested to solve the following problem: what skills will the character have after transmigration and what will the levels of those skills be? | Print on the first line number z — the number of skills the character will have after the transmigration. Then print z lines, on each of which print a skill's name and level, separated by a single space. The skills should be given in the lexicographical order. | C | 7da1a5c4c76540e1c7dc06e4c908c8b4 | c2b9d8bbebce6221d90984ee55896110 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1313247600 | ["5 4 0.75\naxe 350\nimpaler 300\nionize 80\nmegafire 120\nmagicboost 220\nheal\nmegafire\nshield\nmagicboost"] | null | PASSED | 1,700 | standard input | 2 seconds | The first line contains three numbers n, m and k — the number of skills the current character has, the number of skills specific for the class into which the character is going to transmigrate and the reducing coefficient respectively; n and m are integers, and k is a real number with exactly two digits after decimal point (1 ≤ n, m ≤ 20, 0.01 ≤ k ≤ 0.99). Then follow n lines, each of which describes a character's skill in the form "name exp" — the skill's name and the character's skill level: name is a string and exp is an integer in range from 0 to 9999, inclusive. Then follow m lines each of which contains names of skills specific for the class, into which the character transmigrates. All names consist of lowercase Latin letters and their lengths can range from 1 to 20 characters, inclusive. All character's skills have distinct names. Besides the skills specific for the class into which the player transmigrates also have distinct names. | ["6\naxe 262\nheal 0\nimpaler 225\nmagicboost 165\nmegafire 0\nshield 0"] | #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
char a[48][32];
int v[48];
int n,m,k;
int idx[48];
int cmp(const void *t1,const void *t2) {
return strcmp(a[*(int *)t1],a[*(int *)t2]);
}
int main() {
int i,j;
double p;
scanf("%d %d %lf",&n,&m,&p);
k=(int)floor(p*100+1e-12);
for(i=0;i<n;i++) {
scanf("%s %d",a[i],&v[i]);
v[i]=v[i]*k/100;
if (v[i]<100) i--,n--;
}
for(i=0;i<m;i++) {
scanf("%s",a[i+n]);
for(j=0;j<n;j++) if (strcmp(a[j],a[i+n])==0) break;
if (j<n) i--,m--; else v[i+n]=0;
}
n+=m;
for(i=0;i<n;i++) idx[i]=i;
qsort(idx,n,sizeof(idx[0]),cmp);
printf("%d\n",n);
for(i=0;i<n;i++) printf("%s %d\n",a[idx[i]],v[idx[i]]);
return 0;
} | |
In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an integer that increases when you use this skill. Different character classes are characterized by different skills. Unfortunately, the skills that are uncommon for the given character's class are quite difficult to obtain. To avoid this limitation, there is the so-called transmigration. Transmigration is reincarnation of the character in a new creature. His soul shifts to a new body and retains part of his experience from the previous life. As a result of transmigration the new character gets all the skills of the old character and the skill levels are reduced according to the k coefficient (if the skill level was equal to x, then after transmigration it becomes equal to [kx], where [y] is the integral part of y). If some skill's levels are strictly less than 100, these skills are forgotten (the character does not have them any more). After that the new character also gains the skills that are specific for his class, but are new to him. The levels of those additional skills are set to 0. Thus, one can create a character with skills specific for completely different character classes via transmigrations. For example, creating a mage archer or a thief warrior is possible. You are suggested to solve the following problem: what skills will the character have after transmigration and what will the levels of those skills be? | Print on the first line number z — the number of skills the character will have after the transmigration. Then print z lines, on each of which print a skill's name and level, separated by a single space. The skills should be given in the lexicographical order. | C | 7da1a5c4c76540e1c7dc06e4c908c8b4 | 4c20484ae457f880a336af8714dbb6b9 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1313247600 | ["5 4 0.75\naxe 350\nimpaler 300\nionize 80\nmegafire 120\nmagicboost 220\nheal\nmegafire\nshield\nmagicboost"] | null | PASSED | 1,700 | standard input | 2 seconds | The first line contains three numbers n, m and k — the number of skills the current character has, the number of skills specific for the class into which the character is going to transmigrate and the reducing coefficient respectively; n and m are integers, and k is a real number with exactly two digits after decimal point (1 ≤ n, m ≤ 20, 0.01 ≤ k ≤ 0.99). Then follow n lines, each of which describes a character's skill in the form "name exp" — the skill's name and the character's skill level: name is a string and exp is an integer in range from 0 to 9999, inclusive. Then follow m lines each of which contains names of skills specific for the class, into which the character transmigrates. All names consist of lowercase Latin letters and their lengths can range from 1 to 20 characters, inclusive. All character's skills have distinct names. Besides the skills specific for the class into which the player transmigrates also have distinct names. | ["6\naxe 262\nheal 0\nimpaler 225\nmagicboost 165\nmegafire 0\nshield 0"] | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXN 55
struct node
{
char s[MAXN];
int a;
};
void sort (struct node a[MAXN], int l, int r)
{
int i, j;
struct node x, y;
i = l; j = r; x = a[(l+r)/2];
while (i <= j)
{
while (strcmp(a[i].s, x.s) < 0) i++;
while (strcmp(a[j].s, x.s) > 0) j--;
if (i <= j)
{
y = a[i]; a[i] = a[j]; a[j] = y;
i++; j--;
}
}
if (l < j) sort(a,l,j);
if (i < r) sort(a,i,r);
}
int main ()
{
int N, M, K;
scanf("%d %d 0.%d\n",&N,&M,&K);
static struct node a[MAXN];
int i;
int ac = 0;
for (i = 0; i < N; i++)
{
scanf("%s %d\n",a[ac].s,&(a[ac].a));
a[ac].a = (a[ac].a * K) / 100;
if (a[ac].a >= 100) ac++;
}
int orig = ac;
int j;
for (i = 0; i < M; i++)
{
scanf("%s\n",a[ac].s);
a[ac].a = 0;
j = 0;
while (j < orig)
{
if (strcmp(a[ac].s, a[j].s) == 0) break;
j++;
}
if (j == orig) ac++;
}
sort(a,0,ac-1);
printf("%d\n",ac);
for (i = 0; i < ac; i++)
{
printf("%s %d\n",a[i].s,a[i].a);
}
return 0;
}
| |
In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an integer that increases when you use this skill. Different character classes are characterized by different skills. Unfortunately, the skills that are uncommon for the given character's class are quite difficult to obtain. To avoid this limitation, there is the so-called transmigration. Transmigration is reincarnation of the character in a new creature. His soul shifts to a new body and retains part of his experience from the previous life. As a result of transmigration the new character gets all the skills of the old character and the skill levels are reduced according to the k coefficient (if the skill level was equal to x, then after transmigration it becomes equal to [kx], where [y] is the integral part of y). If some skill's levels are strictly less than 100, these skills are forgotten (the character does not have them any more). After that the new character also gains the skills that are specific for his class, but are new to him. The levels of those additional skills are set to 0. Thus, one can create a character with skills specific for completely different character classes via transmigrations. For example, creating a mage archer or a thief warrior is possible. You are suggested to solve the following problem: what skills will the character have after transmigration and what will the levels of those skills be? | Print on the first line number z — the number of skills the character will have after the transmigration. Then print z lines, on each of which print a skill's name and level, separated by a single space. The skills should be given in the lexicographical order. | C | 7da1a5c4c76540e1c7dc06e4c908c8b4 | c0a06c510d28352f9366bb002200a6b5 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1313247600 | ["5 4 0.75\naxe 350\nimpaler 300\nionize 80\nmegafire 120\nmagicboost 220\nheal\nmegafire\nshield\nmagicboost"] | null | PASSED | 1,700 | standard input | 2 seconds | The first line contains three numbers n, m and k — the number of skills the current character has, the number of skills specific for the class into which the character is going to transmigrate and the reducing coefficient respectively; n and m are integers, and k is a real number with exactly two digits after decimal point (1 ≤ n, m ≤ 20, 0.01 ≤ k ≤ 0.99). Then follow n lines, each of which describes a character's skill in the form "name exp" — the skill's name and the character's skill level: name is a string and exp is an integer in range from 0 to 9999, inclusive. Then follow m lines each of which contains names of skills specific for the class, into which the character transmigrates. All names consist of lowercase Latin letters and their lengths can range from 1 to 20 characters, inclusive. All character's skills have distinct names. Besides the skills specific for the class into which the player transmigrates also have distinct names. | ["6\naxe 262\nheal 0\nimpaler 225\nmagicboost 165\nmegafire 0\nshield 0"] | #include <stdio.h>
#include <string.h>
struct case1
{
char str[25];
int v;
}p[45];
char str[25];
int main()
{
struct case1 t;
int i,j,n,m;
double k;
scanf("%d%d%lf",&n,&m,&k);
for (i=1;i<=n;i++)
{
scanf("%s%d",p[i].str+1,&p[i].v);
p[i].v=p[i].v*k+1e-8;
if (p[i].v<100)
{
i--;
n--;
}
}
for (i=1;i<=m;i++)
{
scanf("%s",str+1);
for (j=1;j<=n&&strcmp(p[j].str+1,str+1);j++);
if (j>n)
{
p[++n].v=0;
strcpy(p[n].str+1,str+1);
}
}
for (i=1;i<n;i++)
for (j=i+1;j<=n;j++)
if (strcmp(p[i].str+1,p[j].str+1)>0)
{
t=p[i];
p[i]=p[j];
p[j]=t;
}
printf("%d\n",n);
for (i=1;i<=n;i++)
printf("%s %d\n",p[i].str+1,p[i].v);
return 0;
}
| |
This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of n computers, some of them are connected by a cable. The computers are indexed by integers from 1 to n. It's known that any two computers connected by cable directly or through other computersPolycarpus decided to find out the network's topology. A network topology is the way of describing the network configuration, the scheme that shows the location and the connections of network devices.Polycarpus knows three main network topologies: bus, ring and star. A bus is the topology that represents a shared cable with all computers connected with it. In the ring topology the cable connects each computer only with two other ones. A star is the topology where all computers of a network are connected to the single central node.Let's represent each of these network topologies as a connected non-directed graph. A bus is a connected graph that is the only path, that is, the graph where all nodes are connected with two other ones except for some two nodes that are the beginning and the end of the path. A ring is a connected graph, where all nodes are connected with two other ones. A star is a connected graph, where a single central node is singled out and connected with all other nodes. For clarifications, see the picture. (1) — bus, (2) — ring, (3) — star You've got a connected non-directed graph that characterizes the computer network in Polycarpus' corporation. Help him find out, which topology type the given network is. If that is impossible to do, say that the network's topology is unknown. | In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topology" (without the quotes). | C | 7bb088ce5e4e2101221c706ff87841e4 | 7da0fefcdd349bf0ab11c3eb69bb2c72 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"graphs"
] | 1366040100 | ["4 3\n1 2\n2 3\n3 4", "4 4\n1 2\n2 3\n3 4\n4 1", "4 3\n1 2\n1 3\n1 4", "4 4\n1 2\n2 3\n3 1\n1 4"] | null | PASSED | 1,200 | standard input | 2 seconds | The first line contains two space-separated integers n and m (4 ≤ n ≤ 105; 3 ≤ m ≤ 105) — the number of nodes and edges in the graph, correspondingly. Next m lines contain the description of the graph's edges. The i-th line contains a space-separated pair of integers xi, yi (1 ≤ xi, yi ≤ n) — the numbers of nodes that are connected by the i-the edge. It is guaranteed that the given graph is connected. There is at most one edge between any two nodes. No edge connects a node with itself. | ["bus topology", "ring topology", "star topology", "unknown topology"] | #include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#define max(a,b) ((a)>(b))?(a):(b)
#define min(a,b) ((a)<(b))?(a):(b)
#define si(n) scanf("%d",&n)
#define ss(s) scanf("%s",s)
#define sort(a,n) qsort(a,n,sizeof(int),compare)
#define pi(n) printf("%d ",n)
#define ps(s) printf("%s",s)
#define loop(i,n) for(i=0;i<n;i++)
#define Loop(i,n) for(i=1;i<=n;i++)
typedef long long int lld;
//#define MAX 100005
//int a[MAX];
int compare(const void *a,const void *b)
{
return *(int *)a-*(int *)b;
}
int ones,twos,others,degree[100005];
int main(void)
{
int i,n,ans,k,l,m,t;
si(n);
si(m);
Loop(i,m)
{
si(t);
si(l);
degree[t]++;
degree[l]++;
}
Loop(i,n)
{
if(degree[i]==1)
ones++;
else if(degree[i]==2)
twos++;
else
others++;
}
if(ones==2 && others==0)
puts("bus topology");
else if(ones==n-1 && others==1)
puts("star topology");
else if(twos==n)
puts("ring topology");
else
puts("unknown topology");
return 0;
}
| |
This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of n computers, some of them are connected by a cable. The computers are indexed by integers from 1 to n. It's known that any two computers connected by cable directly or through other computersPolycarpus decided to find out the network's topology. A network topology is the way of describing the network configuration, the scheme that shows the location and the connections of network devices.Polycarpus knows three main network topologies: bus, ring and star. A bus is the topology that represents a shared cable with all computers connected with it. In the ring topology the cable connects each computer only with two other ones. A star is the topology where all computers of a network are connected to the single central node.Let's represent each of these network topologies as a connected non-directed graph. A bus is a connected graph that is the only path, that is, the graph where all nodes are connected with two other ones except for some two nodes that are the beginning and the end of the path. A ring is a connected graph, where all nodes are connected with two other ones. A star is a connected graph, where a single central node is singled out and connected with all other nodes. For clarifications, see the picture. (1) — bus, (2) — ring, (3) — star You've got a connected non-directed graph that characterizes the computer network in Polycarpus' corporation. Help him find out, which topology type the given network is. If that is impossible to do, say that the network's topology is unknown. | In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topology" (without the quotes). | C | 7bb088ce5e4e2101221c706ff87841e4 | 08aadef8b671cd2c8aa7867d6e1889ae | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation",
"graphs"
] | 1366040100 | ["4 3\n1 2\n2 3\n3 4", "4 4\n1 2\n2 3\n3 4\n4 1", "4 3\n1 2\n1 3\n1 4", "4 4\n1 2\n2 3\n3 1\n1 4"] | null | PASSED | 1,200 | standard input | 2 seconds | The first line contains two space-separated integers n and m (4 ≤ n ≤ 105; 3 ≤ m ≤ 105) — the number of nodes and edges in the graph, correspondingly. Next m lines contain the description of the graph's edges. The i-th line contains a space-separated pair of integers xi, yi (1 ≤ xi, yi ≤ n) — the numbers of nodes that are connected by the i-the edge. It is guaranteed that the given graph is connected. There is at most one edge between any two nodes. No edge connects a node with itself. | ["bus topology", "ring topology", "star topology", "unknown topology"] | #include <stdio.h>
#include <stdlib.h>
int max(int a, int b)
{
if (a > b)
return a;
else
return b;
}
int main(void)
{
int n, m, i, s, f;
scanf("%d%d", &n, &m);
int a[n];
for (i = 0; i < n; i++)
a[i] = 0;
for (i = 0; i < m; i++)
{
scanf("%d%d", &s, &f);
a[s - 1]++;
a[f - 1]++;
}
s = 0;
f = 0;
for (i = 0; i < n; i++)
{
if (a[i] == 1)
s++;
if (a[i] == 2)
f++;
}
if ((s == 2) && (f == n - 2))
{
printf("bus topology\n");
return 0;
}
if (f == n)
{
printf("ring topology\n");
return 0;
}
if (s == n - 1)
{
printf("star topology\n");
return 0;
}
printf("unknown topology\n");
return 0;
}
| |
You are asked to watch your nephew who likes to play with toy blocks in a strange way.He has $$$n$$$ boxes and the $$$i$$$-th box has $$$a_i$$$ blocks. His game consists of two steps: he chooses an arbitrary box $$$i$$$; he tries to move all blocks from the $$$i$$$-th box to other boxes. If he can make the same number of blocks in each of $$$n - 1$$$ other boxes then he will be happy, otherwise, will be sad. Note that your nephew can only move the blocks from the chosen box to the other boxes; he cannot move blocks from the other boxes.You don't want to make your nephew sad, so you decided to put several extra blocks into some boxes in such a way that no matter which box $$$i$$$ he chooses he won't be sad. What is the minimum number of extra blocks you need to put? | For each test case, print a single integer — the minimum number of blocks you need to put. It can be proved that the answer always exists, i. e. the number of blocks is finite. | C | e75b88ce4341062c20b6014da1152d29 | 959ed4add011e21881fab40a8975bc22 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"binary search",
"sortings",
"greedy",
"math"
] | 1605796500 | ["3\n3\n3 2 2\n4\n2 2 3 2\n3\n0 3 0"] | NoteIn the first test case, you can, for example, put one extra block into the first box and make $$$a = [4, 2, 2]$$$. If your nephew chooses the box with $$$4$$$ blocks, then we will move two blocks to the second box and two blocks to the third box. If he chooses the box with $$$2$$$ blocks then he will move these two blocks to the other box with $$$2$$$ blocks.In the second test case, you don't need to put any extra blocks, since no matter which box your nephew chooses, he can always make other boxes equal.In the third test case, you should put $$$3$$$ extra blocks. For example, you can put $$$2$$$ blocks in the first box and $$$1$$$ block in the third box. You'll get array $$$a = [2, 3, 1]$$$. | PASSED | 1,400 | standard input | 2 seconds | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of boxes. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the number of blocks in each box. It's guaranteed that the sum of $$$n$$$ over test cases doesn't exceed $$$10^5$$$. | ["1\n0\n3"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
long long test,i,j,k,*arr,*array,box,tot,max,g;
scanf("%lld",&test);
arr=(long long*)malloc(sizeof(long long)*test);
for( i=0;i<test;i++)
{ scanf("%lld",&box);tot=0;max=0;
array=(long long*)malloc(sizeof(long long)*box);
for(j=0;j<box;j++)
{scanf("%lld",&array[j]);tot=tot+array[j];}
for(j=0;j<box;j++)
if(array[j]>max)
max=array[j];
if(tot%(box-1)==0)
g=tot/(box-1);
else
g=tot/(box-1)+1;
if(g>max)
max=g;
arr[i]=((box-1)*max)-tot;
free(array);}
for(i=0;i<test;i++)
{printf("%lld",arr[i]);
if(i!=test-1)
printf("\n");
}
return 0;
}
| |
You are asked to watch your nephew who likes to play with toy blocks in a strange way.He has $$$n$$$ boxes and the $$$i$$$-th box has $$$a_i$$$ blocks. His game consists of two steps: he chooses an arbitrary box $$$i$$$; he tries to move all blocks from the $$$i$$$-th box to other boxes. If he can make the same number of blocks in each of $$$n - 1$$$ other boxes then he will be happy, otherwise, will be sad. Note that your nephew can only move the blocks from the chosen box to the other boxes; he cannot move blocks from the other boxes.You don't want to make your nephew sad, so you decided to put several extra blocks into some boxes in such a way that no matter which box $$$i$$$ he chooses he won't be sad. What is the minimum number of extra blocks you need to put? | For each test case, print a single integer — the minimum number of blocks you need to put. It can be proved that the answer always exists, i. e. the number of blocks is finite. | C | e75b88ce4341062c20b6014da1152d29 | d7555169ed3e867f70ff0d75f672fc79 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"binary search",
"sortings",
"greedy",
"math"
] | 1605796500 | ["3\n3\n3 2 2\n4\n2 2 3 2\n3\n0 3 0"] | NoteIn the first test case, you can, for example, put one extra block into the first box and make $$$a = [4, 2, 2]$$$. If your nephew chooses the box with $$$4$$$ blocks, then we will move two blocks to the second box and two blocks to the third box. If he chooses the box with $$$2$$$ blocks then he will move these two blocks to the other box with $$$2$$$ blocks.In the second test case, you don't need to put any extra blocks, since no matter which box your nephew chooses, he can always make other boxes equal.In the third test case, you should put $$$3$$$ extra blocks. For example, you can put $$$2$$$ blocks in the first box and $$$1$$$ block in the third box. You'll get array $$$a = [2, 3, 1]$$$. | PASSED | 1,400 | standard input | 2 seconds | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of boxes. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the number of blocks in each box. It's guaranteed that the sum of $$$n$$$ over test cases doesn't exceed $$$10^5$$$. | ["1\n0\n3"] | #include<stdio.h>
long long a[100010];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
long long n;
long long max=0,min=1e9;
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
if(max<a[i]) max=a[i];
if(min>a[i]) min=a[i];
}
long long sum=0;
for(int i=1;i<=n;i++)
{
sum+=max-a[i];
}
sum=sum+min-max;
if(sum>=min) printf("%lld\n",sum-min);
else
{
min-=sum;
long long f=0;
while(min%(n-1)!=0)
{
min++;
f++;
}
printf("%lld\n",f);
}
}
return 0;
} | |
You are asked to watch your nephew who likes to play with toy blocks in a strange way.He has $$$n$$$ boxes and the $$$i$$$-th box has $$$a_i$$$ blocks. His game consists of two steps: he chooses an arbitrary box $$$i$$$; he tries to move all blocks from the $$$i$$$-th box to other boxes. If he can make the same number of blocks in each of $$$n - 1$$$ other boxes then he will be happy, otherwise, will be sad. Note that your nephew can only move the blocks from the chosen box to the other boxes; he cannot move blocks from the other boxes.You don't want to make your nephew sad, so you decided to put several extra blocks into some boxes in such a way that no matter which box $$$i$$$ he chooses he won't be sad. What is the minimum number of extra blocks you need to put? | For each test case, print a single integer — the minimum number of blocks you need to put. It can be proved that the answer always exists, i. e. the number of blocks is finite. | C | e75b88ce4341062c20b6014da1152d29 | 042f6df23f5bea270cf7a3a8a92ec674 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"binary search",
"sortings",
"greedy",
"math"
] | 1605796500 | ["3\n3\n3 2 2\n4\n2 2 3 2\n3\n0 3 0"] | NoteIn the first test case, you can, for example, put one extra block into the first box and make $$$a = [4, 2, 2]$$$. If your nephew chooses the box with $$$4$$$ blocks, then we will move two blocks to the second box and two blocks to the third box. If he chooses the box with $$$2$$$ blocks then he will move these two blocks to the other box with $$$2$$$ blocks.In the second test case, you don't need to put any extra blocks, since no matter which box your nephew chooses, he can always make other boxes equal.In the third test case, you should put $$$3$$$ extra blocks. For example, you can put $$$2$$$ blocks in the first box and $$$1$$$ block in the third box. You'll get array $$$a = [2, 3, 1]$$$. | PASSED | 1,400 | standard input | 2 seconds | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of boxes. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the number of blocks in each box. It's guaranteed that the sum of $$$n$$$ over test cases doesn't exceed $$$10^5$$$. | ["1\n0\n3"] | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <inttypes.h>
typedef int64_t int64; typedef int32_t int32;
typedef uint64_t uint64; typedef uint32_t uint32;
#define in(i,bit) scanf("%"PRId##bit"",&i)
#define uin(i,bit) scanf("%"PRIu##bit"",&i)
#define out(i,bit,c) printf("%"PRId##bit"%c",i,c)
#define uout(i,bit,c) printf("%"PRIu##bit"%c",i,c)
#define finc(i,a,b) for(int32 i=(a);i<=(b);i++)
#define fdec(i,a,b) for(int32 i=(b)+1;i-->(a);)
#define N (int32)1e5+1
#define end '\n'
int64 a[N];
int main(void)
{
int32 test; in(test, 32);
while (test--)
{
int64 n; in(n, 64);
finc(i, 1, n)
in(a[i], 32);
int64 max = a[1], sum = 0, ans;
finc(i, 1, n)
{
sum += a[i];
if (a[i] > max)
max = a[i];
}
if (sum <= (n - 1)*max)
ans = (n - 1)*max - sum;
else if ((sum - (n - 1)*max) % (n - 1) == 0)
ans = 0;
else
ans = (n - 1) - ((sum - (n - 1)*max) % (n - 1));
out(ans, 64, end);
}
return 0;
} | |
You are asked to watch your nephew who likes to play with toy blocks in a strange way.He has $$$n$$$ boxes and the $$$i$$$-th box has $$$a_i$$$ blocks. His game consists of two steps: he chooses an arbitrary box $$$i$$$; he tries to move all blocks from the $$$i$$$-th box to other boxes. If he can make the same number of blocks in each of $$$n - 1$$$ other boxes then he will be happy, otherwise, will be sad. Note that your nephew can only move the blocks from the chosen box to the other boxes; he cannot move blocks from the other boxes.You don't want to make your nephew sad, so you decided to put several extra blocks into some boxes in such a way that no matter which box $$$i$$$ he chooses he won't be sad. What is the minimum number of extra blocks you need to put? | For each test case, print a single integer — the minimum number of blocks you need to put. It can be proved that the answer always exists, i. e. the number of blocks is finite. | C | e75b88ce4341062c20b6014da1152d29 | 41721b200e3bf8fda16871ef9a056137 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"binary search",
"sortings",
"greedy",
"math"
] | 1605796500 | ["3\n3\n3 2 2\n4\n2 2 3 2\n3\n0 3 0"] | NoteIn the first test case, you can, for example, put one extra block into the first box and make $$$a = [4, 2, 2]$$$. If your nephew chooses the box with $$$4$$$ blocks, then we will move two blocks to the second box and two blocks to the third box. If he chooses the box with $$$2$$$ blocks then he will move these two blocks to the other box with $$$2$$$ blocks.In the second test case, you don't need to put any extra blocks, since no matter which box your nephew chooses, he can always make other boxes equal.In the third test case, you should put $$$3$$$ extra blocks. For example, you can put $$$2$$$ blocks in the first box and $$$1$$$ block in the third box. You'll get array $$$a = [2, 3, 1]$$$. | PASSED | 1,400 | standard input | 2 seconds | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of boxes. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the number of blocks in each box. It's guaranteed that the sum of $$$n$$$ over test cases doesn't exceed $$$10^5$$$. | ["1\n0\n3"] | #include <stdio.h>
long long max(long long a, long long b) { return a > b ? a : b; }
int comp(const void* a, const void *b){
return *(long long *)a - *(long long *)b;
}
int main()
{
int x,y,z,i,j,k,b,c,n,m,t;
scanf("%d",&t);
long long sum,res,s,mat[100100];
while(t--)
{
res = 0;
sum = 0;
scanf("%d",&n);
for(x = 0; x < n; x++)
scanf("%lld",&mat[x]);
if(n == 2) {puts("0"); continue;}
qsort(mat, n, sizeof(long long), comp);
for(x = n - 1; x > 0; x--)
sum += mat[n - 1] - mat[x];
if(sum - mat[0] >= 0) printf("%lld\n",sum - mat[0]);
else
{
if((mat[0] - sum)%(n-1))
printf("%lld\n",n - 1 - (mat[0] - sum)%(n-1));
else puts("0");
}
}
return 0;
}
| |
You are asked to watch your nephew who likes to play with toy blocks in a strange way.He has $$$n$$$ boxes and the $$$i$$$-th box has $$$a_i$$$ blocks. His game consists of two steps: he chooses an arbitrary box $$$i$$$; he tries to move all blocks from the $$$i$$$-th box to other boxes. If he can make the same number of blocks in each of $$$n - 1$$$ other boxes then he will be happy, otherwise, will be sad. Note that your nephew can only move the blocks from the chosen box to the other boxes; he cannot move blocks from the other boxes.You don't want to make your nephew sad, so you decided to put several extra blocks into some boxes in such a way that no matter which box $$$i$$$ he chooses he won't be sad. What is the minimum number of extra blocks you need to put? | For each test case, print a single integer — the minimum number of blocks you need to put. It can be proved that the answer always exists, i. e. the number of blocks is finite. | C | e75b88ce4341062c20b6014da1152d29 | 9fb8e5d1507a748713f767c8a6b5cdf3 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"binary search",
"sortings",
"greedy",
"math"
] | 1605796500 | ["3\n3\n3 2 2\n4\n2 2 3 2\n3\n0 3 0"] | NoteIn the first test case, you can, for example, put one extra block into the first box and make $$$a = [4, 2, 2]$$$. If your nephew chooses the box with $$$4$$$ blocks, then we will move two blocks to the second box and two blocks to the third box. If he chooses the box with $$$2$$$ blocks then he will move these two blocks to the other box with $$$2$$$ blocks.In the second test case, you don't need to put any extra blocks, since no matter which box your nephew chooses, he can always make other boxes equal.In the third test case, you should put $$$3$$$ extra blocks. For example, you can put $$$2$$$ blocks in the first box and $$$1$$$ block in the third box. You'll get array $$$a = [2, 3, 1]$$$. | PASSED | 1,400 | standard input | 2 seconds | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of boxes. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the number of blocks in each box. It's guaranteed that the sum of $$$n$$$ over test cases doesn't exceed $$$10^5$$$. | ["1\n0\n3"] | #include<stdio.h>
int main(int argc, char *argv[])
{
long long int a,i,b,c,d,e,j,f,g,y;
scanf("%lld",&a);
for(i=0;i<a;i++){
d=0;
scanf("%lld",&b);
long long int x[b];
for(j=0;j<b;j++){
scanf("%lld",&x[j]);
d=d+x[j];
if(j==0)
e=x[j];
else{
if(e<x[j])
e=x[j];}}
f=b-1;
if(b<=2)
printf("%lld\n",y);
else{
g=f*e;
if(g>d)
printf("%lld\n",g-d);
else if(g==d)
printf("%lld\n",y);
else{
g=d-g;
if(g>f){
if(g%f==0)
printf("%lld\n",y);
else{
d=g%f;
printf("%lld\n",f-d);}}
else{
d=f-g;
printf("%lld\n",d);}}}}
return 0;
} | |
You are asked to watch your nephew who likes to play with toy blocks in a strange way.He has $$$n$$$ boxes and the $$$i$$$-th box has $$$a_i$$$ blocks. His game consists of two steps: he chooses an arbitrary box $$$i$$$; he tries to move all blocks from the $$$i$$$-th box to other boxes. If he can make the same number of blocks in each of $$$n - 1$$$ other boxes then he will be happy, otherwise, will be sad. Note that your nephew can only move the blocks from the chosen box to the other boxes; he cannot move blocks from the other boxes.You don't want to make your nephew sad, so you decided to put several extra blocks into some boxes in such a way that no matter which box $$$i$$$ he chooses he won't be sad. What is the minimum number of extra blocks you need to put? | For each test case, print a single integer — the minimum number of blocks you need to put. It can be proved that the answer always exists, i. e. the number of blocks is finite. | C | e75b88ce4341062c20b6014da1152d29 | 16ecaff1a752bfa3d3272797d168dc17 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"binary search",
"sortings",
"greedy",
"math"
] | 1605796500 | ["3\n3\n3 2 2\n4\n2 2 3 2\n3\n0 3 0"] | NoteIn the first test case, you can, for example, put one extra block into the first box and make $$$a = [4, 2, 2]$$$. If your nephew chooses the box with $$$4$$$ blocks, then we will move two blocks to the second box and two blocks to the third box. If he chooses the box with $$$2$$$ blocks then he will move these two blocks to the other box with $$$2$$$ blocks.In the second test case, you don't need to put any extra blocks, since no matter which box your nephew chooses, he can always make other boxes equal.In the third test case, you should put $$$3$$$ extra blocks. For example, you can put $$$2$$$ blocks in the first box and $$$1$$$ block in the third box. You'll get array $$$a = [2, 3, 1]$$$. | PASSED | 1,400 | standard input | 2 seconds | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of boxes. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the number of blocks in each box. It's guaranteed that the sum of $$$n$$$ over test cases doesn't exceed $$$10^5$$$. | ["1\n0\n3"] | #include<stdio.h>
int main(){
int t;
scanf("%d",&t);
while(t--){
long long int i,n,a,j,k,ans=0,b=-1;
scanf("%lld",&n);
for(i=0;i<n;i++){
scanf("%lld",&a);
b=a>b?a:b;
ans+=a;
}
j=ans/(n-1);
k=ans%(n-1);
if(k!=0)j++;
for(;1;){
if(j>=b)break;
j++;
}
printf("%lld\n",j*(n-1)-ans);
}
} | |
You are asked to watch your nephew who likes to play with toy blocks in a strange way.He has $$$n$$$ boxes and the $$$i$$$-th box has $$$a_i$$$ blocks. His game consists of two steps: he chooses an arbitrary box $$$i$$$; he tries to move all blocks from the $$$i$$$-th box to other boxes. If he can make the same number of blocks in each of $$$n - 1$$$ other boxes then he will be happy, otherwise, will be sad. Note that your nephew can only move the blocks from the chosen box to the other boxes; he cannot move blocks from the other boxes.You don't want to make your nephew sad, so you decided to put several extra blocks into some boxes in such a way that no matter which box $$$i$$$ he chooses he won't be sad. What is the minimum number of extra blocks you need to put? | For each test case, print a single integer — the minimum number of blocks you need to put. It can be proved that the answer always exists, i. e. the number of blocks is finite. | C | e75b88ce4341062c20b6014da1152d29 | c698d9554939c59185069e688b129401 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"binary search",
"sortings",
"greedy",
"math"
] | 1605796500 | ["3\n3\n3 2 2\n4\n2 2 3 2\n3\n0 3 0"] | NoteIn the first test case, you can, for example, put one extra block into the first box and make $$$a = [4, 2, 2]$$$. If your nephew chooses the box with $$$4$$$ blocks, then we will move two blocks to the second box and two blocks to the third box. If he chooses the box with $$$2$$$ blocks then he will move these two blocks to the other box with $$$2$$$ blocks.In the second test case, you don't need to put any extra blocks, since no matter which box your nephew chooses, he can always make other boxes equal.In the third test case, you should put $$$3$$$ extra blocks. For example, you can put $$$2$$$ blocks in the first box and $$$1$$$ block in the third box. You'll get array $$$a = [2, 3, 1]$$$. | PASSED | 1,400 | standard input | 2 seconds | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of boxes. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the number of blocks in each box. It's guaranteed that the sum of $$$n$$$ over test cases doesn't exceed $$$10^5$$$. | ["1\n0\n3"] | #include <stdio.h>
#include <math.h>
#include <string.h>
int max(int a,int b)
{
if(a>b)
return a;
else
return b;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
long long n,sum=0,mas=-1;
scanf("%lld",&n);
for(long long i=0;i<n;i++)
{
long long x;
scanf("%lld",&x);
mas=max(mas,x);
sum+=x;
}
long long ans=sum;
long long a=ans/(n-1);
long long b=ans%(n-1);
if(b!=0)
a++;
while(1)
{
ans=a*(n-1);
if(a>=mas)
break;
a++;
}
printf("%lld\n",ans-sum);
}
return 0;
} | |
You are asked to watch your nephew who likes to play with toy blocks in a strange way.He has $$$n$$$ boxes and the $$$i$$$-th box has $$$a_i$$$ blocks. His game consists of two steps: he chooses an arbitrary box $$$i$$$; he tries to move all blocks from the $$$i$$$-th box to other boxes. If he can make the same number of blocks in each of $$$n - 1$$$ other boxes then he will be happy, otherwise, will be sad. Note that your nephew can only move the blocks from the chosen box to the other boxes; he cannot move blocks from the other boxes.You don't want to make your nephew sad, so you decided to put several extra blocks into some boxes in such a way that no matter which box $$$i$$$ he chooses he won't be sad. What is the minimum number of extra blocks you need to put? | For each test case, print a single integer — the minimum number of blocks you need to put. It can be proved that the answer always exists, i. e. the number of blocks is finite. | C | e75b88ce4341062c20b6014da1152d29 | f5ec0384b2b7f66fb33e3dffb6905846 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"binary search",
"sortings",
"greedy",
"math"
] | 1605796500 | ["3\n3\n3 2 2\n4\n2 2 3 2\n3\n0 3 0"] | NoteIn the first test case, you can, for example, put one extra block into the first box and make $$$a = [4, 2, 2]$$$. If your nephew chooses the box with $$$4$$$ blocks, then we will move two blocks to the second box and two blocks to the third box. If he chooses the box with $$$2$$$ blocks then he will move these two blocks to the other box with $$$2$$$ blocks.In the second test case, you don't need to put any extra blocks, since no matter which box your nephew chooses, he can always make other boxes equal.In the third test case, you should put $$$3$$$ extra blocks. For example, you can put $$$2$$$ blocks in the first box and $$$1$$$ block in the third box. You'll get array $$$a = [2, 3, 1]$$$. | PASSED | 1,400 | standard input | 2 seconds | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of boxes. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the number of blocks in each box. It's guaranteed that the sum of $$$n$$$ over test cases doesn't exceed $$$10^5$$$. | ["1\n0\n3"] | #include<stdio.h>
#include<math.h>
#define MAXSIZE 100001
long long Max(long long a, long long b);
int main(int argv, char* argc[])
{
int n;
scanf("%d", &n);
while (n--)
{
long long boxs, blocks[MAXSIZE];
long long averge, sum = 0;
long long max=0, least;
scanf("%lld", &boxs);
for (int i = 0; i < boxs; i++)
{
scanf("%lld", &blocks[i]);
sum += blocks[i];
if (blocks[i] > max)
max = blocks[i];
}
if (sum % (boxs - 1) == 0)
averge = sum / (boxs - 1);
else
averge = sum / (boxs - 1) + 1;
least = Max(averge, max);
printf("%lld\n", least * (boxs - 1) - sum);
}
}
long long Max(long long a, long long b)
{
return a > b ? a : b;
} | |
You are asked to watch your nephew who likes to play with toy blocks in a strange way.He has $$$n$$$ boxes and the $$$i$$$-th box has $$$a_i$$$ blocks. His game consists of two steps: he chooses an arbitrary box $$$i$$$; he tries to move all blocks from the $$$i$$$-th box to other boxes. If he can make the same number of blocks in each of $$$n - 1$$$ other boxes then he will be happy, otherwise, will be sad. Note that your nephew can only move the blocks from the chosen box to the other boxes; he cannot move blocks from the other boxes.You don't want to make your nephew sad, so you decided to put several extra blocks into some boxes in such a way that no matter which box $$$i$$$ he chooses he won't be sad. What is the minimum number of extra blocks you need to put? | For each test case, print a single integer — the minimum number of blocks you need to put. It can be proved that the answer always exists, i. e. the number of blocks is finite. | C | e75b88ce4341062c20b6014da1152d29 | b735cbb3fec97a8681e8ab9dd1dfb79b | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"binary search",
"sortings",
"greedy",
"math"
] | 1605796500 | ["3\n3\n3 2 2\n4\n2 2 3 2\n3\n0 3 0"] | NoteIn the first test case, you can, for example, put one extra block into the first box and make $$$a = [4, 2, 2]$$$. If your nephew chooses the box with $$$4$$$ blocks, then we will move two blocks to the second box and two blocks to the third box. If he chooses the box with $$$2$$$ blocks then he will move these two blocks to the other box with $$$2$$$ blocks.In the second test case, you don't need to put any extra blocks, since no matter which box your nephew chooses, he can always make other boxes equal.In the third test case, you should put $$$3$$$ extra blocks. For example, you can put $$$2$$$ blocks in the first box and $$$1$$$ block in the third box. You'll get array $$$a = [2, 3, 1]$$$. | PASSED | 1,400 | standard input | 2 seconds | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of boxes. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the number of blocks in each box. It's guaranteed that the sum of $$$n$$$ over test cases doesn't exceed $$$10^5$$$. | ["1\n0\n3"] | #include <stdio.h>
typedef long long int lli;
lli d[100005];
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int n;
scanf("%d", &n);
lli sum = 0, maxv = 0;
for(int i = 0; i < n; i++)
{
scanf("%I64d", &d[i]);
sum += d[i];
if(d[i] > maxv)
maxv = d[i];
}
lli ans;
if(maxv * (n-1) < sum)
{
if(sum % (n-1) == 0)
ans = 0;
else
ans = (n-1) - (sum % (n-1));
}
else
ans = maxv*(n-1) - sum;
printf("%I64d\n", ans);
}
} | |
You are asked to watch your nephew who likes to play with toy blocks in a strange way.He has $$$n$$$ boxes and the $$$i$$$-th box has $$$a_i$$$ blocks. His game consists of two steps: he chooses an arbitrary box $$$i$$$; he tries to move all blocks from the $$$i$$$-th box to other boxes. If he can make the same number of blocks in each of $$$n - 1$$$ other boxes then he will be happy, otherwise, will be sad. Note that your nephew can only move the blocks from the chosen box to the other boxes; he cannot move blocks from the other boxes.You don't want to make your nephew sad, so you decided to put several extra blocks into some boxes in such a way that no matter which box $$$i$$$ he chooses he won't be sad. What is the minimum number of extra blocks you need to put? | For each test case, print a single integer — the minimum number of blocks you need to put. It can be proved that the answer always exists, i. e. the number of blocks is finite. | C | e75b88ce4341062c20b6014da1152d29 | fd002f15bf699aff0986c33012a4630e | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"binary search",
"sortings",
"greedy",
"math"
] | 1605796500 | ["3\n3\n3 2 2\n4\n2 2 3 2\n3\n0 3 0"] | NoteIn the first test case, you can, for example, put one extra block into the first box and make $$$a = [4, 2, 2]$$$. If your nephew chooses the box with $$$4$$$ blocks, then we will move two blocks to the second box and two blocks to the third box. If he chooses the box with $$$2$$$ blocks then he will move these two blocks to the other box with $$$2$$$ blocks.In the second test case, you don't need to put any extra blocks, since no matter which box your nephew chooses, he can always make other boxes equal.In the third test case, you should put $$$3$$$ extra blocks. For example, you can put $$$2$$$ blocks in the first box and $$$1$$$ block in the third box. You'll get array $$$a = [2, 3, 1]$$$. | PASSED | 1,400 | standard input | 2 seconds | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of boxes. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the number of blocks in each box. It's guaranteed that the sum of $$$n$$$ over test cases doesn't exceed $$$10^5$$$. | ["1\n0\n3"] | #include <stdio.h>
typedef long long int lli;
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int n;
scanf("%d", &n);
lli sum = 0, maxv = 0, tmp;
for(int i = 0; i < n; i++)
{
scanf("%I64d", &tmp);
sum += tmp;
if(tmp > maxv)
maxv = tmp;
}
lli ans;
n--;
if(maxv * n < sum)
{
if(sum % n == 0)
ans = 0;
else
ans = n - (sum % n);
}
else
ans = maxv*n - sum;
printf("%I64d\n", ans);
}
} | |
You are asked to watch your nephew who likes to play with toy blocks in a strange way.He has $$$n$$$ boxes and the $$$i$$$-th box has $$$a_i$$$ blocks. His game consists of two steps: he chooses an arbitrary box $$$i$$$; he tries to move all blocks from the $$$i$$$-th box to other boxes. If he can make the same number of blocks in each of $$$n - 1$$$ other boxes then he will be happy, otherwise, will be sad. Note that your nephew can only move the blocks from the chosen box to the other boxes; he cannot move blocks from the other boxes.You don't want to make your nephew sad, so you decided to put several extra blocks into some boxes in such a way that no matter which box $$$i$$$ he chooses he won't be sad. What is the minimum number of extra blocks you need to put? | For each test case, print a single integer — the minimum number of blocks you need to put. It can be proved that the answer always exists, i. e. the number of blocks is finite. | C | e75b88ce4341062c20b6014da1152d29 | a374dd59eaaf109373200c9d27be2aa2 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"binary search",
"sortings",
"greedy",
"math"
] | 1605796500 | ["3\n3\n3 2 2\n4\n2 2 3 2\n3\n0 3 0"] | NoteIn the first test case, you can, for example, put one extra block into the first box and make $$$a = [4, 2, 2]$$$. If your nephew chooses the box with $$$4$$$ blocks, then we will move two blocks to the second box and two blocks to the third box. If he chooses the box with $$$2$$$ blocks then he will move these two blocks to the other box with $$$2$$$ blocks.In the second test case, you don't need to put any extra blocks, since no matter which box your nephew chooses, he can always make other boxes equal.In the third test case, you should put $$$3$$$ extra blocks. For example, you can put $$$2$$$ blocks in the first box and $$$1$$$ block in the third box. You'll get array $$$a = [2, 3, 1]$$$. | PASSED | 1,400 | standard input | 2 seconds | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of boxes. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the number of blocks in each box. It's guaranteed that the sum of $$$n$$$ over test cases doesn't exceed $$$10^5$$$. | ["1\n0\n3"] | #include<stdio.h>
#include<string.h>
//#include<stack>
//#include<queue>
//#include<algorithm>
//using namespace std;
long long i,t,n,flag,x,y,sum=0,ans=0,a[200100],min,max;
//char a;
//priority_queue<long long,vector<long long>,greater<long long> >s;
int main(){
scanf("%lld",&t);
while(t--){
scanf("%lld",&n);
for(i=0,min=0;i<n;i++){
scanf("%lld",&a[i]);
if(a[min]>a[i])min=i;
if(i==0)max=a[i];
else if(max<a[i])max=a[i];
}
for(i=0,sum=0;i<n;i++){
if(i!=min){
sum+=max-a[i];
}
}
if(a[min]<=sum)ans=sum-a[min];
else {
if((a[min]-sum)%(n-1)==0)ans=0;
else{
ans=(a[min]-sum)%(n-1);
ans=n-1-ans;
}
}
printf("%lld\n",ans);
}
}
| |
You are asked to watch your nephew who likes to play with toy blocks in a strange way.He has $$$n$$$ boxes and the $$$i$$$-th box has $$$a_i$$$ blocks. His game consists of two steps: he chooses an arbitrary box $$$i$$$; he tries to move all blocks from the $$$i$$$-th box to other boxes. If he can make the same number of blocks in each of $$$n - 1$$$ other boxes then he will be happy, otherwise, will be sad. Note that your nephew can only move the blocks from the chosen box to the other boxes; he cannot move blocks from the other boxes.You don't want to make your nephew sad, so you decided to put several extra blocks into some boxes in such a way that no matter which box $$$i$$$ he chooses he won't be sad. What is the minimum number of extra blocks you need to put? | For each test case, print a single integer — the minimum number of blocks you need to put. It can be proved that the answer always exists, i. e. the number of blocks is finite. | C | e75b88ce4341062c20b6014da1152d29 | becea0ba6d248981b5437ae4e6860fc6 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"binary search",
"sortings",
"greedy",
"math"
] | 1605796500 | ["3\n3\n3 2 2\n4\n2 2 3 2\n3\n0 3 0"] | NoteIn the first test case, you can, for example, put one extra block into the first box and make $$$a = [4, 2, 2]$$$. If your nephew chooses the box with $$$4$$$ blocks, then we will move two blocks to the second box and two blocks to the third box. If he chooses the box with $$$2$$$ blocks then he will move these two blocks to the other box with $$$2$$$ blocks.In the second test case, you don't need to put any extra blocks, since no matter which box your nephew chooses, he can always make other boxes equal.In the third test case, you should put $$$3$$$ extra blocks. For example, you can put $$$2$$$ blocks in the first box and $$$1$$$ block in the third box. You'll get array $$$a = [2, 3, 1]$$$. | PASSED | 1,400 | standard input | 2 seconds | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of boxes. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the number of blocks in each box. It's guaranteed that the sum of $$$n$$$ over test cases doesn't exceed $$$10^5$$$. | ["1\n0\n3"] | #include <stdio.h>
#include <stdlib.h>
int mod(int a)
{
if(a<0)
return(-a);
else
return(a);
}
int main()
{
int t;scanf("%d",&t);
while(t--)
{
int n;scanf("%d",&n);long long int k,z,sum=0,max=0, a[n],j;for(j=0;j<n;j++)scanf("%lld",(a+j));k=n;
for(j=0;j<n;j++)
{
sum+=a[j];
if(a[j]>max)max=a[j];
}
z=(max)*(k-1);
if(z>=sum)
{
printf("%lld\n",z-sum);continue;
}
else
{
if(sum%(k-1)==0)
printf("0\n");
else
printf("%lld\n",(((sum/(k-1))+1)*(k-1))-sum);
}
}
return 0;
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | 013539354c709743dc964a53c5361930 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
int a,b,k,temp;
scanf("%d %d",&a,&b);
if(a>b){temp=a;a=b;b=temp;}
k=b-a;
if(k>0)
{
int f,t,o;
f=k/5;
t=(k%5)/2;
o=((k%5)%2)/1;
printf("%d\n",f+t+o);
}
else if(k==0)
{
printf("0\n");
}
}
return 0;
} | |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | 71d125413077a319f502b20638e245c4 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include <stdio.h>
#include <stdlib.h>
int vol(){
int a,b,s=0;
scanf("%d %d",&a,&b);
if(a<b){
if((b-a)>=5)
s=(b-a)/5;
if((b-a)%5==4 || (b-a)%5==3)
s+=2;
else if((b-a)%5==2 || (b-a)%5==1)
s++;
}
else if(a>b){
if((a-b)>=5)
s=(a-b)/5;
if((a-b)%5==4 || (a-b)%5==3)
s+=2;
else if((a-b)%5==2 || (a-b)%5==1)
s++;
}
return s;
}
int main()
{
int t;
scanf("%d",&t);
for(int i=0;i<t;i++){
printf("%d\n",vol());
}
return 0;
} | |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | 9551fb170f517b4669c497c54d44d4de | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include <stdio.h>
long long int abs(long long int a)
{
if(a<0) return -a;
return a;
}
int m(int a,int b)
{
if(a>b) return b;
return a;
}
int main()
{
int but[6]={-5,-2,-1,1,2,5};
int cmd;
long long int a,b,goal,init=0,ways[6]={0,1,1,2,2,1};
scanf("%d",&cmd);
for(int i=0;i<cmd;i++)
{
scanf("%lld%lld",&a,&b);
init=0;
goal=abs(b-a);
init=m(goal/5+ways[(goal%5)],goal/5+1+ways[5-goal%5]);
printf("%d\n",init);
}
return 0;
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | 16d974830e2d4dab69d6993f456a0f9b | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include <stdio.h>
#include <math.h>
void fungsi(int d)
{
int sum=0;
if(d>=5)
{
sum += d/5;
d=d-((d/5)*5);
}
if(d>=2)
{
sum += d/2;
d=d-((d/2)*2);
}
if(d>=1)
{
sum += d;
}
printf("%d\n", sum);
}
int main (void)
{
int i,j,k,l;
int z;
scanf("%d", &k);
while(k--)
{
scanf("%d %d",&i,&j);
z= abs(j-i);
fungsi(z);
}
return 0;
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | bb3bcc54de699c79ea1284db40d932ba | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
int main()
{
int a,b,n,c,d,e,f,x,y,t;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d %d",&a,&b);
if(a>b)
{
t=a-b;
if(t>=5)
{
x=t/5;
y=t%5;
if(y>=2)
{
c=y/2;
d=y%2;
printf("%d\n",x+c+d);
}
if(y<2)
printf("%d\n",x+y);
}
if(2<=t&&t<5)
{
e=t/2;
f=t%2;
printf("%d\n",e+f);
}
if(t<2)
printf("1\n");
}
if(a<b)
{
t=b-a;
if(t>=5)
{
x=t/5;
y=t%5;
if(y>=2)
{
c=y/2;
d=y%2;
printf("%d\n",x+c+d);
}
if(y<2)
printf("%d\n",x+y);
}
if(2<=t&&t<5)
{
e=t/2;
f=t%2;
printf("%d\n",e+f);
}
if(t<2)
printf("1\n");
}
if(a==b)
printf("0\n");
}
return 0;
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | 76d69df16741a79d78ad5890ad2add44 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
#include<math.h>
int main()
{
long long int t,a,b,d,count;
scanf("%lld",&t);
while(t--)
{
d=0,count=0;
scanf("%lld%lld",&a,&b);
if(a>b)
d=a-b;
else if(a<b)
d=b-a;
else
{
printf("%d\n",count);
continue;
}
if(d>=5)
{
count+=d/5;
d%=5;
if(d==0)
{
printf("%d\n",count);
continue;
}
}
if(d>=2)
{
count+=d/2;
d%=2;
if(d==0)
{
printf("%d\n",count);
continue;
}
}
if(d>=1)
{
count+=d/1;
d%=1;
if(d==0)
{
printf("%d\n",count);
continue;
}
}
}
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | 79fffce5db3312d61bc218c5047345e8 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
int main ()
{
int t;
scanf("%d",&t);
while(t--)
{
long int a,b,c,d,e,x;
long long m=10000000000000;
scanf("%ld %ld",&a,&b);
if(a==b)
printf("0\n");
else
{
c=b-a;
x=abs(c);
if(x==1)
{
printf("1\n");
goto o;
}
if(x%2==0)
{
m=x/2;
}
d=x/5;
e=x%5;
if(e==0)
printf("%ld\n",d);
else
{
if(e==1 && (d+1)<m)
printf("%ld\n",d+1);
else if(e==2 && (d+1)<m)
printf("%ld\n",d+1);
else if(e==3 && (d+2)<m)
printf("%ld\n",d+2);
else if(e==4 &&(d+2)<m)
printf("%ld\n",d+2);
else printf("%lld\n",m);
}
}
o : 1;
}
return 0;
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | c7a20c996d04d6c04ed0467348856cdf | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include <stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int a,b,x=0;
scanf("%d%d",&a,&b);
if(a>=b)
{
while(a!=b)
{
if(a-b>=5)
{
x+=(a-b)/5;
a-=((a-b)/5)*5;
}
else if(a-b>=2)
{
x+=(a-b)/2;
a-=((a-b)/2)*2;
}
else if(a-b>=1)
{
x++;
a-=1;
}
}
}
else
{
while(a!=b)
{
if(b-a>=5)
{
x+=(b-a)/5;
a+=((b-a)/5)*5;
}
else if(b-a>=2)
{
x+=(b-a)/2;
a+=((b-a)/2)*2;
}
else if(b-a>=1)
{
x++;
a+=1;
}
}
}
printf("%d\n",x);
}
return 0;
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | fd035a911d097323495987ca57d20822 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b,c,d,e,n,sum;
scanf("%d",&n);
for(c=0;c<n;c++)
{
sum=0;
scanf("%d%d",&a,&b);
d=abs(a-b);
for(;d>0;)
{
if(d>4)
{
e=d/5;
d=d%5;
sum+=e;
}
else if(d>2)
{d=0;
sum+=2;}
else {d=0;
sum++;}
}
printf("%d\n",sum);
}
} | |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | 0838a5fd9d42c08f0caeb72ca18cc102 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
int main()
{
int t;
int a,b,c=0,i;
scanf("%d",&t);
for(i=0;i<t;i++){
scanf("%d%d",&a,&b);
if(a<b){
a=a+b;
b=a-b;
a=a-b;
}
c=(a-b)/5+(a-b)%5/2+(a-b)%5%2;
printf("%d\n",c);
}
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | ea82e38e953feb3f992c37698ec691c6 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
int main()
{
int tc;
scanf("%d",&tc);
while(tc--)
{
int a,b,subs,sum1=0,sum2=0,sum3=0,sum=0;
scanf("%d %d",&a,&b);
subs=a-b;
if(subs<0)
{
subs=subs*(-1);
}
if(subs>=5)
{
sum1=subs/5;
subs=subs%5;
if(subs<5 && subs>1)
{
if(subs==4 || subs==3)
{
sum2=2;
}
else if(subs==2)
{
sum2=1;
}
}
else if(subs==1)
{
sum3=1;
}
else if(subs=0)
{
sum1=0;
sum2=0;
sum3=0;
}
}
else if(subs<5 && subs>1)
{
if(subs==4 || subs==3)
{
sum2=2;
}
else if(subs==2)
{
sum2=1;
}
}
else if(subs==1)
{
sum3=1;
}
else if(subs==0)
{
sum1=0;
sum2=0;
sum3=0;
}
sum=sum1+sum2+sum3;
printf("%d\n",sum);
}
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | 7978ab43880cd6070af27c78ee8d2d51 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
#include<math.h>
int main()
{
long long int a,b,n,c,t,i;
scanf("%lld",&t);
for(i=1;i<=t;i++)
{
c=0;
scanf("%lld %lld",&a,&b);
n=fabs(a-b);
c=c+n/5;
n=n%5;
c=c+n/2;
n=n%2;
if(n==1)
{
c=c+1;
}
printf("%lld\n",c);
}
return 0;
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | 2522cf7d2023445a9e2b6d2bd1a7d7bd | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b,c,d,i,j,sum=0,r,x=0;
scanf("%d",&a);
while(a--)
{ sum=0;
scanf("%d %d",&b,&c);
j=abs(b-c);
if(j==5 || j==2 || j==1)
{
printf("1\n");
}
else if(j>5)
{
sum=sum+(j/5);
r=j%5;
if(r>0)
{ if(r&1)
{ sum=sum+(r/2)+1;
}
else
sum=sum+(r/2);
}
printf("%d\n",sum);
}
else
{
if(j%2==1)
{
sum=sum+(j/2)+1;
printf("%d\n",sum);
}
else
printf("%d\n",(j/2));
}
}
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | 5ab707c9a6e15053091a05de38940caa | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] |
#include <stdio.h>
int main()
{
int n, a,b,d,k,r,i;
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d %d",&a, &b);
if(a<b)d=b-a; else d=a-b;
k=d /5;
r=d%5;
if(r==1) k++;
if(r==2) k++;
if(r==3) k=k+2;
if(r==4) k=k+2;
printf("%d\n",k);
}
return 0;
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | c6ffbcc01d3e5af912aaf6b37056fc15 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int a, b, ans=0, count=0,n;
scanf("%d %d", &a, &b);
ans= abs(b-a);
while(ans!=0)
{
if(ans>=5){n=(int)ans/5; ans-=n*5; count+=n;}
else if(ans>=2){n=(int) ans/2; ans-=n*2; count+=n;}
else if(ans>=1){n= (int)ans/1; ans-=n*1; count+=n;}
}
printf("%d\n", count);
}
return 0;
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | 0611e52f27352ec76ce56e9744b28ebb | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
#include <stdlib.h>
int main(){
int t;
scanf("%d", &t);
while (t--) {
int a, b, d;
scanf("%d%d", &a, &b), d = abs(a - b);
printf("%d\n", d / 5 + (d % 5 + 1) / 2);
}
return 0;
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | 4c8853ac4a504eb45227c89e97dcccae | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
int main()
{
int cases,j,i,dif,rem,n,step=0;
scanf("%d",&cases);
int a[cases];
int b[cases];
for(j=0;j<cases;j++)
{
scanf("%d %d",&a[j],&b[j]);
}
for(i=0;i<cases;i++)
{
if(b[i]>a[i])
{
dif=b[i]-a[i];
}
else if(a[i]>b[i])
{
dif=a[i]-b[i];
}
else if(a[i]==b[i])
{
dif=0;
step=0;
}
if(dif>=5)
{
n=dif/5;
rem=dif%5;
dif=rem;
step=step+n;
rem=0;
n=0;
}
if(dif<5 && dif>=2)
{
n=dif/2;
rem=dif%2;
dif=rem;
step=step+n;
rem=0;
n=0;
}
if(dif==1)
{
step=step+1;
rem=0;
n=0;
}
printf("%d\n",step);
step=0;
}
return 0;
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | bfaa8219dc2ac119e03a271e3912aaaf | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
int main()
{
int t,a,b,count,z;
scanf(" %d", &z);
while(z--){
scanf(" %d %d", &a, &b);
count=0;
if(a!=b){
t=abs(b-a);
while(t){
if(t>=5){
count+=t/5;
t=t%5;
}
else if(t>=2){
count+=t/2;
t=t%2;
}
else{
count++;
t--;
}
}
}
printf("%d\n",count);
}
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | 1c9ded20c2587501bfb4b4c442f32851 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include <stdio.h>
long long a ,b ,t ,rsp ,i , n;
int main()
{
rsp = 0;
scanf("%lld", &n);
for(i = 1; i <= n; ++i)
{
scanf("%lld %lld", &a ,&b);
if(a < b)
{
a += b;
b = a - b;
a = a - b;
}
rsp = (a - b) / 5;
t = (a - b) % 5;
if(t == 1 || t ==2) rsp = rsp + 1;
else if(t == 3 || t == 4)
rsp += 2;
printf("%ld\n", rsp);
}
return 0;
} | |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | b314a8b4e87e889411058bc64251f2ec | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include <stdio.h>
long a ,b ,t ,rsp ,i , n;
int main()
{
rsp = 0;
scanf("%ld", &n);
for(i = 1; i <= n; ++i)
{
scanf("%ld %ld", &a ,&b);
if(a < b)
{
a += b;
b = a - b;
a = a - b;
}
rsp = (a - b) / 5;
t = (a - b) % 5;
if(t == 1 || t ==2) rsp = rsp + 1;
else if(t == 3 || t == 4)
rsp += 2;
printf("%ld\n", rsp);
}
return 0;
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | 976364eb6e0f11c60ff09aa6c27e4161 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
int main()
{
unsigned long long int t,a,b,c=0;
scanf("%llu",&t);
while(t--){
scanf("%llu %llu",&a,&b);
if(a>b){
while(1){
if(a==b) break;
else if((a-b)>=100000000){a=a-100000000;
c=c+20000000;
continue;}
else if((a-b)>=1000000&&(a-b)<100000000){a=a-1000000;
c=c+200000;
continue;}
else if((a-b)>=10000&&(a-b)<1000000) {a=a-10000;
c=c+2000;
continue;}
else if((a-b)>=100&&(a-b)<10000) {a=a-100;
c=c+20;
continue;}
else if((a-b)>=5&&(a-b)<100) {a=a-5;
c++;
continue;}
else if((a-b)>=2&&(a-b)<5) {a=a-2;
c++;
continue;}
else if((a-b)==1) {a=a-1;
c++;
continue;}
}
}
else {
while(1){
if(a==b) break;
else if((b-a)>=100000000){a=a+100000000;
c=c+20000000;
continue;}
else if((b-a)>=1000000&&(b-a)<100000000){a=a+1000000;
c=c+200000;
continue;}
else if((b-a)>=10000&&(b-a)<1000000) {a=a+10000;
c=c+2000;
continue;}
else if((b-a)>=100&&(b-a)<10000) {a=a+100;
c=c+20;
continue;}
else if((b-a)>=5&&(b-a)<100) {a=a+5;
c++;
continue;}
else if((b-a)>=2&&(b-a)<5) {a=a+2;
c++;
continue;}
else if((b-a)==1) {a=a+1;
c++;
continue;}
}
}
printf("%llu\n",c);
c=0;
}
return 0;
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | 9411794309faf4e1c6a44c7443ded68b | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
#include<math.h>
int main()
{
int t,i,count,x,p,q;
scanf("%d",&t);
int a[t];
for(i=0; i<t; i++)
{
scanf("%d %d",&p,&q);
a[i]=abs(p-q);
}
for(i=0; i<t; i++)
{
x=0;
if(a[i]>0)
{
x=x+a[i]/5;
a[i]=a[i]%5;
x=x+a[i]/2;
a[i]=a[i]%2;
x=x+a[i];
}
else
x=0;
printf("%d\n",x);
}
return 0;
} | |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | efd5822e36649c8d329ec039f793a53a | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
int main()
{
int t,c,d,min,i,a;
scanf("%d",&t);
for(i=1; i<=t; i++)
{
scanf("%d%d",&c,&d);
if(c>d)
a=c-d;
else
a=d-c;
if(a>=5)
{
min=a/5;
a=a%5;
if(a==4 || a==3)
min=min+2;
else if(a==1 || a==2)
min=min+1;
}
else if(a==4 || a==3)
min=2;
else if(a==1 || a==2)
min=1;
else
min=0;
printf("%d\n",min);
}
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | 3be652f8f8bf92f2b97b389e06831959 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
int main()
{
int a,b,c,n,i,x,y;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
int count1=0,count2=0,count3=0;
scanf("%d %d",&a,&b);
c = abs(a-b);
x=c%5;
count1=(c-x)/5;
if(x!=0)
{
y=x%2;
count2=(x-y)/2;
if(y!=0)
count3=y;
}
printf("%d\n",count1+count2+count3);
}
return 0;
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | b9631e206c67cfa95a7f1dddeff19704 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
int main()
{
int t_case, a, b, count;
scanf("%d", &t_case);
while(t_case--){
count=0;
scanf("%d %d", &a, &b);
if(a > b){
a=a+b;
b= a-b;
a= a-b;
}
b=b-a;
a=0;
while(1){
if(a==b)
break;
if(b>=5){
count += b/5;
b = b%5;
}
if(b>=2){///4
count += b/2;///count=2;
b = b%2;
if(b==1){
count++;
b=0;
}
}
if(b>=1){
count += b/1;
b=b%1;
}
if(b==0)
break;
}
printf("%d\n", count);
}
return 0;
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | ffe9296566702527e492a698962efd8f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
int main(){
int t;
long long int a,b,x,n,y,i,s,p,q;
scanf("%d",&t);
for(i=1;i<=t;i++){
s=0;
scanf("%lli%lli",&a,&b);
if(a==b){
printf("0\n");
}
else {
if(a<b){
x=a;
a=b;
b=x;
}
n=a-b;
p=n%5;
q=p%2;
s=(n/5)+(p/2)+(q/1);
printf("%lli\n",s);
}
}
return 0;
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | 4f98f88f6de0b5daf3113b8a8449388f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
unsigned int t;scanf("%d",&t);
while(t--)
{
unsigned int b,a,cnt=0;
scanf("%d%d",&b,&a);
if(abs(a-b)>=5)cnt+=abs(a-b)/5;
if(b<a)b=a-abs(a-b)%5;
else b=a+abs(a-b)%5;
if(abs(a-b)==1||abs(a-b)==2)
{
cnt++;
printf("%d\n",cnt);
}
else if(a==b)
{
printf("%d\n",cnt);
}
else
{
cnt+=2;
printf("%d\n",cnt);
}
}
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | f6d57161d08e9088f341fbd1c1abdd11 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include <stdio.h>
int a, nr = 0, b, t, d, i, r;
int main()
{
scanf("%d", &d);
for(i = 1; i <= d; i++)
{
scanf("%d %d", &a, &b);
if(a < b) {r = a ; a = b; b = r;}
t = a - b;
nr = t / 5;
r= t % 5;
if (r > 2) nr = nr + 2;
else if(r == 2 || r == 1)
nr++;
printf("%d\n", nr);
}
}
| |
Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. | For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$. | C | ccfe798f5dc63c492ff54cf40bb40613 | e7019543ab4e672218feacb70145d342 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1574174100 | ["3\n4 0\n5 14\n3 9"] | NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$. | PASSED | 800 | standard input | 1 second | Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively. | ["2\n3\n2"] | #include <stdio.h>
int a, nr = 0, b, t, d, i, r;
int main()
{
scanf("%d", &d);
for(i = 1; i <= d; i++)
{
scanf("%d %d", &a, &b);
if(a < b) {r = a ; a = b; b = r;}
t = a - b;
nr = t / 5;
r= t % 5;
if (r > 2) nr = nr + 2;
else if(r == 2 || r == 1)
nr++;
printf("%d\n", nr);
}
} | |
In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. | Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. | C | fbfc333ad4b0a750f654a00be84aea67 | d8b00c0801fec82aa8335b91f93bc922 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1448382900 | ["4 2\n1 3\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2"] | NoteIn the first sample, the train can take the route and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. | PASSED | 1,600 | standard input | 2 seconds | The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one railway connecting any two towns. | ["2", "-1", "3"] | #include<stdio.h>
typedef unsigned u;
u A[444][444],B[444][444],(*C)[444],D[444],V[444];
int main()
{
u i,j,k,n,q;
scanf("%u%u",&n,&q);
for(i=0;++i<=n;D[i]=-1)for(j=0;++j<=n;)A[i][j]=1;
while(q--)
{
scanf("%u%u",&i,&j);
A[i][j]=A[j][i]=0;
B[i][j]=B[j][i]=1;
}
if(A[1][n])C=B;
if(B[1][n])C=A;
D[1]=0;
while(1)
{
for(i=0,j=k=-1;++i<=n;)if(!V[i]&&D[i]<j)j=D[k=i];
if(k==-1u)break;
V[k]=1;
for(i=0;++i<=n;)if(!V[i]&&C[k][i]&&D[i]>D[k]+1)D[i]=D[k]+1;
}
printf("%i\n",D[n]);
return 0;
}
| |
In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. | Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. | C | fbfc333ad4b0a750f654a00be84aea67 | a25c3980cbb36cbb3e6dc2fbf8143f6c | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1448382900 | ["4 2\n1 3\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2"] | NoteIn the first sample, the train can take the route and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. | PASSED | 1,600 | standard input | 2 seconds | The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one railway connecting any two towns. | ["2", "-1", "3"] | #include <stdio.h>
#define INF 1000000000
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) > (b)) ? (a) : (b))
int adj1[400][400], adj2[400][400];
int main(void) {
int i, j, k;
int n, m;
int max;
scanf("%d %d", &n, &m);
for (i = 0; i < n; i++)
for (j = 0; j < n; j++) {
adj1[i][j] = i == j ? 0 : INF;
adj2[i][j] = i == j ? 0 : 1;
}
for (i = 0; i < m; i++) {
int u, v;
scanf("%d %d", &u, &v);
u--;
v--;
adj1[u][v] = adj1[v][u] = 1;
adj2[u][v] = adj2[v][u] = INF;
}
for (k = 0; k < n; k++)
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
adj1[i][j] = min(adj1[i][j], adj1[i][k] + adj1[k][j]);
for (k = 0; k < n; k++)
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
adj2[i][j] = min(adj2[i][j], adj2[i][k] + adj2[k][j]);
max = max(adj1[0][n - 1], adj2[0][n - 1]);
printf("%d\n", max == INF ? -1 : max);
return 0;
}
| |
In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. | Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. | C | fbfc333ad4b0a750f654a00be84aea67 | d963461959596d85c16720fdc8190d5a | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1448382900 | ["4 2\n1 3\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2"] | NoteIn the first sample, the train can take the route and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. | PASSED | 1,600 | standard input | 2 seconds | The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one railway connecting any two towns. | ["2", "-1", "3"] | #include <stdio.h>
#include <stdlib.h>
int n,a[401][401];
int bfs(int gt)
{
int q[401][2],d,c,fr[401],i,j;
for (i=1;i<=n;i++) fr[i]=1;
fr[1]=0;
d=0;
c=1;
q[c][0]=1;
q[c][1]=0;
do
{
d++;
if (d>c) break;
for (j=1;j<=n;j++)
if (a[q[d][0]][j]==gt && fr[j]==1)
{
fr[j]=0;
q[++c][0]=j;
q[c][1]=q[d][1]+1;
if (j==n) return q[c][1];
}
} while (d<=c);
return -1;
}
int main()
{
int i,j,cp1,cp2,m,u,v;
scanf("%d%d",&n,&m);
for (i=1;i<=n;i++)
for (j=1;j<=n;j++) a[i][j]=0;
for (i=1;i<=m;i++)
{
scanf("%d%d",&u,&v);
a[u][v]=1;
a[v][u]=1;
}
cp1=bfs(1);
cp2=bfs(0);
if (cp1==-1 || cp2==-1) printf("-1");
else printf("%d",cp1>cp2?cp1:cp2);
return 0;
}
| |
In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. | Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. | C | fbfc333ad4b0a750f654a00be84aea67 | 871c22284323c50f94570778ca71494e | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1448382900 | ["4 2\n1 3\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2"] | NoteIn the first sample, the train can take the route and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. | PASSED | 1,600 | standard input | 2 seconds | The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one railway connecting any two towns. | ["2", "-1", "3"] | #include <stdio.h>
#include <stdlib.h>
#define MAXN 400
int drum[MAXN+1][MAXN+1],cod[MAXN],lung[2][MAXN+1];
int BFS(int nod,int tip,int n){
int i,b,e;
cod[0]=nod;
lung[tip][nod]=1;
b=0;
e=1;
do{
for(i=1;i<=n;i++)
if(lung[tip][i]==0&&drum[i][cod[b]]==tip){
cod[e]=i;
e++;
lung[tip][i]=lung[tip][cod[b]]+1;
}
b++;
}while(b<e);
return lung[tip][n];
}
int main(){
// FILE*fi,*fout;
int x,y,i,n,m,max;
// fi=fopen("C.in" ,"r");
// fout=fopen("C.out" ,"w");
scanf("%d%d" ,&n,&m);
for(i=0;i<m;i++){
scanf("%d%d" ,&x,&y);
drum[x][y]=drum[y][x]=1;
}
if(BFS(1,0,n)==0||BFS(1,1,n)==0)
printf("-1");
else{
int max1,max2;
max1=BFS(1,0,n);
max2=BFS(1,1,n);
if(max1>max2)
max=max1;
else
max=max2;
printf("%d" ,max-1);
}
// fclose(fi);
// fclose(fout);
return 0;
}
| |
In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. | Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. | C | fbfc333ad4b0a750f654a00be84aea67 | 8c742e7cac1e1e3bfd95369e3dc5b47e | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1448382900 | ["4 2\n1 3\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2"] | NoteIn the first sample, the train can take the route and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. | PASSED | 1,600 | standard input | 2 seconds | The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one railway connecting any two towns. | ["2", "-1", "3"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<time.h>
#include<ctype.h>
#include<limits.h>
#define eps 1e-7
#define MOD 1000000007
#define ll long long int
#define N 450000
int que[N];
int has[1000][1000];
int dist[N];
int visited[N];
int rear=-1;
int front=-1;
struct graph{
int v;
struct graph *next;
}*arr[N],*remem[N],*arr1[N],*remem1[N];
void insert_que(int x){
que[++rear]=x;
if(rear==0)
front=0;
}
int pop_que(){
return que[front++];
}
int is_empty(){
return front>rear?1:0;
}
void ins(int x,int x1,int key){
struct graph *temp=(struct graph*)malloc(sizeof(struct graph));
temp->v=x1;
temp->next=NULL;
if(!arr[x] && key){
arr[x]=temp;
remem[x]=temp;
return;
}
else if(!arr1[x] && !key){
arr1[x]=temp;
remem1[x]=temp;
return;
}
if(key){
remem[x]->next=temp;
remem[x]=temp;
}
else{
remem1[x]->next=temp;
remem1[x]=temp;
}
}
int solve(int x,int n){
insert_que(x);
dist[x]=0;
visited[x]=1;
while(!is_empty()){
int get=pop_que();
struct graph *sweep=arr[get];
while(sweep){
if(!visited[sweep->v]){
visited[sweep->v]=1;
insert_que(sweep->v);
dist[sweep->v]=dist[get]+1;
}
sweep=sweep->next;
}
}
if(dist[n]==0){
return -1;
}
else
return dist[n];
}
int solve1(int x,int n){
insert_que(x);
dist[x]=0;
visited[x]=1;
while(!is_empty()){
int get=pop_que();
visited[get]=1;
struct graph *sweep=arr1[get];
while(sweep){
if(!visited[sweep->v]){
visited[sweep->v]=1;
insert_que(sweep->v);
dist[sweep->v]=dist[get]+1;
}
sweep=sweep->next;
}
}
if(dist[n]==0){
return -1;
}
else
return dist[n];
}
int max(int a,int b){
return a>b?a:b;
}
int main(){
int a,b,c,d;
scanf("%d%d",&a,&b);
int flag=2;
for(int i=0;i<b;i++){
int foo[2];
scanf("%d%d",foo,foo+1);
has[foo[0]][foo[1]]=1;
has[foo[1]][foo[0]]=1;
if(foo[0]==a ||foo[1]==a)
flag=1;
ins(foo[0],foo[1],1);
ins(foo[1],foo[0],1);
}
for(int i=1;i<=a;i++){
for(int w=i;w<=a;w++){
if(i!=w){
if(!has[i][w]){
ins(i,w,0);
ins(w,i,0);
}
}
}
}
int x=solve1(1,a);
memset(visited,0,sizeof(visited));
memset(dist,0,sizeof(visited));
memset(que,0,sizeof(que));
rear=front=-1;
int x1=solve(1,a);
if(x==-1 || x1==-1){
printf("-1");
return 0;
}
printf("%d",max(x,x1));
} | |
In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. | Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. | C | fbfc333ad4b0a750f654a00be84aea67 | 347480d0f2263c5cb20af9f8a036ee59 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1448382900 | ["4 2\n1 3\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2"] | NoteIn the first sample, the train can take the route and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. | PASSED | 1,600 | standard input | 2 seconds | The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one railway connecting any two towns. | ["2", "-1", "3"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<time.h>
#include<ctype.h>
#include<limits.h>
#define eps 1e-7
#define MOD 1000000007
#define ll long long int
#define N 450000
int que[N];
int graph[1000][1000];
int new_graph[1000][1000];
int dist[N];
int visited[N];
int rear=-1;
int front=-1;
void insert_que(int x){
que[++rear]=x;
if(rear==0)
front=0;
}
int pop_que(){
return que[front++];
}
int is_empty(){
return front>rear?1:0;
}
int solve(int x,int n){
insert_que(x);
visited[x]=1;
while(!is_empty()){
int get=pop_que();
for(int i=1;i<=n;i++){
if(!visited[i] && new_graph[get][i]){
visited[i]=1;
dist[i]=dist[get]+1;
insert_que(i);
}
}
}
return dist[n]==0?-1:dist[n];
}
int solve1(int x,int n){
insert_que(x);
visited[x]=1;
while(!is_empty()){
int get=pop_que();
for(int i=1;i<=n;i++){
if(!visited[i] && graph[get][i]){
visited[i]=1;
dist[i]=dist[get]+1;
insert_que(i);
}
}
}
return dist[n]==0?-1:dist[n];
}
int main(){
int a,b,c,d;
scanf("%d%d",&a,&b);
int flag=2;
for(int i=0;i<b;i++){
int foo[2];
scanf("%d%d",foo,foo+1);
graph[foo[0]][foo[1]]=1;
graph[foo[1]][foo[0]]=1;
}
for(int i=1;i<=a;i++){
for(int w=1;w<=a;w++){
if(i!=w){
if(!graph[i][w]){
new_graph[i][w]=1;
}
}
}
}
int x=solve(1,a);
memset(visited,0,sizeof(visited));
memset(que,0,sizeof(que));
front=rear=-1;
memset(dist,0,sizeof(dist));
int x1=solve1(1,a);
if(x==-1 || x1==-1){
printf("-1");
return 0;
}
x>x1?printf("%d",x):printf("%d",x1);
} | |
In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. | Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. | C | fbfc333ad4b0a750f654a00be84aea67 | e587766909684f89d2010a19f0e2a2d6 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1448382900 | ["4 2\n1 3\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2"] | NoteIn the first sample, the train can take the route and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. | PASSED | 1,600 | standard input | 2 seconds | The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one railway connecting any two towns. | ["2", "-1", "3"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<time.h>
#include<ctype.h>
#include<limits.h>
#define eps 1e-7
#define MOD 1000000007
#define ll long long int
#define N 450000
int que[N];
int has[1000][1000];
int dist[N];
int visited[N];
int rear=-1;
int front=-1;
struct graph{
int v;
struct graph *next;
}*arr[N],*remem[N],*arr1[N],*remem1[N];
void insert_que(int x){
que[++rear]=x;
if(rear==0)
front=0;
}
int pop_que(){
return que[front++];
}
int is_empty(){
return front>rear?1:0;
}
void ins(int x,int x1,int key){
struct graph *temp=(struct graph*)malloc(sizeof(struct graph));
temp->v=x1;
temp->next=NULL;
if(!arr[x] && key){
arr[x]=temp;
remem[x]=temp;
return;
}
else if(!arr1[x] && !key){
arr1[x]=temp;
remem1[x]=temp;
return;
}
if(key){
remem[x]->next=temp;
remem[x]=temp;
}
else{
remem1[x]->next=temp;
remem1[x]=temp;
}
}
int solve(int x,int n,int key){
insert_que(x);
dist[x]=0;
visited[x]=1;
while(!is_empty()){
int get=pop_que();
struct graph *sweep;
if(key)
sweep=arr[get];
else sweep=arr1[get];
while(sweep){
if(!visited[sweep->v]){
visited[sweep->v]=1;
insert_que(sweep->v);
dist[sweep->v]=dist[get]+1;
}
sweep=sweep->next;
}
}
if(dist[n]==0){
return -1;
}
else
return dist[n];
}
int max(int a,int b){
return a>b?a:b;
}
int main(){
int a,b,c,d;
scanf("%d%d",&a,&b);
int flag=2;
for(int i=0;i<b;i++){
int foo[2];
scanf("%d%d",foo,foo+1);
has[foo[0]][foo[1]]=1;
has[foo[1]][foo[0]]=1;
if(foo[0]==a ||foo[1]==a)
flag=1;
ins(foo[0],foo[1],1);
ins(foo[1],foo[0],1);
}
for(int w=1;w<=a;w++){
for(int i=1;i<=a;i++){
if(w!=i && !has[w][i])
ins(i,w,0);
}
}
int x=solve(1,a,1);
memset(visited,0,sizeof(visited));
memset(dist,0,sizeof(visited));
memset(que,0,sizeof(que));
rear=front=-1;
int x1=solve(1,a,0);
if(x==-1 || x1==-1){
printf("-1");
return 0;
}
printf("%d",max(x,x1));
}
| |
In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. | Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. | C | fbfc333ad4b0a750f654a00be84aea67 | 20934bf1e8fda7feef6b17b304f883bf | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1448382900 | ["4 2\n1 3\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2"] | NoteIn the first sample, the train can take the route and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. | PASSED | 1,600 | standard input | 2 seconds | The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one railway connecting any two towns. | ["2", "-1", "3"] | #include <stdio.h>
#include <stdlib.h>
main()
{
int n,m,i,j,u,v,x,y,z,test;
int M[400],N[400];
int T[400][400];
scanf("%d%d",&n,&m);
for (i=0;i<n;i++) for (j=0;j<n;j++) T[i][j] = 0;
for (i=0;i<m;i++)
{
scanf("%d%d",&u,&v);
T[u-1][v-1] = 1;
T[v-1][u-1] = 1;
}
x = 0;
for (i=0;i<n;i++)
{
M[i] = n;
N[i] = 0;
}
M[0] = 0;
N[0] = 1;
test = 0;
i = 0;
while ((N[n-1]==0) && (test==0))
{
for (j=0;j<n;j++) if ((T[i][j]!=0) && (N[j]==0)) if (M[i]+1<M[j]) M[j] = M[i] + 1;
y = n;
i = 0;
for (j=0;j<n;j++)
{
if (N[j]==0 && M[j]<y)
{
y = M[j];
i = j;
}
}
N[i] = 1;
if (i==0) test = 1;
}
x = M[n-1];
if (test==1) printf("-1");
else
{
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
{
if (i!=j) T[i][j] = 1 - T[i][j];
}
}
z = 0;
for (i=0;i<n;i++)
{
M[i] = n;
N[i] = 0;
}
M[0] = 0;
N[0] = 1;
test = 0;
i = 0;
while ((N[n-1]==0) && (test==0))
{
for (j=0;j<n;j++) if ((T[i][j]!=0) && (N[j]==0)) if (M[i]+1<M[j]) M[j] = M[i] + 1;
y = n;
i = 0;
for (j=0;j<n;j++)
{
if (N[j]==0 && M[j]<y)
{
y = M[j];
i = j;
}
}
N[i] = 1;
if (i==0) test = 1;
}
z = M[n-1];
if (test==1) printf("-1");
else
{
if (x<z) printf("%d",z);
else printf("%d",x);
}
}
}
| |
In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. | Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. | C | fbfc333ad4b0a750f654a00be84aea67 | b36386d45ddbf4747e266672b9fbbe59 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1448382900 | ["4 2\n1 3\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2"] | NoteIn the first sample, the train can take the route and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. | PASSED | 1,600 | standard input | 2 seconds | The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one railway connecting any two towns. | ["2", "-1", "3"] | #include <stdio.h>
#define N 400
int main() {
static char aa[N][N];
static int qq[N], dd[N];
int n, m, i, j, d, head, cnt;
scanf("%d%d", &n, &m);
while (m-- > 0) {
scanf("%d%d", &i, &j);
i--, j--;
aa[i][j] = aa[j][i] = 1;
}
if (aa[0][n - 1])
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++)
aa[i][j] = aa[j][i] = 1 - aa[i][j];
for (i = 0; i < n; i++)
dd[i] = -1;
head = cnt = 0;
qq[head + cnt++] = 0, dd[0] = 0;
while (cnt > 0) {
i = qq[head++];
d = dd[i];
cnt--;
if (i == n - 1) {
printf("%d\n", d);
return 0;
}
for (j = 0; j < n; j++)
if (aa[i][j] && dd[j] == -1)
qq[head + cnt++] = j, dd[j] = d + 1;
}
printf("-1\n");
return 0;
}
| |
In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. | Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. | C | fbfc333ad4b0a750f654a00be84aea67 | 63d568a53cde1093604c85a931cc4ea2 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1448382900 | ["4 2\n1 3\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2"] | NoteIn the first sample, the train can take the route and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. | PASSED | 1,600 | standard input | 2 seconds | The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one railway connecting any two towns. | ["2", "-1", "3"] | #include <stdio.h>
#include <string.h>
#define INF 0x3f3f3f3f
int map1[410][410],map2[410][410];
int n,m;
void dijkstra(int map[410][410])
{
int ans[410];
int vis[410];
int point,min;
int i,j;
for(i=1;i<=n;i++)
{
vis[i]=0;
ans[i]=map[1][i];
}
for(i=1;i<=n;i++)
{
min=INF;
for(j=1;j<=n;j++)
{
if(!vis[j]&&ans[j]<min)
{
point=j;
min=ans[j];
}
}
vis[point]=1;
for(j=1;j<=n;j++)
{
if(!vis[j]&&ans[j]>map[point][j]+ans[point])
{
ans[j]=map[point][j]+ans[point];
}
}
}
if(ans[n]==INF)
{
printf("-1\n");
return ;
}
else
{
printf("%d\n",ans[n]);
return ;
}
}
int main()
{
scanf("%d%d",&n,&m);
int i,j;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(i==j)
{
map1[i][j]=0;
map2[i][j]=0;
}
else
{
map1[i][j]=map1[j][i]=INF;
map2[i][j]=map2[j][i]=INF;
}
}
}
int flag=0;
for(i=0;i<m;i++)
{
int a,b;
scanf("%d%d",&a,&b);
if((a==1&&b==n)||(a==n&&b==1))
{
flag=1;
}
map1[a][b]=1;
map1[b][a]=1;
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(map1[i][j]==INF)
{
map2[i][j]=1;
map2[j][i]=1;
}
}
}
if(m==n*(n-1)/2)
{
printf("-1\n");
return 0;
}
if(flag==1)
{
dijkstra(map2);
}
else
{
dijkstra(map1);
}
return 0;
}
| |
In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. | Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. | C | fbfc333ad4b0a750f654a00be84aea67 | d3241910e0f1c8f03139e82c4cbd589b | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1448382900 | ["4 2\n1 3\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2"] | NoteIn the first sample, the train can take the route and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. | PASSED | 1,600 | standard input | 2 seconds | The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one railway connecting any two towns. | ["2", "-1", "3"] | #include <stdio.h>
#define MAXN 400
#define INF 2000000000
char d[MAXN][MAXN];
int dist[MAXN];
int q[MAXN];
inline void bfs(char x, int n){
int st = 0, dr = 1, i, nd;
dist[0] = 0;
q[0] = 0;
while(st < dr){
nd = q[st];
st++;
for(i = 0; i < n; i++){
if(i != nd && d[nd][i] == x && dist[i] > dist[nd] + 1){
dist[i] = dist[nd] + 1;
q[dr] = i;
dr++;
}
}
}
}
int main(){
//freopen("f.in", "r", stdin);
//freopen("f.out", "w", stdout);
int n, m, i, x, y, aux;
char g = 1;
scanf("%d%d", &n, &m);
for(i = 0; i < m; i++){
scanf("%d%d", &x, &y);
x--; y--;
if(x > y){
aux = x; x = y; y = aux;
}
if(x == 0 && y == n - 1)
g = 0;
d[x][y] = d[y][x] = 1;
}
for(i = 0; i < n; i++)
dist[i] = INF;
bfs(g, n);
if(dist[n - 1] == INF)
dist[n - 1] = -1;
printf("%d", dist[n - 1]);
return 0;
}
| |
In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. | Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. | C | fbfc333ad4b0a750f654a00be84aea67 | 48662f35d57ae039da73db627850f276 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1448382900 | ["4 2\n1 3\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2"] | NoteIn the first sample, the train can take the route and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. | PASSED | 1,600 | standard input | 2 seconds | The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one railway connecting any two towns. | ["2", "-1", "3"] | #include <stdio.h>
#include <string.h>
#define MAXV 401
typedef struct {
int to;
int next;
} Edge_t;
Edge_t ERoad[MAXV * MAXV];
Edge_t ERail[MAXV * MAXV];
int AdjRoad[MAXV];
int AdjRail[MAXV];
int SizeRoad, SizeRail;
int Queue[MAXV];
char Visited[MAXV];
char Flag[MAXV][MAXV];
void Initialize()
{
memset(AdjRoad, -1, sizeof(AdjRoad));
memset(AdjRail, -1, sizeof(AdjRail));
}
void AddEdge(int u, int v, char road)
{
if(road) {
ERoad[SizeRoad].to = v;
ERoad[SizeRoad].next = AdjRoad[u];
AdjRoad[u] = SizeRoad++;
} else {
ERail[SizeRail].to = v;
ERail[SizeRail].next = AdjRail[u];
AdjRail[u] = SizeRail++;
}
}
int BFS(int u, int v, Edge_t *E, int *Adj)
{
int Head, Tail, Cnt, i, j;
Head = 0;
Tail = Cnt = 1;
memset(Visited, 0, sizeof(Visited));
Queue[0] = u;
Visited[u] = 1;
int Ans = 1;
while(Head < Tail) {
for(i = Head; i < Tail; ++i) {
for(j = Adj[Queue[i]]; ~j; j = E[j].next) {
if(!Visited[E[j].to]) {
if(E[j].to == v) {
return Ans;
}
Visited[E[j].to] = 1;
Queue[Cnt++] = E[j].to;
}
}
}
Head = Tail;
Tail = Cnt;
++Ans;
}
return -1;
}
int main()
{
int N, M, u, v, i, j;
Initialize();
scanf("%d %d", &N, &M);
while(M--) {
scanf("%d %d", &u, &v);
Flag[u][v] = Flag[v][u] = 1;
AddEdge(u, v, 0);
AddEdge(v, u, 0);
}
for(i = 1; i <= N; ++i) {
for(j = i + 1; j <= N; ++j) {
if(!Flag[i][j]) {
AddEdge(i, j, 1);
AddEdge(j, i, 1);
}
}
}
if(Flag[1][N]) {
printf("%d\n", BFS(1, N, ERoad, AdjRoad));
} else {
printf("%d\n", BFS(1, N, ERail, AdjRail));
}
return 0;
}
| |
In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. | Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. | C | fbfc333ad4b0a750f654a00be84aea67 | 1be2fbc269464e6c955fa718ce69da94 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1448382900 | ["4 2\n1 3\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2"] | NoteIn the first sample, the train can take the route and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. | PASSED | 1,600 | standard input | 2 seconds | The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one railway connecting any two towns. | ["2", "-1", "3"] | #include <stdio.h>
#include <stdlib.h>
int main() {
int e[500][500] = {{0}};
int rail[500] = {0};
int n, m, i, j, u, v, lvl;
int change;
scanf("%d%d", &n, &m);
for(i = 0; i < m; i++) {
scanf("%d%d", &u, &v);
e[u][v] = 1;
e[v][u] = 1;
}
if(e[1][n]) {
for(i = 1; i <= n; i++) {
for(j = 1; j <= n; j++) {
if(j != i) e[i][j] = !e[i][j];
}
}
}
change = 1;
rail[1] = 1;
lvl = 1;
while(change) {
change = 0;
for(i = 1; i <= n; i++) {
if(rail[i] == lvl) {
for(j = 1; j <= n; j++) {
if(e[i][j] && !rail[j]) {
rail[j] = rail[i] + 1;
change = 1;
if(j == n) {
printf("%d\n", rail[j] - 1);
return 0;
}
}
}
}
}
lvl++;
}
printf("-1\n");
return 0;
}
| |
In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so. | Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output - 1. | C | fbfc333ad4b0a750f654a00be84aea67 | 2c6dd0a2efb78afcafa657b16e907e99 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"graphs"
] | 1448382900 | ["4 2\n1 3\n3 4", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2"] | NoteIn the first sample, the train can take the route and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. | PASSED | 1,600 | standard input | 2 seconds | The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one railway connecting any two towns. | ["2", "-1", "3"] | #include <stdio.h>
#include <stdlib.h>
#define NMAX 410
typedef int adj_t[NMAX][NMAX];
void read(int *n, adj_t adj) {
int m, u, v;
scanf("%d%d", n, &m);
while (m-- > 0) {
scanf("%d%d", &u, &v);
adj[u][v] = adj[v][u] = 1;
}
}
int BFS(int n, adj_t adj, int mean) {
int status[NMAX] = {0},
dist[NMAX] = {0},
q[NMAX], top = 0, tail = -1,
u, v;
q[++tail] = 1;
status[1] = 1;
while (top <= tail) {
u = q[top++];
for (v = 1; v <= n; ++v)
if (adj[u][v] == mean && !status[v]) {
status[v] = 1;
dist[v] = dist[u] + 1;
q[++tail] = v;
if (v == n)
return dist[n];
}
}
return -1;
}
void swap(int *a, int *b) {
int tmp = *a;
*a = *b;
*b = tmp;
}
int main(void) {
int n, dist;
adj_t adj;
read(&n, adj);
dist = BFS(n, adj, 1 - adj[1][n]);
printf("%d", dist);
return 0;
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | fc9d5ce72b269e30cf498beee08749cd | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include<stdio.h>
#include<stdlib.h>
typedef struct Nodo{
int pos;
struct Nodo *sgte;
}Nodo;
int f[100010];
int r[100010];
int main(){
int i,j,n,m;
Nodo *aux;
Nodo *H=(Nodo *)calloc(1,sizeof(Nodo));
scanf("%d",&n);
for(i=0;i<n;i++) scanf("%d",&f[i]);
H->pos=n-1;
H->sgte=NULL;
for(i=n-1;i>=0;i--){
if(f[i]>f[H->pos]){
aux=H;
while(aux!=NULL && f[i]>f[aux->pos]){
r[i]=aux->pos-i-1;
aux=aux->sgte;
}
}else{
r[i]=-1;
if(f[i]<f[H->pos]){
aux=(Nodo *)calloc(1,sizeof(Nodo));
aux->pos=i;
aux->sgte=H;
H=aux;
}
}
}
aux=H;
for(i=0;i<n;i++){
printf("%d ",r[i]);
}
return 0;
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 4a3692b2f3874f576688010f9ee0c644 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include <stdio.h>
int morsas[100005], menor[100005];
int main() {
int n ,i, izq, der, med ;
scanf("%d", &n);
for(i = 0; i < n; i++) {
scanf("%d", &morsas[i]);
}
menor[n-1] = morsas[n-1];
for(i = n - 2; i >= 0; i--) {
if(morsas[i] < menor[i+1]){
menor[i] = morsas[i];
}else{
menor[i] = menor[i+1];
}
}
for(i = 0; i < n - 1; i++) {
if(menor[i+1] < morsas[i]) {
izq = i + 1;
der = n - 1;
while(izq < der-1) {
med = (izq+der)/2;
if(menor[med] < morsas[i]) {
izq = med;
} else {
der = med;
}
}
if(menor[der] < morsas[i]){
izq = der;
}
printf("%d ", izq - i - 1);
} else {
printf("-1 ");
}
}
printf("-1 ");
return 0;
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 17d967b7dc86653fe00ab881754bad6f | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include <stdio.h>
int a[100005], Min[100005];
int main() {
int n;
scanf("%d", &n);
int i;
for(i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
Min[n-1] = a[n-1];
for(i = n - 2; i >= 0; i--) {
Min[i] = a[i] < Min[i+1] ? a[i] : Min[i+1];
}
for(i = 0; i < n - 1; i++) {
if(Min[i+1] < a[i]) {
int l = i + 1, r = n - 1;
while(l<r-1) {
int mid = (l+r)/2;
if(Min[mid] < a[i]) {
l = mid;
} else {
r = mid;
}
}
if(Min[r] < a[i]) l = r;
printf("%d ", l - i - 1);
} else {
printf("-1 ");
}
}
puts("-1");
return 0;
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | 2f1fc223ad4a613623917f45770a8079 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include<stdio.h>
#include<stdlib.h>
typedef struct Nodo
{
int posicion;
struct Nodo *siguiente;
} morsa;
int main()
{
morsa *siguiente,*aux;
int i,n;
scanf("%d",&n);
int a[n+1];
int v[n+1];
for(i = 0; i < n; i++)
scanf("%d",&a[i]);
siguiente = (morsa*)malloc(sizeof(morsa));
siguiente->posicion = n-1;
siguiente->siguiente = NULL ;
for(i = n-1; i >=0; i--)
{
if(a[i] > a[siguiente->posicion])
{
aux=siguiente;
while(aux != NULL && a[i] > a[aux->posicion])
{
v[i] = aux->posicion - i -1;
aux=aux->siguiente;
}
}
else
{
v[i] = -1;
if( a[i] < a[siguiente->posicion])
{
morsa *nuevo;
nuevo = (morsa*)malloc(sizeof(morsa));
nuevo->posicion = i;
nuevo->siguiente = siguiente;
siguiente = nuevo;
}
}
}
for(i = 0; i < n; i++)
printf("%d ",v[i]);
return 0;
}
| |
There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure. | Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus. | C | 668f85cc331bc7bcdd708d9190bbd6e8 | d3977ffd04e65ff7175e08c7f8d1180d | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"binary search"
] | 1308582000 | ["6\n10 8 5 3 50 45", "7\n10 4 6 3 2 8 15", "5\n10 3 1 10 11"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one. | ["2 1 0 -1 0 -1", "4 2 1 0 -1 -1 -1", "1 0 -1 -1 -1"] | #include <stdio.h>
#include <stdlib.h>
typedef struct{
int Pos;
struct NodoLista *ptrSiguiente;
}NodoLista;
int main(){
NodoLista *Aux;
NodoLista *Last = (NodoLista*)calloc(1,sizeof(NodoLista));
int N = 0, i = 0;
scanf("%d", &N);
int Edades[N];
int Disgusto[N];
for(i=0; i<N; i++){
scanf("%d", &Edades[i]);
}
Last->Pos = N-1;
Last->ptrSiguiente = NULL;
for(i = N-1; i>=0; i--){
if(Edades[i] > Edades[Last->Pos]){
Aux = Last;
while(Aux != NULL && Edades[i] > Edades[Aux->Pos]){
Disgusto[i] = Aux->Pos - i - 1;
Aux = Aux->ptrSiguiente;
}
}else{
Disgusto[i] = -1;
if(Edades[i] < Edades[Last->Pos]){
Aux = (NodoLista*)calloc(1,sizeof(NodoLista));
Aux->Pos = i;
Aux->ptrSiguiente = Last;
Last = Aux;
}
}
}
Aux = Last;
for(i=0; i<N; i++){
printf("%d ", Disgusto[i]);
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.