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
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
70c5372e1bd99c0b8d99a2c0032342ec
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include<stdio.h> int main(){ int t,n,i,time,l,r; scanf("%d",&t); while(t--){ scanf("%d%d%d",&n,&l,&r); time=l; printf("%d ",time); time++; for(i=1;i<n;i++){ scanf("%d%d",&l,&r); if(time>r)printf("0 "); else{ if(time<l)time=l; printf("%d ",time); time++; } } printf("\n"); } return 0; }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
7f81735673de7b65c4a51feccfba2dce
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include <stdio.h> int main( void ) { int t, n, l, r; scanf( "%d", &t ); while( t > 0 ) { scanf( "%d", &n ); int time = 0; while( n > 0 ) { scanf( "%d %d", &l, &r ); if( time <= l ) { printf( "%d ", l ); time = l + 1; } else if( time <= r ) { printf( "%d ", time ); time += 1; } else { printf( "%d ", 0 ); } n--; } printf( "\n" ); t--; } return 0; }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
5035d01e06f003ff38300d993ce8da65
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include <stdio.h> #include <stdlib.h> int main() { int t; scanf("%d",&t); while(t--) { int n,l[5000],r[5000],count,answer[5000]; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d %d",&l[i],&r[i]); answer[i]=0; } answer[0]=l[0]; count = l[0]; for(int i=1;i<n;i++){ if(l[i]==l[i-1] && r[i]<=count){ answer[i]=0; } else if(l[i]==l[i-1] && r[i]>count){ answer[i]=++count; } else if(l[i] != l[i-1] && l[i]>count ){ count = l[i]; answer[i]=count; } else if(l[i] != l[i-1] && l[i]==count){ if(r[i]<=count){answer[i]=0;} else if(r[i]>count){answer[i]=++count;} } else if(l[i] != l[i-1] && l[i]<count){ if(r[i]<=count){answer[i]=0;} else if(r[i]>count){answer[i]=++count;} } } for(int i=0;i<n;i++){ printf("%d ",answer[i]); } printf("\n"); } return 0; }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
a82932a55cfc56902abdd1f37372ad67
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include<stdio.h> int main(){ int t,n,i,time,l,r; scanf("%d",&t); while(t--){ scanf("%d%d%d",&n,&l,&r); time=l; printf("%d ",time); time++; for(i=1;i<n;i++){ scanf("%d%d",&l,&r); if(time>r)printf("0 "); else{ if(time<l)time=l; printf("%d ",time); time++; } } printf("\n"); } return 0; }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
b94fcc54e08ddc2212f4789cad5769c3
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include <stdio.h> int main() { int test; scanf("%d" ,&test); for(int j =0 ; j< test; j++){ int n; scanf("%d" ,&n); int arrival[n] , wait[n]; for(int i=0; i<n ; i++){ scanf("%d %d", &arrival[i] ,&wait[i]); } int timer = arrival[0] ,zero= 0; for(int i=0; i<n ; i++){ if(timer >= arrival[i] && timer <= wait[i] ){ printf("%d " ,timer); timer++; } else if( arrival[i] > timer ){ printf("%d " ,arrival[i]); timer = arrival[i] + 1; } else{ printf("%d ", zero); } } printf("\n"); } return 0; }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
0d7bfc333e150ff12c348a94a4bf88ab
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include<stdio.h> int main(){ int t,n,i,time,l,r; scanf("%d",&t); while(t--){ scanf("%d%d%d",&n,&l,&r); time=l; printf("%d ",time); time++; for(i=1;i<n;i++){ scanf("%d%d",&l,&r); if(time>r)printf("0 "); else{ if(time<l)time=l; printf("%d ",time); time++; } } printf("\n"); } return 0; }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
218fd2d87e3ba29b22f3160152153233
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include <stdio.h> struct student { int arrive; int depart; }; struct student s[1000]; int max(int a, int b) { if (a > b) return a; return b; } void print_queue(int n) { int time = 0; for (int i = 0; i < n; i++) { if (time >= s[i].depart) printf("0 "); else { time = max(time+1, s[i].arrive); printf("%d ", time); } } printf("\n"); } int main(void) { int t, n; scanf("%d", &t); for (int i = 0; i < t; i++) { scanf("%d", &n); for (int j = 0; j < n; j++) scanf("%d%d", &s[j].arrive, &s[j].depart); print_queue(n); } return 0; }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
d5c9d825ee47246adf3e2c89f253436d
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include <stdio.h> int main() { int t,n,l,r; int i,a[1005],k; scanf("%d",&t); while(t--) { k=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d%d",&l,&r); if(k<l) k=l; if(k>r) a[i]=0; else a[i]=k++; } for(i=0;i<n;i++) { if(i==0) printf("%d",a[i]); else printf(" %d",a[i]); } printf("\n"); } }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
7967e632216bd3186e6e337b32c6e41a
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> int main() { int t,n,i,a,b,temp; scanf("%d",&t); while(t--) { scanf("%d",&n); temp=-1; for(i=0;i<n;i++) { scanf("%d %d",&a,&b); if(temp<=a) { printf("%d ",a); temp=a+1; } else { if(temp>b) printf("0 "); else { printf("%d ",temp); temp=temp+1; } } } printf("\n"); } return 0; }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
f01eafb399124a81e15b0920981bd441
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
//set many funcs template #include<stdio.h> #include<string.h> #include<stdlib.h> #include<stdbool.h> #define inf 1072114514 #define llinf 4154118101919364364 #define mod 1000000007 #define pi 3.1415926535897932384 int max(int a,int b){if(a>b){return a;}return b;} int min(int a,int b){if(a<b){return a;}return b;} int zt(int a,int b){return max(a,b)-min(a,b);} int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;} int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;} int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;} int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;} int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;} int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;} int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;} long long llmax(long long a,long long b){if(a>b){return a;}return b;} long long llmin(long long a,long long b){if(a<b){return a;}return b;} long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);} long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;} long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;} long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;} long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;} long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;} long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;} long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;} double dbmax(double a,double b){if(a>b){return a;}return b;} double dbmin(double a,double b){if(a<b){return a;}return b;} double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);} int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;} int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;} int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;} int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;} int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;} int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;} int strsortfncsj(const void *a,const void *b){return strcmp((char *)a,(char *)b);} int strsortfnckj(const void *a,const void *b){return strcmp((char *)b,(char *)a);} int main(void){ int i,j,n,m,k,a[262144],b,c,w,l,r,t,x; double d; char s[262144]; scanf("%d",&t); //l=strlen(s); for(i=0;i<t;i++){ x=0; scanf("%d",&n); for(j=0;j<n;j++){ if(j!=0){printf(" ");} scanf("%d%d",&l,&r); if(x<l){x=l;printf("%d",x);x++;} else if(x<=r){ printf("%d",x);x++; } else{ printf("0"); } } printf("\n"); } //qsort(a,n,sizeof(int),sortfncsj); //printf("%d\n",r); return 0; }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
f92ffcaa55344b0b80b0ddc689ecb55b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include <stdio.h> int main() { int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); int a[n],b[n]; for(int i=0;i<n;i++) { scanf("%d%d",&a[i],&b[i]); } int c=1; for(int i=0;i<n;i++) { if(b[i]<c) printf("0 "); else { while(c<a[i]) c++; printf("%d ",c++); } } printf("\n"); } return 0; }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
966d70f5cf74428ba58b9417814a71cc
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include<stdio.h> #include<string.h> #include<math.h> #include<ctype.h> #define mod 100000007 #define N 200001 int main() { int t,n,i,time,l,r; scanf("%d",&t); while(t--) { scanf("%d%d%d",&n,&l,&r); time=l; printf("%d ",time); time++; for(i=1; i<n; i++) { scanf("%d%d",&l,&r); if(time>r)printf("0 "); else { if(time<l)time=l; printf("%d ",time); time++; } } printf("\n"); } return 0; }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
0591b9ded6d1d6a2729a1b90008c9407
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include <stdio.h> #define N 1000 int main() { int t; scanf("%d", &t); while (t-- > 0) { static int tt[N], rr[N]; int n, i, j, time, l; scanf("%d", &n); time = 0; for (i = 0, j = 0; i < n; i++) { scanf("%d%d", &l, &rr[i]); while (time < l && j < i) { tt[j] = 0; if (time <= rr[j]) tt[j] = time++; j++; } time = l; } while (j < n) { tt[j] = 0; if (time <= rr[j]) tt[j] = time++; j++; } for (i = 0; i < n; i++) printf("%d ", tt[i]); printf("\n"); } return 0; }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
dc98a059b051d431e5c6f86d4a3ab51b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include<stdio.h> #include<stdlib.h> void main(){ long long t,k=0,i,j,a,b,count; scanf("%lld",&t); long long n[t],ans[t][1100]; while(t--){ count=1; scanf("%lld",&n[k]); for(i=0;i<n[k];i++){ scanf("%lld %lld",&a,&b); if(count>=a){ if(count-a>(b-a)){ ans[k][i]=0;} else{ ans[k][i]=count; count++;} } else{ count=a+1; ans[k][i]=a;} } k++; } for(i=0;i<k;i++){ for(j=0;j<n[i];j++) printf("%d ",ans[i][j]); printf("\n");} exit(0); }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
2a8518d1fce73fac084c0454048e6d8d
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include<stdio.h> int main() { long long int t,n,l[5009],r[5009],i,p; scanf("%lld",&t); while(t--) { scanf("%lld",&n); for(i=0;i<n;++i) scanf("%lld%lld",&l[i],&r[i]); p=1; i=0; while(i<n) { while(p<l[i]) p++; if(r[i]>=p) { printf("%lld ",p); p++; } else printf("0 "); i++; } printf("\n"); } return 0; }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
c5a72f578ca6eceb98899e52d3b2e54f
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include <stdio.h> int main(void) { int t, n; scanf("%d", &t); for(int i1 = 0; i1 < t; i1++) { scanf("%d", &n); int time = 1; for(int j = 0; j < n; j++) { int l, r; scanf("%d%d", &l, &r); if (l >= time) { time = l; printf("%d ", time); time++; } else { if (time <= r) { printf("%d ", time); time++; } else printf("0 "); } } printf("\n"); } }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
0fd84bf9f65f0411c1446517dd163a6d
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include<stdio.h> int main() { int m,n,i,j,k,p,q,t; scanf("%d",&q); while(q) { int a[1010]; int b[1010]; int c[1010]; q--; scanf("%d",&t); for(i=0;i<t;i++) scanf("%d%d",&a[i],&b[i]); i=0;m=0; while(i!=t) { if(m<=b[i]) { if(a[i]<=m) m++; else m=a[i]+1; c[i]=m-1; } else { c[i]=0; } i++; } for(i=0;i<t;i++) printf("%d ",c[i]); printf("\n"); } return 0; }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
c78cd513bf1be42dcf83d58dc02265ed
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include<stdio.h> int main(void) { int t,n; scanf("%d", &t); int i,j,k,l; for(i=0; i<t; ++i){ scanf("%d", &n); int a[n],b[n]; for(j=0; j<n; ++j){ scanf("%d%d", &a[j], &b[j]); } int sec=1; for(k=0; k<n; ++k){ if(a[k]>sec){ sec=a[k]; } if(b[k]<sec){ b[k]=0; } else{ b[k]=sec; ++sec; } } for(k=0; k<n; ++k){ printf("%d ", b[k]); } puts(""); } }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
f0cec32315a21fc47184dda4fb4f8f6d
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include<stdio.h> struct note { int i; int l; int r; int t; }que[1500]; int main() { int t; scanf("%d",&t); while (t--) { int k; struct note temp; int n,i,j,a[1500],b[1500],c[1500]; scanf("%d",&n); for (i=1;i<=n;i++) { que[i].i=i; scanf("%d%d",&que[i].l,&que[i].r); } for (k=1,i=1;k<=n;i++) { if (i>=que[k].l&&i<=que[k].r) {que[k].t=i;k++;} else if (i>=que[k].l&&i>que[k].r) { que[k].t=0; i--; k++; } } printf("%d",que[1].t); for (i=2;i<=n;i++) printf(" %d",que[i].t); printf("\n"); } return 0; }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
40af697ba3a82c77626fb9b6671885ae
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include<stdio.h> #include<string.h> int main() { int t,i; scanf("%d\n",&t); for(i=1;i<=t;i++) { int n,a[1005],c[1005],b[1005]; memset(c,0,sizeof(c)); memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); scanf("%d\n",&n); int j,k,s=1,d=0; for(j=1;j<=n;j++) { scanf("%d %d",&a[j],&b[j]); } for(j=1;j<=n;j++) { if(s>=a[j]) { if(s<=b[j]) { c[j]=s; s++; } else { c[j]=0; } } else { s=a[j]; c[j]=s; s++; } } for(j=1;j<=n;j++) { if(j==1) { printf("%d",c[j]); } else { printf(" %d",c[j]); } } printf("\n"); } }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
afd4e09e50a67bbc57385b04e701440d
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include<stdio.h> #include<string.h> int main() { int t,i; scanf("%d\n",&t); for(i=1;i<=t;i++) { int n,a[1005],c[1005],b[1005]; memset(c,0,sizeof(c)); memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); scanf("%d\n",&n); int j,k,s=1,d=0; for(j=1;j<=n;j++) { scanf("%d %d",&a[j],&b[j]); } for(j=1;j<=n;j++) { if(s>=a[j]) { if(s<=b[j]) { c[j]=s; s++; } else { c[j]=0; } } else { s=a[j]; c[j]=s; s++; } } for(j=1;j<=n;j++) { if(j==1) { printf("%d",c[j]); } else { printf(" %d",c[j]); } } printf("\n"); } }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
5ccffece787b3130dbfe7d9bde7abb47
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include<stdio.h> int main() { int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); int a[2100],b[2100]; for(int i=1;i<=n;i++) { scanf("%d %d",&a[i],&b[i]); } printf("%d",a[1]); int time=a[1]; for(int i=2;i<=n;i++) { if(a[i]>time) { printf(" %d",a[i]); time=a[i]; } else if(a[i]<=time&&b[i]>time) { printf(" %d",time+1); time++; } else if(b[i]<=time) { printf(" 0"); } } printf("\n"); } }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
9a1623dd341a6e86e28c235a97e4fe6c
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include<stdio.h> int main() { int t,i; scanf("%d",&t); for(i=0;i<t;i++) { int n,j; scanf("%d",&n); int l[n],r[n]; for(j=0;j<n;j++) scanf("%d %d",&l[j],&r[j]); int s=0; for(j=0;j<n;j++) { if(s<l[j]) s=l[j]; if(s>r[j]) { printf("0\n"); } else { printf("%d\n",s); s=s+1; } } } }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
fdb922776599ffcfaecedaaf06746902
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include<stdio.h> #include<stdlib.h> #define N 1002 int max(int a,int b){ if(a>b)return a; else return b; } struct event{ int id; int l; int r; }; static int cmp(const void *a,const void *b){ if( (*(struct event *)a).l==(*(struct event *)b).l){ return (*(struct event *)a).id - (*(struct event *)b).id; }else{ return (*(struct event *)a).l - (*(struct event *)b).l; } } int main(){ int t; scanf("%d",&t); struct event e[N]; int sec[N]; int queue[N]; while(t--){ int n; scanf("%d",&n); int i; //需要排序! for(i=0;i<n;i++){ scanf("%d%d",&(e[i].l),&(e[i].r)); e[i].id=i+1; } qsort(e,n,sizeof(struct event),cmp); /* for(i=0;i<n;i++){ printf("%d %d %d\n",e[i].id,e[i].l,e[i].r); } */ int time=0; for(i=0;i<n;i++){ //printf("time = %d\n",time); //就是说:如果有两个人同时到,然后第一个人喝了茶,第二个人时间不够了,这样第三个人的时间不应该增加? //就是说把不能等的要清理掉? if(time>e[i].r){ sec[e[i].id]=0; //就是说:对于等不及的人,我们的时间也不能变! }else{ sec[e[i].id]=max(e[i].l,time); time=sec[e[i].id]+1; } } for(i=1;i<=n;i++){ printf(" %d",sec[i]); } printf("\n"); } return 0; }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
e9920a912474a2bfbb277066e4aa8b6f
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include <stdio.h> int main() { int c,s,i,j,k,l,m; int a[2000][2]; scanf("%d",&c); for(i=0;i<c;i++) { scanf("%d",&s); for(j=0;j<s;j++) { for(k=0;k<2;k++) { scanf("%d",&a[j][k]); } } for(j=0,m=1;j<s;j++) { l=a[j][0]; if(l>m) { m=l; } if(l<=m&&m<=a[j][1]) { printf("%d ",m); m++; } else { printf("0 "); } } printf("\n"); } return 0; }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
493e1fe31f370045b30a93b5ae3237cf
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include<stdio.h> int main(void){ int t; scanf("%d",&t); for(int j = 0; j < t ; j++){ int n; scanf("%d",&n); int t1,t2,cur_t = 0; for(int i = 0; i < n ; i++){ scanf("%d %d",&t1,&t2); if(cur_t <= t1){ cur_t = t1; } if(t2 >= cur_t){ printf("%d ",cur_t); cur_t++; } else{ printf("0 "); } } printf("\n"); } return 0; }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
1a29ccb602b5f95664837d8880f571d3
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include<stdio.h> struct student{ int arrive,leave; }a[1005]; int t,n,x[1005]; int main() { scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d%d",&a[i].arrive,&a[i].leave); int time=1; for(int i=0;i<n;i++) { if(a[i].arrive>=time) { time=a[i].arrive+1; x[i]=a[i].arrive; } else { if(time-a[i].leave<=0) { x[i]=time; time++; } else x[i]=0; } } for(int i=0;i<n-1;i++) printf("%d ",x[i]); printf("%d\n",x[n-1]); } }
Recently n students from city S moved to city P to attend a programming camp.They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea. For each student determine the second he will use the teapot and get his tea (if he actually gets it).
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
C
471f80e349e70339eedd20d45b16e253
5f373897c4298f17771761cac04c096b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1517582100
["2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3"]
NoteThe example contains 2 tests: During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
PASSED
1,200
standard input
1 second
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000). Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students. Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea. It is guaranteed that for every condition li - 1 ≤ li holds. The sum of n over all test cases doesn't exceed 1000. Note that in hacks you have to set t = 1.
["1 2 \n1 0 2"]
#include<stdio.h> int main() { int t; scanf("%d",&t); while(t) { int n; scanf("%d",&n); int mat[n][2]; for(int i=0; i<n; i++) { scanf("%d %d",&mat[i][0],&mat[i][1]); } if(n==1) printf("%d\n",mat[0][0]); else { for(int i=0; i<n-1; i++) { if(mat[i][1]>=mat[i][0]) { printf("%d ",mat[i][0]); for(int j=i+1; j<n; j++) { if(mat[j][0]==mat[i][0]) mat[j][0]++; } } else { printf("0 "); } } if(mat[n-1][1]>=mat[n-1][0]) printf("%d",mat[n-1][0]); else printf("0"); } printf("\n"); t--; } }
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
C
371100da1b044ad500ac4e1c09fa8dcb
11f21e96b662d0333fa15a3fe379cd9f
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "*special", "greedy" ]
1330804800
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
PASSED
1,100
standard input
3 seconds
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
["4", "5"]
#include <stdio.h> int main(){ int s,n,i,k,o,d,t; k=0; o=0; d=0; t=0; scanf("%i\n", &n); for (i=0; i<n; i++){ scanf("%i", &s); switch(s){ case 1: if (t!=0) t--; else if(t==0) { o++; k++; } break; case 2: if (d!=0) d--; else if (d==0){ d++; k++; } break; case 3: if (o!=0) o--; else if (o==0){ t++; k++; } break; case 4: k++; break; default: continue; } } if(d==1 && o>=2){ d--; o-=2; k-=2; } else if(d==1 && o==1){ d--; o--; k--; } if (o>0) k=k-o+o/4; if (o%4!=0) k++; printf("%i",k); return 0; }
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
C
371100da1b044ad500ac4e1c09fa8dcb
c9ef56d053c7a2141cdf67e2629e43e5
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "*special", "greedy" ]
1330804800
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
PASSED
1,100
standard input
3 seconds
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
["4", "5"]
#include<stdio.h> int main() { int n,b[4],i,count=0,c; scanf("%d",&n); int a[n]; for(i=0;i<4;i++){ b[i]=0; } for(i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]==4) { b[3]++ ; } else if(a[i]==3) { b[2]++ ; } else if(a[i]==2) { b[1]++ ; } else if(a[i]==1) { b[0]++ ; } } if(b[3]!=0) { count=count+b[3]; b[3]=0; } if(b[2]!=0) { count=count+b[2]; while(b[2]--){ if(b[0]>0) { b[0]--; } } b[2]=0; } if(b[1]!=0) { if(b[1]==1){ count=count+1; b[0]=b[0]-2; } else if(b[1]%2==0){ count=count+b[1]/2; b[1]=0; } else { count=count+b[1]/2+1; if(b[0]>0) b[0]=b[0]-2; } b[1]=0; } if(b[0]>0) { if(b[0]<=4) count++; else { if(b[0]%4==0){ c=b[0]/4; count=count+c; } else { c=b[0]/4; count=count+c+1; } } b[0]=0; } printf("%d ",count); }
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
C
371100da1b044ad500ac4e1c09fa8dcb
462f254f7e9b4420c844fae3091b0c70
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "*special", "greedy" ]
1330804800
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
PASSED
1,100
standard input
3 seconds
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
["4", "5"]
#include<stdio.h> int main () { long n,c1=0,c2=0,c3=0,c4=0,mod1,mod2,mod3,c; scanf("%ld",&n); for(long i=0;i<n;i++){scanf("%d",&c);if(c==1)c1++;else if(c==2)c2++;else if(c==3)c3++;else c4++;} while(c1!=0&&c3!=0){c1--;c3--;c4++;} mod3=c1%4; mod1=c1%2; c4+=(c1-mod3)/4;c1=mod3; c2+=(c1-mod1)/2;c1=mod1; int mod4=c2%2; c4+=(c2-mod4)/2;c2=mod4; if(c1>=c2){c1-=c2; c3+=c2; c2=0;}else { c2-=c1; c3+=c1; c1=0;} mod2=c1%3; c3+=(c1-mod2)/3;c1=mod2; printf("%d",c1+c2+c3+c4); }
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
C
371100da1b044ad500ac4e1c09fa8dcb
56c40c8d5388a0cc4617f5c326256297
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "*special", "greedy" ]
1330804800
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
PASSED
1,100
standard input
3 seconds
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
["4", "5"]
#include<stdio.h> int main () { int i ,n ,x, count[4]={0} , taxi = 0; scanf("%d",&n); //scanning the input for(i=0;i<n;i++) { scanf("%d",&x); count[x-1]++; } taxi=count[3]+count[2]; if(count[2]>count[0]) count[0]=0 ; else count[0]-=count[2]; taxi+=count[1]/2; count[1]=count[1]%2 ; if(count[1]) { taxi++; count[0]-=2; if(count[0]<0) count[0]=0; } taxi+=count[0]/4 ; if(count[0]%4) taxi++; printf("%d",taxi); }
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.
C
371100da1b044ad500ac4e1c09fa8dcb
e134b2875a95814e4276379728edec40
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "*special", "greedy" ]
1330804800
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
PASSED
1,100
standard input
3 seconds
The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.
["4", "5"]
#include<stdio.h> int A[5],n,x,w; int main(){ scanf("%d",&n); while(n--){ scanf("%d",&x); A[x]++; }w = A[1] - A[3] + 2 * (A[2] & 1); printf("%d",A[4] + A[2] / 2 + A[3] + (A[1] > A[3] ? w / 4 + (w % 4 != 0) : (A[2] & 1))); return 0; }
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train?
Print a single integer — the minimum number of actions needed to sort the railway cars.
C
277948a70c75840445e1826f2b23a897
52f4d4ca666ec6fed801bb2543a3636a
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "greedy" ]
1449677100
["5\n4 1 2 5 3", "4\n4 1 3 2"]
NoteIn the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
PASSED
1,600
standard input
2 seconds
The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cars in the train. The second line contains n integers pi (1 ≤ pi ≤ n, pi ≠ pj if i ≠ j) — the sequence of the numbers of the cars in the train.
["2", "2"]
#include <stdio.h> #include <string.h> #include <stdlib.h> int max(int a, int b){ return (a>b)?a:b; } int main(void) { int n; scanf("%d",&n); int arr[n+1]; int i; for(i=0;i<=n;i++){ arr[i]=0; } for(i=0;i<n;i++){ int curr; scanf("%d",&curr); arr[curr] = arr[curr-1]+1; } int maxi = 0; for(i=1;i<=n;i++){ maxi = max(maxi,arr[i]); } printf("%d",n-maxi); return 0; }
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train?
Print a single integer — the minimum number of actions needed to sort the railway cars.
C
277948a70c75840445e1826f2b23a897
5c7f9c227581274c0926f38d6e7d653d
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "greedy" ]
1449677100
["5\n4 1 2 5 3", "4\n4 1 3 2"]
NoteIn the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
PASSED
1,600
standard input
2 seconds
The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cars in the train. The second line contains n integers pi (1 ≤ pi ≤ n, pi ≠ pj if i ≠ j) — the sequence of the numbers of the cars in the train.
["2", "2"]
#include<stdio.h> int main() { int i,n,x; scanf("%d",&n); int a[n+1]; for(i=0;i<=n;i++) a[i]=0; for(i=0;i<n;i++) { scanf("%d",&x); if(a[x-1]==0) a[x]=1; else a[x]=a[x-1]+1; }x=0; for(i=0;i<=n;i++) if(a[i]>x) x=a[i]; printf("%d",n-x); return 0; }
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train?
Print a single integer — the minimum number of actions needed to sort the railway cars.
C
277948a70c75840445e1826f2b23a897
5abfa0b8a77388c8f7e49f8df21983ec
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "greedy" ]
1449677100
["5\n4 1 2 5 3", "4\n4 1 3 2"]
NoteIn the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
PASSED
1,600
standard input
2 seconds
The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cars in the train. The second line contains n integers pi (1 ≤ pi ≤ n, pi ≠ pj if i ≠ j) — the sequence of the numbers of the cars in the train.
["2", "2"]
#include "stdio.h" #include "stdlib.h" #include "math.h" main(n,i,k,max,cur) { scanf("%d", &n); int pos[1000001]; for(i=1; i<n; ++i) { scanf("%d ", &k); pos[k] = i; } scanf("%d", &k); pos[k] = i; for(i=1, cur=1, max=cur; i<n; ++i) { if(pos[i] < pos[i+1]) ++cur, max = max < cur ? cur : max; else cur = 1; } printf("%d", n-max); return 0; }
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train?
Print a single integer — the minimum number of actions needed to sort the railway cars.
C
277948a70c75840445e1826f2b23a897
2762c940680388ee0233645ed0228880
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "greedy" ]
1449677100
["5\n4 1 2 5 3", "4\n4 1 3 2"]
NoteIn the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
PASSED
1,600
standard input
2 seconds
The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cars in the train. The second line contains n integers pi (1 ≤ pi ≤ n, pi ≠ pj if i ≠ j) — the sequence of the numbers of the cars in the train.
["2", "2"]
#include <stdio.h> int a[100001],b[100001]; int main() { int n ,i; scanf("%d",&n); for (i = 1; i <= n; i++) { scanf("%d",&a[i]); b[a[i]] = i; } int ans = 1; int max = 1; for (i = 2; i <= n; i++) { if (b[i]>b[i-1]) ans++; else { if (ans>max) max=ans; ans = 1; } } if (ans>max) max=ans; printf("%d",n-max); return 0; }
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train?
Print a single integer — the minimum number of actions needed to sort the railway cars.
C
277948a70c75840445e1826f2b23a897
b61309a4bf268a57bdff19706adf45a2
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "greedy" ]
1449677100
["5\n4 1 2 5 3", "4\n4 1 3 2"]
NoteIn the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
PASSED
1,600
standard input
2 seconds
The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cars in the train. The second line contains n integers pi (1 ≤ pi ≤ n, pi ≠ pj if i ≠ j) — the sequence of the numbers of the cars in the train.
["2", "2"]
/* Problem: 605A - Sorting Railway Cars */ /* Solver: Gusztav Szmolik */ #include <stdio.h> unsigned int q[100000]; int main () { unsigned int n; unsigned int i; unsigned int p; unsigned int sc; unsigned int sx; unsigned int nm; if (scanf("%u",&n) != 1) return -1; if (n < 1 || n > 100000) return -1; for (i = 0; i < n; i++) q[i] = 100000; for (i = 0; i < n; i++) { if (scanf("%u",&p) != 1) return -1; if (p < 1 || p > n) return -1; p--; if (q[p] != 100000) return -1; q[p] = i; } sc = 1; sx = 1; nm = n-1; for (i = 1; i < n; i++) { if (q[i-1] < q[i]) sc++; if (q[i-1] > q[i] || i == nm) { if (sc > sx) sx = sc; sc = 1; } } printf ("%u\n",n-sx); return 0; }
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train?
Print a single integer — the minimum number of actions needed to sort the railway cars.
C
277948a70c75840445e1826f2b23a897
673c564b4cef08921af0befbcd47e1b8
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "greedy" ]
1449677100
["5\n4 1 2 5 3", "4\n4 1 3 2"]
NoteIn the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
PASSED
1,600
standard input
2 seconds
The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cars in the train. The second line contains n integers pi (1 ≤ pi ≤ n, pi ≠ pj if i ≠ j) — the sequence of the numbers of the cars in the train.
["2", "2"]
#include "stdio.h" int n,i,p,mx; int a[100005]; int main(){ scanf("%d",&n); for(i = 0; i < n; i++){ scanf("%d",&p); a[p] = 1+a[p-1]; if(a[p]>mx) mx = a[p]; } printf("%d\n",n-mx); }
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train?
Print a single integer — the minimum number of actions needed to sort the railway cars.
C
277948a70c75840445e1826f2b23a897
d533dbeba3c175e7edfaf538188ec932
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "greedy" ]
1449677100
["5\n4 1 2 5 3", "4\n4 1 3 2"]
NoteIn the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
PASSED
1,600
standard input
2 seconds
The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cars in the train. The second line contains n integers pi (1 ≤ pi ≤ n, pi ≠ pj if i ≠ j) — the sequence of the numbers of the cars in the train.
["2", "2"]
#include <stdio.h> int main() { int n; scanf("%d", &n); int r = 1; int ps[100000]; for (int i = 0; i < n; i++) { ps[i] = 0; } for (int i = 0; i < n; i++) { int p; scanf("%d", &p); ps[p] = 1 + ps[p - 1]; if (ps[p] > r) { r = ps[p]; } } printf("%d\n", n - r); return 0; }
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train?
Print a single integer — the minimum number of actions needed to sort the railway cars.
C
277948a70c75840445e1826f2b23a897
9cd488c773c146e4e733607aa2c1e4dc
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "greedy" ]
1449677100
["5\n4 1 2 5 3", "4\n4 1 3 2"]
NoteIn the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
PASSED
1,600
standard input
2 seconds
The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cars in the train. The second line contains n integers pi (1 ≤ pi ≤ n, pi ≠ pj if i ≠ j) — the sequence of the numbers of the cars in the train.
["2", "2"]
#include<stdio.h> int dp[100009]; int max(int a,int b) { return (a>b?a:b); } int main() { int n,i,count=0; int a[100009]; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=1;i<=n;i++) { dp[a[i]]=dp[a[i]-1]+1; } for(i=1;i<=n;i++) count=max(count,dp[i]); printf("%d\n",n-count); return 0; }
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and teleport it either to the beginning of the train, or to the end of the train, at his desire. What is the minimum number of actions David Blaine needs to perform in order to sort the train?
Print a single integer — the minimum number of actions needed to sort the railway cars.
C
277948a70c75840445e1826f2b23a897
0f85f3088d3e449cbb3e4c86bd264afb
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "greedy" ]
1449677100
["5\n4 1 2 5 3", "4\n4 1 3 2"]
NoteIn the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train.
PASSED
1,600
standard input
2 seconds
The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cars in the train. The second line contains n integers pi (1 ≤ pi ≤ n, pi ≠ pj if i ≠ j) — the sequence of the numbers of the cars in the train.
["2", "2"]
#pragma warning(disable:4996) #include <stdio.h> int dat[100000]; int rev[100000]; int ln[100000]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int x; scanf("%d", &x); x--; dat[i] = x; rev[x] = i; } ln[0] = 1; int M = 1; for (int i = 1; i < n; i++) { if (rev[i] < rev[i - 1]) ln[i] = 1; else { ln[i] = ln[i - 1] + 1; } if (ln[i] > M) M = ln[i]; } printf("%d", n - M); }
Wilbur the pig is tinkering with arrays again. He has the array a1, a2, ..., an initially consisting of n zeros. At one step, he can choose any index i and either add 1 to all elements ai, ai + 1, ... , an or subtract 1 from all elements ai, ai + 1, ..., an. His goal is to end up with the array b1, b2, ..., bn. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value.
Print the minimum number of steps that Wilbur needs to make in order to achieve ai = bi for all i.
C
97a226f47973fcb39c40e16f66654b5f
8a8353c632b2acf487a1df0aeeed73c9
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "greedy" ]
1447605300
["5\n1 2 3 4 5", "4\n1 2 2 1"]
NoteIn the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes.In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
PASSED
1,100
standard input
2 seconds
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the array ai. Initially ai = 0 for every position i, so this array is not given in the input. The second line of the input contains n integers b1, b2, ..., bn ( - 109 ≤ bi ≤ 109).
["5", "3"]
#include <stdio.h> #include <stdlib.h> long long n , i , t ,a[200005]; int main(void) { scanf("%llu",&n); scanf("%llu",&a[0]); for ( i = 1 ; i < n ; i++){ scanf("%llu",&a[i]); t+=abs(a[i]-a[i-1]); } printf("%llu",t+abs(a[0])); return 0; }
Wilbur the pig is tinkering with arrays again. He has the array a1, a2, ..., an initially consisting of n zeros. At one step, he can choose any index i and either add 1 to all elements ai, ai + 1, ... , an or subtract 1 from all elements ai, ai + 1, ..., an. His goal is to end up with the array b1, b2, ..., bn. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value.
Print the minimum number of steps that Wilbur needs to make in order to achieve ai = bi for all i.
C
97a226f47973fcb39c40e16f66654b5f
f41e8a25d577cc6a24df00e83e038138
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "greedy" ]
1447605300
["5\n1 2 3 4 5", "4\n1 2 2 1"]
NoteIn the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes.In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
PASSED
1,100
standard input
2 seconds
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the array ai. Initially ai = 0 for every position i, so this array is not given in the input. The second line of the input contains n integers b1, b2, ..., bn ( - 109 ≤ bi ≤ 109).
["5", "3"]
#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { int n; long long int res=0; scanf("%d",&n); int arr[n]; for(int i=0;i<n;i++) { scanf("%d",&arr[i]); if(i==0) res = abs(arr[i]); else res += abs(arr[i]-arr[i-1]); } printf("%I64d",res); }
Wilbur the pig is tinkering with arrays again. He has the array a1, a2, ..., an initially consisting of n zeros. At one step, he can choose any index i and either add 1 to all elements ai, ai + 1, ... , an or subtract 1 from all elements ai, ai + 1, ..., an. His goal is to end up with the array b1, b2, ..., bn. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value.
Print the minimum number of steps that Wilbur needs to make in order to achieve ai = bi for all i.
C
97a226f47973fcb39c40e16f66654b5f
4e2f720800cac58915806dbd5b72599e
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "greedy" ]
1447605300
["5\n1 2 3 4 5", "4\n1 2 2 1"]
NoteIn the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes.In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
PASSED
1,100
standard input
2 seconds
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the array ai. Initially ai = 0 for every position i, so this array is not given in the input. The second line of the input contains n integers b1, b2, ..., bn ( - 109 ≤ bi ≤ 109).
["5", "3"]
#include <stdio.h> #include <conio.h> #include <math.h> main() { int n; scanf("%d",&n); long long i,t,k; long long b[n+1]; k=0; for (i=0;i<n;i++) scanf("%I64d",&b[i]); b[-1]=0; for(i=0;i<n;i++) {t=abs(b[i]-b[i-1]); k=k+t; } printf("%I64d",k); }
Wilbur the pig is tinkering with arrays again. He has the array a1, a2, ..., an initially consisting of n zeros. At one step, he can choose any index i and either add 1 to all elements ai, ai + 1, ... , an or subtract 1 from all elements ai, ai + 1, ..., an. His goal is to end up with the array b1, b2, ..., bn. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value.
Print the minimum number of steps that Wilbur needs to make in order to achieve ai = bi for all i.
C
97a226f47973fcb39c40e16f66654b5f
4cdfc70da8e76d1fc34f0223ed460f22
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "greedy" ]
1447605300
["5\n1 2 3 4 5", "4\n1 2 2 1"]
NoteIn the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes.In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
PASSED
1,100
standard input
2 seconds
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the array ai. Initially ai = 0 for every position i, so this array is not given in the input. The second line of the input contains n integers b1, b2, ..., bn ( - 109 ≤ bi ≤ 109).
["5", "3"]
#include<stdio.h> #include<stdlib.h> int main() { int n,i; long long total=0; scanf("%d",&n); int b[n]; for(i=0;i<n;i++) { scanf("%d",&b[i]); if(i==0) total=abs(b[i]); else { total+=abs(b[i]-b[i-1]); } } printf("%lld",total); }
Wilbur the pig is tinkering with arrays again. He has the array a1, a2, ..., an initially consisting of n zeros. At one step, he can choose any index i and either add 1 to all elements ai, ai + 1, ... , an or subtract 1 from all elements ai, ai + 1, ..., an. His goal is to end up with the array b1, b2, ..., bn. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value.
Print the minimum number of steps that Wilbur needs to make in order to achieve ai = bi for all i.
C
97a226f47973fcb39c40e16f66654b5f
98650b73d6462fd5533020d3d82adc43
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "greedy" ]
1447605300
["5\n1 2 3 4 5", "4\n1 2 2 1"]
NoteIn the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes.In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
PASSED
1,100
standard input
2 seconds
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the array ai. Initially ai = 0 for every position i, so this array is not given in the input. The second line of the input contains n integers b1, b2, ..., bn ( - 109 ≤ bi ≤ 109).
["5", "3"]
#include <stdio.h> int main() { long long int arr[200006]; long long int i, j, n,p=0, x=0; scanf("%I64d", &n); for(i=0; i<n; i++){ scanf("%I64d", &arr[i]); if(arr[i]>p){ j=arr[i]-p; x+=j; p+=j; }else{ j=p-arr[i]; x+=j; p-=j; } } printf("%I64d\n", x); return 0; }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
a588b26f0f9f9c7258cf5502a3797c79
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include <stdio.h> #define MAX 500 int main() { int q, n; scanf("%d", &q); for (int i = 0; i < q; i++) { scanf("%d", &n); int students[MAX] = {0}; int x, j; for (j = 0; j < n; j++) { scanf("%d", &students[j]); if (students[j] == 1) x = j; } for (; j < 2 * n; j++) { students[j] = students[j - n]; } int clockwise = 1; for (int a = x; a < x + n - 1; a++) { if (students[a] + 1 != students[a + 1]) { clockwise = 0; continue; } } if (clockwise) { printf("YES\n"); continue; } int counter = 1; int k = x + n; for (; k > x + 1; k--) { if (students[k] + 1 != students[k - 1]) { counter = 0; continue; } } if (counter) { printf("YES\n"); continue; } printf("NO\n"); continue; } }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
827f0a9c2b27f9cb29722bf86b22219b
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include<stdio.h> #include<stdlib.h> int main() { int n,a[200],i,t,c=0; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=0; i<n; i++) scanf("%d",&a[i]); if(abs(a[0]-a[n-1])!=1) c++; for(i=0; i<n-1; i++) if(abs(a[i]-a[i+1])!=1) c++; if(c>1) printf("NO\n"); else printf("YES\n"); c=0; } }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
9f50afe7365c266f15ff90ae123c2249
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> int main() { int t,c,d; int n; int a[201], i; scanf("%d", &t); while (t--) { c = 0; d = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n - 1; i++) { if (a[i] > a[i + 1]) { c++; } else { d++; } } if (a[0] > a[n - 1]) { d++; } else { c++; } if (c == 0 || c == 1 || d == 0 || d == 1 || n == 1) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
3cade0be60dc37ddb3d66abba6d9ace1
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include<stdio.h> int main() { int q,w; scanf("%d",&q); for(w=1;w<=q;w++){ int a,m=0,k=0,j,t=0,i; scanf("%d",&a); int aa[a]; for(i=0;i<a;i++) { scanf("%d",&aa[i]); } for(i=1;i<a;i++) { if(aa[i]-aa[i-1]!=1) m++; } for(i=1;i<a;i++) { if(aa[i-1]-aa[i]!=1) k++; } if(m<=1 || k<=1) printf("YES\n"); else printf("NO\n"); } }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
2b1e629219f37076c520a31676b380e8
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include <stdio.h> int Q,n,a,x,c,b,j; int main() { scanf("%d",&Q); while(Q--) { scanf("%d%d",&n,&a); x=a;c=0; for(j=1;j<n;j++) { scanf("%d",&b); if(abs(a-b)>1)c++; a=b; } if(abs(x-a)>1)c++; if(c>1)printf("%s\n","NO"); else printf("%s\n","YES"); } return 0; }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
3fa6045f9b1ed2e2ca17fb3520c1ecd7
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include <stdio.h> int main() { int girada, n, i, j, horario=1, antihorario=1, pessoa[205]; scanf("%d", &girada); for (i=0; i<girada; i++) { horario=1; antihorario=1; scanf("%d", &n); for (j=0; j<n; j++) { scanf("%d", &pessoa[j]); if (j>0) { //if pra saber se eh horario if (pessoa[j] != pessoa[j-1]+1) { if (pessoa[j-1] != n || pessoa[j] != 1) { horario = 0; } } //if pra saber se eh antihorario if (pessoa[j] != pessoa[j-1]-1) { if (pessoa[j] != n || pessoa[j-1] != 1) { antihorario=0; } } } } if (horario == 0 && antihorario == 0) { printf("NO\n"); } else { printf("YES\n"); } } return 0; }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
d065a26f3668720eadae78203e078400
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include <stdio.h> int eh_horario(int pessoa[], int pessoa_size, int pos) { if (pos == pessoa_size-1) { return 1; } else if (pessoa[pos+1] == pessoa[pos] + 1) { return eh_horario(pessoa, pessoa_size, pos+1); } else if (pessoa[pos] == pessoa_size && pessoa[pos+1] == 1) { return eh_horario(pessoa, pessoa_size, pos+1); } return 0; } int eh_antihorario(int pessoa[], int pessoa_size, int pos) { if (pos == pessoa_size-1) { return 1; } else if (pessoa[pos+1] == pessoa[pos] - 1) { return eh_antihorario(pessoa, pessoa_size, pos+1); } else if (pessoa[pos] == 1 && pessoa[pos+1] == pessoa_size) { return eh_antihorario(pessoa, pessoa_size, pos+1); } return 0; } int main() { int girada, n, i, j, pessoa[205]; scanf("%d", &girada); for (i=0; i<girada; i++) { scanf("%d", &n); for (j=0; j<n; j++) { scanf("%d", &pessoa[j]); } if (eh_horario(pessoa, n, 0) || eh_antihorario(pessoa, n, 0)) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
058324a1b79b38e8fc83a2444b4bd0e0
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include <stdio.h> int main(void) { // your code goes here int q,i,n; scanf("%d", &q); while(q--) { scanf("%d", &n); int a,b,c=0; scanf("%d", &b); for(i=1;i<n;i++) {scanf("%d", &a); if(abs(a-b)>1&&abs(a-b)!=n-1) c++; b=a;} if(c>0) printf("NO\n"); else printf("YES\n"); } return 0; }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
61be75868771b38bce608537bf130cf9
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include<stdio.h> int main() { int t,i,j,n,temp,test,diff,check; scanf("%d",&t); while(t--) { scanf("%d",&n); int arr[n]; for(i=0;i<n;i++){ scanf("%d",&arr[i]); } temp=arr[0]; test=0; for(i=1;i<n;i++){ diff=abs(temp-arr[i]); if(diff>1){ test++; } temp=arr[i]; //printf("%d ",diff); } if(n==1){ printf("YES\n"); } else if(test==1){ check=abs(arr[n-1]-arr[0]); if(check==1){ printf("YES\n"); }else{ printf("NO\n"); } } else if(test==0){ printf("YES\n"); } else{ printf("NO\n"); } } return 0; }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
fe022c08e69a9a75cd15bb0f26c8af6c
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include<stdio.h> int main() { int n, q, i, j, c, a[201]; scanf("%d", &n); for(i=1;i<=n;i++) { scanf("%d",&q); for(j=0;j<q;j++) { scanf("%d", &a[j]); } if(q==1) printf("YES\n"); else if(a[0]<a[1]) { c=0; for(j=0;j<q;j++) { if(a[j]-a[0]==1 || a[j]-a[0]==-1 || a[j]-a[0]==q-1 || a[j]-a[0]==-(q-1)) { c++; a[0]=a[j]; } } if(c==q-1) printf("YES\n"); else printf("NO\n"); } else if(a[1]<a[0]) { c=0; for(j=0;j<q;j++) { if(a[0]-a[j]==1 || a[0]-a[j]==-1 || a[0]-a[j]==q-1 || a[0]-a[j]==-(q-1)) { c++; a[0]=a[j]; } } if(c==q-1) printf("YES\n"); else printf("NO\n"); } } return 0; }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
f6f0cbe7a9b41fb62317916c4e519da1
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include<stdio.h> int main(void){ int T; scanf("%d",&T); while(T--){ int n,no1=0,no2=0,out=0; int i,a[250]; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&a[i]); if(n>2){ for(i=1;i<=n-1;i++){ if(a[i]>=a[i+1]){ no1++; } if(a[i]<=a[i+1]){ /*no2 no1*/ no2++; /*54321876*/ /*81234567*/ } } if(a[1]!=a[n]-1){ no2++; } // 判断首尾 if(a[1]!=a[n]+1){ no1++; } if(no1<2||no2<2) out++; } if(n==1||(n==2&&(a[1]==a[2]+1||a[1]==a[2]-1))||out!=0) printf("YES\n"); else printf("NO\n"); } return 0; }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
927af0eeecead3df3b09a6d99032d4d6
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include<stdio.h> #include<stdlib.h> main() {int i,j,n,x,*p; scanf("%d",&n); for(j=0;j<n;j++) { scanf("%d",&x); int a[x],t=0; p=&a[0]; for(i=0;i<x;i++) { scanf("%d",p+i); } for(i=0;i<x;i++) if(abs(*(p+i)-*(p+i+1))==1 || abs(*(p+i)-*(p+i+1))==x-1) t++; if(t==x-1) printf("YES\n"); else printf("NO\n"); } }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
df134b1a571a44bb868b3db681ad9c20
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include<stdio.h> int main() { int ar[205]= {0},ar1[205]= {0},a,b,c,d,i,j; scanf("%d",&a); while(a--) { scanf("%d",&b); for(i=1; i<=b; i++) { scanf("%d",&ar[i]); } int l=0; for(i=1; i<=b*2; i++) { c=b; int k=0; for(j=1; j<=b; j++) { if(ar[j]!=c) { k=1; break; } c--; } int m=0; for(j=1; j<=b; j++) { if(ar[j]!=j) { m=1; break; } } if(b<=3) { printf("YES\n"); l=1; break; } else if(k==0||m==0) { printf("YES\n"); l=1; break; } else { c=0; ar[0]=0; for(j=1; j<=b; j++) { ar[j-1]=ar[j]; } ar[b]=ar[0]; } } if(l==0)printf("NO\n"); } return 0; }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
abdc8d6647094e869094f315dfece112
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include<stdio.h> int main() { int q,i,n,p[201],j,c1,c2; scanf("%d",&q); for(i=0;i<q;i++) { c1=0,c2=0; scanf("%d",&n); for(j=0;j<n;j++)scanf("%d",&p[j]); for(j=0;j<n;j++) { if(j!=n-1) { if(p[j]+1==p[j+1])c1++; else if(p[j]==p[j+1]+1)c2++; } else { if(p[j]+1==p[0])c1++; else if(p[j]==p[0]+1)c2++; } //printf("%d\t",c1); } if(c1==n-1||c2==n-1)printf("YES\n"); else printf("NO\n"); } }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
a9c304b549d0ba92eab1a6d70a935bdc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include<stdio.h> #include<stdlib.h> #include<math.h> int main() { int totalrep,nbrelem,nbr[200],tem=0; scanf("%d",&totalrep); for (int i = 0; i < totalrep; i++) { scanf("%d",&nbrelem); for (int j = 0; j < nbrelem; j++) { scanf("%d",&nbr[j]); } if (nbrelem<=3) { printf("YES\n"); continue; } for (int k = 0; k < nbrelem-1; k++) { int temp; temp=abs(nbr[k]-nbr[k+1]); if (temp!=1&&temp!=nbrelem-1) { printf("NO\n"); tem=1; break; } } if (tem) { tem=0; continue; } printf("YES\n"); } }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
04da8244635681ad05387f27f6533894
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include<stdio.h> //顺时针圆圈舞 int isClockwise(int a[], int n){ for (int j = 0; j < n; j++){ int flag = 0; for (int i = 0; i < n; i++){ if (a[i + j + 1] - a[i + j] != 1){ break; } else flag++; } if (flag == n - 1) return 1; } return 0; } //逆时针圆圈舞 int isCounterclockwise(int a[], int n){ for (int j = 0; j < n; j++){ int flag = 0; for (int i = 0; i < n; i++){ if (a[i + j + 1] - a[i + j] != -1){ break; } else flag++; } if (flag == n - 1) return 1; } return 0; } int main() { //读入判断次数 int q; scanf("%d", &q); while (q--){ //读入数组 int n; scanf("%d", &n); int a[400]; for (int i = 0; i<n; i++) { scanf("%d", &a[i]); a[i + n] = a[i]; } if (n < 4) printf("YES\n"); else if (isClockwise(a, n) == 1 || isCounterclockwise(a, n) == 1) printf("YES\n"); else printf("NO\n"); } return 0; }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
67bf23b6a1d1fe2b98d8f0112869613d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include <stdio.h> int main() { int q, n, i, c, j, k; scanf("%d",&q); while(q--) { scanf("%d",&n); int p[n]; c=0; j=0; k=0; for(i=0;i<n;i++) { scanf("%d",&p[i]); if(i!=0) { if(p[i]-p[i-1]==-1) k=-1; else if(p[i]-p[i-1]==1) j=1; else c++; } } printf("%s\n",k==-1 && j==1?"NO":c>1?"NO":"YES"); } }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
d5fece700927264bc89d57e392c45ee5
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include<stdio.h> int main() { int t,m; scanf("%d",&t); m=t-1; int arr[t]; while(t--) { arr[t]=0; int n,con=0; scanf("%d",&n); int ar[n*2]; for(int i=0;i<n;i++) { scanf("%d",&ar[i]); ar[n+i]=ar[i]; } if(n==1) arr[t]=1; else { if(ar[n-2]-ar[n-1]==1||ar[0]-ar[1]==1) { for(int i=0;i<(n*2)-1;i++) { if(ar[i]-ar[i+1]==1) { con+=1; if(con==n-1) { arr[t]=1; break; } } else con=0; } } else if(ar[n-1]-ar[n-2]==1||ar[1]-ar[0]==1) { for(int i=0;i<(n*2)-1;i++) { if(ar[i+1]-ar[i]==1) { con++; if(con==n-1) { arr[t]=1; break; } } else con=0; }} } } for(int i=m;i>=0;i--) { if(arr[i]==1) printf("%s\n","YES"); else printf("%s\n","NO"); } return 0; }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
944d780b359afc22bfcaad62bd456218
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include<stdio.h> int main(){ int T,i; scanf("%d",&T); for(i=0;i<T;i++) { int n,j,p,k,s=0; scanf("%d",&n); int arr[n],flag=1; for(j=0;j<n;j++) scanf("%d",&arr[j]); for(j=0;j<n;j++) { if(arr[j]==1) { k=j; } } if(k<n-1&&k>0) { p=k; for(j=k+1;j<n;j++) { if(arr[j]-arr[p]==1) { p=j; s++; flag=1; } else { flag=0; goto l1; } if(s<n-1&&j==n-1) j=-1; if(s==n-1) goto end; } l1: p=k; for(j=k-1;j>=0;j--) { if(arr[j]-arr[p]==1) { p=j; s++; flag=1; } else { flag=0; if(flag==0) { printf("NO\n"); goto end; } } if(s<n-1&&j==0) j=n; if(s==n-1) goto end; } } if(k==n-1) { p=k; for(j=k-1;j>=0;j--) { if(arr[j]-arr[p]==1) { p=j; flag=1; } else { flag=0; if(flag==0) { goto l2; } } } if(flag==1) goto end; l2: p=k; for(j=0;j<n-1;j++) { if(arr[j]-arr[p]==1) { p=j; flag=1; } else { flag=0; if(flag==0) { printf("NO\n"); goto end; } } } if(flag==1) goto end; } if(k==0) { p=k; for(j=1;j<n;j++) { if(arr[j]-arr[p]==1) { p=j; flag=1; } else { goto l3; } } if(flag==1) goto end; l3: p=k; for(j=n-1;j>0;j--) { if(arr[j]-arr[p]==1) { p=j; flag=1; } else { flag=0; if(flag==0) { printf("NO\n"); goto end; } } } if(flag==1) goto end; } end: if(flag==1) printf("YES\n"); } }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
b523993ff2760de2bd68d7f9a25c0a4c
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include <stdio.h> typedef long long ll; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define min(l,r) ((l)<(r)?l:r) int n,t; int a[202]; int main(){ scanf("%d", &t); rep(i,t){ scanf("%d", &n); rep(i,n) scanf("%d", a+i); int ok = 1; if(n == 1){ if(a[0] == 1) ok = 1; else ok = 0; }else{ int idx = -1; rep(i,n) if(a[i] == 1){ idx = i; break; } if(idx == -1) ok = 0; else if(a[(idx+1)%n] == 2){ rep(i,n-2) { if(a[(idx+2+i)%n] != i+3) ok = 0; } }else if(a[(n+idx-1)%n] == 2){ rep(i,n-2) { if(a[(n+idx-2-i)%n] != i+3) ok = 0; } }else{ ok = 0; } } if(ok) puts("YES"); else puts("NO"); } }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
3c615c84dcb5c44ffdd96182f8f96848
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include <stdio.h> #include <math.h> int a[210]; void solve() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); int cnt = 0; for (int i = 0; i < n - 1; i++) { if (abs(a[i] - a[i + 1]) != 1) cnt++; } if (abs(a[n - 1] - a[0]) != 1) cnt++; printf("%s\n", (cnt > 1) ? "NO" : "YES"); } int main() { int t; scanf("%d", &t); while (t--) { solve(); } }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
546e136f0e4e246a7908955c560487f0
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include <stdio.h> #include <stdlib.h> int a[210], n; int main(){ int q; scanf("%d", &q); while(q--){ int cnt = 0, ok = 1; scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", &a[i]); for(int i = 0; i < n - 1; i++){ if(abs(a[i] - a[i + 1]) != 1) cnt++; } if(abs(a[n - 1] - a[0]) != 1) cnt++; if(cnt >= 2) ok = 0; if(ok) printf("YES\n"); else printf("NO\n"); } }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
a09cbe6663d92d9078e8a92065e22320
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include<stdio.h> int main(void){ int T; scanf("%d",&T); while(T--){ int n,no1=0,no2=0,out=0; int i,a[250]; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&a[i]); if(n>2){ for(i=1;i<=n-1;i++){ if(a[i]!=a[i+1]+1){ no1++; } if(a[i]!=a[i+1]-1){ /*no2 no1*/ no2++; /*54321876*/ /*81234567*/ } } if(a[1]!=a[n]-1){ no1++; } // 判断首尾 if(a[1]!=a[n]+1){ no2++; } if(no1<2||no2<2) out++; } if(n==1||(n==2&&(a[1]==a[2]+1||a[1]==a[2]-1))||out!=0) printf("YES\n"); else printf("NO\n"); } return 0; }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
487b00f96666d183572fecf31124f79b
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include<stdio.h> int query[205]; int main() { int T; scanf("%d", &T); while (T--) { int num; scanf("%d", &num); int fst,up=0,down=0; scanf("%d", &query[1]); for (int i = 2; i <= num; i++) { scanf("%d", &query[i]); if (query[i] - query[i - 1] > 0) up++; else down++; } if (query[1] - query[num] > 0) up++; else down++; if (num <= 2) puts("YES"); else if (up == 1 || down == 1) puts("YES"); else puts("NO"); } }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
24070494961b1e1656ba86d0165a1907
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include<stdio.h> int main() { int i , q , n; scanf("%d",&q); while(q>0) { int flag = 0 ; scanf("%d",&n); int arr[n]; for(i=1;i<=n;i++) { scanf("%d",&arr[i]); } for(i=1;i<=n-1;i++) { if( (arr[i+1]==arr[i]+1) || (arr[i+1]+1==arr[i]) ) { continue; } else { flag ++; // printf("%d\n",flag); } } if(flag!=0) { if(arr[n]-1 == arr[1]) flag--; else if(arr[n]==arr[1]-1) flag--; } if(flag==0)printf("YES\n"); else printf("NO\n"); q--; } return 0; }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
5844cd7df660308a3161b127e531e276
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include<stdio.h> #include<math.h> int main() { int n, a[202]; int i=0,j=0,flag=0; int t=0,temp=0,m; scanf("%d",&m); for(j=0;j<m;j++){ scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); flag=0; i=0; temp=0; while(flag<n) { t=i+1; if( t>=n) {//i=i%n; t=t%n; } if(abs(a[i]-a[t])!=1) { temp++; } i++; flag++; } if(temp<=1) printf("YES\n"); else printf("NO\n"); } return 0; }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
8e8ba3f4597d851021d37311c7ae9b55
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include <stdio.h> int main() { int n; scanf("%d",&n); while(n--){ int i,p, c =0, cc =0; scanf("%d",&p); int a[p]; for(i =0; i < p; i++) scanf("%d",&a[i]); for(i =0; i< p-1; i++){ if(a[i] == a[i+1] + 1) c++; else if(a[i+1] == a[i]+1) cc++; } if(c >= p-2 || cc >= p-2) printf("YES\n"); else printf("NO\n"); } return 0; }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
b55f3903b2380eb96ea0042f3fbad471
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include<stdio.h> int main() { int t,i,n,k,j=1,l=1,z=0; scanf("%d",&t); for(i=0;i<t;i++) { scanf("%d",&n); int A[n]; for(k=0;k<n;k++) { scanf("%d",&A[k]); if(A[k]-A[k-1]==1&&j==1) { j=1; l=0; } else if(A[k-1]-A[k]==1&&l==1) { l=1; j=0; } else if(A[k]==n&&l==1) { continue; } else if(A[k]==1&&j==1) { continue; } else if(k==0) { continue; } else { z=1; } } if(z==1) { printf("NO\n"); } else { printf("YES\n"); } j=1; l=1; z=0; } return 0; }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
817900c3884eb85b9bb9497161215dbb
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
#include <stdio.h> int main(void) { int q; //printf("Enter the number of queries " ); scanf("%d",&q); int i,j; int n,flag=0; for(i=0;i<q;i++) { flag=0; // printf("Enter the number of students"); scanf("%d",&n); int p[n]; //printf("Enter the index of the students"); for(j=0; j<n; j++) { scanf("%d",&p[j]); } if(n==1) { printf("YES\n"); continue; } for(j=1;j<n;j++) { if(((p[j] - p[j-1]) == 1) || ((p[j]-p[j-1]) == n-1) || ((p[j] - p[j-1]) == 1-n)) { flag=1; } else if(((p[j]-p[j-1]) == n-1) || ((p[j] - p[j-1]) == 1-n) || (( p[j] - p[j-1])==-1)) { flag=1; } else { flag=0; break; } } if(flag==1) printf("YES\n"); else printf("NO\n"); } return 0; }
There are $$$n$$$ students standing in a circle in some order. The index of the $$$i$$$-th student is $$$p_i$$$. It is guaranteed that all indices of students are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).Students want to start a round dance. A clockwise round dance can be started if the student $$$2$$$ comes right after the student $$$1$$$ in clockwise order (there are no students between them), the student $$$3$$$ comes right after the student $$$2$$$ in clockwise order, and so on, and the student $$$n$$$ comes right after the student $$$n - 1$$$ in clockwise order. A counterclockwise round dance is almost the same thing — the only difference is that the student $$$i$$$ should be right after the student $$$i - 1$$$ in counterclockwise order (this condition should be met for every $$$i$$$ from $$$2$$$ to $$$n$$$). For example, if the indices of students listed in clockwise order are $$$[2, 3, 4, 5, 1]$$$, then they can start a clockwise round dance. If the students have indices $$$[3, 2, 1, 4]$$$ in clockwise order, then they can start a counterclockwise round dance.Your task is to determine whether it is possible to start a round dance. Note that the students cannot change their positions before starting the dance; they cannot swap or leave the circle, and no other student can enter the circle. You have to answer $$$q$$$ independent queries.
For each query, print the answer on it. If a round dance can be started with the given order of students, print "YES". Otherwise print "NO".
C
b27436086ead93397be748d8ebdbf19a
3380229617cb147e4165b01d3b9fd57b
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1565706900
["5\n4\n1 2 3 4\n3\n1 3 2\n5\n1 2 3 5 4\n1\n1\n5\n3 2 1 5 4"]
null
PASSED
1,000
standard input
2 seconds
The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of students. The second line of the query contains a permutation of indices $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$), where $$$p_i$$$ is the index of the $$$i$$$-th student (in clockwise order). It is guaranteed that all $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i. e. they form a permutation).
["YES\nYES\nNO\nYES\nYES"]
/// IMTMTO... #include<stdio.h> #include<stdlib.h> void test() { int n; scanf("%d",&n); int a[n],i; for(i=0;i<n;i++){ scanf("%d",&a[i]); } for(i=1;i<n;i++){ if(abs(a[i]-a[i-1])!=1 && abs(a[i]-a[i-1])!=n-1){ printf("NO\n"); return; } } if(abs(a[0]-a[n-1])==1 || abs(a[0]-a[n-1])==n-1){ printf("YES\n"); } else printf("NO\n"); } int main() { int t; scanf("%d",&t); while(t--) test(); }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
771b062c62781698a3a6cf5d63311bfa
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include <stdio.h> #include <string.h> char s[110][110]; int a[110]; int main() { int n,m,c=0; memset(a,0,sizeof(a)); scanf("%d%d",&n,&m); int i,j,k,l; for(i=0;i<n;i++) { scanf(" %s",s[i]); } for(i=0;i<m;i++) { for(j=0;j<n-1;j++) { if(s[j][i]>s[j+1][i]) { if(i==0) { c++; a[i]=1; break; } else { l=0; for(k=0;k<i;k++) { if(a[k]==0&&s[j][k]<s[j+1][k]) { l=1; break; } } if(l==0) { c++; a[i]=1; break; } } } } } printf("%d\n",c); return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
eb6cdebdd72791d6f86540e01d1c8217
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include<stdio.h> #include<string.h> int main() { char a[105][105]; int i,j,k,l,n,m,vis[101],count=0; scanf("%d%d",&n,&m); for(i=0;i<n;i++) { scanf("%s",&a[i]); } for(i=0;i<101;i++) vis[i]=0; for(i=0;i<m;i++) { for(j=1;j<n;j++) { if(!vis[j]) { if(a[j-1][i]<=a[j][i]) { //vis[j]=1; continue; } /*else if(a[j-1][i]==a[j][i]) { continue; }*/ else { count++; break; } } } if(j==n) { for(j=1;j<n;j++) { if(a[j-1][i]<a[j][i]) { vis[j]=1; } } } } printf("%d\n",count); return(0); }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
fc698e15f547a38a05feb22eef3411f4
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include <stdio.h> char Valid[100]; int main() { char Map[100][101]; int N, M, i, j, Ans; scanf("%d %d", &N, &M); for(i = 0; i < N; ++i) { scanf("%s", Map[i]); } for(Ans = j = 0; j < M; ++j) { int flag = 0; for(i = 0; i < N - 1; ++i) { if(Map[i][j] > Map[i + 1][j] && !Valid[i]) { flag = 1; break; } } Ans += flag; if(!flag) { for(i = 0; i < N - 1; ++i) { if(Map[i][j] < Map[i + 1][j]) { Valid[i] = 1; } } } } printf("%d\n", Ans); return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
c4a85d93656edad4d20496b1fcabdbab
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
/* * 1.这个程序做到的事情 * 2.这个程序遇到的困难 * 3.接下来要做的事情 */ #include<stdio.h> #define N 102 int main() { int n,m; scanf("%d%d",&n,&m); char table[N][N]; int i,j; for(i=0;i<n;i++){ scanf("%s",table[i]); } int delete=0; int check[N]; int tmp_check[N]; for(i=0;i<n;i++){ check[i]=1; } for(i=0;i<m;i++){ int is_order=1; for(j=1;j<n;j++){ tmp_check[j]=check[j]; } /* for(j=1;j<n;j++){ printf(" %d",check[j]); } printf("\n"); for(j=0;j<n;j++){ printf("%c",table[j][i]); } printf("\n"); */ for(j=1;j<n;j++){ if(check[j]==1){ if(table[j-1][i]>table[j][i]){ is_order=0; }else if(table[j-1][i]<table[j][i]){ check[j]=0; }else{ check[j]=1; } } if(!is_order){ //当前行必须删除 delete++; //我们需要原先的数据 for(j=1;j<n;j++){ check[j]=tmp_check[j]; } } } /* for(j=1;j<n;j++){ printf(" %d",check[j]); } printf("\n"); */ } printf("%d\n",delete); return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
6e4e20d7ef5760d5b7dc3198f6a30cac
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
/*************** * problem496C.c **************/ /******************************************************************************* * MAC0327 -- Aula01 -- 2015.08.03 -- IME/USP -- Prof. Cris * Aluno: Marcello Souza de Oliveira * Numero USP: 6432692 * Curso: Bacharelado em Ciencias da Computacao * Compilador: gcc linux 4.6.3 * Opcoes compilacao: -Wall -ansi -pedantic -O2 -U_FORTIFY_SOURCE * Compilar: * gcc -Wall -ansi -pedantic -O2 -U_FORTIFY_SOURCE \ * -o pXX pXX.cpp * Compilar (debug): gcc -D MSGDBG -o pXX pXX.cpp * Executar: ./pXX <<< "" ******************************************************************************/ /******************************************************************************* * Referencias: * [1] http://codeforces.com/problemset/problem/496/C * [2] http://a2oj.com/Contest.jsp?ID=19584 * [3] http://www.ime.usp.br/~cris/desafios/ ******************************************************************************/ #include <stdio.h> #include <stdlib.h> /* To debug */ /*#define MSGDBG*/ #ifdef MSGDBG #define MSG_DBG( fmt, ...) \ fprintf( stderr, "\t>>> MSG_DBG [%s:%d:%s]: " \ fmt"\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__) #else #define MSG_DBG( fmt, ...) {;} #endif int main() { int i, j, cnt, n, m; char **t, c, c2; scanf( " %d %d", &n, &m); t = (char **) malloc( n * sizeof (char *)); for (i = 0; i < n; i++) { t[i] = (char *) malloc( m * sizeof (char)); for (j = 0; j < m; j++) { scanf( " %c", &t[i][j]); MSG_DBG( "%c", t[i][j]); } MSG_DBG( "\n"); } for (cnt = 0, i = 1; i < n; i++) { for (j = 0; j < m; j++) { /* se a coluna nao foi removida */ if (t[0][j] != '\0') { MSG_DBG( "%c %c", t[i][j], t[i - 1][j]); if (t[i][j] < t[i - 1][j]) { t[0][j] = '\0'; /* removo a coluna */ cnt++; MSG_DBG( "%d\n", j); j = m; i = 0; } else if (t[i][j] > t[i - 1][j]) { j = m; /* ja sei que e menor, paro a comparacao dessa linha */ } MSG_DBG( "\n"); } } } printf( "%d\n", cnt); /* libero a memoria */ for (i = 0; i < n; i++) { free (t[i]); } free (t); return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
b61f9553cc27104739e80d8f109ff14f
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
/*************** * problem496C.c **************/ /******************************************************************************* * MAC0327 -- Aula01 -- 2015.08.03 -- IME/USP -- Prof. Cris * Aluno: Marcello Souza de Oliveira * Numero USP: 6432692 * Curso: Bacharelado em Ciencias da Computacao * Compilador: gcc linux 4.6.3 * Opcoes compilacao: -Wall -ansi -pedantic -O2 -U_FORTIFY_SOURCE * Compilar: gcc -o problem496C problem496C.c * Compilar (debug): gcc -D MSGDBG -o problem496C problem496C.c * Executar: ./problem496C <<< "2 3 abc def" ******************************************************************************/ /******************************************************************************* * Referencias: * [1] http://codeforces.com/problemset/problem/496/C * [2] http://a2oj.com/Contest.jsp?ID=19584 * [3] http://www.ime.usp.br/~cris/desafios/ ******************************************************************************/ #include <stdio.h> #include <stdlib.h> /* To debug */ /*#define MSGDBG*/ #ifdef MSGDBG #define MSG_DBG( fmt, ...) \ fprintf( stderr, "\t>>> MSG_DBG [%s:%d:%s]: " \ fmt"\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__) #else #define MSG_DBG( fmt, ...) {;} #endif int main() { int i, j, cnt, n, m; char **t, c, c2; scanf( " %d %d", &n, &m); t = (char **) malloc( n * sizeof (char *)); for (i = 0; i < n; i++) { t[i] = (char *) malloc( m * sizeof (char)); for (j = 0; j < m; j++) { scanf( " %c", &t[i][j]); MSG_DBG( "%c", t[i][j]); } MSG_DBG( "\n"); } for (cnt = 0, i = 1; i < n; i++) { for (j = 0; j < m; j++) { /* se a coluna nao foi removida */ if (t[0][j] != '\0') { MSG_DBG( "%c %c", t[i][j], t[i - 1][j]); if (t[i][j] < t[i - 1][j]) { t[0][j] = '\0'; /* removo a coluna */ cnt++; MSG_DBG( "%d\n", j); j = m; i = 0; } else if (t[i][j] > t[i - 1][j]) { j = m; /* ja sei que e menor, paro a comparacao dessa linha */ } MSG_DBG( "\n"); } } } printf( "%d\n", cnt); /* libero a memoria */ for (i = 0; i < n; i++) { free (t[i]); } free (t); return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
b27eb3a1b36edd57ca9743919b8229e8
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
/*************** * problem496C.c **************/ /******************************************************************************* * MAC0327 -- Aula01 -- 2015.08.03 -- IME/USP -- Prof. Cris * Aluno: Marcello Souza de Oliveira * Numero USP: 6432692 * Curso: Bacharelado em Ciencias da Computacao * Compilador: gcc linux 4.6.3 * Opcoes compilacao: -Wall -ansi -pedantic -O2 -U_FORTIFY_SOURCE * Compilar: gcc -o problem496C problem496C.c * Compilar (debug): gcc -D MSGDBG -o problem496C problem496C.c * Executar: ./problem496C <<< "2 3 abc def" ******************************************************************************/ /******************************************************************************* * Referencias: * [1] http://codeforces.com/problemset/problem/496/C * [2] http://a2oj.com/Contest.jsp?ID=19584 * [3] http://www.ime.usp.br/~cris/desafios/ ******************************************************************************/ #include <stdio.h> #include <stdlib.h> /* To debug */ /*#define MSGDBG*/ #ifdef MSGDBG #define MSG_DBG( fmt, ...) \ fprintf( stderr, "\t>>> MSG_DBG [%s:%d:%s]: " \ fmt"\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__) #else #define MSG_DBG( fmt, ...) {;} #endif int main() { int i, j, cnt, n, m; char **t, c, c2; scanf( " %d %d", &n, &m); t = (char **) malloc( n * sizeof (char *)); for (i = 0; i < n; i++) { t[i] = (char *) malloc( m * sizeof (char)); for (j = 0; j < m; j++) { scanf( " %c", &t[i][j]); MSG_DBG( "%c", t[i][j]); } MSG_DBG( "\n"); } for (cnt = 0, i = 1; i < n; i++) { for (j = 0; j < m; j++) { /* se a coluna nao foi removida */ if (t[0][j] != '\0') { MSG_DBG( "%c %c", t[i][j], t[i - 1][j]); if (t[i][j] < t[i - 1][j]) { t[0][j] = '\0'; /* removo a coluna */ cnt++; MSG_DBG( "%d\n", j); j = m; i = 0; } else if (t[i][j] > t[i - 1][j]) { j = m; /* ja sei que e menor, paro a comparacao dessa linha */ } MSG_DBG( "\n"); } } } printf( "%d\n", cnt); /* libero a memoria */ for (i = 0; i < n; i++) { free (t[i]); } free (t); return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
d38a82e4526a4548e744b36f15bf374b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include <stdio.h> char str[1001][1001]; unsigned bigger[1000]; int main() { int n, m, i, j, res, flag, k; scanf("%d %d", &n, &m); getchar(); for (i = 0; i < n; ++i) gets(str[i]); res = 0; for (j = 0; j < m; ++j) { flag = 1; for (i = 0; i < n - 1; ++i) { if (bigger[i])//前面的字母较大,直接标记为大,保留之前标志,然后末位置1 { bigger[i] <<= 1; bigger[i] |= 1; continue; } if (str[i + 1][j] < str[i][j])//当前列字母倒序,错误 { ++res; flag = 0; for (k = 0; k<i; ++k)//撤销当前列之前的标志 bigger[k] >>= 1; break; } else if (str[i + 1][j] > str[i][j])//当前列字母正序,末位置1 { bigger[i] <<= 1; bigger[i] |= 1; } else//末位依然为0 flag = 0; } if (flag) break; } printf("%d\n", res); return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
071e3874431ca872d5552887a202aa59
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include <stdio.h> char str[1001][1001]; int state[1000]; unsigned bigger[1000]; int main() { int n, m, i, j, res, flag, k; scanf("%d %d", &n, &m); getchar(); for (i = 0; i < n; ++i) gets(str[i]); for (j = 0; j < m; ++j) { if (state[j]) continue; flag = 1; for (i = 0; i < n - 1; ++i) { if (bigger[i])//前面的字母较大,直接标记为大,保留之前标志,然后末位置1 { bigger[i] <<= 1; bigger[i] |= 1; continue; } if (str[i + 1][j] < str[i][j])//当前列字母倒序,错误 { state[j] = 1; flag = 0; for (k = 0; k<i; ++k)//撤销当前列之前的标志 bigger[k] >>= 1; break; } else if (str[i + 1][j] > str[i][j])//当前列字母正序,末位置1 { bigger[i] <<= 1; bigger[i] |= 1; } else//末位依然为0 flag = 0; } if (flag) break; } res = 0; for (j = 0; j < m; ++j) res += state[j]; printf("%d\n", res); return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
4c95fa89073c924a3e72b60296042293
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include <stdio.h> int main(){ int n,m,i,j,count; scanf("%d%d",&n,&m); char c[100][101]; int ci[100]; for(i=0;i<100;i++){ ci[i]=0; } for(i=0;i<n;i++){ scanf("%s",c[i]); } count = 0; for(i=0;i<n-1;i++){ for(j=0;j<m;j++){ if(ci[j]==1) {//already removed continue; } if(c[i+1][j]>c[i][j]){ break; }else if(c[i+1][j]<c[i][j]){ ci[j]=1;//remove column i=-1; break; } } } count = 0; for(i=0;i<100;i++){ count += ci[i]; } printf("%d",count); }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
243f8358bc333212e27abb56932ad561
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include <stdio.h> int main(void) { // your code goes here int n,m,i,j, flag, count=0; char s[101][101]; int visited[101]={0}; scanf("%d%d",&n,&m); for(i=0; i<n; i++) { scanf("%s", s[i]); } for(i=0; i<n-1; i++) { flag=0; for(j=0; j<m; j++) { if(!visited[j] && s[i][j]<s[i+1][j]) break; else if(!visited[j] && s[i][j]>s[i+1][j]) { count++; flag=1; visited[j]=1; break; } } if(flag==1){ i=-1; } } printf("%d", count); return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
325d5251e36efcfcdcd7aa2e63822485
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include<stdio.h> char a[100][100]; int x[100],y[100];//x to store removed j //y to store lexi .. smaller int main() { int n,m,i,j,c,q=0,flag; scanf("%d %d",&n,&m); c=getchar(); for(i=0;i<n;i++) { for(j=0;j<m;j++) { scanf("%c",&a[i][j]); } c=getchar(); } for(j=0;j<m;j++) { for(i=0;i<n-1;i++) { if(x[j]!=1) { //printf("za\n"); if(a[i][j]<a[i+1][j]) { //printf("a\n"); if(y[i]==0) y[i]=j+1; else if(x[y[i]-1]==1) y[i]=j+1; } else if(a[i][j]>a[i+1][j]) { //printf("b\n"); if(y[i]>0) { if(x[y[i]-1]==1) { x[j]=1; // printf("%d ",j); break; } } else { x[j]=1; // printf("%d ",j); break; } } } } } for(i=0;i<m;i++) { if(x[i]==1) q++; } printf("%d\n",q); return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
3b5dec617beeddecf54b6524f2be9593
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include<stdio.h> #include<string.h> int main() { char arr[101][101]; int n,m,i,j,k,s=0; scanf("%d %d",&n,&m); for(i=0;i<n;i++) scanf("%s",arr[i]); for(i=1;i<n;) { if(strcmp(arr[i],arr[i-1]) < 0) { for(j=0; j<m; j++) if(arr[i][j]<arr[i-1][j]) break; for(k=0; k<n; k++) arr[k][j]='d'; s++; i=1; } else i++; } printf("%d\n",s); return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
72404ff0a6d3f5b4904c4acf8154e6b0
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <assert.h> #include <limits.h> #include <stdbool.h> int main(void) { int n,m; scanf("%d %d",&n,&m); char str[n][m+1]; int isSmall[n-1]; int i; for(i=0;i<n-1;i++){ isSmall[i] = 0; } for(i=0;i<n;i++){ scanf("%s",str[i]); } int cnt = 0; //int prev = -1; for(i=0;i<m;i++){ int j; int flag = 0; for(j=1;j<n;j++){ if(isSmall[j-1]==0){ if(str[j][i] < str[j-1][i]){ flag = 1; break; } } } if(flag) cnt++; else{ //prev = i; for(j=0;j<n-1;j++){ if(str[j][i] < str[j+1][i]) isSmall[j]=1; } } } printf("%d",cnt); return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
15e242d377e1cf4ee3fb751d2daf0e14
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include<stdio.h> #include<string.h> #include<stdlib.h> #define M 111 char s[M][M]; int flag[M],now[M]; int main() { int n,m,i,j; while((scanf("%d%d",&n,&m))!=EOF){ for(i=0;i<n;i++) { scanf("%s",s[i]); } memset(now,0,sizeof(now)); int cont= 0; for(i=0;i<m;i++) { memset(flag,0,sizeof(flag)); int ok = 1; for(j=0;j<n-1&&ok;j++) { if(now[j]) continue; if(s[j][i] > s[j+1][i]) { cont++; ok=0; break; } else if(s[j][i] < s[j+1][i]) { flag[j]=1; } } if(ok) for(j=0;j<n;j++) { if(flag[j]) now[j]=1; } } printf("%d\n",cont); } return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
2559889d95c578129c7630d6bc1c651d
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include<stdio.h> #include<string.h> #define N 1010 char s[N][N], a[N]; int del[N]; int main() { int n, m, i, j, ans = 0; scanf("%d%d",&n, &m); memset(del, 0, sizeof(del)); for(i = 0; i < n; i++) { scanf("%s",a); for(j = 0; j < m; j++) s[j][i] = a[j]; } for(i = 0; i < m; i++) { int flag = 0; for(j = 1; j < n; j++) if(!del[j] && s[i][j] < s[i][j - 1]) { flag = 1; break; } if(flag) ans++; else { for(j = 1;j < n; j++) if(s[i][j] != s[i][j - 1]) del[j] = 1; } } printf("%d\n", ans); return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
23a4a3fd3fff059d37883a7c02d234a4
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include <stdio.h> #include <string.h> int main() { int flag; int i, j; int n, m; int ans = 0; int mark[105]; char str[105][105]; memset(mark, 0, sizeof(mark)); scanf("%d%d", &n, &m); for ( i = 0; i < n; i++ ) scanf("%s", str[i]); for ( i = 0; i < m; i++ ) { flag = 0; for ( j = 0; j < n-1; j++ ) { if ( mark[j] ) continue; else if ( str[j][i] > str[j+1][i] ) { ans += 1; flag = 1; break; } } if ( !flag ) { for ( j = 0; j < n-1; j++ ) if ( str[j][i] < str[j+1][i] ) mark[j] = 1; } } printf("%d\n", ans); return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
3d5fe26f71fef56dadd639dd16e20fed
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include<stdio.h> int main() { int n,m,b[110],l=0,j,z=0,k,i; char a[110][110]; scanf("%d%d",&n,&m); for(i=1;i<=n;i++) scanf("%s",a[i]); do { z=l; for(i=1;i<n;i++) { for(j=0;j<m;j++) { for(k=0;k<l;k++) if(j==b[k]) break; if(k==l) { if(a[i][j]>a[i+1][j]) b[l++]=j; else if(a[i][j]<a[i+1][j]) break; } } } }while(l!=z); printf("%d\n",l); return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
3e586777532d5c3da584bd6069d79097
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include<stdio.h> int n,m,i,j,ans,tmp,flag[1000]; char s[1000][1000]; int main() { scanf("%d%d",&n,&m); for (i=1;i<=n;i++) scanf("%s",&s[i]); for (j=0;j<m;j++) { tmp=0; for (i=1;i<=n-1;i++) if ((s[i][j]>s[i+1][j])&&(flag[i]==0)) tmp=1; ans=ans+tmp; if (tmp==0) for (i=1;i<=n-1;i++) if ((s[i][j]<s[i+1][j])&&(flag[i]==0)) flag[i]=1; } printf("%d",ans); }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
42eb73e79a4509b2b67180666a358109
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include<stdio.h> #include<string.h> #include<stdlib.h> int main (){ int n,m,i,j,i1,b[110]={0},count=0,flag=0; char a[110][110]; scanf("%d%d",&n,&m); for(i1=1;i1<=n;i1++) scanf("%s",a[i1]); int i5=0; while(i5<m) { flag=0; for(i=1;i<n;i++) { for(j=0;j<m;j++) { /// printf("%d %d ",i,j+1); printf("%c %c \n",a[i][j],a[i+1][j]); if(b[j]!=1) { if(a[i][j] > a[i+1][j]) { b[j]=1; count++; flag=1; break; } if(a[i][j] < a[i+1][j]) break; } } if(flag==1) break; } i5++; } printf("%d\n",count); return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
d6946609adefeecd0c9a45e35217c1c2
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
/* Problem: 496C - Removing Columns */ /* Solver: Gusztav Szmolik */ #include <stdio.h> #include <string.h> #include <ctype.h> int main () { unsigned short n; unsigned short m; unsigned short i; unsigned char s[102]; unsigned short j; unsigned char t[100][100]; unsigned short rc[100]; unsigned short fgc; unsigned short cwc; unsigned char cx; unsigned short r; unsigned short k; unsigned short l; if (scanf("%hu %hu",&n,&m) != 2) return -1; if (n < 1 || n > 100 || m < 1 || m > 100) return -1; for (i = 0; i < n; i++) { if (scanf("%101s",s) != 1) return -1; if (strlen(s) != m) return -1; for (j = 0; j < m; j++) { if (!islower(s[j])) return -1; t[i][j] = s[j]; } } for (i = 0; i < m; i++) rc[i] = 0; fgc = 100; cwc = 0; for (i = 0; i < m; i++) { cx = 'a'; r = 0; for (j = 0; j < n && !r; j++) { if (t[j][i] > cx) cx = t[j][i]; else if (t[j][i] < cx) { if (fgc == 100) { rc[i] = 1; cwc++; r = 1; break; } else { r = 0; for (k = 0; k < j && !r; k++) if (t[j][i] < t[k][i]) { r = 1; for (l = fgc; l < i && r; l++) if (!rc[l] && t[j][l] != t[k][l]) r = 0; if (r) { rc[i] = 1; cwc++; } } } } } if (!r && fgc == 100) fgc = i; } printf ("%hu\n",cwc); return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
a6c117fbf578ff05c18f4f1cea484dfc
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include <stdio.h> #include <string.h> int main() { int n,m; char mat[105][105]; scanf("%d %d",&n,&m); for(int i =0 ;i<n;i++) scanf("%s",mat[i]); int cnt = 0; int del[105] = {0}; int les[105] = {0}; for(int i = 0; i < m; i ++ ) { int flag = 0; for(int j = 1; j<n;j++) { if(les[j] == 0 && mat[j][i] < mat[j-1][i]) { //printf("%d %d\n",j,i ); del[i] =1; flag = 1; break; } } if(flag) cnt++; else { for(int j = 1;j < n;j++) if(mat[j-1][i] < mat[j][i]) les[j] = 1; } } /*for(int i = 0; i < n;i++) printf("%d\n",les[i]);*/ /*for(int i = 0;i<m;i++) printf("%d ",del[i]);*/ printf("%d\n",cnt); return 0; }
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.
Print a single number — the minimum number of columns that you need to remove in order to make the table good.
C
a45cfc2855f82f162133930d9834a9f0
a1bdd5c2dab8703f3c098948dd49cb4b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "brute force" ]
1418833800
["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"]
NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
PASSED
1,500
standard input
2 seconds
The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.
["0", "2", "4"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int nColumns, nRows, i, j, k, m, count, aux; scanf("%d %d", &nRows, &nColumns); char** rows = malloc(nRows*sizeof(char*)); for(i = 0; i < nRows; i++) { rows[i] = malloc(nColumns*sizeof(char)); } for(i = 0; i < nRows; i++) { scanf("%s", rows[i]); } count = 0; for(i = 0; i < nColumns; i++) { aux = count; for(j = 0; j < (nRows - 1); j++) { if(strncmp(&rows[j][i], &rows[j+1][i], 1) > 0) { count++; for(m = 0; m < nRows; m++) { rows[m][i] = 'a'; } break; } } if(count == aux) break; } for(j = 0; j < (nRows - 1); j++) { if(strncmp(&rows[j][i], &rows[j+1][i], 1) == 0) { for(k = i+1; k < nColumns; k++) { if(strncmp(&rows[j][k], &rows[j+1][k], 1) > 0) { count++; for(m = 0; m < nRows; m++) { rows[m][k] = 'a'; } j = -1; break; } else if (strncmp(&rows[j][k], &rows[j+1][k], 1) < 0) { break; } } } } printf("%d", count); }