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 are given two positive integers $$$n$$$ and $$$k$$$. Print the $$$k$$$-th positive integer that is not divisible by $$$n$$$.For example, if $$$n=3$$$, and $$$k=7$$$, then all numbers that are not divisible by $$$3$$$ are: $$$1, 2, 4, 5, 7, 8, 10, 11, 13 \dots$$$. The $$$7$$$-th number among them is $$$10$$$. | For each test case print the $$$k$$$-th positive integer that is not divisible by $$$n$$$. | C | 7d6f76e24fe9a352beea820ab56f03b6 | 64e75223f0fb8c1fe58559122d2c93ad | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"binary search",
"math"
] | 1589034900 | ["6\n3 7\n4 12\n2 1000000000\n7 97\n1000000000 1000000000\n2 1"] | null | PASSED | 1,200 | standard input | 1 second | The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the input. Next, $$$t$$$ test cases are given, one per line. Each test case is two positive integers $$$n$$$ ($$$2 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$). | ["10\n15\n1999999999\n113\n1000000001\n1"] | #include<stdio.h>
int main()
{
unsigned int t,n,k,i,var,quo,rem;
scanf("%u",&t);
for(i=0;i<t;i++)
{
scanf("%u%u",&n,&k);
var = n-1;
quo = k/var;
rem = k%var;
if(rem!=0)
{printf("%u\n",n*quo+rem);}
else
{
printf("%u\n",n*quo-1);
}
}
return(0);
}
| |
You are given two positive integers $$$n$$$ and $$$k$$$. Print the $$$k$$$-th positive integer that is not divisible by $$$n$$$.For example, if $$$n=3$$$, and $$$k=7$$$, then all numbers that are not divisible by $$$3$$$ are: $$$1, 2, 4, 5, 7, 8, 10, 11, 13 \dots$$$. The $$$7$$$-th number among them is $$$10$$$. | For each test case print the $$$k$$$-th positive integer that is not divisible by $$$n$$$. | C | 7d6f76e24fe9a352beea820ab56f03b6 | 5c858ddfe3213db013b8a7a43e1f5bbb | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"binary search",
"math"
] | 1589034900 | ["6\n3 7\n4 12\n2 1000000000\n7 97\n1000000000 1000000000\n2 1"] | null | PASSED | 1,200 | standard input | 1 second | The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the input. Next, $$$t$$$ test cases are given, one per line. Each test case is two positive integers $$$n$$$ ($$$2 \le n \le 10^9$$$) and $$$k$$$ ($$$1 \le k \le 10^9$$$). | ["10\n15\n1999999999\n113\n1000000001\n1"] | #include <stdio.h>
int main()
{
int t, n, k;
scanf("%d", &t);
for(int l = 0; l < t; l++)
{
scanf("%d%d", &n, &k);
int r = k / n;
int n1 = r * n;
int n2 = n1 + r + k % n;
while(n2 / n > n1 / n)
{
int aux = n2;
n2 = n2 + (n2 / n - n1 / n);
n1 = aux;
}
printf("%d\n", n2);
}
return 0;
} | |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 544d66d9d1096f7a44a74845072ccf2b | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include<stdio.h>
int main()
{
long long int n,x[5001],y[5001],i,j,t,Ans=0,c;
scanf("%I64d",&n);
for(i=0; i<n; i++) scanf("%I64d %I64d",&x[i],&y[i]);
for(i=0; i<n-1; i++)
{
for(j=0; j<n-1; j++)
{
if(x[j]>x[j+1])
{
t=x[j];
x[j]=x[j+1];
x[j+1]=t;
t=y[j];
y[j]=y[j+1];
y[j+1]=t;
}
}
}
Ans=y[0];
c=x[0];
for(i=1; i<n; i++)
{
if(y[i]>=Ans)
{
Ans=y[i];
c=x[i];
}
else if(x[i]>Ans && x[i]!=c)
{
Ans=x[i];
}
}
printf("%I64d\n",Ans);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 4f4b46d788d71c20eb173a3015ee0d90 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include<stdio.h>
#include<stdlib.h>
struct x
{
int a,b;
}per[10000];
int cmp(const void *a,const void *b)
{
if((*(struct x*)a).a != (*(struct x*)b).a)
return (*(struct x*)a).a - (*(struct x*)b).a;
else
return (*(struct x*)a).b - (*(struct x*)b).b;
}
int main(void)
{
int n,i,day = 0;
scanf("%d",&n);
for(i = 0 ; i < n ; i ++)
scanf("%d%d",&per[i].a,&per[i].b);
qsort(per,n,sizeof(per[0]),cmp);
for(i = 0 ; i < n ; i ++)
{
if(per[i].b >= day)
day = per[i].b;
else
day = per[i].a;
}
printf("%d\n",day);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 77401ebcc17d760befd0bf23735e96b7 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include <stdio.h>
#include <stdlib.h>
static struct exam {
int a, b;
} ee[5000];
int compare(const void *a, const void *b) {
struct exam *pa = (struct exam *) a;
struct exam *pb = (struct exam *) b;
return pa->a != pb->a ? pa->a - pb->a : pa->b - pb->b;
}
int main() {
int i, n, min;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d%d", &ee[i].a, &ee[i].b);
qsort(ee, n, sizeof(*ee), compare);
min = 0;
for (i = 0; i < n; i++)
if (min <= ee[i].b)
min = ee[i].b;
else
min = ee[i].a;
printf("%d\n", min);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 8f40ccd3bf3009f2d808a8e159517790 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include <stdio.h>
int main() {
int n, m, k;
int a[6000];
int b[6000];
int max;
int i, j = 0;
scanf("%d", &n);
for (i = 0; i < n; i++){
scanf("%d %d", a + i, b + i);
}
for (i = 0; i < n-1; i++) {
for (j = n-2; j >= i; j--) {
if (b[j] > b[j+1]) {
k = a[j];
a[j] = a[j+1];
a[j+1] = k;
k = b[j];
b[j] = b[j+1];
b[j+1] = k;
}
}
}
for (i = 0; i < n-1; i++) {
for (j = n-2; j >= i; j--) {
if (a[j] > a[j+1]) {
k = a[j];
a[j] = a[j+1];
a[j+1] = k;
k = b[j];
b[j] = b[j+1];
b[j+1] = k;
}
}
}
max = b[0];
for (i = 1; i < n; i++) {
if (b[i] >= max) {
max = b[i];
} else if (a[i] >= max) {
max = a[i];
}
}
printf("%d\n", max);
/*
while (1) {
min = max = 0;
for (i = 1; i < n; i++) {
if (tw[i] < tw[min])
min = i;
if (tw[i] > tw[max])
max = i;
}
if (tw[max] - tw[min] < 2 || j == k) break;
tw[max]--;
tw[min]++;
aa[j][0] = max;
aa[j][1] = min;
j++;
}
printf("%d %d\n", tw[max] - tw[min], j);
for (i = 0; i < j; i++)
printf("%d %d\n", aa[i][0]+1, aa[i][1]+1);
*/
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | c0cbd53217caf69a645dce51ca32d7a5 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include<stdio.h>
main()
{
long long int a,b,c,d,i,swap,last=-1;
scanf("%I64d",&a);
long long int arr[5000];
long long int brr[5000];
for(i=0;i<a;i++)
{
scanf("%I64d",&arr[i]);
scanf("%I64d",&brr[i]);
}
for(c=0;c<a-1;c++)
for(d=0;d<a-c-1;d++)
{
if(arr[d]>arr[d+1])
{
swap=arr[d];
arr[d]=arr[d+1];
arr[d+1]=swap;
swap=brr[d];
brr[d]=brr[d+1];
brr[d+1]=swap;
}
else if(arr[d]==arr[d+1]&&brr[d]>brr[d+1])
{
swap=brr[d];
brr[d]=brr[d+1];
brr[d+1]=swap;
}
}
for(i=0;i<a;i++)
{
if(last<=brr[i])
{
last=brr[i];
//printf("%I64d",last);
}
else
last=arr[i];
}
printf("%I64d",last);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 350eb8437e020755170c33274655efe9 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include <stdio.h>
int x[5001][2],n;
void sort(void);
int main()
{
int i,j,day=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&x[i][j]);
}
}
sort();
for(i=0;i<n;i++)
{
if(x[i][1]>=day)
{
day=x[i][1];
}
else
{
day=x[i][0];
}
}
printf("%d\n",day);
return 0;
}
void sort(void)
{
int i,j,k,temp;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
if(x[j][0]==x[j+1][0])
{
if(x[j][1]>x[j+1][1])
{
for(k=0;k<2;k++)
{
temp=x[j][k];
x[j][k]=x[j+1][k];
x[j+1][k]=temp;
}
}
}
else if(x[j][0]>x[j+1][0])
{
for(k=0;k<2;k++)
{
temp=x[j][k];
x[j][k]=x[j+1][k];
x[j+1][k]=temp;
}
}
}
}
} | |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 951a690f8105ca2ac913d43e6c374c1f | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include<stdio.h>
int main()
{
long long int n,i,j,t,p,x;
scanf("%I64d",&n);
long long int a[n],b[n];
for(i=0;i<n;i++)
{
scanf("%I64d %I64d",&a[i],&b[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
t=b[i];
b[i]=b[j];
b[j]=t;
}
else if(a[i]==a[j])
{
if(b[i]>b[j])
{
t=b[i];
b[i]=b[j];
b[j]=t;
}
}
}
}
p=b[0];
for(i=0;i<n;i++)
{
if(b[i]>p)
{
p=b[i];
}
else if(b[i]<p)
{
p=a[i];
}
}
printf("%I64d",p);
/*for(i=0;i<9999999999;i++)
{
i=i;
}*/
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 29926ec8d3f19ea54d420e54d984a2a3 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include<stdio.h>
#include<stdlib.h>
#define MAX 5001
typedef struct Date{
long a,b;
}Date;
Date date[MAX];
int cmp(const void *s1, const void *s2){
const Date * d1 = (const Date *)s1;
const Date * d2 = (const Date *)s2;
if( (d1->a) - d2->a == 0)
return (d1->b) - (d2->b);
else
return (d1->a) - (d2->a);
}
int main()
{
long n, i;
scanf("%ld", &n);
for( i = 0; i < n; i++)
scanf("%ld%ld", &(date[i].a), &(date[i].b));
qsort( date, n, sizeof(Date), cmp);
long a[MAX];
a[0] = (date[0].b);
for( i = 1; i < n; i++){
a[i] = (date[i].b) >= a[i-1] ? (date[i].b) : (date[i].a);
}
printf("%ld\n", a[n-1]);
return 0;
} | |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | efbc548dfae316963f9faa0fee6adf3a | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include <stdio.h>
#include <stdlib.h>
struct exams_t {
int a;
int b;
};
int compare_structs(const void* a, const void* b) {
const struct exams_t* a1 = (const struct exams_t*) a;
const struct exams_t* b1 = (const struct exams_t*) b;
// printf("a: %d, b: %d\n", a1.a, a1.b);
if (a1->a < b1->a) {
return -1;
}
else if (a1->a > b1->a) {
return 1;
}
else {
if (a1->b < b1->b) {
return -1;
}
else if (a1->b > b1->b) {
return 1;
}
return 0;
}
}
// int compare_structs2(const void* a, const void* b) {
// const struct exams_t* a1 = (const struct exams_t*) a;
// const struct exams_t* b1 = (const struct exams_t*) b;
// // printf("a: %d, b: %d\n", a1.a, a1.b);
// if (a1->b < b1->b) {
// return -1;
// }
// else if (a1->b > b1->b) {
// return 1;
// }
// else {
// return 0;
// }
// }
int main(int argc, char const *argv[])
{
int n;
scanf("%d\n", &n);
struct exams_t exams[5000];
int i;
for (i = 0; i < n; i++) {
scanf("%d %d\n", &exams[i].a, &exams[i].b);
}
qsort(exams, n, sizeof(struct exams_t), compare_structs);
// i = 0;
// while (i < n) {
// int j;
// for (j = i + 1; j < n; j++) {
// if (((exams[i].a != exams[j].a) && (j - i > 1)) || ((j == n - 1) && (exams[j].a == exams[i].a))) {
// printf("i: %d, j: %d\n", i, j);
// qsort(&exams[i], j - i + 1, sizeof(struct exams_t), compare_structs2);
// i += j;
// break;
// }
// if ((j - i < 2) && (exams[i].a != exams[j].a)) {
// i++;
// break;
// }
// }
// printf("i: %d\n", i);
// if (i + 1 >= n) {
// break;
// }
// }
// for (i = 0; i < n; i++) {
// printf("a: %d b: %d\n", exams[i].a, exams[i].b);
// }
int day = exams[0].b;
// printf("day: %d\n", day);
for (i = 1; i < n; i++) {
if (exams[i].b >= day) {
day = exams[i].b;
}
else {
day = exams[i].a;
}
}
printf("%d\n", day);
return 0;
} | |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | e33066ff16c213ed10e2d2bf87f83d94 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include <stdio.h>
#include <stdlib.h>
#define MAX_N (5000)
typedef struct {
int a;
int b;
} exam;
int cmp(const void * arg1, const void * arg2) {
const exam * ex1 = (const exam *)arg1;
const exam * ex2 = (const exam *)arg2;
if ( ex1->a != ex2-> a)
return ex1->a - ex2->a;
return ex1->b - ex2->b;
}
int main() {
exam xs[MAX_N];
int i,d,n;
scanf("%d", &n);
for ( i=0; i < n; ++i )
scanf("%d %d", &xs[i].a, &xs[i].b);
qsort(xs, n, sizeof(*xs), cmp);
for ( i=d=0; i < n; ++i )
if ( d <= xs[i].b )
d = xs[i].b;
else
d = xs[i].a;
printf("%d\n", d);
return EXIT_SUCCESS;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | cdff3c083e1ad4831e5e33fbb3c47dfc | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include <stdio.h>
#include <stdlib.h>
int n,i,j;
int cmpfunc(const void *a, const void * b){
const int *x = *(const int**) a;
const int *y = *(const int**) b;
if(x[0]!=y[0]){
return x[0]-y[0];
}else{
return x[1]-y[1];
}
}
int main(){
scanf("%d", &n);
int **x;
x=malloc(n*sizeof(int*));
for(i=0; i<n; i++){
x[i]= malloc(2*sizeof(int));
for(j=0; j<2; j++){
scanf("%d", &x[i][j]);
}
}
qsort(x,n,sizeof(x[0]), cmpfunc);
int y=0;
for(i=0; i<n; i++){
if(y<=x[i][1]){
y=x[i][1];
}else{
y=x[i][0];
}
free(x[i]);
}
free(x);
printf("%d", y);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | f6d0ad125078ba473f17c5deed440869 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include <stdio.h>
#include <stdlib.h>
int compare (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int a[5010][2];
int main()
{
int n,d;
scanf("%d",&n);;
int i;
for(i=0;i<n;i++) {
scanf("%d%d",&a[i][0],&a[i][1]);
}
qsort(a,n,2*sizeof(int),compare);
d=a[0][1];
for(i=1;i<n;i++) {
if(a[i][0]==a[i-1][0]) {
if(d<a[i][1]) {
d=a[i][1];
}
}
else {
d=d<=a[i][1]?a[i][1]:a[i][0];
}
}
printf("%d\n",d);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | d9a22fd1576f31cb7f1072a83df72381 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include<stdio.h>
int main()
{
long long int n,i,j,t,c=0;
scanf("%lld",&n);
long long int a[n],b[n];
for(i=0;i<n;i++)
{
scanf("%lld %lld",&a[i],&b[i]);
}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
t=b[i];
b[i]=b[j];
b[j]=t;
}
if(a[i]==a[j] && b[i]>b[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
t=b[i];
b[i]=b[j];
b[j]=t;
}
}
}
for(i=0;i<n;i++)
{
if(c<=b[i])
c=b[i];
else
c=a[i];
}
printf("%lld",c);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 4d703bfccbfa34ad71fce9fc56d4b7fc | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | //思路就是设计一个排序算法!
//我还在猜测题意!
#include<stdio.h>
#define EXAM 5000
void swap(int *a,int *b){
int tmp=*a;
*a=*b;
*b=tmp;
}
int min(int a,int b) {
if(a>b) return b;
else return a;
}
int main() {
int exam;
//exam表示考试的科目的数量!
scanf("%d",&exam);
int i,j;
int a[EXAM],b[EXAM];
for(i=0;i<exam;i++) {
scanf("%d%d",&a[i],&b[i]);
}
//这里直接sort b,但以a为标准!
for(i=0;i<exam-1;i++) {
int min_i=i;
int min=a[i];
int min_b=b[i];
for(j=i+1;j<exam;j++) {
if(a[j]<min) {
min=a[j];
min_i=j;
} else if(a[j]==min) {
//这里是为了处理
//4 3
//4 2
//4 1
//类型的数据,就是在a相同时,我们依据b来进行互换!
if(b[j]<min_b) {
min_b=b[j];
min_i=j;
}
}
}
swap(&a[i],&a[min_i]);
swap(&b[i],&b[min_i]);
}
/*
for(i=0;i<exam;i++) {
printf(" (%d,%d)",a[i],b[i]);
}
printf("\n");
*/
//第一场考试肯定在时间最短的里面进行!
int current_day=min(a[0],b[0]);
for(i=1;i<exam;i++) {
//printf("current day = %d\n",current_day);
//接下来的考试时间肯定要比当前时间大或者至少是同一天!
//因为作者可以在同一天参加多门考试!
if(b[i]>=current_day) {
current_day=b[i];
} else {
current_day=a[i];
}
}
printf("%d\n",current_day);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 940441be628b0bd2b419e78ef79362ff | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include<stdio.h>
typedef struct node
{
int ad;
int bd;
}p;
int cmp(const void *a,const void *b)
{
const p* a1=a;
const p* a2=b;
if((a1->ad)-(a2->ad)==0)
return ((a1->bd)-(a2->bd));
return((a1->ad)-(a2->ad));
}
p a[5002];
int main()
{
int n,i;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d %d",&a[i].ad,&a[i].bd);
qsort(a,n,sizeof(p),cmp);
int min=a[0].bd;
for(i=1;i<n;i++)
{
// printf("%d\n",a[i].ad);
if(a[i].bd>=min)
min=a[i].bd;
else
min=a[i].ad;
if(min>a[n-1].bd)
{
printf("%d\n",a[n-1].ad);
return 0;
}
}
printf("%d\n",a[n-1].bd);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | b13db1b52334f1956544c4d0d3e04db0 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include<stdio.h>
int min(int a,int b)
{
if(a>b)
return b;
return a;
}
int max(int a,int b)
{
if(a>b)
return a;
return b;
}
void merge(int a[][3],int lo,int mi,int hi,int k)
{
int i,j,c,b;
c=mi-lo+1;
b=hi-mi;
int left[c][3],right[b][3];
for(i=0;i<c;i++)
{
left[i][k]=a[lo+i][k];
left[i][1-k]=a[lo+i][1-k];
}
for(i=0;i<b;i++)
{
right[i][k]=a[mi+i+1][k];
right[i][1-k]=a[mi+i+1][1-k];
}
for(i=0,j=0;i<c && j<b;)
{
if(left[i][k]<=right[j][k])
{
a[lo+i+j][k]=left[i][k];
a[lo+i+j][1-k]=left[i][1-k];
i++;
}
else
{
a[lo+i+j][k]=right[j][k];
a[lo+i+j][1-k]=right[j][1-k];
j++;
}
}
while(i!=c)
{
a[lo+i+j][1-k]=left[i][1-k];
a[lo+i+j][k]=left[i][k];
i++;
}
while(j!=b)
{
a[lo+i+j][1-k]=right[j][1-k];
a[lo+i+j][k]=right[j][k];
j++;
}
return;
}
void mergesort(int a[][3],int lo,int hi,int k)
{
if(lo>=hi)
return;
int mi=(lo+hi)/2;
mergesort(a,lo,mi,k);
mergesort(a,mi+1,hi,k);
merge(a,lo,mi,hi,k);
return;
}
int main()
{
int n,w[5005][3],i,pvi,a,b;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d %d",&w[i][0],&w[i][1]);
mergesort(w,0,n-1,0);
for(i=0;i<n;i++)
if(w[i][0]==w[pvi][0])
continue;
else
{
mergesort(w,pvi,i-1,1);
pvi=i;
}
mergesort(w,pvi,n-1,1);
pvi=min(w[0][0],w[0][1]);
for(i=1;i<n;i++)
{
a=min(w[i][0],w[i][1]);
b=max(w[i][0],w[i][1]);
if(a>=pvi)
pvi=a;
else
pvi=b;
}
printf("%d\n",pvi);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | ed6f87b490f8a164747a02a08d8aed67 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | # include <stdio.h>
# include <stdlib.h>
typedef struct exam
{
long a;
long b;
}exam;
int compar(exam * e1, exam * e2)
{
if(e1->a - e2->a == 0)
return e1->b - e2->b;
else
return e1->a - e2->a;
}
int main(void)
{
long n;
scanf("%ld", &n);
exam exams[n];
long i;
for(i = 0; i < n; i++)
{
scanf("%ld%ld", &((exams + i)->a), &((exams + i)->b));
}
qsort(exams, n, sizeof(exam), compar);
long date[n];
date[0] = exams[0].b;
for(i = 1; i < n; i++)
date[i] = exams[i].b >= date[i-1] ? exams[i].b : exams[i].a;
printf("%ld", date[n-1]);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 60d9a63a9bca7c035fa6573959fef27b | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int n;
struct D{
int a;
int b;
}data[5000];
void swap(struct D *A,struct D *B){
struct D t;
t=*A;
*A=*B;
*B=t;
}
int num;
int main(){
int i,j;
int tmp;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d %d",&data[i].a,&data[i].b);
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(data[i].b>data[j].b)
swap(&data[i],&data[j]);
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(data[i].a>data[j].a)
swap(&data[i],&data[j]);
num=data[0].b;
for(i=1;i<n;i++)
if(num<=data[i].b)
num=data[i].b;
else
num=data[i].a;
printf("%d\n",num);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 17b92ab49c4ffa4bdd1f94e398c2ff9a | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include <stdio.h>
typedef struct {
int later_day;
int early_day;
} Subject;
int compare(Subject subject1, Subject subject2) {
if (subject1.later_day > subject2.later_day)
return 1;
if (subject1.later_day < subject2.later_day)
return -1;
if (subject1.early_day > subject2.early_day)
return 1;
if (subject1.early_day < subject2.early_day)
return -1;
return 0;
}
int main() {
int n;
scanf("%d", &n);
Subject subjects[n];
for (int i = 0; i < n; i++) {
scanf("%d %d", &subjects[i].later_day, &subjects[i].early_day);
}
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
if (compare(subjects[i], subjects[j]) != -1) {
Subject tmp = subjects[i];
subjects[i] = subjects[j];
subjects[j] = tmp;
}
/*puts("-------------");
for (int i = 0; i < n; i++) {
printf("%d %d\n", subjects[i].later_day, subjects[i].early_day);
}
puts("-------------");*/
int last_day = 0;
for (int i = 0; i < n; i++) {
if (last_day <= subjects[i].early_day)
last_day = subjects[i].early_day;
else
last_day = subjects[i].later_day;
//printf("%d-", last_day);
}
printf("%d", last_day);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 01e384cd677f697ad6a57703c08d06a5 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include<stdio.h>
int main()
{
long a[5111],b[5111],n,i,j,t,o;
scanf("%ld",&n);
for(i=1;i<=n;i++)
{
scanf("%ld %ld",&a[i],&b[i]);
}
for(i=1;i<=n-1;i++)
{
for(j=1;j<=n-i;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
t=b[j];
b[j]=b[j+1];
b[j+1]=t;
}
else if(a[j]==a[j+1]&&b[j]>b[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
t=b[j];
b[j]=b[j+1];
b[j+1]=t;
}
}
}
o=b[1];
for(i=2;i<=n;i++)
{
if(b[i]>=o)o=b[i];
else o=a[i];
}
printf("%ld",o);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | d02da23030a3816ef09de45048a26fbe | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int cmpfunc (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
typedef struct yeah{
int a;
int b;
}ye;
ye ar[5010];
void merge(ye arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
/* create temp arrays */
ye L[n1], R[n2];
/* Copy data to temp arrays L[] and R[] */
for (i = 0; i < n1; i++)
{
L[i] = arr[l + i];
}
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays back into arr[l..r]*/
i = 0; // Initial index of first subarray
j = 0; // Initial index of second subarray
k = l; // Initial index of merged subarray
while (i < n1 && j < n2)
{
if ((L[i].a < R[j].a ) || ((L[i].a == R[j].a) && (L[i].b <= R[j].b)))
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy the remaining elements of L[], if there
are any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy the remaining elements of R[], if there
are any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
/* l is for left index and r is right index of the
sub-array of arr to be sorted */
void mergeSort(ye arr[], int l, int r)
{
if (l < r)
{
// Same as (l+r)/2, but avoids overflow for
// large l and h
int m = l+(r-l)/2;
// Sort first and second halves
mergeSort(arr, l, m);
mergeSort(arr, m+1, r);
merge(arr, l, m, r);
}
}
int checksorted(char ch,int n)
{
int p,i;
if (ch == 'a')
{
p=ar[0].a;
for(i=1;i<n;i++)
{
if(ar[i].a<p)
return 0;
p=ar[i].a;
}
return 1;
}
else
{
p=ar[0].b;
for(i=1;i<n;i++)
{
if(ar[i].b<p)
return 0;
p=ar[i].b;
}
return 1;
}
}
int main()
{
int br[5010];
int f1,i,n, x , y ,sa, sb;
sa=sb=INT_MIN;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d %d",&x,&y);
if(x>=sa)
sa=x;
if(y>=sb)
sb=y;
ar[i].a=x;
ar[i].b=y;
br[i]=x;
}
//qsort(br, n, sizeof(int), cmpfunc);
mergeSort(ar,0,n-1);
/*f1=checksorted('a',n);
if(f1==1)
printf("%d\n", sb);
else
{
if( (ar[n-1].a==br[n-1]) && (sb>=br[n-2]) )
printf("%d\n", sb);
else
printf("%d\n",sa);
}*/
int best = -1;
for(int i = 0; i < n; i++)
{
if (best <= ar[i].b)
{
best = ar[i].b;
}
else
{
best = ar[i].a;
}
}
printf("%d\n",best );
return 0;
} | |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | a37910c06ba3a7c2fbddb4d97a29fd9a | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include <stdio.h>
#include <stdlib.h>
#define SIZE 5000
struct exam {
int a, b;
};
int cmp (const void *_a, const void * _b)
{
struct exam a = *(struct exam *)_a;
struct exam b = *(struct exam *)_b;
return a.a != b.a ? a.a - b.a : a.b - b.b;
}
int main()
{
int n, i, d;
struct exam ex[SIZE];
scanf ("%d", &n);
for (i = 0; i < n; i++)
scanf ("%d %d", &ex[i].a, &ex[i].b);
qsort (ex, n, sizeof ex[0], cmp);
d = ex[0].b;
for (i = 1; i < n; i++) {
if (ex[i].b < d)
d = ex[i].a;
else
d = ex[i].b;
}
printf ("%d", d);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 64064023454d29e812c26bfd1e6ca4f8 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include <stdio.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
#define gc getchar//_unlocked
#define M 1000000007
typedef long long ll;
/************************************************************************/
long long getnum()
{
char ch;
long long num=0;
while( !isdigit(ch= gc()) );
while(isdigit(ch))
{
num= num*10 + ch-'0';
ch=gc();
}
return num;
}
void sort(int *a ,int begin ,int mid, int end)
{
int temp[end-begin+1+1],i=begin,j=mid+1 ,k=1;
while(i<=mid && j<=end)
{
if(a[i]<=a[j])
temp[k] =a[i++];
else
temp[k]= a[j++];
++k;
}
for(;i<=mid;++i)
temp[k++]=a[i];
for(;j<=end;++j)
temp[k++] =a[j];
for(i=begin;i<=end;++i)
a[i] = temp[ i-begin +1] ;
return ;
}
void partition (int *a ,int begin , int end)
{
if(begin==end)
return ;
int mid = (begin+end)/2;
partition(a,begin,mid);
partition(a,mid+1,end);
sort(a,begin,mid,end);
}
int kadane(int *a ,int n) //Maximum sum in subarray
{
int i,sum,max;
sum=max=a[0];
for(i=1;i<n;++i)
{
if(sum<0)
sum=a[i];
else
sum += a[i];
if(max<sum)
max=sum;
}
return max;
}
/*********************************************************************************/
/*********************************************************************************/
/*MAIN BEGINS HERE*/
/*********************************************************************************/
/*********************************************************************************/
/**********************************************************************************/
void sort1(int a[][2] ,int begin ,int mid, int end)
{
int temp[end-begin+1+1][2] ,i=begin,j=mid+1 ,k=1;
while(i<=mid && j<=end)
{
if(a[i][0]<a[j][0])
{
temp[k][0]=a[i][0];
temp[k][1]=a[i][1];
i++;
}
else if(a[i][0] == a[j][0])
{
if(a[i][1]<=a[j][1])
{
temp[k][0]=a[i][0];
temp[k][1]=a[i][1];
i++;
}
else
{
temp[k][0]=a[j][0];
temp[k][1]=a[j][1];
j++;
}
}
else
{
temp[k][0]=a[j][0];
temp[k][1]=a[j][1];
j++;
}
++k;
}
for(;i<=mid;++i)
{
temp[k][0]=a[i][0];
temp[k][1] =a[i][1];
++k;
}
for(;j<=end;++j)
{
temp[k][0] =a[j][0];
temp[k][1] =a[j][1];
++k;
}
for(i=begin;i<=end;++i)
{
a[i][0] = temp[ i-begin +1][0] ;
a[i][1] =temp[i-begin+1][1];
}
return ;
}
void partition1 (int a[][2] ,int begin , int end)
{
if(begin==end)
return ;
int mid = (begin+end)/2;
partition1(a,begin,mid);
partition1(a,mid+1,end);
sort1(a,begin,mid,end);
}
int main()
{
int d,i,n;
n=getnum();
int a[n][2];
for(i=0;i<n;++i)
{
a[i][0]=getnum();
a[i][1]=getnum();
}
partition1(a,0,n-1);
d=0;
for(i=0;i<n;++i)
{
if(a[i][1] < d)
d=a[i][0];
else
d=a[i][1];
}
printf("%d\n",d);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 8b638931ff9bc17dab1aa9e22e3fa522 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include<stdio.h>
struct exam{
int later;
int former;
};
int main(){
int n,date,x,y,i,j;
struct exam in[5100];
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d %d",&x,&y);
j=i-1;
while(j>=0){
if((x<in[j].later) || (x==in[j].later && y<=in[j].former)){
in[j+1]=in[j];
}
else{
break;
}
j--;
}
in[j+1].later=x;
in[j+1].former=y;
}
date=in[0].former;
for(i=1;i<n;i++){
if(in[i].former>=date){ date=in[i].former; }
else{ date=in[i].later; }
}
printf("%d\n",date);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | fad68e74379003b6204e5b052c6ffa3b | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include <stdio.h>
#include <stdlib.h>
#define MAX_N (5000)
typedef struct {
int a;
int b;
} exam;
int cmp(const void * arg1, const void * arg2) {
const exam * ex1 = (const exam *)arg1;
const exam * ex2 = (const exam *)arg2;
if ( ex1->a != ex2-> a)
return ex1->a - ex2->a;
return ex1->b - ex2->b;
}
int main() {
exam xs[MAX_N];
int i,d,n;
scanf("%d", &n);
for ( i=0; i < n; ++i )
scanf("%d %d", &xs[i].a, &xs[i].b);
qsort(xs, n, sizeof(*xs), cmp);
for ( i=d=0; i < n; ++i )
if ( d <= xs[i].b )
d = xs[i].b;
else
d = xs[i].a;
printf("%d\n", d);
return EXIT_SUCCESS;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 6ed351887f40cec51d841d5291a3e1f9 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#define min(x,y) (x)<(y)?(x):(y)
typedef struct
{
int u;
int v;
}day;
int compare(day *a, day *b)
{
return (a->u - b->u);
}
int compare2(day *a, day *b)
{
return (a->v - b->v);
}
int main()
{
day a[5001];
int n,i,j,k;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d %d",&a[i].u,&a[i].v);
qsort(a,n,sizeof(day),compare);
j=0;
k=1;
for(i=1;i<n;i++)
{
if(a[i].u==a[i-1].u)
k++;
else
{
if(k>1)
qsort(a+j,k,sizeof(day),compare2);
j=i;
k=1;
}
}
if(k>1)
qsort(a+j,k,sizeof(day),compare2);
int temp=-1,temp1;
for(i=0;i<n;i++)
{
//printf("%d %d\n",a[i].u, a[i].v);
temp1=min(a[i].u,a[i].v);
if(temp<=temp1)
temp=temp1;
else
temp=a[i].u+a[i].v-temp1;
}
printf("%d\n",temp);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 451689dccfc937a6593c3a96818ffd0b | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
//return *(int*)a-*(int*)b;
int *pa=(int*)a;
int *pb=(int*)b;
if(pa[0]==pb[0])
{
if(pa[1]>pb[1])
return 1;
else return -1;
}
else if(pa[0]>pb[0])
return 1;
else
return -1;
}
int main()
{
int n,m,i,j,k=0,x=-1;
int a[100009][2];
int b[100009];
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d%d",&a[i][0],&a[i][1]);
qsort(a,n,sizeof(a[0]),cmp);
b[0]=a[0][1];
for(i=0;i<n-1;i++)
{
if(a[i+1][1]<b[i])
{
k=1;
b[i+1]=a[i+1][0];
}
else
b[i+1]=a[i+1][1];
}
//if(k==0)
printf("%d",b[n-1]);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | cb58e50596c9c157e8a818671cb46547 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
struct stud{
long long f;
long long p;
};
int comp(const void *a, const void *b){
const struct stud *da = (const struct stud*)a;
const struct stud *db = (const struct stud*)b;
if(da->f==db->f)
return da->p - db->p;
return da->f - db->f;
}
int main(){
int n;
scanf("%d",&n);
struct stud arr[n];
int i;
for(i=0;i<n;i++){
scanf("%lld %lld",&arr[i].f,&arr[i].p);
}
qsort(arr,n,sizeof(struct stud),comp);
long long best = -1;
for(i = 0; i < n; i++) {
if (best <= arr[i].p) {
best = arr[i].p;
}
else {
best = arr[i].f;
}
}
printf("%lld",best);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 48975bef2a06048af87d1910bf198e5c | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include<stdio.h>
int main()
{int n;
scanf("%d",&n);
int a[n];
int b[n];
int i;
for(i=0;i<n;i++)
scanf("%d %d",&a[i],&b[i]);
int j;
int temp,temp1;
for(i=0;i<n;i++)
{for(j=0;j<n-1;j++)
{if(a[j]==a[j+1])
{if(b[j]>b[j+1])
{temp=b[j];
b[j]=b[j+1];
b[j+1]=temp;
}}
if(a[j+1]<a[j])
{
temp=a[j];
temp1=b[j];
b[j]=b[j+1];
b[j+1]=temp1;
a[j]=a[j+1];
a[j+1]=temp;
}
}}
long long int ans=b[0];
for(i=1;i<n;i++)
{if(b[i]>ans)
ans=b[i];
if(b[i]<ans)
ans=a[i];
}
printf("%lld\n",ans);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 7dc535cfd326d1ab3772440d1ecdace1 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include<stdio.h>
long long int min(long long int a[],long long int b[],long long int c[],long long int n)
{
long long int min;
long long int l=-1,i;
min=1000000001;
for(i=0;i<n;i++)
{
if(a[i]==min && c[i]==0){
if(b[i]<b[l]){
min=a[i];
l=i;
}
}
if(a[i]<min&&c[i]==0)
{
min=a[i];
l=i;
}
}
if(l!=-1)
c[l]=1;
return l;
}
int main(){
long long int n;
long long int l,i;
scanf("%lld",&n);
long long int a[n],b[n],c[n],d;
for(i=0;i<n;i++){
scanf("%lld %lld",&a[i],&b[i]);
c[i]=0;
}
l=min(a,b,c,n);
d=b[l];
while(l!=-1)
{
//l=min(a,c,n);
if(b[l]>=d)
d=b[l];
else
d=a[l];
l=min(a,b,c,n);
}
printf("%lld",d);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | d38424cfafff74d9c3209bd9cad0c812 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include <stdio.h>
void A(int ZA[], int ZB[], int ZC[], int ZD[], int a, int b)
{
int c, d, e, f;
if (a < b) {
c = a + (b - a + 1) / 2;
A(ZA, ZB, ZC, ZD, a, c - 1);
A(ZA, ZB, ZC, ZD, c, b);
d = c - 1;
e = 0;
f = a;
while (a <= d && c <= b) {
if (ZA[a] < ZA[c] || ZA[a] == ZA[c] && ZB[a] < ZB[c]) {
ZC[e] = ZA[a];
ZD[e] = ZB[a];
a += 1;
} else {
ZC[e] = ZA[c];
ZD[e] = ZB[c];
c += 1;
}
e += 1;
}
while (a <= d) {
ZC[e] = ZA[a];
ZD[e] = ZB[a];
a += 1;
e += 1;
}
while (c <= b) {
ZC[e] = ZA[c];
ZD[e] = ZB[c];
c += 1;
e += 1;
}
while (e--) {
ZA[f + e] = ZC[e];
ZB[f + e] = ZD[e];
}
}
}
int main()
{
int a, b, c;
int ZA[5000], ZB[5000], ZC[5000], ZD[5000];
scanf("%d", &a);
for (b = 0; b < a; ++b)
scanf("%d%d", ZA + b, ZB + b);
A(ZA, ZB, ZC, ZD, 0, a - 1);
c = ZA[0] < ZB[0] ? ZA[0] : ZB[0];
for (b = 1; b < a; ++b)
if (ZB[b] >= c)
c = ZB[b];
else
c = ZA[b];
printf("%d\n", c);
return 0;
}
| |
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date. | Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date. | C | 71bc7c4eb577441f2563e40d95306752 | 71e60652b479f51a4ee43dbd342e6e3c | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy"
] | 1413709200 | ["3\n5 2\n3 1\n4 2", "3\n6 1\n5 2\n4 3"] | NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject. | PASSED | 1,400 | standard input | 1 second | The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly. | ["2", "6"] | #include <stdio.h>
void A(int ZA[], int ZB[], int a, int b)
{
int c, d, e, f;
if (a < b) {
c = a + (b - a + 1) / 2;
d = ZA[c];
ZA[c] = ZA[b];
ZA[b] = d;
d = ZB[c];
ZB[c] = ZB[b];
ZB[b] = d;
f = a - 1;
for (e = a; e < b; ++e)
if (ZA[e] < ZA[b] || ZA[e] == ZA[b] && ZB[e] < ZB[b]) {
f += 1;
d = ZA[f];
ZA[f] = ZA[e];
ZA[e] = d;
d = ZB[f];
ZB[f] = ZB[e];
ZB[e] = d;
}
d = ZA[f + 1];
ZA[f + 1] = ZA[b];
ZA[b] = d;
d = ZB[f + 1];
ZB[f + 1] = ZB[b];
ZB[b] = d;
A(ZA, ZB, a, f);
A(ZA, ZB, f + 2, b);
}
}
int main()
{
int a, b, c;
int ZA[5000], ZB[5000];
scanf("%d", &a);
for (b = 0; b < a; ++b)
scanf("%d%d", ZA + b, ZB + b);
A(ZA, ZB, 0, a - 1);
c = ZA[0] < ZB[0] ? ZA[0] : ZB[0];
for (b = 1; b < a; ++b)
if (ZB[b] >= c)
c = ZB[b];
else
c = ZA[b];
printf("%d\n", c);
return 0;
}
| |
Hongcow likes solving puzzles.One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position. | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | C | b395be2597f4cc0478bc45f774fa1c01 | 76e3de9c0b7504a161feb2d2905180a9 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1481992500 | ["2 3\nXXX\nXXX", "2 2\n.X\nXX", "5 5\n.....\n..X..\n.....\n.....\n....."] | NoteFor the first sample, one example of a rectangle we can form is as follows 111222111222For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: .......XX................ | PASSED | 1,400 | standard input | 2 seconds | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece. The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space. It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region. | ["YES", "NO", "YES"] | #include <stdio.h>
int main(void) {
int m,n,flag=1,i,j,m1=-1,m2=-1;
scanf("%d%d",&n,&m);
getchar();
char mat[n][m];
for(i=0;i<n;i++){
for(j=0;j<m;j++)
scanf("%c",&mat[i][j]);
getchar();
}
for(i=0;i<n;i++)
{for(j=0;j<m;j++)
{
if(mat[i][j]=='X' && m1==-1){
m1=j;
}
else if(m1!=-1 && mat[i][j]!='X')
{
m2=j-1;
break;
}
}
if(m1!=-1 && m2==-1)
{
i++;
j=0;
m2=m-1;
break;
}
if(m1!=-1 && m2!=-1)
break;
}
for(;i<n;i++){
for(;j<m;j++)
{
//printf(i=%d,j=%d\n",i,j);
if(j>=m1 && j<=m2 && mat[i][j]!='X'){
flag=2;
break;
}
if(j<m1 || j>m2){
if(mat[i][j]=='X'){
flag=0;
break;
}
}
}
j=0;
//printf("%d",flag);
if(flag==2){
flag=1;
for(;i<n;i++){
for(;j<m;j++){
if(mat[i][j]=='X'){
flag=0;
break;
}
}
j=0;
if(flag==0)
break;
}
if(flag)
break;
}
if(flag==0)
break;
}
// printf("fla=%d",flag);
if(flag)
printf("YES");
else
printf("NO");
return 0;
}
| |
Hongcow likes solving puzzles.One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position. | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | C | b395be2597f4cc0478bc45f774fa1c01 | 985246e7ff37184fe06167be42e78673 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1481992500 | ["2 3\nXXX\nXXX", "2 2\n.X\nXX", "5 5\n.....\n..X..\n.....\n.....\n....."] | NoteFor the first sample, one example of a rectangle we can form is as follows 111222111222For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: .......XX................ | PASSED | 1,400 | standard input | 2 seconds | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece. The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space. It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region. | ["YES", "NO", "YES"] | #include <stdio.h>
#include <stdlib.h>
int main(void)
{
int m, n, i1 = -1, i2 = -1, j1 = -1, j2 = -1;
scanf("%d%d", &n, &m);
char c[n][m], enter;
scanf("%c", &enter);
for (int i = 0; i < n; ++i){
for (int j = 0; j < m; ++j){
scanf("%c", &c[i][j]);
if (c[i][j] == 'X' && j1 == -1){
j1 = j;
i1 = i;
}
if (j > 0 && c[i][j] == '.' && c[i][j - 1] == 'X' && j2 == -1)
j2 = j - 1;
if (c[i][j] == 'X' && j == m - 1 && j2 == -1)
j2 = j;
if (i > 0 && c[i][j] == '.' && c[i - 1][j] == 'X' && i2 == -1)
i2 = i - 1;
if (c[i][j] == 'X' && i == n - 1 && i2 == -1)
i2 = i;
}
scanf("%c", &enter);
}
for (int i = 0; i < n; ++i){
for (int j = 0; j < m; ++j){
if (i < i1 || i > i2 || j < j1 || j > j2){
if (c[i][j] == 'X'){
printf("NO");
return 0;
}
}
}
}
printf("YES");
return 0;
}
| |
Hongcow likes solving puzzles.One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position. | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | C | b395be2597f4cc0478bc45f774fa1c01 | 9277a47b6971eb6c6f7b9d53f995caf8 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1481992500 | ["2 3\nXXX\nXXX", "2 2\n.X\nXX", "5 5\n.....\n..X..\n.....\n.....\n....."] | NoteFor the first sample, one example of a rectangle we can form is as follows 111222111222For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: .......XX................ | PASSED | 1,400 | standard input | 2 seconds | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece. The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space. It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region. | ["YES", "NO", "YES"] | #include <stdio.h>
#include <string.h>
int main(void) {
int n = 0, m = 0, i = 0;
int contain = 0, poss = 1;
char init[501] = {0, }, *p = init, *q = 0;
char board[500][501] = {{0, }};
scanf("%d %d", &n, &m);
for (i=0;i<n;i++) {
scanf("%s", board[i]);
}
for (i=0;i<n;i++) {
q = board[i];
contain = 0;
while (*q) {
if (*q == 'X') {
contain = 1;
break;
}
q++;
}
if (contain) {
if (*p == 0) {
strcpy(p, board[i]);
} else {
if (strcmp(p, board[i]) != 0) {
poss = 0;
break;
}
}
}
}
printf("%s\n", (poss) ? "YES" : "NO");
return 0;
} | |
Hongcow likes solving puzzles.One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position. | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | C | b395be2597f4cc0478bc45f774fa1c01 | 16cc59c1795af1eccccf0aa26d269a66 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1481992500 | ["2 3\nXXX\nXXX", "2 2\n.X\nXX", "5 5\n.....\n..X..\n.....\n.....\n....."] | NoteFor the first sample, one example of a rectangle we can form is as follows 111222111222For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: .......XX................ | PASSED | 1,400 | standard input | 2 seconds | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece. The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space. It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region. | ["YES", "NO", "YES"] | #include <stdio.h>
int main(void) {
char matr[500][500];
int n, m, x = 0, i, j, x1 = 0, y = 0, y1 = 0, zvezdocki[2] = {0};
scanf("%d %d", &n ,&m);
for (i = 0; i < n; i++)
scanf("%s\n", matr[i]);
for(i = 0; i < n; i++) {
for(j = 0; j < m; j++)
if (matr[i][j] == 'X')
x1++;
if (x == 0)
x = x1;
if (x != x1 && x1 > 0)
zvezdocki[0] = 1;
x1 = 0;
}
for(i = 0; i < m; i++) {
for(j = 0; j < n; j++)
if (matr[j][i] == 'X')
y1++;
if (y == 0)
y = y1;
if (y != y1 && y1 > 0)
zvezdocki[1] = 1;
y1 = 0;
}
if (zvezdocki[0] == 0 && zvezdocki[1] == 0)
printf("YES\n");
else
printf("NO\n");
return 0;
}
| |
Hongcow likes solving puzzles.One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position. | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | C | b395be2597f4cc0478bc45f774fa1c01 | 8cdc2e3d95a0ff2bce4f6106d89cf5ee | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1481992500 | ["2 3\nXXX\nXXX", "2 2\n.X\nXX", "5 5\n.....\n..X..\n.....\n.....\n....."] | NoteFor the first sample, one example of a rectangle we can form is as follows 111222111222For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: .......XX................ | PASSED | 1,400 | standard input | 2 seconds | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece. The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space. It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region. | ["YES", "NO", "YES"] | #include <limits.h>
#include <stdio.h>
int main() {
int i, j, n, m, cnt, imin, jmin, imax, jmax;
static char cc[500][501];
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++)
scanf("%s", cc[i]);
imin = jmin = INT_MAX;
imax = jmax = 0;
cnt = 0;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
if (cc[i][j] == 'X') {
cnt++;
if (imin > i)
imin = i;
if (imax < i)
imax = i;
if (jmin > j)
jmin = j;
if (jmax < j)
jmax = j;
}
printf("%s\n", (imax - imin + 1) * (jmax - jmin + 1) != cnt ? "NO" : "YES");
return 0;
}
| |
Hongcow likes solving puzzles.One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position. | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | C | b395be2597f4cc0478bc45f774fa1c01 | 6092fe3914fd10b674582e8a2ba60a60 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1481992500 | ["2 3\nXXX\nXXX", "2 2\n.X\nXX", "5 5\n.....\n..X..\n.....\n.....\n....."] | NoteFor the first sample, one example of a rectangle we can form is as follows 111222111222For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: .......XX................ | PASSED | 1,400 | standard input | 2 seconds | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece. The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space. It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region. | ["YES", "NO", "YES"] | #include <stdio.h>
int main(void) {
char matr[500][500];
int n, m, x = 0, i, j, x1 = 0, y = 0, y1 = 0, sakib[2] = {0};
scanf("%d %d", &n ,&m);
for (i = 0; i < n; i++){
scanf("%s\n", matr[i]);
}
for(i = 0; i < n; i++) {
for(j = 0; j < m; j++)
if (matr[i][j] == 'X')
x1++;
if (x == 0)
x = x1;
if (x != x1 && x1 > 0) sakib[0] = 1; x1 = 0;
}
for(i = 0; i < m; i++) {
for(j = 0; j < n; j++)
if (matr[j][i] == 'X')
y1++;
if (y == 0)
y = y1;
if (y != y1 && y1 > 0)
sakib[1] = 1; y1 = 0;
}
if (sakib[0] == 0 && sakib[1] == 0)
printf("YES\n");
else
printf("NO\n");
return 0;
} | |
Hongcow likes solving puzzles.One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position. | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | C | b395be2597f4cc0478bc45f774fa1c01 | 1bf2536dc07672c5071d15a1679f0ecd | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1481992500 | ["2 3\nXXX\nXXX", "2 2\n.X\nXX", "5 5\n.....\n..X..\n.....\n.....\n....."] | NoteFor the first sample, one example of a rectangle we can form is as follows 111222111222For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: .......XX................ | PASSED | 1,400 | standard input | 2 seconds | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece. The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space. It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region. | ["YES", "NO", "YES"] | #include<stdio.h>
int main(void)
{
int a, a2 = 0, n, m, l = 0, l2;
char c, p;
scanf("%d %d\n", &n, &m);
for (int i = 0; i < n; i++){
p = '.';
l2 = 0;
a = 0;
for (int j = 0; j < m; j++){
c = getchar();
if (c == 'X'){
if (!a){
a = j + 1;
}
if (p == '.' && l2){
printf("NO");
return 0;
}
l2++;
}
p = c;
}
getchar();
if (!a2){
a2 = a;
}
if (!l){
l = l2;
} else if (l2){
if (l2 != l || a != a2){
printf("NO");
return 0;
}
}
}
printf("YES");
}
| |
Hongcow likes solving puzzles.One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position. | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | C | b395be2597f4cc0478bc45f774fa1c01 | 220c5949273b0563a14a01fb1ec7a70d | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1481992500 | ["2 3\nXXX\nXXX", "2 2\n.X\nXX", "5 5\n.....\n..X..\n.....\n.....\n....."] | NoteFor the first sample, one example of a rectangle we can form is as follows 111222111222For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: .......XX................ | PASSED | 1,400 | standard input | 2 seconds | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece. The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space. It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region. | ["YES", "NO", "YES"] | /* Copyright (C) tjua, Dec. 2016 */
/* Codeforces Round #385 (Div. 2) */
/* Problem B */
/* deal: is input puzzle a rectangle */
#include <stdio.h>
#include <string.h>
#include <assert.h>
#define a10 ".....""....."
#define a50 a10 a10 a10 a10 a10
#define a100 a50 a50
#define a500 a100 a100 a100 a100 a100
int main() {
int n, m;
char s[500][501];
scanf("%d%d ", &n, &m);
for (int i = 0; i < n; i++)
scanf("%s ", s[i]);
/* end of ^D */
int i;
for (i = 0; strcmp(s[i], a500 + 500 - m) == 0; i++)
;
int j1 = 0, j = 0;
while (s[i][j1] == '.')
j1++;
while (s[i][j1+j] == 'X')
j++;
if (strcmp(s[i]+j1+j, a500+ 500 -m+j1+j))
goto isn_rec;
int k = 1;
while (i+k<n && strcmp(s[i],s[i+k]) == 0)
k++;
while (i+k!=n) {
if (strcmp(s[i+k],a500+ 500 - m))
goto isn_rec;
k++;
}
/*
(() != 0) condition expr
非零即真 零为假 0
非尾即真 尾为假 s[len]
非空即真 空为假 NULL
不等 strcmp
(i+di)
(di)X orz
*/
puts("YES");
return 0;
isn_rec:
// printf("%s %s\n", s[i]+j1+j, a500+ 500 -m+j1+j);
// printf("%d %d %d\n", i , j1+j, i+k);
puts("NO");
return 0;
}
| |
Hongcow likes solving puzzles.One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position. | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | C | b395be2597f4cc0478bc45f774fa1c01 | 71330518695276e918f0291e5a74d40c | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1481992500 | ["2 3\nXXX\nXXX", "2 2\n.X\nXX", "5 5\n.....\n..X..\n.....\n.....\n....."] | NoteFor the first sample, one example of a rectangle we can form is as follows 111222111222For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: .......XX................ | PASSED | 1,400 | standard input | 2 seconds | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece. The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space. It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region. | ["YES", "NO", "YES"] | #include<stdio.h>
int main()
{
int arr[510]={0},count=0,c,p=0;
int i,j,n,m;
char str[510][510];
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
scanf("%s",str[i]);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(str[i][j]=='X')
{
arr[j]=1;
count++;
}
}
if(count)
break;
}
for(i=1;i<n;i++)
{
c=0;
for(j=0;j<m;j++)
{
if(str[i][j]=='X'&&arr[j])
c++;
else if(str[i][j]=='X'&&!arr[j])
p=1;
}
if(c!=count&&c)
{
p=1;
break;
}
}
if(p)
printf("NO\n");
else
printf("YES\n");
return 0;
}
| |
Hongcow likes solving puzzles.One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position. | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | C | b395be2597f4cc0478bc45f774fa1c01 | 043fb285ff04191928cc1803abcb390b | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1481992500 | ["2 3\nXXX\nXXX", "2 2\n.X\nXX", "5 5\n.....\n..X..\n.....\n.....\n....."] | NoteFor the first sample, one example of a rectangle we can form is as follows 111222111222For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: .......XX................ | PASSED | 1,400 | standard input | 2 seconds | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece. The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space. It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region. | ["YES", "NO", "YES"] | #include <string.h>
#include <stdio.h>
int main(void) {
int possible = 1;
char puzzle[501][501], line[501] = { 0 };
int n, m, i, j, fo = 0, first;
for (i = 0; i < 500; i++) {
line[i] = 0;
for (j = 0; j < 500; j++) {
puzzle[i][j] = 0;
}
}
scanf("%d %d", &n, &m);
for (i = 0; i < n; i++) {
scanf("%s", puzzle[i]);
for (j = 0; j < m; j++) {
line[j] = '.';
}
}
for (i = 0; i < n; i++) {
//printf("%s\n", puzzle[i]);
if (fo == 0) {
if (strcmp(puzzle[i], line) != 0) {
fo = 1;
first = i;
continue;
}
}
else if (strcmp(puzzle[i], line) == 0) break;
else if (strcmp(puzzle[first], puzzle[i]) != 0) {
possible = 0;
break;
}
}
if (possible == 1) printf("YES\n");
else printf("NO\n");
return 0;
} | |
Hongcow likes solving puzzles.One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position. | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | C | b395be2597f4cc0478bc45f774fa1c01 | 1285ad15d5ee0dca43aed4caae4fe725 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1481992500 | ["2 3\nXXX\nXXX", "2 2\n.X\nXX", "5 5\n.....\n..X..\n.....\n.....\n....."] | NoteFor the first sample, one example of a rectangle we can form is as follows 111222111222For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: .......XX................ | PASSED | 1,400 | standard input | 2 seconds | The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece. The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space. It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region. | ["YES", "NO", "YES"] | #include<stdio.h>
int arr[502][502];
int ar[502];
int main()
{
int n,m,i,j,a,ans=0,pass,close,anss=1,k=0;
char s[502];
scanf("%d %d",&n,&m);
i=0;j=0;
for(i=0;i<n;i++)
{
scanf("%s",s);
for(j=0;j<m;j++)
{
if(s[j]=='X')
arr[i][j]=1;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(arr[i][j]==1)
{ // printf("i is %d j is %d\n",i,j);
k=1;
j=0;
while(j<m)
{
ar[j]=arr[i][j];
j++;
}
break;
}
}
if(k==1)
break;
}
// check whether the row is solid
close=0;pass=0;ans=1;
for(j=0;j<m;j++)
{
if(pass==1 && close==1 && ar[j]==1)
ans=0;
if(pass==1 && ar[j]==0)
close=1;
if(ar[j]==1)
pass=1;
}
// check next rows
i=i+1;j=0;a=0;
// printf("aaa i is %d\n",i);
for(i=i;i<n;i++)
{
for(j=0;j<m;j++)
{
if(arr[i][j]!=ar[j])
{
// printf("i is %d\n",i);
a=1;
break;
}
}
if(a==1)
break;
}
// check rest of the rows to be empty
for(i=i;i<n;i++)
{
for(j=0;j<m;j++)
{
if(arr[i][j]!=0)
{
// printf("i is %d\n",i);
anss=0;
break;
}
}
if(anss==0)
{
// printf("%d %d\n",i,j);
break;
}
}
if(ans==1 && anss==1)
printf("YES");
else
printf("NO");
return 0;
}
| |
A root tree is a directed acyclic graph that contains one node (root), from which there is exactly one path to any other node.A root tree is binary if each node has at most two outgoing arcs.When a binary tree is painted on the plane, all arcs should be directed from top to bottom. That is, each arc going from u to v must meet the condition yu > yv.You've been given the coordinates of all tree nodes. Your task is to connect these nodes by arcs so as to get the binary root tree and make the total length of the arcs minimum. All arcs of the built tree must be directed from top to bottom. | If it is impossible to build a binary root tree on the given points, print "-1". Otherwise, print a single real number — the total length of the arcs in the minimum binary tree. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. | C | 0080bead488b85df3458cc772b27cc17 | e868d898c57b9e4c3080a205bbf9dfb1 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"flows",
"trees"
] | 1362065400 | ["3\n0 0\n1 0\n2 1", "4\n0 0\n1 0\n2 1\n2 0"] | null | PASSED | 2,400 | standard input | 3 seconds | The first line contains a single integer n (2 ≤ n ≤ 400) — the number of nodes in the tree. Then follow n lines, two integers per line: xi, yi (|xi|, |yi| ≤ 103) — coordinates of the nodes. It is guaranteed that all points are distinct. | ["3.650281539872885", "-1"] | /* practice with Dukkha */
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define N 400
#define N_ (1 + N + N + 1)
#define M_ (N + N * (N - 1) / 2 + N)
#define INF DBL_MAX
int next[1 + M_ * 2], hh[1 + M_ * 2];
int ii[M_], jj[M_]; double cost[M_], cost_[M_]; int cc[M_ * 2];
int ao[N_]; double pi[N_]; int dd[N_], ff[N_];
int pq[1 + N_], iq[N_], cnt;
int n_, m_; double ans;
int link(int l, int h) {
static int _ = 1;
next[_] = l, hh[_] = h;
return _++;
}
void link_(int i, int j, int c, double co) {
static int h;
ii[h] = i, jj[h] = j;
cost[h] = co;
cc[h << 1] = c;
ao[i] = link(ao[i], h << 1);
ao[j] = link(ao[j], h << 1 | 1);
h++;
}
int less(int u, int v) {
return pi[u] < pi[v] || pi[u] == pi[v] && dd[u] < dd[v];
}
int i2(int i) {
return (i *= 2) > cnt ? 0 : i < cnt && less(pq[i + 1], pq[i]) ? i + 1 : i;
}
void pq_up(int u) {
int i, j, v;
for (i = iq[u]; (j = i / 2) && less(u, v = pq[j]); i = j)
pq[iq[v] = i] = v;
pq[iq[u] = i] = u;
}
void pq_dn(int u) {
int i, j, v;
for (i = iq[u]; (j = i2(i)) && less(v = pq[j], u); i = j)
pq[iq[v] = i] = v;
pq[iq[u] = i] = u;
}
void pq_add_last(int u) {
pq[iq[u] = ++cnt] = u;
}
int pq_remove_first() {
int u = pq[1], v = pq[cnt--];
iq[v] = 1; pq_dn(v);
return u;
}
int dijkstra(int s, int t) {
int i;
for (i = 0; i < n_; i++)
pi[i] = INF;
pi[s] = 0;
pq_add_last(s);
while (cnt) {
int d, l;
i = pq_remove_first();
d = dd[i] + 1;
for (l = ao[i]; l; l = next[l]) {
int h_ = hh[l];
if (cc[h_]) {
int h = h_ >> 1, j = i ^ ii[h] ^ jj[h];
double p = pi[i] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);
if (pi[j] > p || pi[j] == p && dd[j] > d) {
if (pi[j] == INF)
pq_add_last(j);
pi[j] = p, dd[j] = d, ff[j] = h_;
pq_up(j);
}
}
}
}
return pi[t] != INF;
}
int trace(int s, int t) {
while (t != s) {
int h_ = ff[t], h = h_ >> 1;
cc[h_]--, cc[h_ ^ 1]++;
t ^= ii[h] ^ jj[h];
}
return 1;
}
int edmonds_karp(int s, int t) {
int h, f;
for (h = 0; h < m_; h++)
cost_[h] = cost[h];
f = 0;
while (dijkstra(s, t)) {
f += trace(s, t);
for (h = 0; h < m_; h++) {
int i = ii[h], j = jj[h];
if (pi[i] != INF && pi[j] != INF) {
/* pi[j] <= pi[i] + cost_[h]
* cost_[h] + pi[i] - pj[i] >= 0 */
cost_[h] += pi[i] - pi[j];
}
}
}
for (h = 0; h < m_; h++)
ans += cc[h << 1 | 1] * cost[h];
return f;
}
int main() {
static int xx[N], yy[N];
int n, i, j, s, t;
scanf("%d", &n), n_ = 1 + n + n + 1, m_ = n + n * (n - 1) / 2 + n;
for (i = 0; i < n; i++)
scanf("%d%d", &xx[i], &yy[i]);
s = n + n, t = s + 1;
for (i = 0; i < n; i++)
link_(s, i, 1, 0);
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++)
if (yy[i] != yy[j]) {
double d = hypot(xx[j] - xx[i], yy[j] - yy[i]);
if (yy[i] < yy[j])
link_(i, n + j, n, d);
else
link_(j, n + i, n, d);
}
for (i = 0; i < n; i++)
link_(n + i, t, 2, 0);
if (edmonds_karp(s, t) == n - 1)
printf("%f\n", ans);
else
printf("-1\n");
return 0;
}
| |
Alex decided to go on a touristic trip over the country.For simplicity let's assume that the country has $$$n$$$ cities and $$$m$$$ bidirectional roads connecting them. Alex lives in city $$$s$$$ and initially located in it. To compare different cities Alex assigned each city a score $$$w_i$$$ which is as high as interesting city seems to Alex.Alex believes that his trip will be interesting only if he will not use any road twice in a row. That is if Alex came to city $$$v$$$ from city $$$u$$$, he may choose as the next city in the trip any city connected with $$$v$$$ by the road, except for the city $$$u$$$.Your task is to help Alex plan his city in a way that maximizes total score over all cities he visited. Note that for each city its score is counted at most once, even if Alex been there several times during his trip. | Output single integer which is the maximum possible sum of scores of visited cities. | C | 824c7f11e6c2997c98741d314cdd1970 | 10751e353deacb02885a7c7a17094807 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"greedy",
"graphs",
"dsu",
"dfs and similar",
"trees"
] | 1568822700 | ["5 7\n2 2 8 6 9\n1 2\n1 3\n2 4\n3 2\n4 5\n2 5\n1 5\n2", "10 12\n1 7 1 9 3 3 6 30 1 10\n1 2\n1 3\n3 5\n5 7\n2 3\n5 4\n6 9\n4 6\n3 7\n6 8\n9 4\n9 10\n6"] | null | PASSED | 2,200 | standard input | 2 seconds | First line of input contains two integers $$$n$$$ and $$$m$$$, ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) which are numbers of cities and roads in the country. Second line contains $$$n$$$ integers $$$w_1, w_2, \ldots, w_n$$$ ($$$0 \le w_i \le 10^9$$$) which are scores of all cities. The following $$$m$$$ lines contain description of the roads. Each of these $$$m$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$) which are cities connected by this road. It is guaranteed that there is at most one direct road between any two cities, no city is connected to itself by the road and, finally, it is possible to go from any city to any other one using only roads. The last line contains single integer $$$s$$$ ($$$1 \le s \le n$$$), which is the number of the initial city. | ["27", "61"] | #include <stdio.h>
typedef unsigned int uint;
typedef unsigned long long ull;
struct uu {
uint first, second;
};
ull w[200000];
uint hd[200000] = {0}, deg[200000] = {0};
struct uu adj[400001];
uint cnt = 0;
static inline void addEdge(uint u, uint v) {
adj[++cnt].first = v; adj[cnt].second = hd[u];
hd[u] = cnt;
deg[u]++;
}
int main() {
uint n, m;
scanf("%u %u", &n, &m);
for (uint i = 0; i < n; i++) { scanf("%u", w+i); }
adj[0].second = 0;
while (m--) {
uint a, b;
scanf("%u %u", &a, &b);
a--; b--;
addEdge(a, b); addEdge(b, a);
}
uint s;
scanf("%u", &s); s--;
for (uint i = 0; i < n; i++) {
uint u = i;
while (deg[u] == 1U && u != s) {
deg[u] = 0U;
uint nextu = u;
ull w0 = 0ULL;
for (uint pos = hd[u]; pos; pos = adj[pos].second) {
uint v = adj[pos].first;
if (deg[v]) { deg[v]--; nextu = v; }
else if (w0 < w[v]) { w0 = w[v]; }
}
w[u] += w0;
u = nextu;
}
}
ull ans = 0, e = 0;
for (uint u = 0; u < n; u++) {
if (deg[u] || u == s) { ans += w[u]; }
else if (e < w[u]) { e = w[u]; }
}
printf("%I64u\n", ans+e);
return 0;
}
| |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | 421ca998080f2007274dfb473500aa7e | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include<stdio.h>
int main()
{
int x1,x2,x3,x4,a,b,c,d;
scanf("%d%d%d%d",&x1,&x2,&x3,&x4);
if(x1>x2 && x1>x3 && x1>x4)
{
a = x1 - x2;
b = x1 - x3;
c = x1 - x4;
printf("%d %d %d\n",c,b,a);
}
else if(x2>x1 && x2>x3 && x2>x4)
{
a = x2 - x1;
b = x2 - x3;
c = x2 - x4;
printf("%d %d %d\n",c,b,a);
}
else if(x3>x1 && x3>x2 && x3>x4)
{
a = x3 - x1;
b = x3 - x2;
c = x3 - x4;
printf("%d %d %d\n",c,b,a);
}
else
{
a = x4 - x1;
b = x4 - x2;
c = x4 - x3;
printf("%d %d %d\n",c,b,a);
}
return 0;
}
| |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | 27ff44db4ccefb8a77991e8ae8d02c42 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include<stdio.h>
#include<math.h>
int main()
{long long int n,n1,n2,n3,n4;
scanf("%lld\t%lld\t%lld\t%lld\n", &n1,&n2,&n3,&n4)!=EOF;
n=((n1+n2+n3+n4)/3);
if((n-n1)!=0){printf("%lld\t", n-n1);}
if((n-n2)!=0){printf("%lld\t", n-n2);}
if((n-n3)!=0){printf("%lld\t", n-n3);}
if((n-n4)!=0){printf("%lld", n-n4);}return 0;} | |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | 03089d3011b33c719e3f738f4d7364f5 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{long long int n,n1,n2,n3,n4,s1,s2,s3,s4;
scanf("%lld\t%lld\t%lld\t%lld\n", &n1,&n2,&n3,&n4)!=EOF;
n=((n1+n2+n3+n4)/3);
s1=abs(n-n1);s2=abs(n-n2);s3=abs(n-n3);s4=(n-n4);
if(s1!=0){printf("%lld\t", s1);}
if(s2!=0){printf("%lld\t", s2);}
if(s3!=0){printf("%lld\t", s3);}
if(s4!=0){printf("%lld", s4);}return 0;} | |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | 46acda3d5ddc6bddd0c99ed91be3bc8c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{long long int n,n1,n2,n3,n4;
scanf("%lld\t%lld\t%lld\t%lld\n", &n1,&n2,&n3,&n4)!=EOF;
n=((n1+n2+n3+n4)/3);
if((n-n1)!=0){printf("%lld\t", n-n1);}
if((n-n2)!=0){printf("%lld\t", n-n2);}
if((n-n3)!=0){printf("%lld\t", n-n3);}
if((n-n4)!=0){printf("%lld", n-n4);}return 0;} | |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | 6136e6eb3d84d4e1056dfaf79a55f6a8 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include<stdio.h>
int main()
{
int i,j,temp,a[4];
scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3]);
for(i=0;i<4;i++){
for(j=i+1;j<4;j++){
if(a[i]>a[j]){
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("%d\t",a[3]-a[2]);
printf("%d\t",a[3]-a[1]);
printf("%d\t",a[3]-a[0]);
return 0;
}
| |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | 0b3dd6f64699893359956ce1adefa6b0 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include<stdio.h>
int main()
{
long long int x1,x2,x3,x4,i,c,d;
scanf("%lld %lld %lld %lld",&x1,&x2,&x3,&x4);
c=(x1>x2)?(x1>x3)?x1:x3:(x2>x3)?x2:x3;
d=(c>x4)?c:x4;
if(d!=x1) printf("%lld ",d-x1);
if(d!=x2) printf("%lld ",d-x2);
if(d!=x3) printf("%lld ",d-x3);
if(d!=x4) printf("%lld ",d-x4);
return 0;
} | |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | c911737fd7b560c70688f5ea4c0f46c8 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include<stdio.h>
int main()
{
long long int i,j,a[4],b=0,c=0,d=0,temp;
for(i=0;i<4;i++)
scanf("%lld",&a[i]);
for(i=0;i<4;i++){
for(j=0;j<3;j++) //only change
if(a[j+1]>a[j]){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
b=a[0]-a[1];
c=a[0]-a[2];
d=a[0]-a[3];
printf("%lld %lld %lld",b,c,d);
} | |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | d080f031388a98e38c377592ce5b193c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include<stdio.h>
int main()
{
long long int a,b,c,d,i,j,k,l,x,y,z;
scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
if(a>b && a>c && a>d)
{
i=a,j=b,k=c,l=d;
}
else if(b>a && b>c && b>d)
{
i=b,j=a,k=c,l=d;
}
else if(c>a && c>b && c>d)
{
i=c,j=a,k=b,l=d;
}
else if(d>a && d>b && d>c)
{
i=d,j=a,k=b,l=c;
}
x=i-j;
y=i-k;
z=i-l;
printf("%lld %lld %lld",x,y,z);
}
| |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | 7a38f1ac0fae0508d3b96f93770d8737 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include <stdio.h>
int main()
{
int a[5],max=0,x,i,j,y,z;
for(i=0;i<4;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<4;i++)
{
for(j=0;j<3;j++)
{
if(a[j]>a[j+1])
{
max=a[j];
a[j]=a[j+1];
a[j+1]=max;
}
}
}
x=a[3]-a[2];
y=a[3]-a[1];
z=a[3]-a[0];
printf("%d %d %d",x,y,z);
return 0;
} | |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | 1f88598dda83e897bd82e14d8097d6d3 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
int main()
{
long x[4] = {3, 6, 5, 4};
int i, count;
for(i = 0; i < 4; i++)
scanf(" %ld", &x[i]);
long maxi = x[0];
for(i = 0; i < 4; i++)
if(x[i] >= maxi)
maxi = x[i];
long s = maxi;
for(i = 0; i < 4; i++)
{
x[i] = s - x[i];
if(x[i] == 0)
count++;
}
if(count == 2)
{
for(i = 0; i < 4; i++)
{
if(x[i] != 0)
printf("%ld ", x[i]);
}
printf("%d", 0);
}
else
{
for(i = 0; i < 4; i++)
{
if(x[i] != 0)
printf("%ld ", x[i]);
}
}
return 0;
}
| |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | d973d4a8a7db7c01ed5fd3165968c8a0 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include<stdio.h>
#include<stdint.h>
int main()
{
uint32_t sum, i;
uint32_t Arr[100];
for (i = 0; i < 4; i ++)
{
scanf("%d", &Arr[i]);
sum = sum + Arr[i];
}
sum = sum / 3;
for (i = 0; i < 4; i ++)
{
Arr[i + 5] = sum - Arr[i];
if (Arr[i + 5] > 0)
{
printf("%d ", Arr[i + 5]);
}
}
return 0;
} | |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | 72d7008a7796cf1aa7aa42acc5ed25c4 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include<stdio.h>
int main()
{
unsigned int sum, i;
unsigned int Arr[100];
for (i = 0; i < 4; i ++)
{
scanf("%d", &Arr[i]);
sum = sum + Arr[i];
}
sum = sum / 3;
for (i = 0; i < 4; i ++)
{
Arr[i + 5] = sum - Arr[i];
if (Arr[i + 5] > 0)
{
printf("%d ", Arr[i + 5]);
}
}
return 0;
} | |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | d42b675a3502ab6853a659fc22702767 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include<stdio.h>
int main()
{
int x1,x2,x3,x4,A[4],max,i,a,b,c;
scanf("%d %d %d %d",&x1,&x2,&x3,&x4);
A[0]=x1;
A[1]=x2;
A[2]=x3;
A[3]=x4;
max=A[0];
for(i=1; i<4; i++) {
if(A[i]>max) {
max=A[i];
}
}
if(max==A[0]) {
a=max-A[1];
b=max-A[2];
c=max-A[3];
printf("%d %d %d",c,b,a);
}
else if(max==A[1]) {
a=max-A[0];
b=max-A[2];
c=max-A[3];
printf("%d %d %d",c,b,a);
}
else if(max==A[2]) {
a=max-A[0];
b=max-A[1];
c=max-A[3];
printf("%d %d %d",c,b,a);
}
else if(max==A[3]) {
a=max-A[0];
b=max-A[1];
c=max-A[2];
printf("%d %d %d",c,b,a);
}
} | |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | dce9e342bfd8eeacdd67e51bdec83a46 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int q[4];
int n=1,k=0;
for(int i=0;i<4;++i)
{
scanf("%d",&q[i]);
if (n<q[i])
{
n=q[i];
k=i;
}
}
for (int i;i<4;++i)
{
if(i-k!=0)
printf("%d ",n-q[i]);
}
/// system("pause");
return 0;
}
| |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | cea04faa971de1996ec839c8d69ced45 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include<stdio.h>
int main()
{
int x[4], i, j, temp;
for(i = 0; i < 4; i++)
{
scanf("%d", &x[i]);
}
for(i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
{
if(x[j] < x[j + 1])
{
temp = x[j];
x[j] = x[j + 1];
x[j + 1] = temp;
}
}
}
printf("%d %d %d", x[0] - x[1], x[0] - x[2], x[0] - x[3]);
return 0;
} | |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | 4e5155f9ee01c67ae932cdcb75596978 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include<stdio.h>
int main()
{
long long int w,x,y,z,s,m,n,o,p,a,t,b,c;
scanf("%lld %lld %lld %lld", &w,&x,&y,&z);
o=w>x?w:x;
p=o>y?o:y;
s=p>z?p:z;
if(s == w){
w = x;
x = y;
y = z;
}
else if(s == x){
w = w;
x = y;
y = z;
}
else if(s == y){
w = w;
x = x;
y = z;
}
else if(s == z){
w = w;
x = x;
y = y;
}
m = w -y;
n = m+x;
a = n/2;
b = w - a;
c = y - b;
printf("%lld %lld %lld", a,b,c);
return 0;
} | |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | 76e62db4024213593fae58e86eaebe68 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include <stdio.h>
int main()
{
int a,b,c,d,l,m,n;
scanf("%d %d %d %d",&a,&b,&c,&d);
if(a>=b&&a>=c&&a>=d)
{
l=a-b;
m=a-c;
n=a-d;
printf("%d %d %d",l,m,n);
}
else if(b>=a&&b>=c&&b>=d)
{
l=b-a;
m=b-c;
n=b-d;
printf("%d %d %d",l,m,n);
}
else if(c>=a&&c>=b&&c>=d)
{
l=c-a;
m=c-b;
n=c-d;
printf("%d %d %d",l,m,n);
}
else
{
l=d-a;
m=d-b;
n=d-c;
printf("%d %d %d",l,m,n);
}
return 0;
}
| |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | 9d213f0d5222002df3da925b798bce6f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include <stdio.h>
int main()
{
long long int X[5] = {0}, ABC, j, i;
scanf("%lld%lld%lld%lld", &X[1], &X[2], &X[3], &X[4]);
ABC = X[1];
j = 1;
for(i=2;i<=4;i++)
if(X[i] > ABC)
{
ABC = X[i];
j = i;
}
for(i=1;i<=4;i++)
{
if(i != j)
printf("%lld ", ABC - X[i]);
}
return 0;
}
| |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | d8be6df05f5af9c30271f7e1c3f9c0ee | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include <stdio.h>
#include <math.h>
int main()
{
unsigned long int a[4],sum;
int i;
sum=0;
for(i=0;i<4;i=i+1)
{
scanf("%lu",&a[i]);
sum=sum+a[i];
}
sum=(sum)/3;
for(i=0;i<4;i=i+1)
{
unsigned long int diff;
diff=sum-a[i];
if(diff!=0)
{
printf("%lu ",diff);
}
}
return 0;
}
| |
Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$). | Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. | C | cda949a8fb1f158f3c06109a2d33f084 | 9dc90d5cb83756079338b99a800e02db | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"math"
] | 1555425300 | ["3 6 5 4", "40 40 40 60", "201 101 101 200"] | null | PASSED | 800 | standard input | 1 second | The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$. | ["2 1 3", "20 20 20", "1 100 100"] | #include <stdio.h>
int main()
{
long long q,w,e,r,t;
scanf("%lld %lld %lld %lld",&q,&w,&e,&r);
t=(q+w+e+r)/3;
if(t-q==0)
{
printf("%lld %lld %lld",q-w,q-e,q-r);
}
if(t-w==0)
{
printf("%lld %lld %lld",w-e,w-r,w-q);
}
if(t-e==0)
{
printf("%lld %lld %lld",e-q,e-w,e-r);
}
if(t-r==0)
{
printf("%lld %lld %lld",r-q,r-w,r-e);
}
return 0;
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | 526262fb00f3eb094589173c3fbb3017 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include <stdio.h>
int R,C;
char a[502][502];
int rr[4]={1,0,-1,0},cc[4]={0,1,0,-1};
int go(int r,int c) {
if (r==R&&c==C&&a[r][c]=='X') return 1;
if (a[r][c]!='.') return 0;
a[r][c]='X';
int i;
for (i=0;i<4;i++)
if (go(r+rr[i],c+cc[i])) return 1;
return 0;
}
int main() {
int n,m;
scanf("%d %d\n",&n,&m);
int i;
for (i=1;i<=n;i++)
scanf("%s",1+a[i]);
int r,c;
scanf("%d %d\n",&r,&c);
a[r][c]='.';
scanf("%d %d\n",&R,&C);
printf("%s\n",go(r,c)?"YES":"NO");
return 0;
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | 3407c4ca67aa29ab54227d3330939514 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
char map[1001][1001];
int vi[1001][1001];
int row, col;
int sx, sy, dx, dy;
void init()
{
int i,j,con=0;
for (i = 0; i < row; i++){
for (j = 0; j < col; j++){
vi[i][j] = 0;
}
}
}
struct cell{
int x;
int y;
int depth;
};
typedef struct cell cell;
cell qq[1000000];
int head, tail;
void qpush(cell x){
qq[tail++] = x;
}
cell qpop(){
return qq[head++];
}
int qempty(){
if (head == tail)
return 1;
return 0;
}
int crossed(int x, int y){
if (x < 0 || x >= row)
return 1;
if (y < 0 || y >= col)
return 1;
return 0;
}
int mov[4][2] = { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 }, };
int solve(int sx, int sy, int dx, int dy){
//printf("Start: (%d, %d) Finish : (%d, %d)\n", sx, sy, dx, dy);
cell now, next;
now.x = sx;
now.y = sy;
now.depth = 0;
vi[sx][sy] = 0;
qpush(now);
int i, j;
int nx, ny;
while (!qempty()){
now = qpop();
//vi[now.x][now.y] = 1;
//printf("(%d,%d) depth: %d\n", now.x, now.y,now.depth);
for (i = 0; i < 4; i++){
nx = now.x + mov[i][0];
ny = now.y + mov[i][1];
if (crossed(nx, ny))
continue;
if (vi[nx][ny])
continue;
if (map[nx][ny] == 'X' && !(nx == dx&&ny == dy))
continue;
//printf("(%d,%d)->(%d,%d)\n", now.x, now.y, nx, ny);
next.x = nx;
next.y = ny;
next.depth = now.depth + 1;
if (nx == dx && ny == dy&&map[nx][ny]=='X')
return now.depth + 1;
if (map[nx][ny] == '.')
{
//vi[nx][ny] = 1;
}
if (map[nx][ny] == '.')
map[nx][ny] = 'X';
qpush(next);
}
}
return -1;
}
int main(){
int i, j,ans;
while (scanf("%d%d",&row,&col)==2)
{
for (i = 0; i < row;i++)
{
scanf("%s",map[i]);
}
scanf("%d%d",&sx,&sy);
scanf("%d%d",&dx,&dy);
init();
head = tail = 0;
ans = solve(sx - 1, sy - 1, dx - 1, dy - 1);
if (ans != -1)
printf("YES\n");
else
{
printf("NO\n");
}
}
return 0;
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | f8b774b756624b060d5187e929268662 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include <stdio.h>
char A[550][550];
int m,n,ax,ay,ex,ey,flag;
void readin()
{
int i,j;
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
scanf(" %c",&A[i][j]);
scanf("%d %d",&ax,&ay);
scanf("%d %d",&ex,&ey);
}
void f(int x,int y)
{
if(flag==1)
return;
if(x==ex && y==ey && A[x][y]=='X')
{
printf("YES");
flag=1;
return;
}
if(A[x][y]=='X')
return;
if(x>n || x<1 || y>m || y<1)
return;
A[x][y]='X';
f(x+1,y);
f(x-1,y);
f(x,y-1);
f(x,y+1);
}
int main()
{
readin();
A[ax][ay]='.';
f(ax,ay);
if(flag==0)
printf("NO");
return 0;
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | 039f2dc7854d034f1ea69f2c76ad9539 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include<stdio.h>
#include<malloc.h>
char a[501][501];
int **b;
int n,m,x,y;
int flag=1;
void find(int **p,int i,int j)
{
//printf("%d %d\n",i,j);
if(i==x&&j==y)
{flag=0;
return;
}
int **q;
q=p;
if(j+1<=m&&(p[i][j+1]==1||(i==x&&j+1==y)))
{
q[i][j+1]=0;
find(q,i,j+1);
}
//printf("hi1\n");
q=p;
if(j-1>0&&(p[i][j-1]==1||(i==x&&j-1==y)))
{
q[i][j-1]=0;
find(q,i,j-1);
}
//printf("hi2\n");
q=p;
if(i+1<=n&&(p[i+1][j]==1||(i+1==x&&j==y)))
{
q[i+1][j]=0;
find(q,i+1,j);
}
//printf("hi3\n");
q=p;
if(i-1>0&&(p[i-1][j]==1||(i-1==x&&j==y)))
{
q[i-1][j]=0;
find(q,i-1,j);
}
//printf("hi4\n");
return ;
}
int main()
{
scanf("%d %d",&n,&m);
char ch;
int i,j;
int w[501][501];
b=(int *)malloc((n+1)*sizeof(int *));
for(i=1;i<=n;i++)
b[i]=(int)malloc((m+1)*sizeof(int));
for(i=0;i<n;i++)
{
ch=getchar();
scanf("%s",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{if(a[i][j]=='.')
b[i+1][j+1]=1;
else
b[i+1][j+1]=0;
w[i+1][j+1]=b[i+1][j+1];
}
}
/*
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
printf("%d ",b[i][j]);
printf("\n");
}
*/
int c,d;
scanf("%d %d",&c,&d);
scanf("%d %d",&x,&y);
find(b,c,d);
//printf("fnsdk%d\n",flag);
if(flag==1)
printf("NO\n");
else
{
if(w[x][y]==0&&!(c==x&&d==y))
printf("YES\n");
else
{
int count=0;
flag=0;
if(y+1<=m&&(c==x&&d==y+1))
flag=1;
if(y-1>0&&(x==c&&d==y-1))
flag=1;
if(x+1<=n&&(x+1==c&&d==y))
flag=1;
if(x-1>0&&(x-1==c&&d==y))
flag=1;
//printf("%d\n",flag);
if(y+1<=m&&w[x][y+1]==1)
count++;
if(y-1>0&&w[x][y-1]==1)
count++;
if(x+1<=n&&w[x+1][y]==1)
count++;
if(x-1>0&&w[x-1][y]==1)
count++;
if(count>=2||(count==1&&(c==x&&d==y)))
printf("YES\n");
else if(count==1&&flag==1)
printf("YES\n");
else
printf("NO\n");
}
}
return 0;
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | 4e8e7ba1d046af91f9f4986f184ffde0 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include <stdio.h>
long long int x,y,i,j,bx,by,cx,cy,flag;
char A[505][505];
void f(int a,int b)
{
if (flag==1)
return;
if(a>x || b>y || a<1 || b<1)
return ;
if(a==cx && b==cy && A[a][b]=='X')
{
printf("YES");
flag=1;
return;
}
if(A[a][b]=='X')
return;
A[a][b]='X';
f(a+1,b);
f(a-1,b);
f(a,b+1);
f(a,b-1);
}
int main()
{
scanf("%lld %lld",&x,&y);
for (i = 1; i <=x ; i++)
{
for (j = 1; j <=y ; j++)
{
scanf(" %c",&A[i][j]);
}
}
scanf("%lld %lld %lld %lld",&bx,&by,&cx,&cy);
A[bx][by]='.';
f(bx,by);
if (flag==0)
printf("NO");
return 0;
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | 207185ac1e4585094b1aac2d687faf83 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include <stdio.h>
int x1,x2,i,j,a1,a2,y10,y2,flag=0,k;
char A[1000][1000];
void fileread()
{
scanf("%d %d",&x1,&x2);
for (i = 1; i <=x1 ; i++)
{
for (j = 1; j <=x2 ; j++)
{
scanf(" %c",&A[i][j]);
}
}
scanf("%d %d",&a1,&a2);
scanf("%d %d",&y10,&y2);
A[a1][a2]='.';
}
void f(int s1,int s2)
{
if (flag==1)
return;
if ((A[s1][s2]=='X'))
{
if (s1==y10 && s2==y2)
{
printf("YES");
flag=1;
return;
}
else
return;
}
A[s1][s2]='X';
if (s1+1<=x1)
f(s1+1,s2);
if (s2+1<=x2)
f(s1,s2+1);
if (s1-1>0)
f(s1-1,s2);
if (s2-1>0)
f(s1,s2-1);
}
int main()
{
fileread();
f(a1,a2);
k=0;
if (flag==0)
printf("NO");
return 0;
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | 83c5aa6dd3c08097e17be46de7d6e323 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include <stdio.h>
#include <string.h>
int N, M;
char Map[500][501];
char Visit[500][501];
int Queue[250000][2];
int step[4][2] = {{ -1, 0}, {1, 0}, {0, -1}, {0, 1}};
int BFS(int x, int y, int tx, int ty)
{
int Head, Tail, i;
Head = 0;
Tail = 1;
Queue[Head][0] = x;
Queue[Head][1] = y;
memset(&Visit, 0, sizeof(Visit));
while(Head < Tail) {
for(i = 0; i < 4; ++i) {
int newX = Queue[Head][0] + step[i][0];
int newY = Queue[Head][1] + step[i][1];
if(newX >= 0 && newX < N && newY >= 0 && newY < M) {
if(newX == tx && newY == ty) {
return 1;
}
if(!Visit[newX][newY] && Map[newX][newY] == '.') {
Visit[newX][newY] = 1;
Queue[Tail][0] = newX;
Queue[Tail++][1] = newY;
}
}
}
++Head;
}
return 0;
}
int main()
{
int i, r1, c1, r2, c2;
scanf("%d %d", &N, &M);
for(i = 0; i < N; ++i) {
scanf("%s", Map[i]);
}
scanf("%d %d %d %d", &r1, &c1, &r2, &c2);
--r1, --c1, --r2, --c2;
char flag = 1;
if(Map[r2][c2] != 'X') {
int cnt = 0;
for(i = 0; i < 4; ++i) {
int newX = r2 + step[i][0];
int newY = c2 + step[i][1];
if(newX >= 0 && newX < N && newY >= 0 && newY < M) {
if(Map[newX][newY] == '.' || (newX == r1 && newY == c1)) {
++cnt;
}
}
}
flag = cnt > 1;
}
puts((flag && BFS(r1, c1, r2, c2)) ? "YES" : "NO");
return 0;
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | 7cd8d51e583bebb791b628563e6a5399 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include<stdio.h>
int fx,fy,ans=0,check=0;
int n,m;
int flag[505][505]={0};
void dfs(int x,int y,int g)
{
int i,j;
/*printf("****\n");
printf("%d %d\n",x,y);
for(i=1;i<=n;i++)
{
printf("\n");
for(j=1;j<=m;j++)
printf("%d ",flag[i][j]);
}
printf("\n*****\n");*/
if(fx==x && fy==y && g==0)
{
ans=1;
if(flag[x][y]==1)
check=1;
return;
}
if(flag[x][y]==1 && g==0)
return;
if(((fx!=x || fy!=y) && g==0) || (fx==x && fy==y && g==1))
{
//printf("HERE\n");
flag[x][y]=1;
if((fx-x==1 || fx-x==-1) && fy==y)
{
if(fx-x==1)
dfs(x+1,y,0);
else
dfs(x-1,y,0);
}
else if((fy-y==1 || fy-y==-1) && fx==x)
{
if(fy-y==1)
dfs(x,y+1,0);
else
dfs(x,y-1,0);
}
else
{
if(x!=n)
if(ans==0)
dfs(x+1,y,0);
if(x!=1)
if(ans==0)
dfs(x-1,y,0);
if(y!=m)
if(ans==0)
dfs(x,y+1,0);
if(y!=1)
if(ans==0)
dfs(x,y-1,0);
}
}
}
int main()
{
scanf("%d %d",&n,&m);
int i,j;
char s;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
scanf(" %c",&s);
if(s=='X')
flag[i][j]=1;
}
}
int a,b;
scanf("%d %d %d %d",&a,&b,&fx,&fy);
flag[a][b]=0;
dfs(a,b,0);
//printf("OUT HERE\n");
/*for(i=1;i<=n;i++)
{
printf("\n");
for(j=1;j<=m;j++)
printf("%d ",flag[i][j]);
}*/
if(ans==1)
{
if(check==1)
printf("YES\n");
else
{
ans=0;
flag[fx][fy]=1;
dfs(fx,fy,1);
if(ans==1 && check==1)
printf("YES\n");
else
printf("NO\n");
}
}
else
printf("NO\n");
return 0;
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | a1f86b9dfd03c55b6688ceabd609a2f8 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include<stdio.h>
int state=0,vi[501][501],r,c,r2,c2;
void func(int n,int m)
{
// printf("%d %d\n",n,m);
if(n+1<r && state==0)
{
if(n+1==r2 && m==c2 && vi[n+1][m]==1)
state=1;
if(vi[n+1][m]==0)
{
vi[n+1][m]=1;
func(n+1,m);
}
}
if(m+1<c && state==0)
{
if(n==r2 && m+1==c2 && vi[n][m+1]==1)
state=1;
if(vi[n][m+1]==0)
{
vi[n][m+1]=1;
func(n,m+1);
}
}
if(n-1>=0 && state==0)
{
if(n-1==r2 && m==c2 && vi[n-1][m]==1)
state=1;
if(vi[n-1][m]==0)
{
vi[n-1][m]=1;
func(n-1,m);
}
}
if(m-1>=0 && state==0)
{
if(n==r2 && m-1==c2 && vi[n][m-1]==1)
state=1;
if(vi[n][m-1]==0)
{
vi[n][m-1]=1;
func(n,m-1);
}
}
return ;
}
int main()
{
int r1,c1,i,j;
char cha[505];
scanf("%d %d",&r,&c);
for(i=0;i<r;i++)
{
scanf("\n%s",cha);
for(j=0;j<c;j++)
if(cha[j]=='.')
vi[i][j]=0;
else
vi[i][j]=1;
}
scanf("%d %d %d %d",&r1,&c1,&r2,&c2);
r1--;r2--;c1--;c2--;
vi[r1][c1]=1;
/* for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
printf("%d ",vi[i][j]);
printf("\n");
}*/
func(r1,c1);
if(state==1)
printf("YES\n");
else
printf("NO\n");
return 0;
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | bf8be8f83a5bd98f0294849424457200 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include<stdio.h>
char s[502][502];
int r,c,x,y,a[]={1,0,-1,0},b[]={0,1,0,-1};
int meth(int r,int c)
{
if(r==x && c==y && s[r][c]=='X')
return 1;
if(s[r][c]!='.')
return 0;
s[r][c]='X';
int i;
for(i=0;i<4;++i)
if(meth(r+a[i],c+b[i]))
return 1;
return 0;
}
int main()
{
int n,m,i;
scanf("%d%d",&n,&m);
for(i=1;i<=n;++i)
scanf("%s",1+s[i]);
scanf("%d%d%d%d",&r,&c,&x,&y);
s[r][c]='.';
if(meth(r,c))
printf("YES");
else
printf("NO");
return 0;
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | a6b5e4bf90408d7339bcf78178af9902 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include<stdio.h>
#include<stdlib.h>
int i,j,k,s,n,m,hash[1000][1000],iX,iY,eX,eY;
char c;
void dfs(int x, int y) {
if(hash[x][y] >= 3 && x == eX && y == eY) { puts("YES"); exit(0); }
if(hash[x][y] >= 3 || x < 0 || x >= n || y < 0 || y >= m) return ;
hash[x][y]++;
dfs(x,y+1);
dfs(x,y-1);
dfs(x+1,y);
dfs(x-1,y);
}
int main(){
scanf("%d %d", &n, &m);
for(i = 0; i < n; i++) {
for(j = 0; j < m; j++) {
scanf(" %c", &c);
hash[i][j] = 2*(c == '.') + 3*(c == 'X');
}
}
scanf("%d %d %d %d", &iX, &iY, &eX, &eY); iX--, iY--, eX--, eY--;
hash[iX][iY] = 2;
dfs(iX, iY);
puts("NO");
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | 827d37faf12f65d6caba24b191993f3e | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<time.h>
#include<math.h>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define FOR(i,a,b) for(i = a; i <= b; i++)
#define ROF(i,a,b) for(i = a; i >= b; i--)
#define SWAP(a,b) {t = a; a = b; b = t;}
#define lli long long int
#define endl puts("")
#define MAX 27e5 + 9
typedef struct pair{ int x, y; } pair;
int N = 1000;
int hash[1000][1000];
char matrix[1000][1000];
int i, j, k, s, n, m;
int incX, incY, endX, endY;
void dfs(int x, int y) {
if(hash[x][y] == 3 && x == endX && y == endY) { printf("YES"), endl; exit(0); }
if(hash[x][y] == 3 || x < 0 || x >= n || y < 0 || y >= m) return ;
hash[x][y]++;
dfs(x,y+1);
dfs(x+1,y);
dfs(x,y-1);
dfs(x-1,y);
}
int main() {
scanf("%d %d", &n, &m);
FOR(i,0,n-1) {
scanf("%s", matrix[i]);
FOR(j,0,m-1) {
if(matrix[i][j] == '.') hash[i][j] = 2;
else hash[i][j] = 3;
}
}
scanf("%d %d", &incX, &incY);
scanf("%d %d", &endX, &endY);
incX--, incY--, endX--, endY--;
hash[incX][incY] = 2;
dfs(incX, incY);
printf("NO"), endl;
return 0;
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | b06013d6ed5e6d75439c334b963a1767 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include<stdio.h>
char maze[501][501];
int visited[501][501]={0};
int destrow,destcol;
int main()
{
int n,m,push[250000][2];
scanf("%d%d",&n,&m);
int i,j;
for(i=0;i<n;i++)
scanf("%s",maze[i]);
int row,column;
scanf("%d%d%d%d",&row,&column,&destrow,&destcol);
destrow--,destcol--,row--,column--;
int count=0;
if(destrow)
{
if(maze[destrow-1][destcol]== '.' ||(destrow-1 ==row && destcol == column))
count++;
}
if(maze[destrow+1][destcol]=='.' || (destrow+1 ==row && destcol == column))
count++;
if(destcol)
{
if(maze[destrow][destcol-1]=='.' ||(destrow ==row && destcol -1 == column))
count++;
}
if(maze[destrow][destcol+1]=='.' ||(destrow ==row && destcol+1 == column))
count++;
if(maze[destrow][destcol]=='.' && count < 2)
printf("NO\n");
else if(maze[destrow][destcol]=='X' && count < 1)
printf("NO\n");
else
{
if(row==destrow && column == destcol)
printf("YES\n");
else{
int flag=0;
count=0;
push[count++][0]=row;
push[count-1][1]=column;
visited[row][column]=1;
int k=0;
while(count)
{
if(push[count-1][0]==destrow && push[count-1][1]== destcol)
{
flag=1;
break;
}
else
{
row=push[count-1][0];
column=push[count-1][1];
count--;
//printf("Pop: %d %d\n",row,column);
if((visited[row][column]==0 && maze[row][column]=='.') || k==0)
{
if(row && visited[row-1][column]==0)
push[count][0]=row-1,push[count++][1]=column;//printf("%d %d\n",row-1,column );
if(visited[row+1][column]==0 && row < n-1)
push[count][0]=row+1,push[count++][1]=column;//printf("%d %d\n",row+1,column );
if(column && visited[row][column-1]==0)
push[count][0]=row,push[count++][1]=column-1;//printf("%d %d\n",row,column-1 );
if(visited[row][column+1]==0 && column < m-1)
push[count][0]=row,push[count++][1]=column+1;//printf("%d %d\n",row,column+1);
}
visited[row][column]=1;
}
//printf("%d\n",count );
k=1;
}
if(flag)
printf("YES\n");
else
printf("NO\n");
}
/*
int flag=recurse(row,column);
if(flag)
printf("YES\n");
else
printf("NO\n");
*/
}
return 0;
} | |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | 2222c738af008f8f092d5f0da023a5d3 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include<stdio.h>
#include<stdlib.h>
#define intact 0
#define waiting 1
#define cracked 3
#define visited 2
struct list{
int row;
int col;
struct list *next;
};
typedef struct list node;
void pushQ(node **head, int r, int c)
{
node *curr, *tmp;
tmp = (node *)malloc(sizeof(node));
tmp->row = r;
tmp->col = c;
tmp->next = NULL;
if(*head == NULL){
*head = tmp;
} else {
curr = *head;
while(curr->next != NULL){
curr = curr->next;
}
curr->next = tmp;
}
}
node *frontQ(node *head)
{
if(head == NULL){
return NULL;
} else {
return head;
}
}
void popQ(node **head)
{
if(*head == NULL){
printf("\nStack Underflow!\n\n");
} else {
node *tmp;
tmp = *head;
*head = (*head)->next;
free(tmp);
}
return;
}
int isQempty(node *head)
{
if(head == NULL){
return 1;
} else {
return 0;
}
}
int state[503][503] = {0}, par[503][503] = {0};
int ultimateflag, flag = 0;
int bfs(char grid[503][503], int n, int m, int sx, int sy, int ex, int ey)
{
int i, j, r, c;
node *head = NULL;
node *tmp;
//par- 0 up, 1 down, 2, left, 3 right
par[sx][sy] = -1;
//printf("\npppppppppp\n");
for(i = 0; i <= n; i++){
grid[i][0] = 'X';
grid[i][m+1] = 'X';
}
for(i = 0; i <= m; i++){
grid[0][i] = 'X';
grid[n+1][i] = 'X';
}
grid[n+1][m+1] = 'X';
for(i = 0; i <= n+1; i++){
for(j = 0; j <= m+1; j++){
if( grid[i][j] == 'X' ){
state[i][j] = cracked;
} else {
state[i][j] = intact;
}
}
}
//grid[sx][sy] = 'X';
if(sx == ex && sy == ey){
grid[sx][sy] = '.';
state[sx][sy] = intact;
}
/*
for(i = 0; i <= n+1; i++){
for(j = 0; j <= m+1; j++){
printf("%c",grid[i][j]);
}
printf("\n");
}
printf("\n\n");
for(i = 0; i <= n+1; i++){
for(j = 0; j <= m+1; j++){
printf("%d",state[i][j]);
}
printf("\n");
}
*/
// printf("ooooooooooooo\n");
pushQ(&head, sx, sy);
i = 0;
flag = 0;
while( !isQempty(head) ){
i++;
tmp = frontQ(head);
r = tmp->row;
c = tmp->col;
popQ(&head);
state[r][c] = visited;
if(r == ex && c == ey){
state[ex][ey] = intact;
}
/*
if(par[r][c] == 0){
printf("down ");
} else if(par[r][c] == 1){
printf("up ");
} else if(par[r][c]== 2){
printf("right ");
} else if(par[r][c] == 3){
printf("left ");
}
printf("(%d %d)\n", r, c);
*/
/* if(state[r-1][c] != intact && state[r+1][c] != intact && state[r][c-1] != intact && state[r][c+1] != intact ){
//printf("\n %d azaz\n", i);
break;
}*/
if(state[r-1][c] == intact){
par[r-1][c] = 1;//down
state[r-1][c] = waiting;
pushQ(&head, r-1, c);
//printf("\n up");
if((r-1) == ex && c == ey){
//do something
if(ultimateflag == 0){
ultimateflag = 1;
//grid[ex][ey] = 'X';
flag = 1;
break;
} else if(ultimateflag == 1){
ultimateflag = 2;
break;
}
}
}
if(state[r+1][c] == intact){
par[r+1][c] = 0;//up
state[r+1][c] = waiting;
pushQ(&head, r+1, c);
//printf("\n down");
if((r+1) == ex && c == ey){
//do something
if(ultimateflag == 0){
ultimateflag = 1;
//grid[ex][ey] = 'X';
flag = 1;
break;
} else if(ultimateflag == 1){
ultimateflag = 2;
break;
}
}
}
if(state[r][c-1] == intact){
par[r][c-1] = 3;//right
state[r][c-1] = waiting;
pushQ(&head, r, c-1);
//printf("\n left");
if((r) == ex && (c-1) == ey){
if(ultimateflag == 0){
ultimateflag = 1;
//grid[ex][ey] = 'X';
flag = 1;
break;
} else if(ultimateflag == 1){
ultimateflag = 2;
break;
}
//do something
}
}
if(state[r][c+1] == intact){
par[r][c+1] = 2;//left
state[r][c+1] = waiting;
pushQ(&head, r, c+1);
//printf("\n right");
if( r == ex && c+1 == ey){
//do something
if(ultimateflag == 0){
ultimateflag = 1;
//grid[ex][ey] = 'X';
flag = 1;
break;
} else if(ultimateflag == 1){
ultimateflag = 2;
break;
}
}
}
}
//printf("\n\n");
if(ultimateflag == 2){
printf("YES\n");
return 1;
}
if(flag == 1 && ultimateflag == 1){
//printf("YES\n");
state[ex][ey] = intact;
i = ex; j = ey;
// printf("(%d %d) ", i, j);
while(par[i][j] != -1){
if( par[i][j] == 0){
i = i-1;
}else if(par[i][j] == 1){
i = i+1;
} else if ( par[i][j] == 2 ){
j = j-1;
} else if(par[i][j] == 3){
j = j+1;
}
grid[i][j] = 'X';
//printf("(%d %d) ", i, j);
}
j = bfs(grid, n, m, ex, ey, ex, ey);
} else {
printf("NO\n");
}
return flag;
}
int main()
{
int i, j, n, m, ans, sx, sy, ex, ey;
char grid[503][503];
scanf("%d%d", &n, &m);
for(i = 1; i <= n; i++){
for(j = 1; j <= m; j++){
//getchar();
scanf(" %c",&grid[i][j]);
}
}
scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
/*
for(i = 0; i <= n+1; i++){
for(j = 0; j <= m+1; j++){
printf("%c",grid[i][j]);
}
printf("\n");
}
*/
if(grid[ex][ey] == 'X'){
ultimateflag = 1;
grid[ex][ey] = '.';
} else {
ultimateflag = 0;
}
//printf("\n zzzzzzzzzz\n");
ans = bfs(grid, n, m, sx, sy, ex, ey);
//printf("\n %d\n", ans);
/*if(ans == 1){
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}*/
return 0;
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | 7984d14ccf05b9e67cdf1018b4201264 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include<stdio.h>
int state=0,vi[501][501],r,c,r2,c2;
void func(int n,int m)
{
// printf("%d %d\n",n,m);
if(n+1<r && state==0)
{
if(n+1==r2 && m==c2 && vi[n+1][m]==1)
state=1;
if(vi[n+1][m]==0)
{
vi[n+1][m]=1;
func(n+1,m);
}
}
if(m+1<c && state==0)
{
if(n==r2 && m+1==c2 && vi[n][m+1]==1)
state=1;
if(vi[n][m+1]==0)
{
vi[n][m+1]=1;
func(n,m+1);
}
}
if(n-1>=0 && state==0)
{
if(n-1==r2 && m==c2 && vi[n-1][m]==1)
state=1;
if(vi[n-1][m]==0)
{
vi[n-1][m]=1;
func(n-1,m);
}
}
if(m-1>=0 && state==0)
{
if(n==r2 && m-1==c2 && vi[n][m-1]==1)
state=1;
if(vi[n][m-1]==0)
{
vi[n][m-1]=1;
func(n,m-1);
}
}
return ;
}
int main()
{
int r1,c1,i,j;
char cha[505];
scanf("%d %d",&r,&c);
for(i=0;i<r;i++)
{
scanf("\n%s",cha);
for(j=0;j<c;j++)
if(cha[j]=='.')
vi[i][j]=0;
else
vi[i][j]=1;
}
scanf("%d %d %d %d",&r1,&c1,&r2,&c2);
r1--;r2--;c1--;c2--;
vi[r1][c1]=1;
/* for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
printf("%d ",vi[i][j]);
printf("\n");
}*/
func(r1,c1);
if(state==1)
printf("YES\n");
else
printf("NO\n");
return 0;
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | 635bf9e998c0b43b14ded7fbbc626877 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include<stdio.h>
#include<stdlib.h>
int visit[600][600],visit2[600][600],r,c,x2,y2,xt,yt,flag=0,count=0;
int confirm(int x,int y)
{
if((x<0)||(x>r-1)||(y<0)||(y>c-1))
return 1;
else
return 0;
}
int check(int x,int y)
{
if((visit[x-1][y]==1)&&(x+1==x2)&&(y+1==y2))
return 1;
else if((visit[x][y+1]==1)&&(x+1==x2)&&(y+1==y2))
return 1;
else if((visit[x+1][y]==1)&&(x+1==x2)&&(y+1==y2))
return 1;
else if((visit[x][y-1]==1)&&(x+1==x2)&&(y+1==y2))
return 1;
else return 0;
}
void dfs(int x,int y)
{
if(flag==1)
return;
if(confirm(x,y)==1)
{
return;
}
// printf("%d%d ",x,y);
if((x==x2)&&(y==y2)&&(visit[x][y]==1))
{
printf("YES\n");
flag=1;
return;
}
if((x==x2)&&(y==y2)&&(visit[x][y]!=1))
{
if(count>=2)
{
printf("YES\n");
flag=1;
}
}
if(visit[x][y]==1)
return;
visit[x][y]=1;
// visit2[x][y]=1;
// printf("lola%d%d",x,y);
dfs(x-1,y);
dfs(x,y+1);
dfs(x+1,y);
dfs(x,y-1);
visit2[x][y]=0;
}
int main ()
{
int i,j,k,l,m,n,a[550][550],x1,y1;
char ch[550];
scanf("%d%d",&r,&c);
for(i=0;i<r;i++)
{
scanf("%s",ch);
// printf("%s",ch);
for(j=0;ch[j]!='\0';j++)
{
if(ch[j]=='X')
{
visit[i][j]=1;
visit2[i][j]=1;
}
else
visit[i][j]=0;
visit2[i][j]=0;
}
}
scanf("%d%d",&x1,&y1);
xt=x1-1;
yt=y1-1;
scanf("%d%d",&x2,&y2);
x2=x2-1;
y2=y2-1;
visit[x1-1][y1-1]=0;
// visit2[x1-1][y1-1]=0;
flag=0;
if(confirm(x2-1,y2)==0)
if(visit[x2-1][y2]==0)
count++;
if(confirm(x2,y2+1)==0)
if(visit[x2][y2+1]==0)
count++;
if(confirm(x2+1,y2)==0)
if(visit[x2+1][y2]==0)
count++;
if(confirm(x2,y2-1)==0)
if(visit[x2][y2-1]==0)
count++;
dfs(x1-1,y1-1);
if(flag==0)
printf("NO\n");
return 0;
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | bcc9495dbb435ec1bcdebaaf20af5fd7 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include<stdio.h>
#include<stdlib.h>
char ar[1000][1003];
int n, m, r1, c1, r2, c2, i, j, k=0, count=0, hold;
void func(int x, int y)
{
//printf("x:%d y:%d\n", x, y);
if(x<1 || y<1 || x>n || y>m){
return ;
}
if(x==r2 && y==c2) hold=1;
if(hold==1){
return ;
}
else if(ar[x][y]=='X'){
return ;
}
else{
ar[x][y]='X';
func(x-1 ,y);
func(x+1 ,y);
func(x ,y-1);
func(x ,y+1);
}
return ;
}
int main()
{
scanf("%d %d", &n, &m);
getchar();
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
scanf("%c", &ar[i][j]);
}
getchar();
}
scanf("%d %d", &r1, &c1);
scanf("%d %d", &r2, &c2);
/*if(ar[r2][c2]=='.'){
if(ar[r2-1][c2]=='X'){
count++;
}
if(ar[r2][c2-1]=='X'){
count++;
}
if(ar[r2+1][c2]=='X'){
count++;
}
if(ar[r2][c2+1]=='X'){
count++;
}
if(count>=3){
printf("NO");
return 0;
}
}*/
if(ar[r2][c2]=='X' && ((((r2==r1-1)||(r2==r1+1))&&(c2==c1)) || (((c2==c1-1)||(c2==c1+1))&&(r2==r1)))){
printf("YES");
return 0;
}
if(ar[r2][c2]=='.' && ((((r2==r1-1)||(r2==r1+1))&&(c2==c1)) || (((c2==c1-1)||(c2==c1+1))&&(r2==r1))) && (ar[r2-1][c2]=='.' || ar[r2][c2-1]=='.' || ar[r2+1][c2]=='.' || ar[r2][c2+1]=='.')){
printf("YES");
return 0;
}
count=0;
if(ar[r2-1][c2]=='.'){
++count;
}
if(ar[r2+1][c2]=='.'){
++count;
}
if(ar[r2][c2+1]=='.'){
++count;
}
if(ar[r2][c2-1]=='.'){
++count;
}
//printf(" %c ", ar[1][1]);
// printf("COUNT:%d\n", count);
if(r1==r1 && c1==c2 && count>0){
printf("YES");
return 0;
}
ar[r1][c1] = '.';
func(r1, c1);
if(hold==0){
printf("NO");
return 0;
}
//printf("HOLD:%d k:%d\n", hold, k);
else if(hold==1){
if(ar[r2][c2]=='X'){
printf("YES");
return 0;
}
if(count>1){
printf("YES");
}
else{
printf("NO");
}
return 0;
}
return 0;
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | 6c210f139264c7b70d2773df4991dda9 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include <stdio.h>
#include <stdlib.h>
char s[502][502];
int n,m,ir,ic,fr,fc;
int vis[500][500];
int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
int dfs(int r,int c)
{ //printf("at %d,%d\n",r+1,c+1);
if(vis[r][c]&&r==fr&&c==fc)
return 1;
if(vis[r][c])
return 0;
vis[r][c]=1;
int i,x,y;
for(i=0;i<4;++i)
{ x=r+dx[i];y=c+dy[i];
if(x>=0&&x<n&&y>=0&&y<m)
if(dfs(x,y))return 1;
}
return 0;
}
int main(void) {
//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
int i,j,x,y;
scanf("%d%d",&n,&m);
for(i=0;i<n;++i)scanf("%s",s[i]);
scanf("%d%d%d%d",&ir,&ic,&fr,&fc);
--ir,--ic,--fr,--fc;//0 indexed
for(i=0;i<n;++i)for(j=0;j<m;++j)if(s[i][j]=='X')vis[i][j]=1;
for(i=0;i<4;i++)
{
x=ir+dx[i];y=ic+dy[i];
if(x>=0&&x<n&&y>=0&&y<m)
if(dfs(x,y))
{ puts("YES");
return 0;
}
}
puts("NO");
return 0;
} | |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | 243f8d4d8af7ffa0ef3aefbe5459571b | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
int map[505][505],flag;
void run(int x1,int y1,int x2,int y2)
{
if(map[x1][y1]==0)
{
if(x1==x2&&y1==y2)flag=1;
return;
}
map[x1][y1]--;
run(x1+1,y1,x2,y2);
run(x1-1,y1,x2,y2);
run(x1,y1+1,x2,y2);
run(x1,y1-1,x2,y2);
}
int main()
{
int i,j,x1,y1,x2,y2,n,m;
char ch;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=0;i<=n+1;i++)
{
for(j=0;j<=m+1;j++)
{
if(i==0||i==n+1||j==0||j==m+1)map[i][j]=0;
else
{
scanf(" %c",&ch);
if(ch=='X')map[i][j]=0;
if(ch=='.')map[i][j]=1;
}
}
}
flag=0;
scanf("%d%d",&x1,&y1);
scanf("%d%d",&x2,&y2);
run(x1+1,y1,x2,y2);
run(x1-1,y1,x2,y2);
run(x1,y1+1,x2,y2);
run(x1,y1-1,x2,y2);
if(flag==1)printf("Yes\n");
else printf("No\n");
}
return 0;
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | 1c8d69d8b8c62b29669ce641b7379d44 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include<stdio.h>
typedef struct
{
int x,y;
}Node;
char s[520][520];
int move[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
Node b;
int check(Node b,int i)
{
b.x+=move[i][0];
b.y+=move[i][1];
if(s[b.x][b.y]=='.') return 1;
return 0;
}
int ck(Node a,int i)
{
a.x+=move[i][0];
a.y+=move[i][1];
if(a.x==b.x&&a.y==b.y) return 1;
return 0;
}
void mo(Node a,int i)
{
a.x+=move[i][0];
a.y+=move[i][1];
if(s[a.x][a.y]!='.')
{
s[a.x][a.y]='#';
return ;
}
s[a.x][a.y]='#';
for(i=0;i<4;i++)
mo(a,i);
}
int main()
{
Node a;
int n,m,i,j,match,co,flag;
char u;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=1;i<n+1;i++)
scanf("%s",s[i]+1);
for(i=0;i<n+2;i++)
s[i][0]=s[i][m+1]='0';
for(j=0;j<m+2;j++)
s[0][j]=s[n+1][j]='0';
scanf("%d%d%d%d",&a.x,&a.y,&b.x,&b.y);
u=s[b.x][b.y];
for(co=0,i=0;i<4;i++)
co+=check(b,i);
for(i=0;i<4;i++)
if(ck(a,i)) break;
if(i>=4) flag=0;
else flag=1;
match=1;
if(co<2&&s[b.x][b.y]=='.') match=0;
if(co<1&&s[b.x][b.y]=='X') match=0;
if(match==0)
{
if(flag)
{
if(s[b.x][b.y]=='.'&&co==1) match=1;
if(s[b.x][b.y]=='X'&&co==0) match=1;
}
if(match==0)
{
printf("NO\n");
continue;
}
}
match=0;
for(i=0;i<4;i++)
mo(a,i);
if(s[b.x][b.y]=='#')
{
if(u=='X')
match=1;
else if(u=='.')
{
if(co>=1) match=1;
else match=0;
}
}
if(match==1) printf("YES\n");
else printf("NO\n");
}
return 0;
}
| |
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this? | If you can reach the destination, print 'YES', otherwise print 'NO'. | C | afac59c927522fb223f59c36184229e2 | f1aff0976adcc7d1aab94d657b5274ff | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dfs and similar"
] | 1430411400 | ["4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6"] | NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended. | PASSED | 2,000 | standard input | 2 seconds | The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. | ["YES", "NO", "YES"] | #include <stdio.h>
char map[1000][1000],used[1000][1000];
int found=0,dots=0,totalrow,totalcol,x,y;
void search(int i,int j)
{
//printf("i:%d j:%d\n",i,j);
if(i<0 || j<0 || i>=totalrow || j>=totalcol || used[i][j]==1)
return;
used[i][j]=1;
if(map[i][j]=='B')
{
found=1;
x=i;
y=j;
//printf("checkpoint\n");
return;
}
if(map[i][j]=='C')
{
found=2;
x=i;
y=j;
return;
}
else if(map[i][j]=='X')
{
return;
}
else
{
search(i-1,j);
search(i,j-1);
search(i,j+1);
search(i+1,j);
}
}
int main()
{
int i,j,k,r1,c1,r2,c2;
scanf("%d %d\n",&totalrow,&totalcol);
/*if(totalrow==500 && totalcol==53)
{
printf("YES\n");
return 0;
}*/
for(k=0; k<totalrow; k++)
{
scanf("%s",&map[k]);
}
scanf("%d %d",&r1,&c1);
scanf("%d %d",&r2,&c2);
map[r1-1][c1-1]='A';
if(map[r2-1][c2-1]=='.')
{
map[r2-1][c2-1]='B';
}
if(map[r2-1][c2-1]=='X')
{
map[r2-1][c2-1]='C';
}
if(r1==r2 && c1==c2)
{
if(map[r1-2][c1-1]=='.')
{
printf("YES");
return 0;
}
if(map[r1][c1-1]=='.')
{
printf("YES");
return 0;
}
if(map[r1-1][c1-2]=='.')
{
printf("YES");
return 0;
}
if(map[r1-1][c1]=='.')
{
printf("YES");
return 0;
}
else
printf("NO");
return 0;
}
search(r1-1,c1-1);
int den=0;
if(found==1)
{
//if((map[x][y+1]=='.' && map[x-1][y+1]=='.' && map[x-1][y]=='.') || (map[x][y-1]=='.' && map[x-1][y-1]=='.' && map[x-1][y]=='.') || (map[x-1][y]=='.' && map[x][y-1]=='.') || map[x-1][y]=='.' || (map[x+1][y]=='.' && map[x][y+1]=='.'))
if(map[x][y+1]=='.')
den++;
if(map[x][y-1]=='.')
den++;
if(map[x-1][y]=='.')
den++;
if(map[x+1][y]=='.')
den++;
//|| map[x][y-1]=='.' || map[x-1][y]=='.' || map[x+1][y]=='.')
if(den>=2)
{
//printf("inside");
printf("YES\n");
}
else if(map[x+1][y]=='A' && (map[x][y-1]=='.' || map[x][y+1]=='.'))
{
printf("YES\n");
}
else if(map[x-1][y]=='A' && (map[x][y-1]=='.' || map[x][y+1]=='.'))
{
printf("YES\n");
}
else if((map[x-1][y]=='A' && map[x+1][y]=='.') || (map[x+1][y]=='A' && map[x-1][y]=='.'))
printf("YES\n");
else if((map[x][y-1]=='A' && map[x][y+1]=='.') || (map[x][y+1]=='A' && map[x][y-1]=='.'))
printf("YES\n");
else if(map[x][y]=='A' && (map[x][y+1]=='.' || map[x][y-1]=='.' || map[x-1][y]=='.' || map[x+1][y]=='.'))
printf("YES\n");
else
printf("NO\n");
}
else if(found==2)
{
printf("YES\n");
}
else
printf("NO\n");
/*for(k=0; k<totalrow; k++)
{
printf("%s\n",map[k]);
}
for(k=0; k<totalrow; k++)
{
printf("%s\n",used[k]);
}*/
return 0;
}
| |
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (x + y = n). The sizes of teams differ in no more than one (|x - y| ≤ 1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| ≤ 1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | C | 0937a7e2f912fc094cc4275fd47cd457 | ce628b43574d217c666a1282044da00f | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy",
"math"
] | 1328886000 | ["3\n1 2 1", "5\n2 3 3 1 1"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled. | PASSED | 1,500 | standard input | 1 second | The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≤ ai ≤ 104), the i-th number represents the i-th boy's playing skills. | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | #include <stdio.h>
int a[100000], p[100000];
void sort(int l, int r) {
if (l >= r)
return;
int i = l, j = r, pp = p[l + rand() % (r-l)];
while (i <= j)
if (a[p[i]] < a[pp])
i++;
else if (a[pp] < a[p[j]])
j--;
else {
int t = p[i]; p[i] = p[j]; p[j] = t;
i++; j--;
}
sort(i, r); sort(l, j);
}
int main() {
int n; scanf("%d", &n);
int i;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
p[i] = i;
}
sort(0, n-1);
printf("%d\n", (n+1)/2);
for (i = 0; i < n; i += 2)
printf("%d ", p[i]+1);
putchar('\n');
printf("%d\n", n/2);
for (i = 1; i < n; i += 2)
printf("%d ", p[i]+1);
putchar('\n');
return 0;
}
| |
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (x + y = n). The sizes of teams differ in no more than one (|x - y| ≤ 1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| ≤ 1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | C | 0937a7e2f912fc094cc4275fd47cd457 | c047a82e9f2498ecef453fb7696a91c6 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy",
"math"
] | 1328886000 | ["3\n1 2 1", "5\n2 3 3 1 1"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled. | PASSED | 1,500 | standard input | 1 second | The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≤ ai ≤ 104), the i-th number represents the i-th boy's playing skills. | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | #include<stdio.h>
#include<math.h>
int main()
{
long int n,i,max=0;
scanf("%ld",&n);
long int a[n],b[n],c[n],d=0,e=0,sum1=0,sum2=0;
for(i=0;i<n;i++)
{scanf("%d",&a[i]);
if(a[i]>max)
max=a[i];}
for(i=0;i<n;i+=2)
{if(i<n-1)
{if(abs(sum1+a[i]-sum2-a[i+1])<=max)
{b[d++]=i+1;
c[e++]=i+2;
sum1+=a[i];
sum2+=a[i+1];}
else
{c[e++]=i+1;
b[d++]=i+2;
sum1+=a[i+1];
sum2+=a[i];}}
else
{if(abs(sum1+a[n-1]-sum2)<=max)
b[d++]=n;
else
c[e++]=n;}}
printf("%d\n",d);
for(i=0;i<d;i++)
printf("%d ",b[i]);
printf("\n");
printf("%d\n",e);
for(i=0;i<e;i++)
printf("%d ",c[i]);
return(0);}
| |
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (x + y = n). The sizes of teams differ in no more than one (|x - y| ≤ 1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| ≤ 1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | C | 0937a7e2f912fc094cc4275fd47cd457 | cbf04f0303f3c3cc2a35c4048ea90c7f | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy",
"math"
] | 1328886000 | ["3\n1 2 1", "5\n2 3 3 1 1"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled. | PASSED | 1,500 | standard input | 1 second | The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≤ ai ≤ 104), the i-th number represents the i-th boy's playing skills. | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | #include<stdio.h>
long int index[100010];
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
/* create temp arrays */
int L[n1], R[n2],L1[n1],R1[n2];
/* Copy data to temp arrays L[] and R[] */
for (i = 0; i < n1; i++)
{
L[i] = arr[l + i];
L1[i] = index[l + i];
}
for (j = 0; j < n2; j++)
{
R[j] = arr[m + 1+ j];
R1[j] = index[m + 1+ j];
}
/* Merge the temp arrays back into arr[l..r]*/
i = 0; // Initial index of first subarray
j = 0; // Initial index of second subarray
k = l; // Initial index of merged subarray
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
index[k]=L1[i];
i++;
}
else
{
arr[k] = R[j];
index[k]=R1[j];
j++;
}
k++;
}
/* Copy the remaining elements of L[], if there
are any */
while (i < n1)
{
arr[k] = L[i];
index[k]=L1[i];
i++;
k++;
}
/* Copy the remaining elements of R[], if there
are any */
while (j < n2)
{
arr[k] = R[j];
index[k]=R1[j];
j++;
k++;
}
}
/* l is for left index and r is right index of the
sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
if (l < r)
{
// Same as (l+r)/2, but avoids overflow for
// large l and h
int m = l+(r-l)/2;
// Sort first and second halves
mergeSort(arr, l, m);
mergeSort(arr, m+1, r);
merge(arr, l, m, r);
}
}
int main()
{
long int n,arr[100010],i,c1,c2;
scanf("%ld",&n);
for(i=0;i<n;i++)
{
scanf("%ld",&arr[i]);
index[i]=i+1;
}
mergeSort(arr,0,n-1);
if(n%2==0)
{
c1=n/2;
c2=n/2;
}
else
{
c1=n/2+1;
c2=n/2;
}
printf("%ld\n",c1);
for(i=n-1;i>=0;i-=2)
printf("%ld\n",index[i]);
printf("%ld\n",c2);
for(i=n-2;i>=0;i-=2)
printf("%ld\n",index[i]);
return 0;
}
| |
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (x + y = n). The sizes of teams differ in no more than one (|x - y| ≤ 1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| ≤ 1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | C | 0937a7e2f912fc094cc4275fd47cd457 | d453d9ff84da95ff8d7e00b1f5365c99 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy",
"math"
] | 1328886000 | ["3\n1 2 1", "5\n2 3 3 1 1"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled. | PASSED | 1,500 | standard input | 1 second | The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≤ ai ≤ 104), the i-th number represents the i-th boy's playing skills. | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | #include <stdio.h>
#include <stdlib.h>
typedef struct player{
int num;
int skills;
}Player;
int cmp(const void *a,const void *b)
{
if( ((Player*)a)->skills > ((Player*)b)->skills ) return 1;
else if( ((Player*)a)->skills == ((Player*)b)->skills ) return 0;
else return -1;
}
int main()
{
int n;
scanf("%d",&n);
Player P[n];
int i;
for(i=0; i<n; i++)
{
scanf("%d",&P[i].skills);
P[i].num = i+1;
}
qsort(P,n,sizeof(Player),cmp);
if(n%2 == 0)
{
printf("%d\n", n/2);
for(i=0; i<n; i+=2)
{
printf("%d ",P[i].num);
}
printf("\n%d\n",n/2);
for(i=1; i<n; i+=2)
{
printf("%d ", P[i].num);
}
}
else{
printf("%d\n", n/2+1);
for(i=0; i<n-2; i+=2)
{
printf("%d ",P[i].num);
}
printf("%d",P[n-2].num);
printf("\n%d\n",n/2);
for(i=1; i<n-2; i+=2)
{
printf("%d ", P[i].num);
}
printf("%d",P[n-1].num);
}
return 0;
}
| |
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (x + y = n). The sizes of teams differ in no more than one (|x - y| ≤ 1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| ≤ 1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | C | 0937a7e2f912fc094cc4275fd47cd457 | 3adeea73b7883e4c3b1966dd5924af56 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy",
"math"
] | 1328886000 | ["3\n1 2 1", "5\n2 3 3 1 1"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled. | PASSED | 1,500 | standard input | 1 second | The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≤ ai ≤ 104), the i-th number represents the i-th boy's playing skills. | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | #include<stdio.h>
#include<string.h>
#include<math.h>
#include<limits.h>
struct solve{
int x;
int y;
}arr[200001];
int maxz(int a,int b){
return a>b?a:b;
}
int min(int a,int b){
return a<b?a:b;
}
int compare(int *a,int *b){
return *b-*a;
}
int main(){
int max=0;
int a,b,c,d;
scanf("%d",&a);
int i;
for(i=0;i<a;i++){
scanf("%d",&arr[i].x);
arr[i].y=i+1;
if(arr[i].x>max)
max=arr[i].x;
}
int team1,team2;
team1=a%2==1?(a/2)+1:a/2;
team2=a/2;
qsort(arr,a,sizeof(struct solve),compare);
printf("%d\n",team1);
for(i=0;i<a;i+=2){
printf("%d ",arr[i].y);
}
printf("\n");
printf("%d\n",team2);
for(i=1;i<a;i+=2){
printf("%d ",arr[i].y);
}
}
| |
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (x + y = n). The sizes of teams differ in no more than one (|x - y| ≤ 1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| ≤ 1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | C | 0937a7e2f912fc094cc4275fd47cd457 | 58f6d75042ebc00bd1be001cec6b7e04 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy",
"math"
] | 1328886000 | ["3\n1 2 1", "5\n2 3 3 1 1"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled. | PASSED | 1,500 | standard input | 1 second | The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≤ ai ≤ 104), the i-th number represents the i-th boy's playing skills. | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | /*
* Name : Dhyey Bhansali (Shinchan6599)
* SEAS,AU (ICT,2nd Year)
* Stalking my code? Don't. You won't understand code of a genius.
*/
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
typedef struct myStruct {
long long int id;
long long int value;
} player;
long long int compare (const void * a, const void * b)
{
player *A = (player *)a;
player *B = (player *)b;
long long int val = (B->value - A->value);
return val;
}
int main()
{
long long int N,i,j;
scanf("%lld",&N);
player list[N];
for(i=0;i<N;i++)
{
list[i].id = i+1;
scanf("%lld",&list[i].value);
}
qsort(list,N,sizeof(player),compare);
printf("%lld\n",(N+1)/2);
for(i=0;i<N;i+=2)
{
printf("%lld ",list[i].id);
}
printf("\n%lld\n",N/2);
for(i=1;i<N;i+=2)
{
printf("%lld ",list[i].id);
}
printf("\n");
return 0;
}
| |
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (x + y = n). The sizes of teams differ in no more than one (|x - y| ≤ 1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| ≤ 1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | C | 0937a7e2f912fc094cc4275fd47cd457 | ab0a841f97978f4d9617194838b1d805 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy",
"math"
] | 1328886000 | ["3\n1 2 1", "5\n2 3 3 1 1"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled. | PASSED | 1,500 | standard input | 1 second | The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≤ ai ≤ 104), the i-th number represents the i-th boy's playing skills. | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | #include <stdio.h>
struct play{
int skill;
int position;
};
typedef struct play player;
typedef int (*compfn)(const void*, const void*);
int compare(struct play *, struct play *);
int main(){
int n, x=0, y=0;
int i, j;
scanf("%d", &n);
player players[n];
for(i=0; i<n; i++){
scanf("%d", &players[i].skill);
players[i].position=i+1;
}
/* for(i=0; i<n; i++){
printf("\nSkill: %d\tPosition: %d\n", players[i].skill, players[i].position);
}
*/
//printf("\n");
/* int aux1, aux2;
for(i=0; i<n; i++){
for(j = i+1 ; j<n; j++){
if(players[j].skill < players[i].skill){
aux1 = players[j].position;
aux2 = players[j].skill;
players[j].position = players[i].position;
players[j].skill = players[i].skill;
players[i].position = aux1;
players[i].skill = aux2;
}
}
}
*/
qsort((void *)&players, n, sizeof(struct play),(compfn)compare);
/* for(i=0; i<n; i++){
printf("\nSkill: %d\tPosition: %d\n", players[i].skill, players[i].position);
}
*/
if(n%2==0){
x = n/2;
y = n/2;
}else{
x= (n/2)+1;
y= n/2;
}
printf("%d\n", x);
for(i=0; i<n; i+=2){
printf("%d ", players[i].position);
}
printf("\n%d\n", y);
for(i=1; i<n; i+=2){
printf("%d ", players[i].position);
}
return 0;
}
/*void sortStruct(int ){
for(i=0; i<n; i++){
for(j = i+1 ; j<n; j++){
if(players[j].skill < players[i].skill){
aux1 = players[j].position;
aux2 = players[j].skill;
players[j].position = players[i].position;
players[j].skill = players[i].skill;
players[i].position = aux1;
players[i].skill = aux2;
}
}
}
}
*/
int compare(struct play *elem1, struct play *elem2)
{
if ( elem1->skill < elem2->skill)
return -1;
else if (elem1->skill > elem2->skill)
return 1;
else
return 0;
} | |
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (x + y = n). The sizes of teams differ in no more than one (|x - y| ≤ 1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| ≤ 1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | C | 0937a7e2f912fc094cc4275fd47cd457 | 7468a0d470ca5fa8951d619fd498d6bc | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy",
"math"
] | 1328886000 | ["3\n1 2 1", "5\n2 3 3 1 1"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled. | PASSED | 1,500 | standard input | 1 second | The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≤ ai ≤ 104), the i-th number represents the i-th boy's playing skills. | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | #include <stdio.h>
#include <stdlib.h>
typedef struct {int num; int ab;} boy;
boy arr[110000], k;
int n,t,j,i;
int cmp(const void* el1, const void* el2){ boy a=(*(boy*)el1); boy b=(*(boy*)el2);
return (a.ab==b.ab)?0:((a.ab>b.ab)?1:-1);
}
int main(){
scanf("%d", &n);
for(i=0; i<n; i++){
scanf("%d", &arr[i].ab);
arr[i].num=i+1;
} qsort(arr, n, sizeof(boy), &cmp);
printf("%d\n", (n&1)+n/2);
for(i=0; i<n; i+=2){
printf("%d ", arr[i].num);
}
putchar('\n');
printf("%d\n", n/2);
for(i=1; i<n; i+=2){
printf("%d ", arr[i].num);
}
return 0;
}
| |
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (x + y = n). The sizes of teams differ in no more than one (|x - y| ≤ 1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| ≤ 1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | C | 0937a7e2f912fc094cc4275fd47cd457 | 1dd448b0c86ace393a5078811fb5e5ce | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy",
"math"
] | 1328886000 | ["3\n1 2 1", "5\n2 3 3 1 1"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled. | PASSED | 1,500 | standard input | 1 second | The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≤ ai ≤ 104), the i-th number represents the i-th boy's playing skills. | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | #include<stdio.h>
#include<stdlib.h>
typedef struct boy{
int a;
int num;
}boy;
int compare(const void * a,const void * b){
return(*(int*)a-*(int*)b);
}
int main(){
int i,n,x,y;
int a[100001];
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
a[i]=a[i]*100000+i;
}
qsort(a,n,sizeof(int),compare);
for(i=0;i<n;i++){
// printf("%d ",a[i]);
}
if(n%2==1){
printf("%d\n",n/2+1);
for(i=n-1;i>=0;i-=2){
printf("%d ",a[i]%100000+1);
}
printf("\n");
printf("%d\n",n/2);
for(i=n-2;i>0;i=i-2)
printf("%d ",a[i]%100000+1);
}
else {
printf("%d\n",n/2);
for(i=n-1;i>0;i-=2){
printf("%d ",a[i]%100000+1);
}
printf("\n");
printf("%d\n",n/2);
for(i=n-2;i>=0;i=i-2)
printf("%d ",a[i]%100000+1);
}
return 0;
}
| |
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (x + y = n). The sizes of teams differ in no more than one (|x - y| ≤ 1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| ≤ 1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | C | 0937a7e2f912fc094cc4275fd47cd457 | 26bb715477602d7ead8f3bd97f68ef3a | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy",
"math"
] | 1328886000 | ["3\n1 2 1", "5\n2 3 3 1 1"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled. | PASSED | 1,500 | standard input | 1 second | The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≤ ai ≤ 104), the i-th number represents the i-th boy's playing skills. | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | #include <stdio.h>
#include <stdlib.h>
void intercambiar ( int*, int*);
void quicksort(int[], int[], int, int);
int main()
{
int n, i, x=0, y=0;
scanf("%d",&n);
int jug[n],num[n],equip1[n/2+1],equip2[n/2+1];
for(i=0; i<n; i++)
{
scanf("%d",&jug[i]);
num[i]= i+1;
}
quicksort(jug, num, 0, n-1);
for(i=0; i<n; i++)
{
if((i%2)==0)
{
equip1[x] = num[i];
x++;
}
else
{
equip2[y] = num[i];
y++;
}
}
printf("%d\n", x);
for(i=0; i<x; i++)
printf("%d ", equip1[i]);
printf("\n%d\n", y);
for(i=0; i<y; i++)
printf("%d ", equip2[i]);
return 0;
}
void intercambiar ( int* a, int* b )
{
int t = *a;
*a = *b;
*b = t;
}
void quicksort(int a[], int b[], int primero, int ultimo)
{
int i, j, central, pivote;
central = (primero + ultimo)/2;
pivote = a[central];
i = primero;
j = ultimo;
do{
while (a[i] < pivote) i++;
while (a[j] > pivote) j--;
if(i<=j)
{
intercambiar(&a[i], &a[j]);
intercambiar(&b[i], &b[j]);
i++;
j--;
}
}while(i <= j);
if(primero < j)
quicksort(a, b, primero, j);
if(i < ultimo)
quicksort(a, b, i, ultimo);
}
| |
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (x + y = n). The sizes of teams differ in no more than one (|x - y| ≤ 1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| ≤ 1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | C | 0937a7e2f912fc094cc4275fd47cd457 | cd8dd0e4ea7fc777df0e9bac4d824f58 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy",
"math"
] | 1328886000 | ["3\n1 2 1", "5\n2 3 3 1 1"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled. | PASSED | 1,500 | standard input | 1 second | The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≤ ai ≤ 104), the i-th number represents the i-th boy's playing skills. | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | #include<stdio.h>
#include<stdlib.h>
typedef struct player{
int skill;
int order;
} player_t;
player_t a[100001];
int n;
int compare(const void * a, const void * b){
return ((player_t*)a)->skill-((player_t*)b)->skill;
}
int main(){
int i;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&(a[i].skill));
a[i].order = i+1;
}
qsort(a,n,sizeof(player_t),compare);
if(n%2==0) printf("%d\n",n/2);
else printf("%d\n",n/2+1);
i=0;
while(i<n){
printf("%d ",a[i].order);
i+=2;
}
printf("\n");
printf("%d\n",n/2);
i=1;
while(i<n){
printf("%d ",a[i].order);
i+=2;
}
printf("\n");
return 0;
}
| |
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers).The key in football is to divide into teams fairly before the game begins. There are n boys playing football in the yard (including Petya), each boy's football playing skill is expressed with a non-negative characteristic ai (the larger it is, the better the boy plays). Let's denote the number of players in the first team as x, the number of players in the second team as y, the individual numbers of boys who play for the first team as pi and the individual numbers of boys who play for the second team as qi. Division n boys into two teams is considered fair if three conditions are fulfilled: Each boy plays for exactly one team (x + y = n). The sizes of teams differ in no more than one (|x - y| ≤ 1). The total football playing skills for two teams differ in no more than by the value of skill the best player in the yard has. More formally: Your task is to help guys divide into two teams fairly. It is guaranteed that a fair division into two teams always exists. | On the first line print an integer x — the number of boys playing for the first team. On the second line print x integers — the individual numbers of boys playing for the first team. On the third line print an integer y — the number of boys playing for the second team, on the fourth line print y integers — the individual numbers of boys playing for the second team. Don't forget that you should fulfil all three conditions: x + y = n, |x - y| ≤ 1, and the condition that limits the total skills. If there are multiple ways to solve the problem, print any of them. The boys are numbered starting from one in the order in which their skills are given in the input data. You are allowed to print individual numbers of boys who belong to the same team in any order. | C | 0937a7e2f912fc094cc4275fd47cd457 | 4f59b79916297ef42b0a38ca327483ef | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"sortings",
"greedy",
"math"
] | 1328886000 | ["3\n1 2 1", "5\n2 3 3 1 1"] | NoteLet's consider the first sample test. There we send the first and the second boy to the first team and the third boy to the second team. Let's check all three conditions of a fair division. The first limitation is fulfilled (all boys play), the second limitation on the sizes of groups (|2 - 1| = 1 ≤ 1) is fulfilled, the third limitation on the difference in skills ((2 + 1) - (1) = 2 ≤ 2) is fulfilled. | PASSED | 1,500 | standard input | 1 second | The first line contains the only integer n (2 ≤ n ≤ 105) which represents the number of guys in the yard. The next line contains n positive space-separated integers, ai (1 ≤ ai ≤ 104), the i-th number represents the i-th boy's playing skills. | ["2\n1 2 \n1\n3", "3\n4 1 3 \n2\n5 2"] | #include <stdio.h>
struct pares
{
int prim;
int seg;
};
typedef struct pares PAR;
void quicksort(PAR a[], int primero, int ultimo);
int team1Total = 0;
int team2Total = 0;
int main()
{
int n, i;
scanf("%d",&n);
PAR arr[n];
int team1[n];
int team2[n];
for (i=0; i<n; i++)
{
int x;
scanf("%d",&x);
arr[i].prim = x;
arr[i].seg = i;
}
int m=0, p=0;
quicksort(arr, 0, n-1);
for (i=0; i<n; i++)
{
if(team1Total < team2Total)
{
team1[m]= arr[i].seg;
m++;
team1Total += arr[i].prim ;
}
else
{
team2[p] =(arr[i].seg);
p++;
team2Total += arr[i].prim;
}
}
printf("%d\n",p);
for ( i=0; i<p; i++)
{
printf("%d ",team2[i]+1);
}
printf("\n%d\n",m);
for (i=0; i<m; i++)
{
printf("%d ",team1[i]+1);
}
printf("\n") ;
return 0;
}
void quicksort(PAR a[], int primero, int ultimo)
{
int i, j, central,pivote;
central = (primero + ultimo)/2;
pivote = a[central].prim;
i = primero;
j = ultimo;
do {
while (a[i].prim < pivote) i++;
while (a[j].prim > pivote) j--;
if (i <= j)
{
int tmp;
tmp = a[i].prim;
a[i].prim = a[j].prim;
a[j].prim = tmp;
tmp = a[i].seg;
a[i].seg = a[j].seg;
a[j].seg = tmp;
i++;
j--;
}
}while (i <= j);
if (primero < j)
quicksort(a, primero, j);
if (i < ultimo)
quicksort(a, i, ultimo);
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.