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
Andrew plays a game called "Civilization". Dima helps him.The game has n cities and m bidirectional roads. The cities are numbered from 1 to n. Between any pair of cities there either is a single (unique) path, or there is no path at all. A path is such a sequence of distinct cities v1, v2, ..., vk, that there is a road between any contiguous cities vi and vi + 1 (1 ≤ i < k). The length of the described path equals to (k - 1). We assume that two cities lie in the same region if and only if, there is a path connecting these two cities.During the game events of two types take place: Andrew asks Dima about the length of the longest path in the region where city x lies. Andrew asks Dima to merge the region where city x lies with the region where city y lies. If the cities lie in the same region, then no merging is needed. Otherwise, you need to merge the regions as follows: choose a city from the first region, a city from the second region and connect them by a road so as to minimize the length of the longest path in the resulting region. If there are multiple ways to do so, you are allowed to choose any of them. Dima finds it hard to execute Andrew's queries, so he asks you to help him. Help Dima.
For each event of the first type print the answer on a separate line.
C
54c1d57482a1aa9c1013c2d54c5f9c13
48077918c94ce114b5c2c8c6b274b8aa
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "dp", "trees", "dsu", "dfs and similar", "ternary search" ]
1407511800
["6 0 6\n2 1 2\n2 3 4\n2 5 6\n2 3 2\n2 5 3\n1 1"]
null
PASSED
2,100
standard input
1 second
The first line contains three integers n, m, q (1 ≤ n ≤ 3·105; 0 ≤ m < n; 1 ≤ q ≤ 3·105) — the number of cities, the number of the roads we already have and the number of queries, correspondingly. Each of the following m lines contains two integers, ai and bi (ai ≠ bi; 1 ≤ ai, bi ≤ n). These numbers represent the road between cities ai and bi. There can be at most one road between two cities. Each of the following q lines contains one of the two events in the following format: 1 xi. It is the request Andrew gives to Dima to find the length of the maximum path in the region that contains city xi (1 ≤ xi ≤ n). 2 xi yi. It is the request Andrew gives to Dima to merge the region that contains city xi and the region that contains city yi (1 ≤ xi, yi ≤ n). Note, that xi can be equal to yi.
["4"]
/* practice with Dukkha */ #include <stdio.h> #include <string.h> #define N 300000 int max(int a, int b) { return a > b ? a : b; } int next[1 + (N - 1) * 2], jj[1 + (N - 1) * 2]; int link(int l, int j) { static int l_ = 1; next[l_] = l; jj[l_] = j; return l_++; } int ao[N], cc[N], d_, j_; void dfs(int p, int i, int c, int d) { int l, j; if (d_ < d) d_ = d, j_ = i; cc[i] = c; for (l = ao[i]; l; l = next[l]) { j = jj[l]; if (j != p) dfs(i, j, c, d + 1); } } int dsu[N], dd[N]; int find(int i) { return dsu[i] < 0 ? i : (dsu[i] = find(dsu[i])); } void join(int i, int j) { int d; i = find(i); j = find(j); if (i == j) return; d = max(max(dd[i], dd[j]), (dd[i] + 1) / 2 + 1 + (dd[j] + 1) / 2); if (dsu[i] > dsu[j]) { dsu[i] = j; dd[j] = d; } else { if (dsu[i] == dsu[j]) dsu[i]--; dsu[j] = i; dd[i] = d; } } int main() { int n, m, q, i, j; scanf("%d%d%d", &n, &m, &q); while (m--) { scanf("%d%d", &i, &j), i--, j--; ao[i] = link(ao[i], j); ao[j] = link(ao[j], i); } memset(cc, -1, n * sizeof *cc); for (i = 0; i < n; i++) if (cc[i] == -1) { d_ = 0, j_ = i; dfs(-1, i, i, 0); dfs(-1, j_, i, 0); dd[i] = d_; dsu[i] = -1; } for (i = 0; i < n; i++) if (cc[i] != i) dsu[i] = cc[i]; while (q--) { int t; scanf("%d%d", &t, &i), i--; if (t == 1) printf("%d\n", dd[find(i)]); else { scanf("%d", &j), j--; join(i, j); } } return 0; }
Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot.One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the permutation of numbers and inserts it back in an arbitrary position. He can either insert last number between any two consecutive numbers, or he can place it at the beginning of the permutation.Happy PMP has an algorithm that solves the problem. But it is not fast enough. He wants to know the minimum number of moves to convert the first permutation to the second.
Print a single integer denoting the minimum number of moves required to convert the first permutation to the second.
C
a26e048eb9b18f87f1703d42e172f318
03cd986d6b3c7f48b1d0685e18feb9eb
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "greedy" ]
1336663800
["3\n3 2 1\n1 2 3", "5\n1 2 3 4 5\n1 5 2 3 4", "5\n1 5 2 3 4\n1 2 3 4 5"]
NoteIn the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3.In the second sample, he removes number 5 and inserts it after 1.In the third sample, the sequence of changes are like this: 1 5 2 3 4 1 4 5 2 3 1 3 4 5 2 1 2 3 4 5 So he needs three moves.
PASSED
1,500
standard input
2 seconds
The first line contains a single integer n (1 ≤ n ≤ 2·105) — the quantity of the numbers in the both given permutations. Next line contains n space-separated integers — the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same format.
["2", "1", "3"]
/* practice with Dukkha */ #include <stdio.h> #define N 200000 int main() { static int pp[N], ii[N]; int n, i, q; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &pp[i]), pp[i]--; for (i = 0; i < n; i++) { scanf("%d", &q), q--; ii[q] = i; } for (i = 0; i < n; i++) pp[i] = ii[pp[i]]; i = 1; while (i < n && pp[i] > pp[i - 1]) i++; printf("%d\n", n - i); return 0; }
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li &lt; ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed. The number of operations should not exceed 20 000. If the animals are arranged correctly from the start, you are allowed to output nothing.
C
233c2806db31916609421fbd126133d0
8bd00a0fd6e403bc129dc81bff428511
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "sortings" ]
1466699700
["4\n2 1 4 3", "7\n36 28 57 39 66 69 68", "5\n1 2 1 2 1"]
NoteNote that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
PASSED
1,100
standard input
2 seconds
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
["1 4", "1 4\n6 7", "2 5\n3 4\n1 4\n1 4"]
#include <stdio.h> #include <stdlib.h> int main() { int n; scanf("%d", &n); int *v = (int*) malloc(n*sizeof(int)); for (int i = 0; i < n; i++) scanf("%d", &v[i]); for (int i = n-1; i > 0; --i) { for (int j = 0; j < i; j++) { if (v[j] > v[j+1]) { int tmp = v[j]; v[j] = v[j+1]; v[j+1] = tmp; printf("%d %d\n", j+1, j+2); } } } free(v); }
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li &lt; ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed. The number of operations should not exceed 20 000. If the animals are arranged correctly from the start, you are allowed to output nothing.
C
233c2806db31916609421fbd126133d0
5a0edeb56108f6c84412666c16f5c360
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "sortings" ]
1466699700
["4\n2 1 4 3", "7\n36 28 57 39 66 69 68", "5\n1 2 1 2 1"]
NoteNote that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
PASSED
1,100
standard input
2 seconds
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
["1 4", "1 4\n6 7", "2 5\n3 4\n1 4\n1 4"]
#include <stdio.h> int main() { int n; scanf("%d", &n); long long grid[n]; for(int i = 0 ; i < n ; i++) { scanf("%lld", grid+i); } /* a[0] to a[n-1] is the array to sort */ int i,j; /* advance the position through the entire array */ /* (could do j < n-1 because single element is also min element) */ for (j = 0; j < n-1; j++) { /* find the min element in the unsorted a[j .. n-1] */ /* assume the min is the first element */ int iMin = j; /* test against elements after j to find the smallest */ for ( i = j+1; i < n; i++) { /* if this element is less, then it is the new minimum */ if (grid[i] < grid[iMin]) { /* found new minimum; remember its index */ iMin = i; } } if(iMin != j) { // printf("R %d(%lld)::", j, grid[j]); for (int z = iMin - 1 ; z >= j ; z--) { long long temp = grid[z+1]; grid[z+1] = grid[z]; grid[z] = temp; // printf(" %d(%lld) <-> %d(%lld) ", z+1,grid[z+1], z, grid[z]); printf("%d %d\n",z+1, z+2); } } } // for (j = 0; j < n; j++) { // printf("%lld ",grid[j] ); // } }
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li &lt; ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed. The number of operations should not exceed 20 000. If the animals are arranged correctly from the start, you are allowed to output nothing.
C
233c2806db31916609421fbd126133d0
8ed07d7d5dc125341ec6836bd1fa1158
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "sortings" ]
1466699700
["4\n2 1 4 3", "7\n36 28 57 39 66 69 68", "5\n1 2 1 2 1"]
NoteNote that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
PASSED
1,100
standard input
2 seconds
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
["1 4", "1 4\n6 7", "2 5\n3 4\n1 4\n1 4"]
#include <stdio.h> int main() { int n,a,t,i,j; int z[105]; scanf("%d",&n); for(a=0;n>a;a++){ scanf("%d",&z[a]); } i=0; j=1; for(;j<n;){ if(z[i]>z[j]){ printf("%d %d\n",i+1,j+1); t=z[i]; z[i]=z[j]; z[j]=t; if(z[i-1]>z[i]&&i-1>=0){ i--; j--; continue; } i++; j++; } else{ i++; j++; } } return 0; }
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li &lt; ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed. The number of operations should not exceed 20 000. If the animals are arranged correctly from the start, you are allowed to output nothing.
C
233c2806db31916609421fbd126133d0
796158b7e5af6bf33602222d8582a6fc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "sortings" ]
1466699700
["4\n2 1 4 3", "7\n36 28 57 39 66 69 68", "5\n1 2 1 2 1"]
NoteNote that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
PASSED
1,100
standard input
2 seconds
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
["1 4", "1 4\n6 7", "2 5\n3 4\n1 4\n1 4"]
#include <stdio.h> #define N 100 int sorted(int *aa, int n) { int i; for (i = 0; i < n - 1; i++) if (aa[i] > aa[i + 1]) return 0; return 1; } int main() { static int aa[N]; int n, i; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &aa[i]); while (!sorted(aa, n)) for (i = 0; i < n - 1; i++) if (aa[i] > aa[i + 1]) { int tmp; tmp = aa[i]; aa[i] = aa[i + 1]; aa[i + 1] = tmp; printf("%d %d\n", i + 1, i + 2); } return 0; }
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li &lt; ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed. The number of operations should not exceed 20 000. If the animals are arranged correctly from the start, you are allowed to output nothing.
C
233c2806db31916609421fbd126133d0
d236bb8bfb70fd0728ba2b5bd7370b25
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "sortings" ]
1466699700
["4\n2 1 4 3", "7\n36 28 57 39 66 69 68", "5\n1 2 1 2 1"]
NoteNote that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
PASSED
1,100
standard input
2 seconds
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
["1 4", "1 4\n6 7", "2 5\n3 4\n1 4\n1 4"]
#include <stdio.h> int main() { static int aa[100]; int i, j, n, tmp; scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &aa[i]); for (i = 0; i < n; i++) for (j = 1; j < n; j++) if (aa[j - 1] > aa[j]) { tmp = aa[j - 1], aa[j - 1] = aa[j], aa[j] = tmp; printf("%d %d\n", j, j + 1); } return 0; }
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li &lt; ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed. The number of operations should not exceed 20 000. If the animals are arranged correctly from the start, you are allowed to output nothing.
C
233c2806db31916609421fbd126133d0
799a579f54cde751679e40b3df750b13
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "sortings" ]
1466699700
["4\n2 1 4 3", "7\n36 28 57 39 66 69 68", "5\n1 2 1 2 1"]
NoteNote that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
PASSED
1,100
standard input
2 seconds
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
["1 4", "1 4\n6 7", "2 5\n3 4\n1 4\n1 4"]
#include<stdio.h> int main() { int n, f=1, i, x, k; scanf("%d", &n); int a[n+1]; for(k=0; k<n; k++) { scanf("%d", &a[k]); } while(f==1) { f=0; for(i=0; i<n-1; i++) { if(a[i]>a[i+1]) { printf("%d %d\n", i+1, i+2); f=1; x=a[i]; a[i]=a[i+1]; a[i+1]=x; } } } return 0; }
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li &lt; ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed. The number of operations should not exceed 20 000. If the animals are arranged correctly from the start, you are allowed to output nothing.
C
233c2806db31916609421fbd126133d0
cb5303bbc1bb9a6d86b751ae2ea094ab
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "sortings" ]
1466699700
["4\n2 1 4 3", "7\n36 28 57 39 66 69 68", "5\n1 2 1 2 1"]
NoteNote that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
PASSED
1,100
standard input
2 seconds
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
["1 4", "1 4\n6 7", "2 5\n3 4\n1 4\n1 4"]
#include <stdio.h> int main (void){ int n; scanf("%d", &n); long h[n]; int i; for (i=0; i<n; i++) { scanf("%ld", &h[i]); } int j; for (i=n; i>1; i--){ for(j=0; j<i-1; j++){ if(h[j]>h[j+1]){ printf("%d %d\n",j+1,j+1+1); int temp=h[j+1]; h[j+1]=h[j]; h[j]=temp; } } } }
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li &lt; ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed. The number of operations should not exceed 20 000. If the animals are arranged correctly from the start, you are allowed to output nothing.
C
233c2806db31916609421fbd126133d0
15ba4b3f7996a0ca920230ba1fd196a0
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "sortings" ]
1466699700
["4\n2 1 4 3", "7\n36 28 57 39 66 69 68", "5\n1 2 1 2 1"]
NoteNote that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
PASSED
1,100
standard input
2 seconds
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
["1 4", "1 4\n6 7", "2 5\n3 4\n1 4\n1 4"]
#include<stdio.h> int main() { int n,i,r,t; scanf("%d",&n); int a[n+1]; for(i=1;i<=n;i++) scanf("%d",&a[i]); r=n; while(r!=1){ for(i=1;i<r;i++){ if(a[i]>a[i+1]){ t=a[i]; a[i]=a[i+1]; a[i+1]=t; printf("%d %d\n",i,i+1); } } r--; } }
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li &lt; ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed. The number of operations should not exceed 20 000. If the animals are arranged correctly from the start, you are allowed to output nothing.
C
233c2806db31916609421fbd126133d0
22ebddcdad85dbb5fe58244d1e1929ec
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "sortings" ]
1466699700
["4\n2 1 4 3", "7\n36 28 57 39 66 69 68", "5\n1 2 1 2 1"]
NoteNote that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
PASSED
1,100
standard input
2 seconds
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
["1 4", "1 4\n6 7", "2 5\n3 4\n1 4\n1 4"]
#include<stdio.h> int main(){ long long arr[105],n,i,j,temp; scanf("%lld",&n); for(i=0;i<n;i++) scanf("%lld",&arr[i]); for(i=0;i<n-1;i++){ for(j=0;j<n-i-1;j++){ if(arr[j]>arr[j+1]){ temp= arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp; printf("%lld %lld\n",j+1,j+2); } } } return 0; }
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li &lt; ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed. The number of operations should not exceed 20 000. If the animals are arranged correctly from the start, you are allowed to output nothing.
C
233c2806db31916609421fbd126133d0
d7b757cdbd03a0f5d9bbff984b90d7fa
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "sortings" ]
1466699700
["4\n2 1 4 3", "7\n36 28 57 39 66 69 68", "5\n1 2 1 2 1"]
NoteNote that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
PASSED
1,100
standard input
2 seconds
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
["1 4", "1 4\n6 7", "2 5\n3 4\n1 4\n1 4"]
#include <stdio.h> int main (void){ int n; scanf("%d", &n); long h[n]; int i; for (i=0; i<n; i++) { scanf("%ld", &h[i]); } int j; for (i=n; i>1; i--){ for(j=0; j<i-1; j++){ if(h[j]>h[j+1]){ printf("%d %d\n",j+1,j+1+1); int temp=h[j+1]; h[j+1]=h[j]; h[j]=temp; } } } }
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li &lt; ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed. The number of operations should not exceed 20 000. If the animals are arranged correctly from the start, you are allowed to output nothing.
C
233c2806db31916609421fbd126133d0
c761104b58f44001fc0e566bae7164ad
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "sortings" ]
1466699700
["4\n2 1 4 3", "7\n36 28 57 39 66 69 68", "5\n1 2 1 2 1"]
NoteNote that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
PASSED
1,100
standard input
2 seconds
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
["1 4", "1 4\n6 7", "2 5\n3 4\n1 4\n1 4"]
#include <stdlib.h> #include <stdio.h> int main() { int n, x; scanf("%d", &n); long long int A[n]; for(x=0; x<n; x++) { scanf("%lld", &A[x]); } int temp, swapped; while(1) { swapped = 0; for(x=0; x<n-1; x++) { if(A[x]>A[x+1]) { temp = A[x]; A[x] = A[x+1]; A[x+1] = temp; printf("%d %d\n", x + 1, x+2); swapped = 1; } } if(swapped == 0) break; } return 0; }
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li &lt; ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed. The number of operations should not exceed 20 000. If the animals are arranged correctly from the start, you are allowed to output nothing.
C
233c2806db31916609421fbd126133d0
a708d290fdb144afa03c5fea259c2982
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "sortings" ]
1466699700
["4\n2 1 4 3", "7\n36 28 57 39 66 69 68", "5\n1 2 1 2 1"]
NoteNote that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
PASSED
1,100
standard input
2 seconds
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
["1 4", "1 4\n6 7", "2 5\n3 4\n1 4\n1 4"]
#include <stdio.h> int main() { int n; scanf("%d", &n); long h[n]; for (int i = 0; i < n; i++) scanf("%ld", h+i); int run = 1; while (run) { run = 0; for (int i = 0; i < n-1; i++) { if (h[i] > h[i+1]) { printf("%d %d\n", i+1, i+2); h[i] ^= h[i+1]; h[i+1] ^= h[i]; h[i] ^= h[i+1]; run = 1; } } } }
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li &lt; ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed. The number of operations should not exceed 20 000. If the animals are arranged correctly from the start, you are allowed to output nothing.
C
233c2806db31916609421fbd126133d0
bf4ce6929c3d69edc2893053fc0df3fa
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "sortings" ]
1466699700
["4\n2 1 4 3", "7\n36 28 57 39 66 69 68", "5\n1 2 1 2 1"]
NoteNote that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
PASSED
1,100
standard input
2 seconds
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
["1 4", "1 4\n6 7", "2 5\n3 4\n1 4\n1 4"]
#include <stdio.h> int main(void) { int n,a[102],i=0,flag=1; scanf("%d",&n); while(i<n) { scanf("%d",&a[i]); i++; } while(flag) { i=0; flag=0; while(i<n-1) { if(a[i+1]<a[i]) { int temp=a[i]; a[i]=a[i+1]; a[i+1]=temp; printf("%d %d\n",i+1,i+2); flag=1; } i++; } } return 0; }
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li &lt; ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed. The number of operations should not exceed 20 000. If the animals are arranged correctly from the start, you are allowed to output nothing.
C
233c2806db31916609421fbd126133d0
68bc32a85bea9c4ea8875e250f39171a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "sortings" ]
1466699700
["4\n2 1 4 3", "7\n36 28 57 39 66 69 68", "5\n1 2 1 2 1"]
NoteNote that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
PASSED
1,100
standard input
2 seconds
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
["1 4", "1 4\n6 7", "2 5\n3 4\n1 4\n1 4"]
/* 20160711 JJA Codeforces #359 B.Little Robber Girl's Zoo */ #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> int isInversion(int start); void swapping(int s, int e); unsigned long long* height; int l; int r; int tmpL; int tmpR; int between; int n; int main() { n = 0; l = 0; r = -2; tmpL = 0; tmpR = -2; scanf("%d", &n); height = (unsigned long long*)malloc(sizeof(unsigned long long)*n); for (int i = 0; i < n; i++) scanf("%llu", &height[i]); while (1) { l = 0; r = 0; tmpL = 0; tmpR = -2; isInversion(-1); if (tmpR == -2) break; swapping(l, r); } return 0; } int isInversion(int start) { if (start < n - 1) { start++; if (height[start + 1] < height[start]) { if (tmpR == start - 1) { start++; tmpR = start; } else { tmpL = start; start++; tmpR = start; } isInversion(start); } else { if (tmpR - tmpL > r - l) { l = tmpL; r = tmpR; } isInversion(start); } } if (r == 0) { l = tmpL; r = tmpR; } return 0; } void swapping(int s, int e) { int tmp; for (int i = s; i < e; i += 2) { tmp = height[i]; height[i] = height[i + 1]; height[i + 1] = tmp; } printf("%d %d\n", s + 1, e + 1); }
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places.The robber girl was angry at first, but then she decided to arrange the animals herself. She repeatedly names numbers l and r such that r - l + 1 is even. After that animals that occupy positions between l and r inclusively are rearranged as follows: the animal at position l swaps places with the animal at position l + 1, the animal l + 2 swaps with the animal l + 3, ..., finally, the animal at position r - 1 swaps with the animal r.Help the robber girl to arrange the animals in the order of non-decreasing height. You should name at most 20 000 segments, since otherwise the robber girl will become bored and will start scaring the animals again.
Print the sequence of operations that will rearrange the animals by non-decreasing height. The output should contain several lines, i-th of the lines should contain two space-separated integers li and ri (1 ≤ li &lt; ri ≤ n) — descriptions of segments the robber girl should name. The segments should be described in the order the operations are performed. The number of operations should not exceed 20 000. If the animals are arranged correctly from the start, you are allowed to output nothing.
C
233c2806db31916609421fbd126133d0
ae95619f4ce4ebe3bb2071f59bdfd02e
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "implementation", "sortings" ]
1466699700
["4\n2 1 4 3", "7\n36 28 57 39 66 69 68", "5\n1 2 1 2 1"]
NoteNote that you don't have to minimize the number of operations. Any solution that performs at most 20 000 operations is allowed.
PASSED
1,100
standard input
2 seconds
The first line contains a single integer n (1 ≤ n ≤ 100) — number of animals in the robber girl's zoo. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the height of the animal occupying the i-th place.
["1 4", "1 4\n6 7", "2 5\n3 4\n1 4\n1 4"]
#include <stdio.h> #include <stdlib.h> /* * */ int main(int argc, char** argv) { int i, j, n, check = 0; scanf("%d", &n); long long a[n], x; for (i = 0; i < n; i++) { scanf("%I64d", &a[i]); } for (i = 0; i < n; i++) { check = 0; while (a[i] > a[i + 1]) { if (check == 0)printf("%d ", i + 1); check = 1; x = a[i]; a[i] = a[i + 1]; a[i + 1] = x; if (i + 2 >= n || a[i + 2] <= a[i + 3]) break; i += 2; } if (check == 1) { printf("%d\n", i + 2); i = -1; } } return (EXIT_SUCCESS); }
Kolya got an integer array $$$a_1, a_2, \dots, a_n$$$. The array can contain both positive and negative integers, but Kolya doesn't like $$$0$$$, so the array doesn't contain any zeros.Kolya doesn't like that the sum of some subsegments of his array can be $$$0$$$. The subsegment is some consecutive segment of elements of the array. You have to help Kolya and change his array in such a way that it doesn't contain any subsegments with the sum $$$0$$$. To reach this goal, you can insert any integers between any pair of adjacent elements of the array (integers can be really any: positive, negative, $$$0$$$, any by absolute value, even such a huge that they can't be represented in most standard programming languages).Your task is to find the minimum number of integers you have to insert into Kolya's array in such a way that the resulting array doesn't contain any subsegments with the sum $$$0$$$.
Print the minimum number of integers you have to insert into Kolya's array in such a way that the resulting array doesn't contain any subsegments with the sum $$$0$$$.
C
05548be393d794bf106708627220b9a3
b2f0cf8bd469a62c585e052c67b2e6f2
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "constructive algorithms", "sortings", "greedy" ]
1601280300
["4\n1 -5 3 2", "5\n4 -2 3 -9 2", "9\n-1 1 -1 1 -1 1 1 -1 -1", "8\n16 -5 -11 -15 10 5 4 -4"]
NoteConsider the first example. There is only one subsegment with the sum $$$0$$$. It starts in the second element and ends in the fourth element. It's enough to insert one element so the array doesn't contain any subsegments with the sum equal to zero. For example, it is possible to insert the integer $$$1$$$ between second and third elements of the array.There are no subsegments having sum $$$0$$$ in the second example so you don't need to do anything.
PASSED
1,500
standard input
2 seconds
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of elements in Kolya's array. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^{9} \le a_i \le 10^{9}, a_i \neq 0$$$) — the description of Kolya's array.
["1", "0", "6", "3"]
#include<stdio.h> long long int sum[200005]; int u[200005], v[200005], m; int h[200005], l; int comp_h(int a, int b, int z) { if (z == 0) { if (sum[h[a]] > sum[h[b]]) return 1; else if (sum[h[a]] < sum[h[b]]) return -1; else if (h[a] > h[b]) return 1; else return -1; } else { if (v[h[a]] > v[h[b]]) return 1; else return -1; } } void swap_h(int a, int b) { int f = h[a]; h[a] = h[b]; h[b] = f; return; } void push(int ne, int z) { h[l] = ne; int p = l; l++; for (; p > 0; p = (p - 1) / 2) if (comp_h((p - 1) / 2, p, z) > 0) swap_h((p - 1) / 2, p); return; } int pop(int z) { l--; swap_h(0, l); int p = 0; for (;;) { if (2 * p + 2 < l) { if (comp_h(2 * p + 1, 2 * p + 2, z) > 0) { if (comp_h(p, 2 * p + 2, z) > 0) swap_h(p, 2 * p + 2); p = 2 * p + 2; } else { if (comp_h(p, 2 * p + 1, z) > 0) swap_h(p, 2 * p + 1); p = 2 * p + 1; } } else if (2 * p + 1 < l) { if (comp_h(p, 2 * p + 1, z) > 0) swap_h(p, 2 * p + 1); p = 2 * p + 1; } else break; } return h[l]; } int main() { int n; scanf("%d", &n); int i, j; long long int a[200005]; for (i = 0; i < n; i++) scanf("%lld", &a[i]); sum[0] = 0; for (i = 0; i < n; i++) sum[i + 1] = sum[i] + a[i]; l = 0; for (i = 0; i <= n; i++) push(i, 0); m = 0; j = pop(0); while (l > 0) { i = pop(0); if (sum[j] == sum[i]) { u[m] = j + 1; v[m] = i; m++; } j = i; } l = 0; for (i = 0; i < m; i++) push(i, 1); int ans = 0; j = -1; while (l > 0) { i = pop(1); if (j <= u[i]) { ans++; j = v[i]; } } printf("%d\n", ans); return 0; }
Kolya got an integer array $$$a_1, a_2, \dots, a_n$$$. The array can contain both positive and negative integers, but Kolya doesn't like $$$0$$$, so the array doesn't contain any zeros.Kolya doesn't like that the sum of some subsegments of his array can be $$$0$$$. The subsegment is some consecutive segment of elements of the array. You have to help Kolya and change his array in such a way that it doesn't contain any subsegments with the sum $$$0$$$. To reach this goal, you can insert any integers between any pair of adjacent elements of the array (integers can be really any: positive, negative, $$$0$$$, any by absolute value, even such a huge that they can't be represented in most standard programming languages).Your task is to find the minimum number of integers you have to insert into Kolya's array in such a way that the resulting array doesn't contain any subsegments with the sum $$$0$$$.
Print the minimum number of integers you have to insert into Kolya's array in such a way that the resulting array doesn't contain any subsegments with the sum $$$0$$$.
C
05548be393d794bf106708627220b9a3
1cfd66a57fe263cd190d5fc43a84f63a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "constructive algorithms", "sortings", "greedy" ]
1601280300
["4\n1 -5 3 2", "5\n4 -2 3 -9 2", "9\n-1 1 -1 1 -1 1 1 -1 -1", "8\n16 -5 -11 -15 10 5 4 -4"]
NoteConsider the first example. There is only one subsegment with the sum $$$0$$$. It starts in the second element and ends in the fourth element. It's enough to insert one element so the array doesn't contain any subsegments with the sum equal to zero. For example, it is possible to insert the integer $$$1$$$ between second and third elements of the array.There are no subsegments having sum $$$0$$$ in the second example so you don't need to do anything.
PASSED
1,500
standard input
2 seconds
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of elements in Kolya's array. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^{9} \le a_i \le 10^{9}, a_i \neq 0$$$) — the description of Kolya's array.
["1", "0", "6", "3"]
#pragma region kyopuro_templates #pragma GCC optimize("Ofast") #include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> #include<stdbool.h> #include<assert.h> #include<time.h> #include<ctype.h> typedef long long ll; typedef long double ld; #define rep(i,l,r)for(ll i=(l);i<(r);i++) #define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k)) #define rrep(i,l,r)for(ll i=(l);i>=(r);i--) #define INF (1LL<<62) #define MOD1 1000000007 #define MOD2 998244353 #define MAX_N (1 << 20) #define YES printf("Yes\n") #define NO printf("No\n") #define PN printf("\n") #define charsize 100005 //10^5+5 #define PI 3.141592653589793238 void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;} void cin(ll *n){ scanf("%lld",&(*n)); } void PriAll1(ll a[], ll n){ rep(i,0,n){ printf("%lld",a[i]); if(i!=n-1) printf(" "); }PN; } ll min(ll a, ll b){ return a < b ? a : b; } ll max(ll a, ll b){ return a < b ? b : a; } // ll max2(ll a,ll b){return a>=b?a:b;} // ll min2(ll a,ll b){return a>=b?b:a;} ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;} ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;} ll minn(ll n, ll a[]){ll b=INF;rep(i,0,n) b=min(b,a[i]);return b;} ll maxn(ll n, ll a[]){ll b=-INF;rep(i,0,n) b=max(b,a[i]);return b;} ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;} double POW_d(double a, double b){double c=1;rep(i,0,b) c*=a;return c;} ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} ll mod_MOD1(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;} ll mod_p(ll n ,ll p){n+= n<0?((-n)/p+1)*p:0; return n%=p;} ll change_into_num(char s[] , ll len, ll p){ return !p ? 0 : POW(10,p-1)*(s[len-p]-'0') + change_into_num(s,len,p-1); } ll digits(ll a, ll b){return a/b?1+digits(a/b,b):1;} ll base(ll n, ll a, ll i){return i==1?n%a:base(n/a,a,i-1);} ll is_inArr1(ll x, ll n){ return ( x<0 || x>=n ) ? 0 : 1 ; } ll is_inArr2(ll y, ll x, ll h, ll w){ return ( y<0 || y>=h || x<0 || x>=w ) ? 0 : 1 ; } void lr_lower( int *l, int *r, ll am, ll val , int type ){ (type<3) ? ( am < val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ) : ( am <= val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ); } void lr_upper( int *l, int *r, ll am, ll val , int type ){ (type<3) ? ( am <= val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ) : ( am < val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ); } int cmp_lower( ll a, ll b, int type ){ return (type==1) ? ( a==b ? 1 : 0 ) : (type==2) ? ( a>=b ? 1 : 0 ) : ( a>b ? 1 : 0 ) ; } int cmp_upper( ll a, ll b, int type ){ return (type==1) ? ( a==b ? 1 : 0 ) : (type==2) ? ( a<=b ? 1 : 0 ) : ( a<b ? 1 : 0 ) ; } // return smallest p which meets a[p]==val :1 >=:2 >:3 ll lower_bound( ll a[], int l, int r, ll val , int type ){ while(r-l>1) lr_lower(&l,&r,a[ (l+r)/2 ],val,type); return cmp_lower(a[l],val,type) ? l : cmp_lower(a[r],val,type) ? r : -1; } // return biggest p which meets a[p]==val :1 <=:2 <:3 ll upper_bound( ll a[], int l, int r, ll val , int type ){ while(r-l>1) lr_upper(&l,&r,a[ (l+r)/2 ],val,type); return cmp_upper(a[r],val,type) ? r : cmp_upper(a[l],val,type) ? l : -1; } // count i which meets ai==x ll count(ll a[], int l, int r, ll x){ int p = lower_bound(a,l,r,x,1); return p==-1 ? 0 : upper_bound(a,p,r,x,1)-p+1; } ll *factors[2] , fac_cnt=0 , is_factor_prepared=0; ll factor_pre(){ rep(i,0,1){ if(is_factor_prepared++) return 0; } ll tmp=(1e6)/2+1, fac_tmp[tmp]; rep(i,0,tmp){fac_tmp[i]=i?2*i+1:2;} rep(i,1,tmp){if(fac_tmp[i]){ repp(j,3,tmp/(2*i+1)+1,2 ){ if( j*(2*i+1)<tmp ) fac_tmp[ (j*(2*i+1)-1)/2 ]=0; } }else continue;} rep(i,0,tmp){if(fac_tmp[i]){ rep(j,0,2){ factors[j] = (ll*) realloc( factors[j] , sizeof(ll)*( fac_cnt +1 ) ); factors[j][j?fac_cnt++:fac_cnt]=j?0:fac_tmp[i]; } } } return 0; } ll factor(ll n, ll new_common_plus){ factor_pre(); rep(i,0,fac_cnt){ ll cnt=0; rep(j,0,1){ while( ( cnt+= n %factors[0][i]==0 ? 1 : 0 ) && (n/=factors[0][i]) %factors[0][i]==0 ) continue; } factors[1][i]= new_common_plus==1 ? cnt : new_common_plus==2 ? max(factors[1][i],cnt) : factors[1][i]+cnt ; if( factors[0][i]> n ) break; } return n; } ll judge_prime(ll n){ factor_pre(); rep(i,0,fac_cnt){ if(n<factors[0][i]*factors[0][i] || n==factors[0][i]) break; else if(n%factors[0][i]==0) n/=n; } return n==1?0:1; } #pragma region mod ll *mf_arr, *inv_arr, *finv_arr, is_minv_made, is_mf_made, num_of_inv=3*1e5+10; void makeinv(ll n , ll mod){ if(is_minv_made++) return; inv_arr = (ll*) malloc((n + 1) * sizeof(ll)); finv_arr = (ll*) malloc((n + 1) * sizeof(ll)); inv_arr[1] = finv_arr[0] = finv_arr[1] = 1; rep(i,2,n+1){ inv_arr[i] = mod - inv_arr[mod % i] * (mod / i) % mod; finv_arr[i] = finv_arr[i - 1] * inv_arr[i] % mod; } } void make_mf(ll n, ll mod){ if(is_mf_made++) return; mf_arr = (ll*) malloc((n + 1) * sizeof(ll)); ll x = mf_arr[0] = mf_arr[1] = 1; rep(i,2,n+1){ x = x * i % mod; mf_arr[i]=x; } } ll m_inv(ll x, ll mod, ll is_fac){ makeinv(num_of_inv, mod); return is_fac ? finv_arr[x] : inv_arr[x]; } ll m_f(ll x, ll mod){ make_mf(num_of_inv, mod); return mf_arr[x]; } ll mod_nck(ll n, ll k, ll mod){ return m_f(n, mod) * m_inv(k, mod, 1) % mod * m_inv(n-k, mod, 1) % mod; } ll m_p(ll r, ll n, ll mod){ ll t = 1, s = r; while(n > 0){ t = (n & 1) ? t * s % mod : t; s = s * s % mod; n >>= 1; } return r ? t : 0; } #pragma endregion mod int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;} int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;} int cmp_string( const void * a , const void * b ) { return strcmp( (char *)a , (char *)b ); } // qsort((void*)s,n,sizeof(s[0]),int_sort ); int cmp_char(const void * a, const void * b) { return *(char *)a - *(char *)b;} void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);} void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);} // void sort_string(int n,int size,char s[][size]){ qsort( (void*)s , n , sizeof(s[0]) , cmp_string ); } // void sort_char(char *s){ qsort( (void *)s , strlen(s) , sizeof(char) , cmp_char ); } // ll unique_string(ll n ,ll size, char s[][size]){ ll ans=1; rep(i,1,n) if( strcmp(s[i],s[i-1]) ) ans++; return ans; } // ll unique_num(ll n , ll a[]){ ll ans=1; rep(i,1,n) if( a[i]!=a[i-1] ) ans++; return ans; } ll compare(ll a, ll b){ return a<b?-1:a>b?1:0; } typedef struct{ ll a , b;}fr; int cmp1( const void *p, const void *q ){ ll pa=((fr*)p)->a; ll qa=((fr*)q)->a; return compare(pa,qa); } int cmp2( const void *p, const void *q ){ ll pa=((fr*)p)->a; ll qa=((fr*)q)->a; return compare(qa,pa); } void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);} void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);} void sort_partial(ll a[],int begin,int end,int is_increase){ ll *b; b = (ll *) malloc( sizeof(ll)*(end-begin) ); rep(i,begin,end) b[i-begin]=a[i]; if(is_increase) sortup(b,end-begin); else sortdown(b,end-begin); rep(i,begin,end) a[i]=b[i-begin]; } // ll pre_rui[2151][1151]; // ll ruiseki[2151][1151]; // void rui_make(ll h, ll w){ // rep(i,0,h){ // rep(j,0,w){ // ruiseki[i+1][j+1]=ruiseki[i+1][j]+pre_rui[i][j]; // } // rep(j,0,w){ // ruiseki[i+1][j+1]+=ruiseki[i][j+1]; // } // } // } // ll rui_get(ll st_y, ll st_x, ll en_y, ll en_x, ll h, ll w){ // if(en_y<0) return 0; // if(en_x<0) return 0; // if(st_y>h) return 0; // if(st_x>w) return 0; // if(st_y<0) st_y=0; // if(st_x<0) st_x=0; // if(en_y>h) en_y=h; // if(en_x>w) en_x=w; // ll val=0; // val+=ruiseki[en_y][en_x]; // val-=ruiseki[en_y][st_x]; // val-=ruiseki[st_y][en_x]; // val+=ruiseki[st_y][st_x]; // return val; // } #pragma region AVL /*---------------------------AVL start--------------------------------*/ //https://qiita.com/mikecat_mixc/items/e9f8248de2ae7f7a0a29 typedef struct node_AVL_set{ ll val; int diff; int cnt; struct node_AVL_set *child[2]; }AVL_set; void AVL_set_inside_rotate(AVL_set **node, int is_right){ int l = is_right==false , r = is_right==true , sign = is_right ? 1 : -1; if((*node)->child[l] != NULL){ AVL_set* left = (*node)->child[l]; int a= (*node)->diff * sign , b= left->diff * sign ,na,nb; if(b+1){ na=a-1-b; nb= (a-b) ? b-1 : a-2; }else{ na=a-1; nb= a ? b-1 : a+b-2; } (*node)->diff = na * sign; left->diff = nb * sign; /* rotate-> */ (*node)->child[l] = (*node)->child[l]->child[r]; left->child[r] = *node; *node = left; } } int AVL_set_inside_update(AVL_set **node, ll data, int add){ if(*node == NULL){ if(add==2){ *node = (AVL_set*)malloc(sizeof(AVL_set)); (*node)->val = data; (*node)->cnt = 1; (*node)->diff = 0; (*node)->child[0] = NULL; (*node)->child[1] = NULL; } return add==2 ? *node != NULL : 0; }else{ int l, delta, delta_sign; AVL_set *next_node; if(data == (*node)->val){ if(add==2){ (*node)->cnt++; return 0; }else{ if( add && (*node)->cnt > 1 ){ (*node)->cnt--; return 0; }else{ if((*node)->child[1] == NULL){ next_node = (*node)->child[0]; free(*node); *node = next_node; return -1; }else if((*node)->child[0] == NULL){ next_node = (*node)->child[1]; free(*node); *node = next_node; return -1; }else{ for(next_node = (*node)->child[0]; next_node->child[1] != NULL; next_node = next_node->child[1]); (*node)->val = next_node->val; l=0; delta_sign=1; delta = AVL_set_inside_update(&(*node)->child[l], next_node->val, add); } } } }else{ l = data >= (*node)->val ? 1 : 0; delta_sign = data < (*node)->val ? 1 : -1; delta = AVL_set_inside_update(&(*node)->child[l], data, add); } if( delta ){ int orig_diff = (*node)->diff; int do_rotate = 0, rotate_l , diff_sign , rotate_right; (*node)->diff += delta * delta_sign; if((*node)->diff > 1){ do_rotate = 1; rotate_l = 0; diff_sign = 1; rotate_right = 1; }else if((*node)->diff < -1){ do_rotate = 1; rotate_l = 1; diff_sign = -1; rotate_right = 0; } if(do_rotate){ int child_diff = (*node)->child[rotate_l]->diff; if((*node)->child[rotate_l]->diff * diff_sign < 0){ AVL_set_inside_rotate(&(*node)->child[rotate_l], !rotate_right); } AVL_set_inside_rotate(node, rotate_right); return delta < 0 && child_diff != 0 ? -1 : 0; } if (delta > 0 && orig_diff == 0) return 1; else if(delta < 0 && orig_diff != 0) return -1; else return 0; }else{ return 0; } } } void AVL_set_inside_print(const AVL_set *node, int depth){ if(node == NULL) return; AVL_set_inside_print(node->child[1], depth + 1); printf("%lld %d\n", node->val,node->cnt); AVL_set_inside_print(node->child[0], depth + 1); } void AVL_set_inside_free(AVL_set *node){ if(node == NULL) return; AVL_set_inside_free(node->child[0]); AVL_set_inside_free(node->child[1]); free(node); } ll AVL_set_inside_count(AVL_set *root, ll val){ AVL_set *node; node = root; while(node){ if (val < node->val) node = node->child[0]; else if(val > node->val) node = node->child[1]; else return node->cnt; } return 0; } int AVL_set_lowcomp(ll node, ll val, int type){ if(node==val){ if(type!=3) return 0; else return 1; } if(node<val) return 1; if(node>val) return -1; return 0; } // return smallest p which meets a[p]==val :1 >=:2 >:3 AVL_set* AVL_set_inside_lowerbound(AVL_set *root, ll val, int type){ AVL_set *node; node = root; while(node){ int com=AVL_set_lowcomp(node->val,val,type); if(com==0) return node; if(com==1) node = node->child[1]; if(com==-1){ AVL_set *small; small=AVL_set_inside_lowerbound(node->child[0],val,type); if(type==1){ return small; }else{ if(small!=NULL) return small; else return node; } } } return node; } int AVL_set_upcomp(ll node, ll val, int type){ if(node==val){ if(type!=3) return 0; else return -1; } if(node<val) return 1; if(node>val) return -1; return 0; } // return biggest p which meets a[p]==val :1 <=:2 <:3 AVL_set* AVL_set_inside_upperbound(AVL_set *root, ll val, int type){ AVL_set *node; node = root; while(node){ int com=AVL_set_upcomp(node->val,val,type); if(com==0) return node; if(com==-1) node = node->child[0]; if(com==1){ AVL_set *big; big=AVL_set_inside_upperbound(node->child[1],val,type); if(type==1){ return big; }else{ if(big!=NULL) return big; else return node; } } } return node; } ll AVL_set_inside_minmax(AVL_set *root, int type){ while(root->child[type] !=NULL) root= root->child[type]; return root->val; } void AVL_set_inside_swap(AVL_set **node1, AVL_set **node2){ AVL_set *tmp; tmp=*node1; *node1=*node2; *node2=tmp; } #define set_MAX_SIZE 514511 ll set_main( int command , int set_num , ll val ,ll option){ static bool set_is_init=false; static AVL_set *set_pointer[set_MAX_SIZE]; static ll set_siz[set_MAX_SIZE]; if(!set_is_init){ set_is_init=true; rep(i,0,set_MAX_SIZE){ *(set_pointer+i) = NULL; set_siz[i]=0; } } if(command==-1){ AVL_set_inside_print( set_pointer[set_num] ,0); } if(command==1){ AVL_set_inside_count(set_pointer[set_num],val) ? 1 : set_siz[set_num]++; AVL_set_inside_update( &set_pointer[set_num] , val , 2 ); } if(command==2){ return AVL_set_inside_count(set_pointer[set_num],val); } if(command==3){ ( AVL_set_inside_count(set_pointer[set_num],val) > 1 ) ? 1 : set_siz[set_num]--; AVL_set_inside_update( &set_pointer[set_num] , val,1); } if(command==4){ set_siz[set_num]--; AVL_set_inside_update( &set_pointer[set_num] , val , 0 ); } if(command==5){ set_siz[set_num]=0; AVL_set_inside_free( set_pointer[set_num] ); set_pointer[set_num] = NULL; } if(command==6){ return set_siz[set_num]; } if(command==7){ return AVL_set_inside_minmax(set_pointer[set_num],1); } if(command==8){ return AVL_set_inside_minmax(set_pointer[set_num],0); } if(command==9){ AVL_set_inside_swap(&set_pointer[set_num],&set_pointer[val]); } if(10<=command&&command<=12){ AVL_set *lowbound = AVL_set_inside_lowerbound(set_pointer[set_num],val,command-9); if(lowbound==NULL) return option; else return lowbound->val; } if(13<=command&&command<=15){ AVL_set *upbound = AVL_set_inside_upperbound(set_pointer[set_num],val,command-12); if(upbound==NULL) return option; else return upbound->val; } return 0; } void set_print(int set_num){ set_main(-1,set_num,0,0); } void set_insert(int set_num, ll val){ set_main(1,set_num,val,0); } ll set_count(int set_num, ll val){ return set_main(2,set_num,val,0); } void set_erase(int set_num, ll val, int is_all){ if(is_all) set_main(4,set_num,val,0); else set_main(3,set_num,val,0); } void set_clear(int set_num){ set_main(5,set_num,0,0); } ll set_size(int set_num){ return set_main(6,set_num,0,0); } ll set_max(int set_num){ return set_main(7,set_num,0,0); } ll set_min(int set_num){ return set_main(8,set_num,0,0); } void set_swap(int set_num1, int set_num2){ set_main(9,set_num1,set_num2,0); } // return smallest p which meets a[p]==val :1 >=:2 >:3 ll set_lowerbound(int set_num, ll val, int type, ll error){ return set_main(9+type,set_num,val,error); } // return biggest p which meets a[p]==val :1 <=:2 <:3 ll set_upperbound(int set_num, ll val, int type, ll error){ return set_main(12+type,set_num,val,error); } /* insert * size * clear * erase * count * max * min * swap * begin x end x merge source の要素のキーと等価なキーの要素がある場合、その要素は source から抽出されない lower_bound * upper_bound * */ // ll map_main() /*---------------------------AVL start--------------------------------*/ #pragma endregion AVL #pragma endregion kyopuro_templates char s[1151154]; void solve(){ // fgets(s,sizeof(s),stdin); ll n; ll ans=0; cin(&n); // scanf("%s",s); ll a[n]; rep(i,0,n){ cin(&a[i]); } set_insert(0,a[0]); ll sum=a[0]; ll pp=0; rep(i,1,n){ sum+=a[i]; // if() if(set_count(pp,sum)||sum==0){ // set_clear(0); pp++; ans++; sum=a[i]; set_insert(pp,a[i]); }else{ set_insert(pp,sum); } // if(ext){ // if(sum+a[i]==0){ // ans++; // } // if( sum>0 != sum+a[i] ){ // } // } // if(plus){ // } // sum+=a[i]; // if(sum==0){ // ans++; // sum=a[i]; // } } printf("%lld\n",ans); } int main(void){ ll T=1; // cin(&T); rep(i,0,T){ solve(); } return 0; } /* while (ng + 1 < ok) { ll p = ng + (ok - ng) / 2; ll cnt = 0; rep(i,0,n){ cnt += (a[i] + p - 1) / p - 1; } if (cnt <= k) ok = p; else ng = p; } */ // 10^18 2^60 3^38 5^26
Kolya got an integer array $$$a_1, a_2, \dots, a_n$$$. The array can contain both positive and negative integers, but Kolya doesn't like $$$0$$$, so the array doesn't contain any zeros.Kolya doesn't like that the sum of some subsegments of his array can be $$$0$$$. The subsegment is some consecutive segment of elements of the array. You have to help Kolya and change his array in such a way that it doesn't contain any subsegments with the sum $$$0$$$. To reach this goal, you can insert any integers between any pair of adjacent elements of the array (integers can be really any: positive, negative, $$$0$$$, any by absolute value, even such a huge that they can't be represented in most standard programming languages).Your task is to find the minimum number of integers you have to insert into Kolya's array in such a way that the resulting array doesn't contain any subsegments with the sum $$$0$$$.
Print the minimum number of integers you have to insert into Kolya's array in such a way that the resulting array doesn't contain any subsegments with the sum $$$0$$$.
C
05548be393d794bf106708627220b9a3
673fb886466bf076395a2b647616a922
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "constructive algorithms", "sortings", "greedy" ]
1601280300
["4\n1 -5 3 2", "5\n4 -2 3 -9 2", "9\n-1 1 -1 1 -1 1 1 -1 -1", "8\n16 -5 -11 -15 10 5 4 -4"]
NoteConsider the first example. There is only one subsegment with the sum $$$0$$$. It starts in the second element and ends in the fourth element. It's enough to insert one element so the array doesn't contain any subsegments with the sum equal to zero. For example, it is possible to insert the integer $$$1$$$ between second and third elements of the array.There are no subsegments having sum $$$0$$$ in the second example so you don't need to do anything.
PASSED
1,500
standard input
2 seconds
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of elements in Kolya's array. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^{9} \le a_i \le 10^{9}, a_i \neq 0$$$) — the description of Kolya's array.
["1", "0", "6", "3"]
#include <stdio.h> #include <stdlib.h> typedef struct Node { long long int val; struct Node *next; } Node; Node** setCreate(int size); int setHash(int size, long long int val); int setContains(Node** set, int size, long long int val); void setAdd(Node** set, int size, long long int val); void setDestroy(Node** set, int size); const int SIZE = 1000; int main () { int n; scanf("%d", &n); long long int sum = 0; int cur; int cnt = 0; Node** set = setCreate(SIZE); setAdd(set, SIZE, 0); for (int i = 0; i < n; i++) { scanf("%d", &cur); sum += cur; if (setContains(set, SIZE, sum)) { cnt++; setDestroy(set, SIZE); set = setCreate(SIZE); setAdd(set, SIZE, 0); sum = cur; } setAdd(set, SIZE, sum); } printf("%d\n", cnt); return 0; } Node** setCreate(int size) { Node** set = (Node**)malloc(sizeof(Node) * size); for (int i = 0; i < size; i++) set[i] = NULL; return set; } int setHash(int size, long long int val) { return abs(val) % size; } int setContains(Node** set, int size, long long int val) { int h = setHash(size, val); for (Node* cur = set[h]; cur; cur = cur->next) if (cur->val == val) return 1; return 0; } void setAdd(Node** set, int size, long long int val) { int h = setHash(size, val); if (setContains(set, size, val)) return; Node* node = (Node*)malloc(sizeof(Node)); node->val = val; node->next = set[h]; set[h] = node; } void setDestroy(Node** set, int size) { for (int i = 0; i < size; i++) { Node* cur = set[i]; while (cur) { Node* tmp = cur; cur = cur->next; free(tmp); } } free(set); }
Kolya got an integer array $$$a_1, a_2, \dots, a_n$$$. The array can contain both positive and negative integers, but Kolya doesn't like $$$0$$$, so the array doesn't contain any zeros.Kolya doesn't like that the sum of some subsegments of his array can be $$$0$$$. The subsegment is some consecutive segment of elements of the array. You have to help Kolya and change his array in such a way that it doesn't contain any subsegments with the sum $$$0$$$. To reach this goal, you can insert any integers between any pair of adjacent elements of the array (integers can be really any: positive, negative, $$$0$$$, any by absolute value, even such a huge that they can't be represented in most standard programming languages).Your task is to find the minimum number of integers you have to insert into Kolya's array in such a way that the resulting array doesn't contain any subsegments with the sum $$$0$$$.
Print the minimum number of integers you have to insert into Kolya's array in such a way that the resulting array doesn't contain any subsegments with the sum $$$0$$$.
C
05548be393d794bf106708627220b9a3
5be7a0f151a306144abeb798df9e6316
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "constructive algorithms", "sortings", "greedy" ]
1601280300
["4\n1 -5 3 2", "5\n4 -2 3 -9 2", "9\n-1 1 -1 1 -1 1 1 -1 -1", "8\n16 -5 -11 -15 10 5 4 -4"]
NoteConsider the first example. There is only one subsegment with the sum $$$0$$$. It starts in the second element and ends in the fourth element. It's enough to insert one element so the array doesn't contain any subsegments with the sum equal to zero. For example, it is possible to insert the integer $$$1$$$ between second and third elements of the array.There are no subsegments having sum $$$0$$$ in the second example so you don't need to do anything.
PASSED
1,500
standard input
2 seconds
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of elements in Kolya's array. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^{9} \le a_i \le 10^{9}, a_i \neq 0$$$) — the description of Kolya's array.
["1", "0", "6", "3"]
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> typedef long long value_t; typedef struct node node; struct node { value_t val; node *next; }; node *node_new(value_t val) { node *n = malloc(sizeof(node)); n->val = val; n->next = NULL; return n; } void node_free(node *n) { if (n->next != NULL) { node_free(n->next); } free(n); } void node_append(node *n, value_t val) { while (n->next != NULL) { n = n->next; } n->next = node_new(val); } bool node_contains(node *n, value_t val) { do { if (n->val == val) { return true; } n = n->next; } while (n != NULL); return false; } typedef struct { int size, capacity; node **buckets; } set; int set_hash(value_t val, int capacity) { int res = (int) (val % capacity); if (res < 0) { res += capacity; } return res; } void set_buckets_free(set *s) { for (int i = 0; i < s->capacity; i++) { node *n = s->buckets[i]; if (n != NULL) { node_free(n); } } free(s->buckets); } void set_init(set *s) { s->size = 0; s->capacity = 16; s->buckets = calloc(s->capacity, sizeof(node *)); } void set_insert_to_buckets(value_t val, node **buckets, int capacity) { int bucket_idx = set_hash(val, capacity); if (buckets[bucket_idx] == NULL) { buckets[bucket_idx] = node_new(val); } else { node_append(buckets[bucket_idx], val); } } void set_grow(set *s) { int new_capacity = s->capacity * 2 + 1; node **new_buckets = calloc(new_capacity, sizeof(node *)); for (int i = 0; i < s->capacity; i++) { node *n = s->buckets[i]; while (n != NULL) { set_insert_to_buckets(n->val, new_buckets, new_capacity); n = n->next; } } set_buckets_free(s); s->capacity = new_capacity; s->buckets = new_buckets; } void set_insert(set *s, value_t val) { s->size++; set_insert_to_buckets(val, s->buckets, s->capacity); if (s->size > s->capacity / 2) { set_grow(s); } } bool set_contains(set *s, value_t val) { int bucket_idx = set_hash(val, s->capacity); if (s->buckets[bucket_idx] == NULL) { return false; } else { return node_contains(s->buckets[bucket_idx], val); } } int main() { int ar[200000]; int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &ar[i]); } int ans = 0; long long cursum = 0; set s; set_init(&s); set_insert(&s, 0); for (int i = 0; i < n; i++) { int x = ar[i]; cursum += x; if (set_contains(&s, cursum)) { cursum = x; ans++; set_buckets_free(&s); set_init(&s); set_insert(&s, 0); } set_insert(&s, cursum); } printf("%d\n", ans); }
Kolya got an integer array $$$a_1, a_2, \dots, a_n$$$. The array can contain both positive and negative integers, but Kolya doesn't like $$$0$$$, so the array doesn't contain any zeros.Kolya doesn't like that the sum of some subsegments of his array can be $$$0$$$. The subsegment is some consecutive segment of elements of the array. You have to help Kolya and change his array in such a way that it doesn't contain any subsegments with the sum $$$0$$$. To reach this goal, you can insert any integers between any pair of adjacent elements of the array (integers can be really any: positive, negative, $$$0$$$, any by absolute value, even such a huge that they can't be represented in most standard programming languages).Your task is to find the minimum number of integers you have to insert into Kolya's array in such a way that the resulting array doesn't contain any subsegments with the sum $$$0$$$.
Print the minimum number of integers you have to insert into Kolya's array in such a way that the resulting array doesn't contain any subsegments with the sum $$$0$$$.
C
05548be393d794bf106708627220b9a3
56e8efdc730da8d2bcb5d06672e62d29
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "data structures", "constructive algorithms", "sortings", "greedy" ]
1601280300
["4\n1 -5 3 2", "5\n4 -2 3 -9 2", "9\n-1 1 -1 1 -1 1 1 -1 -1", "8\n16 -5 -11 -15 10 5 4 -4"]
NoteConsider the first example. There is only one subsegment with the sum $$$0$$$. It starts in the second element and ends in the fourth element. It's enough to insert one element so the array doesn't contain any subsegments with the sum equal to zero. For example, it is possible to insert the integer $$$1$$$ between second and third elements of the array.There are no subsegments having sum $$$0$$$ in the second example so you don't need to do anything.
PASSED
1,500
standard input
2 seconds
The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of elements in Kolya's array. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^{9} \le a_i \le 10^{9}, a_i \neq 0$$$) — the description of Kolya's array.
["1", "0", "6", "3"]
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> typedef long long value_t; typedef struct node node; struct node { value_t val; node *next; }; node *node_new(value_t val) { node *n = malloc(sizeof(node)); n->val = val; n->next = NULL; return n; } void node_free(node *n) { if (n->next != NULL) { node_free(n->next); } free(n); } void node_append(node *n, value_t val) { while (n->next != NULL) { n = n->next; } n->next = node_new(val); } bool node_contains(node *n, value_t val) { do { if (n->val == val) { return true; } n = n->next; } while (n != NULL); return false; } typedef struct { int size, capacity; node **buckets; } set; int set_hash(value_t val, int capacity) { int res = (int) (val % capacity); if (res < 0) { res += capacity; } return res; } void set_buckets_free(set *s) { for (int i = 0; i < s->capacity; i++) { node *n = s->buckets[i]; if (n != NULL) { node_free(n); } } free(s->buckets); } void set_init(set *s) { s->size = 0; s->capacity = 16; s->buckets = calloc(s->capacity, sizeof(node *)); } void set_clear(set *s) { if (s->buckets != NULL) { set_buckets_free(s); } set_init(s); } void set_insert_to_buckets(value_t val, node **buckets, int capacity) { int bucket_idx = set_hash(val, capacity); if (buckets[bucket_idx] == NULL) { buckets[bucket_idx] = node_new(val); } else { node_append(buckets[bucket_idx], val); } } void set_grow(set *s) { int new_capacity = s->capacity * 2 + 1; node **new_buckets = calloc(new_capacity, sizeof(node *)); for (int i = 0; i < s->capacity; i++) { node *n = s->buckets[i]; while (n != NULL) { set_insert_to_buckets(n->val, new_buckets, new_capacity); n = n->next; } } set_buckets_free(s); s->capacity = new_capacity; s->buckets = new_buckets; } void set_insert(set *s, value_t val) { s->size++; set_insert_to_buckets(val, s->buckets, s->capacity); if (s->size > s->capacity / 2) { set_grow(s); } } bool set_contains(set *s, value_t val) { int bucket_idx = set_hash(val, s->capacity); if (s->buckets[bucket_idx] == NULL) { return false; } else { return node_contains(s->buckets[bucket_idx], val); } } int main() { int ar[200000]; int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &ar[i]); } int ans = 0; long long cursum = 0; set s; set_init(&s); set_insert(&s, 0); for (int i = 0; i < n; i++) { int x = ar[i]; cursum += x; if (set_contains(&s, cursum)) { cursum = x; ans++; set_clear(&s); set_insert(&s, 0); } set_insert(&s, cursum); } printf("%d\n", ans); }
On a number axis directed from the left rightwards, n marbles with coordinates x1, x2, ..., xn are situated. Let's assume that the sizes of the marbles are infinitely small, that is in this task each of them is assumed to be a material point. You can stick pins in some of them and the cost of sticking in the marble number i is equal to ci, number ci may be negative. After you choose and stick the pins you need, the marbles will start to roll left according to the rule: if a marble has a pin stuck in it, then the marble doesn't move, otherwise the marble rolls all the way up to the next marble which has a pin stuck in it and stops moving there. If there is no pinned marble on the left to the given unpinned one, it is concluded that the marble rolls to the left to infinity and you will pay an infinitely large fine for it. If no marble rolled infinitely to the left, then the fine will consist of two summands: the sum of the costs of stuck pins; the sum of the lengths of the paths of each of the marbles, that is the sum of absolute values of differences between their initial and final positions. Your task is to choose and pin some marbles in the way that will make the fine for you to pay as little as possible.
Output the single number — the least fine you will have to pay.
C
334d2bcb32d88a7037bcf262f49938cf
e01b38eb7108ac2d382eb9e76f9150b4
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dp", "sortings" ]
1288440000
["3\n2 3\n3 4\n1 2", "4\n1 7\n3 1\n5 10\n6 1"]
null
PASSED
1,800
standard input
2 seconds
The first input line contains an integer n (1 ≤ n ≤ 3000) which is the number of marbles. The next n lines contain the descriptions of the marbles in pairs of integers xi, ci ( - 109 ≤ xi, ci ≤ 109). The numbers are space-separated. Each description is given on a separate line. No two marbles have identical initial positions.
["5", "11"]
#include <stdio.h> #define MAXN 3005 #define oo 9223372036854775807LL long n; long long f[MAXN][MAXN]={0},min,ans=oo; char h[MAXN][MAXN]={'\0'}; struct point {long long d,c;}a[MAXN]={0},tmp={0}; void qsort(long left,long right) { if(left<right) { long l=left,r=right,mid=(l+r)>>1; tmp=a[mid];a[mid]=a[l]; while(l<r) { while(l<r && a[r].d>=tmp.d) r--; if(l<r) a[l++]=a[r]; while(l<r && a[l].d<=tmp.d) l++; if(l<r) a[r--]=a[l]; } a[l]=tmp; qsort(left,l-1); qsort(l+1,right); } } int main() { long i,j,k; scanf("%ld",&n); for(i=1;i<=n;i++) scanf("%I64d%I64d",&a[i].d,&a[i].c); qsort(1,n); f[1][1]=a[1].c;h[1][1]='Y'; for(i=1+1;i<=n;i++) { min=oo; for(j=1;j<i;j++) if(h[i-1][j]=='Y') { if(f[i-1][j]<min) min=f[i-1][j]; if(h[i][j]=='\0' || f[i-1][j]+a[i].d-a[j].d<f[i][j]) {f[i][j]=f[i-1][j]+a[i].d-a[j].d;h[i][j]='Y';} } f[i][i]=min+a[i].c;h[i][i]='Y'; } for(i=1;i<=n;i++) if(f[n][i]<ans) ans=f[n][i]; printf("%I64d\n",ans); return(0); }
On a number axis directed from the left rightwards, n marbles with coordinates x1, x2, ..., xn are situated. Let's assume that the sizes of the marbles are infinitely small, that is in this task each of them is assumed to be a material point. You can stick pins in some of them and the cost of sticking in the marble number i is equal to ci, number ci may be negative. After you choose and stick the pins you need, the marbles will start to roll left according to the rule: if a marble has a pin stuck in it, then the marble doesn't move, otherwise the marble rolls all the way up to the next marble which has a pin stuck in it and stops moving there. If there is no pinned marble on the left to the given unpinned one, it is concluded that the marble rolls to the left to infinity and you will pay an infinitely large fine for it. If no marble rolled infinitely to the left, then the fine will consist of two summands: the sum of the costs of stuck pins; the sum of the lengths of the paths of each of the marbles, that is the sum of absolute values of differences between their initial and final positions. Your task is to choose and pin some marbles in the way that will make the fine for you to pay as little as possible.
Output the single number — the least fine you will have to pay.
C
334d2bcb32d88a7037bcf262f49938cf
47525d5c2306223a191549167a7a21d8
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dp", "sortings" ]
1288440000
["3\n2 3\n3 4\n1 2", "4\n1 7\n3 1\n5 10\n6 1"]
null
PASSED
1,800
standard input
2 seconds
The first input line contains an integer n (1 ≤ n ≤ 3000) which is the number of marbles. The next n lines contain the descriptions of the marbles in pairs of integers xi, ci ( - 109 ≤ xi, ci ≤ 109). The numbers are space-separated. Each description is given on a separate line. No two marbles have identical initial positions.
["5", "11"]
#include <stdio.h> #include <stdlib.h> long long dp[3000][3000]; typedef struct { int x; int c; } marble; int cmp(const void *a, const void *b) { return ((marble *)a)->x - ((marble *)b)->x; } long long minimum(long long a, long long b) { if (a < b) { return a; } else { return b; } } int main() { int n, p = 0, i, j; marble m[3000]; long long x = 1e18; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { dp[i][j] = 1e18; } } for (i = 0; i < n; i++) scanf("%d %d", &m[i].x, &m[i].c); qsort(m, n, sizeof(marble), cmp); dp[0][0] = m[0].c; for (i = 1; i < n; i++) { for (j = 0; j < i; j++) { dp[i][j] = dp[i - 1][j] + m[i].x - m[j].x; } for (j = 0; j < i; j++) { dp[i][i] = minimum(dp[i][i], dp[i - 1][j] + m[i].c); } } for (i = 0; i < n; i++) x = minimum(x, dp[n - 1][i]); printf("%I64d\n", x); return 0; }
On a number axis directed from the left rightwards, n marbles with coordinates x1, x2, ..., xn are situated. Let's assume that the sizes of the marbles are infinitely small, that is in this task each of them is assumed to be a material point. You can stick pins in some of them and the cost of sticking in the marble number i is equal to ci, number ci may be negative. After you choose and stick the pins you need, the marbles will start to roll left according to the rule: if a marble has a pin stuck in it, then the marble doesn't move, otherwise the marble rolls all the way up to the next marble which has a pin stuck in it and stops moving there. If there is no pinned marble on the left to the given unpinned one, it is concluded that the marble rolls to the left to infinity and you will pay an infinitely large fine for it. If no marble rolled infinitely to the left, then the fine will consist of two summands: the sum of the costs of stuck pins; the sum of the lengths of the paths of each of the marbles, that is the sum of absolute values of differences between their initial and final positions. Your task is to choose and pin some marbles in the way that will make the fine for you to pay as little as possible.
Output the single number — the least fine you will have to pay.
C
334d2bcb32d88a7037bcf262f49938cf
2dac2c457d4dd8ee31060ccca1b5afd8
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dp", "sortings" ]
1288440000
["3\n2 3\n3 4\n1 2", "4\n1 7\n3 1\n5 10\n6 1"]
null
PASSED
1,800
standard input
2 seconds
The first input line contains an integer n (1 ≤ n ≤ 3000) which is the number of marbles. The next n lines contain the descriptions of the marbles in pairs of integers xi, ci ( - 109 ≤ xi, ci ≤ 109). The numbers are space-separated. Each description is given on a separate line. No two marbles have identical initial positions.
["5", "11"]
#include <stdio.h> #define oo 1000000000 struct zxf { long long c,x; }a[5000]={0,0},tmp; long long f[5000]={0}; void quick(long l,long r) { long i,j,t; t=(l+r)/2; i=l; j=r+1; while(i<j) { while(i<j && a[i].x>a[t].x) i++; if(i<j) { tmp=a[i]; a[i]=a[t]; a[t]=tmp; t=i; j--; } while(i<j && a[t].x>a[j].x) j--; if(i<j) { tmp=a[t]; a[t]=a[j]; a[j]=tmp; t=j; i++; } } if(l<t-1) quick(l,t-1); if(t+1<r) quick(t+1,r); } int main() { long long cost; long i,n,j; scanf("%I64d\n",&n); for(i=1;i<=n;i++) scanf("%I64d %I64d\n",&a[i].x,&a[i].c); quick(1,n); for(i=1;i<=n;i++) f[i]=(long long )oo*oo; f[1]=a[1].c; for(i=1;i<=n;i++) { for(j=i-1,cost=0;j>=0;j--) { if(cost+f[j]+a[i].c<f[i]) f[i]=f[j]+cost+a[i].c; cost+=a[j].x-a[i].x; } } printf("%I64d",f[n]); return 0; }
On a number axis directed from the left rightwards, n marbles with coordinates x1, x2, ..., xn are situated. Let's assume that the sizes of the marbles are infinitely small, that is in this task each of them is assumed to be a material point. You can stick pins in some of them and the cost of sticking in the marble number i is equal to ci, number ci may be negative. After you choose and stick the pins you need, the marbles will start to roll left according to the rule: if a marble has a pin stuck in it, then the marble doesn't move, otherwise the marble rolls all the way up to the next marble which has a pin stuck in it and stops moving there. If there is no pinned marble on the left to the given unpinned one, it is concluded that the marble rolls to the left to infinity and you will pay an infinitely large fine for it. If no marble rolled infinitely to the left, then the fine will consist of two summands: the sum of the costs of stuck pins; the sum of the lengths of the paths of each of the marbles, that is the sum of absolute values of differences between their initial and final positions. Your task is to choose and pin some marbles in the way that will make the fine for you to pay as little as possible.
Output the single number — the least fine you will have to pay.
C
334d2bcb32d88a7037bcf262f49938cf
51c69ec7ee12ec36d50c45ac286367ff
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dp", "sortings" ]
1288440000
["3\n2 3\n3 4\n1 2", "4\n1 7\n3 1\n5 10\n6 1"]
null
PASSED
1,800
standard input
2 seconds
The first input line contains an integer n (1 ≤ n ≤ 3000) which is the number of marbles. The next n lines contain the descriptions of the marbles in pairs of integers xi, ci ( - 109 ≤ xi, ci ≤ 109). The numbers are space-separated. Each description is given on a separate line. No two marbles have identical initial positions.
["5", "11"]
#include <stdio.h> #include <stdlib.h> #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define INF 1ll << 62 typedef long long ll; struct marble { int x; int c; }; struct marble a[3000]; ll dp[3000][2]; ll d[3000][3000]; int cmp(const void *_p, const void *_q) { struct marble *p = (struct marble *)_p; struct marble *q = (struct marble *)_q; return p->x - q->x; } void func(int n) { int i, j; ll ans; qsort(a, n, sizeof(struct marble), cmp); for (i = 0; i < n; i ++) { d[i][i] = 0; for (j = i + 1; j < n; j ++) { d[i][j] = d[i][j - 1] + (a[j].x - a[i].x); } } dp[0][1] = a[0].c; dp[0][0] = INF; for (i = 1; i < n; i ++) { dp[i][0] = INF; dp[i][1] = MIN(dp[i - 1][1], dp[i - 1][0]) + a[i].c; for (j = 0; j < i; j ++) { dp[i][0] = MIN(dp[i][0], dp[j][1] + d[j][i]); } } ans = MIN(dp[n - 1][0], dp[n - 1][1]); printf("%I64d\n", ans); } int main() { int n, i; while (scanf("%d", &n) == 1) { for (i = 0; i < n; i ++) { scanf("%d%d", &a[i].x, &a[i].c); } func(n); } return 0; }
On a number axis directed from the left rightwards, n marbles with coordinates x1, x2, ..., xn are situated. Let's assume that the sizes of the marbles are infinitely small, that is in this task each of them is assumed to be a material point. You can stick pins in some of them and the cost of sticking in the marble number i is equal to ci, number ci may be negative. After you choose and stick the pins you need, the marbles will start to roll left according to the rule: if a marble has a pin stuck in it, then the marble doesn't move, otherwise the marble rolls all the way up to the next marble which has a pin stuck in it and stops moving there. If there is no pinned marble on the left to the given unpinned one, it is concluded that the marble rolls to the left to infinity and you will pay an infinitely large fine for it. If no marble rolled infinitely to the left, then the fine will consist of two summands: the sum of the costs of stuck pins; the sum of the lengths of the paths of each of the marbles, that is the sum of absolute values of differences between their initial and final positions. Your task is to choose and pin some marbles in the way that will make the fine for you to pay as little as possible.
Output the single number — the least fine you will have to pay.
C
334d2bcb32d88a7037bcf262f49938cf
fbbc2df257e5dc7b96a6f848956a67d8
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dp", "sortings" ]
1288440000
["3\n2 3\n3 4\n1 2", "4\n1 7\n3 1\n5 10\n6 1"]
null
PASSED
1,800
standard input
2 seconds
The first input line contains an integer n (1 ≤ n ≤ 3000) which is the number of marbles. The next n lines contain the descriptions of the marbles in pairs of integers xi, ci ( - 109 ≤ xi, ci ≤ 109). The numbers are space-separated. Each description is given on a separate line. No two marbles have identical initial positions.
["5", "11"]
#include <stdio.h> #define oo 100000000000000000LL #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) struct case1 { long long x,c; }dian[3005]={{0,0}}; long long f[3005]={0}; long long g[3005]={0}; int main() { long long n,i,j; long long s=0; struct case1 temp; scanf("%I64d",&n); for(i=1;i<=n;i++) { scanf("%I64d%I64d",&dian[i].x,&dian[i].c); f[i]=g[i]=oo; } for(i=1;i<n;i++) for(j=i+1;j<=n;j++) if(dian[i].x>dian[j].x) { temp=dian[i]; dian[i]=dian[j]; dian[j]=temp; } for(i=1;i<=n;i++) { s=0; f[i]=g[i-1]+dian[i].c; for(j=i-1;j>=1;j--) { s+=(i-j)*(dian[j+1].x-dian[j].x); if(f[j]+s<g[i]) g[i]=f[j]+s; } if(f[i]<g[i]) g[i]=f[i]; } printf("%I64d\n",g[n]); return 0; }
On a number axis directed from the left rightwards, n marbles with coordinates x1, x2, ..., xn are situated. Let's assume that the sizes of the marbles are infinitely small, that is in this task each of them is assumed to be a material point. You can stick pins in some of them and the cost of sticking in the marble number i is equal to ci, number ci may be negative. After you choose and stick the pins you need, the marbles will start to roll left according to the rule: if a marble has a pin stuck in it, then the marble doesn't move, otherwise the marble rolls all the way up to the next marble which has a pin stuck in it and stops moving there. If there is no pinned marble on the left to the given unpinned one, it is concluded that the marble rolls to the left to infinity and you will pay an infinitely large fine for it. If no marble rolled infinitely to the left, then the fine will consist of two summands: the sum of the costs of stuck pins; the sum of the lengths of the paths of each of the marbles, that is the sum of absolute values of differences between their initial and final positions. Your task is to choose and pin some marbles in the way that will make the fine for you to pay as little as possible.
Output the single number — the least fine you will have to pay.
C
334d2bcb32d88a7037bcf262f49938cf
3f327a51f2bb2a84328e6dfa9e51f154
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dp", "sortings" ]
1288440000
["3\n2 3\n3 4\n1 2", "4\n1 7\n3 1\n5 10\n6 1"]
null
PASSED
1,800
standard input
2 seconds
The first input line contains an integer n (1 ≤ n ≤ 3000) which is the number of marbles. The next n lines contain the descriptions of the marbles in pairs of integers xi, ci ( - 109 ≤ xi, ci ≤ 109). The numbers are space-separated. Each description is given on a separate line. No two marbles have identical initial positions.
["5", "11"]
#include<math.h> #include<time.h> #include<stdio.h> #include<string.h> #include<stdlib.h> #define oo 1000000000000000000LL #define pi 3.14159265359 #define zero(a) (abb(a)<=1e-7) #define lowbit(a) ((a)&(-(a))) #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) #define abb(a) ((a)>0?(a):(-(a))) #define cj(x1,y1,x2,y2) ((x1)*(y2)-(x2)*(y2)) #define dj(x1,y1,x2,y2) ((x1)*(y1)+(y1)*(y2)) #define dis(x1,y1,x2,y2) sqrt(((x2)-(x1))*((x2)-(x1))+((y2)-(y1))*((y2)-(y1))) struct case1 { long x,c; }p[3001]={{0,0}}; long long f[3001]={0},s[3001]={0}; int main() { long i,j,n; struct case1 t; scanf("%ld",&n); for (i=1;i<=n;i++) scanf("%ld%ld",&p[i].x,&p[i].c); for (i=1;i<n;i++) for (j=i+1;j<=n;j++) if (p[i].x>p[j].x) { t=p[i]; p[i]=p[j]; p[j]=t; } for (i=1;i<=n;i++) { s[i]=s[i-1]+p[i].x; f[i]=oo; for (j=i;j>=1;j--) f[i]=min(f[i],f[j-1]+p[j].c+s[i]-s[j-1]-(long long)p[j].x*(i-j+1)); } printf("%I64d\n",f[n]); return 0; }
On a number axis directed from the left rightwards, n marbles with coordinates x1, x2, ..., xn are situated. Let's assume that the sizes of the marbles are infinitely small, that is in this task each of them is assumed to be a material point. You can stick pins in some of them and the cost of sticking in the marble number i is equal to ci, number ci may be negative. After you choose and stick the pins you need, the marbles will start to roll left according to the rule: if a marble has a pin stuck in it, then the marble doesn't move, otherwise the marble rolls all the way up to the next marble which has a pin stuck in it and stops moving there. If there is no pinned marble on the left to the given unpinned one, it is concluded that the marble rolls to the left to infinity and you will pay an infinitely large fine for it. If no marble rolled infinitely to the left, then the fine will consist of two summands: the sum of the costs of stuck pins; the sum of the lengths of the paths of each of the marbles, that is the sum of absolute values of differences between their initial and final positions. Your task is to choose and pin some marbles in the way that will make the fine for you to pay as little as possible.
Output the single number — the least fine you will have to pay.
C
334d2bcb32d88a7037bcf262f49938cf
06de4b170cc7d631006f86ded18c00f4
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dp", "sortings" ]
1288440000
["3\n2 3\n3 4\n1 2", "4\n1 7\n3 1\n5 10\n6 1"]
null
PASSED
1,800
standard input
2 seconds
The first input line contains an integer n (1 ≤ n ≤ 3000) which is the number of marbles. The next n lines contain the descriptions of the marbles in pairs of integers xi, ci ( - 109 ≤ xi, ci ≤ 109). The numbers are space-separated. Each description is given on a separate line. No two marbles have identical initial positions.
["5", "11"]
long long dp[3000][3000]; typedef struct { int x; int c; } marble; int cmp(const void *a, const void *b) { return ((marble *)a)->x - ((marble *)b)->x; } long long minimum(long long a, long long b) { if (a < b) { return a; } else { return b; } } int main() { int n, p = 0, i, j; marble m[3000]; long long x = 1e18; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { dp[i][j] = 1e18; } } for (i = 0; i < n; i++) scanf("%d %d", &m[i].x, &m[i].c); qsort(m, n, sizeof(marble), cmp); dp[0][0] = m[0].c; for (i = 1; i < n; i++) { for (j = 0; j < i; j++) { dp[i][j] = dp[i - 1][j] + m[i].x - m[j].x; } for (j = 0; j < i; j++) { dp[i][i] = minimum(dp[i][i], dp[i - 1][j] + m[i].c); } } for (i = 0; i < n; i++) x = minimum(x, dp[n - 1][i]); printf("%I64d\n", x); return 0; }
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
C
6639d6c53951f8c1a8324fb24ef68f7a
8c84adf3593acd6c844f0f7f793f6e43
GNU C
standard output
256 megabytes
train_001.jsonl
[ "strings" ]
1301410800
["4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis"]
null
PASSED
800
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
["word\nl10n\ni18n\np43s"]
#include<stdio.h> main(){ int a,i,j,sum; char n[200]; scanf("%d",&a); for(i=1;i<=a;i++){ scanf("%s",n); sum=0; for(j=0;n[j]!='\0';j++){ sum++; } if(sum>10) printf("%c%d%c\n",n[0],sum-2,n[sum-1]); else printf("%s\n",n); } }
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
C
6639d6c53951f8c1a8324fb24ef68f7a
9767ea67610b1a85e5bd9b1532a4044d
GNU C
standard output
256 megabytes
train_001.jsonl
[ "strings" ]
1301410800
["4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis"]
null
PASSED
800
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
["word\nl10n\ni18n\np43s"]
#include<stdio.h> #include<stdlib.h> #include<string.h> int main() { char* word; int x,i,y; scanf("%d",&x); for(i=0;i<x;i++) { word=(char*)malloc(sizeof(char)*120); scanf("%s",word); y=strlen(word); if(y<=10) printf("%s\n",word); else printf("%c%d%c\n",*word,(y-2),*(word+y-1)); } return 0; }
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
C
6639d6c53951f8c1a8324fb24ef68f7a
9e159b97af6bc3bcc8ffebcb5042dbfc
GNU C
standard output
256 megabytes
train_001.jsonl
[ "strings" ]
1301410800
["4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis"]
null
PASSED
800
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
["word\nl10n\ni18n\np43s"]
#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { char* a; a=calloc(102,sizeof(char)); int num; scanf("%d",&num); int i=0; int x; while(i!=num) { scanf("%s",a); x=strlen(a); if((x)<=10) printf("%s",a); else { printf("%c%d%c",a[0],(x-2),a[x-1]); } printf("\n"); i++; } return 0; }
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
C
6639d6c53951f8c1a8324fb24ef68f7a
c6c358fb47f886e468dbf79c3cf2f1ff
GNU C
standard output
256 megabytes
train_001.jsonl
[ "strings" ]
1301410800
["4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis"]
null
PASSED
800
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
["word\nl10n\ni18n\np43s"]
#include <stdio.h> int main(void) { int g,i; scanf("%d",&g); char w[100][10000]; for(i=0;i<g;i++) { scanf("%s",&w[i]); } int j,k,l[100]; for(j=0;j<g;j++) { l[j]=strlen(w[j]); } for(k=0;k<g;k++) { if(l[k]<=10) { printf("%s",w[k]); } else { printf("%c%d%c",w[k][0],(l[k])-2,w[k][l[k]-1]); } printf("\n"); } }
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
C
6639d6c53951f8c1a8324fb24ef68f7a
95e85eb203a590170bbdf03abf85000e
GNU C
standard output
256 megabytes
train_001.jsonl
[ "strings" ]
1301410800
["4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis"]
null
PASSED
800
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
["word\nl10n\ni18n\np43s"]
#include<stdio.h> int panduan(char *p); int main() { int i,n; char str[105]; scanf("%d",&n); while(n--) { scanf("%s",str); i=panduan(str); if(i>10) { printf("%c%d%c\n",str[0],(i-2),str[i-1]); } else { printf("%s\n",str); } } return 0; } int panduan(char *p) { int i; for(i=0;i<105;i++) { if(p[i]=='\0') { return i; break; } } }
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
C
6639d6c53951f8c1a8324fb24ef68f7a
fe1da7d0d514c7453030fbc6bface2dc
GNU C
standard output
256 megabytes
train_001.jsonl
[ "strings" ]
1301410800
["4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis"]
null
PASSED
800
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
["word\nl10n\ni18n\np43s"]
#include<stdio.h> #include<string.h> void wtlw(char s[101]) { int k=0,i=0; k=strlen(s); if(k>10) printf("%c%d%c\n",s[0],k-2,s[k-1]); else printf("%s\n",s); } int main() { char s[100][101]; int n,i; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%s",s[i]); } for(i=0;i<n;i++) wtlw(s[i]); return 0; }
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
C
6639d6c53951f8c1a8324fb24ef68f7a
68000257c339eee53f3bea89085470c8
GNU C
standard output
256 megabytes
train_001.jsonl
[ "strings" ]
1301410800
["4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis"]
null
PASSED
800
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
["word\nl10n\ni18n\np43s"]
#include <stdio.h> #include <string.h> int main() { int i,j,n; scanf("%d",&n); char a[n][150]; for(i=0;i<n;i++) scanf("%s",&a[i]); for(i=0;i<n;i++) if(strlen(a[i])>10) printf("%c%d%c\n",a[i][0],strlen(a[i])-2,a[i][strlen(a[i])-1]); else puts(a[i]); return 0; }
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
C
6639d6c53951f8c1a8324fb24ef68f7a
cb12b57521c788646fd0f33d5b981067
GNU C
standard output
256 megabytes
train_001.jsonl
[ "strings" ]
1301410800
["4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis"]
null
PASSED
800
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
["word\nl10n\ni18n\np43s"]
#include<stdio.h> #include<string.h> int main() { int n,l; char s[100]; scanf("%d",&n); while(n--){ scanf("%s",s); l=strlen(s); if(l<=10) printf("%s\n",s); else printf("%c%d%c\n",s[0],l-2,s[l-1]); } return 0; }
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
C
6639d6c53951f8c1a8324fb24ef68f7a
21bc8f548656b926e6aaa38052fca86c
GNU C
standard output
256 megabytes
train_001.jsonl
[ "strings" ]
1301410800
["4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis"]
null
PASSED
800
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
["word\nl10n\ni18n\np43s"]
#include<stdio.h> #include<string.h> int main() { int i,n; char a[100]; scanf("%d",&n);getchar(); for(i=0;i<n;i++) { gets(a); if(strlen(a)>10) printf("%c%d%c\n",a[0],strlen(a)-2,a[strlen(a)-1]); else puts(a); } return 0; }
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
C
6639d6c53951f8c1a8324fb24ef68f7a
eaec87970a386e95e358dcfcea6718cd
GNU C
standard output
256 megabytes
train_001.jsonl
[ "strings" ]
1301410800
["4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis"]
null
PASSED
800
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
["word\nl10n\ni18n\np43s"]
#include<stdio.h> #include<string.h> int main() { int i,n,len; char a[1000]; scanf("%d",&n);getchar(); for(i=0;i<n;i++) { gets(a); if(strlen(a)>10) printf("%c%d%c\n",a[0],strlen(a)-2,a[strlen(a)-1]); else puts(a); } return 0; }
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
C
6639d6c53951f8c1a8324fb24ef68f7a
e27811de40c29f35f0cf74448a729f05
GNU C
standard output
256 megabytes
train_001.jsonl
[ "strings" ]
1301410800
["4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis"]
null
PASSED
800
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
["word\nl10n\ni18n\np43s"]
#include<stdio.h> #include<string.h> int main() { int i,n,l; char a[100]; scanf("%d",&n); getchar(); for(i=0;i<n;i++) { gets(a); if(strlen(a)>10) printf("%c%d%c\n",a[0],strlen(a)-2,a[strlen(a)-1]); else puts(a); } return 0; }
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
C
6639d6c53951f8c1a8324fb24ef68f7a
ec0ef31ae294f1e32dcfcf3c11ce1bc8
GNU C
standard output
256 megabytes
train_001.jsonl
[ "strings" ]
1301410800
["4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis"]
null
PASSED
800
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
["word\nl10n\ni18n\np43s"]
#include<stdio.h> #include<math.h> #include<string.h> int main() { int x,y; char z[100]; scanf("%d",&x); for(int i=0;i<x;i++) { scanf("%s",&z); if(strlen(z)<=10) printf("%s",z); else printf("%c%d%c",z[0],strlen(z)-2,z[strlen(z)-1]); printf("\n"); } }
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Print n lines. The i-th line should contain the result of replacing of the i-th word from the input data.
C
6639d6c53951f8c1a8324fb24ef68f7a
fdfa7b2dcce431c7de391101b2d7a16f
GNU C
standard output
256 megabytes
train_001.jsonl
[ "strings" ]
1301410800
["4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis"]
null
PASSED
800
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 100). Each of the following n lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
["word\nl10n\ni18n\np43s"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int n,i=0,j; char str[101]; scanf("%d",&n); if(n<1||n>100) exit(1); do { scanf("%s",str); char tmp = getchar(); for(j=0;j<strlen(str);j++) { if(str[j]<'a'||str[j]>'z') exit(1); } if(strlen(str)>100) exit(1); else if(strlen(str)<=10) { printf("%s\n",str); i++; } else if(strlen(str)>10) { printf("%c%d%c\n",str[0],strlen(str)-2,str[strlen(str)-1]); i++; } } while(i!=n); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
df86270831c3dbe852ea6dc464b3ba40
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> #include<string.h> #include<stdlib.h> int main(){ int n,m,l,r; char c1[2],c2[2]; scanf("%d%d",&n,&m); char *str=malloc((n+1)*sizeof(char)); scanf("%s",str); while(m--){ scanf("%d%d%s%s",&l,&r,c1,c2); l--;r--; // printf("%c\t%c\n",c1,c2); for(int i=l;i<=r;i++){ //printf("%d\n",i); if(str[i]==c1[0]){str[i]=c2[0];} } } for(int i=0;i<n;i++){printf("%c",str[i]);} printf("\n"); }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
0a5854b1ca27f0b21cc7d4381dea4cf7
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> void change(char* str, int l, int r, char e, char s) { for (int i=l-1; i<r; i++) { if (str[i]==e) str[i]=s; } } int main() { int len,op; scanf("%d %d",&len,&op); char word[len]; scanf("%s",word); for (int i=0; i<op; i++) { int l,r,e,s; scanf("%d %d %c %c",&l,&r,&e,&s); change(word,l,r,e,s); } printf("%s",word); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
205e679d488a2b3b2035d89bcf1b0ced
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> int main() { char ch[1000],c1,c2; int i,j,l,r,n,m; scanf("%d %d",&n,&m); getchar(); gets(ch); for(i=0; i<m; i++) { scanf("%d %d %c %c",&l,&r,&c1,&c2); for(j=l-1; j<r; j++) { if(ch[j]==c1) { ch[j]=c2; } } } printf(ch); }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
44d86e61d70ae128af7ed0d5b531cd05
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> int main() { int n,m; scanf("%d%d",&n,&m); char s[n]; scanf("%s",s); int a[m][2]; char c1[m],c2[m]; for(int i=0;i<m;i++) { scanf("%d%d %c %c",&a[i][0],&a[i][1],&c1[i],&c2[i]); for(int j=a[i][0]-1;j<=a[i][1]-1;j++) { if(s[j]==c1[i]) s[j]=c2[i]; } } printf("%s",s); }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
fb17a33b2a7875b04312aa3f40d2f451
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> #include<string.h> int main() { int n,m,l,r,i; char c1,c2; scanf("%d%d",&n,&m); char S[n]; scanf("%s",S); while(m--) { scanf("%d %d %c %c",&l,&r,&c1,&c2); for(i=l-1;i<=r-1;i++) { if(S[i]==c1) S[i]=c2; } } printf("%s",S); }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
5fa9dcbb0b4b2588e59063440fbcf6ab
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> int main() { int n,m,i,j,p,q; char c1,c2; scanf("%d %d",&n,&m); char a[n]; scanf("%s",a); for(j=1; j<=m; j++) { scanf("%d %d %c %c",&p,&q,&c1,&c2); for( i=p-1; i<q; i++) { if(a[i]==c1) a[i]=c2; } } printf("%s",a); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
4f02f981437ab623b18bb18bed6d1e71
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> int main() { int n,m,l,r,i,j; scanf("%d%d",&n,&m); char s[n+1],c1[2],c2[2]; scanf("%s",s); while(m--){ scanf("%d%d%s%s",&l,&r,&c1,&c2); for(i=l-1;i<r;i++) { if(s[i]==c1[0]) s[i]=c2[0]; } } printf("%s\n",s); }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
21b660262fcad9cd2afd259bb7a0218a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> int main() { int n,m; scanf("%d %d",&n,&m); char ch[n]; scanf("%s",ch); for(int i=0;i<m;i++) { int a,b; char x,y; scanf("%d %d %c %c",&a,&b,&x,&y); for(int j=a-1;j<b;j++) { if(ch[j]==x) ch[j]=y; } } printf("%s",ch); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
7bcdb60812089f3c9ed79d6a3e7af9d2
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> int main() { int n, q; scanf("%d%d", &n, &q); char d[n+3]; scanf("%s", d); while(q--) { int left, right; char s1[3], s2[3]; scanf("%d%d%s%s", &left, &right, s1, s2); for(int i = left-1; i <= right-1; i++) { if(d[i] == s1[0]) d[i] = s2[0]; } } puts(d); }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
576cbf5588d7bcf8c98c7c4c33a982d3
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> int main() { int n,m,l,r,i,j,a,b; scanf("%d %d",&n,&m); getchar(); char c[200],e,d; for(i=0;i<n;i++) scanf("%c",&c[i]); for(i=0;i<m;i++){ scanf("%d %d %c %c",&a,&b,&e,&d); for(j=a-1;j<b;j++){ if(c[j]==e) c[j]=d; } } for(i=0;i<n;i++) printf("%c",c[i]); }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
3fedfc0220d3ee86f16ebfa21abee31a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> int main() { int n, m, l, r, i, j; scanf("%d %d", &n, &m); getchar(); char str[n], c1, c2; scanf(" %s", str); while(m--) { scanf("%d %d %c %c", &l, &r, &c1, &c2); getchar(); for(j = l-1; j < r; j++) { if(str[j] == c1) { str[j] = c2; } } } printf("%s\n", str); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
296dd6a324ec09fc961e72ede695ba5f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> int main() { int n, m, l, r, i, j; scanf("%d %d", &n, &m); getchar(); char str[n], c1, c2; scanf("%s", &str); for(i = 0; i < m; i++) { scanf("%d %d %c %c", &l, &r, &c1, &c2); for(j = l - 1; j < r; j++) { if(str[j] == c1) { str[j] = c2; } } } printf("%s\n", str); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
3819f367f6d8ac6b6b36cdf0fe92d74f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> #include<stdlib.h> char str[10000]; int main(){ int n,i,j,k,l,m,r; char c1,c2; scanf("%d%d",&n,&m); scanf("%s",str); for(i=0;i<m;i++){ scanf("%d %d %c %c",&l,&r,&c1,&c2); // printf("%d %d %c %c\n",l,r,c1,c2); for(j=l-1;j<=r-1;j++){ if(str[j]==c1) str[j]=c2; } } printf("%s\n",str); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
0e3246c7ba8443e06cdb36a8f601c152
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> int main() { int n,m,i,j,l,r; char s[101],c1,c2; scanf("%d %d\n",&n,&m); for(i=1;i<=n;i++) { scanf("%c",&s[i]); } for(i=1;i<=m;i++) { scanf("\n%d %d %c %c",&l,&r,&c1,&c2); for(j=l;j<=r;j++) { if(s[j]==c1) { s[j]=c2; } } } for(i=1;i<=n;i++) { printf("%c",s[i]); } return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
d4abe848685c72c4afc542b6e6e7fe52
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> int main() { int n , m ; char ara[101] ; scanf("%d %d %s",&n,&m,ara) ; // char ch = getchar() ; // scanf("%s",ara) ; int f , r ; char c1 , c2 ; for( int a = 0 ; a < m ; a++ ) { scanf("%d %d %c %c",&f,&r,&c1,&c2) ; // scanf("%c %c",&c1,&c2) ; f-- ; r-- ; // f -= 1 ; // r -= 1 ; for( ; f <= r ; f++ ) { if( ara[f] == c1 ) { ara[f] = c2 ; } } } printf("%s\n",ara) ; return 0 ; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
aa3ab56708261656d5dd3b592e199965
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> int main() { int n , m ; scanf("%d %d",&n,&m) ; // char ch = getchar() ; char ara[n] ; scanf("%s",ara) ; int f , r ; char c1 , c2 ; for( int a = 0 ; a < m ; a++ ) { scanf("%d %d %c %c",&f,&r,&c1,&c2) ; // scanf("%c %c",&c1,&c2) ; f -= 1 ; r -= 1 ; for( int b = f ; b <= r ; b++ ) { if( ara[b] == c1 ) { ara[b] = c2 ; } } } printf("%s\n",ara) ; return 0 ; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
0730102939475cdd527a6d940ff85b04
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> int main() { int n,i,m,j,l,r,count; char c1,c2; scanf("%d %d",&n,&m); char s[n+1]; scanf("%s",&s); for(i=1;i<=m;i=i+1) { scanf("%d %d %c %c",&l,&r,&c1,&c2); j=l-1; while(j<=r-1) { if(s[j]==c1) { s[j]=c2; } j=j+1; } } printf("%s\n",s); }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
ddc5937ebb217bc1a64af7590c7db031
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> int main() { int n,m; int i,j,a,b; char c,d; scanf("%d %d",&n,&m); char x[n]; scanf("%s",&x); for(i=0;i<m;i++) { scanf("%d %d %c %c",&a,&b,&c,&d); for(j=0;j<n;j++) { if((a<=(j+1))&&((j+1)<=b)) { if(x[j]==c) x[j]=d; } } } printf(x); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
8602913a492a8636bb2a2851b4f015ff
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> #include<string.h> int main() { int n,m,l,r; char c1,c2,s[101]; scanf("%d %d %s",&n,&m,s); for(int i=1;i<=m;i++) { scanf("%d %d %c %c",&l,&r,&c1,&c2); for(int j=l-1;j<=r-1;j++) { if(s[j]==c1) s[j]=c2; } } printf("%s",s); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
91ef9262d1449cbe863581ec041dfce0
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> int main() { int n, m, i, l, r; scanf("%d%d", &n, &m); char s[1001], c[2], d[2]; scanf("%s", s); while (m--) { scanf("%d%d%s%s", &l, &r, c, d); for (i = l-1 ; i < r; i++) if (s[i] == c[0]) s[i] = d[0]; } printf("%s\n", s); }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
74e95642fa43400301ba7a28fe42d8a3
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> int main() { int n,m; scanf("%d%d",&n,&m); char ar[n]; scanf("%s",ar); char a,b; int x,y; for(int p=0;p<m;p++) { scanf("%d%d",&x,&y); getchar(); scanf("%c",&a); getchar(); scanf("%c",&b); for(int i=x-1;i<y;i++) { if(ar[i]==a) ar[i]=b; } } printf("%s\n",ar); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
2aac138a8cc183b425affa966c394e7d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> //AA06( 15/ 04/ 20) If u see my code, Have a Good Day! (^_^) int main() { int n, m, i, j, l, r; char S[1000], C1, C2; scanf("%d%d%s", &n, &m, S); for(i = 0; i < m; i++) { scanf("%d %d %c %c", &l, &r, & C1, &C2); for(j = l; j <= r; j++) { if(S[j - 1] == C1){ S[j - 1] = C2; } } } printf("%s\n", S); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
01529e07b7d1a1bb129a4b8e411dfadb
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> #include<string.h> int main() { char s[101]; char ch1,ch2; int i,j,l,r,m,n; scanf("%d",&n); scanf("%d",&m); scanf(" %s", s); for(i=1;i<=m;i++){ scanf("%d",&l); scanf("%d",&r); scanf(" %c", &ch1); scanf(" %c", &ch2); for(j=l-1;j<=r-1;j++){ if(s[j]==ch1){ s[j]=ch2; } } } printf("%s", s); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
7a9bf5a0e5457f22858bbee055ade94d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> #include<string.h> int main() { char s[101]; char ch1,ch2; int i,j,l,r,m,n; scanf("%d",&n); scanf("%d",&m); scanf("%s", s); for(i=1;i<=m;i++){ scanf("%d",&l); scanf("%d",&r); scanf(" %c", &ch1); scanf(" %c", &ch2); for(j=l-1;j<=r-1;j++){ if(s[j]==ch1){ s[j]=ch2; } } } printf("%s", s); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
6623bd61911ded0fdf082abd91676df9
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> int main() { int n,m; scanf("%d %d",&n,&m); char ch[n]; scanf("%s",&ch); for(int i=0; i<m; i++) { int l,r; char c1,c2; scanf("%d %d %c %c",&l,&r,&c1,&c2); for(int j = l-1; j < r; j++) { if(ch[j] == c1) { ch[j] = c2; } } } printf("%s",ch); }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
098c20d5aa02541e8233b45815091bae
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> int main() { int n,m; scanf("%d%d ",&n,&m); char a[1000]; gets(a); int j,i; int l,r; char c1,c2; for(j=0;j<m;j++) { scanf("%d %d %c %c",&l,&r,&c1,&c2); for(i=l-1;i<r;i++) { if(a[i]==c1) { a[i]=c2; } } } puts(a); }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
af48e59a2388809d3fc816d8aca990e1
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> int main() { int num1,num2,i,j,c,d,e,sum=0; scanf("%d %d ",&num1,&num2); char a[num1],ch1,ch2; gets(a); for(i=0;i<num2;i++) { scanf("%d %d %c %c",&c,&d,&ch1,&ch2); for(j=c-1;j<=d-1;j++){ if(a[j]==ch1){a[j]=ch2;} } } puts(a); }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
8c7631761e48f9219f749f4585555a28
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> int main(void) { int n,m,j,k,h,i; char s[100],b,p; scanf("%d %d",&n,&m); scanf("%s",s); for(j=0; j<m; j++) { scanf("%d %d %c %c",&k,&h,&b,&p); for(i=k-1; i<=h-1; i++) { if(s[i]==b) { s[i] = p; } } } printf("%s",s); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
6b62c11c23f89472ec58c9ba14be7d59
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> #include<string.h> int main () { int n,m,x,y,i; scanf("%d %d\n", &n,&m); char a[n+1],z,z1; gets(a); for(i=0;i<m;i++) { scanf("%d %d %c %c",&x,&y,&z,&z1); for(int j=x-1;j<y;j++) { if(a[j]==z) a[j]=z1; } } puts(a); }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
7b305a2c19ab68d6eb0f68cc6021bcde
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> int main (void) { char s[200]; int len,t; while(~scanf("%d%d",&len,&t)) { getchar(); for(int i=1;i<=len;i++) scanf("%c",&s[i]); getchar(); while(t--) { int l,r; char a,b; scanf("%d %d %c %c",&l,&r,&a,&b); getchar(); for(int i=l;i<=r;i++) if(s[i]==a) s[i]=b; } for(int i=1;i<=len;i++) printf("%c",s[i]); printf("\n"); } return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
a04182475e7f7e6f888b2921a2720b45
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> int main() { char s1[100],c1,c2; int n,m,l,r,i,j; scanf("%d%d",&n,&m); scanf("%s",s1); for(i=0;i<m;i++) { scanf("%d %d %c %c",&l,&r,&c1,&c2); l=l-1; r=r-1; for(j=l;j<=r;j++) { if(s1[j]==c1) { s1[j]=c2; } } } puts(s1); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
f91e81e46cb6aa4d71d263224c2c4d55
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> int main () { int i,j,t,a,b,x; char s[100]; char ch1,ch2; scanf ("%d %d",&j,&t); scanf ("%s",s); for (i=0;i<t;i++) { scanf ("%d %d",&a,&b); x=a-1; ch1=getchar(); ch1=getchar(); ch2=getchar(); ch2=getchar(); for (;x<b;x++) { if (s[x]==ch1) s[x]=ch2; } } printf ("%s\n",s); }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
a44617359b24f0628f35c98ac0e8268c
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> int main() { int n,m,i,j,l,r; char s[100],c,d; scanf("%d%d",&n,&m); scanf("%s",&s); for(i=1;i<=m;i++) { scanf("%d%d",&l,&r); scanf(" %c %c",&c,&d); for(j=(l-1);j<r;j++) { if(s[j]==c) { s[j]=d; } else { continue; } } } printf("%s",s); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
01eb9b074e505fea7bcb8932aa5c8ae5
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> int main() { int n,m,i,j,l,r; char c1,c2; char s[100]; scanf("%d %d",&n,&m); scanf("%s",s); for(i=0;i<m;i++) { scanf("%d %d %c %c",&l,&r,&c1,&c2); for(j=l-1;j<=r-1;j++) { if(s[j] == c1) s[j]=c2; } } printf("%s",s); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
d687a69294311b00ecf3ead6b6fc9dbb
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
int main() { int n,m; scanf("%d %d",&n,&m); char s[200]; scanf("%s",s); for(int i=0;i<m;i++) { int l,r; char c1,c2; scanf("%d %d %c %c",&l,&r,&c1,&c2); for(int i=l-1;i<=r-1;i++) { if(s[i]==c1) s[i]=c2; } } printf("%s",s); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
606e8f62570d5b55ce70f666ecd3b965
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> int main() { int n, m,l,r; scanf("%d%d",&n,&m); char ch[n+1],a,b; scanf("%s",ch); for(int i=0;i<m;i++) { scanf("%d%d %c %c",&l,&r,&a,&b); for(int j=l-1;j<r;j++) { if(ch[j]==a) ch[j]=b; } } //printf("%c %c",a,b); printf("%s",ch); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
8ef0a4ef2ea451ad36219d9f31b9add3
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> int main() { int n,m,i; scanf("%d %d",&n,&m); char c[101]; scanf("%s",&c); for(i=1;i<=m;i++) { int l,r,j; char c1,c2; scanf("%d %d %c %c",&l,&r,&c1,&c2); for(j=l-1;j<=r-1;j++) { if(c[j] == c1) c[j] = c2; } } printf("%s",c); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
aee7abe789475f8704702559854754ab
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> //CODED BY SAYEM MD. NAFI int main() { int LENGTH, OPERATION, L, R, I; char STRING[102], C1, C2; scanf("%d %d %s", &LENGTH, &OPERATION, STRING); while (OPERATION--) { scanf("%d %d %c %c", &L, &R, &C1, &C2); for(I = L; I <= R; I++) { if(STRING[I - 1] == C1) STRING[I - 1] = C2; } } printf("%s\n", STRING); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
20d5f41e8e14d34b583c468ef8bcbee4
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> int main(void) { int n,m,a,b; scanf("%d%d",&n,&m); char word[n]; getchar(); gets(word); char c1,c2; for(int i = 0; i < m; i++) { scanf("%d%d",&a,&b); getchar(); scanf("%c %c",&c1,&c2); for(int x = a-1; x < b; x++) { if(word[x] == c1) word[x] = c2; } } puts(word); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
5446f8cdfc8058059e67c204ca163ba6
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> int main() { int n,m,i,j,x,y; scanf("%d%d",&n,&m); char ch[100],c1,c2; scanf("%s",ch); for(i=0;i<m;i++) { scanf("%d%d",&x,&y); scanf(" %c",&c1); scanf(" %c",&c2); for(j=x-1;j<y;j++) if(ch[j]==c1) ch[j]=c2; } printf("%s",ch); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
81e008b89bb787580c1da4095a63e219
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> int main() { int n, m; scanf("%d %d \n", &n, &m); char c1, c2; char s[n+1]; int i, l, r, j; for( i = 0; i < n; i++) { scanf("%c", &s[i]); } for(j = 0 ; j < m; j++) { scanf("\n%d %d %c %c", &l, &r, &c1, &c2); for( i = l-1 ; i < r; i++) { if( s[i] == c1) s[i] = c2; } } for( i = 0; i < n; i++) { printf("%c", s[i]); } return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
6ba2e7844540cc1ae33d3a725c4907ca
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> #include<string.h> int main() { int n,m,i,k,j,s,l,r; scanf("%d %d",&n,&m); char S[n+1]; scanf("%s",S); for(s=0;s<m;s++) { char c1,c2; scanf("%d %d %c %c",&l,&r,&c1,&c2); for(i=l-1;i<r;i++) { if(S[i]==c1) { S[i]=c2; } } } for(i=0;i<n;i++) { printf("%c",S[i]); } printf("\n"); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
db7fe424ed1a7b79715fe84e021b0c4e
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> int main(void) { int n,m,i,j,k,l,r; char ch1,ch2; scanf("%d %d",&n,&m); char array[n+1]; scanf("%s",array); for(i=0;i<m;i++) { scanf("%d %d %c %c",&l,&r,&ch1,&ch2); for(j=l;j<=r;j++) { if(array[j-1]==ch1) array[j-1]=ch2; } } printf("%s",array); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
144609f6ebc9649e0d2ade8a7477c639
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> int main(){ int n, t, l, r; char s[100], c1, c2; fscanf(stdin,"%d%d%s",&n,&t,s); for(int i=0;i<t;i++){ fscanf(stdin,"%d%d %c %c",&l,&r,&c1,&c2); for(int j=l-1;j<r;j++){ if(s[j]==c1){ s[j]=c2; } } } fprintf(stdout,"%s",s); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
586484e925149db21abddbf20efdfe08
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { int num,j,i,oper,l,r; char ch,arr[102],c1,c2; scanf("%d %d",&num,&oper); for(i=1;i<=num;i++) { scanf(" %c",&ch); arr[i]=ch; } for(i=1;i<=oper;i++) { scanf("%d %d %c %c",&l,&r,&c1,&c2); for(j=l;j<=r;j++) if(arr[j]==c1) arr[j]=c2; } for(i=1;i<=num;i++) { printf("%c",arr[i]); } }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
513860485f8e2564e6b28138c802f2c9
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> int main() { int n,m; scanf("%d%d",&n,&m); char s[n+1]; scanf("%s",s); int l,r,j; char c1,c2; for(int i=1;i<=m;i++) { scanf("%d %d %c %c",&l,&r,&c1,&c2); //scanf("%c%c",&c1,&c2); for(j=l-1;j<r;j++) { if(s[j]==c1) s[j]=c2; // printf("%s\n",s); } } printf("%s",s); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
1169b8adb552facf5424c8873ae78f77
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include<stdio.h> int main(void) { int i,j,a,b,n,m; scanf("%d %d",&n,&m); char string[n+1],operation[8]; scanf("%s",string); for(i=0;i<m;i++) { scanf("%d %d",&a,&b); scanf(" %[^\n]",operation); for(j=a-1;j<b;j++) { if(operation[0]==string[j]) string[j]=operation[2]; } } printf("%s",string); return 0; }
Are you going to Scarborough Fair?Parsley, sage, rosemary and thyme.Remember me to one who lives there.He once was the true love of mine.Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.Although the girl wants to help, Willem insists on doing it by himself.Grick gave Willem a string of length n.Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.Grick wants to know the final string after all the m operations.
Output string s after performing m operations described above.
C
3f97dc063286a7af4838b7cd1c01df69
e609a01d7aa615e3cd1d9cf16cc2c251
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1512223500
["3 1\nioi\n1 1 i n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g"]
NoteFor the second example:After the first operation, the string is wxxak.After the second operation, the string is waaak.After the third operation, the string is gaaak.
PASSED
800
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
["noi", "gaaak"]
#include <stdio.h> #include <string.h> int length,r1,r2,parameters; char s[100000],wanted,target; void change (int rr1,int rr2,char w,char t) { for (int i=rr1-1;i<rr2;i++) { if (s[i]==w) s[i] = t; } } int main () { //freopen ("cf.in","r",stdin),freopen("cf.out","w",stdout); scanf ("%d %d %s",&length,&parameters,s); while (parameters--) { scanf ("%d %d %c %c",&r1,&r2,&wanted,&target); change (r1,r2,wanted,target); } printf (" %s",s); }
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k.
Print the required number.
C
98de093d78f74273e0ac5c7886fb7a41
6a07264f0d75049ca81209c9f9df7bbc
GNU C
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1447264800
["1 1 10", "2 -4 4"]
null
PASSED
1,600
standard input
1 second
The only line contains three space-separated integers k, a and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).
["10", "5"]
#include<stdio.h> typedef long long ll; ll S(ll x){return x<0?-x:x;} int main() { ll k,a,b,c; scanf("%I64d%I64d%I64d",&k,&a,&b); c=a/k*k;while(c<a)c+=k;a=c; c=b/k*k;while(c>b)c-=k;b=c; printf("%I64d\n",b/k-a/k+1); return 0; }
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k.
Print the required number.
C
98de093d78f74273e0ac5c7886fb7a41
55ccb8ede7659d3c0cb3f39435cb6164
GNU C
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1447264800
["1 1 10", "2 -4 4"]
null
PASSED
1,600
standard input
1 second
The only line contains three space-separated integers k, a and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).
["10", "5"]
#include <stdio.h> int main(void) { long long k, a, b; long long t; scanf("%lld %lld %lld", &k, &a, &b); t = ((long long)1e18 + k - 1) / k * k; a += t; b += t; printf("%lld\n", b / k - (a + k - 1) / k + 1); return 0; }
Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k.
Print the required number.
C
98de093d78f74273e0ac5c7886fb7a41
04f9cdb77210c89d244738c9425a3ad0
GNU C
standard output
256 megabytes
train_001.jsonl
[ "math" ]
1447264800
["1 1 10", "2 -4 4"]
null
PASSED
1,600
standard input
1 second
The only line contains three space-separated integers k, a and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).
["10", "5"]
#include <stdio.h> #include <stdlib.h> typedef long long ll; int main() { ll a, b, k, ans, temp; scanf("%I64d %I64d %I64d", &k, &a, &b); if (b < 0) { b*=-1; a*=-1; temp = b; b = a; a = temp; } if(b >= 0) { if(a <= 0){ a*=-1; ans = b/k + a/k + 1; } else { ans = b/k - ((a-1)/k); } } printf("%I64d", ans); return 0; }
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape.
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower).
C
6405161be280fea943201fa00ef6f448
bc47ba750134528b6c4e14d01e0ab804
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "dfs and similar", "strings" ]
1560258300
["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."]
NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape.
PASSED
1,300
standard input
1 second
The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
["YES", "NO", "NO", "NO", "NO", "NO"]
#include<stdio.h> #include<string.h> int main() { int h,w,i,j,f=0,p=0,t=0,m,n; scanf("%d %d",&h,&w); char s[h][w]; for(i=0;i<h;i++){ scanf("%s",s[i]); } for(i=0;i<h;i++) { for(j=0;j<w;j++) { if(s[i][j]=='*'){p++;} if(i>=1&&j>=1&&i<h-1&&j<w-1&&s[i][j]=='*'&&s[i-1][j]=='*'&&s[i][j+1]=='*'&&s[i][j-1]=='*'&&s[i+1][j]=='*'){m=i;n=j;f++;} } } if(f==1) { i=m;j=n; while(s[i][j]!='.'&&i>=0) { if(s[i][j]=='*'){t++;i--;} } i=m;j=n+1; while(s[i][j]!='.'&&j<w){ if(s[i][j]=='*'){t++;j++;}} i=m+1;j=n; while(s[i][j]!='.'&&i<h){ if(s[i][j]=='*'){t++;i++;} } i=m;j=n-1; while(s[i][j]!='.'&&j>=0){ if(s[i][j]=='*'){t++;j--;} } if(t==p){printf("YES");} else{printf("NO");} } else {printf("NO");} }
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape.
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower).
C
6405161be280fea943201fa00ef6f448
b15332ba3bac7d54c45c29dc3d6b11ee
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "dfs and similar", "strings" ]
1560258300
["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."]
NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape.
PASSED
1,300
standard input
1 second
The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
["YES", "NO", "NO", "NO", "NO", "NO"]
#include <stdio.h> int main(){ char a[1000][1000]; int n,m,i,j,k,cnt=0,t; scanf("%d%d",&n,&m); for(i=1;i<=n;++i){ scanf("%s",a[i]+1); for(j=1;j<=m;++j)if(a[i][j]=='*')++cnt; } for(i=2;i<n;++i) for(j=2;j<m;++j)if(a[i][j]=='*'&&a[i-1][j]=='*'&&a[i+1][j]=='*'&&a[i][j-1]=='*'&&a[i][j+1]=='*'){ for(t=1,k=i-1;k&&a[k][j]=='*';--k)++t; for(k=i+1;k<=n&&a[k][j]=='*';++k)++t; for(k=j-1;k&&a[i][k]=='*';--k)++t; for(k=j+1;k<=m&&a[i][k]=='*';++k)++t; if(t==cnt){ printf("YES\n"); return 0; } } printf("NO\n"); return 0; }
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape.
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower).
C
6405161be280fea943201fa00ef6f448
a0cca42fb966e7fe4cb4c60decec2fdb
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "dfs and similar", "strings" ]
1560258300
["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."]
NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape.
PASSED
1,300
standard input
1 second
The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
["YES", "NO", "NO", "NO", "NO", "NO"]
#include<stdio.h> int main() { int h,w,f=0,r,c; scanf("%d %d",&h,&w); char a[h][w]; int star[h][w]; for(int i=0;i<h;i++) { scanf(" %[^\n]",a[i]); } for(int g=0;g<h;g++) { for(int k=0;k<w;k++) { star[g][k]=0; } } for(int i=0;i<h-1;i++) { for(int j=0;j<w-1;j++) { if((a[i][j]=='*')&&(a[i][j-1]=='*')&&(a[i][j+1]=='*')&&(a[i-1][j]=='*')&&(a[i+1][j]=='*')) { r=i;c=j; while(r>=0 && a[r][c]=='*') { star[r][c]=1; r--; } r=i;c=j; while(r<h && a[r][c]=='*') { star[r][c]=1; r++; } r=i;c=j; while(c>=0 && a[r][c]=='*') { star[r][c]=1; c--; } r=i;c=j; while(c<w && a[r][c]=='*') { star[r][c]=1; c++; } for(int g=0;g<h;g++) { for(int k=0;k<w;k++) { if(a[g][k]=='*' && star[g][k]!=1) { printf("NO"); return 0; } } } printf("YES"); return 0; } } } printf("NO"); return 0; }
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape.
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower).
C
6405161be280fea943201fa00ef6f448
52299c68863a4ffe3415c6899ccaa8e3
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "dfs and similar", "strings" ]
1560258300
["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."]
NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape.
PASSED
1,300
standard input
1 second
The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
["YES", "NO", "NO", "NO", "NO", "NO"]
#include <stdio.h> int main(void) { int h,w; scanf(" %d %d",&h,&w); char a[510][510]; for(int i=0;i<h;i++) { for(int j=0;j<w;j++) { scanf(" %c",&a[i][j]); } } int count=0; int x,y; for(int i=0;i<h;i++) { for(int j=0;j<w;j++) { if(a[i][j]=='*'&&a[i-1][j]=='*'&&a[i][j-1]=='*'&&a[i+1][j]=='*'&&a[i][j+1]=='*') { count++; x=i; y=j; } } } if(count!=1) { printf("NO"); return 0; } int i=x,j=y; while(a[i][j]=='*'&&i<h) { a[i][j]='.'; i++; } i=x,j=y; while(a[i-1][j]=='*'&&i>=1) { a[i-1][j]='.'; i--; } i=x,j=y; while(a[i][j+1]=='*'&&j<w) { a[i][j+1]='.'; j++; } i=x,j=y; while(a[i][j-1]=='*'&&j>=1) { a[i][j-1]='.'; j--; } for(i=0;i<h;i++) { for(j=0;j<w;j++) { if(a[i][j]=='*') { printf("NO"); return 0; } } } printf("YES"); return 0; }
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape.
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower).
C
6405161be280fea943201fa00ef6f448
a0cfd490bc8645a4353aa9015b91a91e
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "dfs and similar", "strings" ]
1560258300
["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."]
NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape.
PASSED
1,300
standard input
1 second
The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
["YES", "NO", "NO", "NO", "NO", "NO"]
#include<stdio.h> #include<stdlib.h> char pic[550][550]={}; int n, m, cx=-1, cy=-1; int isCenter( int i, int j ) { if( pic[i-1][j] == '*' && pic[i+1][j] == '*' && pic[i][j-1] == '*' && pic[i][j+1] == '*' ) return 1; return 0; } void del( int x, int y ) { for( int i=x-1; i>=0; i-- ){ //上下左右 if( pic[i][y] == '.' ) break; pic[i][y] = '.'; } for( int i=x+1; i<n; i++ ){ if( pic[i][y] == '.' ) break; pic[i][y] = '.'; } for( int j=y-1; j>=0; j-- ){ if( pic[x][j] == '.' ) break; pic[x][j] = '.'; } for( int j=y+1; j<m; j++ ){ if( pic[x][j] == '.' ) break; pic[x][j] = '.'; } pic[x][y] = '.'; //中心点置零 } int check( ) { for( int i=0; i<n; i++ ) for( int j=0; j<m; j++ ) if( pic[i][j] == '*' ) return 0; return 1; } int main() { scanf("%d %d", &n, &m); for( int i=0; i<n; i++ ) scanf("%s", pic[i]); for( int i=1; i<n-1; i++ ){ //中心点一定不再边界 for( int j=1; j<m-1; j++ ) if( isCenter( i, j ) && pic[i][j] == '*' ){ //寻找中心点 cx = i; cy = j; } } if( cx == -1 ) printf("NO\n"); //没有中心点 没有灵魂 else{ del( cx, cy ); //从中心点辐射 删除横竖星号 if( check( ) ) printf("YES\n"); //标准加号此时没有星号了 else printf("NO\n"); } //system("pause"); return 0; }
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape.
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower).
C
6405161be280fea943201fa00ef6f448
7af9f92a450b09e647957752b96404fe
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "dfs and similar", "strings" ]
1560258300
["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."]
NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape.
PASSED
1,300
standard input
1 second
The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
["YES", "NO", "NO", "NO", "NO", "NO"]
#include<stdio.h> #include<math.h> int main() { int w, h, i, j, a=0, cnt=0, c=0, d=0; scanf("%d %d", &h, &w); getchar(); char str[h+1][w+1]; for (i=0; i<h; i++) gets(str[i]); for (i=0; i<h; i++) for (j=0; j<w; j++) if ( str[i][j]=='*' ) cnt++; if ( cnt==0 ) a++; for (i=0; i<h; i++) for (j=0; j<w; j++) if ( str[i][j]=='*' && str[i+1][j]=='*' && str[i-1][j]=='*' && str[i][j+1]=='*' && str[i][j-1]=='*' ) goto A; A: for ( c=i; c<h; c++) { if ( str[c][j]=='*') str[c][j]='.'; else break; } for ( c=i-1; c>=0; c--) { if ( str[c][j]=='*') str[c][j]='.'; else break; } for ( d=j+1; d<w; d++) { if ( str[i][d]=='*') str[i][d]='.'; else break; } for ( d=j-1; d>=0; d--) { if ( str[i][d]=='*') str[i][d]='.'; else break; } for (i=0; i<h; i++) for (j=0; j<w; j++) if ( str[i][j]=='*' ) a++; if ( a==0 ) printf("YES\n"); else printf("NO\n"); return 0; }
You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction. All other cells are empty. Find out if the given picture has single "+" shape.
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower).
C
6405161be280fea943201fa00ef6f448
9a652b338e3d7247ec223b1fe6e7a2fa
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "dfs and similar", "strings" ]
1560258300
["5 6\n......\n..*...\n.****.\n..*...\n..*...", "3 5\n..*..\n****.\n.*...", "7 7\n.......\n...*...\n..****.\n...*...\n...*...\n.......\n.*.....", "5 6\n..**..\n..**..\n******\n..**..\n..**..", "3 7\n.*...*.\n***.***\n.*...*.", "5 10\n..........\n..*.......\n.*.******.\n..*.......\n.........."]
NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape.
PASSED
1,300
standard input
1 second
The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
["YES", "NO", "NO", "NO", "NO", "NO"]
#include <stdio.h> void abort() { printf("NO"); exit(0); } int main() { int w, h, x = -1, y, u, d, l, r, i, j; char p[500][500]; scanf("%d %d", &w, &h); for(i = 0; i < w; i++) for(j = 0; j < h; j++) scanf(" %c", &p[i][j]); for(i = 1; i < w - 1; i++) { for(j = 1; j < h - 1; j++) { if(p[i][j] == '*' && p[i+1][j] == '*' && p[i-1][j] == '*' && p[i][j+1] == '*' && p[i][j-1] == '*') { x = i; l = i - 1; r = i + 1; y = j; u = j - 1; d = j + 1; break; } } if(x != -1) break; } if(x == -1) abort(); for(i = x - 2; i >= 0; i--) if(p[i][y] == '*') l = i; for(i = x + 2; i < w; i++) if(p[i][y] == '*') r = i; for(j = y - 2; j >= 0; j--) if(p[x][j] == '*') u = j; for(j = y + 2; j < h; j++) if(p[x][j] == '*') d = j; for(i = 0; i < w; i++) for(j = 0; j < h; j++) if(i == x) { if(p[i][j] != (j >= u && j <= d ? '*' : '.')) abort(); } else if(j == y) { if(p[i][j] != (i >= l && i <= r ? '*' : '.')) abort(); } else if(p[i][j] != '.') abort(); printf("YES"); return 0; }