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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 2026c5cf74868b68bb145d075fa25feb | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | /* practice with Dukkha */
#include <stdio.h>
#define N 500
int main() {
static char cc[N][N + 1];
int n, m, i, j, i_, j_;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++)
scanf("%s", cc[i]);
i_ = j_ = -1;
for (i = 1; i < n - 1; i++)
for (j = 1; j < m - 1; j++)
if (cc[i][j] == '*' && cc[i - 1][j] == '*' && cc[i + 1][j] == '*' && cc[i][j - 1] == '*' && cc[i][j + 1] == '*') {
i_ = i, j_ = j;
j = j_;
for (i = i_ + 1; i < n && cc[i][j] == '*'; i++)
cc[i][j] = '.';
for (i = i_ - 1; i >= 0 && cc[i][j] == '*'; i--)
cc[i][j] = '.';
i = i_;
for (j = j_ + 1; j < m && cc[i][j] == '*'; j++)
cc[i][j] = '.';
for (j = j_ - 1; j >= 0 && cc[i][j] == '*'; j--)
cc[i][j] = '.';
cc[i_][j_] = '.';
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
if (cc[i][j] == '*') {
printf("NO\n");
return 0;
}
printf("YES\n");
return 0;
}
printf("NO\n");
return 0;
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 110bf528d861c195bbda30ea64cfdd8c | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include<stdio.h>
int main()
{
int n, m, i, cnt, j, p, q,z=0;
scanf("%d%d", &n, &m);
char a[504][504];
for (i = 0; i < n; i++)
{
scanf("%s", a[i]);
}
int cnt1 = 0;
for (i = 0; i < n; i++)
{
cnt = 0;
q = 501;
for (j = 0; j < m; j++)
{
if (a[i][j] == '*')
{
cnt++;
p = j;
if (p - q > 1)
{
printf("No");
z=1;
return 0;
}
q = p;
}
}
if (cnt > 1)
cnt1++;
}
if (cnt1 > 1)
{
z = 1;
printf("No");
return 0;
}
if (z = 0)
{
cnt1 = 0;
for (j = 0; j < m && z != 1; j++)
{
cnt = 0;
q=501;
for (i = 0; i < n && z != 1; i++)
{
if (a[i][j] == '*')
{
cnt++;
p = i;
if (p - q > 1)
{
z = 1;
printf("No");
return 0;
}
}
}
if (cnt > 1 && z != 1)
cnt1++;
}
}
if (cnt1 > 1)
{
z = 1;
printf("No");
return 0;
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j]=='*')
{
if(a[i][j+1]!='*'&&a[i][j-1]!='*'&&a[i+1][j]!='*'&&a[i-1][j]!='*'){
printf("no");
return 0;
}
}
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j]=='*')
{
if(a[i][j+1]=='*'&&a[i][j-1]=='*'&&a[i+1][j]=='*'&&a[i-1][j]=='*'){
printf("yes");
return 0;
}
}
}
}
printf("no");
} | |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 1f56a4cc471be7684ecb8963678ad905 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include <stdio.h>
#define H 500
#define W 500
int main() {
static char cc[H][W + 1];
int h, w, i, j, cnt, empty;
scanf("%d%d", &h, &w);
for (i = 0; i < h; i++)
scanf("%s", cc[i]);
cnt = 0;
for (i = 1; i + 1 < h; i++)
for (j = 1; j + 1 < w; j++)
if (cc[i][j] == '*' && cc[i + 1][j] == '*' && cc[i][j + 1] == '*' && cc[i - 1][j] == '*' && cc[i][j - 1] == '*') {
int u, l, d, r;
cnt++;
cc[i][j] = '.';
for (u = i - 1; u >= 0 && cc[u][j] == '*'; u--)
cc[u][j] = '.';
for (l = j - 1; l >= 0 && cc[i][l] == '*'; l--)
cc[i][l] = '.';
for (d = i + 1; d < h && cc[d][j] == '*'; d++)
cc[d][j] = '.';
for (r = j + 1; r < w && cc[i][r] == '*'; r++)
cc[i][r] = '.';
}
empty = 1;
for (i = 0; i < h; i++)
for (j = 0; j < w; j++)
if (cc[i][j] != '.') {
empty = 0;
break;
}
printf(cnt == 1 && empty ? "YES\n" : "NO\n");
return 0;
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | f203552369ce1ec4a9825bf67183c33b | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include <stdio.h>
#define H 500
#define W 500
int main() {
static char cc[H][W + 1];
int h, w, i, j;
scanf("%d%d", &h, &w);
for (i = 0; i < h; i++)
scanf("%s", cc[i]);
for (i = 1; i + 1 < h; i++)
for (j = 1; j + 1 < w; j++)
if (cc[i][j] == '*' && cc[i + 1][j] == '*' && cc[i][j + 1] == '*' && cc[i - 1][j] == '*' && cc[i][j - 1] == '*') {
int u, l, d, r;
cc[i][j] = '.';
for (u = i - 1; u >= 0 && cc[u][j] == '*'; u--)
cc[u][j] = '.';
for (l = j - 1; l >= 0 && cc[i][l] == '*'; l--)
cc[i][l] = '.';
for (d = i + 1; d < h && cc[d][j] == '*'; d++)
cc[d][j] = '.';
for (r = j + 1; r < w && cc[i][r] == '*'; r++)
cc[i][r] = '.';
for (i = 0; i < h; i++)
for (j = 0; j < w; j++)
if (cc[i][j] != '.') {
printf("NO\n");
return 0;
}
printf("YES\n");
return 0;
}
printf("NO\n");
return 0;
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 5df85c61ca399f6e9fdaa54e615122d5 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include<stdio.h>
#include<math.h>
int main()
{
int w, h, i, j, a=0, cnt=0, c=0, d=0;
scanf("%d %d", &h, &w);
getchar();
char str[h+1][w+1];
for (i=0; i<h; i++)
gets(str[i]);
for (i=0; i<h; i++)
for (j=0; j<w; j++)
if ( str[i][j]=='*' )
cnt++;
if ( cnt==0 )
a++;
for (i=0; i<h; i++)
for (j=0; j<w; j++)
if ( str[i][j]=='*' && str[i+1][j]=='*' && str[i-1][j]=='*' && str[i][j+1]=='*' && str[i][j-1]=='*' )
goto A;
A:
for ( c=i; c<h; c++)
{
if ( str[c][j]=='*')
str[c][j]='.';
else
break;
}
for ( c=i-1; c>=0; c--)
{
if ( str[c][j]=='*')
str[c][j]='.';
else
break;
}
for ( d=j+1; d<w; d++)
{
if ( str[i][d]=='*')
str[i][d]='.';
else
break;
}
for ( d=j-1; d>=0; d--)
{
if ( str[i][d]=='*')
str[i][d]='.';
else
break;
}
for (i=0; i<h; i++)
for (j=0; j<w; j++)
if ( str[i][j]=='*' )
a++;
if ( a==0 )
printf("YES\n");
else
printf("NO\n");
return 0;
} | |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | eae1b5b632303532e03b06c41d2f8949 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] |
#include<stdio.h>
#include<math.h>
int array[512][512] = { 0 };
int main()
{
int h, w;
int fp = 0;
int fpx, fpy;
int cnt = 0;
int expc = 0;
scanf("%d %d", &h, &w);
for (int cy = 0; cy < h; cy++)
{
for (int cx = 0; cx < w; cx++)
{
while (1)
{
int c = getchar();
if (c == '.')
{
//array[cy][cx] = 0;
break;
}
else if (c == '*')
{
array[cy][cx] = 1;
if (fp == 0)
{
fpx = cx;
fpy = cy;
fp = 1;
}
cnt++;
break;
}
}
}
}
if (fp == 0)
{
printf("NO");
return 0;
}
if (fpx == 0 || fpx == w - 1)
{
printf("NO");
return 0;
}
//找第一个点,纵向扩展试试看
int endY = fpy;
for (int ey = fpy; ey < h; ey++)
{
if (array[ey][fpx])
{
expc++;
endY++;
}
else
{
break;
}
}
endY--;
//寻找分叉节点,横向扩展,左右展开统计个数
for (int ey = fpy; ey <= endY; ey++)
{
if (array[ey][fpx-1] && array[ey][fpx + 1])
{
if (ey == fpy || ey == endY)
{
printf("NO");
return 0;
}
//左右展开
for (int lx = fpx - 1; lx >= 0; lx--)
{
if (array[ey][lx])
{
expc++;
}
else
{
break;
}
}
for (int rx = fpx + 1; rx < w; rx++)
{
if (array[ey][rx])
{
expc++;
}
else
{
break;
}
}
if (expc == cnt)
{
printf("YES");
}
else
{
printf("NO");
}
return 0;
}
else if (array[ey][fpx - 1] || array[ey][fpx + 1])
{
printf("NO");
return 0;
}
}
printf("NO");
return 0;
} | |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | fd5d1ec496db29be09a7a55c79508cc3 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #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 A[1000][1000];
ll N, M;
ll inbounds(ll x, ll y)
{
if (x >= 0 && y >= 0 && x < N && y < M)
{
if (A[x][y] == 1)
{
return 1;
}
}
return 0;
}
int main(int argc, char const *argv[])
{
ll T = 1;
// scanf("%lld",&T);
for (ll t = 0; t < T; t++)
{
// ll N, M;
scanf("%lld %lld", &N, &M);
// ll A[N];
for (ll n = 0; n < N; n++)
{
char string[M];
scanf("%s",string);
for (ll m = 0; m < M; m++)
{
if(string[m]=='*'){
A[n][m] = 1;
}
}
}
ll flag = 0;
for (ll n = 0; n < N; n++)
{
for (ll m = 0; m < M; m++)
{
// printf("%lld ",A[n][m]);
}
// printf("\n");
}
ll xpos,ypos ;
for (ll n = 0; n < N; n++)
{
for (ll m = 0; m < M; m++)
{
if (A[n][m])
{
// printf("%lld %lld %lld %lld %lld %lld\n",n,m,inbounds(n, m - 1) ,inbounds(n - 1, m),inbounds(n, m + 1) , inbounds(n + 1, m));
if (inbounds(n, m - 1) && inbounds(n - 1, m) && inbounds(n, m + 1) && inbounds(n + 1, m))
{
flag++;
// A[n][m] = -1;
xpos = n;
ypos = m;
}
}
}
}
// printf("flag is %lld\n",flag);
if (flag > 1 || flag==0)
{
// printf()
printf("NO\n");
return 0;
}
ll u = xpos,v = ypos;
A[u][v] = 1;
while(inbounds(u,v)){
A[u][v] = -1;
u--;
}
u = xpos,v = ypos;
A[u][v] = 1;
while(inbounds(u,v)){
A[u][v] = -1;
v--;
}
u = xpos,v = ypos;
A[u][v] = 1;
while(inbounds(u,v)){
A[u][v] = -1;
u++;
}
u = xpos,v = ypos;
A[u][v] = 1;
while(inbounds(u,v)){
A[u][v] = -1;
v++;
}
for (ll n = 0; n < N; n++)
{
for (ll m = 0; m < M; m++)
{
// printf("%lld ",A[n][m]);
}
// printf("\n");
}
for (ll n = 0; n < N; n++)
{
for (ll m = 0; m < M; m++)
{
if(A[n][m]==1){
printf("NO\n");
return 0;
}
}
}
printf("YES\n");
}
return 0;
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 3f1360d06a3bedfa54704dd6dd388fea | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include<stdio.h>
#include<string.h>
int main ()
{
int i,n,m,j,s=0,q=0;
char a[505][505];
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
getchar();
for(j=0;j<m;j++)
{
scanf("%c",&a[i][j]);
if(a[i][j]=='*')
s++;
}
}
for(i=1;i<n-1;i++)
for(j=1;j<m-1;j++)
if(a[i][j]=='*')
{
int x=i-1,y=j,t=s-1,x1=0,x2=0,x3=0,x4=0;
while(x>=0&&a[x][y]=='*')
t--,x--,x1=1;
x=i,y=j-1;
while(y>=0&&a[x][y]=='*')
t--,y--,x2=1;
x=i+1,y=j;
while(x<n&&a[x][y]=='*')
t--,x++,x3=1;
x=i,y=j+1;
while(y<m&&a[x][y]=='*')
t--,y++,x4=1;
if(t==0&&x1==1&&x2==1&&x3==1&&x4==1)
{
q=1;
break;
}
}
if(q==0)
printf("NO");
else
printf("YES");
return 0;
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 0d8fa2307ccb5fafb56da7196df3a98a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
typedef int64_t i64;
typedef int32_t i32;
static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))
#define POS(i, j) ((i) * w + (j))
void run (void) {
i32 h = read_int();
i32 w = read_int();
char *s = ALLOC (h * w + 1, char);
for (i32 i = 0; i < h; ++i) {
scanf ("%s", s + i * w);
}
i32 cnt = 0;
for (i32 i = 0; i < h * w; ++i) {
cnt += s[i] == '*' ? 1 : 0;
}
for (i32 i = 1; i < h; ++i) {
for (i32 j = 1; j < w; ++j) {
if (s[POS(i, j)] != '*') continue;
i32 d[4] = {1, 0, -1, 0};
i32 ok = 1;
for (i32 k = 0; k < 4; ++k) {
if (s[POS(i + d[k], j + d[k ^ 1])] != '*') {
ok = 0;
}
}
if (!ok) continue;
i32 c = 1;
for (i32 k = 0; k < 4; ++k) {
for (i32 x = i + d[k], y = j + d[k ^ 1]; 0 <= x && x < h && 0 <= y && y < w && s[POS(x, y)] == '*'; x += d[k], y += d[k ^ 1]) {
c++;
}
}
if (c == cnt) {
puts ("YES");
return;
}
}
}
puts ("NO");
}
int main (void) {
run ();
return 0;
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | fc5819839adf4d7dfc079fd0f171ab3c | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include <stdio.h>
#include <stdlib.h>
int IfEmp(int array[][505] , int w,int h);
void delet(int array[][505] , int w, int h,int i,int j) ;
int main()
{
int array[505][505]={0},w,h;
scanf("%d %d",&w,&h);
for(int i=0;i<w;i++)
{
for(int j=0;j<h;j++)
{
char a;
do{
a=getchar();
}
while(a=='\n');
if(a=='*')
array[i][j] = 1;
}
}
if(array[0][0] == 1 || array[w-1][0] == 1 || array[0][h-1] == 1 || array[w-1][h-1] == 1 )
printf("NO\n");
else
{
int flag =0;
for(int i=1 ; i<w-1 ; i++)
{
for(int j=1 ; j<h-1 ; j++)
{
if(flag == 0 && array[i][j] == 1 && array[i-1][j] == 1 && array[i+1][j] == 1 && array[i][j-1] == 1 && array[i][j+1] == 1)
{
delet(array,w,h,i,j);
flag = 1;
break;
}
}
if(flag)
break;
}
if(flag && IfEmp(array , w, h)==0)
printf("YES\n");
else
printf("NO\n");
}
}
void delet(int array[][505] , int w, int h,int i ,int j)
{
int k;
array[i][j] = 0;
for(k=1 ; k<=i ; k++)
{
if(array[i-k][j]==1)
array[i-k][j] = 0;
else
break;
}
for(k=1 ; k<=w-i ; k++)
{
if(array[i+k][j]==1)
array[i+k][j] = 0;
else
break;
}
for(k=1 ; k<=j ; k++)
{
if(array[i][j-k]==1)
array[i][j-k] = 0;
else
break;
}
for(k=1 ; k<=h-j ; k++)
{
if(array[i][j+k]==1)
array[i][j+k] = 0;
else
break;
}
}
int IfEmp(int array[][505],int w,int h)
{
int flag = 0;
for(int i=0;i<w;i++)
{
for(int j=0;j<h;j++)
{
if(array[i][j] == 1)
{
flag = 1;
break;
}
}
if(flag)
break;
}
return flag;
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | b536328e405a5fabecbc1620f15168e9 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include<stdio.h>
int main()
{
int h,w;
scanf("%d %d",&h,&w);
char s[h][w];
for(int i=0;i<h;i++)
scanf("%s",s[i]);
int flag=1;
int ch,cw;
int count=0;
for(int i=1;i<h-1;i++)
for(int j=0;j<w-2;j++)
if(s[i][j]=='*' && s[i][j+1]=='*' && s[i][j+2]=='*')
if(s[i-1][j+1]=='*' && s[i+1][j+1]=='*')
{
ch=i;
cw=j+1;
count++;
}
if(count==1)
{
for(int i=cw;i>0;i--)
if(s[ch][i]=='.'&& s[ch][i-1]=='*')
flag=0;
if(flag!=0)
for(int i=cw;i<w-1;i++)
if(s[ch][i]=='.'&& s[ch][i+1]=='*')
flag=0;
if(flag!=0)
for(int i=ch;i>0;i--)
if(s[i][cw]=='.'&& s[i-1][cw]=='*')
flag=0;
if(flag!=0)
for(int i=ch;i<h-1;i++)
if(s[i][cw]=='.'&& s[i+1][cw]=='*')
flag=0;
}
if(count==1 && flag==1)
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
if(i!=ch && j!=cw)
if(s[i][j]=='*')
{
flag=0;
break;
}
}
}
if(flag==1 && count==1)
printf("YES");
else printf("NO");
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | e3a0a2fd3a5b317167f124123e2c3649 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include <stdio.h>
#include <string.h>
char grid[555][555];
int check(int x, int y, int h, int w, int cc) {
int i, j, c = 1;
if (x+1 >= h || grid[x+1][y] == '.')
return 0;
for (i = x+1; i < h; i++) {
if (grid[i][y] == '.')
break;
c++;
}
if (x-1 < 0 || grid[x-1][y] == '.')
return 0;
for (i = x-1; i >= 0; i--) {
if (grid[i][y] == '.')
break;
c++;
}
if (y+1 >= w || grid[x][y+1] == '.')
return 0;
for (j = y+1; j < w; j++) {
if (grid[x][j] == '.')
break;
c++;
}
if (y-1 < 0 || grid[x][y-1] == '.')
return 0;
for (j = y-1; j >= 0; j--) {
if (grid[x][j] == '.')
break;
c++;
}
return cc == c;
}
int main(int argc, char** argv) {
int i, j, h, w, cnt, ok;
scanf("%d%d", &h, &w);
for (i = 0; i < h; i++) {
getchar();
for (j = 0; j < w; j++)
grid[i][j] = getchar();
}
cnt = ok = 0;
for (i = 0; i < h; i++)
for (j = 0; j < w; j++)
if (grid[i][j] == '*')
cnt++;
for (i = 0; i < h; i++)
for (j = 0; j < w; j++)
if (grid[i][j] == '*') {
int ret = check(i, j, h, w, cnt);
if (ret) {
ok = 1;
i = j = 1000;
}
}
puts(ok ? "YES" : "NO");
return 0;
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | ea1e2094ec89eeaa82da48d56365a8d6 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include <stdio.h>
#include <stdlib.h>
typedef int bool;
//enum{false, true};
#define false 0;
#define true 1;
bool Up(char **tab, int l, int c, int *i, int *j)
{
for(int ii=0; ii<l; ii++)
{
for(int jj=0; jj<c; jj++)
{
if ((tab[ii][jj]=='*') && !((ii == 0) && (jj == 0)) && !((ii == 0) && (jj == c-1)) && (ii<l-2))
{
*i = ii;
*j = jj;
return true;
}
}
}
return false;
}
bool Down(char **tab, int l, int c, int *i, int *j)
{
for(int ii=l-1; ii>=0; ii--)
{
for(int jj=0; jj<c; jj++)
{
if ((tab[ii][jj]=='*') && !((ii == l-1) && (jj == 0)) && !((ii == l-1) && (jj == c-1)) && (ii>1))
{
*i = ii;
*j = jj;
return true;
}
}
}
return false;
}
bool Left(char **tab, int l, int c, int *i, int *j)
{
for(int jj=0; jj<c; jj++)
{
for(int ii=0; ii<l; ii++)
{
if ((tab[ii][jj]=='*') && !((ii == 0) && (jj == 0)) && !((jj == 0) && (ii == l-1)) && (jj<c-2))
{
*i = ii;
*j = jj;
return true;
}
}
}
return false;
}
bool Right(char **tab, int l, int c, int *i, int *j)
{
for(int jj=c-1; jj>=0; jj--)
{
for(int ii=0; ii<l; ii++)
{
if ((tab[ii][jj]=='*') && !((jj == c-1) && (ii == 0)) && !((jj == c-1) && (ii == l-1)) && (jj>1))
{
*i = ii;
*j = jj;
return true;
}
}
}
return false;
}
int main(){
int l,c, ind1, ind2, ind3, ind4, ind5, ind6, ind7, ind8;
char **tab;
bool a;
scanf("%d", &l);
scanf("%d", &c);
tab = (char**)malloc(l * sizeof(char*));
for(int i=0; i<l; i++)
tab[i] = (char*)malloc(c * sizeof(char));
for(int i=0; i<l; i++)
for(int j=0; j<c; j++)
scanf(" %c", &tab[i][j]);
// for(int i=0; i<l; i++)
// {
// for(int j=0; j<c; j++)
// printf("%c", tab[i][j]);
// printf("\n");
// }
ind1 = 0;
ind2 = 0;
if (!Up(tab, l, c, &ind1, &ind2) || !Down(tab, l, c, &ind3, &ind4)
|| !Left(tab, l, c, &ind5, &ind6) || !Right(tab, l, c, &ind7, &ind8))
{
printf("NO");
return 0;
}
if ((ind2 != ind4) || (ind5 != ind7) || (ind3 < ind1+2) || (ind8 < ind6+2))
{
printf("NO");
return 0;
}
for(int i=ind1+1; i<ind3;i++)
{
if (tab[i][ind2] != '*')
{
printf("NO");
return 0;
}
}
for(int i=ind6+1; i<ind8;i++)
{
if (tab[ind5][i] != '*')
{
printf("NO");
return 0;
}
}
for(int i=0; i<l; i++)
{
if (i == ind5)
{
continue;
}
for(int j=0; j<c; j++)
{
if (j == ind2)
{
continue;
}
if (tab[i][j] == '*')
{
printf("NO");
return 0;
}
}
}
printf("YES");
return 0;
} | |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | f754229af6cfcdc6cc3db9f7f19a0f1d | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include<stdio.h>
int main()
{
int h,w;
char ch;
int mm[520][520];
scanf("%d%d",&h,&w);
ch=getchar();
for (int i=1;i<=h;i++)
for (int j=1;j<=w;j++)
{
while (ch!='.' && ch!='*') ch=getchar();
if (ch=='.') mm[i][j]=0;
else mm[i][j]=1;
ch=getchar();
}
int flag=1;
int x=0,y=0;
for (int i=1;i<=h;i++)
{
for (int j=1;j<w;j++)
if (mm[i][j]+mm[i][j+1]==2)
{
if (x!=0 && x!=i){printf("NO");return 0;}
x=i;
}
}
for (int j=1;j<=w;j++)
for (int i=1;i<h;i++)
if (mm[i][j]+mm[i+1][j]==2)
{
if (y!=0 && y!=j) {printf("NO");return 0;}
y=j;
}
if (x==0 || y==0) {printf("NO");return 0;}
if (mm[x][y]==0 || mm[x-1][y]==0 || mm[x+1][y]==0 || mm[x][y+1]==0 || mm[x][y-1]==0){printf("NO");return 0;}
int tmpx=x-1,tmpy=y;
mm[x][y]=0;
while (mm[tmpx][tmpy]) mm[tmpx--][tmpy]=0;
tmpx=x+1,tmpy=y;while (mm[tmpx][tmpy]) mm[tmpx++][tmpy]=0;
tmpx=x,tmpy=y-1;while (mm[tmpx][tmpy]) mm[tmpx][tmpy--]=0;
tmpx=x,tmpy=y+1;while (mm[tmpx][tmpy]) mm[tmpx][tmpy++]=0;
for (int i=1;i<=h;i++)
for (int j=1;j<=w;j++)
if (mm[i][j]) {printf("NO");return 0;}
printf("YES");
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 47c91fb918a8bc0e803fcec82af447eb | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include<stdio.h>
#include<stdlib.h>
#include <stdbool.h>
#define max_ll 18
#define max_s 505
char* in;
char** arr;
// BEGIN_TEMPLATE
// BEGIN_HEADER
int solve();
// END_HEADER
typedef struct pair {
long long x;
long long y;
} pair;
int main(){
solve();
}
// END_TEMPLATE
pair dir[]={
{.x=1,.y=0},
{.x=0,.y=1},
{.x=-1,.y=0},
{.x=0,.y=-1}
};
int solve(){
long long x, y;
in = malloc(max_ll * sizeof(char));
fgets(in, max_ll, stdin);
sscanf(in, "%lld %lld", &x, &y);
free(in);
arr = malloc(x * sizeof(char*));
for(int i = 0; i < x; ++i){
in = malloc(max_s * sizeof(char));
fgets(in, max_s, stdin);
*(arr+i) = in;
}
bool ada = false;
for(int i = 1; i < x-1; ++i){
for(int j = 1; j < y-1;++j){
if(*(*(arr+i)+j)=='*'){
int count = 0;
for(int k = 0; k < 4; ++k){
if(*(*(arr+i+dir[k].x)+j+dir[k].y)=='*'){
count++;
}
}
if(count == 4){
ada = true;
*(*(arr+i)+j) = '.';
for(int k = 0; k < 4; ++k){
long long ban = 1;
while(
i+dir[k].x*ban >= 0 && i+dir[k].x*ban < x &&
j+dir[k].y*ban >=0 && j+dir[k].y*ban < y &&
*(*(arr+i+dir[k].x*ban)+j+dir[k].y*ban)=='*'
){
*(*(arr+i+dir[k].x*ban)+j+dir[k].y*ban) = '.';
ban++;
}
}
goto san;
}
}
}
}
san:;
if(!ada) goto san2;
for(int i = 0; i < x; ++i){
for(int j = 0; j < y; ++j){
if(*(*(arr+i)+j)=='*'){
san2:;
printf("NO\n");
return 0;
}
}
}
printf("YES\n");
for(int i = 0; i < x; ++i){
free(*(arr+i));
}
free(arr);
} | |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 590511d5b6c6c9ad1db398d529c22d8c | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include <stdio.h>
int main()
{
int row, col;
scanf("%d %d", &row, &col);
int d[row][col];
char tmp[col+1];
for(int i = 0; i < row; i++)
{
scanf("%s", tmp);
for(int j = 0; j < col; j++)
d[i][j] = (tmp[j] == '*' ? 1 : 0);
}
/* for(int i = 0; i < row; i++)
{
for(int j = 0; j < col; j++)
printf("%d ", d[i][j]);
printf("\n");
}*/
char hasStar = 0;
int starX = -1, starY = -1;
for(int i = 1; i < row-1; i++)
{
for(int j = 1; j < col-1; j++)
{
if(d[i][j]*d[i+1][j]*d[i-1][j]*d[i][j+1]*d[i][j-1] == 1)
{
starX = i, starY = j;
if(hasStar == 1)
{
printf("NO\n");
return 0;
}
else
hasStar = 1;
}
}
}
if(hasStar == 0)
{
printf("NO\n");
return 0;
}
int cnt = 1;
for(int i = starX+1; i < row; i++)
if(d[i][starY] == 1)
cnt++;
else
break;
for(int i = starX-1; i >= 0; i--)
if(d[i][starY] == 1)
cnt++;
else
break;
for(int i = starY+1; i < col; i++)
if(d[starX][i] == 1)
cnt++;
else
break;
for(int i = starY-1; i >= 0; i--)
if(d[starX][i] == 1)
cnt++;
else
break;
int sum = 0;
for(int i = 0; i < row; i++)
for(int j = 0; j < col; j++)
sum += d[i][j];
if(sum == cnt)
printf("YES\n");
else
printf("NO\n");
return 0;
} | |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 0b9a712b929d4b5c12f751e65d95f1b5 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include<stdio.h>
int main()
{
int w,h,i,j,k,d[505][505],q,p,l;
char c[505][505];
scanf("%d %d",&w,&h);
getchar();
for(i=0;i<w;i++){
for(j=0;j<h;j++)
scanf("%c",&c[i][j]);
getchar();
}
for(i=0;i<w;i++){
for(j=0;j<h;j++)
d[i][j]=0;
}
q=0;
p=0;
for(i=1;i<w-1;i++){
for(j=1;j<h-1;j++){
if(c[i][j]=='*' && c[i][j+1]=='*' && c[i][j-1]=='*' && c[i-1][j]=='*' && c[i+1][j]=='*'){
q=1;
d[i][j]=1;
for(l=i+1;l<w;l++){
if(c[l][j]=='.')
break;
d[l][j]=1;
}
for(l=i-1;l>=0;l--){
if(c[l][j]=='.')
break;
d[l][j]=1;
}
for(l=j+1;l<h;l++){
if(c[i][l]=='.')
break;
d[i][l]=1;
}
for(l=j-1;l>=0;l--){
if(c[i][l]=='.')
break;
d[i][l]=1;
}
break;
}
}
if(q==1)
break;
}
if(q==0)
printf("NO");
else{
for(i=0;i<w;i++){
for(j=0;j<h;j++){
if(d[i][j]==0 && c[i][j]=='*'){
p=1;
break;
}
}
if(p==1)
break;
}
if(p==1)
printf("NO");
else
printf("YES");
}
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 7333754e99ffdd62ab2a81a45f759a03 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include <stdio.h>
int h, w;
int grid[500][500];
int checkgrid(int x, int y){
// printf("%d %d %d %d %d\n", grid[x][y], grid[x-1][y], grid[x+1][y], grid[x][y-1], grid[x][y+1]);
if(grid[x][y] && grid[x-1][y] && grid[x+1][y] && grid[x][y-1] && grid[x][y+1])
return 1;
return 0;
}
void trace(int x, int y){
int i, j;
for(i=x+1, j=y; i<h && grid[i][j]; i++)
grid[i][j] = 0;
for(i=x-1, j=y; i>=0 && grid[i][j]; i--)
grid[i][j] = 0;
for(i=x, j=y+1; j<w && grid[i][j]; j++)
grid[i][j] = 0;
for(i=x, j=y-1; j>=0 && grid[i][j]; j--)
grid[i][j] = 0;
grid[x][y] = 0;
}
int exist_isolated(){
int i, j;
for(i=0; i<h; i++){
for(j=0; j<w; j++){
if(grid[i][j])
return 1;
}
}
return 0;
}
int main () {
scanf("%d %d", &h, &w);
int i, j;
char str[w+1];
for(i=0; i < h; i++){
scanf("%s", str);
for(j=0; j < w; j++){
if(str[j] == '.'){
grid[i][j] = 0;
}
else{
grid[i][j] = 1;
}
}
}
// for(i=0; i < h; i++){
// for(j=0; j < w; j++){
// printf("%d", grid[i][j]);
// }
// printf("\n");
// }
// printf("checkgrid: %d\n", checkgrid(2, 2));
int flag = 0;
for(i=1; i<h-1; i++){
for(j=1; j<w-1; j++){
if(checkgrid(i, j)){
flag++;
if(flag > 1)
break;
trace(i, j);
}
}
if(flag > 1)
break;
}
if(flag == 2 || flag == 0) {
printf("NO\n");
}
else {
if(exist_isolated())
printf("NO\n");
else
printf("YES\n");
}
return 0;
} | |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 8f17704e908ae38c6d3c613cd3bf2aa8 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include<stdio.h>
int main()
{
int h,r,i,q=0,p=0,u=0,v=0,w,x;
scanf("%d %d",&h,&r);
char s[h+1][r+1];
for(i=0;i<h;i=i+1)
{
scanf("%s",&s[i]);
int k=0;
while(s[i][k]!=0)
{
if(s[i][k]=='*')
{
q=q+1;
}
k=k+1;
}
}
for(i=0;i<h;i=i+1)
{
int j=0;
while(s[i][j]!=0)
{
if(s[i][j]=='*' && s[i][j+1]=='*' && v==0)
{
v=1;
j=j+1;
}
if(v==1 && s[i-1][j]=='*' && s[i+1][j]=='*')
{
u=1;
w=i;
x=j;
break;
}
j=j+1;
}
if(v==1 && u==0)
{
printf("NO\n");
break;
}
if(v==1 && u==1)
{
break;
}
}
if(v==0 && u==0)
{
printf("NO\n");
}
if(u==1 && v==1)
{
for(i=w;i>=0;i=i-1)
{
if(s[i][x]=='*')
{
p=p+1;
}
else
{
break;
}
}
for(i=w+1;i<h;i=i+1)
{
if(s[i][x]=='*')
{
p=p+1;
}
else
{
break;
}
}
for(i=x;i>=0;i=i-1)
{
if(s[w][i]=='*')
{
p=p+1;
}
else
{
break;
}
}
for(i=x+1;i<r;i=i+1)
{
if(s[w][i]=='*')
{
p=p+1;
}
else
{
break;
}
}
p=p-1;
//printf("%d %d ",p,q);
if(p==q && p>=5)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
} | |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 96809776e21eba7fa6ffb236c1e4a6b8 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include <stdio.h>
#include <stdlib.h>
int H,W;
int cnt=0,plus=0;
char **m;
int isPlus(int h,int w){
if(h<=0||h>=H-1) return 0;
if(w<=0||w>=W-1) return 0;
if(m[h][w]=='*'&&m[h-1][w]=='*'&&m[h+1][w]=='*'&&m[h][w-1]=='*'&&m[h][w+1]=='*') return 1;
return 0;
}
void dfsH(int h,int w){
if(m[h][w]=='*'){
m[h][w]='.';cnt--;
if(w>0) dfsH(h,w-1);
if(w<W-1) dfsH(h,w+1);
}
}
void dfsV(int h,int w){
if(m[h][w]=='*'){
m[h][w]='.';cnt--;
if(h>0) dfsV(h-1,w);
if(h<H-1) dfsV(h+1,w);
}
}
int main(void){
int i,j;
scanf("%d %d",&H,&W);
m=(char**)calloc(H,sizeof(char*));
for(i=0;i<H;i++){
m[i]=(char*)calloc(W+1,sizeof(char));
scanf("%s",m[i]);
}
for(i=0;i<H;i++){
for(j=0;j<W;j++){
if(m[i][j]=='*'){
cnt++;
}
}
}
for(i=0;i<H;i++){
for(j=0;j<W;j++){
if(m[i][j]=='*'){
if(isPlus(i,j)){
plus++;
dfsH(i,j);
m[i][j]='*';cnt++;
dfsV(i,j);
}
}
}
}
if(plus==1&&cnt==0) puts("YES");
else puts("NO");
for(i=0;i<H;i++) free(m[i]);
free(m);
return 0;
} | |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 99a258e647e8048ef4eae60a936e9a92 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include<stdio.h>
int main()
{
char s[501][501]={'\0'};
int n,m,scnt=0,f=0,l=0,r=0;
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
scanf("%s",s[i]);
for(int i=0;i<n;i++)
{
for (int j=0;j<m;j++)
{
if(s[i][j]=='*')
scnt++;
}
}
for(int i=1;i<n-1&&f==0;i++)
{
for (int j=1;j<m-1;j++)
{
if(s[i][j]=='*'&&s[i][j+1]=='*'&&s[i][j-1]=='*'&&s[i+1][j]=='*'&&s[i-1][j]=='*')
{
l=i;
r=j;
f=1;
break;
}
}}
if(f==1)
{
int left=0, right=0,up=0,down=0;
for(int i=l-1;s[i][r]=='*';i--)
left++;
for(int i=l+1;s[i][r]=='*';i++)
right++;
for(int j=r-1;s[l][j]=='*';j--)
up++;
for(int j=r+1;s[l][j]=='*';j++)
down++;
if(left+right+up+down+1==scnt)
printf("%s","YES");
else
printf("%s","NO");
}
else
printf("%s","NO");
return 0;
} | |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 426baf4f71b87688b0e9e1dc2b7788e1 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include<stdio.h>
#include<string.h>
int main(void)
{
#ifdef test
freopen("in.txt","r",stdin);
#endif // test
int n,m,t=0,x,y,cnt=0,flag=0;
scanf("%d%d",&n,&m);
char s[n][m];
for(int i=0;i<n;i++)
scanf("%s",s[i]);
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(s[i][j]=='*')cnt++;
if(s[i][j]=='*'&&i>=1&&j>=1&&i<n-1&&j<m-1&&s[i-1][j]=='*'&&s[i+1][j]=='*'&&s[i][j-1]=='*'&&s[i][j+1]=='*')x=i,y=j,flag++;
}
}
if(flag==1)
{
int i=x,j=y;
while(s[i][j]!='.'&&i>=0)
if(s[i][j]=='*')t++,i--;
i=x+1,j=y;
while(s[i][j]!='.'&&i<n)
if(s[i][j]=='*')t++,i++;
i=x,j=y+1;
while(s[i][j]!='.'&&j<m)
if(s[i][j]=='*')t++,j++;
i=x,j=y-1;
while(s[i][j]!='.'&&j>=0)
if(s[i][j]=='*')t++,j--;
if(t==cnt)printf("YES\n");
else printf("NO\n");
}
else printf("NO\n");
return 0;
}
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 2de8b90d66b16e92cfe0665edba57d78 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | // make it in c
#include <stdio.h>
int image[505][505];
void artiyibul(int i, int j)
{
int i1 = i + 2, j1 = j + 2;
image[i][j] = 1;
image[i + 1][j] = 1;
image[i - 1][j] = 1;
image[i][j + 1] = 1;
image[i][j - 1] = 1;
while(1)
{
if (image[i1][j] == 42)
{
image[i1][j] = 1;
i1++;
}
else
break;
}
while(1)
{
if (image[i][j1] == 42)
{
image[i][j1] = 1;
j1++;
}
else
break;
}
i1 = i - 2;
j1 = j - 2;
while(1)
{
if (image[i1][j] == 42)
{
image[i1][j] = 1;
i1--;
}
else
break;
}
while(1)
{
if (image[i][j1] == 42)
{
image[i][j1] = 1;
j1--;
}
else
break;
}
}
int main()
{
int i, j, height, width, answer = 0, checkothers = 0;
char x;
scanf (" %d %d", &height, &width);
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
scanf (" %c", &x);
image[i][j] = x;
}
}
for (i = 1; i < height - 1; i++)
{
for (j = 1; j < width - 1; j++)
{
if (image[i][j] == 42)
{
if (image[i + 1][j] == 42 && image[i - 1][j] == 42 && image[i][j + 1] == 42 && image[i][j - 1] == 42)
{
answer++;
artiyibul (i, j);
checkothers++;
}
//
// else
// {
// printf("NO");
// return 0;
// }
}
if (checkothers == 1)
break;
}
if (checkothers == 1)
break;
}
if (checkothers == 1)
for (i = 0; i < height; i++)
for (j = 0; j < width; j++)
if (image[i][j] == 42)
{
printf("NO");
return 0;
}
if (checkothers == 1)
printf("YES");
else
printf("NO");
return 0;
}
//#include <iostream>
//#include <vector>
//using namespace std;
//
//int x, y, a, b, answer = 0, p;
//
//int main()
//{
// cin >> a >> b;
//
// vector < char > image[b];
//
// for (x = 0; x < a; x++)
// for (y = 0; y < b; y++)
// {
// cin >> p;
// image[x].push_back(p);
// }
//
// for (x = 0; x < a; x++)
// for (y = 0; y < b; y++)
// cout << image[x][y];
//
// for (x = 1; x < a - 1; x++)
// {
// for (y = 1; y < b - 1; y++)
// {
// if (image[x][y] == "*")
// if (image[x + 1][y] == "*" && image[x - 1][y] == "*" && image[x][y + 1] == "*" && image[x][y - 1] == "*")
// answer++;
// }
// }
//}
//
| |
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape. | If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower). | C | 6405161be280fea943201fa00ef6f448 | 2820858dd815e80d0a4878ecb02f6f09 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"dfs and similar",
"strings"
] | 1560258300 | ["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."] | NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape. | PASSED | 1,300 | standard input | 1 second | The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space. | ["YES", "NO", "NO", "NO", "NO", "NO"] | #include<stdio.h>
char matrix[507][507];
int main()
{
int w, h;
scanf("%d%d", &h, &w);
for(int i = 1; i <= h; i++)
for(int j = 1; j <= w; j++)
scanf(" %c", &matrix[i][j]);
int count = 0;
int r, c;
if(w <= 2 || h <= 2)
{
printf("%s", "NO");
return 0;
}
for(int i = 2; i < h; i++)
for(int j = 2; j < w; j++)
{
if(matrix[i][j] == '*' && matrix[i-1][j] == '*' && matrix[i+1][j] == '*' && matrix[i][j-1] == '*' && matrix[i][j+1] == '*')
{
r = i;
c = j;
count++;
}
if(count > 1 )
{
printf("%s", "NO");
return 0;
}
}
//printf("%d %d\n", r, c);
for(int i = 1; i <= h; i++)
for(int j = 1; j <= w; j++)
{
if(r!=i && c!=j && matrix[i][j] == '*')
{
printf("%s", "NO");
return 0;
}
}
if( count == 1 )
{
int flag = 0;
for(int j = 1; j <= w; j++)
{
if(flag == 1 && matrix[r][j] == '*' )
{
printf("%s", "NO");
return 0;
}
if(matrix[r][j] == '*' && j<w && matrix[r][j+1] == '.')
flag = 1;
}
flag = 0;
for(int i = 1; i <= h; i++)
{
if(flag == 1 && matrix[i][c] == '*' )
{
printf("%s", "NO");
return 0;
}
if(matrix[i][c] == '*' && i<h && matrix[i+1][c] == '.')
flag = 1;
}
}
if(count == 0 )
printf("%s", "NO");
else
printf("%s", "YES");
return 0;
}
| |
You are given three integers $$$x, y$$$ and $$$n$$$. Your task is to find the maximum integer $$$k$$$ such that $$$0 \le k \le n$$$ that $$$k \bmod x = y$$$, where $$$\bmod$$$ is modulo operation. Many programming languages use percent operator % to implement it.In other words, with given $$$x, y$$$ and $$$n$$$ you need to find the maximum possible integer from $$$0$$$ to $$$n$$$ that has the remainder $$$y$$$ modulo $$$x$$$.You have to answer $$$t$$$ independent test cases. It is guaranteed that such $$$k$$$ exists for each test case. | For each test case, print the answer — maximum non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$ and $$$k \bmod x = y$$$. It is guaranteed that the answer always exists. | C | 2589e832f22089fac9ccd3456c0abcec | 5e3de3592be99dd56abdbfa2ca77fcbc | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"math"
] | 1593354900 | ["7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999"] | NoteIn the first test case of the example, the answer is $$$12339 = 7 \cdot 1762 + 5$$$ (thus, $$$12339 \bmod 7 = 5$$$). It is obvious that there is no greater integer not exceeding $$$12345$$$ which has the remainder $$$5$$$ modulo $$$7$$$. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines contain test cases. The only line of the test case contains three integers $$$x, y$$$ and $$$n$$$ ($$$2 \le x \le 10^9;~ 0 \le y < x;~ y \le n \le 10^9$$$). It can be shown that such $$$k$$$ always exists under the given constraints. | ["12339\n0\n15\n54306\n999999995\n185\n999999998"] | #include<stdio.h>
#include<math.h>
int main()
{
long long int t,a,b,c;
scanf("%lld",&t);
while(t--)
{
scanf("%lld %lld %lld",&a,&b,&c);
printf("%lld\n",(c-b)/a*a+b);
}
} | |
You are given three integers $$$x, y$$$ and $$$n$$$. Your task is to find the maximum integer $$$k$$$ such that $$$0 \le k \le n$$$ that $$$k \bmod x = y$$$, where $$$\bmod$$$ is modulo operation. Many programming languages use percent operator % to implement it.In other words, with given $$$x, y$$$ and $$$n$$$ you need to find the maximum possible integer from $$$0$$$ to $$$n$$$ that has the remainder $$$y$$$ modulo $$$x$$$.You have to answer $$$t$$$ independent test cases. It is guaranteed that such $$$k$$$ exists for each test case. | For each test case, print the answer — maximum non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$ and $$$k \bmod x = y$$$. It is guaranteed that the answer always exists. | C | 2589e832f22089fac9ccd3456c0abcec | aa90bb7f5f6b97f904e3c97d27c5e1d1 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"math"
] | 1593354900 | ["7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999"] | NoteIn the first test case of the example, the answer is $$$12339 = 7 \cdot 1762 + 5$$$ (thus, $$$12339 \bmod 7 = 5$$$). It is obvious that there is no greater integer not exceeding $$$12345$$$ which has the remainder $$$5$$$ modulo $$$7$$$. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines contain test cases. The only line of the test case contains three integers $$$x, y$$$ and $$$n$$$ ($$$2 \le x \le 10^9;~ 0 \le y < x;~ y \le n \le 10^9$$$). It can be shown that such $$$k$$$ always exists under the given constraints. | ["12339\n0\n15\n54306\n999999995\n185\n999999998"] | #include <stdio.h>
int main()
{
int test_cases;
scanf("%d", &test_cases);
long int ans[test_cases], x, y, n;
for(int i = 0; i < test_cases; ++i)
{
scanf("%ld %ld %ld", &x, &y, &n);
int k = (n/x)*x;
k = k+y > n ? k+y-x : k+y;
ans[i] = k;
}
for(int i = 0; i < test_cases; ++i)
{
printf("%ld\n", ans[i]);
}
return 0;
} | |
You are given three integers $$$x, y$$$ and $$$n$$$. Your task is to find the maximum integer $$$k$$$ such that $$$0 \le k \le n$$$ that $$$k \bmod x = y$$$, where $$$\bmod$$$ is modulo operation. Many programming languages use percent operator % to implement it.In other words, with given $$$x, y$$$ and $$$n$$$ you need to find the maximum possible integer from $$$0$$$ to $$$n$$$ that has the remainder $$$y$$$ modulo $$$x$$$.You have to answer $$$t$$$ independent test cases. It is guaranteed that such $$$k$$$ exists for each test case. | For each test case, print the answer — maximum non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$ and $$$k \bmod x = y$$$. It is guaranteed that the answer always exists. | C | 2589e832f22089fac9ccd3456c0abcec | 3125c3ee4eb71c8e967bcede330cdb65 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"math"
] | 1593354900 | ["7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999"] | NoteIn the first test case of the example, the answer is $$$12339 = 7 \cdot 1762 + 5$$$ (thus, $$$12339 \bmod 7 = 5$$$). It is obvious that there is no greater integer not exceeding $$$12345$$$ which has the remainder $$$5$$$ modulo $$$7$$$. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines contain test cases. The only line of the test case contains three integers $$$x, y$$$ and $$$n$$$ ($$$2 \le x \le 10^9;~ 0 \le y < x;~ y \le n \le 10^9$$$). It can be shown that such $$$k$$$ always exists under the given constraints. | ["12339\n0\n15\n54306\n999999995\n185\n999999998"] | #include<stdio.h>
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int x,y,n;
scanf("%d%d%d",&x,&y,&n);
int temp,t1,k1;
temp=n%x;
if(temp>=y)
{
t1=(n/x);
k1=(t1*x)+y;
}
else
{
t1=(n/x);
t1--;
k1=(t1*x)+y;
}
printf("%d\n",k1);
}
} | |
You are given three integers $$$x, y$$$ and $$$n$$$. Your task is to find the maximum integer $$$k$$$ such that $$$0 \le k \le n$$$ that $$$k \bmod x = y$$$, where $$$\bmod$$$ is modulo operation. Many programming languages use percent operator % to implement it.In other words, with given $$$x, y$$$ and $$$n$$$ you need to find the maximum possible integer from $$$0$$$ to $$$n$$$ that has the remainder $$$y$$$ modulo $$$x$$$.You have to answer $$$t$$$ independent test cases. It is guaranteed that such $$$k$$$ exists for each test case. | For each test case, print the answer — maximum non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$ and $$$k \bmod x = y$$$. It is guaranteed that the answer always exists. | C | 2589e832f22089fac9ccd3456c0abcec | b5f943112c37cb978ba0eb1c439a1aea | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"math"
] | 1593354900 | ["7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999"] | NoteIn the first test case of the example, the answer is $$$12339 = 7 \cdot 1762 + 5$$$ (thus, $$$12339 \bmod 7 = 5$$$). It is obvious that there is no greater integer not exceeding $$$12345$$$ which has the remainder $$$5$$$ modulo $$$7$$$. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines contain test cases. The only line of the test case contains three integers $$$x, y$$$ and $$$n$$$ ($$$2 \le x \le 10^9;~ 0 \le y < x;~ y \le n \le 10^9$$$). It can be shown that such $$$k$$$ always exists under the given constraints. | ["12339\n0\n15\n54306\n999999995\n185\n999999998"] | #include<stdio.h>
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int x,y,n;
scanf("%d%d%d",&x,&y,&n);
int temp,t1,k;
temp=n%x;
if(temp>=y)
{
t1=(n/x);
k=(t1*x)+y;
}
else
{
t1=(n/x);
t1--;
k=(t1*x)+y;
}
printf("%d\n",k);
}
} | |
You are given three integers $$$x, y$$$ and $$$n$$$. Your task is to find the maximum integer $$$k$$$ such that $$$0 \le k \le n$$$ that $$$k \bmod x = y$$$, where $$$\bmod$$$ is modulo operation. Many programming languages use percent operator % to implement it.In other words, with given $$$x, y$$$ and $$$n$$$ you need to find the maximum possible integer from $$$0$$$ to $$$n$$$ that has the remainder $$$y$$$ modulo $$$x$$$.You have to answer $$$t$$$ independent test cases. It is guaranteed that such $$$k$$$ exists for each test case. | For each test case, print the answer — maximum non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$ and $$$k \bmod x = y$$$. It is guaranteed that the answer always exists. | C | 2589e832f22089fac9ccd3456c0abcec | d5866731c9ae2adc3ab6c6cf3a68542f | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"math"
] | 1593354900 | ["7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999"] | NoteIn the first test case of the example, the answer is $$$12339 = 7 \cdot 1762 + 5$$$ (thus, $$$12339 \bmod 7 = 5$$$). It is obvious that there is no greater integer not exceeding $$$12345$$$ which has the remainder $$$5$$$ modulo $$$7$$$. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines contain test cases. The only line of the test case contains three integers $$$x, y$$$ and $$$n$$$ ($$$2 \le x \le 10^9;~ 0 \le y < x;~ y \le n \le 10^9$$$). It can be shown that such $$$k$$$ always exists under the given constraints. | ["12339\n0\n15\n54306\n999999995\n185\n999999998"] | #include<stdio.h>
int main()
{
long long int t,n,x,y,p,q;
scanf("%lld",&t);
while(t--){
scanf("%lld %lld %lld",&x,&y,&n);
p=n/x;q=n%x;
if(q>=y) printf("%lld\n",(p*x)+y);
else printf("%lld\n",(p-1)*x+y);
}
return 0;
} | |
You are given three integers $$$x, y$$$ and $$$n$$$. Your task is to find the maximum integer $$$k$$$ such that $$$0 \le k \le n$$$ that $$$k \bmod x = y$$$, where $$$\bmod$$$ is modulo operation. Many programming languages use percent operator % to implement it.In other words, with given $$$x, y$$$ and $$$n$$$ you need to find the maximum possible integer from $$$0$$$ to $$$n$$$ that has the remainder $$$y$$$ modulo $$$x$$$.You have to answer $$$t$$$ independent test cases. It is guaranteed that such $$$k$$$ exists for each test case. | For each test case, print the answer — maximum non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$ and $$$k \bmod x = y$$$. It is guaranteed that the answer always exists. | C | 2589e832f22089fac9ccd3456c0abcec | 085b5001fd2e172a83b5bd8921fb1608 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"math"
] | 1593354900 | ["7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999"] | NoteIn the first test case of the example, the answer is $$$12339 = 7 \cdot 1762 + 5$$$ (thus, $$$12339 \bmod 7 = 5$$$). It is obvious that there is no greater integer not exceeding $$$12345$$$ which has the remainder $$$5$$$ modulo $$$7$$$. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines contain test cases. The only line of the test case contains three integers $$$x, y$$$ and $$$n$$$ ($$$2 \le x \le 10^9;~ 0 \le y < x;~ y \le n \le 10^9$$$). It can be shown that such $$$k$$$ always exists under the given constraints. | ["12339\n0\n15\n54306\n999999995\n185\n999999998"] | #include <stdio.h>
int main(void) {
int t;
long int x, y, n;
scanf("%d", &t);
while (t) {
scanf(" %ld %ld %ld", &x, &y, &n);
printf("%ld\n", ((n - y)/x)*x + y);
t--;
}
return 0;
}
| |
You are given three integers $$$x, y$$$ and $$$n$$$. Your task is to find the maximum integer $$$k$$$ such that $$$0 \le k \le n$$$ that $$$k \bmod x = y$$$, where $$$\bmod$$$ is modulo operation. Many programming languages use percent operator % to implement it.In other words, with given $$$x, y$$$ and $$$n$$$ you need to find the maximum possible integer from $$$0$$$ to $$$n$$$ that has the remainder $$$y$$$ modulo $$$x$$$.You have to answer $$$t$$$ independent test cases. It is guaranteed that such $$$k$$$ exists for each test case. | For each test case, print the answer — maximum non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$ and $$$k \bmod x = y$$$. It is guaranteed that the answer always exists. | C | 2589e832f22089fac9ccd3456c0abcec | 1e1fb76557c97d8f071dbd90a93943ae | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"math"
] | 1593354900 | ["7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999"] | NoteIn the first test case of the example, the answer is $$$12339 = 7 \cdot 1762 + 5$$$ (thus, $$$12339 \bmod 7 = 5$$$). It is obvious that there is no greater integer not exceeding $$$12345$$$ which has the remainder $$$5$$$ modulo $$$7$$$. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines contain test cases. The only line of the test case contains three integers $$$x, y$$$ and $$$n$$$ ($$$2 \le x \le 10^9;~ 0 \le y < x;~ y \le n \le 10^9$$$). It can be shown that such $$$k$$$ always exists under the given constraints. | ["12339\n0\n15\n54306\n999999995\n185\n999999998"] | #include<stdio.h>
int main()
{
int n,a,b,c,d=0,e=0;
scanf("%d",&n);
while(n--) {
scanf("%d %d %d",&a, &b, &c);
d=(c-b)/a;
e=d*a+b;
printf("%d\n",e);
}
return 0;
} | |
You are given three integers $$$x, y$$$ and $$$n$$$. Your task is to find the maximum integer $$$k$$$ such that $$$0 \le k \le n$$$ that $$$k \bmod x = y$$$, where $$$\bmod$$$ is modulo operation. Many programming languages use percent operator % to implement it.In other words, with given $$$x, y$$$ and $$$n$$$ you need to find the maximum possible integer from $$$0$$$ to $$$n$$$ that has the remainder $$$y$$$ modulo $$$x$$$.You have to answer $$$t$$$ independent test cases. It is guaranteed that such $$$k$$$ exists for each test case. | For each test case, print the answer — maximum non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$ and $$$k \bmod x = y$$$. It is guaranteed that the answer always exists. | C | 2589e832f22089fac9ccd3456c0abcec | 30a09f2a0f2ae9b21fec5f38e84ddc2c | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"math"
] | 1593354900 | ["7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999"] | NoteIn the first test case of the example, the answer is $$$12339 = 7 \cdot 1762 + 5$$$ (thus, $$$12339 \bmod 7 = 5$$$). It is obvious that there is no greater integer not exceeding $$$12345$$$ which has the remainder $$$5$$$ modulo $$$7$$$. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines contain test cases. The only line of the test case contains three integers $$$x, y$$$ and $$$n$$$ ($$$2 \le x \le 10^9;~ 0 \le y < x;~ y \le n \le 10^9$$$). It can be shown that such $$$k$$$ always exists under the given constraints. | ["12339\n0\n15\n54306\n999999995\n185\n999999998"] | #include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
for(int i=0;i<t;i++)
{
int x,y,n,w,p;
scanf("%d%d%d",&x,&y,&n);
int c=0;
w=n/x;
p=w*x;
p=p+y;
if(p<=n)
{
c=p;
}
else{
w=w-1;
p=w*x;
c=p+y;
}
printf("%d\n",c);
}
} | |
You are given three integers $$$x, y$$$ and $$$n$$$. Your task is to find the maximum integer $$$k$$$ such that $$$0 \le k \le n$$$ that $$$k \bmod x = y$$$, where $$$\bmod$$$ is modulo operation. Many programming languages use percent operator % to implement it.In other words, with given $$$x, y$$$ and $$$n$$$ you need to find the maximum possible integer from $$$0$$$ to $$$n$$$ that has the remainder $$$y$$$ modulo $$$x$$$.You have to answer $$$t$$$ independent test cases. It is guaranteed that such $$$k$$$ exists for each test case. | For each test case, print the answer — maximum non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$ and $$$k \bmod x = y$$$. It is guaranteed that the answer always exists. | C | 2589e832f22089fac9ccd3456c0abcec | df01e96a4ad07dcd6cf4066ee70be88d | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"math"
] | 1593354900 | ["7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999"] | NoteIn the first test case of the example, the answer is $$$12339 = 7 \cdot 1762 + 5$$$ (thus, $$$12339 \bmod 7 = 5$$$). It is obvious that there is no greater integer not exceeding $$$12345$$$ which has the remainder $$$5$$$ modulo $$$7$$$. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines contain test cases. The only line of the test case contains three integers $$$x, y$$$ and $$$n$$$ ($$$2 \le x \le 10^9;~ 0 \le y < x;~ y \le n \le 10^9$$$). It can be shown that such $$$k$$$ always exists under the given constraints. | ["12339\n0\n15\n54306\n999999995\n185\n999999998"] | #include<stdio.h>
int main()
{
int x, y, n, a, t;
scanf("%d", &t);
while(t--)
{
scanf("%d %d %d", &x, &y, &n);
a = n % x;
if (n - a + y <= n)
{
printf("%d\n", n - a + y);
}
else
{
printf("%d\n", n - a - x + y);
}
}
return 0;
} | |
You are given three integers $$$x, y$$$ and $$$n$$$. Your task is to find the maximum integer $$$k$$$ such that $$$0 \le k \le n$$$ that $$$k \bmod x = y$$$, where $$$\bmod$$$ is modulo operation. Many programming languages use percent operator % to implement it.In other words, with given $$$x, y$$$ and $$$n$$$ you need to find the maximum possible integer from $$$0$$$ to $$$n$$$ that has the remainder $$$y$$$ modulo $$$x$$$.You have to answer $$$t$$$ independent test cases. It is guaranteed that such $$$k$$$ exists for each test case. | For each test case, print the answer — maximum non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$ and $$$k \bmod x = y$$$. It is guaranteed that the answer always exists. | C | 2589e832f22089fac9ccd3456c0abcec | bafb373f3d0affdc20ebbb3df14f5c6e | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"math"
] | 1593354900 | ["7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999"] | NoteIn the first test case of the example, the answer is $$$12339 = 7 \cdot 1762 + 5$$$ (thus, $$$12339 \bmod 7 = 5$$$). It is obvious that there is no greater integer not exceeding $$$12345$$$ which has the remainder $$$5$$$ modulo $$$7$$$. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines contain test cases. The only line of the test case contains three integers $$$x, y$$$ and $$$n$$$ ($$$2 \le x \le 10^9;~ 0 \le y < x;~ y \le n \le 10^9$$$). It can be shown that such $$$k$$$ always exists under the given constraints. | ["12339\n0\n15\n54306\n999999995\n185\n999999998"] | #include <stdio.h>
int main(){
int t,x,y,n,k,i,rem;
scanf("%d",&t);
while(t--){
scanf("%d %d %d",&x,&y,&n);
rem=(n-y)/x*x+y;
printf("%d\n",rem);
}
return 0;
} | |
You are given three integers $$$x, y$$$ and $$$n$$$. Your task is to find the maximum integer $$$k$$$ such that $$$0 \le k \le n$$$ that $$$k \bmod x = y$$$, where $$$\bmod$$$ is modulo operation. Many programming languages use percent operator % to implement it.In other words, with given $$$x, y$$$ and $$$n$$$ you need to find the maximum possible integer from $$$0$$$ to $$$n$$$ that has the remainder $$$y$$$ modulo $$$x$$$.You have to answer $$$t$$$ independent test cases. It is guaranteed that such $$$k$$$ exists for each test case. | For each test case, print the answer — maximum non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$ and $$$k \bmod x = y$$$. It is guaranteed that the answer always exists. | C | 2589e832f22089fac9ccd3456c0abcec | 6507d49c033d90779649272763726a62 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"math"
] | 1593354900 | ["7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999"] | NoteIn the first test case of the example, the answer is $$$12339 = 7 \cdot 1762 + 5$$$ (thus, $$$12339 \bmod 7 = 5$$$). It is obvious that there is no greater integer not exceeding $$$12345$$$ which has the remainder $$$5$$$ modulo $$$7$$$. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines contain test cases. The only line of the test case contains three integers $$$x, y$$$ and $$$n$$$ ($$$2 \le x \le 10^9;~ 0 \le y < x;~ y \le n \le 10^9$$$). It can be shown that such $$$k$$$ always exists under the given constraints. | ["12339\n0\n15\n54306\n999999995\n185\n999999998"] | #include<stdio.h>
int main()
{
int test;
scanf("%d",&test);
while(test--)
{
int x,y,n,ans;
scanf("%d%d%d",&x,&y,&n);
ans=(n-y)/x*x+y;
printf("%d\n",ans);
}
} | |
You are given three integers $$$x, y$$$ and $$$n$$$. Your task is to find the maximum integer $$$k$$$ such that $$$0 \le k \le n$$$ that $$$k \bmod x = y$$$, where $$$\bmod$$$ is modulo operation. Many programming languages use percent operator % to implement it.In other words, with given $$$x, y$$$ and $$$n$$$ you need to find the maximum possible integer from $$$0$$$ to $$$n$$$ that has the remainder $$$y$$$ modulo $$$x$$$.You have to answer $$$t$$$ independent test cases. It is guaranteed that such $$$k$$$ exists for each test case. | For each test case, print the answer — maximum non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$ and $$$k \bmod x = y$$$. It is guaranteed that the answer always exists. | C | 2589e832f22089fac9ccd3456c0abcec | 8708ed617085b6c1f474e322f805ad06 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"math"
] | 1593354900 | ["7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999"] | NoteIn the first test case of the example, the answer is $$$12339 = 7 \cdot 1762 + 5$$$ (thus, $$$12339 \bmod 7 = 5$$$). It is obvious that there is no greater integer not exceeding $$$12345$$$ which has the remainder $$$5$$$ modulo $$$7$$$. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines contain test cases. The only line of the test case contains three integers $$$x, y$$$ and $$$n$$$ ($$$2 \le x \le 10^9;~ 0 \le y < x;~ y \le n \le 10^9$$$). It can be shown that such $$$k$$$ always exists under the given constraints. | ["12339\n0\n15\n54306\n999999995\n185\n999999998"] |
static inline int max_remainder(int x, int y, int n){
int res;
for (int k = n; k >= 0; k){
res = k%x;
if (res == y) {
return k;
}
else if (res < y){
k += -x + (y - res);
} else {
k += -(res - y);
}
}
}
int main(){
int t;
scanf("%d\n", &t);
int x, y, n;
// double start = get_wall_time();
for (int i = 0; i < t; i++){
scanf("%d %d %d\n", &x, &y, &n);
printf("%d\n", max_remainder(x, y, n));
}
// double end = get_wall_time();
// printf("Time: %f\n", end - start);
} | |
You are given three integers $$$x, y$$$ and $$$n$$$. Your task is to find the maximum integer $$$k$$$ such that $$$0 \le k \le n$$$ that $$$k \bmod x = y$$$, where $$$\bmod$$$ is modulo operation. Many programming languages use percent operator % to implement it.In other words, with given $$$x, y$$$ and $$$n$$$ you need to find the maximum possible integer from $$$0$$$ to $$$n$$$ that has the remainder $$$y$$$ modulo $$$x$$$.You have to answer $$$t$$$ independent test cases. It is guaranteed that such $$$k$$$ exists for each test case. | For each test case, print the answer — maximum non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$ and $$$k \bmod x = y$$$. It is guaranteed that the answer always exists. | C | 2589e832f22089fac9ccd3456c0abcec | 0c6ab5cd44cc8b5705d48e4dbd1984b0 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"math"
] | 1593354900 | ["7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999"] | NoteIn the first test case of the example, the answer is $$$12339 = 7 \cdot 1762 + 5$$$ (thus, $$$12339 \bmod 7 = 5$$$). It is obvious that there is no greater integer not exceeding $$$12345$$$ which has the remainder $$$5$$$ modulo $$$7$$$. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines contain test cases. The only line of the test case contains three integers $$$x, y$$$ and $$$n$$$ ($$$2 \le x \le 10^9;~ 0 \le y < x;~ y \le n \le 10^9$$$). It can be shown that such $$$k$$$ always exists under the given constraints. | ["12339\n0\n15\n54306\n999999995\n185\n999999998"] | static inline int max_remainder(int x, int y, int n){
int res;
int k = n;
res = k%x;
if (res == y) {
return k;
}
else if (res < y){
k += -x + (y - res);
} else {
k += -(res - y);
}
return k;
}
int main(){
int t;
scanf("%d\n", &t);
int x, y, n;
// double start = get_wall_time();
for (int i = 0; i < t; i++){
scanf("%d %d %d\n", &x, &y, &n);
printf("%d\n", max_remainder(x, y, n));
}
// double end = get_wall_time();
// printf("Time: %f\n", end - start);
} | |
You are given three integers $$$x, y$$$ and $$$n$$$. Your task is to find the maximum integer $$$k$$$ such that $$$0 \le k \le n$$$ that $$$k \bmod x = y$$$, where $$$\bmod$$$ is modulo operation. Many programming languages use percent operator % to implement it.In other words, with given $$$x, y$$$ and $$$n$$$ you need to find the maximum possible integer from $$$0$$$ to $$$n$$$ that has the remainder $$$y$$$ modulo $$$x$$$.You have to answer $$$t$$$ independent test cases. It is guaranteed that such $$$k$$$ exists for each test case. | For each test case, print the answer — maximum non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$ and $$$k \bmod x = y$$$. It is guaranteed that the answer always exists. | C | 2589e832f22089fac9ccd3456c0abcec | e55ac07c6e0599f75d525d216599de0c | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"math"
] | 1593354900 | ["7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999"] | NoteIn the first test case of the example, the answer is $$$12339 = 7 \cdot 1762 + 5$$$ (thus, $$$12339 \bmod 7 = 5$$$). It is obvious that there is no greater integer not exceeding $$$12345$$$ which has the remainder $$$5$$$ modulo $$$7$$$. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines contain test cases. The only line of the test case contains three integers $$$x, y$$$ and $$$n$$$ ($$$2 \le x \le 10^9;~ 0 \le y < x;~ y \le n \le 10^9$$$). It can be shown that such $$$k$$$ always exists under the given constraints. | ["12339\n0\n15\n54306\n999999995\n185\n999999998"] | #include "stdio.h"
/*print the answer � maximum non-negative integer k such that 0=k=n and kmodx=y.
It is guaranteed that the answer always exists*/
int main()
{
int x, y, n;
int N = 0;
// printf("Enter loop number \n");
scanf("%d", &N);
while (N > 0){
scanf("%d", &x);
scanf("%d", &y);
scanf("%d", &n);
// printf("x = %d y= %d n = %d\n", x, y,n );
if (x == 0){
printf("%s\n", "x is zero, no answer");
return -1;
}
int k = (n / x ) *x ;
if (k + y <= n){
// printf("Result k is %d\n", k+y);
printf("%d\n", k+y);
}else{
// printf("Result k is %d\n", k -x +y);
printf("%d\n", k -x +y);
}
N --; //next value
}
}
| |
You are given three integers $$$x, y$$$ and $$$n$$$. Your task is to find the maximum integer $$$k$$$ such that $$$0 \le k \le n$$$ that $$$k \bmod x = y$$$, where $$$\bmod$$$ is modulo operation. Many programming languages use percent operator % to implement it.In other words, with given $$$x, y$$$ and $$$n$$$ you need to find the maximum possible integer from $$$0$$$ to $$$n$$$ that has the remainder $$$y$$$ modulo $$$x$$$.You have to answer $$$t$$$ independent test cases. It is guaranteed that such $$$k$$$ exists for each test case. | For each test case, print the answer — maximum non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$ and $$$k \bmod x = y$$$. It is guaranteed that the answer always exists. | C | 2589e832f22089fac9ccd3456c0abcec | 1fbed911cff4d89726f6ec9622c9d679 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"math"
] | 1593354900 | ["7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999"] | NoteIn the first test case of the example, the answer is $$$12339 = 7 \cdot 1762 + 5$$$ (thus, $$$12339 \bmod 7 = 5$$$). It is obvious that there is no greater integer not exceeding $$$12345$$$ which has the remainder $$$5$$$ modulo $$$7$$$. | PASSED | 800 | standard input | 1 second | The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^4$$$) — the number of test cases. The next $$$t$$$ lines contain test cases. The only line of the test case contains three integers $$$x, y$$$ and $$$n$$$ ($$$2 \le x \le 10^9;~ 0 \le y < x;~ y \le n \le 10^9$$$). It can be shown that such $$$k$$$ always exists under the given constraints. | ["12339\n0\n15\n54306\n999999995\n185\n999999998"] | #include <stdio.h>
#define ll long long int
int main ()
{
ll x,y,n;
int t;
scanf ("%d",&t);
while (t--)
{
scanf ("%lld %lld %lld",&x,&y,&n);
if (n%x<y)n-=y;
ll p = n/x;
ll a = p*x+y;
printf ("%lld\n",a);
}
return 0;} | |
A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not.A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points.You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. | Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. | C | e63de0fffd00b2da103545a7f1e405be | 628800d77522eccab5239eced337924c | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1379691000 | ["5\n0 1 3 4 2"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n integers a0, a1, ..., an - 1 — the given permutation. | ["3"] | #include<stdio.h>
int main()
{
long long int t,i;
long long int a[1000000];
long long int fp=0,np=0,dp=0;
scanf("%lld",&t);
for(i=0;i<t;i++)
{
scanf("%lld",&a[i]);
}
for(i=0;i<t;i++)
{
if(a[i]==i)
fp++;
else
{
if(a[a[i]]==i)
dp++;
else
np++;
}
// printf ("%lld %lld\n", fp, np);
}
if(dp>0)
fp+=2;
else if (np>0)
fp++;
printf("%lld\n",fp);
return 0;
}
| |
A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not.A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points.You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. | Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. | C | e63de0fffd00b2da103545a7f1e405be | cc9fad1ba65975751f9c34aa9c8d4309 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1379691000 | ["5\n0 1 3 4 2"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n integers a0, a1, ..., an - 1 — the given permutation. | ["3"] | #include<stdio.h>
#include<stdbool.h>
int main(){
int n;
int i;
int a[100000];
int count=0;
bool swap=false;
bool xu=true;
scanf("%d", &n);
for(i=0; i<n; i++){
if(i==(n-1))
scanf("%d", &a[i]);
else
scanf("%d ", &a[i]);
}
for(i=0; i<n; i++){
if(a[i]==i)
count++;
else{
xu=false;
if(!swap&&a[a[i]]==i){
count+=2;
swap=true;
}
}
}
if(!swap)
if(!xu)
count++;
if(n==1)
if(a[0]==0)
count=1;
else
count=0;
printf("%d\n", count);
return 0;
}
| |
A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not.A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points.You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. | Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. | C | e63de0fffd00b2da103545a7f1e405be | 51462e24504d05cc0c76fa6177aab7a4 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1379691000 | ["5\n0 1 3 4 2"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n integers a0, a1, ..., an - 1 — the given permutation. | ["3"] | #include<stdio.h>
int main()
{
int n,s,a[100001],i,t,d,c;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
s=1;
c=0;
for(t=0;t<n;t++)
{
if(a[t]==t)
{
c++;
}
else if(s==1)
{
d=a[t];
if(a[d]==t)
{
c=c+2;
s--;
}
}
if(t==(n-1) && s==1)
{
if(c<n)
c++;
}
}
printf("%d",c);
return 0;
} | |
A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not.A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points.You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. | Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. | C | e63de0fffd00b2da103545a7f1e405be | 66d6d220db6ed079058ae31c15083e58 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1379691000 | ["5\n0 1 3 4 2"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n integers a0, a1, ..., an - 1 — the given permutation. | ["3"] | #include <stdio.h>
int main()
{
int n;
char ch;
scanf("%d", &n);
int a[n], fixp=0, x=0,i,j;
for (i=0; i<n; i++){
scanf("%d", &a[i]);
if (a[i]==i) fixp++;
ch=getchar();
}
for (i=0; i<n; i++){
if (a[i]==i) continue;
j=a[i];
if (a[j]==i) {x=1; break;}
}
if (x) printf("%d", fixp+2);
else if (!x && fixp!=n) printf("%d", fixp+1);
else printf("%d", fixp);
return 0;
}
| |
A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not.A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points.You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. | Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. | C | e63de0fffd00b2da103545a7f1e405be | 96690c0a3bdf38073d93ddb0725b3671 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1379691000 | ["5\n0 1 3 4 2"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n integers a0, a1, ..., an - 1 — the given permutation. | ["3"] | #include <stdio.h>
#define MAXN 100001
int num[MAXN];
int maxnum=0;
int exd=0;
int main (void)
{
int i,n;
scanf ("%d",&n);
for(i=0;i<n;i++) {
scanf ("%d",&num[i]);
}
for(i=0;i<n;i++) {
if (i==num[i]) ++maxnum;
else if (num[num[i]]==i) ++exd;
}
if (exd>0)
printf ("%d",maxnum+2);
else if (maxnum==n)
printf ("%d",maxnum);
else
printf ("%d",++maxnum);
return 0;
}
| |
A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not.A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points.You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. | Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. | C | e63de0fffd00b2da103545a7f1e405be | 765b9dd02282dd5be1664444c8b56106 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1379691000 | ["5\n0 1 3 4 2"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n integers a0, a1, ..., an - 1 — the given permutation. | ["3"] | #include<stdio.h>
int se[100009];
int main()
{
int n,i,s,ar[100009],c=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&ar[i]);
if(ar[i]==i)
{
se[i]=1;
c++;
}
}
s=c;
if(c<n)
{
for(i=0;i<n;i++)
{
if(se[i]!=1 && ar[ar[i]]==i)
{
c+=2;
break;
}
}
}
if(s==c && c<n)
c++;
printf("%d\n",c);
return 0;
}
| |
You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string s so that for any prime number p ≤ |s| and for any integer i ranging from 1 to |s| / p (inclusive) the following condition was fulfilled sp = sp × i. If the answer is positive, find one way to rearrange the characters. | If it is possible to rearrange the characters in the string so that the above-mentioned conditions were fulfilled, then print in the first line "YES" (without the quotes) and print on the second line one of the possible resulting strings. If such permutation is impossible to perform, then print the single string "NO". | C | 64700ca85ef3b7408d7d7ad1132f8f81 | 57010ad857cc18d46d64afa12b23d671 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"number theory",
"strings"
] | 1320333000 | ["abc", "abcd", "xxxyxxx"] | NoteIn the first sample any of the six possible strings will do: "abc", "acb", "bac", "bca", "cab" or "cba".In the second sample no letter permutation will satisfy the condition at p = 2 (s2 = s4).In the third test any string where character "y" doesn't occupy positions 2, 3, 4, 6 will be valid. | PASSED | 1,300 | standard input | 1 second | The only line contains the initial string s, consisting of small Latin letters (1 ≤ |s| ≤ 1000). | ["YES\nabc", "NO", "YES\nxxxxxxy"] | #include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
char eq[1024];
int n;
char s[1024];
char t[1024];
int f[26];
#define MAXP 65536
char sieve[MAXP];
int prime[6542];
int primes;
void createsieve() {
int i,j,q;
memset(sieve,1,sizeof(sieve));
q=sqrt(MAXP);
for(sieve[0]=sieve[1]=0,i=2;i<q;i++) if(sieve[i])
for(j=i*i;j<MAXP;j+=i) sieve[j]=0;
}
void genprimes() {
int i;
for(primes=i=0;i<MAXP;i++) if(sieve[i]) prime[primes++]=i;
}
int main() {
int i,j,eqn=0;
memset(eq,0,sizeof(eq));
createsieve();
genprimes();
scanf("%s",s);
n=strlen(s);
for(i=0;i<26;i++) f[i]=0;
for(i=0;i<n;i++) f[s[i]-'a']++;
for(i=0;i<primes;i++) if(prime[i]*2<=n) for(j=1;prime[i]*j<=n;j++) eq[prime[i]*j-1]=1;
for(i=0;i<n;i++) if(eq[i]) eqn++;
for(i=0;i<26;i++) if(eqn<=f[i]) break;
if(i==26) { puts("NO"); return 0; }
memset(t,0,sizeof(t));
for(j=0;j<n;j++) if(eq[j]) t[j]=i+'a',f[i]--;
for(i=j=0;j<n;j++) if(!eq[j]) {
while(!f[i]) i++;
t[j]='a'+i;
f[i]--;
}
puts("YES");
puts(t);
return 0;
}
| |
You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string s so that for any prime number p ≤ |s| and for any integer i ranging from 1 to |s| / p (inclusive) the following condition was fulfilled sp = sp × i. If the answer is positive, find one way to rearrange the characters. | If it is possible to rearrange the characters in the string so that the above-mentioned conditions were fulfilled, then print in the first line "YES" (without the quotes) and print on the second line one of the possible resulting strings. If such permutation is impossible to perform, then print the single string "NO". | C | 64700ca85ef3b7408d7d7ad1132f8f81 | 5d409ce43e8183b1d17383883e456fdc | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"number theory",
"strings"
] | 1320333000 | ["abc", "abcd", "xxxyxxx"] | NoteIn the first sample any of the six possible strings will do: "abc", "acb", "bac", "bca", "cab" or "cba".In the second sample no letter permutation will satisfy the condition at p = 2 (s2 = s4).In the third test any string where character "y" doesn't occupy positions 2, 3, 4, 6 will be valid. | PASSED | 1,300 | standard input | 1 second | The only line contains the initial string s, consisting of small Latin letters (1 ≤ |s| ≤ 1000). | ["YES\nabc", "NO", "YES\nxxxxxxy"] | #include<stdio.h>
#include<string.h>
#define MAX 1010
int graph[MAX][MAX];
int isprime(int n)
{
int i;
for(i=2;i<n;i++){
if((n%i)==0)
return 0;
}
return 1;
}
int visited[MAX];
int group[MAX][MAX];
int pos;
int dfs(int node,int n,int cnt)
{
int size=1,i;
if(visited[node]==1)
return 0;
group[cnt][pos]=node;
pos++;
visited[node]=1;
for(i=1;i<=n;i++)
if((graph[i][node]==1)&& (visited[i]==0))
size+=dfs(i,n,cnt);
return size;
}
struct {
char c;
int cnt;
}alph['z'-'a'+1],tmp;
void hist(char *in)
{
int i,j;
for(i=0;i<26;i++){
alph[i].c='a'+i;
alph[i].cnt=0;
}
while(*in){
alph[*in-'a'].cnt++;
in++;
}
for(i=0;i<26;i++)
for(j=i+1;j<26;j++)
if(alph[i].cnt<alph[j].cnt){
tmp=alph[i];
alph[i]=alph[j];
alph[j]=tmp;
}
}
int main()
{
int i,ptr,p,len,cnt=0,n,j;
char in[MAX],string[MAX];
char ans;
int grp[MAX],tmp[MAX];
scanf("%s",in);
n=len=strlen(in);
for(p=2;p<len;p++)
if(isprime(p))
for(i=p*2;i<=len;i+=p)
graph[p][i]=graph[i][p]=1;
cnt=0;
for(i=1;i<=n;i++){
pos=0;
grp[cnt]=dfs(i,n,cnt);
if(grp[cnt])
cnt++;
}
int k,jkl;
for(i=0;i<cnt;i++)
for(j=i+1;j<cnt;j++)
if(grp[i]<grp[j]){
for(k=0;k<grp[i];k++)
tmp[k]=group[i][k];
jkl=grp[i];
for(k=0;k<grp[j];k++)
group[i][k]=group[j][k];
grp[i]=grp[j];
for(k=0;k<jkl;k++)
group[j][k]=tmp[k];
grp[j]=jkl;
}
hist(in);
ans='y';
ptr=0;
for(i=0;i<cnt;i++){
if(alph[ptr].cnt<grp[i]){
ans='n';
break;
}
else{
alph[ptr].cnt-=grp[i];
for(j=0;j<grp[i];j++){
string[group[i][j]-1]=alph[ptr].c;
}
if((i+1<cnt)&&(alph[ptr].cnt<grp[i+1]))
ptr++;
}
}
printf("%s\n",((ans=='y')?"YES":"NO"));
string[len]='\0';
if(ans=='y')
printf("%s\n",string);
return 0;
}
| |
You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string s so that for any prime number p ≤ |s| and for any integer i ranging from 1 to |s| / p (inclusive) the following condition was fulfilled sp = sp × i. If the answer is positive, find one way to rearrange the characters. | If it is possible to rearrange the characters in the string so that the above-mentioned conditions were fulfilled, then print in the first line "YES" (without the quotes) and print on the second line one of the possible resulting strings. If such permutation is impossible to perform, then print the single string "NO". | C | 64700ca85ef3b7408d7d7ad1132f8f81 | 13c40a2aecc2bc211100cc65d5d2920f | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"number theory",
"strings"
] | 1320333000 | ["abc", "abcd", "xxxyxxx"] | NoteIn the first sample any of the six possible strings will do: "abc", "acb", "bac", "bca", "cab" or "cba".In the second sample no letter permutation will satisfy the condition at p = 2 (s2 = s4).In the third test any string where character "y" doesn't occupy positions 2, 3, 4, 6 will be valid. | PASSED | 1,300 | standard input | 1 second | The only line contains the initial string s, consisting of small Latin letters (1 ≤ |s| ≤ 1000). | ["YES\nabc", "NO", "YES\nxxxxxxy"] | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct {
int x;
int y;
} count;
int par[1000];
int find(int x)
{
if (par[x] == x) {
return x;
} else {
return par[x] = find(par[x]);
}
}
void unite(int x, int y)
{
x = find(x);
y = find(y);
if (x == y) return;
par[x] = y;
}
int cmp(const void *a, const void *b)
{
return ((count *)b)->x - ((count *)a)->x;
}
int main()
{
char s1[1001], s2[1001];
int n, i, j, k;
int a[26] = {0};
int b[1001] = {0};
count c[1001];
scanf("%s", s1);
n = strlen(s1);
for (i = 0; i < n; i++) a[s1[i] - 'a']++;
for (i = 0; i < n; i++) par[i] = i;
for (i = 2; i < n; i++) {
if (b[i] == 0) {
for (j = i * 2; j <= n; j += i) b[j] = 1;
for (j = 2; j <= n / i; j++) unite(i - 1, i * j - 1);
}
}
for (i = 0; i < n; i++) {
c[i].x = 0;
c[i].y = i;
}
for (i = 0; i < n; i++) c[find(i)].x++;
qsort(c, n, sizeof(count), cmp);
for (i = 0; i < n; i++) {
if (c[i].x == 0) break;
for (j = 0; j < 26; j++) {
if (a[j] >= c[i].x) break;
}
if (j == 26) {
puts("NO");
return 0;
}
for (k = 0; k < n; k++) {
if (find(k) == c[i].y) {
s2[k] = 'a' + j;
a[j]--;
}
}
}
s2[n] = '\0';
puts("YES");
printf("%s\n", s2);
return 0;
}
| |
You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string s so that for any prime number p ≤ |s| and for any integer i ranging from 1 to |s| / p (inclusive) the following condition was fulfilled sp = sp × i. If the answer is positive, find one way to rearrange the characters. | If it is possible to rearrange the characters in the string so that the above-mentioned conditions were fulfilled, then print in the first line "YES" (without the quotes) and print on the second line one of the possible resulting strings. If such permutation is impossible to perform, then print the single string "NO". | C | 64700ca85ef3b7408d7d7ad1132f8f81 | 50315eb9dbf8ea800ee7266ada0fd3c6 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"number theory",
"strings"
] | 1320333000 | ["abc", "abcd", "xxxyxxx"] | NoteIn the first sample any of the six possible strings will do: "abc", "acb", "bac", "bca", "cab" or "cba".In the second sample no letter permutation will satisfy the condition at p = 2 (s2 = s4).In the third test any string where character "y" doesn't occupy positions 2, 3, 4, 6 will be valid. | PASSED | 1,300 | standard input | 1 second | The only line contains the initial string s, consisting of small Latin letters (1 ≤ |s| ≤ 1000). | ["YES\nabc", "NO", "YES\nxxxxxxy"] | #include <stdio.h>
#include <string.h>
char ans[1001];
char s[1001];
int a[1001];
int b[1001];
int c[26];
int p[1001];
int q[1001];
int init() {
int i, j, m = 0;
memset(q, 0, sizeof(q));
for (i = 2; i <= 1000; i ++) {
if (q[i] == 0) {
p[m ++] = i;
for (j = i << 1; j <= 1000; j += i) {
q[j] = 1;
}
}
}
return m;
}
void func(int m) {
int n = strlen(s), i, j, k, t = 0, h;
memset(c, 0, sizeof(c));
for (i = 0; i < n; i ++) {
c[s[i] - 'a'] ++;
}
memset(b, -1, n * sizeof(int));
for (i = 0; i < m && p[i] <= n; i ++) {
for (j = 1; j <= n / p[i]; j ++) {
if (b[p[i] * j - 1] != -1) {
break;
}
}
if (j <= n / p[i]) {
k = b[p[i] * j - 1];
for (j = 1; j <= n / p[i]; j ++) {
if (b[p[i] * j - 1] == -1) {
b[p[i] * j - 1] = k;
}
}
}
else {
for (j = 1; j <= n / p[i]; j ++) {
b[p[i] * j - 1] = t;
}
t ++;
}
}
memset(a, 0, t * sizeof(int));
for (i = 0; i < n; i ++) {
a[b[i]] ++;
}
for (i = 0; i < t; i ++) {
k = 2000;
h = -1;
for (j = 0; j < 26; j ++) {
if (c[j] >= a[i] && c[j] < k) {
k = c[j];
h = j;
}
}
if (k == 2000) {
printf("NO\n");
return;
}
for (j = 0; j < n; j ++) {
if (b[j] == i) {
ans[j] = h + 'a';
}
}
c[h] -= a[i];
}
for (i = 0; i < 26; i ++) {
if (c[i] == 1) {
ans[0] = i + 'a';
break;
}
}
ans[n] = '\0';
printf("YES\n%s\n", ans);
}
int main() {
int m;
m = init();
while (scanf("%s", s) == 1) {
func(m);
}
return 0;
} | |
You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string s so that for any prime number p ≤ |s| and for any integer i ranging from 1 to |s| / p (inclusive) the following condition was fulfilled sp = sp × i. If the answer is positive, find one way to rearrange the characters. | If it is possible to rearrange the characters in the string so that the above-mentioned conditions were fulfilled, then print in the first line "YES" (without the quotes) and print on the second line one of the possible resulting strings. If such permutation is impossible to perform, then print the single string "NO". | C | 64700ca85ef3b7408d7d7ad1132f8f81 | 452810ddcfb746efcdaec1ae6bc5f255 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"number theory",
"strings"
] | 1320333000 | ["abc", "abcd", "xxxyxxx"] | NoteIn the first sample any of the six possible strings will do: "abc", "acb", "bac", "bca", "cab" or "cba".In the second sample no letter permutation will satisfy the condition at p = 2 (s2 = s4).In the third test any string where character "y" doesn't occupy positions 2, 3, 4, 6 will be valid. | PASSED | 1,300 | standard input | 1 second | The only line contains the initial string s, consisting of small Latin letters (1 ≤ |s| ≤ 1000). | ["YES\nabc", "NO", "YES\nxxxxxxy"] | #include <stdio.h>
#include <string.h>
char ans[1001];
char s[1001];
int a[1001];
int b[1001];
int c[26];
int p[1001];
int q[1001];
int init() {
int i, j, m = 0;
memset(q, 0, sizeof(q));
for (i = 2; i <= 1000; i ++) {
if (q[i] == 0) {
p[m ++] = i;
for (j = i << 1; j <= 1000; j += i) {
q[j] = 1;
}
}
}
return m;
}
void func(int m) {
int n = strlen(s), i, j, k, t = 0, h;
memset(c, 0, sizeof(c));
for (i = 0; i < n; i ++) {
c[s[i] - 'a'] ++;
}
memset(b, -1, n * sizeof(int));
for (i = 0; i < m && p[i] <= n; i ++) {
for (j = 1; j <= n / p[i]; j ++) {
if (b[p[i] * j - 1] != -1) {
break;
}
}
if (j <= n / p[i]) {
k = b[p[i] * j - 1];
for (j = 1; j <= n / p[i]; j ++) {
if (b[p[i] * j - 1] == -1) {
b[p[i] * j - 1] = k;
}
}
}
else {
for (j = 1; j <= n / p[i]; j ++) {
b[p[i] * j - 1] = t;
}
t ++;
}
}
memset(a, 0, t * sizeof(int));
for (i = 0; i < n; i ++) {
a[b[i]] ++;
}
for (i = 0; i < t; i ++) {
k = 2000;
h = -1;
for (j = 0; j < 26; j ++) {
if (c[j] >= a[i] && c[j] < k) {
k = c[j];
h = j;
}
}
if (k == 2000) {
printf("NO\n");
return;
}
for (j = 0; j < n; j ++) {
if (b[j] == i) {
ans[j] = h + 'a';
}
}
c[h] -= a[i];
}
for (i = 0; i < 26; i ++) {
if (c[i] == 1) {
ans[0] = i + 'a';
break;
}
}
if (i == 26) {
printf("NO\n");
return;
}
ans[n] = '\0';
printf("YES\n%s\n", ans);
}
int main() {
int m;
m = init();
while (scanf("%s", s) == 1) {
func(m);
}
return 0;
} | |
You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string s so that for any prime number p ≤ |s| and for any integer i ranging from 1 to |s| / p (inclusive) the following condition was fulfilled sp = sp × i. If the answer is positive, find one way to rearrange the characters. | If it is possible to rearrange the characters in the string so that the above-mentioned conditions were fulfilled, then print in the first line "YES" (without the quotes) and print on the second line one of the possible resulting strings. If such permutation is impossible to perform, then print the single string "NO". | C | 64700ca85ef3b7408d7d7ad1132f8f81 | c1ed9db01f97458ca9489a0f679fb34d | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"number theory",
"strings"
] | 1320333000 | ["abc", "abcd", "xxxyxxx"] | NoteIn the first sample any of the six possible strings will do: "abc", "acb", "bac", "bca", "cab" or "cba".In the second sample no letter permutation will satisfy the condition at p = 2 (s2 = s4).In the third test any string where character "y" doesn't occupy positions 2, 3, 4, 6 will be valid. | PASSED | 1,300 | standard input | 1 second | The only line contains the initial string s, consisting of small Latin letters (1 ≤ |s| ≤ 1000). | ["YES\nabc", "NO", "YES\nxxxxxxy"] | #include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
int main(){
int i,j,k,len,max,prime[1001],b[26],num;
char a[1001];
for(i=0;i<=1000;i++)prime[i]=1;
prime[0]=0;prime[1]=0;
for(i=2;i<=1000;i++)if(prime[i])for(j=i+i;j<=1000;j+=i)prime[j]=0;
while(scanf("%s",a)!=EOF){
memset(b,0,sizeof(b));
max=0;len=strlen(a);num=0;
for(i=0;i<len;i++){
if((i+1)*2>len&&prime[i+1])num++;
b[a[i]-'a']++;
if(b[a[i]-'a']>b[max])max=a[i]-'a';
}
b[max]-=len-num-1;
if(b[max]>=0){
printf("YES\n");
for(i=0;i<len;i++){
if(i==0||((i+1)*2>len&&prime[i+1])){
for(j=0;j<26;j++)if(b[j])break;
b[j]--;
printf("%c",j+'a');
}
else printf("%c",max+'a');
}
printf("\n");
}
else printf("NO\n");
}
} | |
You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string s so that for any prime number p ≤ |s| and for any integer i ranging from 1 to |s| / p (inclusive) the following condition was fulfilled sp = sp × i. If the answer is positive, find one way to rearrange the characters. | If it is possible to rearrange the characters in the string so that the above-mentioned conditions were fulfilled, then print in the first line "YES" (without the quotes) and print on the second line one of the possible resulting strings. If such permutation is impossible to perform, then print the single string "NO". | C | 64700ca85ef3b7408d7d7ad1132f8f81 | b72a64700cce015d5ad57fdb6a9f7494 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"number theory",
"strings"
] | 1320333000 | ["abc", "abcd", "xxxyxxx"] | NoteIn the first sample any of the six possible strings will do: "abc", "acb", "bac", "bca", "cab" or "cba".In the second sample no letter permutation will satisfy the condition at p = 2 (s2 = s4).In the third test any string where character "y" doesn't occupy positions 2, 3, 4, 6 will be valid. | PASSED | 1,300 | standard input | 1 second | The only line contains the initial string s, consisting of small Latin letters (1 ≤ |s| ≤ 1000). | ["YES\nabc", "NO", "YES\nxxxxxxy"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
void unionInit(int d[],int s){int i;rep(i,s)d[i]=i;}
int unionGet(int d[],int n){int t=n,k;while(d[t]!=t)t=d[t];while(d[n]!=n)k=d[n],d[n]=t,n=k;return n;}
int unionConnect(int d[],int a,int b){a=unionGet(d,a);b=unionGet(d,b);if(a==b)return 0;d[a]=b;return 1;}
int main(){
int i,j,k,l,m,n;
int ind[1001];
int num[1001], sz;
char in[1020];
int cnt[26];
int dame = 0;
while(scanf("%s",in)==1){
n = strlen(in);
rep(i,26) cnt[i] = 0;
rep(i,n) cnt[in[i]-'a']++;
rep(i,n) in[i] = 0;
unionInit(ind,n+1);
for(i=2;i<=n;i++){
for(j=2*i;j<=n;j+=i) unionConnect(ind, i, j);
}
k = 0;
REP(i,1,n+1) if(unionGet(ind,2)==unionGet(ind,i)) k++;
rep(i,26) if(cnt[i] >= k){
REP(j,1,n+1) if(unionGet(ind,2)==unionGet(ind,j)){
cnt[i]--;
in[j-1] = 'a'+i;
}
break;
}
if(i==26){puts("NO"); continue;}
rep(i,n) if(!in[i]){
rep(j,26) if(cnt[j]) break;
cnt[j]--; in[i] = j+'a';
}
puts("YES");
puts(in);
}
return 0;
}
| |
You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string s so that for any prime number p ≤ |s| and for any integer i ranging from 1 to |s| / p (inclusive) the following condition was fulfilled sp = sp × i. If the answer is positive, find one way to rearrange the characters. | If it is possible to rearrange the characters in the string so that the above-mentioned conditions were fulfilled, then print in the first line "YES" (without the quotes) and print on the second line one of the possible resulting strings. If such permutation is impossible to perform, then print the single string "NO". | C | 64700ca85ef3b7408d7d7ad1132f8f81 | 3a478bc7237d067bd0099194ed4fc429 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"number theory",
"strings"
] | 1320333000 | ["abc", "abcd", "xxxyxxx"] | NoteIn the first sample any of the six possible strings will do: "abc", "acb", "bac", "bca", "cab" or "cba".In the second sample no letter permutation will satisfy the condition at p = 2 (s2 = s4).In the third test any string where character "y" doesn't occupy positions 2, 3, 4, 6 will be valid. | PASSED | 1,300 | standard input | 1 second | The only line contains the initial string s, consisting of small Latin letters (1 ≤ |s| ≤ 1000). | ["YES\nabc", "NO", "YES\nxxxxxxy"] | #include <stdio.h>
#include <string.h>
char s[1002], ans[1002];
int n, max_p, letters[256];
void
read(void)
{
while((s[++n] = getchar()) != '\n');
--n;
int i, max = 0;
for(i = 1; i <= n; ++i){
++letters[s[i]];
}
for(i = 'a'; i <= 'z'; ++i){
if(letters[i] > max){
max = letters[i];
max_p = i;
}
}
}
int
is_prime(int p)
{
int i;
for(i = 2; i < p; ++i)
if(!(p % i)){
return 0;
}
return 1;
}
int
solve(void)
{
int i, j;
for(i = 2; i <= n / 2; ++i)
if(is_prime(i)){
int need = n / i;
for(j = 1; j <= need; ++j)
if(!ans[i * j]){
if(!letters[max_p]){
return 0;
}
ans[i * j] = max_p;
--letters[max_p];
}
}
printf("YES\n");
for(i = 1; i <= n; ++i){
if(!ans[i]){
for(j = 'a'; j <= 'z'; ++j){
if(letters[j]){
ans[i] = j;
letters[j]--;
break;
}
}
}
printf("%c", ans[i]);
}
return 1;
}
int
main(void)
{
read();
if (!solve()){
printf("NO");
}
return 0;
}
| |
You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string s so that for any prime number p ≤ |s| and for any integer i ranging from 1 to |s| / p (inclusive) the following condition was fulfilled sp = sp × i. If the answer is positive, find one way to rearrange the characters. | If it is possible to rearrange the characters in the string so that the above-mentioned conditions were fulfilled, then print in the first line "YES" (without the quotes) and print on the second line one of the possible resulting strings. If such permutation is impossible to perform, then print the single string "NO". | C | 64700ca85ef3b7408d7d7ad1132f8f81 | 6d672c9ae1706f9ea5d1dd519a3fa880 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"number theory",
"strings"
] | 1320333000 | ["abc", "abcd", "xxxyxxx"] | NoteIn the first sample any of the six possible strings will do: "abc", "acb", "bac", "bca", "cab" or "cba".In the second sample no letter permutation will satisfy the condition at p = 2 (s2 = s4).In the third test any string where character "y" doesn't occupy positions 2, 3, 4, 6 will be valid. | PASSED | 1,300 | standard input | 1 second | The only line contains the initial string s, consisting of small Latin letters (1 ≤ |s| ≤ 1000). | ["YES\nabc", "NO", "YES\nxxxxxxy"] | #include <stdio.h>
int prime(int);
int primelist[2000];
int main()
{
int n,i,letter[300],slong=0,max=0,maxl,lastl,k=0;
char s;
primelist[0]=1;
for(i=0;i<26;i++)
{
letter[i]=0;
}
while(scanf(" %c",&s) == 1)
{
if(s-'a' >=0 && s-'a'<=25)
{
letter[s-'a']++;
slong++;
}
}
/*printf("slong=%d\n",slong);*/
n=prime(slong);
/*for(i=0;i<=n;i++)
{
printf("%d ",primelist[i]);
}
printf("\n");*/
for(i=0;i<26;i++)
{
if(max<letter[i])
{
max=letter[i];
maxl=i;
}
}
for(i=0;i<26;i++)
{
if(letter[i] !=0 && i != maxl)
{
lastl=i;
break;
}
if(i == 25)
k=1;
}
/*printf("%d %d\n",maxl,lastl);*/
if(max < slong - n - 1)
{
printf("NO\n");
}
else
{
printf("YES\n");
int now=0;
for(i=0;i<slong;i++)
{
/*printf("%d\n",lastl);*/
if(k == 1)
{
printf("%c",maxl+'a');
/*system("pause");*/
}
else
{
if(i+1 == primelist[now])
{
now++;
printf("%c",lastl+'a');
if(--letter[lastl] == 0)
{
for(lastl+=1;lastl<26;lastl++)
{
if(letter[lastl] !=0 && lastl != maxl)
{
break;
}
}
if(lastl == 26)
k=1;
}
}
else
printf("%c",maxl+'a');
}
}
}
/*system("pause");*/
return 0;
}
int prime(int lens)
{
int i,j,ret=0;
for(i=lens/2+1;i<=lens;i++)
{
/*printf("i=%d\n",i);*/
for(j=2;j*j<=i;j++)
{
/*printf("j=%d\n",j);*/
if(i%j == 0)
break;
}
if(j*j > i)
{
primelist[ret+1]=i;
ret++;
}
}
return ret;
}
/****** PCCA -Sat Nov 19 05:43:15 GMT 2011 *******/ | |
You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string s so that for any prime number p ≤ |s| and for any integer i ranging from 1 to |s| / p (inclusive) the following condition was fulfilled sp = sp × i. If the answer is positive, find one way to rearrange the characters. | If it is possible to rearrange the characters in the string so that the above-mentioned conditions were fulfilled, then print in the first line "YES" (without the quotes) and print on the second line one of the possible resulting strings. If such permutation is impossible to perform, then print the single string "NO". | C | 64700ca85ef3b7408d7d7ad1132f8f81 | 1a7d1032f07926d416aff9adcf22ff30 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"number theory",
"strings"
] | 1320333000 | ["abc", "abcd", "xxxyxxx"] | NoteIn the first sample any of the six possible strings will do: "abc", "acb", "bac", "bca", "cab" or "cba".In the second sample no letter permutation will satisfy the condition at p = 2 (s2 = s4).In the third test any string where character "y" doesn't occupy positions 2, 3, 4, 6 will be valid. | PASSED | 1,300 | standard input | 1 second | The only line contains the initial string s, consisting of small Latin letters (1 ≤ |s| ≤ 1000). | ["YES\nabc", "NO", "YES\nxxxxxxy"] | #include <stdio.h>
#include <string.h>
int main() {
char s[1001];
gets(s);
int n = strlen(s);
int i, j, pn = 0, p[1000];
for (i = 2; i <= n; i++) {
for (j = 0; j < pn; j++)
if (i % p[j] == 0)
break;
if (j == pn)
p[pn++] = i;
}
int c = 1;
for (i = 0; i < pn; i++)
if (2*p[i] > n)
c++;
int lc[200], m = -1, ml;
memset(lc, 0, sizeof(lc));
for (i = 0; i < n; i++) {
lc[s[i]]++;
if (lc[s[i]] > m) {
m = lc[s[i]];
ml = s[i];
}
}
if (n - c <= m) {
puts("YES");
char ss[2000];
memset(ss, 0, sizeof(ss));
for (i = 0; i < pn; i++)
if (2*p[i] <= n)
for (j = p[i]; j <= n; j += p[i])
if (ss[j-1] == 0) {
ss[j-1] = ml;
lc[ml]--;
}
char l = 'a';
for (i = 0; i < n; i++)
if (ss[i] == 0) {
while (lc[l] == 0)
l++;
ss[i] = l;
lc[l]--;
}
ss[n] = '\0';
puts(ss);
} else
puts("NO");
return 0;
}
| |
You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string s so that for any prime number p ≤ |s| and for any integer i ranging from 1 to |s| / p (inclusive) the following condition was fulfilled sp = sp × i. If the answer is positive, find one way to rearrange the characters. | If it is possible to rearrange the characters in the string so that the above-mentioned conditions were fulfilled, then print in the first line "YES" (without the quotes) and print on the second line one of the possible resulting strings. If such permutation is impossible to perform, then print the single string "NO". | C | 64700ca85ef3b7408d7d7ad1132f8f81 | 66f7fa359db4ddae52b9592dd406e26c | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"number theory",
"strings"
] | 1320333000 | ["abc", "abcd", "xxxyxxx"] | NoteIn the first sample any of the six possible strings will do: "abc", "acb", "bac", "bca", "cab" or "cba".In the second sample no letter permutation will satisfy the condition at p = 2 (s2 = s4).In the third test any string where character "y" doesn't occupy positions 2, 3, 4, 6 will be valid. | PASSED | 1,300 | standard input | 1 second | The only line contains the initial string s, consisting of small Latin letters (1 ≤ |s| ≤ 1000). | ["YES\nabc", "NO", "YES\nxxxxxxy"] | #include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
int a[128],p[1111],q[1111],s,t;
char str[1111];
main(){
int i,j,m=0;
int c;
for(i=2;i<=1111;i+=2)p[i]=q[i]=1;
for(i=3;i<=1111;i+=2){
if(p[i]==0)
for(j=i*i;j<=1111;j+=i)
p[j]=1;
}
for(;c=getchar(),isalpha(c);){
a[c]++; s++;
if(a[c]>a[m]) m=c;
}
t=s/2;
for(i=3;i*2<=s;i+=2){
if(p[i]==0&&q[i]==0){
q[i]=1;t++;
for(j=i*i;j<=s;j+=i*2){
t+=q[j]==0;
q[j]=1;
}
}
}
a[m]-=t;
if(a[m]<0){
puts("NO");
return 0;
}
puts("YES");
for(i=j=1;i<=s;i++){
if(q[i]) str[i]=m;
else for(c=1;c;){
if(a[j]>0) a[j]--,str[i]=j,c=0;
else j++;
}
}
puts(str+1);
return 0;
}
| |
You have n devices that you want to use simultaneously.The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. | If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if . | C | 1c2fc9449989d14d9eb02a390f36b7a6 | 52bca662b7949769f8c470ef30adf2ba | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"binary search",
"greedy"
] | 1492356900 | ["2 1\n2 2\n2 1000", "1 100\n1 1", "3 5\n4 3\n5 2\n6 1"] | NoteIn sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.In sample test 2, you can use the device indefinitely.In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. | PASSED | 1,800 | standard input | 2 seconds | The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning. | ["2.0000000000", "-1", "0.5000000000"] | #include <stdio.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MAX_N 200000
int a[MAX_N], b[MAX_N];
int main(void) {
int n, p;
scanf("%i %i", &n, &p);
long long ta = 0;
for (int i = 0; i < n; i++) {
scanf("%i %i", &a[i], &b[i]);
ta += a[i];
}
if (ta <= p) {
puts("-1");
return 0;
}
int rep = 300;
double lo = 0.0, hi = 1e18, ans = 0.0;
while (rep--) {
double mid = (lo + hi) / 2.0;
double tot = 0.0;
for (int i = 0; i < n; i++) {
double s = mid * a[i] - b[i];
tot += MAX(0.0, s);
}
if (tot <= p * mid) {
ans = mid;
lo = mid;
} else {
hi = mid;
}
}
printf("%f\n", ans);
return 0;
} | |
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff. | Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | C | dcca7c58ba7111125608f659a577c3a2 | 869453b93e77eeb22e6f1c73e308fdd4 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1525007700 | ["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"] | NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing. | PASSED | 1,100 | standard input | 1 second | The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order. | ["6 1", "24 50", "0 0"] | #include<stdio.h>
int main()
{
int n,b,x=0,y=0,z,m,i;
scanf("%d %d",&n,&b);
int a[n],c[n],t[n];
for(i=0;i<n;i++)
{
scanf("%d %d",&a[i],&c[i]);
t[i]=a[i]*60+c[i];
}
if(t[0]>b)
{
printf("0 0");
return 0;
}
else
{
for(i=0;i<n;i++)
{
if(t[i+1]-t[i]>=2*b+2)
{
z=t[i]+b+1;
printf("%d %d",z/60,z%60);
return 0;
}
}
z=t[n-1]+b+1;
printf("%d %d",z/60,z%60);
return 0;
}
}
| |
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff. | Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | C | dcca7c58ba7111125608f659a577c3a2 | 2ea7a15b2dcbb5d322a1fcbdefca4004 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1525007700 | ["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"] | NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing. | PASSED | 1,100 | standard input | 1 second | The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order. | ["6 1", "24 50", "0 0"] | #include <stdio.h>
int main(void)
{
int i, n, s, h1, m1, t1, h2, m2, t2;
scanf("%d %d", &n, &s);
scanf("%d %d", &h1, &m1);
t1 = h1 * 60 + m1;
if (t1 >= s + 1) {
puts("0 0");
return 0;
}
for (i = 0; i < n - 1; i++) {
scanf("%d %d", &h2, &m2);
t2 = h2 * 60 + m2;
if (t2 - t1 > 2 * s + 1) {
printf("%d %d", (t1 + s + 1) / 60, (t1 + s + 1) % 60);
return 0;
}
t1 = t2;
}
printf("%d %d", (t1 + s + 1) / 60, (t1 + s + 1) % 60);
return 0;
}
| |
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff. | Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | C | dcca7c58ba7111125608f659a577c3a2 | c5aca3ff3dfe06e8416ff59ace711468 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1525007700 | ["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"] | NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing. | PASSED | 1,100 | standard input | 1 second | The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order. | ["6 1", "24 50", "0 0"] | #include <stdio.h>
int time[100];
int main()
{
int n,s,i;
scanf("%d%d",&n,&s);
int d=2*s+2;
for(i=0;i<n;i++)
{
int h,m;
scanf("%d%d",&h,&m);
time[i]=60*h+m;
}
if(time[0]>=(s+1)) printf("0 0\n");
else
{
for(i=0;i<n-1;i++)
{
if(time[i+1]-time[i]>=d)
{
int t=time[i]+s+1;
printf("%d %d\n",t/60,t%60);
break;
}
}
if(i==n-1)
{
int t=time[i]+s+1;
printf("%d %d\n",t/60,t%60);
}
}
return 0;
} | |
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff. | Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | C | dcca7c58ba7111125608f659a577c3a2 | f15542636340031892e3e9c6811c1543 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1525007700 | ["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"] | NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing. | PASSED | 1,100 | standard input | 1 second | The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order. | ["6 1", "24 50", "0 0"] | #include<stdio.h>
int main()
{
int n, s;
scanf("%d %d", &n, &s);
int a[n][2];
int i, j;
for (i=0;i<n;i++)
{
for(j=0;j<2;j++)
{
scanf("%d", &a[i][j]);
}
}
if((60*(a[0][0]))+a[0][1]>=(s+1))
{
printf("0 0");
return 0;
}
else
{
int t,h, m, h_res, m_res;
for(i=1;i<n;i++)
{
if(a[i][1]>=a[i-1][1])
{
h=a[i][0]-a[i-1][0];
m=a[i][1]-a[i-1][1];
if(((h*60)+m)>=((2*s)+2))
{
m_res=a[i-1][1]+s+1;
if(m_res>=120)
{
m_res-=120;
h_res=a[i-1][0]+2;
}
else if(m_res>=60&& m_res<120)
{
m_res-=60;
h_res=a[i-1][0]+1;
}
else
h_res=a[i-1][0];
printf("%d %d", h_res, m_res);
return 0;
}
}
else
{
m=(60+a[i][1])-a[i-1][1];
h=a[i][0]-a[i-1][0]-1;
if(((h*60)+m)>=((2*s)+2))
{
m_res=a[i-1][1]+s+1;
if(m_res>=120)
{
m_res-=120;
h_res=a[i-1][0]+2;
}
else if(m_res>=60 && m_res<120)
{
m_res-=60;
h_res=a[i-1][0]+1;
}
else
h_res=a[i-1][0];
printf("%d %d", h_res, m_res);
return 0;
}
}
}
if(i==n)
{
m_res=a[i-1][1]+s+1;
if(m_res>=120)
{
m_res-=120;
h_res=a[i-1][0]+2;
}
else if(m_res>=60&& m_res<120)
{
m_res-=60;
h_res=a[n-1][0]+1;
}
else
h_res=a[n-1][0];
printf("%d %d", h_res, m_res);
return 0;
}
}
return 0;
}
| |
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff. | Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | C | dcca7c58ba7111125608f659a577c3a2 | a03fbc32b27bff6d4d1680283e6bbe16 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1525007700 | ["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"] | NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing. | PASSED | 1,100 | standard input | 1 second | The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order. | ["6 1", "24 50", "0 0"] | #include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int n,s;
scanf("%d %d",&n,&s);
int time[n];
for(int o=0;o<n;o++)
{
int h,m;
scanf("%d %d",&h,&m);
time[o]=(60*h)+m;
}
if(s+1<=time[0])
{
printf("0 0");
exit(0);
}
for(int o=0;o<n-1;o++)
{
int diff;
diff=time[o+1]-time[o];
if(diff>=(2*s)+2)
{
int t;
t=time[o]+1+s;
printf("%d %d",t/60,t%60);
exit(0);
}
}
int y;
y=time[n-1]+s+1;
printf("%d %d",y/60,y%60);
} | |
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff. | Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | C | dcca7c58ba7111125608f659a577c3a2 | 304c68267a7266c58641b861d117c4b8 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1525007700 | ["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"] | NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing. | PASSED | 1,100 | standard input | 1 second | The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order. | ["6 1", "24 50", "0 0"] | #include<stdio.h>
int main()
{
int n,s,i,h,m,x[100],count=0;
scanf("%d%d",&n,&s);
for(i=0;i<n;i++){
scanf("%d%d",&h,&m);
x[i]=(h*60)+m;
}
if(x[0]/(s+1)>=1){
h=0;
m=0;
printf("%d %d",h,m);
count++;
}
for(i=0;i<(n-1);i++){
if(count==0){
if((x[(i+1)]-x[i])/(2*(s+1))>=1){
x[i]+=s+1;
h=x[i]/60;
m=x[i]%60;
printf("%d %d",h,m);
count++;
break;
}
}
}
if(count==0){
x[n-1]+=s+1;
h=x[i]/60;
m=x[i]%60;
printf("%d %d",h,m);
}
return 0;
}
| |
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff. | Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | C | dcca7c58ba7111125608f659a577c3a2 | 6cf3120cf49449bb827c6909a7d3b0a9 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1525007700 | ["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"] | NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing. | PASSED | 1,100 | standard input | 1 second | The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order. | ["6 1", "24 50", "0 0"] | #include<stdio.h>
int n,s,h,m,inm,a[105];
int ok(int i)
{
if((a[i]-a[i-1])>=((2*s)+2))
return 1;
return 0;
}
int main()
{
scanf("%d%d",&n,&s);
for(int i=1;i<=n;i++)
{
scanf("%d%d",&h,&m);
a[i]=(h*60)+m;
}
if(a[1]>s)
{
puts("0 0");
return 0;
}
for(int i=2;i<=n;i++)
if(ok(i))
{
inm=a[i-1]+s+1;
h=inm/60;
m=inm%60;
printf("%d %d",h,m);
return 0;
}
inm=a[n]+s+1;
h=inm/60;
m=inm%60;
printf("%d %d",h,m);
}
| |
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff. | Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | C | dcca7c58ba7111125608f659a577c3a2 | 090aa22324db18215c759b46bc9200e9 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1525007700 | ["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"] | NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing. | PASSED | 1,100 | standard input | 1 second | The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order. | ["6 1", "24 50", "0 0"] | #include <stdio.h>
int main()
{
int n,s,min;
int a[101];
scanf("%d %d",&n,&s);
for(int i=0;i<n;i++)
{
int h,m;
scanf("%d %d",&h,&m);
a[i]=60*h+m;
}
if(a[0]>=s+1)
{
printf("0 0");
return 0;
}
for(int i=0;i<n;i++)
{
if((a[i+1]-a[i])>=2*s+2)
{
min=a[i]+s+1;
printf("%d %d",min/60, min%60);
return 0;
}
}
min= a[n-1]+s+1;
printf("%d %d",min/60, min%60);
return 0;
}
| |
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff. | Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | C | dcca7c58ba7111125608f659a577c3a2 | 416a5978f63f599dd5b1fdfd645283c5 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1525007700 | ["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"] | NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing. | PASSED | 1,100 | standard input | 1 second | The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order. | ["6 1", "24 50", "0 0"] | #include<stdio.h>
int main()
{
int n,s,h,m,a=0,b,c,d,e,f;
scanf("%d %d",&n,&s);
f=2*s+2;
for(c=1;c<=n;c++)
{
scanf("%d %d",&h,&m);
b=h*60+m;
d=b-a;
if(c==1){if(d>=(s+1)) {a=a-s-1;break;}}
if(d>=f)
break;
a=b;
}
e=a+s+1;
printf("%d %d",e/60,e%60);
}
| |
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff. | Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | C | dcca7c58ba7111125608f659a577c3a2 | 6b7807ffb5f53577dbed1a6e81130560 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1525007700 | ["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"] | NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing. | PASSED | 1,100 | standard input | 1 second | The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order. | ["6 1", "24 50", "0 0"] | #include<stdio.h>
#include<stdlib.h>
int th(int i,int s,int* m,int* h){
int r =(m[i-1]+1+s)/60;
return (h[i-1]+r); }
int tm(int i,int s,int* m,int* h){
int r =(m[i-1]+1+s)%60;
return r;
}
int main(){
int n,s;
scanf("%d %d",&n,&s);
int h[n],m[n];
int d[n];
scanf("%d %d",&h[0],&m[0]);
d[0] = (h[0]-0)*60 +m[0];
for(int i=1;i<n;i++){
scanf("%d %d",&h[i],&m[i]);
int min =m[i] - m[i-1];
if((m[i] - m[i-1])<0);
min = 60+min;
d[i] = (h[i]-h[i-1])*60 +m[i] - m[i-1];
// d[i] =0;
// int t;
// while(t!=h[i]){
// d[i]
// }
}
if((d[0] - s -1)>=0){
printf("0 0");
return 0;
}
int flag=0;
for(int i=1;i<n;i++){
if(d[i]-2*s-2>=0){
// printf("%d\n",(d[i]));
// printf("%d\n",i);
printf("%d %d",th(i,s,m,h),tm(i,s,m,h));
flag =1;
break;
}
}
if(flag==0){
//printf("hello");
int r = (m[n-1]+1+s)/60;
int rm = (m[n-1]+1+s)%60;
printf("%d %d",(h[n-1]+r),(rm));
}
} | |
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff. | Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | C | dcca7c58ba7111125608f659a577c3a2 | 8a79eaa39de642692e334be95a5f6ef6 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1525007700 | ["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"] | NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing. | PASSED | 1,100 | standard input | 1 second | The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order. | ["6 1", "24 50", "0 0"] | #include <stdio.h>
#define _min(a,b) (a>=b?b:a)
int time(int h, int m) {
return m+h*60;
}
int main(void) {
int n, s;
scanf("%d %d",&n, &s);
int t[n];
for (int i=0;i<n;++i) {
int h,m;
scanf("%d %d",&h,&m);
t[i] = time(h,m);
}
int ans = t[n-1]+1+s;
for (int i=0;i<n;++i) {
if (i == 0) {
if (t[0] >= s+1) {
ans = _min(ans, 0);
break;
}
}
if (i == n-1) {
ans = _min(ans, t[i]+1+s);
}
if (i+1 < n) {
if (t[i+1] - t[i] >= 2*(s+1)) {
ans = _min(ans, t[i]+1+s);
}
}
}
int x = ans/60;
int y = ans%60;
printf("%d %d",x,y);
return 0;
} | |
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff. | Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | C | dcca7c58ba7111125608f659a577c3a2 | f51f92e98f19b2d21fc6c93ca403d281 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1525007700 | ["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"] | NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing. | PASSED | 1,100 | standard input | 1 second | The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order. | ["6 1", "24 50", "0 0"] | #include<stdio.h>
int x[101]= {0};
int y[101]= {0};
int main()
{
int n,s,h,m,i,t1,t2;
scanf("%d %d",&n,&s);
for(i=1; i<=n; i++) scanf("%d %d",&x[i],&y[i]);
t1=(x[1]*60)+y[1];
if(t1>s) printf("0 0");
else
{
for(i=1; i<=n; i++)
{
t1=(x[i-1]*60)+y[i-1];
t2=(x[i]*60)+y[i];
if(t2-t1>=(2*s)+2)
{
t1=(x[i-1]*60)+y[i-1]+s+1;
printf("%d %d",t1/60,t1%60);
return 0;
}
}
t2=(x[n]*60)+y[n]+s+1;
printf("%d %d",t2/60,t2%60);
}
return 0;
}
| |
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff. | Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | C | dcca7c58ba7111125608f659a577c3a2 | bb48af4f3feffdefb5c841dd9b117c50 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1525007700 | ["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"] | NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing. | PASSED | 1,100 | standard input | 1 second | The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order. | ["6 1", "24 50", "0 0"] | #include <stdio.h>
int main(void) {
// your code goes here
int time[200], n, s, h, sec, i;
scanf("%d %d", &n, &s);
for(i = 0; i < n; i++)
{
scanf("%d %d", &h, &sec);
time[i] = (h * 60) + sec;
}
if(time[0] > s && time[0] != 0)
{
printf("0 0");
}
else
{
for(i = 0; i < n - 1; i++)
{
if(time[i + 1] - time[i] > ((s * 2) + 1))
{
//printf("%d\n", i);
printf("%d %d", (time[i] + s + 1) / 60, (time[i] + s + 1) % 60);
break;
}
}
if(i == n - 1)
{
printf("%d %d", (time[n - 1] + s + 1) / 60, (time[n - 1] + s + 1) % 60);
}
}
return 0;
} | |
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff. | Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | C | dcca7c58ba7111125608f659a577c3a2 | 074d41923567279412e9f23a5fe0b0c9 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1525007700 | ["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"] | NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing. | PASSED | 1,100 | standard input | 1 second | The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order. | ["6 1", "24 50", "0 0"] | #include<stdio.h>
int main(){
int n,s;
scanf("%d%d",&n,&s);
int h,m,h1=0,m1=0,h2,m2,t1,t2,i;
scanf("%d%d",&h2,&m2);
/*if(h1==0 && m1==0){printf("0 2"); return 0;}*/
if(n==1){t1 = h1*60+m1; t2 = h2*60+m2;
if(t2-t1>=s+1){printf("0 0");return 0;} else {t2=t2+s+1;h = t2/60; m = t2%60;
printf("%d %d",h,m);
return 0;}
}
else if((h2*60+m2)>=(s+1)){printf("0 0"); return 0;}
else h1=h2; m1=m2;
for( i=1;i<n;i++){
scanf("%d%d",&h2,&m2);
t1 = h1*60+m1; t2 = h2*60+m2;
if(t2-t1 >= 2*s+2){
t1 = t1+s+1;
h = t1/60; m = t1%60;
printf("%d %d",h,m);
break;
}
h1 = h2; m1 = m2;
}
if(i==n){t1 = h1*60+m1+(s+1); h = t1/60; m = t1%60; printf("%d %d",h,m);}
return 0;
} | |
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $$$1$$$ minute.He was asked to insert one takeoff in the schedule. The takeoff takes $$$1$$$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $$$s$$$ minutes from both sides.Find the earliest time when Arkady can insert the takeoff. | Print two integers $$$h$$$ and $$$m$$$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | C | dcca7c58ba7111125608f659a577c3a2 | 0155710f1fea249bfb718804892271ae | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1525007700 | ["6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "3 17\n0 30\n1 0\n12 0"] | NoteIn the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $$$24$$$ hours to insert the takeoff.In the third example Arkady can insert the takeoff even between the first landing. | PASSED | 1,100 | standard input | 1 second | The first line of input contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 100$$$, $$$1 \le s \le 60$$$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $$$n$$$ lines contains two integers $$$h$$$ and $$$m$$$ ($$$0 \le h \le 23$$$, $$$0 \le m \le 59$$$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $$$0$$$ $$$0$$$). These times are given in increasing order. | ["6 1", "24 50", "0 0"] | #include<stdio.h>
int t[110];
int a[110],b[110],c[110];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int tt=(m+1);
int t1=-1,t2=-1;
int time=-1,flag=0;
for(int i=0;i<n;i++)
{
scanf("%d%d",&a[i],&b[i]);
c[i]=a[i]*60+b[i];
}
if(c[0]>=tt)
{
t1=0;
t2=0;
flag=1;
}
if(flag==0)
{
for(int i=1;i<n;i++)
{
if(c[i]-c[i-1]>=2*tt)
{
time=c[i-1]+tt;
// printf("%d\n",time);
break;
}
}
if(time==-1)
time=c[n-1]+tt;
t1=time/60;
t2=time%60;
}
printf("%d %d\n",t1,t2);
return 0;
}
/*
6 60
0 0
1 21
3 21
5 0
19 30
23 40
*/ | |
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen. | C | ff0843cbd7c3a07c7d7d0be46b03a700 | c384f95d4ee491523446de3713691014 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1468933500 | ["4\nRLRL\n2 4 6 10", "3\nLLR\n40 50 60"] | NoteIn the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | PASSED | 1,000 | standard input | 2 seconds | The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles. The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right. The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 ≤ xi ≤ 109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. | ["1", "-1"] | #include <stdio.h>
int main() {
long n, x[200001], i, min = 1111111111, temp;
char s[200001];
//freopen("input.txt", "r", stdin);
scanf("%d %s", &n, s);
for (i = 0; i < n; i++) scanf("%d", x + i);
for (i = 0; i < n; i++) {
if (s[i] == 'R' && s[i + 1] == 'L') {
temp = (x[i + 1] - x[i]) / 2;
if (min > temp) min = temp;
}
}
printf("%d", min == 1111111111 ? -1 : min);
return 0;
} | |
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen. | C | ff0843cbd7c3a07c7d7d0be46b03a700 | d07e348e920a87009bb24e9e91f838fa | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1468933500 | ["4\nRLRL\n2 4 6 10", "3\nLLR\n40 50 60"] | NoteIn the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | PASSED | 1,000 | standard input | 2 seconds | The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles. The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right. The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 ≤ xi ≤ 109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. | ["1", "-1"] | #include <stdio.h>
char a[3000000];
int k[3000000];
int main (){
int t,time=2000000000;
scanf ("%d",&t);
scanf ("%s",a);
for (int i=0;i<t;i++)
scanf ("%d",&k[i]);
for (int i=0;i<t-1;i++){
if(a[i]=='R'&&a[i+1]=='L'){
if(time>(k[i+1]-k[i])/2)
time=(k[i+1]-k[i])/2;
}
}
if(time==2000000000) printf ("-1\n");
if(time!=2000000000) printf ("%d\n",time);
return 0;
} | |
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen. | C | ff0843cbd7c3a07c7d7d0be46b03a700 | 348b430a9c2f1abbfc82b7f700159765 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1468933500 | ["4\nRLRL\n2 4 6 10", "3\nLLR\n40 50 60"] | NoteIn the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | PASSED | 1,000 | standard input | 2 seconds | The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles. The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right. The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 ≤ xi ≤ 109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. | ["1", "-1"] | #include<stdio.h>
int main(){
int n,i,index=-1;
long long smallest=100000000000000;
scanf("%d",&n);
char arr[200000];
int dis[200000];
int pos[200000];
for(i=0;i<n;i++){
scanf(" %c",&arr[i]);
}
for(i=0;i<n;i++){
scanf(" %d",&pos[i]);
}
for(i=0;i<n-1;i++){
dis[i]=pos[i+1]-pos[i];
}
for(i=0;i<n-1;i++){
if(dis[i]<smallest){
if((arr[i+1]=='L')&&(arr[i]=='R')){
smallest=dis[i];
index=dis[i]/2;
}
}
}
printf("%d",index);
}
| |
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen. | C | ff0843cbd7c3a07c7d7d0be46b03a700 | c2f94fc6653dd575df729f455e00dedc | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1468933500 | ["4\nRLRL\n2 4 6 10", "3\nLLR\n40 50 60"] | NoteIn the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | PASSED | 1,000 | standard input | 2 seconds | The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles. The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right. The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 ≤ xi ≤ 109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. | ["1", "-1"] | #include <stdio.h>
int main(void) {
int n,i,c=0;
long int a[300000],m=1000000010,t;
char s[1000000];
scanf("%d",&n);
scanf("%s",s);
for(i=0;i<n;i++)
scanf("%ld",&a[i]);
for(i=0;i<n-1;i++)
if(s[i]=='R'&&s[i+1]=='L')
{
t=a[i+1]-a[i];
if(m>t)
m=t;
}
if(m==1000000010)
{
printf("-1");
return 0;
}
printf("%ld",m/2);
return 0;
}
| |
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen. | C | ff0843cbd7c3a07c7d7d0be46b03a700 | ccf81fb22687f1dc82182adf9ed4cb2b | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1468933500 | ["4\nRLRL\n2 4 6 10", "3\nLLR\n40 50 60"] | NoteIn the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | PASSED | 1,000 | standard input | 2 seconds | The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles. The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right. The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 ≤ xi ≤ 109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. | ["1", "-1"] | #include "stdio.h"
#include "stdlib.h"
struct tt
{
char s;
int p;
}c[200002];
int main(int argc, char const *argv[])
{
int n, i;
while(~scanf("%d", &n))
{
getchar();
for(i=0;i<n;i++) scanf("%c", &c[i].s);
for(i=0;i<n;i++)
{
scanf("%d", &c[i].p);
}
int min=2147483647, k;
for(i=0;i<n-1;i++)
{
if(c[i].s=='R')
{
if(c[i+1].s=='R') continue;
else
{
k=(c[i+1].p-c[i].p)/2;
if(min>k) min=k;
}
}
}
if(min==2147483647) printf("-1\n");
else printf("%d\n", min);
}
return 0;
} | |
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen. | C | ff0843cbd7c3a07c7d7d0be46b03a700 | fb179b737ae4feb8aa556d3e299b1b83 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1468933500 | ["4\nRLRL\n2 4 6 10", "3\nLLR\n40 50 60"] | NoteIn the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | PASSED | 1,000 | standard input | 2 seconds | The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles. The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right. The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 ≤ xi ≤ 109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. | ["1", "-1"] | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char a[2000002];
long long n,b[2000001]={0},c[10000]={0},i,k,j=0,min=1000000001;
scanf("%I64d",&n);
scanf("%s",&a);
for(k=0;k<n;k++)
{
scanf("%I64d",&b[k]);
}
for(i=1;i<n;i++)
{
if(a[i-1]=='R' && a[i]=='L')
{
c[++j]=(b[i]-b[i-1]);
if(c[j]<min)
min=c[j];
}
}
if(j==0)
printf("-1");
else
{
printf("%I64d",min/2);
}
return 0;
} | |
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen. | C | ff0843cbd7c3a07c7d7d0be46b03a700 | a85b0120eb4d23a8c21ce3e20af41b00 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1468933500 | ["4\nRLRL\n2 4 6 10", "3\nLLR\n40 50 60"] | NoteIn the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | PASSED | 1,000 | standard input | 2 seconds | The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles. The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right. The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 ≤ xi ≤ 109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. | ["1", "-1"] | #include <stdio.h>
main()
{
int n,i,k=-1,diff,min=1000000000;
scanf("%d",&n);
char s[n];
scanf("%s",s);
int a[n];
if(n==2)
{
scanf("%d %d",&a[0],&a[1]);
if(s[0]=='R'&&s[1]=='L')
printf("%d",(a[1]-a[0])/2);
else
printf("-1");
}
else
{
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
diff=a[i]-a[i-1];
if(i&&min>diff&&(s[i-1]=='R'&&s[i]=='L'))
{min=diff;
k=min/2;}
}
printf("%d",k);
}
/*for(k=1;k<=max/2+1;k++)
{
for(i=0;i<n;i++)
{
if(s[i]=='L')
a[i]--;
else
a[i]++;
if(i&&a[i]==a[i-1])
{flag=1;
break;}
}
}"""
"""if(k!=-1)
printf("%d",k);
else
printf("-1");*/
} | |
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen. | C | ff0843cbd7c3a07c7d7d0be46b03a700 | 3287ca6edc2c848ae855bb5e50e45470 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1468933500 | ["4\nRLRL\n2 4 6 10", "3\nLLR\n40 50 60"] | NoteIn the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | PASSED | 1,000 | standard input | 2 seconds | The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles. The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right. The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 ≤ xi ≤ 109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. | ["1", "-1"] | #include <stdio.h>
#include <stdlib.h>
/*
input
4
RLRL
2 4 6 10
output
1
*/
int n;
int l = -1,r = -1;
int result = 0;
int time,minTime = 1<<30;
int main()
{
scanf("%d",&n);
int *pos = (int *)malloc(sizeof(int)*n);
char *direction = (char *)malloc(sizeof(char)*n);
getchar();
for(int i = 0; i < n; i++)
{
scanf("%c",&direction[i]);
}
for(int i = 0; i < n; i++)
{
scanf("%d",&pos[i]);
}
/*
for(int i = 0; i < n; i++)
{
printf("%c",direction[i]);
}
for(int i = 0; i < n; i++)
{
printf("%d ",pos[i]);
}
*/
for(int i = 0; i < n; i++)
{
if(direction[i] == 'R' && i != n-1 && direction[i+1] == 'L')
{
l = pos[i];
r = pos[i+1];
result = 1;
time = ( r - l ) / 2;
if(time < minTime)
{
minTime = time;
}
}
}
if(result)
{
printf("%d",minTime);
}
else
{
printf("-1");
}
return 0;
}
| |
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen. | C | ff0843cbd7c3a07c7d7d0be46b03a700 | 494b96888e4df25519434eefa1873436 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1468933500 | ["4\nRLRL\n2 4 6 10", "3\nLLR\n40 50 60"] | NoteIn the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | PASSED | 1,000 | standard input | 2 seconds | The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles. The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right. The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 ≤ xi ≤ 109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. | ["1", "-1"] | #include <stdio.h>
#define MAX 200007
#define MIN 1000000007
int main()
{
int n, i, len, a[MAX], min = MIN;
char str[MAX];
scanf("%d", &n);
//printf("%d\n", n);
scanf("%s", str);
//printf("%s\n", str);
for(i=0;i<n;++i)
{
scanf("%d", &a[i]);
}
for(i=0;i<n-1;++i)
{
if(str[i] == 'R' && str[i + 1] == 'L')
{
if(min > (a[i + 1] - a[i]))
{
min = (a[i + 1] - a[i]);
}
}
}
if(min == MIN)
{
printf("-1\n");
}
else
{
printf("%d\n", min / 2);
}
return 0;
}
| |
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen. | C | ff0843cbd7c3a07c7d7d0be46b03a700 | 68b0a322cee4e37c44bd7663160e84c6 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1468933500 | ["4\nRLRL\n2 4 6 10", "3\nLLR\n40 50 60"] | NoteIn the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | PASSED | 1,000 | standard input | 2 seconds | The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles. The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right. The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 ≤ xi ≤ 109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. | ["1", "-1"] | #include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <limits.h>
#define lim INT_MAX
int min(int a, int b){
return (a<b) ? a : b;
}
int main(void){
int n1;
for(; scanf("%d", &n1)!= EOF;){
char s[n1];
scanf("%s",s);
int c[n1];
/*char ch;*/
/*do{*/
/*ch = fgetc(stdin);*/
/*if(isdigit(ch)){*/
/*c[k++] = ch - 48;*/
/*}*/
/*}*/
/*while(isdigit(ch) && k < sizeof(c)/sizeof(c[0]));*/
for(int i = 0; i < n1; i++){
scanf("%d", &c[i]);
}
int time = lim;
int cnt,cnt1,count;
for(int i = 0; i < n1; i++){
if(s[i] == 'R' && s[i+1] == 'L'){
time = min(time,(c[i+1]-c[i])/2);
}
}
if(time!=lim){
printf("%d\n",time);
}
else{
printf("-1\n");
}
}
return 0;
}
| |
The Little Elephant enjoys recursive functions.This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: If x = 1, exit the function. Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. | In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. | C | d9ba1dfe11cf3dae177f8898f3abeefd | 14d91a504b3b2cec7303e079db77c78e | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"math"
] | 1346427000 | ["1", "2"] | null | PASSED | 1,000 | standard input | 2 seconds | A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. | ["1", "2 1"] | #include<stdio.h>
int main(){
int n, i;
scanf("%d", &n);
printf("%d", n);
for (i = 1 ; i < n ; ++i)
printf(" %d", i);
puts("");
return 0;
}
| |
The Little Elephant enjoys recursive functions.This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: If x = 1, exit the function. Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. | In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. | C | d9ba1dfe11cf3dae177f8898f3abeefd | 028fe39200d5c8d2bfc1d4e9d6785123 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"math"
] | 1346427000 | ["1", "2"] | null | PASSED | 1,000 | standard input | 2 seconds | A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. | ["1", "2 1"] |
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main()
{
/*long int n;
long int z;
scanf("%ld %ld",&n,&z);
int *a = (int *)malloc(n* sizeof(int));
long int i;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
long int c=0;
long int q[3];
while(z!=0)
{
scanf("%d",&q[0]);
if(q[0]==1)
{
scanf("%d",&q[1]);
a[q[1]-1]^=1;
}
else if(q[0]==0)
{
scanf("%d %d",&q[1],&q[2]);
if(a[q[2]-1]==0)
{
printf("EVEN\n");
}
else printf("ODD\n");
}
z--;
}*/
int n;
scanf("%d",&n);
printf("%d ",n);
int i;
for(i=1;i<=n-1;i++)
printf("%d ",i);
}
| |
The Little Elephant enjoys recursive functions.This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: If x = 1, exit the function. Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. | In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. | C | d9ba1dfe11cf3dae177f8898f3abeefd | f73f8432cf6d61f1c97f7e8196d27cb8 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"math"
] | 1346427000 | ["1", "2"] | null | PASSED | 1,000 | standard input | 2 seconds | A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. | ["1", "2 1"] | #include <stdio.h>
int main(){
int n;
scanf("%d",&n);
printf("%d ",n);
for(int i=1;i<n;i++) printf("%d ",i);
printf("\n");
return 0;
}
| |
The Little Elephant enjoys recursive functions.This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: If x = 1, exit the function. Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. | In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. | C | d9ba1dfe11cf3dae177f8898f3abeefd | c6a523f37776ef64e1fa0a6b728c4af3 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"math"
] | 1346427000 | ["1", "2"] | null | PASSED | 1,000 | standard input | 2 seconds | A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. | ["1", "2 1"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n, i;
scanf("%d", &n);
printf("%d", n);
for (i = 1; i < n; i++) printf(" %d", i);
printf("\n");
return 0;
}
| |
The Little Elephant enjoys recursive functions.This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: If x = 1, exit the function. Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. | In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. | C | d9ba1dfe11cf3dae177f8898f3abeefd | 133cb3258ea2eb8293e35f46d2757265 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"math"
] | 1346427000 | ["1", "2"] | null | PASSED | 1,000 | standard input | 2 seconds | A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. | ["1", "2 1"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int i=2;
if(n)printf("%d ",n);
for(i=1;i<n;i++)printf("%d ",i);
return 0;}
| |
The Little Elephant enjoys recursive functions.This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: If x = 1, exit the function. Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. | In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. | C | d9ba1dfe11cf3dae177f8898f3abeefd | fbbd90680e3fde6ba5371cd6fef71a7b | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"math"
] | 1346427000 | ["1", "2"] | null | PASSED | 1,000 | standard input | 2 seconds | A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. | ["1", "2 1"] | #include <stdio.h>
int main()
{
int n,i;
scanf("%d",&n);
printf("%d ",n);
for(i=1;i<n;i++){
printf("%d ",i);
}
return 0;
}
| |
The Little Elephant enjoys recursive functions.This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: If x = 1, exit the function. Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. | In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. | C | d9ba1dfe11cf3dae177f8898f3abeefd | f75098406ef6cb7e18b0ed7a7ceaca72 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"math"
] | 1346427000 | ["1", "2"] | null | PASSED | 1,000 | standard input | 2 seconds | A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. | ["1", "2 1"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int x;
scanf("%d",&x);
if(x == 1)
{
printf("1\n");
return 0;
}
else
{
int *f = malloc(x * sizeof(int));
*f = x;
int i;
for(i = 1; i <= x-1; i++)
*(f+i) = i;
printf("%d",*f);
for(i = 1; i <= x-1; i++)
printf(" %d",*(f+i));
return 0;
}
}
| |
The Little Elephant enjoys recursive functions.This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: If x = 1, exit the function. Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. | In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. | C | d9ba1dfe11cf3dae177f8898f3abeefd | 8bc205321d04f7156f2745a499b2095d | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"math"
] | 1346427000 | ["1", "2"] | null | PASSED | 1,000 | standard input | 2 seconds | A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. | ["1", "2 1"] | #include<stdio.h>
#include<string.h>
int main()
{
int a,b,i;
scanf("%d",&a);
printf("%d",a);
for(i=1;i<a;i++)
{
printf(" %d",i);
}
} | |
The Little Elephant enjoys recursive functions.This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: If x = 1, exit the function. Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. | In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. | C | d9ba1dfe11cf3dae177f8898f3abeefd | 6ba93155fecf00ab98c072bac688f26a | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"math"
] | 1346427000 | ["1", "2"] | null | PASSED | 1,000 | standard input | 2 seconds | A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. | ["1", "2 1"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int n;
scanf("%d",&n);
if(n==1)
{ printf("1");
exit(0);
}
printf("%d %d",n,1);
int k=2;
int i;
for(i=1;i<=n-2;i++)
{ printf(" %d",k);
k++;
}
return 0;
}
| |
The Little Elephant enjoys recursive functions.This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: If x = 1, exit the function. Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. | In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. | C | d9ba1dfe11cf3dae177f8898f3abeefd | db536f11e2798299d7e1ab4a7e1ec4eb | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"math"
] | 1346427000 | ["1", "2"] | null | PASSED | 1,000 | standard input | 2 seconds | A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. | ["1", "2 1"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n, temp;
while(scanf("%d", &n)!=EOF)
{
printf("%d", n);
temp = 1;
while(temp<n)
{
printf(" %d", temp);
temp++;
}
printf("\n");
}
return 0;
}
| |
The Little Elephant enjoys recursive functions.This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: If x = 1, exit the function. Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. | In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. | C | d9ba1dfe11cf3dae177f8898f3abeefd | 966eaca71ee0aac28cdb55a82f59b558 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"math"
] | 1346427000 | ["1", "2"] | null | PASSED | 1,000 | standard input | 2 seconds | A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. | ["1", "2 1"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int i,n;
scanf("%d",&n);
if(n==1)
putchar('1');
else
{
printf("%d",n);
for(i=1; i<n; i++)
{
printf(" %d",i);
}
}
return 0;
}
| |
The Little Elephant enjoys recursive functions.This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: If x = 1, exit the function. Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. | In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. | C | d9ba1dfe11cf3dae177f8898f3abeefd | e60e3a03725590996105b81df3e863c7 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"math"
] | 1346427000 | ["1", "2"] | null | PASSED | 1,000 | standard input | 2 seconds | A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. | ["1", "2 1"] | #include<stdio.h>
int main()
{
int n,i;
scanf("%d",&n);
printf("%d ",n);
for(i=1;i<n;i++)
printf("%d ",i);
return 0;
} | |
The Little Elephant enjoys recursive functions.This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: If x = 1, exit the function. Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. | In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. | C | d9ba1dfe11cf3dae177f8898f3abeefd | 0d6c14798da0351308fb2def93326291 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"math"
] | 1346427000 | ["1", "2"] | null | PASSED | 1,000 | standard input | 2 seconds | A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. | ["1", "2 1"] | int main()
{
int n,i;
scanf("%d",&n);
printf("%d ",n);
for(i=1;i<n;i++)
printf("%d ",i);
return 0;
} | |
The Little Elephant enjoys recursive functions.This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: If x = 1, exit the function. Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. | In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. | C | d9ba1dfe11cf3dae177f8898f3abeefd | f53f417d37280cd027a89d1b24818b58 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"math"
] | 1346427000 | ["1", "2"] | null | PASSED | 1,000 | standard input | 2 seconds | A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. | ["1", "2 1"] | #include <stdio.h>
int n;
int arr[100];
void swap(int *a, int *b)
{
int buf;
buf = *a;
*a = *b;
*b = buf;
}
void func(int x)
{
if(x == n - 1)
{
return;
}
func(x + 1);
swap(&arr[x], &arr[x + 1]);
}
int main()
{
int c;
scanf("%d", &n);
for(c = 0; c < n; c++)
{
arr[c] = c + 1;
}
func(0);
for(c = 0; c < n; c++)
{
printf("%d ", arr[c]);
}
return 0;
} | |
The Little Elephant enjoys recursive functions.This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: If x = 1, exit the function. Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. | In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. | C | d9ba1dfe11cf3dae177f8898f3abeefd | e73a4895c5fef8a642e8a0bbc7b39f97 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"math"
] | 1346427000 | ["1", "2"] | null | PASSED | 1,000 | standard input | 2 seconds | A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. | ["1", "2 1"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int i,n;
scanf("%d",&n);
printf("%d ",n);
for(i=1;i<n;i++)
printf("%d ",i);
printf("\n");
return 0;
}
| |
The Little Elephant enjoys recursive functions.This time he enjoys the sorting function. Let a is a permutation of an integers from 1 to n, inclusive, and ai denotes the i-th element of the permutation. The Little Elephant's recursive function f(x), that sorts the first x permutation's elements, works as follows: If x = 1, exit the function. Otherwise, call f(x - 1), and then make swap(ax - 1, ax) (swap the x-th and (x - 1)-th elements of a). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to n, such that after performing the Little Elephant's function (that is call f(n)), the permutation will be sorted in ascending order. | In a single line print n distinct integers from 1 to n — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. | C | d9ba1dfe11cf3dae177f8898f3abeefd | 0062e60a9c20bf568c048c9dcbd366aa | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"math"
] | 1346427000 | ["1", "2"] | null | PASSED | 1,000 | standard input | 2 seconds | A single line contains integer n (1 ≤ n ≤ 1000) — the size of permutation. | ["1", "2 1"] | #include<stdio.h>
int main()
{
int i,n;
scanf("%d",&n);
printf("%d ",n);
for(i=1;i<n;i++)
printf("%d ",i);
printf("\n");
return 0;
} | |
You are given an array $$$a_1, a_2, \dots, a_n$$$ of integer numbers.Your task is to divide the array into the maximum number of segments in such a way that: each element is contained in exactly one segment; each segment contains at least one element; there doesn't exist a non-empty subset of segments such that bitwise XOR of the numbers from them is equal to $$$0$$$. Print the maximum number of segments the array can be divided into. Print -1 if no suitable division exists. | Print the maximum number of segments the array can be divided into while following the given constraints. Print -1 if no suitable division exists. | C | 0e0f30521f9f5eb5cff2549cd391da3c | 9f04cb395fa438afa7955852ab95b3da | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"math",
"matrices"
] | 1547217300 | ["4\n5 5 7 2", "3\n1 2 3", "3\n3 1 10"] | NoteIn the first example $$$2$$$ is the maximum number. If you divide the array into $$$\{[5], [5, 7, 2]\}$$$, the XOR value of the subset of only the second segment is $$$5 \oplus 7 \oplus 2 = 0$$$. $$$\{[5, 5], [7, 2]\}$$$ has the value of the subset of only the first segment being $$$5 \oplus 5 = 0$$$. However, $$$\{[5, 5, 7], [2]\}$$$ will lead to subsets $$$\{[5, 5, 7]\}$$$ of XOR $$$7$$$, $$$\{[2]\}$$$ of XOR $$$2$$$ and $$$\{[5, 5, 7], [2]\}$$$ of XOR $$$5 \oplus 5 \oplus 7 \oplus 2 = 5$$$.Let's take a look at some division on $$$3$$$ segments — $$$\{[5], [5, 7], [2]\}$$$. It will produce subsets: $$$\{[5]\}$$$, XOR $$$5$$$; $$$\{[5, 7]\}$$$, XOR $$$2$$$; $$$\{[5], [5, 7]\}$$$, XOR $$$7$$$; $$$\{[2]\}$$$, XOR $$$2$$$; $$$\{[5], [2]\}$$$, XOR $$$7$$$; $$$\{[5, 7], [2]\}$$$, XOR $$$0$$$; $$$\{[5], [5, 7], [2]\}$$$, XOR $$$5$$$; As you can see, subset $$$\{[5, 7], [2]\}$$$ has its XOR equal to $$$0$$$, which is unacceptable. You can check that for other divisions of size $$$3$$$ or $$$4$$$, non-empty subset with $$$0$$$ XOR always exists.The second example has no suitable divisions.The third example array can be divided into $$$\{[3], [1], [10]\}$$$. No subset of these segments has its XOR equal to $$$0$$$. | PASSED | 2,300 | standard input | 2 seconds | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the size of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). | ["2", "-1", "3"] | /* upsolve with Dukkha */
#include <stdio.h>
int main() {
static int pp[30];
int n, a, b, p, q, ans;
scanf("%d", &n);
p = 0;
while (n--) {
scanf("%d", &a);
q = p ^= a;
for (b = 0; b < 30; b++)
if (q & 1 << b)
q ^= pp[b];
if (q) {
b = 0;
while (!(q & 1 << b))
b++;
pp[b] = q;
}
}
ans = -1;
if (p) {
ans = 0;
for (b = 0; b < 30; b++)
if (pp[b])
ans++;
}
printf("%d\n", ans);
return 0;
}
| |
You are given an array $$$a_1, a_2, \dots, a_n$$$ of integer numbers.Your task is to divide the array into the maximum number of segments in such a way that: each element is contained in exactly one segment; each segment contains at least one element; there doesn't exist a non-empty subset of segments such that bitwise XOR of the numbers from them is equal to $$$0$$$. Print the maximum number of segments the array can be divided into. Print -1 if no suitable division exists. | Print the maximum number of segments the array can be divided into while following the given constraints. Print -1 if no suitable division exists. | C | 0e0f30521f9f5eb5cff2549cd391da3c | 075b0afc26d35611fda162e336555c81 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"math",
"matrices"
] | 1547217300 | ["4\n5 5 7 2", "3\n1 2 3", "3\n3 1 10"] | NoteIn the first example $$$2$$$ is the maximum number. If you divide the array into $$$\{[5], [5, 7, 2]\}$$$, the XOR value of the subset of only the second segment is $$$5 \oplus 7 \oplus 2 = 0$$$. $$$\{[5, 5], [7, 2]\}$$$ has the value of the subset of only the first segment being $$$5 \oplus 5 = 0$$$. However, $$$\{[5, 5, 7], [2]\}$$$ will lead to subsets $$$\{[5, 5, 7]\}$$$ of XOR $$$7$$$, $$$\{[2]\}$$$ of XOR $$$2$$$ and $$$\{[5, 5, 7], [2]\}$$$ of XOR $$$5 \oplus 5 \oplus 7 \oplus 2 = 5$$$.Let's take a look at some division on $$$3$$$ segments — $$$\{[5], [5, 7], [2]\}$$$. It will produce subsets: $$$\{[5]\}$$$, XOR $$$5$$$; $$$\{[5, 7]\}$$$, XOR $$$2$$$; $$$\{[5], [5, 7]\}$$$, XOR $$$7$$$; $$$\{[2]\}$$$, XOR $$$2$$$; $$$\{[5], [2]\}$$$, XOR $$$7$$$; $$$\{[5, 7], [2]\}$$$, XOR $$$0$$$; $$$\{[5], [5, 7], [2]\}$$$, XOR $$$5$$$; As you can see, subset $$$\{[5, 7], [2]\}$$$ has its XOR equal to $$$0$$$, which is unacceptable. You can check that for other divisions of size $$$3$$$ or $$$4$$$, non-empty subset with $$$0$$$ XOR always exists.The second example has no suitable divisions.The third example array can be divided into $$$\{[3], [1], [10]\}$$$. No subset of these segments has its XOR equal to $$$0$$$. | PASSED | 2,300 | standard input | 2 seconds | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the size of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). | ["2", "-1", "3"] | int a[31],s[200005],n,x,i;
int I(int p){for(i=30;~i;--i)if(p>>i&1){if(!a[i]){a[i]=p;return 1;}p^=a[i];}return 0;}
int main(){scanf("%d",&n);for(int i=x=1;i<=n;++i)scanf("%d",s+i),s[i]^=s[i-1];if(!s[n])exit(0&puts("-1"));I(s[n]);while(--n)x+=I(s[n]);exit(!printf("%d",x));} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.