prob_desc_description
stringlengths
63
3.8k
prob_desc_output_spec
stringlengths
17
1.47k
lang_cluster
stringclasses
2 values
src_uid
stringlengths
32
32
code_uid
stringlengths
32
32
lang
stringclasses
7 values
prob_desc_output_to
stringclasses
3 values
prob_desc_memory_limit
stringclasses
19 values
file_name
stringclasses
111 values
tags
listlengths
0
11
prob_desc_created_at
stringlengths
10
10
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_notes
stringlengths
4
3k
exec_outcome
stringclasses
1 value
difficulty
int64
-1
3.5k
prob_desc_input_from
stringclasses
3 values
prob_desc_time_limit
stringclasses
27 values
prob_desc_input_spec
stringlengths
28
2.42k
prob_desc_sample_outputs
stringlengths
2
796
source_code
stringlengths
42
65.5k
hidden_unit_tests
stringclasses
1 value
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You want to split it into exactly $$$k$$$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i. e. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the $$$n$$$ elements of the array $$$a$$$ must belong to exactly one of the $$$k$$$ subsegments.Let's see some examples of dividing the array of length $$$5$$$ into $$$3$$$ subsegments (not necessarily with odd sums): $$$[1, 2, 3, 4, 5]$$$ is the initial array, then all possible ways to divide it into $$$3$$$ non-empty non-intersecting subsegments are described below: $$$[1], [2], [3, 4, 5]$$$; $$$[1], [2, 3], [4, 5]$$$; $$$[1], [2, 3, 4], [5]$$$; $$$[1, 2], [3], [4, 5]$$$; $$$[1, 2], [3, 4], [5]$$$; $$$[1, 2, 3], [4], [5]$$$. Of course, it can be impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.You have to answer $$$q$$$ independent queries.
For each query, print the answer to it. If it is impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as $$$k$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_k$$$ such that $$$1 \le r_1 < r_2 < \dots < r_k = n$$$, where $$$r_j$$$ is the right border of the $$$j$$$-th segment (the index of the last element that belongs to the $$$j$$$-th segment), so the array is divided into subsegments $$$[1; r_1], [r_1 + 1; r_2], [r_2 + 1, r_3], \dots, [r_{k - 1} + 1, n]$$$. Note that $$$r_k$$$ is always $$$n$$$ but you should print it anyway.
C
7f5269f3357827b9d8682d70befd3de1
8d75c67aba11115071aef59cd2ba1ba3
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "math" ]
1563978900
["3\n5 3\n7 18 3 14 1\n5 4\n1 2 3 4 5\n6 2\n1 2 8 4 10 2"]
null
PASSED
1,200
standard input
3 seconds
The first line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) — the number of elements in the array and the number of subsegments, respectively. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["YES\n1 3 5\nNO\nNO"]
#include<stdio.h> int main() { long int T,n,i,j,k,l,Sum=0,c; scanf("%ld",&T); for(i=0;i<T;i++) { c=0; scanf("%ld",&n); scanf("%ld",&k); long int ar[n]; long int br[n]; for(j=0;j<n;j++) { scanf("%ld",&ar[j]); if(c==k-1) { Sum=Sum+ar[j]; continue; } Sum=Sum+ar[j]; if(Sum%2!=0) { br[c]=j; c++; Sum=0; } } if(Sum%2!=0) { br[c]=n-1; c++; Sum=0; } if(c==k) { printf("YES\n"); for(j=0;j<c;j++) { printf("%ld ",br[j]+1); } } else printf("NO\n"); } }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You want to split it into exactly $$$k$$$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i. e. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the $$$n$$$ elements of the array $$$a$$$ must belong to exactly one of the $$$k$$$ subsegments.Let's see some examples of dividing the array of length $$$5$$$ into $$$3$$$ subsegments (not necessarily with odd sums): $$$[1, 2, 3, 4, 5]$$$ is the initial array, then all possible ways to divide it into $$$3$$$ non-empty non-intersecting subsegments are described below: $$$[1], [2], [3, 4, 5]$$$; $$$[1], [2, 3], [4, 5]$$$; $$$[1], [2, 3, 4], [5]$$$; $$$[1, 2], [3], [4, 5]$$$; $$$[1, 2], [3, 4], [5]$$$; $$$[1, 2, 3], [4], [5]$$$. Of course, it can be impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.You have to answer $$$q$$$ independent queries.
For each query, print the answer to it. If it is impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as $$$k$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_k$$$ such that $$$1 \le r_1 &lt; r_2 &lt; \dots &lt; r_k = n$$$, where $$$r_j$$$ is the right border of the $$$j$$$-th segment (the index of the last element that belongs to the $$$j$$$-th segment), so the array is divided into subsegments $$$[1; r_1], [r_1 + 1; r_2], [r_2 + 1, r_3], \dots, [r_{k - 1} + 1, n]$$$. Note that $$$r_k$$$ is always $$$n$$$ but you should print it anyway.
C
7f5269f3357827b9d8682d70befd3de1
63bdff0eb5b118a8adcdadd6a9c2126f
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "math" ]
1563978900
["3\n5 3\n7 18 3 14 1\n5 4\n1 2 3 4 5\n6 2\n1 2 8 4 10 2"]
null
PASSED
1,200
standard input
3 seconds
The first line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) — the number of elements in the array and the number of subsegments, respectively. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["YES\n1 3 5\nNO\nNO"]
#include <stdio.h> typedef long long ll; #define max(l,r) ((l)>(r)?l:r) #define min(l,r) ((l)<(r)?l:r) #define swap(l,r) {ll tp=l;l=r;r=tp;} #define rep(i,n) for(int i=0;i<(int)(n);i++) int n,t,k; int a[202020]; int solve(){ int ans = 0; int odd = 0; rep(i,n) if(a[i]%2) odd++; if((odd%2) != (k%2) || odd < k) ans = 0; else ans = 1; return ans; } int main(){ scanf("%d", &t); rep(tes,t){ scanf("%d", &n); scanf("%d", &k); rep(i,n) scanf("%d", a+i); if(solve()){ puts("YES"); rep(j,n){ if(k <= 1) break; if(a[j]%2) { printf("%d ",j+1); k--; } } printf("%d\n",n); }else puts("NO"); } }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You want to split it into exactly $$$k$$$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i. e. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the $$$n$$$ elements of the array $$$a$$$ must belong to exactly one of the $$$k$$$ subsegments.Let's see some examples of dividing the array of length $$$5$$$ into $$$3$$$ subsegments (not necessarily with odd sums): $$$[1, 2, 3, 4, 5]$$$ is the initial array, then all possible ways to divide it into $$$3$$$ non-empty non-intersecting subsegments are described below: $$$[1], [2], [3, 4, 5]$$$; $$$[1], [2, 3], [4, 5]$$$; $$$[1], [2, 3, 4], [5]$$$; $$$[1, 2], [3], [4, 5]$$$; $$$[1, 2], [3, 4], [5]$$$; $$$[1, 2, 3], [4], [5]$$$. Of course, it can be impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.You have to answer $$$q$$$ independent queries.
For each query, print the answer to it. If it is impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as $$$k$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_k$$$ such that $$$1 \le r_1 &lt; r_2 &lt; \dots &lt; r_k = n$$$, where $$$r_j$$$ is the right border of the $$$j$$$-th segment (the index of the last element that belongs to the $$$j$$$-th segment), so the array is divided into subsegments $$$[1; r_1], [r_1 + 1; r_2], [r_2 + 1, r_3], \dots, [r_{k - 1} + 1, n]$$$. Note that $$$r_k$$$ is always $$$n$$$ but you should print it anyway.
C
7f5269f3357827b9d8682d70befd3de1
843abaa52c7a5aa3e5b14b5b4b8182d9
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "math" ]
1563978900
["3\n5 3\n7 18 3 14 1\n5 4\n1 2 3 4 5\n6 2\n1 2 8 4 10 2"]
null
PASSED
1,200
standard input
3 seconds
The first line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) — the number of elements in the array and the number of subsegments, respectively. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["YES\n1 3 5\nNO\nNO"]
#include <stdio.h> #define READ(n) int (n); scanf("%d",&(n)) #define getInt(a) scanf("%d", &a) #define FOR(i,L,R) for (int i = L; i < R; i++) int main(){ READ(q); while(q--){ READ(n); READ(k); int arr[n], oddCnt = 0; FOR(i, 0, n){ READ(a); arr[i] = a % 2; if (arr[i] == 1) oddCnt++; } if (oddCnt % 2 != k % 2 || oddCnt < k){ printf("NO\n"); continue; } else { printf("YES\n"); FOR(i, 0, n){ if (k == 1){ printf("%d ", n); break; } else if (arr[i] == 1){ printf("%d ", i + 1); k--; } } printf("\n"); } } }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You want to split it into exactly $$$k$$$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i. e. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the $$$n$$$ elements of the array $$$a$$$ must belong to exactly one of the $$$k$$$ subsegments.Let's see some examples of dividing the array of length $$$5$$$ into $$$3$$$ subsegments (not necessarily with odd sums): $$$[1, 2, 3, 4, 5]$$$ is the initial array, then all possible ways to divide it into $$$3$$$ non-empty non-intersecting subsegments are described below: $$$[1], [2], [3, 4, 5]$$$; $$$[1], [2, 3], [4, 5]$$$; $$$[1], [2, 3, 4], [5]$$$; $$$[1, 2], [3], [4, 5]$$$; $$$[1, 2], [3, 4], [5]$$$; $$$[1, 2, 3], [4], [5]$$$. Of course, it can be impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.You have to answer $$$q$$$ independent queries.
For each query, print the answer to it. If it is impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as $$$k$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_k$$$ such that $$$1 \le r_1 &lt; r_2 &lt; \dots &lt; r_k = n$$$, where $$$r_j$$$ is the right border of the $$$j$$$-th segment (the index of the last element that belongs to the $$$j$$$-th segment), so the array is divided into subsegments $$$[1; r_1], [r_1 + 1; r_2], [r_2 + 1, r_3], \dots, [r_{k - 1} + 1, n]$$$. Note that $$$r_k$$$ is always $$$n$$$ but you should print it anyway.
C
7f5269f3357827b9d8682d70befd3de1
58c1c4c7a500e5f234cbe22847d56c51
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "math" ]
1563978900
["3\n5 3\n7 18 3 14 1\n5 4\n1 2 3 4 5\n6 2\n1 2 8 4 10 2"]
null
PASSED
1,200
standard input
3 seconds
The first line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) — the number of elements in the array and the number of subsegments, respectively. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["YES\n1 3 5\nNO\nNO"]
#include<stdio.h> int main(){ int t; scanf("%d", &t); while(t--){ int n, k; scanf("%d %d", &n, &k); int a[n]; int b[n]; int count = 0; for(int i=0; i<n; i++){ scanf("%d", &a[i]); if(a[i]%2 == 1){ b[count] = i; count++; } } if(count >=k && k%2 == count%2){ printf("YES\n"); for(int j=0; j<k-1; j++){ printf("%d ", b[j]+1); } printf("%d\n", n); } else{ printf("NO\n"); } } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You want to split it into exactly $$$k$$$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i. e. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the $$$n$$$ elements of the array $$$a$$$ must belong to exactly one of the $$$k$$$ subsegments.Let's see some examples of dividing the array of length $$$5$$$ into $$$3$$$ subsegments (not necessarily with odd sums): $$$[1, 2, 3, 4, 5]$$$ is the initial array, then all possible ways to divide it into $$$3$$$ non-empty non-intersecting subsegments are described below: $$$[1], [2], [3, 4, 5]$$$; $$$[1], [2, 3], [4, 5]$$$; $$$[1], [2, 3, 4], [5]$$$; $$$[1, 2], [3], [4, 5]$$$; $$$[1, 2], [3, 4], [5]$$$; $$$[1, 2, 3], [4], [5]$$$. Of course, it can be impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.You have to answer $$$q$$$ independent queries.
For each query, print the answer to it. If it is impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as $$$k$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_k$$$ such that $$$1 \le r_1 &lt; r_2 &lt; \dots &lt; r_k = n$$$, where $$$r_j$$$ is the right border of the $$$j$$$-th segment (the index of the last element that belongs to the $$$j$$$-th segment), so the array is divided into subsegments $$$[1; r_1], [r_1 + 1; r_2], [r_2 + 1, r_3], \dots, [r_{k - 1} + 1, n]$$$. Note that $$$r_k$$$ is always $$$n$$$ but you should print it anyway.
C
7f5269f3357827b9d8682d70befd3de1
dc8e414860b0c72ba52fdb04dfe20008
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "math" ]
1563978900
["3\n5 3\n7 18 3 14 1\n5 4\n1 2 3 4 5\n6 2\n1 2 8 4 10 2"]
null
PASSED
1,200
standard input
3 seconds
The first line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) — the number of elements in the array and the number of subsegments, respectively. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["YES\n1 3 5\nNO\nNO"]
#include<stdio.h> int main() { int q,n,k,a,b,i,o=0,t[200001],j=0; scanf("%d",&q); while(q--) { scanf("%d%d",&n,&k); for(i=0; i<n; i++) { scanf("%d",&a); if(a&1) o++,t[j++]=i+1; } if(o<k||((k+o)&1)) printf("NO\n"); else { printf("YES\n"); for(i=0; i<k-1; i++) printf("%d ",t[i]); printf("%d\n",n); } o=j=0; } return 0; }
You are given an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. You want to split it into exactly $$$k$$$ non-empty non-intersecting subsegments such that each subsegment has odd sum (i. e. for each subsegment, the sum of all elements that belong to this subsegment is odd). It is impossible to rearrange (shuffle) the elements of a given array. Each of the $$$n$$$ elements of the array $$$a$$$ must belong to exactly one of the $$$k$$$ subsegments.Let's see some examples of dividing the array of length $$$5$$$ into $$$3$$$ subsegments (not necessarily with odd sums): $$$[1, 2, 3, 4, 5]$$$ is the initial array, then all possible ways to divide it into $$$3$$$ non-empty non-intersecting subsegments are described below: $$$[1], [2], [3, 4, 5]$$$; $$$[1], [2, 3], [4, 5]$$$; $$$[1], [2, 3, 4], [5]$$$; $$$[1, 2], [3], [4, 5]$$$; $$$[1, 2], [3, 4], [5]$$$; $$$[1, 2, 3], [4], [5]$$$. Of course, it can be impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements. In this case print "NO". Otherwise, print "YES" and any possible division of the array. See the output format for the detailed explanation.You have to answer $$$q$$$ independent queries.
For each query, print the answer to it. If it is impossible to divide the initial array into exactly $$$k$$$ subsegments in such a way that each of them will have odd sum of elements, print "NO" in the first line. Otherwise, print "YES" in the first line and any possible division of the array in the second line. The division can be represented as $$$k$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_k$$$ such that $$$1 \le r_1 &lt; r_2 &lt; \dots &lt; r_k = n$$$, where $$$r_j$$$ is the right border of the $$$j$$$-th segment (the index of the last element that belongs to the $$$j$$$-th segment), so the array is divided into subsegments $$$[1; r_1], [r_1 + 1; r_2], [r_2 + 1, r_3], \dots, [r_{k - 1} + 1, n]$$$. Note that $$$r_k$$$ is always $$$n$$$ but you should print it anyway.
C
7f5269f3357827b9d8682d70befd3de1
ee73fb60e42e178afac280a47661fd2f
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "constructive algorithms", "math" ]
1563978900
["3\n5 3\n7 18 3 14 1\n5 4\n1 2 3 4 5\n6 2\n1 2 8 4 10 2"]
null
PASSED
1,200
standard input
3 seconds
The first line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$) — the number of elements in the array and the number of subsegments, respectively. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["YES\n1 3 5\nNO\nNO"]
#include <stdio.h> int main() { int t; scanf("%d",&t); while(t--) { int n,k,K[200000],o=0; scanf("%d %d",&n,&k); int a[200000]; long long sum=0; int i=0; while(i<n) { scanf("%d",&a[i]); sum=(long long)sum+a[i]; if(a[i]%2!=0) o++; i++; } int q=0; if(o==0) printf("NO\n"); else if((sum%2==0 && k%2==0)||(sum%2!=0 &&k%2 !=0)) { for(i=0; i<n; i++) { if(a[i]%2!=0 ) { if(q<k-1) { K[q]=i+1; //printf("%d ",a[i]); q++; } if(q==k-1) { K[q]=n; q++; break; } } } if(q==k) { printf("YES\n"); for(i=0; i<k; i++) { printf("%d ",K[i]); } printf("\n"); } else printf("NO\n"); } else printf("NO\n"); } return 0; }
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
C
88d56c1e3a7ffa94354ce0c70d8e958f
3daf5000b5ebb47e754421ae8c987988
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1475330700
["24\n17:30", "12\n17:30", "24\n99:99"]
null
PASSED
1,300
standard input
1 second
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
["17:30", "07:30", "09:09"]
#include <stdio.h> int main(void) { int n; int hh,mm; scanf("%d",&n); scanf("%d:%d", &hh, &mm); if( n == 12) { while(hh<1) hh+=10; while(hh>12) hh-=10; while(mm>=60) mm-=60; } else if( n == 24) { while(hh<0) hh+=10; while(hh>23) hh-=10; while(mm>=60) mm-=60; } else return 0; if(hh<10 && mm<10) printf("0%d:0%d",hh,mm); else if(mm<10) printf("%d:0%d",hh,mm); else if(hh<10) printf("0%d:%d",hh,mm); else printf("%d:%d",hh,mm); return 0; }
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
C
88d56c1e3a7ffa94354ce0c70d8e958f
6491916d048e8aa381d1a1faa1f7b616
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1475330700
["24\n17:30", "12\n17:30", "24\n99:99"]
null
PASSED
1,300
standard input
1 second
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
["17:30", "07:30", "09:09"]
/* Problem: 722A - Broken Clock */ /* Solver: Gusztav Szmolik */ #include <stdio.h> #include <string.h> #include <ctype.h> int main () { unsigned short tf; unsigned char tm[7]; unsigned short h; unsigned short m; if (scanf("%hu",&tf) != 1) return -1; if (tf != 12 && tf != 24) return -1; if (scanf("%6s",tm) != 1) return -1; if (strlen(tm) != 5) return -1; if (!isdigit(tm[0]) || !isdigit(tm[1]) || !isdigit(tm[3]) || !isdigit(tm[4])) return -1; if (tm[2] != ':') return -1; h = 10*(tm[0]-'0')+tm[1]-'0'; m = 10*(tm[3]-'0')+tm[4]-'0'; if (tf == 12 && !h) printf ("01:"); else if (tf == 12 && h > 12) { if (tm[1] == '0') printf ("10:"); else printf ("0%c:",tm[1]); } else if (tf == 24 && h > 23) printf ("0%c:",tm[1]); else printf ("%c%c:",tm[0],tm[1]); if (m > 59) printf ("0%c\n",tm[4]); else printf ("%c%c\n",tm[3],tm[4]); return 0; }
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
C
88d56c1e3a7ffa94354ce0c70d8e958f
180a29068d293b57af3ed0144797026c
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1475330700
["24\n17:30", "12\n17:30", "24\n99:99"]
null
PASSED
1,300
standard input
1 second
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
["17:30", "07:30", "09:09"]
#include<stdio.h> int main() { char h1, h2, m1, m2; int form; scanf("%d\n", &form); scanf("%c%c:%c%c", &h1,&h2,&m1,&m2); if (form == 12) { if (h1 > '1') { if (h2 != '0') { h1 = '0'; } else { h1 = '1'; } } if (h1 == '0'&&h2 == '0') { h2 = '1'; } if(h1 == '1'&&h2 > '2'){ h2 = '0'; } } else { if (h1 > '2'||h1=='2'&&h2>'3') { h1 = '1'; } } if (m1 >= '6') { m1 = '1'; } printf("%c%c:%c%c\n",h1,h2,m1,m2); return 0; }
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
C
88d56c1e3a7ffa94354ce0c70d8e958f
cb08db9b7a25fc2f6bf5655c903f1add
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1475330700
["24\n17:30", "12\n17:30", "24\n99:99"]
null
PASSED
1,300
standard input
1 second
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
["17:30", "07:30", "09:09"]
#include <stdio.h> #include <stdlib.h> int main(void) { int format; char hh[3], mm[3]; scanf("%d\n", &format); hh[0]=getchar(); hh[1]=getchar(); getchar(); mm[0]=getchar(); mm[1]=getchar(); hh[2]='\0'; mm[2]='\0'; int m=atoi(mm), h=atoi(hh); if(m>59) mm[0]='0'; if(format==12) if(h<1 || h>12) if(h==0) hh[1]='1'; else if(h%10==0) hh[0]='1'; else hh[0]='0'; if(format==24) if(h>23) hh[0]='0'; printf("%s:%s\n", hh, mm); return 0; }
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
C
88d56c1e3a7ffa94354ce0c70d8e958f
2b338822baa846554fc9c1be6f51d941
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1475330700
["24\n17:30", "12\n17:30", "24\n99:99"]
null
PASSED
1,300
standard input
1 second
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
["17:30", "07:30", "09:09"]
#include <stdio.h> #include <string.h> int main() { //freopen ("lel.in","r",stdin); int format; int h,m; scanf("%d",&format); scanf("%2d:%2d",&h,&m); if(format==24) { if(h>23) h=h%10; if(m>59) m=m%10; } else if(format==12) { if(h==0) h=1; if(h>12 && h%10!=0) h=h%10; else if(h>12) h=10; if(m>59) m=m%10; } printf("%.2d:%.2d",h,m); return 0; }
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
C
88d56c1e3a7ffa94354ce0c70d8e958f
a6f3ada5415f077f7ffd35801b6f049a
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1475330700
["24\n17:30", "12\n17:30", "24\n99:99"]
null
PASSED
1,300
standard input
1 second
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
["17:30", "07:30", "09:09"]
#include<stdio.h> int main() { int a,h,m; scanf ("%d\n", &a); a = a / 12; scanf ("%d:%d", &h, &m); if ( a == 1) { if (h > 12) h = h % 10; if (h == 0) h = 10; if (m > 59) m = m % 10; } else { if (h > 24) h = h % 10; if (h == 24) h = 14; if (m > 59) m = m % 10; } printf ("%02d:%02d", h, m ); return 0; }
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
C
88d56c1e3a7ffa94354ce0c70d8e958f
e6368f3076e5ac06a287a48281756e1c
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1475330700
["24\n17:30", "12\n17:30", "24\n99:99"]
null
PASSED
1,300
standard input
1 second
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
["17:30", "07:30", "09:09"]
#include <stdio.h> int main (){ int format,h1,h2,m1,m2,hh,mm; scanf ("%d",&format); scanf ("%1d%1d:%1d%1d",&h1,&h2,&m1,&m2); hh=h1*10+h2; mm=m1*10+m2; if (format==24){ if (hh>=24) h1=0; if (mm>=60) m1=0; }else { if (hh> 12) h1=0; if (mm>=60) m1=0; if (h1==0 && h2==0) h1=1; } printf ("%d%d:%d%d",h1,h2,m1,m2); }
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
C
88d56c1e3a7ffa94354ce0c70d8e958f
9b3fbfa2c4be558959c5d364aaa9700f
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1475330700
["24\n17:30", "12\n17:30", "24\n99:99"]
null
PASSED
1,300
standard input
1 second
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
["17:30", "07:30", "09:09"]
#include <stdio.h> int main(){ int n; char h1, h2, m1, m2; scanf("%d\n", &n); scanf("%c%c:%c%c", &h1, &h2, &m1, &m2); if(n == 24){ if(h1 == '2' && h2 > '3'){ h2 = '0'; } else if(h1 > '2'){ h1 = '0'; } } else{ if(h1 == '0' && h2 == '0'){ h1 = '1'; } else if(h1 == '1' && h2 > '2'){ h1 = '0'; } else if(h1 > '1'){ if(h2 > '2' && h2 != '0'){ h1 = '0'; } else{ h1 = '1'; } } } if(m1 > '5'){ m1 = '0'; } printf("%c%c:%c%c\n", h1, h2, m1, m2); return 0; }
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
C
88d56c1e3a7ffa94354ce0c70d8e958f
ecd5079a190e9ebe11d31abe9e9f79eb
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1475330700
["24\n17:30", "12\n17:30", "24\n99:99"]
null
PASSED
1,300
standard input
1 second
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
["17:30", "07:30", "09:09"]
#include<stdio.h> int main() { int n; int a,b; scanf("%d",&n); scanf("%d:%d",&a,&b); if(n==24) { if(0<=a&&a<=23) { if(a<=9) printf("0"); printf("%d",a); } else { if(a/10==2) printf("20"); else { a%=10; printf("%d",10+a); } } } else if(n==12) { if(1<=a&&a<=12) { if(a<=9) printf("0"); printf("%d",a); } else { if(!a||a/10==1||!(a%10)) printf("10"); else printf("0%d",a%10); } } printf(":"); if(0<=b&&b<=59) { if(b<=9) printf("0"); printf("%d",b); } else { b%=10; printf("3%d",b); } return 0; }
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
C
88d56c1e3a7ffa94354ce0c70d8e958f
4a4917ba77eeaf7307328b5ae5ea656c
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1475330700
["24\n17:30", "12\n17:30", "24\n99:99"]
null
PASSED
1,300
standard input
1 second
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
["17:30", "07:30", "09:09"]
#include <stdio.h> #include <stdlib.h> int main() { int stat; scanf("%d", &stat); char s[10]; scanf("%s", &s); if (s[3] > '5') s[3] = '5'; if (stat == 12){ if ((s[0] > '1') && (s[1] != '0')) s[0] = '0'; else if (s[1] == '0') s[0] = '1'; else if ((s[0] == '1') && (s[1] > '2')) s[1] = '1'; else if ((s[0] == '0') && (s[1] == '0')) s[1] = '1'; }else { if (s[0] > '2') s[0] = '1'; else if ((s[0] == '2') && (s[1] > '3')) s[1] = '2'; } printf("%s\n", s); return 0; }
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
C
88d56c1e3a7ffa94354ce0c70d8e958f
6194cad9500aac975311ac44b4f0ec9a
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1475330700
["24\n17:30", "12\n17:30", "24\n99:99"]
null
PASSED
1,300
standard input
1 second
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
["17:30", "07:30", "09:09"]
#define _CRT_SECURE_NO_WARNINGS #include <stdlib.h> #include <stdio.h> int main() { int m; char s[100]; int hour=0, min = 0; scanf("%d", &m); scanf("%s", s); hour = 10 * (s[0] - '0') + s[1] - '0'; min = 10 * (s[3] - '0') + s[4] - '0'; if (m == 24) { if (hour > 23) hour %=10; if (min > 59) min %= 10; } else { if (hour > 12 && hour % 10 != 0) hour %= 10; if (hour > 12 && hour % 10 == 0) hour = 10; if (hour == 0) hour = 1; if (min > 59) min %= 10; } if (hour < 10) printf("0%d", hour); else printf("%d", hour); printf(":"); if (min < 10) printf("0%d", min); else printf("%d", min); // system("pause"); return 0; }
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
C
88d56c1e3a7ffa94354ce0c70d8e958f
f01f02805dd75f194d9a60814463a755
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1475330700
["24\n17:30", "12\n17:30", "24\n99:99"]
null
PASSED
1,300
standard input
1 second
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
["17:30", "07:30", "09:09"]
#include<stdio.h> int main() { int f; int h, m; scanf("%d", &f); scanf("%d:%d", &h,&m); if(m>59) m=m%10; if(f==12){ if(h==0) h=1; if(h>12){ if(h%10==0) h=10; else h=h%10; } } else if(f==24){ if(h>23) h=h%10; } printf("%02d:%02d\n", h,m); return 0; }
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
C
88d56c1e3a7ffa94354ce0c70d8e958f
3376071714d819562e5b51580bf2e504
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1475330700
["24\n17:30", "12\n17:30", "24\n99:99"]
null
PASSED
1,300
standard input
1 second
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
["17:30", "07:30", "09:09"]
#include<stdio.h> int main() { int h,a,b,c,d; scanf("%d",&h); scanf("%1d%1d:%1d%1d",&a,&b,&c,&d); if(h==12) { if(a==1 && b>2) a=0; else if(b==0 && a>1) a=1; else if(a>1 && b>0) a=0; else if(a==0 && b==0) b=1; } if(h==24) { if(a>2 || (a==2 && b>3)) a=0; } if(c>5) c=0; printf("%d%d:%d%d",a,b,c,d); return 0; }
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
C
88d56c1e3a7ffa94354ce0c70d8e958f
87ead4856a67dde8cd389d230d098045
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1475330700
["24\n17:30", "12\n17:30", "24\n99:99"]
null
PASSED
1,300
standard input
1 second
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
["17:30", "07:30", "09:09"]
#include <stdio.h> #include <string.h> char ss[7]; int main() { int t; scanf("%d", &t); scanf("%s", ss); if (ss[3] - '0' > 5) ss[3] = '5'; if (t == 12) { if (ss[0] == '0'&&ss[1] == '0') ss[1] = '1'; else if (ss[0] == '1'&&ss[1] - '0' > 2) ss[1] = '2'; else if (ss[0] - '0' > 1 && ss[1] - '0' <= 2) ss[0] = '1'; else if (ss[0] - '0' > 1 && ss[1] - '0' > 0) ss[0] = '0'; } else { if (ss[0] - '0' > 2) ss[0] = '1'; if (ss[0] == '2'&&ss[1] - '0' > 3)ss[1] = '0'; } printf("%s\n", ss); return 0; }
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
C
88d56c1e3a7ffa94354ce0c70d8e958f
fd404e93fcedc8fdeedb7ef90e9e3cba
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1475330700
["24\n17:30", "12\n17:30", "24\n99:99"]
null
PASSED
1,300
standard input
1 second
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
["17:30", "07:30", "09:09"]
#include <stdio.h> //#define DEBUG int main(void) { #ifdef DEBUG freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int f; char t[10]; scanf("%d\n%s", &f, t); if (t[3] > '5') t[3] = '0'; if (f == 12) { if (t[0] == '0' && t[1] == '0') t[1] = '1'; else if (t[0] == '1' && t[1] > '2' || t[0] > '1' && t[1] != '0') t[0] = '0'; else if (t[0] > '1' && t[1] == '0') t[0] = '1'; } else if (f == 24 && (t[0] == '2' && t[1] > '3' || t[0] > '2')) t[0] = '0'; printf("%s\n", t); return 0; }
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
C
88d56c1e3a7ffa94354ce0c70d8e958f
c0ca0a1d6fcc78541bc24e6388d55187
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1475330700
["24\n17:30", "12\n17:30", "24\n99:99"]
null
PASSED
1,300
standard input
1 second
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively. The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
["17:30", "07:30", "09:09"]
#include <stdio.h> int main() { int a, h1, h2; scanf("%d", &a); scanf("%d:%d", &h1, &h2); if (h2 > 59) h2 = h2 % 10; if (a == 12) if (h1 > 12||h1 == 0) if (h1%10 == 0) h1 = 10; else h1 = h1 % 10; if (a == 24) if (!(h1 <= 23)) h1 =h1 % 10; printf("%02d:%02d\n", h1, h2); return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
4ed0d6fd1effbd3c5b64fd6a5c4fc066
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> #include<math.h> int cmp(const void*a,const void*b) { return *(int*)b-*(int*)a; } int main() { int i,j,k1=0,k2=0,k3=0,n,n1=0,n2=0,n3=0,judge=0; int c[5001],a[5001],b[5001],d[5001]; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&c[i]); if(c[i]==1) { a[n1]=i+1; n1++; } else if(c[i]==2) { b[n2]=i+1; n2++; } else { d[n3]=i+1; n3++; } } if(n1>n2) { n1=n1^n2; n2=n1^n2; n1=n1^n2; } if(n1>n3) { n1=n1^n3; n3=n1^n3; n1=n1^n3; } if(n2>n3) { n2=n2^n3; n3=n2^n3; n2=n2^n3; } printf("%d\n",n1); for(i=0;i<n1;i++) { printf("%d %d %d\n",a[i],b[i],d[i]); } return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
506b46418a71b032acada012c3a6dd72
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> #include<math.h> int cmp(const void*a,const void*b) { return *(int*)b-*(int*)a; } int main() { int i,j,k,a,num,n,n1=0,n2=0,n3=0,judge=0; int c[5001],b[4][5001]; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&c[i]); if(c[i]==1) { b[1][n1]=i+1; n1++; } else if(c[i]==2) { b[2][n2]=i+1; n2++; } else { b[3][n3]=i+1; n3++; } } if(n1>n2) { n1=n1^n2; n2=n1^n2; n1=n1^n2; } if(n1>n3) { n1=n1^n3; n3=n1^n3; n1=n1^n3; } if(n2>n3) { n2=n2^n3; n3=n2^n3; n2=n2^n3; } printf("%d\n",n1); for(i=0;i<n1;i++) { printf("%d %d %d\n",b[1][i],b[2][i],b[3][i]); } return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
b8eeb1bf65a68a336c6f5170184ce20b
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> #include<math.h> int cmp(const void*a,const void*b) { return *(int*)b-*(int*)a; } int main() { int i,j,k,a,n,n1=0,n2=0,n3=0,judge=0; int c[5001],b[3][2],d[5001]; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&c[i]); if(c[i]==1) { n1++; } else if(c[i]==2) { n2++; } else { n3++; } } if(n1>n2) { n1=n1^n2; n2=n1^n2; n1=n1^n2; } if(n1>n3) { n1=n1^n3; n3=n1^n3; n1=n1^n3; } if(n2>n3) { n2=n2^n3; n3=n2^n3; n2=n2^n3; } printf("%d\n",n1); for(i=0;i<n1;i++) { k=0; for(j=0;j<n;j++) { if(c[j]==1) { c[j]=0; b[k][0]=j+1; b[k][1]=1; k++; break; } } for(j=0;j<n;j++) { if(c[j]==2) { c[j]=0; b[k][0]=j+1; b[k][1]=2; k++; break; } } for(j=0;j<n;j++) { if(c[j]==3) { c[j]=0; b[k][0]=j+1; b[k][1]=3; k++; break; } } for(j=1;j<=3;j++) { for(k=0;k<3;k++) { if(b[k][1]==j) { printf("%d ",b[k][0]); } } } printf("\n"); } return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
7083d4553353124078d639a35790ca2a
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> int main() { int n,i,t,one[5002],two[5005],three[5005],on=0,tw=0,thr=0; scanf("%d",&n); for(i=1; i<=n; i++) { scanf("%d",&t); if(t==1) { on++; one[on]=i; } if(t==2) { tw++; two[tw]=i; } if(t==3) { thr++; three[thr]=i; } } if(on==0||tw==0||thr==0) { printf("0\n"); return 0; } int temp; if(on>tw) { temp=tw; on=tw; tw=on; } if(on>thr) { temp=thr; on=thr; thr=on; } printf("%d\n",on); for(i=1;i<=on;i++) { printf("%d %d %d\n",one[i],two[i],three[i]); } return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
45237a8acfaae043554c384fe6b3b175
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> int main(){ int ones=0,twoes=0,threes=0; int n,checker,j=1,n1=0,n2=1,n3=2,w; scanf("%d",&n); int a[n*3]; for(int i=1;i<=n;i++){ scanf("%d",&checker); if(checker==1){ a[n1]=j; n1+=3; j++; ones++; } else if(checker==2){ a[n2]=j; n2+=3; j++; twoes++; } else{ a[n3]=j; n3+=3; j++; threes++; } } if(ones==0||twoes==0||threes==0){ printf("0"); return 0; } else if(ones==1||twoes==1||threes==1){ printf("1\n"); w=1; } else{ if(ones<=twoes&&ones<=threes){ w=ones; printf("%d\n",w); }else if( twoes<=ones&&twoes<= threes){ w=twoes; printf("%d\n",w); } else{ w=threes; printf("%d\n",w); } } for(int i=0;i<w*3;i++){ if(i>=3&&i%3==0) printf("\n"); printf("%d ",a[i]); } }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
ad47f8056a6a7e98b4dfe67b64f36a0e
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> #include<stdlib.h> int main(void) { unsigned n,i,j,k,l,num,num1,num2,num3,*a,*b,*c,*t; scanf("%u",&n); t=(unsigned*)malloc(n*sizeof(unsigned)); a=(unsigned*)malloc((n)*sizeof(unsigned)); b=(unsigned*)malloc((n)*sizeof(unsigned)); c=(unsigned*)malloc((n)*sizeof(unsigned)); for(i=num=num1=num2=num3=0;i<n;i++) { scanf("%u",(t+i)); if(*(t+i)==1) num1++; else if(*(t+i)==2) num2++; else num3++; } num=((num1<=num2)?((num1<=num3)?num1:num3):((num2<=num3)?num2:num3)); for(i=j=k=l=0;i<n;i++) { if(*(t+i)==1) *(a+j++)=i+1; else if(*(t+i)==2) *(b+k++)=i+1; else *(c+l++)=i+1; } if(num==0) printf("%u",num); else {printf("%u\n",num); for(i=0;i<num;i++) printf("%u %u %u\n",*(a+i),*(b+i),*(c+i));} return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
e77a1d5f0a5a379fc9dd0f0ae97547ad
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
// Codeforces A. Team Olympiad // Created by Abdulrahman Elsayed on 04/07/2020 #include <stdio.h> int min(int *a, int *b, int *c); int main() { int n, c1 = 0, c2 = 0, c3 = 0, teams = 0; scanf("%d", &n); int array[n]; int count1[n], count2[n], count3[n]; for (int i = 0; i < n; i++) { scanf("%d", &array[i]); if (array[i] == 1) { count1[c1] = i + 1; c1++; } else if (array[i] == 2) { count2[c2] = i + 1; c2++; } else { count3[c3] = i + 1; c3++; } } teams = min(&c1, &c2, &c3); printf("%d\n", teams); if (teams > 0) for (int i = 0; i < teams; i++) printf("%d %d %d\n", count1[i], count2[i], count3[i]); return 0; } int min(int *a, int *b, int *c) { int m = *a; if (*b < m) m = *b; if (*c < m) m = *c; return m; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
7f892cdfea0f0bb71ab92a61c88c5946
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> main(){ int n, i, j, input; scanf("%d", &n); int prog[n], math[n], sports[n], p=0, m=0, s=0, teams; for(i=0; i<n; i++){ scanf("%d", &input); // store the index if(input==1){ prog[p] = i+1; p++; }else if(input==2){ math[m] = i+1; m++; }else if(input==3){ sports[s] = i+1; s++; } } if(p<1 || m<1 || s<1){ printf("0"); return 0; } teams = (m<=p && m<=s) ? m : (s<=p && s<=m) ? s : p; printf("%d\n", teams); for(j=0; j<teams; j++){ printf("%d %d %d\n", prog[j], math[j], sports[j]); } }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
87db91479654336c44cdc297d1d2f91a
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> main(){ int n, i, input; scanf("%d", &n); int skills[3][n], p=0, m=0, s=0; for(i=0; i<n; i++){ scanf("%d", &input); // store the index if(input==1){ skills[0][p] = i+1; p++; }else if(input==2){ skills[1][m] = i+1; m++; }else if(input==3){ skills[2][s] = i+1; s++; } } if(p<1 || m<1 || s<1){ printf("0"); return 0; } input = (m<=p && m<=s) ? m : (s<=p && s<=m) ? s : p; printf("%d\n", input); for(i=0; i<input; i++){ printf("%d %d %d\n", skills[0][i], skills[1][i], skills[2][i]); } }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
e2ee8d99e2f0db9d6762c89d729fe026
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> main(){ int n, i, input; scanf("%d", &n); int skills[3][n], p=0, m=0, s=0, teams; for(i=0; i<n; i++){ scanf("%d", &input); // store the index if(input==1){ skills[0][p] = i+1; p++; }else if(input==2){ skills[1][m] = i+1; m++; }else if(input==3){ skills[2][s] = i+1; s++; } } if(p<1 || m<1 || s<1){ printf("0"); return 0; } teams = (m<=p && m<=s) ? m : (s<=p && s<=m) ? s : p; printf("%d\n", teams); for(i=0; i<teams; i++){ printf("%d %d %d\n", skills[0][i], skills[1][i], skills[2][i]); } }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
6b8d078876733abf6be038e03d00ca18
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> main(){ int i,j,k,a[4],b[6000],n1,n,l,p,j1,j2,j3; scanf("%d",&n); a[1]=0;a[2]=0;a[3]=0; for(i=0;i<n;i++){ scanf("%d",&k); b[i]=k; a[k]=a[k]+1; } if(a[1]<=a[2] && a[1]<=a[3]) n1=a[1]; if(a[2]<=a[1] && a[2]<=a[3]) n1=a[2]; if(a[3]<=a[2] && a[3]<=a[1]) n1=a[3]; if(n1){ printf("%d\n",n1); for(i=0;i<n1;i++){ j1=0;j2=0;j3=0; for(j=0;j<n;j++){ l=b[j]; if(l==1 && j1<1){ a[l]=j; j1++; b[j]=0; } if(l==2 && j2<1){ a[l]=j; j2++; b[j]=0; } if(l==3 && j3<1){ a[l]=j; j3++; b[j]=0; } } printf("%d %d %d \n",a[1]+1,a[2]+1,a[3]+1); } } else{ printf("0"); } return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
2559d5acfdabd05d64d49220ad8ea035
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include <stdio.h> int main() { int a,b,c,d=0,e=0,f=0,j=0,k,x=0,y=0,z=0,w=0,r=0,t=0; scanf("%d",&a); int s[a]; int i; for(i=1;i<=a;i++) { scanf("%d",&s[i]); if(s[i]==1) { d++; } else if(s[i]==2) { e++; }else { f++; } } if(d==0||e==0||f==0) { printf("0"); } else { if(d<=f&&d<=e) { j=d; printf("%d\n",d); }else if(e<=f&&e<=d) { j=e; printf("%d\n",e); }else {j=f; printf("%d\n",f); }for(k=j;k!=0;k--) { for(i=1;i<=a;i++) { if(s[i]==1&&x==0&&i>w) { x=1; w=i; printf("%d ",i); }else if(s[i]==2&&y==0&&i>r) { y=1; r=i; printf("%d ",i); }else if(s[i]==3&&z==0&&i>t) { z=1; t=i; printf("%d ",i); } } printf("\n"); x=0; y=0; z=0; } } return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
7310f1cbd987b810feb4258514316d09
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> int main() { int i,j,k,n,a[10000],u=0,o=0,p=0,q[10000],w[10000],e[10000],count,ct=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n;i++) { count=0; if(a[i]==1) { for(j=0;j<n;j++) { if(a[j]==2) { for(k=0;k<n;k++) { if(a[k]==3) { ct++; count++; a[i]=0; a[j]=0; a[k]=0; break; } } break; } } } if(count==1) { q[u]=i+1; w[o]=j+1; e[p]=k+1; u++; o++; p++; } } printf("%d\n",ct); for(i=0;i<ct;i++) { printf("%d %d %d\n",q[i],w[i],e[i]); } return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
7890ed9a13f13953dac54e766c81b2ec
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include <stdio.h> int main() { int n; scanf("%d", &n); int a[n], i, b[4]={0}, min=5010; for(i=0; i<n; i++) { scanf("%d", &a[i]); b[a[i]]++; } for(i=1; i<4; i++) { if(b[i]<min) min = b[i]; } printf("%d\n", min); int p=0, q=0, r=0; for(i=0; i<min; i++) { while(a[p]!=1) p++; printf("%d ", ++p); while(a[q]!=2) q++; printf("%d ", ++q); while(a[r]!=3) r++; printf("%d\n", ++r); } return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
8d11fc7f24429840e0a3f04018938c4f
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include <stdio.h> #include <stdlib.h> int cmp(void const* a,void const* b) { return (*(int *)a - *(int *)b); } int main() { int n; scanf("%d",&n); int i,o=0,t=0,p=0; int q; int cal[4]={0}; int one[5002]={0},two[5002]={0},three[5002]={0}; for(i=1;i<=n;i++) { scanf("%d",&q); cal[q]++; if(q==1) { one[o]=i; o++; } else if(q==2) { two[t]=i; t++; } else if(q==3) { three[p]=i; p++; } } qsort(one,o,sizeof(int),cmp); qsort(two,t,sizeof(int),cmp); qsort(three,p,sizeof(int),cmp); int max=6000; for(i=1;i<=3;i++) { if(cal[i]<max) { max=cal[i]; } } printf("%d\n",max); if(max!=0) { while(1) { printf("%d %d %d\n",one[o-1],two[t-1],three[p-1]); o--; t--; p--; max--; if(max==0) { break; } } } return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
c431977125f4d8fb0566bc864e03e3cc
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> int main() { int n,i,min; scanf("%d",&n); int a[n]; int freq[4]={0}; for(i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]==1) { freq[1]=freq[1]+1; } else if(a[i]==2) { freq[2]=freq[2]+1; } else { freq[3]=freq[3]+1; } } min=freq[1]; for(i=2;i<4;i++) { if(freq[i]<min) { min=freq[i]; } } printf("%d\n",min); int onePosition[min],twoPosition[min],threePosition[min]; int count=0; for(i=0;count!=min;i++) { if(a[i]==1) { onePosition[count]=i; count++; } } count=0; for(i=0;count!=min;i++) { if(a[i]==2) { twoPosition[count]=i; count++; } } count=0; for(i=0;count!=min;i++) { if(a[i]==3) { threePosition[count]=i; count++; } } for(i=0;i<min;i++) { printf("%d %d %d\n",onePosition[i]+1,twoPosition[i]+1,threePosition[i]+1); } return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
585b3e0161320024bb691112911cc320
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include <stdio.h> int main() { int n; scanf("%d",&n); int a[5005]; int q1[5000],q2[5000],q3[5000]; int x=0,y=0,z=0; int min; for(int i=1; i<=n ; ++i){ scanf("%d",&a[i]); if(a[i]==1) { q1[x] = i; x=x+1; } if(a[i]==2) { q2[y] = i; y=y+1; } if(a[i]==3) { q3[z] = i; z=z+1; } } if(x<=y && x<=z) min = x; if(y<=x && y<=z) min = y; if(z<=y && z<=x) min = z; if(x==0 || y==0 || z==0) { printf("0"); }else{ printf("%d\n",min); for(int i =0 ; i<min; ++i){ printf("%d %d %d\n",q1[i],q2[i],q3[i]); } } return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
d6d76e99f66d46461273e7e964c6a3f9
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include <stdio.h> int mini (int a, int b) { return a > b ? b : a; } void teams(void) { int n; scanf("%d", &n); int arr[n]; int o = 0, t = 0, th = 0; for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); if (arr[i] == 1) { o++; } else if (arr[i] == 2) { t++; } else if (arr[i] == 3) { th++; } } int max = mini(o,mini(t,th)); printf("%d\n", max); for (int i = 0; i < max; i++) { int pos[3]; for (int j = 0; j < n; j++) { if (arr[j] == 1) { pos[0] = j + 1; } else if (arr[j] == 2) { pos[1] = j + 1; } else if (arr[j] == 3) { pos[2] = j + 1; } } printf("%d %d %d\n", pos[0], pos[1], pos[2]); arr[pos[0] - 1] = 0; arr[pos[1] - 1] = 0; arr[pos[2] - 1] = 0; } } int main(void) { teams(); return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
2d7800ad3f194308e701582a3dd55a25
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> int a[5000],b[5000],c[5000],a1=0,b1=0,c1=0,n,m,i,j=0,k=0,l=0; int main(){ scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d",&m); if(m==1) a1++,a[j]=i,j++; else if(m==2) b1++,b[k]=i,k++; else if(m==3) c1++,c[l]=i,l++; } int p=a1>b1? b1:a1; if(c1<p) p=c1; printf("%d\n",p); for(i=0;i<p;i++){ printf("%d %d %d\n",a[i],b[i],c[i]); } }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
57ae667eb7455cdccacc632c082a0135
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> int min(int a,int b,int c){ if(a<=b && a<=c) return(a); else if(b<=a && b<=c) return(b); else if(c<=a && c<=b) return(c); } int a[5000],b[5000],c[5000],a1=0,b1=0,c1=0,n,m,i,j=0,k=0,l=0; int main(){ scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d",&m); if(m==1) a1++,a[j]=i,j++; else if(m==2) b1++,b[k]=i,k++; else if(m==3) c1++,c[l]=i,l++; } int p=min(a1,b1,c1); printf("%d\n",p); for(i=0;i<p;i++){ printf("%d %d %d\n",a[i],b[i],c[i]); } }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
b96547662726fb8985008064623c5da7
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> int main() { int n,a[5005],k,i,d,j,one=0,two=0,th=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]==1) one++; else if(a[i]==2) two++; else if(a[i]==3) th++; } if(one<two) { d=one; one=two; two=d; }if(two<th) { d=two; two=th; th=d; } //smallest is three printf("%d\n",th); for(i=0;i<th;i++) { for(j=0,k=1;j<n;j++) { if(a[j]==k) { printf("%d ",j+1); a[j]=0; k++; j=-1; } /*else if(a[j]==2) { printf("%d ",j+1); a[j]=0; } else if(a[j]==3){ printf("%d ",j+1); a[j]=0; }*/ } printf("\n"); k=1; } return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
abd62fadfecc833c3dfa8814f49ddd24
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include <stdio.h> #include <stdlib.h> int nearestOne(int * childrenArray,int numberOfChildren); int nearestTwo(int * childrenArray,int numberOfChildren); int nearestThree(int * childrenArray,int numberOfChildren); int numberOfTeams(int * childrenArray,int numberOfChildren); void printIndex(int * childrenArray,int numberOfChildren); int main(void){ //Taking Inputs int numberOfChildren; scanf("%d",&numberOfChildren); int * childrenArray = (int *)malloc( numberOfChildren * sizeof(int)); int * childrenArray2 = (int *)malloc( numberOfChildren * sizeof(int)); for(int i = 0;i<numberOfChildren;i++){ scanf("%d",&childrenArray[i]); childrenArray2[i] = childrenArray[i]; } //Algorithm printf("%d\n",numberOfTeams(childrenArray,numberOfChildren)); printIndex(childrenArray2,numberOfChildren); free(childrenArray); free(childrenArray2); return 0; } int nearestOne(int * childrenArray,int numberOfChildren){ for(int i = 0;i<numberOfChildren;i++){ if(childrenArray[i]==1){ childrenArray[i] = 0; return i; } } return -1; // Meaning NO 1s were found } int nearestTwo(int * childrenArray,int numberOfChildren){ for(int i = 0;i<numberOfChildren;i++){ if(childrenArray[i]==2){ childrenArray[i] = 0; return i; } } return -1; // Meaning NO 2s were found } int nearestThree(int * childrenArray,int numberOfChildren){ for(int i = 0;i<numberOfChildren;i++){ if(childrenArray[i]==3){ childrenArray[i] = 0; return i; } } return -1; // Meaning NO 3s were found } int numberOfTeams(int * childrenArray,int numberOfChildren){ int numberOfTeams = 0 ; int indexArray[3]; while (1) { indexArray[0] = nearestOne(childrenArray,numberOfChildren); indexArray[1] = nearestTwo(childrenArray,numberOfChildren); indexArray[2] = nearestThree(childrenArray,numberOfChildren); if(indexArray[0] == -1 || indexArray[1] == -1 || indexArray[2] == -1 ){ break; } else { numberOfTeams++; } } return numberOfTeams; } void printIndex(int * childrenArray,int numberOfChildren){ int indexArray[3]; while (1) { indexArray[0] = nearestOne(childrenArray,numberOfChildren); indexArray[1] = nearestTwo(childrenArray,numberOfChildren); indexArray[2] = nearestThree(childrenArray,numberOfChildren); if(indexArray[0] == -1 || indexArray[1] == -1 || indexArray[2] == -1 ){ break; } else { for(int i = 0;i<3;i++){ printf("%d ",indexArray[i]+1); } printf("\n"); } } }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
e353d71fff4a3ed17f0aee67d42008b9
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> int nearestOne(int*, int); int nearestTwo(int*, int); int nearestThree(int*, int); int main() { int n; int* children; int one, two, three,numberOfTeams=0; int outputArray[5000]; scanf("%d", &n); children = (int*)malloc(n * sizeof(int)); for (int i = 0; i < n; i++) { scanf("%d", &children[i]); } while (1) { one = nearestOne(children, n); two = nearestTwo(children, n); three = nearestThree(children, n); if (one == -1 || two == -1 || three == -1) { break; } else { outputArray[(numberOfTeams * 3)] = one+1; outputArray[(numberOfTeams * 3 + 1)] = two+1; outputArray[(numberOfTeams * 3 + 2)] = three+1; numberOfTeams++; } } printf("%d\n", numberOfTeams); for (int i = 0; i < numberOfTeams*3; i+=3) { printf("%d %d %d\n", outputArray[i], outputArray[i + 1], outputArray[i + 2]); } return 0; } int nearestOne(int* children, int n) { for (int i = 0; i < n; i++) { if (children[i] == 1) { children[i] = 0; return i; } } return -1; } int nearestTwo(int* children, int n) { for (int i = 0; i < n; i++) { if (children[i] == 2) { children[i] = 0; return i; } } return -1; } int nearestThree(int* children, int n) { for (int i = 0; i < n; i++) { if (children[i] == 3) { children[i] = 0; return i; } } return -1; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
82aeddcd7549f56e9b1753d665ea9924
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include <stdio.h> #include <stdlib.h> int nearestOne(int * childrenArray,int numberOfChildren); int nearestTwo(int * childrenArray,int numberOfChildren); int nearestThree(int * childrenArray,int numberOfChildren); int numberOfTeams(int * childrenArray,int numberOfChildren); void printIndex(int * childrenArray,int numberOfChildren); int main(void){ //Taking Inputs int numberOfChildren; scanf("%d",&numberOfChildren); int * childrenArray = (int *)malloc( numberOfChildren * sizeof(int)); int * childrenArray2 = (int *)malloc( numberOfChildren * sizeof(int)); for(int i = 0;i<numberOfChildren;i++){ scanf("%d",&childrenArray[i]); childrenArray2[i] = childrenArray[i]; } //Algorithm printf("%d\n",numberOfTeams(childrenArray,numberOfChildren)); printIndex(childrenArray2,numberOfChildren); free(childrenArray); return 0; } int nearestOne(int * childrenArray,int numberOfChildren){ for(int i = 0;i<numberOfChildren;i++){ if(childrenArray[i]==1){ childrenArray[i] = 0; return i; } } return -1; // Meaning NO 1s were found } int nearestTwo(int * childrenArray,int numberOfChildren){ for(int i = 0;i<numberOfChildren;i++){ if(childrenArray[i]==2){ childrenArray[i] = 0; return i; } } return -1; // Meaning NO 2s were found } int nearestThree(int * childrenArray,int numberOfChildren){ for(int i = 0;i<numberOfChildren;i++){ if(childrenArray[i]==3){ childrenArray[i] = 0; return i; } } return -1; // Meaning NO 3s were found } int numberOfTeams(int * childrenArray,int numberOfChildren){ int numberOfTeams = 0 ; int indexArray[3]; while (1) { indexArray[0] = nearestOne(childrenArray,numberOfChildren); indexArray[1] = nearestTwo(childrenArray,numberOfChildren); indexArray[2] = nearestThree(childrenArray,numberOfChildren); if(indexArray[0] == -1 || indexArray[1] == -1 || indexArray[2] == -1 ){ break; } else { numberOfTeams++; } } return numberOfTeams; } void printIndex(int * childrenArray,int numberOfChildren){ int indexArray[3]; while (1) { indexArray[0] = nearestOne(childrenArray,numberOfChildren); indexArray[1] = nearestTwo(childrenArray,numberOfChildren); indexArray[2] = nearestThree(childrenArray,numberOfChildren); if(indexArray[0] == -1 || indexArray[1] == -1 || indexArray[2] == -1 ){ break; } else { for(int i = 0;i<3;i++){ printf("%d ",indexArray[i]+1); } printf("\n"); } } }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
c3b29f62ebf35c385b2fd1292f139102
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> #include<math.h> int main() { int n,i,x=0,y=0,z=0,l,m=0,j,p=0,o=0; scanf("%d",&n); int a[n]; for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { if(a[i]==1) x++; else if(a[i]==2) y++; else if(a[i]==3) z++; } if(x==0||y==0||z==0) printf("0"); else { if(x<y) { if(x<z) l=x; else l=z; } else { if(y<z) l=y; else l=z; } printf("%d\n",l); int b[l],c[l],d[l]; for(j=0;j<l;j++) for(i=m;i<n;i++) { if(a[i]==1) { m=i+1; b[j]=i+1; break; } } for(j=0;j<l;j++) for(i=p;i<n;i++) { if(a[i]==2) { p=i+1; c[j]=i+1; break; } } for(j=0;j<l;j++) for(i=o;i<n;i++) { if(a[i]==3) { o=i+1; d[j]=i+1; break; } } for(i=0;i<l;i++) printf("%d %d %d\n",b[i],c[i],d[i]); } }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
fc5a185011665182d7e5b53ecbb945e9
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> int min(int i, int j, int k) { int x; x=i; if(j<x) x=j; if(k<x) x=k; return x; } int main() { int a[5000]; int p[5000],q[5000],r[5000]; int n,i; int x=0,y=0,z=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n;i++) { if(a[i]==1) { p[x]=i+1; x++; } if(a[i]==2) { q[y]=i+1; y++; } if(a[i]==3) { r[z]=i+1; z++; } } //printf("%d %d %d\n",x,y,z); int t=min(x,y,z); printf("%d\n",t); if(t==0) return 0; for(i=0;i<t;i++) printf("%d %d %d\n",p[i],q[i],r[i]); return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
a9b70553dcefd8aaa2237c1b2b49e168
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include <stdio.h> int main(void) { int n; scanf("%d", &n); int students[3][5000]; int cnts[3] = {0, 0, 0}; for(int i = 0; i < n; i++) { int a; scanf("%d", &a); students[a-1][cnts[a-1]] = i+1; cnts[a-1]++; } int smallest = cnts[0]; for(int i = 1; i < 3; i++) { if(cnts[i] < smallest) smallest = cnts[i]; } printf("%d\n", smallest); if(smallest) { for(int i = 0; i < smallest; i++) { printf("%d %d %d\n", students[0][i], students[1][i], students[2][i]); } } }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
db28aa183f5f7c078c71e6aed96d7a0e
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include <stdio.h> #include <stdlib.h> int min(int k, int l, int m){ if(m<=k&&m<=l){ return m; } else if(k<=m&&k<=l){ return k; } else{ return l; } } int main() { int n,team[5001],i,onepost[5001],twopostion[5001],threepostion[5001],k=0,l=0,m=0,teamnumber; scanf("%d",&n); for(i=0;i<n;++i){ scanf("%d",&team[i]); } for(i=0;i<n;++i){ if(team[i]==1){ onepost[k]=i+1; k++; } else if(team[i]==2){ twopostion[l]=i+1; l++; } else{ threepostion[m]=i+1; m++; } } teamnumber=min(k,l,m); printf("%d\n",teamnumber); for(i=0;i<teamnumber;++i){ printf("%d %d %d\n",onepost[i],twopostion[i],threepostion[i]); } return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
46d1018a83deb2e3c7d70161937c2c65
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include <stdio.h> #include <stdlib.h> int main() { int num,i,j=0,k=0,l=0,array[5001],array1[5001],array2[5001],array3[5001],team; scanf("%d",&num); for(i=0;i<num;++i){ scanf("%d",&array[i]); } for(i=0;i<num;++i){ if(array[i]==1){ array1[j]=i; j++; } else if(array[i]==2){ array2[k]=i; k++; } else{ array3[l]=i; l++; } } if(j<=k&&j<=l){ team=j; } else if(k<=j&&k<=l){ team=k; } else{ team=l; } printf("%d\n",team); for(i=0;i<team;++i){ printf("%d %d %d\n",array1[i]+1,array2[i]+1,array3[i]+1); } return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
195b48cbf3b97fcd137f8969e99e0c97
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> int main() { int n,t[10000],a=0,b=0,c=0,i,p,e[10000],f[10000],g[10000]; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&t[i]); if(t[i]==1) { e[a]=i; a++; } else if(t[i]==2) { f[b]=i; b++; } else if(t[i]==3) { g[c]=i; c++; } } if(a==0||b==0||c==0) { printf("0"); return 0; } if(a<=b&&a<=c) { p=a; } else if(b<=c&&b<=a) { p=b; } else { p=c; } printf("%d\n",p); for(i=0;i<p;i++) { printf("%d %d %d\n",e[i],f[i],g[i]); } return 0; }
There is a country with $$$n$$$ citizens. The $$$i$$$-th of them initially has $$$a_{i}$$$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $$$x$$$ are paid accordingly so that after the payout they have exactly $$$x$$$ money. In this case the citizens don't send a receipt.You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Print $$$n$$$ integers — the balances of all citizens after all events.
C
7b788c660fb8ca703af0030f4c84ce96
852ee8d505f20c21fe2e2d8041546906
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "data structures", "binary search", "sortings", "brute force" ]
1564497300
["4\n1 2 3 4\n3\n2 3\n1 2 2\n2 1", "5\n3 50 2 1 10\n3\n1 2 0\n2 8\n1 3 20"]
NoteIn the first example the balances change as follows: 1 2 3 4 $$$\rightarrow$$$ 3 3 3 4 $$$\rightarrow$$$ 3 2 3 4 $$$\rightarrow$$$ 3 2 3 4In the second example the balances change as follows: 3 50 2 1 10 $$$\rightarrow$$$ 3 0 2 1 10 $$$\rightarrow$$$ 8 8 8 8 10 $$$\rightarrow$$$ 8 8 20 8 10
PASSED
1,600
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^{5}$$$) — the numer of citizens. The next line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$0 \le a_{i} \le 10^{9}$$$) — the initial balances of citizens. The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^{5}$$$) — the number of events. Each of the next $$$q$$$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($$$1 \le p \le n$$$, $$$0 \le x \le 10^{9}$$$), or 2 x ($$$0 \le x \le 10^{9}$$$). In the first case we have a receipt that the balance of the $$$p$$$-th person becomes equal to $$$x$$$. In the second case we have a payoff with parameter $$$x$$$.
["3 2 3 4", "8 8 20 8 10"]
#include<stdio.h> #define MAX(a,b) a>b?a:b int tc[200000],x[200000]; int main() { int n; scanf("%d",&n); int current[n],i; for(i=0; i<n; i++) scanf("%d",&current[i]); int q; scanf("%d",&q); int serial,max=0,t,tx; for(i=0; i<q; i++) { scanf("%d",&serial); if(serial==1) { scanf("%d%d",&t,&tx); current[t-1]=tx; tc[t-1]=i; } else scanf("%d",&x[i]); } for(i=q-1; i>=0; i--) x[i]=MAX(x[i],x[i+1]); for(i=0; i<n; i++) printf("%d ",MAX(current[i],x[tc[i]])); return 0; }
There is a country with $$$n$$$ citizens. The $$$i$$$-th of them initially has $$$a_{i}$$$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.Sometimes the government makes payouts to the poor: all citizens who have strictly less money than $$$x$$$ are paid accordingly so that after the payout they have exactly $$$x$$$ money. In this case the citizens don't send a receipt.You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.
Print $$$n$$$ integers — the balances of all citizens after all events.
C
7b788c660fb8ca703af0030f4c84ce96
1fe8af35dbbc4c82f2a871becd0f835b
GNU C11
standard output
256 megabytes
train_000.jsonl
[ "data structures", "binary search", "sortings", "brute force" ]
1564497300
["4\n1 2 3 4\n3\n2 3\n1 2 2\n2 1", "5\n3 50 2 1 10\n3\n1 2 0\n2 8\n1 3 20"]
NoteIn the first example the balances change as follows: 1 2 3 4 $$$\rightarrow$$$ 3 3 3 4 $$$\rightarrow$$$ 3 2 3 4 $$$\rightarrow$$$ 3 2 3 4In the second example the balances change as follows: 3 50 2 1 10 $$$\rightarrow$$$ 3 0 2 1 10 $$$\rightarrow$$$ 8 8 8 8 10 $$$\rightarrow$$$ 8 8 20 8 10
PASSED
1,600
standard input
2 seconds
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^{5}$$$) — the numer of citizens. The next line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$0 \le a_{i} \le 10^{9}$$$) — the initial balances of citizens. The next line contains a single integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^{5}$$$) — the number of events. Each of the next $$$q$$$ lines contains a single event. The events are given in chronological order. Each event is described as either 1 p x ($$$1 \le p \le n$$$, $$$0 \le x \le 10^{9}$$$), or 2 x ($$$0 \le x \le 10^{9}$$$). In the first case we have a receipt that the balance of the $$$p$$$-th person becomes equal to $$$x$$$. In the second case we have a payoff with parameter $$$x$$$.
["3 2 3 4", "8 8 20 8 10"]
#include<stdio.h> #define MAX(a,b) a>b?a:b int tc[200000],x[200000]; int main() { int n; scanf("%d",&n); int current[n],i; for(i=0; i<n; i++) scanf("%d",&current[i]); int q; scanf("%d",&q); int serial,max=0,t,tx; for(i=0; i<q; i++) { scanf("%d",&serial); if(serial==1) { scanf("%d%d",&t,&tx); current[t-1]=tx; tc[t-1]=i; } else scanf("%d",&x[i]); } for(i=q-1; i>=0; i--) x[i]=MAX(x[i],x[i+1]); for(i=0; i<n; i++) printf("%d ",MAX(current[i],x[tc[i]])); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
9af15124a2eda317f02851efadfb158f
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include<stdio.h> #include<string.h> int main() { int n, i, j, count = 0; scanf ("%d", &n); char str[n][102]; for (i = 0; i < n; i++) { scanf ("%s", str[i]); } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if ((j + 1) < n && str[i][j + 1]=='o') count++; if ((j - 1)>= 0 && str[i][j - 1]=='o') count++; if ((i + 1) < n && str[i + 1][j]=='o') count++; if ((i - 1) >= 0 && str[i - 1][j]=='o') count++; if (count & 1) { printf ("NO\n"); return 0; } } } printf ("YES\n"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
18190a2e4bc0845f4d7473974f862bd9
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include <stdio.h> int main(){ int n; scanf("%d", &n); int i, j; char a[102][102]; for (i = 1; i <= n; i++) scanf("%s", a[i]); for (i = 1; i <= n; i++) for (j = n; j > 0; j--) a[i][j] = a[i][j-1]; for (i = 1; i <= n; i++){ a[0][i] = 'a'; a[n+1][i] = 'a'; a[i][n+1] = 'a'; a[i][0] = 'a'; } int kt = 1; for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) { int s = 0; if (a[i-1][j] == 'o') s++; if (a[i+1][j] == 'o') s++; if (a[i][j+1] == 'o') s++; if (a[i][j-1] == 'o') s++; if (s % 2 != 0) kt = 0; } if (kt) printf("YES"); else printf("NO"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
bcd09fbf55eaa5d57283e5dd185ea73a
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include <stdio.h> int main(){ int n; scanf("%d", &n); int i, j; char a[1002][1002]; for (i = 1; i <= n; i++) scanf("%s", a[i]); for (i = 1; i <= n; i++) for (j = n; j > 0; j--) a[i][j] = a[i][j-1]; for (i = 1; i <= n; i++){ a[0][i] = 'a'; a[n+1][i] = 'a'; a[i][n+1] = 'a'; a[i][0] = 'a'; } int kt = 1; for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) { int s = 0; if (a[i-1][j] == 'o') s++; if (a[i+1][j] == 'o') s++; if (a[i][j+1] == 'o') s++; if (a[i][j-1] == 'o') s++; if (s % 2 != 0) kt = 0; } if (kt) printf("YES"); else printf("NO"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
bf29f3150eeb29803f093b532a3d9f8d
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include<Stdio.h> int main() { int i,j,n,c=0; scanf("%d",&n); char s[105],a[n][n]; for(i=0;i<n;i++) { scanf("%s",s); for(j=0;j<n;j++) a[i][j]=s[j]; } for(i=0;i<n;i++) for(j=0;j<n;j++) { c=0; if(a[i-1][j]=='o'&&i>0) c++; if(a[i+1][j]=='o'&&i<n-1) c++; if(a[i][j-1]=='o'&&j>0) c++; if(a[i][j+1]=='o'&&j<n-1) c++; if(c%2) { printf("NO"); return 0; } } printf("YES"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
c689be621e26d936dcc6e2fd8b98e065
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include <stdio.h> int main() { int n, i, j; char a[105][105]; scanf("%d", &n); for(i=0; i<n; i++) scanf("%s", &a[i]); int flag=0, sum; for(i=0; i<n; i++) { for(j=0; j<n; j++) { sum=0; if(a[i][j+1]=='o') sum++; if(a[i+1][j]=='o') sum++; if(a[i-1][j]=='o') sum++; if(a[i][j-1]=='o') sum++; if(sum%2!=0) { printf("NO\n"); return 0; } } } printf("YES\n"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
4990d1f5558fb7041f5cac14bdbafed3
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include<stdio.h> int main() { int n,i,j,count=0; scanf("%d",&n); char a[n+1][n+1]; for(i=0;i<n;i++) { scanf("%s",&a[i]); } int flag =0; for(i=0;i<n;i++) { for(j=0;j<n;j++) { count =0; if(i-1>=0) { if(a[i-1][j]=='o') count++; } if(i+1<n) { if(a[i+1][j]=='o') count++; } if(j>0) { if(a[i][j-1]=='o') count++; } if(j<n-1) { if(a[i][j+1]=='o') count++; } if(count%2!=0) { flag =1; printf("NO"); break; } } if(flag==1) break; } if(flag==0) printf("YES"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
83c85093139c0233d629a54b5ea997c4
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include <stdio.h> int main() { int n, k, i, j, flag, count; char a[111][111]; scanf ("%d", &n); for (i = 0; i < n; i++) { scanf ("%c", &k); for (j = 0; j < n; j++) { scanf ("%c", &a[i][j]); } } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { count = 0; if (a[i+1][j] == 'o') { count++; } if (a[i][j-1] == 'o') { count++; } if (a[i-1][j] == 'o') { count++; } if (a[i][j+1] == 'o') { count++; } if (count%2 != 0) { printf ("NO\n"); return 0; } } } printf ("YES\n"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
98c8ac51cb3f1ce37d8693b11cf96f03
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include<stdio.h> int i,j,n,c=0; char a[101][101]; int main() { scanf("%d",&n); for(i=0;i<n;i++) { for(j=0;j<n;j++) { scanf(" %c",&a[i][j]); } } for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(a[i-1][j]=='o' && i-1>=0 ) c++; if(a[i][j-1]=='o' && j-1>=0) c++; if(a[i+1][j]=='o' && i+1<n) c++; if(a[i][j+1]=='o' && j+1<n) c++; if(c%2!=0) { printf("NO\n"); return 0; } } } printf("YES\n"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
3944af2d1e289f1cc6e6ecd84b3df9e9
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include<stdio.h> int i,j,n,c=0; char a[101][101]; int main() { scanf("%d",&n); for(i=0;i<n;i++) { for(j=0;j<n;j++) { scanf(" %c",&a[i][j]); } } for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(a[i-1][j]=='o' && i>=1 ) c++; if(a[i][j-1]=='o' && j>=1) c++; if(a[i+1][j]=='o' && i<=(n-2)) c++; if(a[i][j+1]=='o' && j<=(n-2)) c++; if(c%2!=0) { printf("NO\n"); return 0; } } } printf("YES\n"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
ac6f9542b22e1d2c387028a1b707c142
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include <stdio.h> #include <stdlib.h> int main() { int n,i,j,ocount=0; char c[100][100]; scanf("%d ",&n); for(i=0;i<n;i++) { scanf("%s",c[i]); } for(i=0;i<n;i++) { for(j=0;j<n;j++) { if((i < (n-1)) && (c[i+1][j] == 'o')) { ocount++; } if((i > 0) && (c[i-1][j] == 'o')) { ocount++; } if((j<(n-1)) && (c[i][j+1] == 'o')) { ocount++; } if((j>0) && (c[i][j-1] == 'o')) { ocount++; } if((ocount % 2) != 0) { printf("NO\n"); return 0; } } } printf("YES\n"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
286302edcedf6b820df881b305ae7585
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include <stdio.h> int main() { int n,i,j; scanf("%d",&n); int a[n][n]; getchar(); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { char temp; scanf("%c",&temp); if (temp == 'x') a[i][j] = 1; else a[i][j] = 0; } getchar(); } int f = 0; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { int ctr = 0; if (i+1 <= n-1 && a[i+1][j] == 0) ctr++; if (i-1 >= 0 && a[i-1][j] == 0) ctr++; if (j+1 <= n-1 && a[i][j+1] == 0) ctr++; if (j-1 >= 0 && a[i][j-1] == 0) ctr++; if (ctr % 2 != 0) { f = 1; printf("NO\n"); break; } } if (f == 1) break; } if (f == 0) printf("YES\n"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
60d0511909705592fa99616de30a8519
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include<stdio.h> char arr[250][250]; int main(){ int a; scanf("%d",&a); getchar(); int i,b; for(i=0;i<a;i++){ for(b=0;b<a;b++){ scanf("%c",&arr[i][b]); } getchar(); } for(i=0;i<a;i++){ int cnt=0; for(b=0;b<a;b++){ if(arr[i][b+1]=='o') cnt++; if(arr[i][b-1]=='o') cnt++; if(arr[i+1][b]=='o') cnt++; if(arr[i-1][b]=='o') cnt++; if(cnt%2){ printf("NO"); return 0; } } } printf("YES"); }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
5b3ee389e2c5aaa57345560660f70437
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include<stdio.h> int main() { int i,j,c=0,flag=0; int n; scanf("%d",&n); getchar(); char a[n][n]; for(i=0;i<n;i++) { for(j=0;j<n;j++) { scanf("%c",&a[i][j]); // printf("%c",a[i][j]); } getchar(); // printf("\n"); } for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(i+1<n) { if(a[i+1][j]=='o') c++; } if(i-1>=0) { if(a[i-1][j]=='o') c++; } if(j+1<n) { if(a[i][j+1]=='o') c++; } if(j-1>=0) { if(a[i][j-1]=='o') c++; } if(c%2!=0) { flag=1; break; } c=0; } if (flag==1) break; } if(flag==1) printf("NO\n"); else printf("YES\n"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
a768afb53a263801c0c8e694621e176f
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
/* Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side. Input The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces. Output Print "YES" or "NO" (without the quotes) depending on the answer to the problem. Sample test(s) Input 3 xxo xox oxx Output YES Input 4 xxxo xoxo oxox xxxx Output NO */ #include<stdio.h> int main() { int n; scanf("%d",&n); char arr[n][n],in[n]; int i,j; for(i=0;i<n;i++) { scanf("%s",in); for(j=0;in[j]!='\0';j++) { arr[i][j]=in[j]; } } int c=0; int flag=0; for(i=0;i<n;i++) { for(j=0;j<n;j++) { c=0; //if(arr[i][j]=='x') { if(j-1>-1 && arr[i][j-1]=='o') c++; if(i-1>-1 && arr[i-1][j]=='o') c++; if(j+1<n && arr[i][j+1]=='o') c++; if(i+1<n && arr[i+1][j]=='o') c++; } if(c%2!=0) flag=1; } } if(flag==0) printf("YES\n"); else printf("NO\n"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
adb188a63d791fd6e6de2c598dcb7477
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include<stdio.h> int main() { int n,i,p,q,r,s,sum,j; char a[101][101]; scanf("%d",&n); for(i=0;i<n;i++) scanf("%s",a[i]); for(i=0;i<n;i++) { for(j=0;j<n;j++) { sum=0; p=j-1; q=j+1; r=i-1; s=i+1; if(p>=0 && a[i][p]=='o') sum++; if(q<=n && a[i][q]=='o') sum++; if(r>=0 && a[r][j]=='o') sum++; if(s<=n && a[s][j]=='o') sum++; if(sum%2!=0) { printf("NO"); goto A; } } } printf("YES"); A: return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
b0f633037732103f26bb153751712ffe
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include <stdio.h> int n, i, j, sum; char a[105][105]; int main () { scanf("%d",&n); for(i = 1 ; i <= n ; i++) for(j = 1 ; j <= n ; j++) scanf(" %c",&a[i][j]); for(i = 1 ; i <= n ; i++) for(j = 1 ; j <= n ; j++, sum = 0){ if(a[i-1][j] == 'o')sum++; if(a[i+1][j] == 'o')sum++; if(a[i][j-1] == 'o')sum++; if(a[i][j+1] == 'o')sum++; if(sum%2){ printf("NO"); return 0; } } printf("YES"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
76710c1f30404acca17ab6fa65eca4c3
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include <stdio.h> #define MAXN 100 typedef enum bool {FALSE,TRUE} bool; int n; int a [MAXN+2][MAXN+2]; int main (void) { scanf("%d",&n); int i, j; char s [MAXN+1]; for (i=1; i<=n; i++) { scanf("%s",s); for (j=1; j<=n; j++) { if (s[j-1]=='x') a[i][j] = 0; else a[i][j] = 1; } } for (i=0; i<=n+1; i++) a[i][0] = a[i][n+1] = 0; for (j=1; j<=n; j++) a[0][j] = a[n+1][j] = 0; bool ok = TRUE; for (i=1; i<=n; i++) { for (j=1; j<=n; j++) { if ((a[i-1][j]+a[i][j-1]+a[i+1][j]+a[i][j+1])%2==1) { ok = FALSE; break; } } if (!ok) break; } if (ok) puts("YES"); else puts("NO"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
3f5320140f4138039c95c7dac5015260
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include<stdio.h> char c[101][101]; int main(){ int n, sum = 0, i, j; scanf("%d", &n); for(i=0; i<n; i++){ for(j=0; j<n; j++){ scanf("%c", &c[i][j]); if(c[i][j] == '\n') scanf("%c", &c[i][j]); } } for(i=0; i<n; i++){ for(j=0; j<n; j++){ if(c[i+1][j] == 'o') sum++; if(c[i-1][j] == 'o') sum++; if(c[i][j+1] == 'o') sum++; if(c[i][j-1] == 'o') sum++; if(sum%2 == 1){ printf("NO\n"); return 0; } } } printf("YES\n"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
825c47e354a4fc0322aebf7642fa6226
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include<stdio.h> int main() { int n,i,j; scanf("%d",&n); char a[101][101]; for(i=0;i<n;i++) { scanf(" %s",a[i]); } int count; for(i=0;i<n;i++) { for(j=0;j<n;j++) { count=0; if(i-1>=0 && a[i-1][j]=='o')count++; if(i+1<n && a[i+1][j]=='o')count++; if(j-1>=0 && a[i][j-1]=='o')count++; if(j+1<n && a[i][j+1]=='o')count++; if(count&1)break; } if(j<n)break; } if(i==n && j==n) printf("YES"); else printf("NO"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
f7f5f867957e4c52b1bada7af385c87f
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include<stdio.h> int main() { char ch; int i,j,n,cnt,flag=0; char mat[101][101]; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%s",mat[i]); } /*for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%c",mat[i][j]); } printf("\n"); }*/ for(i=0;i<n;i++) { for(j=0;j<n;j++) { cnt=0; if((i-1)>=0 && mat[i-1][j]=='o') { cnt++; } if((j-1)>=0 && mat[i][j-1]=='o') { cnt++; } if((i+1)<n && mat[i+1][j]=='o') { cnt++; } if((j+1)<n && mat[i][j+1]=='o') { cnt++; } //printf("%d\n",cnt); if(cnt%2) { flag=1; break; } } if(flag) break; } if(flag) { printf("NO"); } else { printf("YES"); } return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
e17a2657588577204d8d81b0cfb17226
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include<stdio.h> int main() { int n,i,j,p=0,q=0,count=0,count1=0; char A[101][101]; scanf("%d",&n); for(i=0;i<n;i++) { scanf("\n"); for(j=0;j<n;j++) { scanf("%c",&A[i][j]); } } if(n==1) { printf("YES"); return 0; } for(i=0;i<n;i++) { for(j=0;j<n;j++) { count=0; if(i>0) { if(A[i-1][j]=='o') count++; } if(A[i+1][j]=='o') count++; if(j>0) { if(A[i][j-1]=='o') count++; } if(A[i][j+1]=='o') count++; if((count%2)==0) count1++; } } if(count1==(n*n)) printf("YES"); else printf("NO"); /*for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%c ",A[i][j]); } printf("\n"); }*/ return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
b07191d0669a983060881560c52a2819
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include<stdio.h> int main() { int n,i,j,p=0,q=0,count=0,count1=0; char A[101][101]; scanf("%d",&n); for(i=0;i<n;i++) { scanf("\n"); for(j=0;j<n;j++) { scanf("%c",&A[i][j]); } } if(n==1) { printf("YES"); return 0; } for(i=0;i<n;i++) { for(j=0;j<n;j++) { count=0; if(i>0) { if(A[i-1][j]=='o') count++; } if(A[i+1][j]=='o') count++; if(j>0) { if(A[i][j-1]=='o') count++; } if(A[i][j+1]=='o') count++; if((count%2)==0) count1++; } } if(count1==(n*n)) printf("YES"); else printf("NO"); /*for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%c ",A[i][j]); } printf("\n"); }*/ return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
9be99d7ff59694e43fefda2b642d15c7
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include<stdio.h> #include<string.h> #define loop(i,a,b) for(int i=a;i<b;i++) int main(){ int n,t; scanf("%d",&n); char cb[n][n]; loop(i,0,n){ scanf("%s",cb[i]); } loop(i,0,n){ loop(j,0,n){ t=0; if(i-1>=0){ if(cb[i-1][j]=='o'){ t++; } } if(i<n-1){ if(cb[i+1][j]=='o'){ t++; } } if(j<n-1){ if(cb[i][j+1]=='o'){ t++; } } if(j-1>=0){ if(cb[i][j-1]=='o'){ t++; } } if(t%2!=0){ printf("NO"); return(0); } } } printf("YES"); return(0); }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
a068ab2ef37d4d686202fc7f37a77fbb
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include<stdio.h> char ar[100][100]; int check_horizontal(int a, int b,int n) { int counter=0; if((b-1)>=0 && ar[a][b-1]=='o') counter++; if((a-1)>=0 && ar[a-1][b]=='o') counter++; if((b+1)<=(n-1) && ar[a][b+1]=='o') counter++; if((a+1)<=(n-1) && ar[a+1][b]=='o') counter++; return counter; } int check_possible(int n) { int h,i,j; for(i=0;i<n;i++) { for(j=0;j<n;j++) { h=check_horizontal(i,j,n); if(h%2!=0) return 0; } } return 1; } int main() { int n,flag=1,i,j; char str[100]; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%s",&str); for(j=0;j<n;j++) ar[i][j]=str[j]; } flag=check_possible(n); if(flag==1) printf("YES"); if(flag==0) printf("NO"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
4cf2ff28149330a44938685f560b626b
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include<stdio.h> int main () { int i ,n , j; char c[100][101] ; scanf ("%d" , &n) ; int counter ; for(i = 0; i < n; ++i) scanf ("%s" , c[i] ) ; for(i = 0; i < n; ++i){ counter= 0; for(j = 0; j < n; ++j){ if ( i -1 >= 0 ) if(c[i - 1][j] == 'o') counter++; if ( i + 1 < n ) if(c[i + 1][j] == 'o') counter++; if ( j - 1 >= 0 ) if(c[i][j - 1] == 'o') counter++; if ( j + 1 < n ) if(c[i][j + 1] == 'o') counter++; if( counter % 2 ) { puts ("NO") ; return 0 ; } } } puts ("YES") ; return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
24074e193bafcd966a12d804557f30b5
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include <stdio.h> #include <string.h> int main() { int i, j, k, l, m, n; scanf("%d", &n); char a[n][n + 1]; for(i = 0; i < n; i++) { scanf("%s", a[i]); } for(i = 0; i < n; i++) { for(j = 0; j < n; j++) { k = 0; if(i+1 < n && a[i + 1][j] == 'o') { k++; } if(j+1 < n && a[i][j + 1] == 'o') { k++; } if(i - 1 >= 0 && a[i - 1][j] == 'o') { k++; } if(j - 1 >= 0 && a[i][j - 1] == 'o') { k++; } if(k % 2) { printf("NO\n"); return 0; } } } printf("YES\n"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
8a9ed61bd4a26b133697f3945e1a4c77
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include <stdio.h> #include <string.h> int main(){ char p[101][101] ; int i , j, k=0 , n ; scanf("%d", &n) ; for(i=0;i<n;i++){ scanf("%s", &p[i]) ; } for(i=0;i < n;i++){ k= 0 ; for(j=0;j<n;j++){ if(p[i+1][j] == 'o'){ k++ ; // printf("a%d\n",k) ; } if(p[i-1][j] == 'o'){ k++ ; // printf("c%d\n",k) ; } if(p[i][j+1] =='o'){ k++ ; // printf("d%dn",k) ; } if(p[i][j-1] =='o'){ k++ ; // printf("%d\n",k) ; } if(k%2 != 0){ printf("NO") ; return 0 ; } } } printf("YES"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
6a53db393e0242b7d8440dda84011c24
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> int main (int argc, char * argv[]) { int n; scanf ("%d\n", &n); char black_hole; char ** board = (char **) malloc (sizeof(char *) * n); for (int i = 0; i < n; i++) { board[i] = (char *) malloc (sizeof(char) * n); for (int j = 0; j < n; j++) { scanf ("%c", &board[i][j]); } scanf ("%c", &black_hole); // The tailing '\n' } bool ok = true; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int os = 0; if (i > 0 && 'o' == board[i - 1][j]) { os++; } if (i < n - 1 && 'o' == board[i + 1][j]) { os++; } if (j > 0 && 'o' == board[i][j - 1]) { os++; } if (j < n - 1 && 'o' == board[i][j + 1]) { os++; } if (os % 2 != 0) { ok = false; break; } } } if (ok) { printf ("YES\n"); } else { printf ("NO\n"); } for (int i = 0; i < n; i++) { free (board[i]); } free (board); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
14871fa7b5531bc8bc28e4c6abd2da0b
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include<stdio.h> char mat[101][101]; int main() { int n; scanf("%d", &n); int i, j, a=0; for(i=0; i<n; i++) { scanf("%s", &mat[i]); } for(i=0; i<n-1; i++) { a=0; for(j=0; j<n; j++) { if(mat[i+1][j]=='o') a++; if(mat[i-1][j]=='o') a++; if(mat[i][j+1]=='o') a++; if(mat[i][j-1]=='o') a++; //printf("%d\n", a); if(a%2!=0) { printf("NO"); return 0; } } } printf("YES"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
7e84ce58351dd1c23a2654a251a98421
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include <stdio.h> int main() { char tempc; int a[104][104] = {0}; int i, flag = 0, n, j, temp; // STDIN scanf("%d\n", &n); for(i=1; i<=n; i++) { for(j=1; j<=n; j++) { scanf("%c", &tempc); if(tempc == 'o') a[i][j] = 1; } scanf("%c", &temp); } // GO ON for(i=1; i<=n; i++) for(j=1; j<=n; j++) { temp = a[i-1][j] + a[i+1][j] + a[i][j-1] + a[i][j+1]; if(temp%2 != 0) flag = 1; } if(flag == 1) printf("NO"); else printf("YES"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
a9594c7f6463237337972a5680699283
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include <stdio.h> int main() { int i, j, n, cnt, yes; static char a[100][101]; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%s", a[i]); yes = 1; for (i = 0; i < n; i++) for (j = 0; j < n; j++) { cnt = 0; if (i > 0 && a[i - 1][j] == 'o') cnt++; if (i + 1 < n && a[i + 1][j] == 'o') cnt++; if (j > 0 && a[i][j - 1] == 'o') cnt++; if (j + 1 < n && a[i][j + 1] == 'o') cnt++; if (cnt % 2 != 0) { yes = 0; break; } } printf("%s\n", yes ? "YES" : "NO"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
96aded186d02618af37be46a664ec299
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include<stdio.h> int main() { int n,i,j,c=0,count,u; char chk[100][100]; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%s",&chk[i]); } for(i=0;i<n;i++) { for(j=0;j<n;j++) { count=0; if((i-1>=0)&&(chk[i-1][j]=='o')) count++; if((i+1<n)&&(chk[i+1][j]=='o')) count++; if((j+1<n)&&(chk[i][j+1]=='o')) count++; if((j-1>=0)&&(chk[i][j-1]=='o')) count++; u=count%2; if(u==1) { c=1; break; } else continue; } if(c==1) break; else continue; } if(c==1) printf("NO\n"); else printf("YES\n"); return 0; }
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
C
03fcf7402397b94edd1d1837e429185d
83742a6ad175a930904295cc6b29380f
GNU C
standard output
256 megabytes
train_000.jsonl
[ "implementation", "brute force" ]
1409061600
["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx"]
null
PASSED
1,000
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.
["YES", "NO"]
#include <stdio.h> #include <stdlib.h> int main() { int n, i, j, k; scanf("%d", &n); char c[n][n+1]; for (i = 0; i < n; ++i) { scanf("%s", &c[i]); } for (i = 0; i < n; ++i) { for (j = 0; j < n; ++j) { k = 0; if (i == 0) { if (j == 0) { if (c[i][j+1] == 'o') { k++; } if (c[i+1][j] == 'o') { k++; } if ((k % 2) != 0) { printf("NO\n"); exit(0); } } else if (j == n-1) { if (c[i][j-1] == 'o') { k++; } if (c[i+1][j] == 'o') { k++; } if ((k % 2) != 0) { printf("NO\n"); exit(0); } } else { if (c[i][j+1] == 'o') { k++; } if (c[i+1][j] == 'o') { k++; } if (c[i][j-1] == 'o') { k++; } if ((k % 2) != 0) { printf("NO\n"); exit(0); } } } else if (i == n-1) { if (j == 0) { if (c[i][j+1] == 'o') { k++; } if (c[i-1][j] == 'o') { k++; } if ((k % 2) != 0) { printf("NO\n"); exit(0); } } else if (j == n-1) { if (c[i][j-1] == 'o') { k++; } if (c[i-1][j] == 'o') { k++; } if ((k % 2) != 0) { printf("NO\n"); exit(0); } } else { if (c[i][j+1] == 'o') { k++; } if (c[i-1][j] == 'o') { k++; } if (c[i][j-1] == 'o') { k++; } if ((k % 2) != 0) { printf("NO\n"); exit(0); } } } else { if (j == 0) { if (c[i][j+1] == 'o') { k++; } if (c[i+1][j] == 'o') { k++; } if (c[i-1][j] == 'o') { k++; } if ((k % 2) != 0) { printf("NO\n"); exit(0); } } else if (j == n-1) { if (c[i][j-1] == 'o') { k++; } if (c[i+1][j] == 'o') { k++; } if (c[i-1][j] == 'o') { k++; } if ((k % 2) != 0) { printf("NO\n"); exit(0); } } else { if (c[i][j+1] == 'o') { k++; } if (c[i+1][j] == 'o') { k++; } if (c[i][j-1] == 'o') { k++; } if (c[i-1][j] == 'o') { k++; } if ((k % 2) != 0) { printf("NO\n"); exit(0); } } } } } printf("YES\n"); return 0; }
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
C
bda2ca1fd65084bb9d8659c0a591743d
92c1e21e52118048d37bb1090c9ce58d
GNU C11
standard output
64 megabytes
train_000.jsonl
[ "shortest paths", "graphs" ]
1276875000
["5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1"]
null
PASSED
1,900
standard input
1 second
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that the graph has loops and multiple edges between pair of vertices.
["1 4 3 5", "1 4 3 5"]
#include <stdio.h> #include <string.h> #include <limits.h> #include <stdlib.h> #define int long long int struct adjacencylist { int nodeindex; int weight; struct adjacencylist* adj; }; struct minheap { int mindist; int vertex; }; struct adjacencylist *graph[100002],*traverse; int swap(int *a,int *b){ int temp=*a; *a=*b; *b=temp;} int minimum(int a, int b){ if(a<=b)return a; else return b;} int add_edge(int a,int b,int distance) { traverse=(struct adjacencylist*)malloc(sizeof(struct adjacencylist)); traverse->adj=graph[a]; traverse->nodeindex=b; traverse->weight=distance; graph[a]=traverse; } int main() { int nodes,edges,distance,a,b,update,parent,pick,cur,ok=0,adjacent,edge,c1,c2,small,stop; scanf("%lld%lld",&nodes,&edges); //nodes and edges int adjac[nodes+1],previous[nodes+1]; memset(adjac,0,sizeof(adjac)); struct adjacencylist *ptr; //graph input in linked list begins for(int i=0;i<edges;i++) { scanf("%lld%lld%lld",&a,&b,&distance); adjac[a]++; add_edge(a,b,distance); add_edge(b,a,distance); adjac[b]++; } //Djkstra algorithm int source=1; int visit[nodes+1],dist[nodes+1]; for(int i=1;i<=nodes;i++){dist[i]=LLONG_MAX; visit[i]=0;} visit[source]=1; dist[source]=0; //Building Minimum Heap struct minheap* heap=(struct minheap*)malloc((nodes+1)*sizeof(struct minheap)); int cnt=1; int map[nodes+1]; heap[1].mindist=dist[source]; heap[1].vertex=source; map[heap[1].vertex]=1; cnt++; for(int i=1;i<=nodes;i++) { if(i==source){previous[i]=1;continue;} else if(i!=source)previous[i]=-1; heap[cnt].mindist=dist[i]; heap[cnt].vertex=i; map[heap[cnt].vertex]=cnt; cnt++; } int heapsize=cnt-1; while(heapsize>0) { pick=heap[1].vertex; /*Deletion in Min. Heap*/ map[heap[heapsize].vertex]=map[heap[1].vertex]; heap[1].mindist=heap[heapsize].mindist; heap[1].vertex=heap[heapsize].vertex; heapsize--; /*Compare the first node with it's child nodes*/ cur=1; while(1) { c1=2*cur; //left child c2=(2*cur)+1; //right child small=LLONG_MAX; if(c1<=heapsize && heap[c1].mindist<heap[cur].mindist)small=c1; if(c2<=heapsize && heap[c2].mindist<heap[cur].mindist) { if(small!=LLONG_MAX){if(heap[c2].mindist<heap[small].mindist)small=c2;} else if(small==LLONG_MAX)small=c2; } if(small==LLONG_MAX)break; swap(&map[heap[small].vertex],&map[heap[cur].vertex]); swap(&heap[small].mindist,&heap[cur].mindist); swap(&heap[small].vertex,&heap[cur].vertex); cur=small; } //Relax the nodes adjacent to picked vertexk ptr=graph[pick]; ok=0,adjacent,edge; stop=adjac[pick]; while(stop>0 && dist[pick]!=LLONG_MAX) { adjacent=ptr->nodeindex; edge=ptr->weight; if(map[adjacent]<=heapsize && dist[pick]+edge<dist[adjacent] && dist[pick]!=LLONG_MAX && edge>=0) { dist[adjacent]=dist[pick]+edge;//relaxation of nodes adjacent to picked vertex previous[adjacent]=pick; update=map[adjacent]; heap[update].mindist=dist[pick]+edge; parent=update/2; while(heap[update].mindist<heap[parent].mindist && parent>=1 && update>=1) { swap(&map[heap[parent].vertex],&map[heap[update].vertex]); swap(&heap[update].mindist,&heap[parent].mindist); swap(&heap[update].vertex,&heap[parent].vertex); update=parent; parent=update/2; } } ptr=ptr->adj; stop--; } } int shortestpath[nodes+1],index=1,answer_exist=1,prev=nodes; shortestpath[index]=nodes; index++; while(1) { prev=previous[prev]; if(prev==-1){answer_exist=0;break;} shortestpath[index]=prev; if(prev==1){break;} index++; } if(answer_exist==0){printf("-1\n");return 0;} for(int i=index;i>0;i--) printf("%lld ",shortestpath[i]); printf("\n"); free(graph); free(heap); free(traverse); free(ptr); return 0; }
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
C
bda2ca1fd65084bb9d8659c0a591743d
76f03ac09949f74f113ff97e51c71140
GNU C11
standard output
64 megabytes
train_000.jsonl
[ "shortest paths", "graphs" ]
1276875000
["5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1"]
null
PASSED
1,900
standard input
1 second
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that the graph has loops and multiple edges between pair of vertices.
["1 4 3 5", "1 4 3 5"]
#include <stdio.h> #include <string.h> #include <limits.h> #include <stdlib.h> #define int long long int struct adjacencylist { int nodeindex; int weight; struct adjacencylist* adj; }; struct minheap { int mindist; int vertex; }; struct minheap* heap; struct adjacencylist *graph[100002],*traverse; int nodes,edges,distance,a,b,update,parent,pick,cur,ok=0,adjacent,edge,c1,c2,small,stop,source,heapsize; int index,answer_exist,prev,cnt; struct adjacencylist *ptr; int swap(int *a,int *b){ int temp=*a; *a=*b; *b=temp;} int minimum(int a, int b){ if(a<=b)return a; else return b;} int add_edge(int a,int b,int distance) { traverse=(struct adjacencylist*)malloc(sizeof(struct adjacencylist)); traverse->adj=graph[a]; traverse->nodeindex=b; traverse->weight=distance; graph[a]=traverse; } int build_minheap(int *dist,int *previous,int *map) { cnt=1; heap[1].mindist=dist[source]; heap[1].vertex=source; map[heap[1].vertex]=1; cnt++; for(int i=1;i<=nodes;i++) { if(i==source){previous[i]=1;continue;} else if(i!=source)previous[i]=-1; heap[cnt].mindist=dist[i]; heap[cnt].vertex=i; map[heap[cnt].vertex]=cnt; cnt++; } } int delete_min(int map[]) { map[heap[heapsize].vertex]=map[heap[1].vertex]; heap[1].mindist=heap[heapsize].mindist; heap[1].vertex=heap[heapsize].vertex; heapsize--; /*Compare the first node with it's child nodes*/ cur=1; while(1) { c1=2*cur; //left child c2=(2*cur)+1; //right child small=LLONG_MAX; if(c1<=heapsize && heap[c1].mindist<heap[cur].mindist)small=c1; if(c2<=heapsize && heap[c2].mindist<heap[cur].mindist) { if(small!=LLONG_MAX){if(heap[c2].mindist<heap[small].mindist)small=c2;} else if(small==LLONG_MAX)small=c2; } if(small==LLONG_MAX)break; swap(&map[heap[small].vertex],&map[heap[cur].vertex]); swap(&heap[small].mindist,&heap[cur].mindist); swap(&heap[small].vertex,&heap[cur].vertex); cur=small; } } int decrease_key(int map[]) { parent=update/2; while(heap[update].mindist<heap[parent].mindist && parent>=1 && update>=1) { swap(&map[heap[parent].vertex],&map[heap[update].vertex]); swap(&heap[update].mindist,&heap[parent].mindist); swap(&heap[update].vertex,&heap[parent].vertex); update=parent; parent=update/2; } } int dijkstra_minheap(int *map ,int *adjac,int* dist,int *previous) { heapsize=cnt-1; while(heapsize>0) { pick=heap[1].vertex; delete_min(map); /*Deletion in Min. Heap*/ //Relax the nodes adjacent to picked vertexk ptr=graph[pick]; ok=0,adjacent,edge; stop=adjac[pick]; while(stop>0 && dist[pick]!=LLONG_MAX) { adjacent=ptr->nodeindex; edge=ptr->weight; if(map[adjacent]<=heapsize && dist[pick]+edge<dist[adjacent] && dist[pick]!=LLONG_MAX && edge>=0) { dist[adjacent]=dist[pick]+edge;//relaxation of nodes adjacent to picked vertex previous[adjacent]=pick; update=map[adjacent]; heap[update].mindist=dist[pick]+edge; decrease_key(map); } ptr=ptr->adj; stop--; } } } int print_path(int *previous) { int shortestpath[nodes+1]; index=1,answer_exist=1,prev=nodes; shortestpath[index]=nodes; index++; while(1) { prev=previous[prev]; if(prev==-1){answer_exist=0;break;} shortestpath[index]=prev; if(prev==1){break;} index++; } if(answer_exist==0){printf("-1\n");return 0;} for(int i=index;i>0;i--) printf("%lld ",shortestpath[i]); printf("\n"); } int main() { scanf("%lld%lld",&nodes,&edges); //nodes and edges int adjac[nodes+1],previous[nodes+1],map[nodes+1];; memset(adjac,0,sizeof(adjac)); heap=(struct minheap*)malloc((nodes+1)*sizeof(struct minheap)); //graph input in linked list begins for(int i=0;i<edges;i++) { scanf("%lld%lld%lld",&a,&b,&distance); adjac[a]++; add_edge(a,b,distance); add_edge(b,a,distance); adjac[b]++; } //Djkstra algorithm source=1; int visit[nodes+1],dist[nodes+1]; for(int i=1;i<=nodes;i++){dist[i]=LLONG_MAX; visit[i]=0;} visit[source]=1; dist[source]=0; //Building Minimum Heap build_minheap(&dist,&previous,&map); //dijkstra dijkstra_minheap(&map,&adjac,&dist,&previous); //printing path from source to node to destination node 'n' print_path(&previous); free(graph); free(heap); free(traverse); free(ptr); return 0; }
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
C
bda2ca1fd65084bb9d8659c0a591743d
935b226cde59743816be7a4a5d1eced8
GNU C11
standard output
64 megabytes
train_000.jsonl
[ "shortest paths", "graphs" ]
1276875000
["5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1"]
null
PASSED
1,900
standard input
1 second
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that the graph has loops and multiple edges between pair of vertices.
["1 4 3 5", "1 4 3 5"]
#include <stdio.h> #include <string.h> #include <limits.h> #include <stdlib.h> #define int long long int struct adjacencylist { int nodeindex; int weight; struct adjacencylist* adj; }; struct minheap { int mindist; int vertex; }; struct adjacencylist *graph[100002],*traverse; int swap(int *a,int *b){ int temp=*a; *a=*b; *b=temp;} int minimum(int a, int b){ if(a<=b)return a; else return b;} int add_edge(int a,int b,int distance) { traverse=(struct adjacencylist*)malloc(sizeof(struct adjacencylist)); traverse->adj=graph[a]; traverse->nodeindex=b; traverse->weight=distance; graph[a]=traverse; } int main() { int nodes,edges,distance,a,b; scanf("%lld%lld",&nodes,&edges); //nodes and edges int adjac[nodes+1],previous[nodes+1]; memset(adjac,0,sizeof(adjac)); struct adjacencylist *ptr; //graph input in linked list begins for(int i=0;i<edges;i++) { scanf("%lld%lld%lld",&a,&b,&distance); adjac[a]++; add_edge(a,b,distance); add_edge(b,a,distance); adjac[b]++; } //graph input in linked list ends //Djkstra algorithm int source=1; int visit[nodes+1],dist[nodes+1]; for(int i=1;i<=nodes;i++)dist[i]=LLONG_MAX; for(int i=1;i<=nodes;i++)visit[i]=0; visit[source]=1; dist[source]=0; //Building Minimum Heap struct minheap* heap=(struct minheap*)malloc((nodes+1)*sizeof(struct minheap)); int cnt=1; int map[nodes+1]; heap[1].mindist=dist[source]; heap[1].vertex=source; map[heap[1].vertex]=1; cnt++; for(int i=1;i<=nodes;i++) { if(i==source){previous[i]=1;continue;} else if(i!=source)previous[i]=-1; heap[cnt].mindist=dist[i]; heap[cnt].vertex=i; map[heap[cnt].vertex]=cnt; cnt++; } int heapsize=cnt-1; while(heapsize>0) { int pick=heap[1].vertex; /*Deletion in Min. Heap*/ map[heap[heapsize].vertex]=map[heap[1].vertex]; heap[1].mindist=heap[heapsize].mindist; heap[1].vertex=heap[heapsize].vertex; heapsize--; /*Compare the first node with it's child nodes*/ int cur=1; while(1) { int c1=2*cur; //left child int c2=(2*cur)+1; //right child int small=LLONG_MAX; if(c1<=heapsize && heap[c1].mindist<heap[cur].mindist)small=c1; if(c2<=heapsize && heap[c2].mindist<heap[cur].mindist) { if(small!=LLONG_MAX){if(heap[c2].mindist<heap[small].mindist)small=c2;} else if(small==LLONG_MAX)small=c2; } if(small==LLONG_MAX)break; swap(&map[heap[small].vertex],&map[heap[cur].vertex]); swap(&heap[small].mindist,&heap[cur].mindist); swap(&heap[small].vertex,&heap[cur].vertex); cur=small; } //Relax the nodes adjacent to picked vertexk ptr=graph[pick]; int ok=0,adjacent,edge; int stop=adjac[pick]; while(stop>0 && dist[pick]!=LLONG_MAX) { adjacent=ptr->nodeindex; edge=ptr->weight; if(map[adjacent]<=heapsize && dist[pick]+edge<dist[adjacent] && dist[pick]!=LLONG_MAX && edge>=0) { dist[adjacent]=dist[pick]+edge;//relaxation of nodes adjacent to picked vertex previous[adjacent]=pick; int update=map[adjacent]; heap[update].mindist=dist[pick]+edge; int parent=update/2; while(heap[update].mindist<heap[parent].mindist && parent>=1 && update>=1) { swap(&map[heap[parent].vertex],&map[heap[update].vertex]); swap(&heap[update].mindist,&heap[parent].mindist); swap(&heap[update].vertex,&heap[parent].vertex); update=parent; parent=update/2; } } ptr=ptr->adj; stop--; } } int shortestpath[nodes+1],index=1,answer_exist=1,prev=nodes; shortestpath[index]=nodes; index++; while(1) { prev=previous[prev]; if(prev==-1){answer_exist=0;break;} shortestpath[index]=prev; if(prev==1){break;} index++; } if(answer_exist==0){printf("-1\n");return 0;} for(int i=index;i>0;i--) printf("%lld ",shortestpath[i]); printf("\n"); free(graph); free(heap); free(traverse); free(ptr); return 0; }
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
C
bda2ca1fd65084bb9d8659c0a591743d
05b55ec6e547a14ad38bd63c0a5b60b0
GNU C11
standard output
64 megabytes
train_000.jsonl
[ "shortest paths", "graphs" ]
1276875000
["5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1"]
null
PASSED
1,900
standard input
1 second
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that the graph has loops and multiple edges between pair of vertices.
["1 4 3 5", "1 4 3 5"]
#include <stdio.h> #include <string.h> #include <limits.h> #include <stdlib.h> #define int long long int struct adjacencylist { int nodeindex; int weight; struct adjacencylist* adj; }; struct minheap { int mindist; int vertex; }; struct adjacencylist *graph[100002],*traverse; int swap(int *a,int *b){ int temp=*a; *a=*b; *b=temp;} int minimum(int a, int b){ if(a<=b)return a; else return b;} int add_edge(int a,int b,int distance) { traverse=(struct adjacencylist*)malloc(sizeof(struct adjacencylist)); traverse->adj=graph[a]; traverse->nodeindex=b; traverse->weight=distance; graph[a]=traverse; } int main() { int nodes,edges,distance,a,b,update,parent,pick,cur,ok=0,adjacent,edge,c1,c2,small,stop; scanf("%lld%lld",&nodes,&edges); //nodes and edges int adjac[nodes+1],previous[nodes+1]; memset(adjac,0,sizeof(adjac)); struct adjacencylist *ptr; //graph input in linked list begins for(int i=0;i<edges;i++) { scanf("%lld%lld%lld",&a,&b,&distance); adjac[a]++; add_edge(a,b,distance); add_edge(b,a,distance); adjac[b]++; } //graph input in linked list ends //Djkstra algorithm int source=1; int visit[nodes+1],dist[nodes+1]; for(int i=1;i<=nodes;i++){dist[i]=LLONG_MAX; visit[i]=0;} visit[source]=1; dist[source]=0; //Building Minimum Heap struct minheap* heap=(struct minheap*)malloc((nodes+1)*sizeof(struct minheap)); int cnt=1; int map[nodes+1]; heap[1].mindist=dist[source]; heap[1].vertex=source; map[heap[1].vertex]=1; cnt++; for(int i=1;i<=nodes;i++) { if(i==source){previous[i]=1;continue;} else if(i!=source)previous[i]=-1; heap[cnt].mindist=dist[i]; heap[cnt].vertex=i; map[heap[cnt].vertex]=cnt; cnt++; } int heapsize=cnt-1; while(heapsize>0) { pick=heap[1].vertex; /*Deletion in Min. Heap*/ map[heap[heapsize].vertex]=map[heap[1].vertex]; heap[1].mindist=heap[heapsize].mindist; heap[1].vertex=heap[heapsize].vertex; heapsize--; /*Compare the first node with it's child nodes*/ cur=1; while(1) { c1=2*cur; //left child c2=(2*cur)+1; //right child small=LLONG_MAX; if(c1<=heapsize && heap[c1].mindist<heap[cur].mindist)small=c1; if(c2<=heapsize && heap[c2].mindist<heap[cur].mindist) { if(small!=LLONG_MAX){if(heap[c2].mindist<heap[small].mindist)small=c2;} else if(small==LLONG_MAX)small=c2; } if(small==LLONG_MAX)break; swap(&map[heap[small].vertex],&map[heap[cur].vertex]); swap(&heap[small].mindist,&heap[cur].mindist); swap(&heap[small].vertex,&heap[cur].vertex); cur=small; } //Relax the nodes adjacent to picked vertexk ptr=graph[pick]; ok=0,adjacent,edge; stop=adjac[pick]; while(stop>0 && dist[pick]!=LLONG_MAX) { adjacent=ptr->nodeindex; edge=ptr->weight; if(map[adjacent]<=heapsize && dist[pick]+edge<dist[adjacent] && dist[pick]!=LLONG_MAX && edge>=0) { dist[adjacent]=dist[pick]+edge;//relaxation of nodes adjacent to picked vertex previous[adjacent]=pick; update=map[adjacent]; heap[update].mindist=dist[pick]+edge; parent=update/2; while(heap[update].mindist<heap[parent].mindist && parent>=1 && update>=1) { swap(&map[heap[parent].vertex],&map[heap[update].vertex]); swap(&heap[update].mindist,&heap[parent].mindist); swap(&heap[update].vertex,&heap[parent].vertex); update=parent; parent=update/2; } } ptr=ptr->adj; stop--; } } int shortestpath[nodes+1],index=1,answer_exist=1,prev=nodes; shortestpath[index]=nodes; index++; while(1) { prev=previous[prev]; if(prev==-1){answer_exist=0;break;} shortestpath[index]=prev; if(prev==1){break;} index++; } if(answer_exist==0){printf("-1\n");free(graph); free(heap); free(traverse); free(ptr);return 0;} for(int i=index;i>0;i--) printf("%lld ",shortestpath[i]); printf("\n"); free(graph); free(heap); free(traverse); free(ptr); return 0; }
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
C
bda2ca1fd65084bb9d8659c0a591743d
21eb9c734b08ea7f87f0cce1aa2423c1
GNU C11
standard output
64 megabytes
train_000.jsonl
[ "shortest paths", "graphs" ]
1276875000
["5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1"]
null
PASSED
1,900
standard input
1 second
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that the graph has loops and multiple edges between pair of vertices.
["1 4 3 5", "1 4 3 5"]
#include <stdio.h> #include <string.h> #include <limits.h> #include <stdlib.h> #define int long long int struct adjacencylist { int nodeindex; int weight; struct adjacencylist* adj; }; struct minheap { int mindist; int vertex; }; struct adjacencylist *graph[100002],*traverse; int swap(int *a,int *b){ int temp=*a; *a=*b; *b=temp;} int minimum(int a, int b){ if(a<=b)return a; else return b;} int add_edge(int a,int b,int distance) { traverse=(struct adjacencylist*)malloc(sizeof(struct adjacencylist)); traverse->adj=graph[a]; traverse->nodeindex=b; traverse->weight=distance; graph[a]=traverse; } int main() { int nodes,edges,distance,a,b,update,parent,pick,cur,ok=0,adjacent,edge,c1,c2,small,stop; scanf("%lld%lld",&nodes,&edges); //nodes and edges int adjac[nodes+1],previous[nodes+1]; memset(adjac,0,sizeof(adjac)); struct adjacencylist *ptr; //graph input in linked list begins for(int i=0;i<edges;i++) { scanf("%lld%lld%lld",&a,&b,&distance); adjac[a]++; add_edge(a,b,distance); add_edge(b,a,distance); adjac[b]++; } //graph input in linked list ends //Djkstra algorithm int source=1; int visit[nodes+1],dist[nodes+1]; for(int i=1;i<=nodes;i++){dist[i]=LLONG_MAX; visit[i]=0;} visit[source]=1; dist[source]=0; //Building Minimum Heap struct minheap* heap=(struct minheap*)malloc((nodes+1)*sizeof(struct minheap)); int cnt=1; int map[nodes+1]; heap[1].mindist=dist[source]; heap[1].vertex=source; map[heap[1].vertex]=1; cnt++; for(int i=1;i<=nodes;i++) { if(i==source){previous[i]=1;continue;} else if(i!=source)previous[i]=-1; heap[cnt].mindist=dist[i]; heap[cnt].vertex=i; map[heap[cnt].vertex]=cnt; cnt++; } int heapsize=cnt-1; while(heapsize>0) { pick=heap[1].vertex; /*Deletion in Min. Heap*/ map[heap[heapsize].vertex]=map[heap[1].vertex]; heap[1].mindist=heap[heapsize].mindist; heap[1].vertex=heap[heapsize].vertex; heapsize--; /*Compare the first node with it's child nodes*/ cur=1; while(1) { c1=2*cur; //left child c2=(2*cur)+1; //right child small=LLONG_MAX; if(c1<=heapsize && heap[c1].mindist<heap[cur].mindist)small=c1; if(c2<=heapsize && heap[c2].mindist<heap[cur].mindist) { if(small!=LLONG_MAX){if(heap[c2].mindist<heap[small].mindist)small=c2;} else if(small==LLONG_MAX)small=c2; } if(small==LLONG_MAX)break; swap(&map[heap[small].vertex],&map[heap[cur].vertex]); swap(&heap[small].mindist,&heap[cur].mindist); swap(&heap[small].vertex,&heap[cur].vertex); cur=small; } //Relax the nodes adjacent to picked vertexk ptr=graph[pick]; ok=0,adjacent,edge; stop=adjac[pick]; while(stop>0 && dist[pick]!=LLONG_MAX) { adjacent=ptr->nodeindex; edge=ptr->weight; if(map[adjacent]<=heapsize && dist[pick]+edge<dist[adjacent] && dist[pick]!=LLONG_MAX && edge>=0) { dist[adjacent]=dist[pick]+edge;//relaxation of nodes adjacent to picked vertex previous[adjacent]=pick; update=map[adjacent]; heap[update].mindist=dist[pick]+edge; parent=update/2; while(heap[update].mindist<heap[parent].mindist && parent>=1 && update>=1) { swap(&map[heap[parent].vertex],&map[heap[update].vertex]); swap(&heap[update].mindist,&heap[parent].mindist); swap(&heap[update].vertex,&heap[parent].vertex); update=parent; parent=update/2; } } ptr=ptr->adj; stop--; } } int shortestpath[nodes+1],index=1,answer_exist=1,prev=nodes; shortestpath[index]=nodes; index++; while(1) { prev=previous[prev]; if(prev==-1){answer_exist=0;break;} shortestpath[index]=prev; if(prev==1){break;} index++; } if(answer_exist==0){printf("-1\n");return 0;} for(int i=index;i>0;i--) printf("%lld ",shortestpath[i]); printf("\n"); free(graph); free(heap); free(traverse); free(ptr); return 0; }
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
C
bda2ca1fd65084bb9d8659c0a591743d
39beac03da2c4cce02fecd8e083b7fa0
GNU C11
standard output
64 megabytes
train_000.jsonl
[ "shortest paths", "graphs" ]
1276875000
["5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1"]
null
PASSED
1,900
standard input
1 second
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that the graph has loops and multiple edges between pair of vertices.
["1 4 3 5", "1 4 3 5"]
#include <stdio.h> #include <string.h> #include <limits.h> #include <stdlib.h> #define int long long int struct adjacencylist { int nodeindex; int weight; struct adjacencylist* adj; }; struct minheap { int mindist; int vertex; }; struct minheap* heap; struct adjacencylist *graph[100002],*traverse; int nodes,edges,distance,a,b,update,parent,pick,cur,ok=0,adjacent,edge,c1,c2,small,stop,source,heapsize; int index,answer_exist,prev,cnt; struct adjacencylist *ptr; int swap(int *a,int *b){ int temp=*a; *a=*b; *b=temp;} int minimum(int a, int b){ if(a<=b)return a; else return b;} int add_edge(int a,int b,int distance) { traverse=(struct adjacencylist*)malloc(sizeof(struct adjacencylist)); traverse->adj=graph[a]; traverse->nodeindex=b; traverse->weight=distance; graph[a]=traverse; } int build_minheap(int *dist,int *previous,int *map) { cnt=1; heap[1].mindist=dist[source]; heap[1].vertex=source; map[heap[1].vertex]=1; cnt++; for(int i=1;i<=nodes;i++) { if(i==source){previous[i]=1;continue;} else if(i!=source)previous[i]=-1; heap[cnt].mindist=dist[i]; heap[cnt].vertex=i; map[heap[cnt].vertex]=cnt; cnt++; } } int dijkstra_minheap(int *map ,int *adjac,int* dist,int *previous) { heapsize=cnt-1; while(heapsize>0) { pick=heap[1].vertex; /*Deletion in Min. Heap*/ map[heap[heapsize].vertex]=map[heap[1].vertex]; heap[1].mindist=heap[heapsize].mindist; heap[1].vertex=heap[heapsize].vertex; heapsize--; /*Compare the first node with it's child nodes*/ cur=1; while(1) { c1=2*cur; //left child c2=(2*cur)+1; //right child small=LLONG_MAX; if(c1<=heapsize && heap[c1].mindist<heap[cur].mindist)small=c1; if(c2<=heapsize && heap[c2].mindist<heap[cur].mindist) { if(small!=LLONG_MAX){if(heap[c2].mindist<heap[small].mindist)small=c2;} else if(small==LLONG_MAX)small=c2; } if(small==LLONG_MAX)break; swap(&map[heap[small].vertex],&map[heap[cur].vertex]); swap(&heap[small].mindist,&heap[cur].mindist); swap(&heap[small].vertex,&heap[cur].vertex); cur=small; } //Relax the nodes adjacent to picked vertexk ptr=graph[pick]; ok=0,adjacent,edge; stop=adjac[pick]; while(stop>0 && dist[pick]!=LLONG_MAX) { adjacent=ptr->nodeindex; edge=ptr->weight; if(map[adjacent]<=heapsize && dist[pick]+edge<dist[adjacent] && dist[pick]!=LLONG_MAX && edge>=0) { dist[adjacent]=dist[pick]+edge;//relaxation of nodes adjacent to picked vertex previous[adjacent]=pick; update=map[adjacent]; heap[update].mindist=dist[pick]+edge; parent=update/2; while(heap[update].mindist<heap[parent].mindist && parent>=1 && update>=1) { swap(&map[heap[parent].vertex],&map[heap[update].vertex]); swap(&heap[update].mindist,&heap[parent].mindist); swap(&heap[update].vertex,&heap[parent].vertex); update=parent; parent=update/2; } } ptr=ptr->adj; stop--; } } } int print_path(int *previous) { int shortestpath[nodes+1]; index=1,answer_exist=1,prev=nodes; shortestpath[index]=nodes; index++; while(1) { prev=previous[prev]; if(prev==-1){answer_exist=0;break;} shortestpath[index]=prev; if(prev==1){break;} index++; } if(answer_exist==0){printf("-1\n");return 0;} for(int i=index;i>0;i--) printf("%lld ",shortestpath[i]); printf("\n"); } int main() { scanf("%lld%lld",&nodes,&edges); //nodes and edges int adjac[nodes+1],previous[nodes+1],map[nodes+1];; memset(adjac,0,sizeof(adjac)); heap=(struct minheap*)malloc((nodes+1)*sizeof(struct minheap)); //graph input in linked list begins for(int i=0;i<edges;i++) { scanf("%lld%lld%lld",&a,&b,&distance); adjac[a]++; add_edge(a,b,distance); add_edge(b,a,distance); adjac[b]++; } //Djkstra algorithm source=1; int visit[nodes+1],dist[nodes+1]; for(int i=1;i<=nodes;i++){dist[i]=LLONG_MAX; visit[i]=0;} visit[source]=1; dist[source]=0; //Building Minimum Heap build_minheap(&dist,&previous,&map); //dijkstra dijkstra_minheap(&map,&adjac,&dist,&previous); //printing path from source to node to destination node 'n' print_path(&previous); free(graph); free(heap); free(traverse); free(ptr); return 0; }
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
C
bda2ca1fd65084bb9d8659c0a591743d
5f9ad3f2486546fc964ca06b2a128e28
GNU C11
standard output
64 megabytes
train_000.jsonl
[ "shortest paths", "graphs" ]
1276875000
["5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1"]
null
PASSED
1,900
standard input
1 second
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that the graph has loops and multiple edges between pair of vertices.
["1 4 3 5", "1 4 3 5"]
//OLD CODE WITHOUT FUNCTION #include <stdio.h> #include <string.h> #include <limits.h> #include <stdlib.h> #define int long long int struct adjacencylist { int nodeindex; int weight; struct adjacencylist* adj; }; struct minheap { int mindist; int vertex; }; struct adjacencylist *graph[100002],*traverse; int swap(int *a,int *b){ int temp=*a; *a=*b; *b=temp;} int minimum(int a, int b){ if(a<=b)return a; else return b;} int add_edge(int a,int b,int distance) { traverse=(struct adjacencylist*)malloc(sizeof(struct adjacencylist)); traverse->adj=graph[a]; traverse->nodeindex=b; traverse->weight=distance; graph[a]=traverse; } int main() { int nodes,edges,distance,a,b,update,parent,pick,cur,ok=0,adjacent,edge,c1,c2,small,stop; scanf("%lld%lld",&nodes,&edges); //nodes and edges int adjac[nodes+1],previous[nodes+1]; memset(adjac,0,sizeof(adjac)); struct adjacencylist *ptr; //graph input in linked list begins for(int i=0;i<edges;i++) { scanf("%lld%lld%lld",&a,&b,&distance); adjac[a]++; add_edge(a,b,distance); add_edge(b,a,distance); adjac[b]++; } //Djkstra algorithm int source=1; int visit[nodes+1],dist[nodes+1]; for(int i=1;i<=nodes;i++){dist[i]=LLONG_MAX; visit[i]=0;} visit[source]=1; dist[source]=0; //Building Minimum Heap struct minheap* heap=(struct minheap*)malloc((nodes+1)*sizeof(struct minheap)); int cnt=1; int map[nodes+1]; heap[1].mindist=dist[source]; heap[1].vertex=source; map[heap[1].vertex]=1; cnt++; for(int i=1;i<=nodes;i++) { if(i==source){previous[i]=1;continue;} else if(i!=source)previous[i]=-1; heap[cnt].mindist=dist[i]; heap[cnt].vertex=i; map[heap[cnt].vertex]=cnt; cnt++; } int heapsize=cnt-1; while(heapsize>0) { pick=heap[1].vertex; /*Deletion in Min. Heap*/ map[heap[heapsize].vertex]=map[heap[1].vertex]; heap[1].mindist=heap[heapsize].mindist; heap[1].vertex=heap[heapsize].vertex; heapsize--; /*Compare the first node with it's child nodes*/ cur=1; while(1) { c1=2*cur; //left child c2=(2*cur)+1; //right child small=LLONG_MAX; if(c1<=heapsize && heap[c1].mindist<heap[cur].mindist)small=c1; if(c2<=heapsize && heap[c2].mindist<heap[cur].mindist) { if(small!=LLONG_MAX){if(heap[c2].mindist<heap[small].mindist)small=c2;} else if(small==LLONG_MAX)small=c2; } if(small==LLONG_MAX)break; swap(&map[heap[small].vertex],&map[heap[cur].vertex]); swap(&heap[small].mindist,&heap[cur].mindist); swap(&heap[small].vertex,&heap[cur].vertex); cur=small; } //Relax the nodes adjacent to picked vertexk ptr=graph[pick]; ok=0,adjacent,edge; stop=adjac[pick]; while(stop>0 && dist[pick]!=LLONG_MAX) { adjacent=ptr->nodeindex; edge=ptr->weight; if(map[adjacent]<=heapsize && dist[pick]+edge<dist[adjacent] && dist[pick]!=LLONG_MAX && edge>=0) { dist[adjacent]=dist[pick]+edge;//relaxation of nodes adjacent to picked vertex previous[adjacent]=pick; update=map[adjacent]; heap[update].mindist=dist[pick]+edge; parent=update/2; while(heap[update].mindist<heap[parent].mindist && parent>=1 && update>=1) { swap(&map[heap[parent].vertex],&map[heap[update].vertex]); swap(&heap[update].mindist,&heap[parent].mindist); swap(&heap[update].vertex,&heap[parent].vertex); update=parent; parent=update/2; } } ptr=ptr->adj; stop--; } } int shortestpath[nodes+1],index=1,answer_exist=1,prev=nodes; shortestpath[index]=nodes; index++; while(1) { prev=previous[prev]; if(prev==-1){answer_exist=0;break;} shortestpath[index]=prev; if(prev==1){break;} index++; } if(answer_exist==0){printf("-1\n");return 0;} for(int i=index;i>0;i--) printf("%lld ",shortestpath[i]); printf("\n"); free(graph); free(heap); free(traverse); free(ptr); return 0; }
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
C
bda2ca1fd65084bb9d8659c0a591743d
b603f3dd3a7c304e963721c0fe8d50c2
GNU C11
standard output
64 megabytes
train_000.jsonl
[ "shortest paths", "graphs" ]
1276875000
["5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1"]
null
PASSED
1,900
standard input
1 second
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that the graph has loops and multiple edges between pair of vertices.
["1 4 3 5", "1 4 3 5"]
//Testing somebody's code #include <stdio.h> #include <stdlib.h> #define MAX 100005 #define ll long long #define M 0x7f7f7f7f7f7f7f7f // 有向边 typedef struct node{ // 终点 int e; // 权值 int w; // 指向下一个边的下标 int next; }Edge; // 用来保存边的链表 Edge edges[MAX<<2]; // 记录图上的每一个点能到边的链表的头位置 int first[MAX]; // 最短路 ll dist[MAX]; // 标记该点是否在队列中 int vis[MAX]; // 队列相关 int rear = 0; int front = 0; int queue[MAX]; // 标记每一个点入队多少次 int used[MAX]; // 记录最短路径 int pre[MAX]; // 点的个数和边的个数 int v,e; // edges数组的使用量 int use = 0; void add(int x,int y,int w){ edges[use].e = y; edges[use].w = w; // 反向插入,不是插在最后面,而是插在最前面 edges[use].next = first[x]; first[x] = use++; } void push(int data){ queue[front++] = data; if(front >= MAX){ front = 0; } } int pop(){ int res = queue[rear++]; if(rear >= MAX){ rear = 0; } return res; } int isEmpty(){ return rear == front; } int spfa(){ push(1); vis[1] = 1; used[1]++; dist[1] = 0; while(!isEmpty()){ int p = pop(); vis[p] = 0; int next = first[p]; while(next!=-1){ int end = edges[next].e; if(dist[end] > dist[p] + edges[next].w){ dist[end] = dist[p] + edges[next].w; pre[end] = p; if(!vis[end]){ used[end]++; // 如果该数进队列的次数大于v,说明存在负环。 // 因为如果是一个不带负权的图,一个点最多可能被更新N次 // 也就是说,他最多被入队N次 if(used[end]>v){ return 0; } vis[end] = 1; push(end); } } next = edges[next].next; } } return 1; } int main() { memset(vis,0,sizeof(vis)); memset(first,-1,sizeof(first)); memset(used,0,sizeof(used)); // 初始化的时候源点到每一个点的代价都是最大值 memset(dist,127,sizeof(dist)); // 源点到源点的代价为0 scanf("%d%d",&v,&e); // 输入边,注意是输入的有向边这里,如果是无向边需要一点修改 for(int i=0;i<e;i++){ int s,e,w; scanf("%d%d%d",&s,&e,&w); add(s,e,w); add(e,s,w); } spfa(); if(dist[v]!=M){ int cur = v; for(int i=0;1;i++){ dist[i] = cur; if(cur == 1){ for(int j=i;j>=0;j--){ printf("%d ",dist[j]); } break; } cur = pre[cur]; } }else{ printf("-1\n"); } return 0; }
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
C
bda2ca1fd65084bb9d8659c0a591743d
9d3b57e97511d1d745311b376f46c933
GNU C11
standard output
64 megabytes
train_000.jsonl
[ "shortest paths", "graphs" ]
1276875000
["5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1"]
null
PASSED
1,900
standard input
1 second
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that the graph has loops and multiple edges between pair of vertices.
["1 4 3 5", "1 4 3 5"]
//Testing Somebody's code #include <limits.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 222222 typedef long long ll; typedef struct {ll v, w;} pair; typedef struct _list{ pair p; struct _list *next; } list; list *g[N]; ll n, m, u, v, w, size, dist[N], prev[N]; pair pq[N]; void min_heapify(ll ind){ ll l=ind*2, r=l+1, lowest=ind; if (l<=size&&(pq[l].v<pq[ind].v||pq[l].w<pq[ind].w)) lowest=l; if (r<=size&&(pq[r].v<pq[ind].v||pq[r].w<pq[ind].w)) lowest=r; if (lowest!=ind){ pair tmp=pq[ind]; pq[ind]=pq[lowest]; pq[lowest]=tmp; min_heapify(lowest); } } pair top(void){ pair min=pq[1]; pq[1]=pq[size]; size--; min_heapify(1); return min; } void pushh(ll v, ll w){ ++size; pq[size].v=v; pq[size].w=w; min_heapify(size/2); } void pushg(ll u, ll v, ll w){ list *ptr=(list *) malloc(sizeof(list)); ptr->next=g[u]; ptr->p.v=v; ptr->p.w=w; g[u]=ptr; } void dijkstra(ll s){ for (ll i=1; i<=n; i++) dist[i]=LLONG_MAX; dist[s]=0; pushh(1, 0); while (size){ pair p=top(); ll u=p.v; for (list *a=g[u]; a; a=a->next){ pair v=a->p; if (dist[u]+v.w<dist[v.v]){ dist[v.v]=dist[u]+v.w; prev[v.v]=u; pushh(v.v, w); } } } } void output(ll v){ if (prev[v]) output(prev[v]); printf("%lld ", v); } int main(){ scanf("%lld%lld", &n, &m); while (m--){ scanf("%lld%lld%lld", &u, &v, &w); pushg(u, v, w); pushg(v, u, w); } dijkstra(1); prev[1]=0; if (prev[n]) output(n); else printf("-1"); }
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
C
bda2ca1fd65084bb9d8659c0a591743d
a1b6861ce734515b888c58ba7bd935e8
GNU C11
standard output
64 megabytes
train_000.jsonl
[ "shortest paths", "graphs" ]
1276875000
["5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1"]
null
PASSED
1,900
standard input
1 second
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that the graph has loops and multiple edges between pair of vertices.
["1 4 3 5", "1 4 3 5"]
//OLD CODE WITHOUT FUNCTION #include <stdio.h> #include <string.h> #include <limits.h> #include <stdlib.h> #define int long long int struct adjacencylist { int nodeindex; int weight; struct adjacencylist* adj; }; struct minheap { int mindist; int vertex; }; struct adjacencylist *graph[100002],*traverse; int swap(int *a,int *b){ int temp=*a; *a=*b; *b=temp;} int minimum(int a, int b){ if(a<=b)return a; else return b;} int add_edge(int a,int b,int distance) { traverse=(struct adjacencylist*)malloc(sizeof(struct adjacencylist)); traverse->adj=graph[a]; traverse->nodeindex=b; traverse->weight=distance; graph[a]=traverse; } main() { int nodes,edges,distance,a,b,update,parent,pick,cur,ok=0,adjacent,edge,c1,c2,small,stop; scanf("%lld%lld",&nodes,&edges); //nodes and edges int adjac[nodes+1],previous[nodes+1]; memset(adjac,0,sizeof(adjac)); struct adjacencylist *ptr; //graph input in linked list begins for(int i=0;i<edges;i++) { scanf("%lld%lld%lld",&a,&b,&distance); adjac[a]++; add_edge(a,b,distance); add_edge(b,a,distance); adjac[b]++; } //Djkstra algorithm int source=1; int visit[nodes+1],dist[nodes+1]; for(int i=1;i<=nodes;i++){dist[i]=LLONG_MAX; visit[i]=0;} visit[source]=1; dist[source]=0; //Building Minimum Heap struct minheap* heap=(struct minheap*)malloc((nodes+1)*sizeof(struct minheap)); int cnt=1; int map[nodes+1]; heap[1].mindist=dist[source]; heap[1].vertex=source; map[heap[1].vertex]=1; cnt++; for(int i=1;i<=nodes;i++) { if(i==source){previous[i]=1;continue;} else if(i!=source)previous[i]=-1; heap[cnt].mindist=dist[i]; heap[cnt].vertex=i; map[heap[cnt].vertex]=cnt; cnt++; } int heapsize=cnt-1; while(heapsize>0) { pick=heap[1].vertex; /*Deletion in Min. Heap*/ map[heap[heapsize].vertex]=map[heap[1].vertex]; heap[1].mindist=heap[heapsize].mindist; heap[1].vertex=heap[heapsize].vertex; heapsize--; /*Compare the first node with it's child nodes*/ cur=1; while(1) { c1=2*cur; //left child c2=(2*cur)+1; //right child small=LLONG_MAX; if(c1<=heapsize && heap[c1].mindist<heap[cur].mindist)small=c1; if(c2<=heapsize && heap[c2].mindist<heap[cur].mindist) { if(small!=LLONG_MAX){if(heap[c2].mindist<heap[small].mindist)small=c2;} else if(small==LLONG_MAX)small=c2; } if(small==LLONG_MAX)break; swap(&map[heap[small].vertex],&map[heap[cur].vertex]); swap(&heap[small].mindist,&heap[cur].mindist); swap(&heap[small].vertex,&heap[cur].vertex); cur=small; } //Relax the nodes adjacent to picked vertexk ptr=graph[pick]; ok=0,adjacent,edge; stop=adjac[pick]; while(stop>0 && dist[pick]!=LLONG_MAX) { adjacent=ptr->nodeindex; edge=ptr->weight; if(map[adjacent]<=heapsize && dist[pick]+edge<dist[adjacent] && dist[pick]!=LLONG_MAX && edge>=0) { dist[adjacent]=dist[pick]+edge;//relaxation of nodes adjacent to picked vertex previous[adjacent]=pick; update=map[adjacent]; heap[update].mindist=dist[pick]+edge; parent=update/2; while(heap[update].mindist<heap[parent].mindist && parent>=1 && update>=1) { swap(&map[heap[parent].vertex],&map[heap[update].vertex]); swap(&heap[update].mindist,&heap[parent].mindist); swap(&heap[update].vertex,&heap[parent].vertex); update=parent; parent=update/2; } } ptr=ptr->adj; stop--; } } int shortestpath[nodes+1],index=1,answer_exist=1,prev=nodes; shortestpath[index]=nodes; index++; while(1) { prev=previous[prev]; if(prev==-1){answer_exist=0;break;} shortestpath[index]=prev; if(prev==1){break;} index++; } if(answer_exist==0){printf("-1\n");return 0;} for(int i=index;i>0;i--) printf("%lld ",shortestpath[i]); printf("\n"); free(graph); free(heap); free(traverse); free(ptr); return 0; }
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
C
bda2ca1fd65084bb9d8659c0a591743d
b840a1c9c6434e7cefc4480a343c0111
GNU C11
standard output
64 megabytes
train_000.jsonl
[ "shortest paths", "graphs" ]
1276875000
["5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1"]
null
PASSED
1,900
standard input
1 second
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that the graph has loops and multiple edges between pair of vertices.
["1 4 3 5", "1 4 3 5"]
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct { int to; int len; } edge; typedef struct { edge* vec; int size; int max_size; } vector; vector* vector_new() { vector* vec = calloc(1, sizeof(*vec)); return vec; } void vector_free(vector* vec) { free(vec->vec); free(vec); } void vector_push(vector* vec, int b, int w) { if (vec->size == vec->max_size) { // we need to allocate more memory int new_size = (vec->size == 0 ? 10 : 2 * vec->size); edge* new_vec = calloc(new_size, sizeof(*new_vec)); // copy from old to new if (vec->size > 0) memcpy(new_vec, vec->vec, vec->size * sizeof(edge)); // free the old memory if (vec->vec != NULL) free(vec->vec); // ues new vec vec->max_size = new_size; vec->vec = new_vec; } edge e = {b, w}; vec->vec[vec->size++] = e; } typedef struct heap_node heap_node; struct heap_node { int node; long long dist; heap_node* left; heap_node* right; }; // join two small heaps heap_node* join(heap_node* left, heap_node* right) { if (left == NULL) return right; if (right == NULL) return left; if (rand() % 100 < 50) { heap_node* z = left; left = right; right = z; } if (left->dist < right->dist) { left->right = join(left->right, right); return left; } else { right->left = join(left, right->left); return right; } } heap_node* heap_node_new(int node_id, long long dist) { heap_node* node = calloc(1, sizeof(heap_node)); node->node = node_id; node->dist = dist; node->left = node->right = NULL; return node; } heap_node* heap_node_pop(heap_node* top) { heap_node* left = top->left; heap_node* right = top->right; free(top); return join(left, right); } // returns a path from source to destination or NULL if no such path vector* dijkstra(int n, vector* graph, int source, int destination) { // dist[x] = shortest distanct to node x from source long long* dist = calloc(n + 1, sizeof(long long)); int* path_parent = calloc(n + 1, sizeof(int)); long long inf = 1e18; // assuming all nodes are very far away except for source node for (int i = 1; i <= n; ++i) dist[i] = inf; dist[source] = 0; // make an empty heap heap_node* heap = NULL; // add source node with distance = 0 heap = join(heap, heap_node_new(source, dist[source])); // here we go, looping until we find the destination while (heap != NULL) { // extract the top heap node int u = heap->node; long long d = heap->dist; // pop top node heap = heap_node_pop(heap); // is it the dest node? if (u == destination) break; // redundant node? if (d > dist[u]) continue; // relax edges for (int i = 0; i < graph[u].size; ++i) { int v = graph[u].vec[i].to; int w = graph[u].vec[i].len; // is current path better? if (d + w < dist[v]) { dist[v] = d + w; // to reconstruct the path path_parent[v] = u; // add it to the heap heap = join(heap, heap_node_new(v, dist[v])); } } } vector* path = NULL; // is there a path? if (dist[destination] != inf) { path = vector_new(); // reconstruct the path starting from the destination for (int i = destination; i != 0; i = path_parent[i]) vector_push(path, i, 0); // reverse the path for (int l = 0, r = path->size - 1; l < r; ++l, --r) { // swap, we don't care about the 2nd value, just the first int x = path->vec[l].to; int y = path->vec[r].to; path->vec[l].to = y; path->vec[r].to = x; } } // free used memory before returning while (heap != NULL) heap = heap_node_pop(heap); free(path_parent); free(dist); return path; } int main() { int n, m; scanf("%d%d", &n, &m); // allocate a vector for each node (assuming 1-based indexing) vector* graph = calloc(n + 1, sizeof(*graph)); for (int i = 0; i < m; ++i) { int a, b, w; scanf("%d%d%d", &a, &b, &w); // the graph is undirected, so add two edges, one in each direction vector_push(&graph[a], b, w); vector_push(&graph[b], a, w); } // run dijkstra's algorithms vector* path = dijkstra(n, graph, 1, n); // print path if (path == NULL) { puts("-1"); } else { for (int i = 0; i < path->size; ++i) printf("%d ", path->vec[i].to); vector_free(path); // no need } free(graph); // no need return 0; }
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
C
bda2ca1fd65084bb9d8659c0a591743d
470a561ee26ec3fb2700d4cea4f8c742
GNU C11
standard output
64 megabytes
train_000.jsonl
[ "shortest paths", "graphs" ]
1276875000
["5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1"]
null
PASSED
1,900
standard input
1 second
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that the graph has loops and multiple edges between pair of vertices.
["1 4 3 5", "1 4 3 5"]
#include <limits.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 222222 typedef long long ll; typedef struct {ll v, w;} pair; typedef struct _list{ pair p; struct _list *next; } list; list *g[N]; ll n, m, u, v, w, size, dist[N], prev[N]; pair pq[N]; void min_heapify(ll ind){ ll l=ind*2, r=l+1, lowest=ind; if (l<=size&&(pq[l].v<pq[ind].v||pq[l].w<pq[ind].w)) lowest=l; if (r<=size&&(pq[r].v<pq[ind].v||pq[r].w<pq[ind].w)) lowest=r; if (lowest!=ind){ pair tmp=pq[ind]; pq[ind]=pq[lowest]; pq[lowest]=tmp; min_heapify(lowest); } } pair top(void){ pair min=pq[1]; pq[1]=pq[size]; size--; min_heapify(1); return min; } void pushh(ll v, ll w){ ++size; pq[size].v=v; pq[size].w=w; min_heapify(size/2); } void pushg(ll u, ll v, ll w){ list *ptr=(list *) malloc(sizeof(list)); ptr->next=g[u]; ptr->p.v=v; ptr->p.w=w; g[u]=ptr; } void dijkstra(ll s){ for (ll i=1; i<=n; i++) dist[i]=LLONG_MAX; dist[s]=0; pushh(1, 0); while (size){ pair p=top(); ll u=p.v; for (list *a=g[u]; a; a=a->next){ pair v=a->p; if (dist[u]+v.w<dist[v.v]){ dist[v.v]=dist[u]+v.w; prev[v.v]=u; pushh(v.v, w); } } } } void output(ll v){ if (prev[v]) output(prev[v]); printf("%lld ", v); } int main(){ scanf("%lld%lld", &n, &m); while (m--){ scanf("%lld%lld%lld", &u, &v, &w); pushg(u, v, w); pushg(v, u, w); } dijkstra(1); prev[1]=0; if (prev[n]) output(n); else printf("-1"); }
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
C
bda2ca1fd65084bb9d8659c0a591743d
19ddbe733c809c4ff497e55871028504
GNU C11
standard output
64 megabytes
train_000.jsonl
[ "shortest paths", "graphs" ]
1276875000
["5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1"]
null
PASSED
1,900
standard input
1 second
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that the graph has loops and multiple edges between pair of vertices.
["1 4 3 5", "1 4 3 5"]
#include <limits.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 222222 typedef long long ll; typedef struct {ll v, w;} pair; typedef struct _list{ pair p; struct _list *next; } list; list *g[N]; ll n, m, a, b, w, size, dist[N], prev[N], ans[N], ind; pair pq[N]; void min_heapify(ll ind){ ll l=ind*2, r=l+1, lowest=ind; if (l<=size&&(pq[l].v<pq[ind].v||pq[l].w<pq[ind].w)) lowest=l; if (r<=size&&(pq[r].v<pq[ind].v||pq[r].w<pq[ind].w)) lowest=r; if (lowest!=ind){ pair tmp=pq[ind]; pq[ind]=pq[lowest]; pq[lowest]=tmp; min_heapify(lowest); } } pair extract_min(void){ pair min=pq[1]; pq[1]=pq[size]; size--; min_heapify(1); return min; } void pushh(ll v, ll w){ ++size; pq[size].v=v; pq[size].w=w; min_heapify(size); } void pushg(ll u, ll v, ll w){ list *ptr=(list *) malloc(sizeof(list)); ptr->next=g[u]; ptr->p.v=v; ptr->p.w=w; g[u]=ptr; } int main(){ scanf("%I64d%I64d", &n, &m); for (ll i=1; i<=n; i++) dist[i]=LLONG_MAX; while (m--){ scanf("%I64d%I64d%I64d", &a, &b, &w); pushg(a, b, w); pushg(b, a, w); } pushh(1, 0); while (size){ pair p=extract_min(); for (list *a=g[p.v]; a; a=a->next){ pair v=a->p; if (dist[p.v]+v.w<dist[v.v]){ dist[v.v]=dist[p.v]+v.w; prev[v.v]=p.v; pushh(v.v, v.w); } } } if (!prev[n]){ printf("-1"); return 0; } prev[1]=0; a=n; if (prev[a]) while (prev[a]){ ans[ind]=a; a=prev[a]; ind++; } printf("1 "); for (ll i=ind-1; i>=0; i--) printf("%I64d ", ans[i]); }