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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). | On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. | C | a55d6c4af876e9c88b43d088f2b81817 | 178fc11109e42a81056b4f74c274ea9b | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"hashing",
"greedy"
] | 1409383800 | ["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"] | null | PASSED | 1,900 | standard input | 3 seconds | The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard. | ["12\n2 2 3 2"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<time.h>
#include<ctype.h>
#include<limits.h>
#define eps 1e-7
#define ll long long int
#define N 2500
ll board[N][N];
ll up[N][N];
ll low[N][N];
int main(){
int a,b,c;
scanf("%d",&a);
for(int i=1;i<=a;i++){
for(int w=1;w<=a;w++){
scanf("%lld",&board[i][w]);
up[i][w]=low[i][w]=board[i][w];
}
}
for(int w=2;w<=a;w++){
for(int i=1;i<=a;i++){
if(i-1>0)
up[w][i]=up[w][i]+up[w-1][i-1];
if(i+1<=a)
low[w][i]=low[w][i]+low[w-1][i+1];
}
}
for(int w=a-1;w>=1;w--){
for(int i=1;i<=a;i++){
if(i+1<=a)
up[w][i]=up[w+1][i+1];
if(i-1>0)
low[w][i]=low[w+1][i-1];
}
}
int x,x1,y,y1; ll m,m1;m=m1=0; int finish=0;
x=1; x1=1; y=1; y1=2;
for(int w=1;w<=a;w++){
for(int i=1;i<=a;i++){
ll s=0;int flag=w%2;
if(flag){
if(i%2){
ll s=up[w][i]+low[w][i]-board[w][i];
if(s>m){
m=s;
x=w; x1=i;
}
}
else{
ll s=up[w][i]+low[w][i]-board[w][i];
if(s>m1){
m1=s;
y=w; y1=i;
}
}
}
else{
if(i%2){
ll s=up[w][i]+low[w][i]-board[w][i];
if(s>m1){
m1=s;
y=w; y1=i;
}
}
else{
ll s=up[w][i]+low[w][i]-board[w][i];
if(s>m){
m=s;
x=w; x1=i;
}
}
}
}
}
printf("%lld\n",m+m1);
printf("%d %d %d %d",x,x1,y,y1);
} | |
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will get x dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it). | On the first line print the maximal number of dollars Gargari will get. On the next line print four integers: x1, y1, x2, y2 (1 ≤ x1, y1, x2, y2 ≤ n), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right. If there are several optimal solutions, you can print any of them. | C | a55d6c4af876e9c88b43d088f2b81817 | 4e1c20813005b6313b19807d0a44aab0 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"hashing",
"greedy"
] | 1409383800 | ["4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1"] | null | PASSED | 1,900 | standard input | 3 seconds | The first line contains a single integer n (2 ≤ n ≤ 2000). Each of the next n lines contains n integers aij (0 ≤ aij ≤ 109) — description of the chessboard. | ["12\n2 2 3 2"] | #include<stdio.h>
#define MAX 2005
long long d1[2*MAX]={0},d2[2*MAX]={0};
int a[MAX][MAX];
long long value[2];
struct point{
int x,y;
}pp[2];
void update(int num,int i,int j,long long val){
if(value[num] < val){
value[num] = val;
pp[num].x = i;
pp[num].y = j;
}
}
int main(){
int n,i,j;
scanf("%d",&n);
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
scanf("%d",&a[i][j]);
d1[i+j] += a[i][j];
d2[i-j+n-1] += a[i][j];
}
}
value[0] = value[1] = -1;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
update((i+j)&1,i,j,d1[i+j] + d2[i-j+n-1] - a[i][j]);
}
}
printf("%lld\n",value[0]+value[1]);
printf("%d %d %d %d\n",pp[0].x,pp[0].y,pp[1].x,pp[1].y);
return 0;
} | |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | d79bc21cbf0433204d1c2dc575486e96 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] |
#include <stdio.h>
int main()
{
int n, count = 0;
scanf("%d", &n);
int a[n];
for(int i = 1; i <= n; i++){
scanf("%d", &a[i]);
}
a[0] = a[1];
int max = a[0];
for(int i = 1; i <= n; i++){
if (max < a[i])
max = a[i];
if((a[i] == i) && !(a[i] < a[i - 1]) && !(a[i] < max))
count++;
}
printf("%d", count);
return 0;
}
| |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | 86cfd1f99d8c405a69aa2105a57fde52 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | #include <stdio.h>
#include <string.h>
#include <limits.h>
#define FOR(i, a, b) for (i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
int cmpfunc (const void * a, const void * b){
//qsort(values, 5, sizeof(int), cmpfunc);
return ( *(int*)a - *(int*)b );
}
int min(int a,int b){
return a < b ? a : b;
}
long ncr(int n, int k)
{
long C[k+1];
memset(C, 0, sizeof(C));
int i;
int j;
C[0] = 1; // nC0 is 1
for (i = 1; i <= n; i++)
{
// Compute next row of pascal triangle using
// the previous row
for ( j = min(i, k); j > 0; j--)
C[j] = C[j] + C[j-1];
}
return C[k];
}
void solve(int t){
int n,k;
scanf("%d%d",&n,&k);
int a[n];
int i,j;
for(i = 0;i < n;i++){
scanf("%d",&a[i]);
}
// printf("Case #%d: %ld\n",t,count);
}
int main(){
int n;
scanf("%d",&n);
int a[n];
int i, days = 0, max = -1;
for(i = 0;i < n;i++){
scanf("%d",&a[i]);
}
for(i = 0;i < n;i++){
if(i+1 >= max && a[i] == i+1){
days++;
max = a[i];
}
else{
if(a[i] > max){
max = a[i];
}
}
}
printf("%d\n",days);
} | |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | 45131e25cc1fa48b68b30bb9242c4fe5 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | #include<stdio.h>
int main()
{
int n,i,j,d=0,c=0,max=0;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
if(i+1==a[i])
{
for(j=0;j<=i;j++)
{
if(a[i]>=a[j])
d++;
}
printf("\n");
if(d==i+1)
c++;
d=0;
}
}
printf("%d\n",c);
return 0;
} | |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | dcaf72696b01b9bfe16e5201ee488c42 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | #include <stdio.h>
int main()
{
int i,j=0,k=0,n;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=1;i<=n;i++)
{
if(a[i-1]>j)
j=a[i-1];
if(i>=j)
k++;
}
printf("%d",k);
} | |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | 4395635f10a5e964acb91cb2da90fc5a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | #include<stdio.h>
int main()
{
int n,i,count=0,sum=0;
scanf("%d",&n);
int array[n];
for(i=0;i<n;i++)
{
scanf("%d",&array[i]);
}
for(i=0;i<n;i++)
{
if((array[i]<=i+1)&&(array[i]>=sum)) count++;
if(array[i]>sum) sum=array[i];
}
printf("%d",count);
return 0;
} | |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | 10b5ea071a4da79d71de1133ae75f7b4 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | #include<stdio.h>
int main()
{
int n,a[10001],i,k=0,j;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]==(1+i))
{
for(j=0;j<i;j++)
{
if(a[j]>a[i])
break;
}
if(i==j)
{
k++;
}
}
}
printf("%d",k);
return 0;
} | |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | 66e362b17bcd1738a17f4edc9411d94d | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | #include <stdio.h>
int main()
{
int p;
int a[10000];
int i;
scanf("%d",&p);
for(i=0 ; i<p ; i++){
scanf("%d",&a[i]);
}
int days = 0;
int read = 0;
int start = 0;
int mystery;
while(1){
mystery = a[start];
while(read<mystery){
if(a[read]>mystery)
mystery = a[read];
read += 1;
}
//printf("read:%d\n",read);
start = read;
days += 1;
if(read==p){
break;
}
}
printf("%d",days);
return 0;
} | |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | 4dd82d085b2512cfbbb7dcbb71a6b041 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | #include <stdio.h>
int a[10005], v[10005];
int main()
{
int n, cnt = 0;
// freopen("test.txt","r",stdin);
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
int max = 0;
for(int i = 1; i <= n; i++)
{
if(max < a[i]) max = a[i];
if(i == max) cnt++;
}
printf("%d\n", cnt);
// fclose(stdin);
return 0;
} | |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | b7e17dc5f2d6b60b1ddb432937480fb5 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | #include<stdio.h>
#include<stdlib.h>
int main(){
int N, day = 0, cnt = 0, t = 1, s = 0, max;
int arr[10001] = {};
scanf("%d", &N);
for(int i=0; i<N; i++){
scanf("%d", &arr[i]);
}
while(1){
if(cnt == N) break;
for(int j=s; j<t; j++){
if(arr[j] > t) t = arr[j];
cnt++;
}
s = t;
t++;
day++;
}
printf("%d", day);
}
| |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | 16be89cfa21d0aa5892973b87a7e5a40 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | #include<stdio.h>
int main(void){
int n=0,i=0,day=0;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
i=0;
while(i<n){
for(i++;i<a[i-1];i++){
if(a[i]<a[i-1]){
a[i]+=a[i-1];
a[i-1]=a[i]-a[i-1];
a[i]-=a[i-1];
}
}
day++;
}
printf("%d",day);
}
| |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | 05627b7a5809708414e0387cc87e8661 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | #include<stdio.h>
int main()
{
int n,mam;
scanf("%d",&n);
int a[n];
int i,count=0;
scanf("%d",&a[0]);
mam=a[0];
if(mam==1){
++count;
mam=2;
}
for(i=1;i<n;i++){
scanf("%d",&a[i]);
if(mam == (i+1)){
if(a[i] == (i+1)){
count++;
mam = i+2;
}
else mam = a[i];
}
else{
if(mam < a[i]){
mam = a[i];
}
}
}
printf("%d",count);
return 0;
}
| |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | a616f64bc2901ba8513d80a57750f9a6 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | /* AUTHOR:AKASH JAIN
* USERNAME:akash19jain
* DATE:23/03/2019
*/
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
int main()
{
long long t=1;
//scanf("%lld",&t);
while(t--)
{
long long n,ans=0,max=0;
scanf("%lld",&n);
long long arr[n];
for(long long i=0;i<n;i++)
{
scanf("%lld",&arr[i]);
}
for(long long i=0;i<n;i++)
{
if(arr[i]>max)
max=arr[i];
if(max<=(i+1))
{
ans++;
max=0;
}
}
printf("%lld",ans);
}
return 0;
} | |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | 3ac6a75e937f059fb2c7f6829dd79d85 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | #include<stdio.h>
int main(){
int n;
scanf("%d",&n);
int count=0;
int sum=0;
for(int i=1;i<=n;i++){
int a;
scanf("%d",&a);
if(a>count) count=a;
if(i==count) sum++;
}
printf("%d",sum);
} | |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | 21a6f90f0592050a99257500c1e35bd2 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | #include <stdio.h>
int main() {
unsigned n;
scanf("%u", &n);
unsigned max = 0;
unsigned count = 0;
for (unsigned i = 1; i <= n; i++) {
unsigned next;
scanf("%u", &next);
if (next > max) max = next;
if (max <= i) count++;
}
printf("%u\n", count);
return 0;
}
| |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | 5bf13fc646db8abe631211d7dd5c1618 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | #include<stdio.h>
int main()
{
int n,c=0,temp;
scanf("%d",&n);
int ar[n];
for(int i=0;i<n;i++)
{
scanf("%d",&ar[i]);
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(ar[i]>ar[j])
{
temp=ar[j];
ar[j]=ar[i];
ar[i]=temp;
}
}
}
for(int i=1;i<=n;i++)
{
if(ar[i-1]==i)c++;
}
printf("%d",c);
}
| |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | f36f5b938bdc4cbd7277b3f8c8959bea | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | #include<stdio.h>
int main(){
int n,i,p,max=0,j=0,c=0;
scanf("%d",&n);
int arr[n];
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
for(i=0;i<n;i++){
j=i;
do{
if(arr[j]-1>=max)
max=arr[j]-1;
j++;
}while(j<=max);
c++;
i=j-1;
}
printf("%d\n",c);
return 0;
}
| |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | 55b74e415b7846721c0d4e767aeb6d88 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int k[n],i,j;
for(i=0;i<n;i++)
{
scanf("%d",&k[i]);
}
int day=0,next_stop=0,prev_stop=-1;
for(i=0;i<n;i++)
{
int num = k[i];
next_stop = num>next_stop?num:next_stop;
for(j=i;j<next_stop;j++)
{
next_stop = k[j]>next_stop?k[j]:next_stop;
}
if(next_stop != prev_stop) day++;
prev_stop = next_stop;
}
printf("%d\n",day);
return 0;
}
| |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | ea0ae13349b47f454646a9c7a8f7b7be | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | #include<stdio.h>
int main(){
int n;
scanf("%d", &n);
int a[n], k, i, count = 0;
for(i = 1; i <= n; i++)
scanf("%d", &a[i]);
k = a[1];
for(i = 1; i <= n; i++){
if(a[i] > k){
k = a[i];
}
if(k == i){
k++;
count++;
}
}
printf("%d", count);
return 0;
}
| |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | 77ca8c557ab87cfc0de1a6ad54dda19f | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | #include<stdio.h>
int main(){
int n,arr[100000], i, j, point=0, count=0;
scanf("%d", &n);
for(i=0; i<n; i++) scanf("%d", &arr[i]);
for(i=0; i<n; i++)
{
if(arr[i]-1>point) point = arr[i]-1;
if(point == i) count++;
}
printf("%d", count);
}
| |
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $$$i$$$-th page contains some mystery that will be explained on page $$$a_i$$$ ($$$a_i \ge i$$$).Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $$$i$$$ such that Ivan already has read it, but hasn't read page $$$a_i$$$). After that, he closes the book and continues to read it on the following day from the next page.How many days will it take to read the whole book? | Print one integer — the number of days it will take to read the whole book. | C | 291601d6cdafa4113c1154f0dda3470d | 50c07f1b8ac035183045d1e390354f61 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1553267100 | ["9\n1 3 3 6 7 6 8 8 9"] | NoteExplanation of the example test:During the first day Ivan will read only the first page. During the second day Ivan will read pages number $$$2$$$ and $$$3$$$. During the third day — pages $$$4$$$-$$$8$$$. During the fourth (and the last) day Ivan will read remaining page number $$$9$$$. | PASSED | 1,000 | standard input | 2 seconds | The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^4$$$) — the number of pages in the book. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$), where $$$a_i$$$ is the number of page which contains the explanation of the mystery on page $$$i$$$. | ["4"] | #include<stdio.h>
#include<string.h>
int v[10005];
int main()
{
int a,s,d,f,g;
scanf("%d",&a);
for(int i=1;i<=a;++i)
scanf("%d",&v[i]);
s=d=0;
for(int i=1;i<=a;++i)
{
if(s<v[i]) s=v[i];
if(s==i) ++d;
}
printf("%d\n",d);
}
| |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | 059315d67770b2596c5d2b0e834024ea | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include <stdio.h>
#include <string.h>
int main() {
char s[200111];
int n;
scanf("%d", &n);
scanf("%s", s);
int i = 0, len = strlen(s);
int num = 0;
while (s[i] == '<') { i++; num++; }
i = len - 1;
while (s[i] == '>') { i--; num++; }
printf("%d", num);
return 0;
} | |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | cddd7267c9f585334b83623e19618527 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include <stdio.h>
#include <string.h>
int main() {
int n;
char str[200000];
scanf("%d", &n);
scanf("%s", &str);
int count = 0;
int i = 0;
while (str[i] == '<') {
count++;
i++;
}
i = n - 1;
while (str[i] == '>') {
count++;
i--;
}
printf("%d", count);
return 0;
}
| |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | 4009b260bab0f958636ce2ef59270121 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include <stdio.h>
#define N 200000
int main() {
static char s[N + 1];
int n, i, j;
scanf("%d%s", &n, s);
for (i = 0; i < n && s[i] == '<'; i++)
;
for (j = n - 1; j >= 0 && s[j] == '>'; j--)
;
printf("%d\n", i + (n - 1 - j));
return 0;
}
| |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | 4f452d518424db6167ac6f9887a444a8 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include <stdio.h>
int main(void) {
long long int n,i,count=0;
scanf("%lld",&n);
char s[n];
scanf("%s",s);
for(i=0;i<n;i++)
{
if(s[i]=='<'){
count++;}
else
break;
}
for(i=n-1;i>=0;i--)
{
if(s[i]=='>')
{count++;}
else
break;
}
printf("%lld\n",count);
return 0;
}
| |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | b04f0a5ae9debf245ca0aebb7f07c34e | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include<stdio.h>
#include<string.h>
int main()
{
int i,n,a=0,b=0;
char ch[200005],m;
scanf("%d",&n);
m=getchar();
gets(ch);
for(i=0; i<n; i++)
{
if(ch[i]=='<')
a++;
else
break;
}
for(i=n-1; i>=0; i--)
{
if(ch[i]=='>')
b++;
else
break;
}
printf("%d\n",a+b);
return 0;
}
| |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | 142abfe0e493c491c931e6d9797ecd6c | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int n, i, j;
scanf("%d", &n);
char a[n+1];
scanf("%s", a);
i=0;
j=n-1;
while(a[i]=='<')
i++;
while(a[j]=='>')
j--;
j = n-1-j;
printf("%d", i+j);
return 0;
}
| |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | a09e8b194d23ec8dd8f6e69d64218c90 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
char s[200002];
scanf("%s",s);
int i=0,count=0;
if(s[0]=='<')
{
while(s[i]=='<'){count++;i++;}
}
i=n-1;
if(s[n-1]=='>')
{
while(s[i]=='>'){count++;i--;}
}
printf("%d\n",count);
return 0;
}
| |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | 6ebea0aaf806773cfab672e4c457216e | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int l , i = 1 , k ,ans;
//int ans = 0 , portion = 0;
scanf("%d",&l);
char arr[l + 1];
//while (i <= l && scanf(" %c", &arr[i++]) == 1);
scanf("%s",arr);
for( i = 0 ; i < (l-1) ; i++ )
{
if(arr[i] == '>' && arr[i+1] == '<')
{
arr[i] = ' $';
arr[i + 1] = '$';
i++;
}
}
for(i = 0 ; i < l ; i++)
{
u:
if(arr[i] == '>')
{
if( arr[i+1] == '$' )
{
arr[i] = '$';
i--;
goto u;
}
}
if(arr[i] == '<')
{
if( arr[i-1] == '$' )
{
arr[i] = '$';
i++;
goto u;
}
}
}
for(ans = 0 , i = 0 ; i < l ; i++ )
{
if(arr[i] != '$')
ans++;
}
printf("%d",ans);
return 0;
}
| |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | 9e0f607e4c07466e80fb63328b3263da | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include <stdio.h>
int main()
{
int n, m=0, i, j;
char s[200005];
scanf("%d", &n);
scanf("%s",s);
for (i=0; i<n; i++)
{
if (s[i]=='<')
{
m++;
}
else
{
break;
}
}
for (i=n-1; i>=0; i--)
{
if (s[i]=='>')
{
m++;
}
else
{
break;
}
}
printf("%d", m);
return 0;
} | |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | 01d7b387f7c1b3da4426e736c32513e4 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include <stdio.h>
int main(){
int n;
scanf("%d",&n);
char a[n];
scanf("%s",&a);
int num=0;
for(int i=0;i<n;i++){
if(a[i]=='<')
num++;
else{
break;
}
}
for(int i=n-1;i>=0;i--){
if(a[i]=='>')
num++;
else{
break;
}
}
printf("%d",num);
} | |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | aabff62db86db09cc4b7676fd4f00d0c | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include <stdio.h>
#include <string.h>
int main()
{
long long n,i,r=0,p,s=0,t=0,f=0;
scanf("%I64d", &n);
char str[n];
scanf("%s",&str);
p = strlen(str);
for(i=0;i<p;i++)
{
if(str[i] == '>')
s++;
else if(s > 0 && str[i] == '<')
{
s = 0;
f++;
}
else if(s == 0 && f==0 && str[i] == '<')
r++;
}
printf("%I64d",s+r);
return 0;
} | |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | 09c474a483f170ae4e26819c0a6e51be | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include<stdio.h>
#include<string.h>
int main()
{
int n,count=0,i=0,j,k,p;
char s[200000];
scanf("%d",&n);
scanf("%s",s);
while(i<n)
{
k=1;
if(s[i]=='>')
{
for(j=i+1;j<n;j++)
{if(s[j]=='<')
{k=0;
break;}
}
if(k==1)
count+=n-i;
i=j+1;
}
//printf("%d\n",count);
else
i++;
}
for(p=0;p<n;p++)
{
if(s[p]=='>')
break;
}
printf("%d",count+p);
return 0;
}
| |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | 72b1e8ab7ef057a3ec4f03a91ffce68e | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include<stdio.h>
#include<string.h>
int main()
{
int n,i,j,c,d,sum,s;
while(scanf("%d",&n)!=EOF)
{
c=0,d=0;
char array[n];
getchar();
gets(array);
s=strlen(array);
for(i=0; i<s; i++)
{
if(array[i]=='<')
{
c++;
}
else
{
break;
}
}
for(j=s-1; j>=0; j--)
{
if(array[j]=='>')
{
d++;
}
else
{
break;
}
}
sum=c+d;
printf("%d\n",sum);
}
return 0;
}
| |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | 6025ee8d9e7623c20b439ec01879107e | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include<stdio.h>
int main()
{
int t,i,count1=0,count2=0,x;
scanf("%d",&t);
char str[t];
scanf("%s",str);
for(i=0;i<t;i++)
{
if(str[i]=='<')
count1++;
else
break;
}
for(i=t-1;i>=0;i--)
{
if(str[i]=='>')
count2++;
else
break;
}
printf("%d\n",x=count1+count2);
return 0;
} | |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | eed03d5710c97958dd617f7e53414ba9 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include <stdio.h>
int main(void)
{
int n;
scanf("%d", &n);
char str[200001];
scanf("%s", str);
int count = 0;
int i = 0;
while(i < n && str[i++] == '<')
{
count++;
}
i = n - 1;
while(i >= 0 && str[i--] == '>')
{
count++;
}
printf("%d\n", count);
return 0;
} | |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | 03d3d7828f6b7a99b17b9e6e07a1b0f5 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include <stdio.h>
char str[1<<18];
int main(void) {
int n;
int cnt = 0;
scanf("%d\n", &n);
fgets(str, n + 1, stdin);
for(int i = 0; str[i] == '<'; cnt = ++i);
for(int i = n - 1; str[i] == '>'; cnt++, i--);
printf("%d", cnt);
} | |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | 900b76159e3dddeeb7e9a77078c03dec | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include<stdio.h>
int main()
{
int n,i,j=0,k=0;
scanf("%d",&n);
char a[n];
scanf("%s",a);
for(i=0;a[i]!='>' && i<n;i++)
++j;
for(i=n-1;a[i]!='<' && i>=0;--i)
++k;
printf("%d",j+k);
return 0;
}
| |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | 5ddb81b17123b8e62ab64eed2af5d08f | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include<stdio.h>
int main()
{
int n,i,j=0,k=0;
scanf("%d",&n);
char a[n];
scanf("%s",a);
for(i=0;a[i]!='>' && i<n;i++)
++j;
for(i=n-1;a[i]!='<' && i>=0;--i)
++k;
printf("%d",j+k);
return 0;
}
| |
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it goes one position to the right (to the position i + 1) if the type of this bumper is '>', or one position to the left (to i - 1) if the type of the bumper at position i is '<'. If there is no such position, in other words if i - 1 < 1 or i + 1 > n, the ball falls from the game field.Depending on the ball's starting position, the ball may eventually fall from the game field or it may stay there forever. You are given a string representing the bumpers' types. Calculate the number of positions such that the ball will eventually fall from the game field if it starts at that position. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | C | 6b4242ae9a52d36548dda79d93fe0aef | 97bde7444f6c96f0f47110ade89962ea | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1477148700 | ["4\n<<><", "5\n>>>>>", "4\n>><<"] | NoteIn the first sample, the ball will fall from the field if starts at position 1 or position 2.In the second sample, any starting position will result in the ball falling from the field. | PASSED | 1,000 | standard input | 2 seconds | The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper. | ["2", "5", "0"] | #include <stdio.h>
#include<math.h>
#include<string.h>
int main()
{
char str[1000000];
long long i, frequency = 0,f=0,n;
scanf("%I64d",&n);
scanf("%s",str);
for(i=0; str[i] != '\0';i++)
{
if(str[i]=='>')
break;
frequency++;
}
long long l=strlen(str);
for(i=l-1;i>=0;i--)
{
if(str[i]=='<')
break;
frequency++;
}
printf("%I64d",frequency);
return 0;
}
| |
While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly $$$H$$$ centimeters above the water surface. Inessa grabbed the flower and sailed the distance of $$$L$$$ centimeters. Exactly at this point the flower touched the water surface. Suppose that the lily grows at some point $$$A$$$ on the lake bottom, and its stem is always a straight segment with one endpoint at point $$$A$$$. Also suppose that initially the flower was exactly above the point $$$A$$$, i.e. its stem was vertical. Can you determine the depth of the lake at point $$$A$$$? | Print a single number — the depth of the lake at point $$$A$$$. The absolute or relative error should not exceed $$$10^{-6}$$$. Formally, let your answer be $$$A$$$, and the jury's answer be $$$B$$$. Your answer is accepted if and only if $$$\frac{|A - B|}{\max{(1, |B|)}} \le 10^{-6}$$$. | C | 2cd5807e3f9685d4eff88f2283904f0d | 40c6687006d27d2db7f544cf44454c6f | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"geometry",
"math"
] | 1564497300 | ["1 2", "3 5"] | null | PASSED | 1,000 | standard input | 1 second | The only line contains two integers $$$H$$$ and $$$L$$$ ($$$1 \le H < L \le 10^{6}$$$). | ["1.5000000000000", "2.6666666666667"] | #include<stdio.h>
int main()
{
float a,b;
scanf("%f %f",&a,&b);
printf("%f",(b*b - a*a)/(2*a));
}
| |
While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly $$$H$$$ centimeters above the water surface. Inessa grabbed the flower and sailed the distance of $$$L$$$ centimeters. Exactly at this point the flower touched the water surface. Suppose that the lily grows at some point $$$A$$$ on the lake bottom, and its stem is always a straight segment with one endpoint at point $$$A$$$. Also suppose that initially the flower was exactly above the point $$$A$$$, i.e. its stem was vertical. Can you determine the depth of the lake at point $$$A$$$? | Print a single number — the depth of the lake at point $$$A$$$. The absolute or relative error should not exceed $$$10^{-6}$$$. Formally, let your answer be $$$A$$$, and the jury's answer be $$$B$$$. Your answer is accepted if and only if $$$\frac{|A - B|}{\max{(1, |B|)}} \le 10^{-6}$$$. | C | 2cd5807e3f9685d4eff88f2283904f0d | a9b4c8901da488e439e81a991a743b05 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"geometry",
"math"
] | 1564497300 | ["1 2", "3 5"] | null | PASSED | 1,000 | standard input | 1 second | The only line contains two integers $$$H$$$ and $$$L$$$ ($$$1 \le H < L \le 10^{6}$$$). | ["1.5000000000000", "2.6666666666667"] | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<limits.h>
int main()
{
float l,h;
scanf("%f %f",&h,&l);
double k;
k=l*l-h*h;
float ans=k/(2*h);
printf("%f",ans);
}
| |
While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly $$$H$$$ centimeters above the water surface. Inessa grabbed the flower and sailed the distance of $$$L$$$ centimeters. Exactly at this point the flower touched the water surface. Suppose that the lily grows at some point $$$A$$$ on the lake bottom, and its stem is always a straight segment with one endpoint at point $$$A$$$. Also suppose that initially the flower was exactly above the point $$$A$$$, i.e. its stem was vertical. Can you determine the depth of the lake at point $$$A$$$? | Print a single number — the depth of the lake at point $$$A$$$. The absolute or relative error should not exceed $$$10^{-6}$$$. Formally, let your answer be $$$A$$$, and the jury's answer be $$$B$$$. Your answer is accepted if and only if $$$\frac{|A - B|}{\max{(1, |B|)}} \le 10^{-6}$$$. | C | 2cd5807e3f9685d4eff88f2283904f0d | 645ac2fe1bb826c28fed32c66db412f0 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"geometry",
"math"
] | 1564497300 | ["1 2", "3 5"] | null | PASSED | 1,000 | standard input | 1 second | The only line contains two integers $$$H$$$ and $$$L$$$ ($$$1 \le H < L \le 10^{6}$$$). | ["1.5000000000000", "2.6666666666667"] | #include<stdio.h>
int main()
{
float s,l,a;
scanf("%f%f",&s,&l);
a=((l*l)-(s*s))/(2*s);
printf("%f",a);
return 0;
}
| |
While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly $$$H$$$ centimeters above the water surface. Inessa grabbed the flower and sailed the distance of $$$L$$$ centimeters. Exactly at this point the flower touched the water surface. Suppose that the lily grows at some point $$$A$$$ on the lake bottom, and its stem is always a straight segment with one endpoint at point $$$A$$$. Also suppose that initially the flower was exactly above the point $$$A$$$, i.e. its stem was vertical. Can you determine the depth of the lake at point $$$A$$$? | Print a single number — the depth of the lake at point $$$A$$$. The absolute or relative error should not exceed $$$10^{-6}$$$. Formally, let your answer be $$$A$$$, and the jury's answer be $$$B$$$. Your answer is accepted if and only if $$$\frac{|A - B|}{\max{(1, |B|)}} \le 10^{-6}$$$. | C | 2cd5807e3f9685d4eff88f2283904f0d | 126e49c4bac83f2c35b7909a7d8e37c7 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"geometry",
"math"
] | 1564497300 | ["1 2", "3 5"] | null | PASSED | 1,000 | standard input | 1 second | The only line contains two integers $$$H$$$ and $$$L$$$ ($$$1 \le H < L \le 10^{6}$$$). | ["1.5000000000000", "2.6666666666667"] | #include<stdio.h>
int main(){
float h,l,x;
scanf("%f%f",&h,&l);
x=(l*l-h*h)/(2.0*h);
printf("%.13f",x);
return 0;
} | |
While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly $$$H$$$ centimeters above the water surface. Inessa grabbed the flower and sailed the distance of $$$L$$$ centimeters. Exactly at this point the flower touched the water surface. Suppose that the lily grows at some point $$$A$$$ on the lake bottom, and its stem is always a straight segment with one endpoint at point $$$A$$$. Also suppose that initially the flower was exactly above the point $$$A$$$, i.e. its stem was vertical. Can you determine the depth of the lake at point $$$A$$$? | Print a single number — the depth of the lake at point $$$A$$$. The absolute or relative error should not exceed $$$10^{-6}$$$. Formally, let your answer be $$$A$$$, and the jury's answer be $$$B$$$. Your answer is accepted if and only if $$$\frac{|A - B|}{\max{(1, |B|)}} \le 10^{-6}$$$. | C | 2cd5807e3f9685d4eff88f2283904f0d | ae008be0d663149e6c222d5f95b34d86 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"geometry",
"math"
] | 1564497300 | ["1 2", "3 5"] | null | PASSED | 1,000 | standard input | 1 second | The only line contains two integers $$$H$$$ and $$$L$$$ ($$$1 \le H < L \le 10^{6}$$$). | ["1.5000000000000", "2.6666666666667"] | #include <stdio.h>
int main()
{
float a, b;
scanf("%f %f", &a, &b);
printf("%f\n", (b * b - a * a) / (2 * a));
}
| |
While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly $$$H$$$ centimeters above the water surface. Inessa grabbed the flower and sailed the distance of $$$L$$$ centimeters. Exactly at this point the flower touched the water surface. Suppose that the lily grows at some point $$$A$$$ on the lake bottom, and its stem is always a straight segment with one endpoint at point $$$A$$$. Also suppose that initially the flower was exactly above the point $$$A$$$, i.e. its stem was vertical. Can you determine the depth of the lake at point $$$A$$$? | Print a single number — the depth of the lake at point $$$A$$$. The absolute or relative error should not exceed $$$10^{-6}$$$. Formally, let your answer be $$$A$$$, and the jury's answer be $$$B$$$. Your answer is accepted if and only if $$$\frac{|A - B|}{\max{(1, |B|)}} \le 10^{-6}$$$. | C | 2cd5807e3f9685d4eff88f2283904f0d | 159c6497a102cd53146e763dd39f1577 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"geometry",
"math"
] | 1564497300 | ["1 2", "3 5"] | null | PASSED | 1,000 | standard input | 1 second | The only line contains two integers $$$H$$$ and $$$L$$$ ($$$1 \le H < L \le 10^{6}$$$). | ["1.5000000000000", "2.6666666666667"] | #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main()
{
float h, l, a;
scanf("%f %f", &h, &l);
a = (l*l-h*h)/(2*h);
printf("%.12f\n", a);
}
| |
While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly $$$H$$$ centimeters above the water surface. Inessa grabbed the flower and sailed the distance of $$$L$$$ centimeters. Exactly at this point the flower touched the water surface. Suppose that the lily grows at some point $$$A$$$ on the lake bottom, and its stem is always a straight segment with one endpoint at point $$$A$$$. Also suppose that initially the flower was exactly above the point $$$A$$$, i.e. its stem was vertical. Can you determine the depth of the lake at point $$$A$$$? | Print a single number — the depth of the lake at point $$$A$$$. The absolute or relative error should not exceed $$$10^{-6}$$$. Formally, let your answer be $$$A$$$, and the jury's answer be $$$B$$$. Your answer is accepted if and only if $$$\frac{|A - B|}{\max{(1, |B|)}} \le 10^{-6}$$$. | C | 2cd5807e3f9685d4eff88f2283904f0d | fba5b4e2f3437ba7ea78ca70f0b99e78 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"geometry",
"math"
] | 1564497300 | ["1 2", "3 5"] | null | PASSED | 1,000 | standard input | 1 second | The only line contains two integers $$$H$$$ and $$$L$$$ ($$$1 \le H < L \le 10^{6}$$$). | ["1.5000000000000", "2.6666666666667"] | #include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
int h,l;
float a;
scanf("%d %d",&h,&l);
a=l*tan(atan(1.0*h/l)-atan(1.0*l/h));
if(a<0)
a=-a;
printf("%.10f",a);
return 0;
}
| |
While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly $$$H$$$ centimeters above the water surface. Inessa grabbed the flower and sailed the distance of $$$L$$$ centimeters. Exactly at this point the flower touched the water surface. Suppose that the lily grows at some point $$$A$$$ on the lake bottom, and its stem is always a straight segment with one endpoint at point $$$A$$$. Also suppose that initially the flower was exactly above the point $$$A$$$, i.e. its stem was vertical. Can you determine the depth of the lake at point $$$A$$$? | Print a single number — the depth of the lake at point $$$A$$$. The absolute or relative error should not exceed $$$10^{-6}$$$. Formally, let your answer be $$$A$$$, and the jury's answer be $$$B$$$. Your answer is accepted if and only if $$$\frac{|A - B|}{\max{(1, |B|)}} \le 10^{-6}$$$. | C | 2cd5807e3f9685d4eff88f2283904f0d | ccd3d653f06ce24c0246a92fdeb72b26 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"geometry",
"math"
] | 1564497300 | ["1 2", "3 5"] | null | PASSED | 1,000 | standard input | 1 second | The only line contains two integers $$$H$$$ and $$$L$$$ ($$$1 \le H < L \le 10^{6}$$$). | ["1.5000000000000", "2.6666666666667"] | #include<stdio.h>
int main()
{
float h,l;
scanf("%f %f",&h,&l);
printf("%.13f",(l*l-h*h)/2/h);
}
| |
While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly $$$H$$$ centimeters above the water surface. Inessa grabbed the flower and sailed the distance of $$$L$$$ centimeters. Exactly at this point the flower touched the water surface. Suppose that the lily grows at some point $$$A$$$ on the lake bottom, and its stem is always a straight segment with one endpoint at point $$$A$$$. Also suppose that initially the flower was exactly above the point $$$A$$$, i.e. its stem was vertical. Can you determine the depth of the lake at point $$$A$$$? | Print a single number — the depth of the lake at point $$$A$$$. The absolute or relative error should not exceed $$$10^{-6}$$$. Formally, let your answer be $$$A$$$, and the jury's answer be $$$B$$$. Your answer is accepted if and only if $$$\frac{|A - B|}{\max{(1, |B|)}} \le 10^{-6}$$$. | C | 2cd5807e3f9685d4eff88f2283904f0d | 26cd6c26ea4ba99ff2f92242d13d305d | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"geometry",
"math"
] | 1564497300 | ["1 2", "3 5"] | null | PASSED | 1,000 | standard input | 1 second | The only line contains two integers $$$H$$$ and $$$L$$$ ($$$1 \le H < L \le 10^{6}$$$). | ["1.5000000000000", "2.6666666666667"] | main(h,l){scanf("%d%d",&h,&l);printf("%.9f",l/2.0*l/h-h/2.0);} | |
DZY loves colors, and he enjoys painting.On a colorful day, DZY gets a colorful ribbon, which consists of n units (they are numbered from 1 to n from left to right). The color of the i-th unit of the ribbon is i at first. It is colorful enough, but we still consider that the colorfulness of each unit is 0 at first.DZY loves painting, we know. He takes up a paintbrush with color x and uses it to draw a line on the ribbon. In such a case some contiguous units are painted. Imagine that the color of unit i currently is y. When it is painted by this paintbrush, the color of the unit becomes x, and the colorfulness of the unit increases by |x - y|.DZY wants to perform m operations, each operation can be one of the following: Paint all the units with numbers between l and r (both inclusive) with color x. Ask the sum of colorfulness of the units between l and r (both inclusive). Can you help DZY? | For each operation 2, print a line containing the answer — sum of colorfulness. | C | 562656bfc27b7cf06f7c4a373c6bc029 | c9b7e0f17aa0d9429704fff539ea2278 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"data structures"
] | 1404651900 | ["3 3\n1 1 2 4\n1 2 3 5\n2 1 3", "3 4\n1 1 3 4\n2 1 1\n2 2 2\n2 3 3", "10 6\n1 1 5 3\n1 2 7 9\n1 10 10 11\n1 3 8 12\n1 1 10 3\n2 1 10"] | NoteIn the first sample, the color of each unit is initially [1, 2, 3], and the colorfulness is [0, 0, 0].After the first operation, colors become [4, 4, 3], colorfulness become [3, 2, 0].After the second operation, colors become [4, 5, 5], colorfulness become [3, 3, 2].So the answer to the only operation of type 2 is 8. | PASSED | 2,400 | standard input | 2 seconds | The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 105). Each of the next m lines begins with a integer type (1 ≤ type ≤ 2), which represents the type of this operation. If type = 1, there will be 3 more integers l, r, x (1 ≤ l ≤ r ≤ n; 1 ≤ x ≤ 108) in this line, describing an operation 1. If type = 2, there will be 2 more integers l, r (1 ≤ l ≤ r ≤ n) in this line, describing an operation 2. | ["8", "3\n2\n1", "129"] | #include <stdio.h>
#include <string.h>
#include <math.h>
#define ll __int64
#define in(a) scanf("%d", &a)
#define out(b) printf("%I64d\n", b)
#define maxn 100000 + 4
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
ll sum[maxn << 2], lazy[maxn << 2];
int color[maxn << 2];
void pushUp(int rt) {
sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
if(color[rt << 1] == color[rt << 1 | 1]) {
color[rt] = color[rt << 1];
} else {
color[rt] = -1;
}
}
void build(int l, int r, int rt) {
if(l == r) {
sum[rt] = 0;
color[rt] = l;
return ;
}
int mid = (l + r) >> 1;
build(lson);
build(rson);
pushUp(rt);
}
void pushDown(int rt, int m) {
if(lazy[rt]) {
sum[rt << 1] += lazy[rt] * (m - m / 2);
sum[rt << 1 | 1] += lazy[rt] * (m / 2);
lazy[rt << 1] += lazy[rt];
lazy[rt << 1 | 1] += lazy[rt];
lazy[rt] = 0;
}
}
void update(int L, int R, int col, int l, int r, int rt) {
if(L <= l && R >= r) {
if(color[rt] != -1) {
sum[rt] += (ll)(r - l + 1) * abs(col - color[rt]);
lazy[rt] += abs(col - color[rt]);
color[rt] = col;
} else {
int mid = (l + r) >> 1;
pushDown(rt, r - l + 1);
update(L, R, col, lson);
update(L, R, col,rson);
pushUp(rt);
}
return ;
}
if(color[rt] != -1) {
color[rt << 1] = color[rt << 1 | 1] = color[rt];
color[rt] = -1;
}
pushDown(rt, r - l + 1);
int mid = (l + r) >> 1;
if(L <= mid) {
update(L, R, col, lson);
}
if(R > mid) {
update(L, R, col, rson);
}
pushUp(rt);
}
ll query(int L, int R, int l, int r, int rt) {
if(L <= l &&R >= r) {
return sum[rt];
}
int mid = (l + r) >> 1;
ll res = 0;
pushDown(rt, r - l + 1);
if(L <= mid) {
res += query(L, R, lson);
}
if(R > mid) {
res += query(L, R, rson);
}
return res;
}
int main()
{
int n, m;
while(~scanf("%d%d", &n, &m))
{
build(1, n, 1);
while(m--)
{
int t, l, r, x;
in(t);
if(t == 1)
{
in(l);in(r);in(x);
update(l, r, x, 1, n, 1);
}
if(t == 2)
{
in(l);in(r);
out(query(l, r, 1, n, 1));
}
}
}
return 0;
}
| |
DZY loves colors, and he enjoys painting.On a colorful day, DZY gets a colorful ribbon, which consists of n units (they are numbered from 1 to n from left to right). The color of the i-th unit of the ribbon is i at first. It is colorful enough, but we still consider that the colorfulness of each unit is 0 at first.DZY loves painting, we know. He takes up a paintbrush with color x and uses it to draw a line on the ribbon. In such a case some contiguous units are painted. Imagine that the color of unit i currently is y. When it is painted by this paintbrush, the color of the unit becomes x, and the colorfulness of the unit increases by |x - y|.DZY wants to perform m operations, each operation can be one of the following: Paint all the units with numbers between l and r (both inclusive) with color x. Ask the sum of colorfulness of the units between l and r (both inclusive). Can you help DZY? | For each operation 2, print a line containing the answer — sum of colorfulness. | C | 562656bfc27b7cf06f7c4a373c6bc029 | 7acece5f0fff48c680030f5323270290 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"data structures"
] | 1404651900 | ["3 3\n1 1 2 4\n1 2 3 5\n2 1 3", "3 4\n1 1 3 4\n2 1 1\n2 2 2\n2 3 3", "10 6\n1 1 5 3\n1 2 7 9\n1 10 10 11\n1 3 8 12\n1 1 10 3\n2 1 10"] | NoteIn the first sample, the color of each unit is initially [1, 2, 3], and the colorfulness is [0, 0, 0].After the first operation, colors become [4, 4, 3], colorfulness become [3, 2, 0].After the second operation, colors become [4, 5, 5], colorfulness become [3, 3, 2].So the answer to the only operation of type 2 is 8. | PASSED | 2,400 | standard input | 2 seconds | The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 105). Each of the next m lines begins with a integer type (1 ≤ type ≤ 2), which represents the type of this operation. If type = 1, there will be 3 more integers l, r, x (1 ≤ l ≤ r ≤ n; 1 ≤ x ≤ 108) in this line, describing an operation 1. If type = 2, there will be 2 more integers l, r (1 ≤ l ≤ r ≤ n) in this line, describing an operation 2. | ["8", "3\n2\n1", "129"] | #include <stdio.h>
#include <string.h>
#include <math.h>
#define ll __int64
#define in(a) scanf("%d", &a)
#define out(b) printf("%I64d\n", b)
#define maxn 100000 + 4
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
ll sum[maxn << 2], lazy[maxn << 2];
int color[maxn << 2];
void pushUp(int rt) {
sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
if(color[rt << 1] == color[rt << 1 | 1]) {
color[rt] = color[rt << 1];
} else {
// color[rt] = -1;
color[rt] = 0;
}
}
void build(int l, int r, int rt) {
if(l == r) {
sum[rt] = 0;
color[rt] = l;
return ;
}
color[rt] = lazy[rt] = 0;
int mid = (l + r) >> 1;
build(lson);
build(rson);
pushUp(rt);
}
void pushDown(int rt, int m) {
if(/*lazy[rt]*/color[rt]) {
color[rt << 1] = color[rt << 1 | 1] = color[rt];
sum[rt << 1] += lazy[rt] * (m - m / 2);
sum[rt << 1 | 1] += lazy[rt] * (m / 2);
lazy[rt << 1] += lazy[rt];
lazy[rt << 1 | 1] += lazy[rt];
lazy[rt] = color[rt] = 0;
}
}
void update(int L, int R, int col, int l, int r, int rt) {
// if(L <= l && R >= r) {
// if(color[rt] != -1) {
// sum[rt] += (ll)(r - l + 1) * abs(col - color[rt]);
// lazy[rt] += abs(col - color[rt]);
// color[rt] = col;
// } else {
// int mid = (l + r) >> 1;
// pushDown(rt, r - l + 1);
// update(L, R, col, lson);
// update(L, R, col,rson);
// pushUp(rt);
// }
// return ;
// }
// if(color[rt] != -1) {
// color[rt << 1] = color[rt << 1 | 1] = color[rt];
// color[rt] = -1;
// }
if(L <= l && R >= r && color[rt]) {
sum[rt] += abs(color[rt] - col) * (ll)(r - l + 1);
lazy[rt] += abs(color[rt] - col);
color[rt] = col;
return ;
}
pushDown(rt, r - l + 1);
int mid = (l + r) >> 1;
if(L <= mid) {
update(L, R, col, lson);
}
if(R > mid) {
update(L, R, col, rson);
}
pushUp(rt);
}
ll query(int L, int R, int l, int r, int rt) {
if(L <= l && R >= r) {
return sum[rt];
}
int mid = (l + r) >> 1;
ll res = 0;
pushDown(rt, r - l + 1);
if(L <= mid) {
res += query(L, R, lson);
}
if(R > mid) {
res += query(L, R, rson);
}
return res;
}
int main()
{
int n, m;
while(~scanf("%d%d", &n, &m))
{
build(1, n, 1);
while(m--)
{
int t, l, r, x;
in(t);
if(t == 1)
{
in(l);in(r);in(x);
update(l, r, x, 1, n, 1);
}
if(t == 2)
{
in(l);in(r);
out(query(l, r, 1, n, 1));
}
}
}
return 0;
}
| |
An array of integers $$$p_1, p_2, \dots, p_n$$$ is called a permutation if it contains each number from $$$1$$$ to $$$n$$$ exactly once. For example, the following arrays are permutations: $$$[3, 1, 2]$$$, $$$[1]$$$, $$$[1, 2, 3, 4, 5]$$$ and $$$[4, 3, 1, 2]$$$. The following arrays are not permutations: $$$[2]$$$, $$$[1, 1]$$$, $$$[2, 3, 4]$$$.Polycarp invented a really cool permutation $$$p_1, p_2, \dots, p_n$$$ of length $$$n$$$. It is very disappointing, but he forgot this permutation. He only remembers the array $$$q_1, q_2, \dots, q_{n-1}$$$ of length $$$n-1$$$, where $$$q_i=p_{i+1}-p_i$$$.Given $$$n$$$ and $$$q=q_1, q_2, \dots, q_{n-1}$$$, help Polycarp restore the invented permutation. | Print the integer -1 if there is no such permutation of length $$$n$$$ which corresponds to the given array $$$q$$$. Otherwise, if it exists, print $$$p_1, p_2, \dots, p_n$$$. Print any such permutation if there are many of them. | C | b6ac7c30b7efdc7206dbbad5cfb86db7 | 247f7086c1862b81923713aa42151741 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1553006100 | ["3\n-2 1", "5\n1 1 1 1", "4\n-1 2 2"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains the integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) — the length of the permutation to restore. The second line contains $$$n-1$$$ integers $$$q_1, q_2, \dots, q_{n-1}$$$ ($$$-n < q_i < n$$$). | ["3 1 2", "1 2 3 4 5", "-1"] | #include<stdio.h>
#include<stdlib.h>
#define size 2*100000
main()
{
long long int n,i,k=0;
long long int a[size+1];
long long int ans[size+2];
long long int cnt[size+1]={0};
long long int sum=0;
scanf("%I64d",&n);
for(i=0;i<n-1;++i)
{
scanf("%I64d",&a[i]);
sum+=a[i];
}
if(sum==0)
{
printf("-1");
}
else
{
ans[k++]=1;
for(i=0;i<n-1;++i)
{
ans[k]=ans[k-1]+a[i];
k++;
}
int flag=0,flag1=0;
long long int maxn=90;
for(i=0;i<k;++i)
{
if(ans[i]<=0)
{
flag=1;
}
if(ans[i]>n)
{
printf("-1");
exit(0);
}
if(ans[i]==n)
{
flag1=1;
}
if(ans[i]<maxn)
{
maxn=ans[i];
}
}
if(flag1==1 && flag==1)
{
printf("-1");
exit(0);
}
maxn=-maxn;
maxn++;
for(i=0;i<k;++i)
{
ans[i]=ans[i]+maxn;
if(ans[i]<=n)
cnt[ans[i]]++;
if(cnt[ans[i]]>1 || ans[i]>n)
{
printf("-1");
exit(0);
}
}
for(i=0;i<k;++i)
{
printf("%I64d ",ans[i]);
}
}
} | |
An array of integers $$$p_1, p_2, \dots, p_n$$$ is called a permutation if it contains each number from $$$1$$$ to $$$n$$$ exactly once. For example, the following arrays are permutations: $$$[3, 1, 2]$$$, $$$[1]$$$, $$$[1, 2, 3, 4, 5]$$$ and $$$[4, 3, 1, 2]$$$. The following arrays are not permutations: $$$[2]$$$, $$$[1, 1]$$$, $$$[2, 3, 4]$$$.Polycarp invented a really cool permutation $$$p_1, p_2, \dots, p_n$$$ of length $$$n$$$. It is very disappointing, but he forgot this permutation. He only remembers the array $$$q_1, q_2, \dots, q_{n-1}$$$ of length $$$n-1$$$, where $$$q_i=p_{i+1}-p_i$$$.Given $$$n$$$ and $$$q=q_1, q_2, \dots, q_{n-1}$$$, help Polycarp restore the invented permutation. | Print the integer -1 if there is no such permutation of length $$$n$$$ which corresponds to the given array $$$q$$$. Otherwise, if it exists, print $$$p_1, p_2, \dots, p_n$$$. Print any such permutation if there are many of them. | C | b6ac7c30b7efdc7206dbbad5cfb86db7 | 3b42ec776d137bcb1975d6cbc81c4a5a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1553006100 | ["3\n-2 1", "5\n1 1 1 1", "4\n-1 2 2"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains the integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) — the length of the permutation to restore. The second line contains $$$n-1$$$ integers $$$q_1, q_2, \dots, q_{n-1}$$$ ($$$-n < q_i < n$$$). | ["3 1 2", "1 2 3 4 5", "-1"] | #include <stdio.h>
#include <stdint.h>
#include <string.h>
#define P_SIZE 200000 + 4
#define ABS(x) (((x)^((x) >> 31)) + (1&((x) >> 31)))
#define PREFIX_ID(id) (id+1)
uint32_t n;
int32_t ready[P_SIZE];
int32_t p[P_SIZE+1];
uint8_t exists[P_SIZE];
#define LEFT_BIT_ONE (1 << 31)
struct sub_sum {
uint32_t left;
uint32_t right;
int32_t sum;
};
struct sub_sum max_subsum, min_subsum;
int main(int argc, char** argv) {
max_subsum.sum = LEFT_BIT_ONE;
min_subsum.sum = ~LEFT_BIT_ONE;
int32_t pref = 0;
uint32_t min_id = -1, max_id = -1;
int32_t min_pref = 0, max_pref = 0;
int32_t delta;
uint8_t exist = 1;
memset(exists, 0, sizeof(uint8_t)*n);
//
scanf("%d", &n);
const uint32_t n_minus_one = n - 1;
for (uint32_t i = 0; i < n_minus_one; i++) {
scanf("%d", &p[i]);
pref += p[i];
// MAX
delta = pref - min_pref;
if (max_subsum.sum < delta) {
max_subsum.sum = delta;
max_subsum.left = min_id+1;
max_subsum.right = i;
}
if (pref < min_pref) {
min_pref = pref;
min_id = i;
}
// ---
// MIN
delta = pref - max_pref;
if (min_subsum.sum > delta) {
min_subsum.sum = delta;
min_subsum.left = max_id+1;
min_subsum.right = i;
}
if (pref > max_pref) {
max_pref = pref;
max_id = i;
}
// ---
exist = exist && p[i];
}
uint32_t n_id;
if (min_subsum.sum < 0 && ABS(min_subsum.sum) >= ABS(max_subsum.sum)) {
n_id = min_subsum.left;
}
else {
n_id = max_subsum.right + 1;
}
ready[n_id] = n;
exists[n-1] = 1;
for (uint32_t i = n_id + 1; exist && i < n; i++) {
ready[i] = ready[i-1] + p[i-1];
exist = !exists[ready[i]-1] && ready[i] > 0 && ready[i] <= n;
exists[ready[i]-1] = 1;
}
for (int32_t i = n_id - 1; exist && i >= 0; i--) {
ready[i] = ready[i+1] - p[i];
exist = !exists[ready[i]-1] && ready[i] > 0 && ready[i] <= n;
exists[ready[i]-1] = 1;
}
if (exist) {
for (uint32_t i = 0; i < n; i++) {
printf("%d ", ready[i]);
}
}
else {
printf("-1");
}
return 0;
} | |
An array of integers $$$p_1, p_2, \dots, p_n$$$ is called a permutation if it contains each number from $$$1$$$ to $$$n$$$ exactly once. For example, the following arrays are permutations: $$$[3, 1, 2]$$$, $$$[1]$$$, $$$[1, 2, 3, 4, 5]$$$ and $$$[4, 3, 1, 2]$$$. The following arrays are not permutations: $$$[2]$$$, $$$[1, 1]$$$, $$$[2, 3, 4]$$$.Polycarp invented a really cool permutation $$$p_1, p_2, \dots, p_n$$$ of length $$$n$$$. It is very disappointing, but he forgot this permutation. He only remembers the array $$$q_1, q_2, \dots, q_{n-1}$$$ of length $$$n-1$$$, where $$$q_i=p_{i+1}-p_i$$$.Given $$$n$$$ and $$$q=q_1, q_2, \dots, q_{n-1}$$$, help Polycarp restore the invented permutation. | Print the integer -1 if there is no such permutation of length $$$n$$$ which corresponds to the given array $$$q$$$. Otherwise, if it exists, print $$$p_1, p_2, \dots, p_n$$$. Print any such permutation if there are many of them. | C | b6ac7c30b7efdc7206dbbad5cfb86db7 | ae0f7be4ed34f06d6bb8d904b1c05fe0 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1553006100 | ["3\n-2 1", "5\n1 1 1 1", "4\n-1 2 2"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains the integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) — the length of the permutation to restore. The second line contains $$$n-1$$$ integers $$$q_1, q_2, \dots, q_{n-1}$$$ ($$$-n < q_i < n$$$). | ["3 1 2", "1 2 3 4 5", "-1"] | #include<stdio.h>
#include<math.h>
long long arr[200010]={};
int main(){
long long n;int inarr[200010];
scanf("%lld",&n);
for(int i=1;i<n ; i++){
scanf("%d",&inarr[i]);
arr[i]=arr[i-1]+inarr[i];
}
long long sum=0;
for(int i=1;i<n; i++){
sum+=arr[i];
arr[i]=0;
}
inarr[0]=(n*(n+1)-2*sum)/(2*n);
double x=(n*((double)n+1)-2*(double)sum)/(2*(double)n);
if(inarr[0]<1 || inarr[0]>n || (fabs(inarr[0]-x)>1e-12)){
printf("-1");
return 0;
}
arr[inarr[0]]=1;
for(int i=1;i<n; i++){
inarr[i]=inarr[i]+inarr[i-1];
if(arr[inarr[i]]==1){
printf("-1");
return 0;
}
else{
arr[inarr[i]]=1;
}
}
for(int i=0;i<n ; i++){
printf("%d ",inarr[i]);
}
return 0;
}
| |
An array of integers $$$p_1, p_2, \dots, p_n$$$ is called a permutation if it contains each number from $$$1$$$ to $$$n$$$ exactly once. For example, the following arrays are permutations: $$$[3, 1, 2]$$$, $$$[1]$$$, $$$[1, 2, 3, 4, 5]$$$ and $$$[4, 3, 1, 2]$$$. The following arrays are not permutations: $$$[2]$$$, $$$[1, 1]$$$, $$$[2, 3, 4]$$$.Polycarp invented a really cool permutation $$$p_1, p_2, \dots, p_n$$$ of length $$$n$$$. It is very disappointing, but he forgot this permutation. He only remembers the array $$$q_1, q_2, \dots, q_{n-1}$$$ of length $$$n-1$$$, where $$$q_i=p_{i+1}-p_i$$$.Given $$$n$$$ and $$$q=q_1, q_2, \dots, q_{n-1}$$$, help Polycarp restore the invented permutation. | Print the integer -1 if there is no such permutation of length $$$n$$$ which corresponds to the given array $$$q$$$. Otherwise, if it exists, print $$$p_1, p_2, \dots, p_n$$$. Print any such permutation if there are many of them. | C | b6ac7c30b7efdc7206dbbad5cfb86db7 | 6f998298cadc7d9c46dd67ddd2ced1c9 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1553006100 | ["3\n-2 1", "5\n1 1 1 1", "4\n-1 2 2"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains the integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) — the length of the permutation to restore. The second line contains $$$n-1$$$ integers $$$q_1, q_2, \dots, q_{n-1}$$$ ($$$-n < q_i < n$$$). | ["3 1 2", "1 2 3 4 5", "-1"] | #include <stdio.h>
#include <stdlib.h>
int cmpfunc (const void * a, const void * b) {
return ( *(int*)a - *(int*)b );
}
int main()
{
int i, b, c, d, e, f,check=0,check1 =0,min =1;
scanf("%d", &i);
int br[i], cr[i+1], dr[i+1];
cr[0] = 1;
for(b=0; b<i-1; b++)
{
scanf("%d", &br[b]);
cr[b+1] = cr[b] + br[b];
if(cr[b+1] < min)
min = cr[b+1];
}
e = 1 - min;
for (b=0; b<i; b++)
{
cr[b] = cr[b]+e;
dr[b] = cr[b];
}
qsort(cr, i, sizeof(int), cmpfunc);
for (b=0; b<i; b++)
{
if(cr[b] == 1)
check1 = 1;
// printf("%d ", cr[b]);
}
// f = cr[1] - cr[0] ;
for(b=1; b<i; b++)
{
if((cr[b] - cr[b-1]) !=1)
{
check = 1;
// printf("Here %d, %d ", cr[b], cr[b-1]);
break;
}
}
if(check != 1 && check1 ==1)
{
for(b=0; b<i; b++)
printf("%d ", dr[b]);
}
else
printf("-1");
return 0;
}
| |
An array of integers $$$p_1, p_2, \dots, p_n$$$ is called a permutation if it contains each number from $$$1$$$ to $$$n$$$ exactly once. For example, the following arrays are permutations: $$$[3, 1, 2]$$$, $$$[1]$$$, $$$[1, 2, 3, 4, 5]$$$ and $$$[4, 3, 1, 2]$$$. The following arrays are not permutations: $$$[2]$$$, $$$[1, 1]$$$, $$$[2, 3, 4]$$$.Polycarp invented a really cool permutation $$$p_1, p_2, \dots, p_n$$$ of length $$$n$$$. It is very disappointing, but he forgot this permutation. He only remembers the array $$$q_1, q_2, \dots, q_{n-1}$$$ of length $$$n-1$$$, where $$$q_i=p_{i+1}-p_i$$$.Given $$$n$$$ and $$$q=q_1, q_2, \dots, q_{n-1}$$$, help Polycarp restore the invented permutation. | Print the integer -1 if there is no such permutation of length $$$n$$$ which corresponds to the given array $$$q$$$. Otherwise, if it exists, print $$$p_1, p_2, \dots, p_n$$$. Print any such permutation if there are many of them. | C | b6ac7c30b7efdc7206dbbad5cfb86db7 | 11f85dcf9b7b9dd06a47c9fb255a42aa | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1553006100 | ["3\n-2 1", "5\n1 1 1 1", "4\n-1 2 2"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains the integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) — the length of the permutation to restore. The second line contains $$$n-1$$$ integers $$$q_1, q_2, \dots, q_{n-1}$$$ ($$$-n < q_i < n$$$). | ["3 1 2", "1 2 3 4 5", "-1"] | #include <stdio.h>
#include <stdlib.h>
#define SWAP(a , b) *a = *a ^ *b; *b = *a ^ *b; *a = *a ^ *b;
#define INP_INT_ARA(ara_ads , size) for(int i = 0; i < size ; i++) scanf("%d",(ara_ads + i));
double qSum = 0 , tempP , tempN ;
int n , p[200000] = {0} , q[199999] = {0} , flag[200001] = {0};
int main(void) {
scanf("%d",&n); tempN = (double) n ;
INP_INT_ARA(q , n-1);
for (int i = n - 1 , j = 0 ; i > 0 ; i-- , j++) {
qSum += (double) (*(q + j))*(i);
}
tempP = ((tempN + 1.000000)/2.000000) -(qSum / tempN) ;
if (( tempP < 1) || ( tempP > n )) {
printf("-1");
exit(0);
}
*p = (int) tempP ;
*(flag + *p) = -1 ;
for (int i = 1; i < n; i++) {
*(p + i) = *(p + i - 1) + *(q + i - 1);
if (( *(p + i) < 1) || ( *(p + i) > n )) {
printf("-1");
exit(0);
}
if ( *(flag + *(p + i)) == -1) {
printf("-1");
exit(0);
}
*(flag + *(p + i)) = -1;
}
for (int i = 0; i < n; i++) {
printf("%d " , *(p + i));
}
return 0;
}
| |
An array of integers $$$p_1, p_2, \dots, p_n$$$ is called a permutation if it contains each number from $$$1$$$ to $$$n$$$ exactly once. For example, the following arrays are permutations: $$$[3, 1, 2]$$$, $$$[1]$$$, $$$[1, 2, 3, 4, 5]$$$ and $$$[4, 3, 1, 2]$$$. The following arrays are not permutations: $$$[2]$$$, $$$[1, 1]$$$, $$$[2, 3, 4]$$$.Polycarp invented a really cool permutation $$$p_1, p_2, \dots, p_n$$$ of length $$$n$$$. It is very disappointing, but he forgot this permutation. He only remembers the array $$$q_1, q_2, \dots, q_{n-1}$$$ of length $$$n-1$$$, where $$$q_i=p_{i+1}-p_i$$$.Given $$$n$$$ and $$$q=q_1, q_2, \dots, q_{n-1}$$$, help Polycarp restore the invented permutation. | Print the integer -1 if there is no such permutation of length $$$n$$$ which corresponds to the given array $$$q$$$. Otherwise, if it exists, print $$$p_1, p_2, \dots, p_n$$$. Print any such permutation if there are many of them. | C | b6ac7c30b7efdc7206dbbad5cfb86db7 | 46a5b3f2c009e760e7acccb59dfad2b1 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1553006100 | ["3\n-2 1", "5\n1 1 1 1", "4\n-1 2 2"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains the integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) — the length of the permutation to restore. The second line contains $$$n-1$$$ integers $$$q_1, q_2, \dots, q_{n-1}$$$ ($$$-n < q_i < n$$$). | ["3 1 2", "1 2 3 4 5", "-1"] | #include<stdio.h>
#include<math.h>
int y[200001]={0};
int main()
{
int n,i,j,k=0,min=0;
scanf("%d",&n);
int a[n],b[n],c[n];
for(i=1;i<n;i++)
{
scanf("%d",&a[i]);
k=k+a[i];
if(k>n || k<-n)
{
printf("-1");
return 0;
}
if(k<min)
{
min=k;
}
}
min=abs(min)+1;
if(min>n)
{
printf("-1");
return 0;
}
b[0]=min;
y[b[0]]++;
for(i=1;i<n;i++)
{
b[i]=b[i-1]+a[i];
y[b[i]]++;
if(b[i]>n)
{
printf("-1");
return 0;
}
}
for(i=0;i<200001;i++)
{
if(y[i]>1)
{
printf("-1");
return 0;
}
}
for(i=0;i<n;i++)
{
printf("%d\n",b[i]);
}
return 0;
}
| |
An array of integers $$$p_1, p_2, \dots, p_n$$$ is called a permutation if it contains each number from $$$1$$$ to $$$n$$$ exactly once. For example, the following arrays are permutations: $$$[3, 1, 2]$$$, $$$[1]$$$, $$$[1, 2, 3, 4, 5]$$$ and $$$[4, 3, 1, 2]$$$. The following arrays are not permutations: $$$[2]$$$, $$$[1, 1]$$$, $$$[2, 3, 4]$$$.Polycarp invented a really cool permutation $$$p_1, p_2, \dots, p_n$$$ of length $$$n$$$. It is very disappointing, but he forgot this permutation. He only remembers the array $$$q_1, q_2, \dots, q_{n-1}$$$ of length $$$n-1$$$, where $$$q_i=p_{i+1}-p_i$$$.Given $$$n$$$ and $$$q=q_1, q_2, \dots, q_{n-1}$$$, help Polycarp restore the invented permutation. | Print the integer -1 if there is no such permutation of length $$$n$$$ which corresponds to the given array $$$q$$$. Otherwise, if it exists, print $$$p_1, p_2, \dots, p_n$$$. Print any such permutation if there are many of them. | C | b6ac7c30b7efdc7206dbbad5cfb86db7 | 6bbc91cff589c33041eafafec45f1480 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1553006100 | ["3\n-2 1", "5\n1 1 1 1", "4\n-1 2 2"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains the integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) — the length of the permutation to restore. The second line contains $$$n-1$$$ integers $$$q_1, q_2, \dots, q_{n-1}$$$ ($$$-n < q_i < n$$$). | ["3 1 2", "1 2 3 4 5", "-1"] | #include<stdio.h>
void merge(int arr[], int l, int m, int r)
{
int n1 = m - l + 1;
int n2 = r - m;
// Create temp arrays
int L[n1], R[n2];
// Copy data to temp arrays L[] and R[]
for(int i = 0; i < n1; i++)
L[i] = arr[l + i];
for(int j = 0; j < n2; j++)
R[j] = arr[m + 1 + j];
// Merge the temp arrays back into arr[l..r]
// Initial index of first subarray
int i = 0;
// Initial index of second subarray
int j = 0;
// Initial index of merged subarray
int k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
// Copy the remaining elements of
// L[], if there are any
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
// Copy the remaining elements of
// R[], if there are any
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
// l is for left index and r is
// right index of the sub-array
// of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
if (l < r)
{
// Same as (l+r)/2, but avoids
// overflow for large l and h
int m = l + (r - l) / 2;
// Sort first and second halves
mergeSort(arr, l, m);
mergeSort(arr, m + 1, r);
merge(arr, l, m, r);
}
}
int main(){
int n,pass=1;
scanf("%d\n",&n);
int b[n-1];
int a[n],c[n];
a[0]=0;c[0]=0;
for(int i=0;i<n-1;i++){
scanf("%d ",&b[i]);
a[i+1]=a[i]+b[i];
c[i+1]=a[i+1];
}
mergeSort(a,0,n-1);
int l=a[0]-1;
for(int i=0;i<n;i++){
a[i]=a[i]-l;
}
mergeSort(a,0,n-1);
for(int i=0;i<n;i++){
if(a[i]!=i+1){
pass=0;
break;
}
}
printf("\n");
if(pass!=1){
printf("-1");
}
else{
for(int i=0;i<n;i++){
printf("%d ",c[i]-l);
}
}
return 0;
} | |
An array of integers $$$p_1, p_2, \dots, p_n$$$ is called a permutation if it contains each number from $$$1$$$ to $$$n$$$ exactly once. For example, the following arrays are permutations: $$$[3, 1, 2]$$$, $$$[1]$$$, $$$[1, 2, 3, 4, 5]$$$ and $$$[4, 3, 1, 2]$$$. The following arrays are not permutations: $$$[2]$$$, $$$[1, 1]$$$, $$$[2, 3, 4]$$$.Polycarp invented a really cool permutation $$$p_1, p_2, \dots, p_n$$$ of length $$$n$$$. It is very disappointing, but he forgot this permutation. He only remembers the array $$$q_1, q_2, \dots, q_{n-1}$$$ of length $$$n-1$$$, where $$$q_i=p_{i+1}-p_i$$$.Given $$$n$$$ and $$$q=q_1, q_2, \dots, q_{n-1}$$$, help Polycarp restore the invented permutation. | Print the integer -1 if there is no such permutation of length $$$n$$$ which corresponds to the given array $$$q$$$. Otherwise, if it exists, print $$$p_1, p_2, \dots, p_n$$$. Print any such permutation if there are many of them. | C | b6ac7c30b7efdc7206dbbad5cfb86db7 | 6237585f78791139468d2bd2ba907e9c | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1553006100 | ["3\n-2 1", "5\n1 1 1 1", "4\n-1 2 2"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains the integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) — the length of the permutation to restore. The second line contains $$$n-1$$$ integers $$$q_1, q_2, \dots, q_{n-1}$$$ ($$$-n < q_i < n$$$). | ["3 1 2", "1 2 3 4 5", "-1"] | #include <stdio.h>
#include <string.h>
int main() {
int a[200010], test[200010];
int N, i, temp, MAX = 0, p1;
scanf("%d", &N);
a[0] = 0;
for(i = 1; i < N; i++) {
scanf("%d", &temp);
a[i] = a[i - 1] + temp;
if(a[i] > N || a[i] < 1 - N) {
printf("-1\n");
return 0;
}
if(a[i] > MAX) MAX = a[i];
}
memset(test, 0, (N + 1) * sizeof(int));
p1 = N - MAX;
for(i = 0; i < N; i++) {
a[i] += p1;
test[a[i]] = 1;
}
for(i = 1; i <= N; i++)
if(test[i] == 0) {
printf("-1\n");
return 0;
}
for(i = 0; i < N; i++)
printf("%d ", a[i]);
return 0;
} | |
An array of integers $$$p_1, p_2, \dots, p_n$$$ is called a permutation if it contains each number from $$$1$$$ to $$$n$$$ exactly once. For example, the following arrays are permutations: $$$[3, 1, 2]$$$, $$$[1]$$$, $$$[1, 2, 3, 4, 5]$$$ and $$$[4, 3, 1, 2]$$$. The following arrays are not permutations: $$$[2]$$$, $$$[1, 1]$$$, $$$[2, 3, 4]$$$.Polycarp invented a really cool permutation $$$p_1, p_2, \dots, p_n$$$ of length $$$n$$$. It is very disappointing, but he forgot this permutation. He only remembers the array $$$q_1, q_2, \dots, q_{n-1}$$$ of length $$$n-1$$$, where $$$q_i=p_{i+1}-p_i$$$.Given $$$n$$$ and $$$q=q_1, q_2, \dots, q_{n-1}$$$, help Polycarp restore the invented permutation. | Print the integer -1 if there is no such permutation of length $$$n$$$ which corresponds to the given array $$$q$$$. Otherwise, if it exists, print $$$p_1, p_2, \dots, p_n$$$. Print any such permutation if there are many of them. | C | b6ac7c30b7efdc7206dbbad5cfb86db7 | 8240756ba16220791fbb9279672a8be4 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1553006100 | ["3\n-2 1", "5\n1 1 1 1", "4\n-1 2 2"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains the integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) — the length of the permutation to restore. The second line contains $$$n-1$$$ integers $$$q_1, q_2, \dots, q_{n-1}$$$ ($$$-n < q_i < n$$$). | ["3 1 2", "1 2 3 4 5", "-1"] | #include<stdio.h>
void merge(int a[],int l,int m,int r)
{
int i=0,j=m+1,k=l;
int size1=m-l+1;
int size2=r-m;
int leftArr[size1],rightArr[size2];
for(int i=0;i<size1;i++){
leftArr[i]=a[l+i];
}
for(int i=0;i<size2;i++){
rightArr[i]=a[m+1+i];
}
i=0;
j=0;
while(i<size1&&j<size2)
{
if(leftArr[i]<rightArr[j])
{
a[k++]=leftArr[i++];
}
else
{
a[k++]=rightArr[j++];
}
}
while(i<size1)
{
a[k++]=leftArr[i++];
}
while(j<size2)
{
a[k++]=rightArr[j++];
}
}
void mergesort(int a[],int l,int r)
{
if(l<r)
{
int m=(l+r)/2;
mergesort(a,l,m);
mergesort(a,m+1,r);
merge(a,l,m,r);
}
}
int main(){
int n,i,index,flag=0;
scanf("%d",&n);
int p[n],q[n-1],b[n-1],a[n];
for(i=0;i<n-1;i++)
scanf("%d",&q[i]);
index=0;
b[0]=q[0];
for(i=1;i<n-1;i++)
{
b[i]=b[i-1]+q[i];
if(b[i]>b[index])
index=i;
}
if(b[index]<0)
{
p[0]=n;
for(i=0;i<n-1;i++)
p[i+1]=b[i]+p[0];
}
else
{
p[index+1]=n;
p[0]=p[index+1]-b[index];
for(i=0;i<n-1;i++)
p[i+1]=b[i]+p[0];
}
for(i=0;i<n;i++)
a[i]=p[i];
mergesort(p,0,n-1);
for(i=0;i<n;i++)
{
if(p[i]!=i+1)
{
flag=1;
break;
}
}
if(flag==0)
{
for(i=0;i<n;i++)
printf("%d ",a[i]);
}
else
printf("-1\n");
return 0;
} | |
An array of integers $$$p_1, p_2, \dots, p_n$$$ is called a permutation if it contains each number from $$$1$$$ to $$$n$$$ exactly once. For example, the following arrays are permutations: $$$[3, 1, 2]$$$, $$$[1]$$$, $$$[1, 2, 3, 4, 5]$$$ and $$$[4, 3, 1, 2]$$$. The following arrays are not permutations: $$$[2]$$$, $$$[1, 1]$$$, $$$[2, 3, 4]$$$.Polycarp invented a really cool permutation $$$p_1, p_2, \dots, p_n$$$ of length $$$n$$$. It is very disappointing, but he forgot this permutation. He only remembers the array $$$q_1, q_2, \dots, q_{n-1}$$$ of length $$$n-1$$$, where $$$q_i=p_{i+1}-p_i$$$.Given $$$n$$$ and $$$q=q_1, q_2, \dots, q_{n-1}$$$, help Polycarp restore the invented permutation. | Print the integer -1 if there is no such permutation of length $$$n$$$ which corresponds to the given array $$$q$$$. Otherwise, if it exists, print $$$p_1, p_2, \dots, p_n$$$. Print any such permutation if there are many of them. | C | b6ac7c30b7efdc7206dbbad5cfb86db7 | ef0e65673016cfaab9c8b29d6c9011ee | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1553006100 | ["3\n-2 1", "5\n1 1 1 1", "4\n-1 2 2"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains the integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) — the length of the permutation to restore. The second line contains $$$n-1$$$ integers $$$q_1, q_2, \dots, q_{n-1}$$$ ($$$-n < q_i < n$$$). | ["3 1 2", "1 2 3 4 5", "-1"] | /// Property of vipulks \\
#include <stdio.h>
#include <limits.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
int main(){
ll t,n,m,i,j,k,cnt;
t=1;
//scanf("%lld",&t);
while(t--){
bool ok=true;
scanf("%lld",&n);
ll q[n+2],p[n+2],pref[n+3];
for(i=1;i<=n;i++)
p[i]=0;
for(i=0;i<n-1;i++)
scanf("%lld",&q[i]);
pref[0]=0;
for(i=0;i<n-1;i++)
pref[i+1]=pref[i]+q[i];
ll min=pref[0];
for(i=1;i<n;i++){
if(pref[i]<min)
min=pref[i];
}
for(i=0;i<n;i++){
pref[i]+=1-min;
if(pref[i]>n || pref[i]<1)
ok=false;
if(ok && p[pref[i]]==1)
ok=false;
else if(ok)
p[pref[i]]=1;
}
for(i=0;i<n && ok;i++)
printf("%lld ",pref[i]);
if(ok==false)
printf("-1");
printf("\n");
}
return 0;
} | |
An array of integers $$$p_1, p_2, \dots, p_n$$$ is called a permutation if it contains each number from $$$1$$$ to $$$n$$$ exactly once. For example, the following arrays are permutations: $$$[3, 1, 2]$$$, $$$[1]$$$, $$$[1, 2, 3, 4, 5]$$$ and $$$[4, 3, 1, 2]$$$. The following arrays are not permutations: $$$[2]$$$, $$$[1, 1]$$$, $$$[2, 3, 4]$$$.Polycarp invented a really cool permutation $$$p_1, p_2, \dots, p_n$$$ of length $$$n$$$. It is very disappointing, but he forgot this permutation. He only remembers the array $$$q_1, q_2, \dots, q_{n-1}$$$ of length $$$n-1$$$, where $$$q_i=p_{i+1}-p_i$$$.Given $$$n$$$ and $$$q=q_1, q_2, \dots, q_{n-1}$$$, help Polycarp restore the invented permutation. | Print the integer -1 if there is no such permutation of length $$$n$$$ which corresponds to the given array $$$q$$$. Otherwise, if it exists, print $$$p_1, p_2, \dots, p_n$$$. Print any such permutation if there are many of them. | C | b6ac7c30b7efdc7206dbbad5cfb86db7 | 29d4f0def3f05548f7e3549a2b3b5381 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1553006100 | ["3\n-2 1", "5\n1 1 1 1", "4\n-1 2 2"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains the integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) — the length of the permutation to restore. The second line contains $$$n-1$$$ integers $$$q_1, q_2, \dots, q_{n-1}$$$ ($$$-n < q_i < n$$$). | ["3 1 2", "1 2 3 4 5", "-1"] | #include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define maxn 200001
int min(int a, int b){
return (a < b ? a : b);
}
void quick_sort(int a[], int l, int r){
int i = l, j = r, mid, tmp;
mid = a[(l + r + 1) / 2];
do{
while(a[i] < mid) i++;
while(mid < a[j]) j--;
if(i <= j){
tmp = a[i]; a[i] = a[j]; a[j] = tmp;
i++; j--;
}
}while(i < j);
if(l < j)
quick_sort(a, l, j);
if(i < r)
quick_sort(a, i, r);
}
int main(){
int n, q[maxn], p[maxn], i;
long long a = LONG_MAX;
scanf("%d", &n);
q[1] = 0;
for(i = 2; i <= n; i++){
scanf("%d", &q[i]);
q[i] += q[i - 1];
a = min(a, q[i]);
}
if(a < 0) a = 1 - a;
for(i = 1; i <= n; i++){
q[i] += a;
p[i] = q[i];
}
quick_sort(p, 1, n);
for(i = 1; i <= n; i++){
if(p[i] != i){
printf("-1\n");
exit(0);
}
}
for(i = 1; i <= n; i++) printf("%d ", q[i]);
} | |
An array of integers $$$p_1, p_2, \dots, p_n$$$ is called a permutation if it contains each number from $$$1$$$ to $$$n$$$ exactly once. For example, the following arrays are permutations: $$$[3, 1, 2]$$$, $$$[1]$$$, $$$[1, 2, 3, 4, 5]$$$ and $$$[4, 3, 1, 2]$$$. The following arrays are not permutations: $$$[2]$$$, $$$[1, 1]$$$, $$$[2, 3, 4]$$$.Polycarp invented a really cool permutation $$$p_1, p_2, \dots, p_n$$$ of length $$$n$$$. It is very disappointing, but he forgot this permutation. He only remembers the array $$$q_1, q_2, \dots, q_{n-1}$$$ of length $$$n-1$$$, where $$$q_i=p_{i+1}-p_i$$$.Given $$$n$$$ and $$$q=q_1, q_2, \dots, q_{n-1}$$$, help Polycarp restore the invented permutation. | Print the integer -1 if there is no such permutation of length $$$n$$$ which corresponds to the given array $$$q$$$. Otherwise, if it exists, print $$$p_1, p_2, \dots, p_n$$$. Print any such permutation if there are many of them. | C | b6ac7c30b7efdc7206dbbad5cfb86db7 | d1ed764dfc81ccf9884b9018103f2184 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1553006100 | ["3\n-2 1", "5\n1 1 1 1", "4\n-1 2 2"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains the integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) — the length of the permutation to restore. The second line contains $$$n-1$$$ integers $$$q_1, q_2, \dots, q_{n-1}$$$ ($$$-n < q_i < n$$$). | ["3 1 2", "1 2 3 4 5", "-1"] | # include <stdio.h>
long long cun[200010];
long long fang[200010];
long long cha[200010];
int main ()
{
long long max,xu,a,b,c,d,e,i,j,k,n;
scanf("%lld",&n);
max=0;
xu=1;
c=0;
fang[1]=0;
for(i=1;i<=n;i++)
{
cha[i]=0;
if(i<n)
scanf("%lld",&cun[i]);
if(i!=n)
{
fang[i+1]=fang[i]+cun[i];
if(fang[i+1]>max)
{
max=fang[i+1];
xu=i+1;
}
if(cun[i]==0)
c=-1;
}
}
if(c==-1)
printf("-1");
if(c!=-1)
{
max=xu;
fang[max]=n;
cha[n]=1;
for(i=max;i<n;i++)
{
a=fang[i]+cun[i];
if(cha[a]==1||a<=0||a>n)
{
c=-1;
break;
}
if(cha[a]==0)
{
fang[i+1]=a;
cha[a]=1;
}
}
if(c!=-1)
{
for(i=max-1;i>=1;i--)
{
a=fang[i+1]-cun[i];
if(cha[a]==1||a<=0||a>n)
{
c=-1;
break;
}
if(cha[a]==0)
{
fang[i]=a;
cha[a]=1;
}
}
}
if(c==-1)
printf("-1");
else
{
for(i=1;i<=n;i++)
{
printf("%lld",fang[i]);
if(i!=n)
printf(" ");
}
}
}
return 0;
} | |
An array of integers $$$p_1, p_2, \dots, p_n$$$ is called a permutation if it contains each number from $$$1$$$ to $$$n$$$ exactly once. For example, the following arrays are permutations: $$$[3, 1, 2]$$$, $$$[1]$$$, $$$[1, 2, 3, 4, 5]$$$ and $$$[4, 3, 1, 2]$$$. The following arrays are not permutations: $$$[2]$$$, $$$[1, 1]$$$, $$$[2, 3, 4]$$$.Polycarp invented a really cool permutation $$$p_1, p_2, \dots, p_n$$$ of length $$$n$$$. It is very disappointing, but he forgot this permutation. He only remembers the array $$$q_1, q_2, \dots, q_{n-1}$$$ of length $$$n-1$$$, where $$$q_i=p_{i+1}-p_i$$$.Given $$$n$$$ and $$$q=q_1, q_2, \dots, q_{n-1}$$$, help Polycarp restore the invented permutation. | Print the integer -1 if there is no such permutation of length $$$n$$$ which corresponds to the given array $$$q$$$. Otherwise, if it exists, print $$$p_1, p_2, \dots, p_n$$$. Print any such permutation if there are many of them. | C | b6ac7c30b7efdc7206dbbad5cfb86db7 | 3c510c6d00612eb04f0afd678aaa9a3f | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1553006100 | ["3\n-2 1", "5\n1 1 1 1", "4\n-1 2 2"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains the integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) — the length of the permutation to restore. The second line contains $$$n-1$$$ integers $$$q_1, q_2, \dots, q_{n-1}$$$ ($$$-n < q_i < n$$$). | ["3 1 2", "1 2 3 4 5", "-1"] | #include <stdio.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
typedef long long i64;
i64 min(i64 a, i64 b) {
return a < b ? a : b;
}
i64 max(i64 a, i64 b) {
return a > b ? a : b;
}
i64 minimum(i64* a, int n) {
i64 m = LLONG_MAX;
while(n-- > 0)
m = min(m, *a++);
return m;
}
i64 maximum(i64* a, int n) {
i64 m = LLONG_MIN;
while(n-- > 0)
m = max(m, *a++);
return m;
}
void copy(i64* p, int* a, int n) {
while(n-- > 0)
*p++ = *a++;
}
void prefixsum(i64* p, int* a, int n) {
copy(p, a, n--);
while(n-- > 0)
*p += *p++;
}
void increment(i64* p, int n, i64 m) {
while(n-- > 0)
*p++ += m;
}
bool isperm(i64* p, int n) {
int *c = (int*)calloc(n + 1, sizeof(int));
if(minimum(p, n) < 1 || maximum(p, n) > n)
return false;
while(n-- > 0 && c[*p++]++ == 0);
free(c);
return n < 0;
}
bool solve(i64* p, int* a, int n) {
prefixsum(p, a, n);
increment(p, n, 1 - minimum(p, n));
return isperm(p, n);
}
void rd(int* a, int n) {
while(n-- > 0)
scanf("%d", a++);
}
void pr(i64* p, int n) {
while(n-- > 0)
printf("%lld ", *p++);
}
int main(void) {
int n;
scanf("%d", &n);
int* a = (int*)calloc(n, sizeof(int));
i64* p = (i64*)calloc(n, sizeof(i64));
rd(a + 1, n - 1);
if(solve(p, a, n))
pr(p, n);
else
puts("-1");
free(a);
free(p);
return 0;
} | |
An array of integers $$$p_1, p_2, \dots, p_n$$$ is called a permutation if it contains each number from $$$1$$$ to $$$n$$$ exactly once. For example, the following arrays are permutations: $$$[3, 1, 2]$$$, $$$[1]$$$, $$$[1, 2, 3, 4, 5]$$$ and $$$[4, 3, 1, 2]$$$. The following arrays are not permutations: $$$[2]$$$, $$$[1, 1]$$$, $$$[2, 3, 4]$$$.Polycarp invented a really cool permutation $$$p_1, p_2, \dots, p_n$$$ of length $$$n$$$. It is very disappointing, but he forgot this permutation. He only remembers the array $$$q_1, q_2, \dots, q_{n-1}$$$ of length $$$n-1$$$, where $$$q_i=p_{i+1}-p_i$$$.Given $$$n$$$ and $$$q=q_1, q_2, \dots, q_{n-1}$$$, help Polycarp restore the invented permutation. | Print the integer -1 if there is no such permutation of length $$$n$$$ which corresponds to the given array $$$q$$$. Otherwise, if it exists, print $$$p_1, p_2, \dots, p_n$$$. Print any such permutation if there are many of them. | C | b6ac7c30b7efdc7206dbbad5cfb86db7 | da3f04d8264b7e17d13a4582188bf4d4 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1553006100 | ["3\n-2 1", "5\n1 1 1 1", "4\n-1 2 2"] | null | PASSED | 1,500 | standard input | 2 seconds | The first line contains the integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) — the length of the permutation to restore. The second line contains $$$n-1$$$ integers $$$q_1, q_2, \dots, q_{n-1}$$$ ($$$-n < q_i < n$$$). | ["3 1 2", "1 2 3 4 5", "-1"] | #include <stdio.h>
#include <stdlib.h>
int com(const void *a, const void *b)
{
return (*(int *)a - *(int *)b);
}
int main()
{
int n, m, i;
scanf("%d", &n);
int p[n], q[n-1], v[n];
p[0]=2;
for(i=0; i<(n-1); i++){
scanf("%d", &q[i]);
p[i+1]=q[i]+p[i];
}
for(i=0; i<n; i++){
v[i]=p[i];
}
qsort(p, n, 4, com);
m=p[0]-1;
for(i=1; i<n;){
if(p[i]==p[i-1]+1){
i++;
continue;
}
break;
}
if(i==n){
for(i=0; i<n; i++){
printf("%d ", v[i]-m);
}
printf("\n");
return 0;
}
if(i!=n){
printf("-1\n");
}
return 0;
}
| |
Vasya owns three big integers — $$$a, l, r$$$. Let's define a partition of $$$x$$$ such a sequence of strings $$$s_1, s_2, \dots, s_k$$$ that $$$s_1 + s_2 + \dots + s_k = x$$$, where $$$+$$$ is a concatanation of strings. $$$s_i$$$ is the $$$i$$$-th element of the partition. For example, number $$$12345$$$ has the following partitions: ["1", "2", "3", "4", "5"], ["123", "4", "5"], ["1", "2345"], ["12345"] and lots of others.Let's call some partition of $$$a$$$ beautiful if each of its elements contains no leading zeros.Vasya want to know the number of beautiful partitions of number $$$a$$$, which has each of $$$s_i$$$ satisfy the condition $$$l \le s_i \le r$$$. Note that the comparison is the integer comparison, not the string one.Help Vasya to count the amount of partitions of number $$$a$$$ such that they match all the given requirements. The result can be rather big, so print it modulo $$$998244353$$$. | Print a single integer — the amount of partitions of number $$$a$$$ such that they match all the given requirements modulo $$$998244353$$$. | C | 0d212ea4fc9f03fdd682289fca9b517e | 164465db3c1b11861cac17b14b8712b7 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"hashing",
"data structures",
"binary search",
"strings"
] | 1537454700 | ["135\n1\n15", "10000\n0\n9"] | NoteIn the first test case, there are two good partitions $$$13+5$$$ and $$$1+3+5$$$.In the second test case, there is one good partition $$$1+0+0+0+0$$$. | PASSED | 2,600 | standard input | 1 second | The first line contains a single integer $$$a~(1 \le a \le 10^{1000000})$$$. The second line contains a single integer $$$l~(0 \le l \le 10^{1000000})$$$. The third line contains a single integer $$$r~(0 \le r \le 10^{1000000})$$$. It is guaranteed that $$$l \le r$$$. It is also guaranteed that numbers $$$a, l, r$$$ contain no leading zeros. | ["2", "1"] | /* practice with Dukkha */
#include <stdio.h>
#include <string.h>
#define N 1000001
#define MD 998244353
int min(int a, int b) { return a < b ? a : b; }
void zzz(char *cc, int n, int *zz) {
int i, l, r;
for (i = 1, l = r = 0; i < n; i++)
if (i + zz[i - l] < r)
zz[i] = zz[i - l];
else {
l = i;
if (r < l)
r = l;
while (r < n && cc[r] == cc[r - l])
r++;
zz[i] = r - l;
}
}
void solve(char *aa, int n, char *bb, int m, int *zz) {
static int zz_[N + N];
static char cc[N + N + 1];
int i, j;
for (i = 0; i < n; i++)
cc[i] = aa[i];
for (j = 0; j < m; j++)
cc[n + j] = bb[j];
zzz(cc, n + m, zz_);
for (j = 0; j < m; j++)
zz[j] = zz_[n + j];
}
int main() {
static char aa[N + 1], ll[N + 1], rr[N + 1];
static int zl[N], zr[N], dd[N + 2];
int n, nl, nr, i, zero, dp;
scanf("%s%s%s", aa, ll, rr);
n = strlen(aa), nl = strlen(ll), nr = strlen(rr);
zero = nl == 1 && ll[0] == '0';
solve(ll, nl, aa, n, zl);
solve(rr, nr, aa, n, zr);
dd[0] = 1;
dd[1] = -1;
dp = 0;
for (i = 0; i <= n; i++) {
dp = (dp + dd[i]) % MD;
if (i == n) {
if (dp < 0)
dp += MD;
printf("%d\n", dp);
return 0;
}
if (aa[i] == '0') {
if (zero) {
dd[i + 1] = (dd[i + 1] + dp) % MD;
dd[i + 2] = (dd[i + 2] - dp) % MD;
}
} else {
int j, l = nl, r = nr;
j = min(zl[i], nl - 1);
if (i + j < n && aa[i + j] < ll[j])
l++;
j = min(zr[i], nr - 1);
if (i + j < n && aa[i + j] > rr[j])
r--;
if (l <= r)
if (i + l <= n) {
dd[i + l] = (dd[i + l] + dp) % MD;
if (i + r + 1 <= n)
dd[i + r + 1] = (dd[i + r + 1] - dp) % MD;
}
}
}
return 0;
}
| |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | e724c7f28fbeadd9b5c5811b54608d00 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include<stdio.h>
//#include<conio.h>
int main()
{
int n,m,mid,i,temp1,temp2,found=0,j,count=0,ans=0;
int str[105][105];
// printf("enter the value of n and m:");
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
scanf("%d",&str[i][j]);
}
ans=n;
if(n%2==1)
mid=n;
else
{
do
{
mid=ans/2;
temp1=mid;
temp2=mid+1;
for(i=1;i<=mid && found==0 && mid>0;i++)
{
count=0;
for(j=1;j<=m;j++)
{
if(str[temp1][j]==str[temp2][j])
{
count++;
// printf("count=%d\n",count);
}
}
if(count==m)
{
temp1--;
temp2++;
}
else
found=1;
}
if(found==0 && mid>0)
{
// printf("it comes here\n");
ans=mid;
}
if(ans%2==1)
break;
}while(found<=0 && mid>=1);
}
printf("%d",ans);
// getch();
// clrscr();
return 0;
} | |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | d30e3382c21e7d27b09a7c1d6ef3176c | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include<stdio.h>
int main(){
int i,j,n,m,a[100][100],ans;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++){
for(j=0;j<m;j++){
scanf("%d",&a[i][j]);
}
}
while(n>0){
ans=n;
if(n%2==0){
for(i=n/2;i<n;i++){
for(j=0;j<m;j++){
if(a[i][j]!=a[n-i-1][j]){
goto z;
}
}
}
}
else
{
break;
}
n=n/2;
}
z:
printf("%d",ans);
return 0;
} | |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 089bdd13539a0b55156633f76b2b68d2 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include<stdio.h>
int main()
{
int n,m;
scanf("%d %d",&n,&m);
int i,j,arr[105][105];
for(i=0;i<n;++i)
{
for(j=0;j<m;++j)
{
scanf("%d",&arr[i][j]);
}
}
if(n%2==1)
printf("%d",n);
else
{
int prev=1;
int ch=0;
int div=2;
while(ch==0 && div<=n)
{
int i2=n/div;
i=i2-1;
while(i>=0)
{
for(j=0;j<m;++j)
{
if(arr[i][j]!=arr[i2][j])
{
ch=1;
// printf("a");
break;
}
}
--i;
++i2;
if(ch==1)
break;
}
if(ch==0)
{
prev=div;
div=div*2;
if(n%div==0)
;
else
{
ch=1;
break;
}
}
else
{
break;
}
}
printf("%d",n/prev);
}
return 0;
}
| |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | f01f468746f888b7cc8cfcf0fac7a576 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
int main(void)
{
int n,m,matrix[102][102],min=0,i,j,k;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
scanf("%d",&matrix[i][j]);
}
min=n;
if(n%2==1){
printf("%d",n);
return 0;
}
i=n/2;
j=(n/2)+1;
while(n>1)
{
while(i>0&&j<=n)
{
for(k=1;k<=m&&i>0&&j<=n;k++)
{
if(matrix[i][k]!=matrix[j][k])
{
printf("%d",min);
return 0;
}
}
i--;
j++; }
min=n/2;
n=n/2;
i=n/2;
j=n/2+1;
if(n%2==1)
{
printf("%d",min);
return 0;
}
}
return 0;
}
| |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 5350a8c13d7f88ba522442bc0218fa3f | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#define MAXN 1005
#define N 205
#define INF 1<<30
#define eps 1.0e-10
#define For(i,m,n) for(i=(m);i<n;i++)
#define MAX(x,y) (x)>(y)?(x):(y)
#define MIN(x,y) (x)<(y)?(x):(y)
int a[N][N], n, m;
int judge(int t)
{
int i, j, k;
For(k,0,n/t){For(i,0,t) For(j,0,m){
if(k%2==0)
{
if(a[k*t+i][j]!=a[k*t+2*t-i-1][j]||(k*t+2*t+i<n&&a[k*t+2*t-i-1][j]!=a[k*t+2*t+i][j]))return 0;
}
else{
if(a[k*t-i-1][j]!=a[k*t+i][j]||(k*t+2*t+i<n&&a[k*t+2*t-i-1][j]!=a[k*t+i][j]))return 0;
}
}
}
return 1;
}
main()
{
int i, j, x, t, ans=1, flag, cnt=1, tmp;
scanf("%d%d",&n,&m);
For(i,0,n) For(j,0,m) scanf("%d",&a[i][j]);
if(n%2){
printf("%d\n",n);
exit(0);
}
ans=n/2, tmp=n;
while(1){
if(judge(ans)){
tmp=ans;
}
if(ans%2){
printf("%d\n",tmp); break;
}
else ans/=2;
}
return 0;
}
| |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 1540fca066f6fb8b02e72193374f765e | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int ma[110][110];
bool equals(int a,int b,int length)
{
int j;
for (j=1;j<=length;j++)
{
if (ma[a][j] != ma[b][j])
{
return false;
} else {
if (j==length) return true;
}
}
return false;
}
int main()
{
int n,m,j,i,max=0;
scanf("%d%d",&n,&m);
for (j=1;j<=n;j++)
{
for(i=1;i<=m;i++)
{
scanf("%d",&ma[j][i]);
}
}
max = n;
if (max % 2)
{
printf("%d\n",max);
}
while (max % 2==0)
{
for(j=1;j<=max/2;j++)
{
if (!equals(j,max-j+1,m))
{
printf("%d\n",max);
return 0;
}
}
max /= 2;
if (max % 2)
{
printf("%d\n",max);
}
}
return 0;
}
| |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 5b2a084c8a788ab4f985c72ef164b343 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
#define maxlen 105
int N;
int check(int s,int e,int col,int mx[][maxlen])
{
int upi,downi,j,ok=0;
if(e&1) return N;
upi=(s+e)/2,downi=upi+1;
while(upi>=1)
{
for(j=1;j<=col;j++)
if(mx[upi][j]!=mx[downi][j]) {ok=1;break;}
if(ok) break;
upi--,downi++;
}
//printf("j=%d upi=%d\n",j,upi);
if(!ok)
if(e%2==1) return N/2;
else return check(s,(s+e)/2,col,mx)/2;
//printf("s=%d e=%d",s,e);
return N;
}
int main()
{
int n,m,mx[maxlen][maxlen],i,j,res;
//freopen("C:\\Users\\Shen\\Desktop\\in.txt","r",stdin);
while(~scanf("%d%d",&n,&m))
{
N=n;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++) scanf("%d",&mx[i][j]);
if(n&1) printf("%d\n",n);
else
{
res=check(1,n,m,mx);
printf("%d\n",res);
}
}
return 0;
}
| |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 3605a548477cede2fcba276b15232ff2 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
int main(int argc, char *argv[])
{
int n, m, a[100][100] = {}, num;
int i, j, l;
scanf("%d%d", &n, &m);
num = n;
for(i = 0; i < n; i++)
for( j = 0; j < m; j++)
scanf("%d", &a[i][j]);
for(;num > 1; )
{
if(num%2 == 1)
{
printf("%d\n", num);
return 0;
}
for(j = 0; j < num/2; j++)
for(l = 0; l < m; l++)
if(a[j][l] != a[num-j-1][l])
{
printf("%d\n", num);
return 0;
}
num /= 2;
}
printf("%d\n", num);
return 0;
}
| |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | ee8c3083baa309ef00b6c94fcce40d0e | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
char str[100+1][10000+10];
int main()
{
int n,k;
scanf("%d%d",&n,&k);
getchar();
int i,j;
for(i=0;i<n;i++)
gets(str[i]);
if(n&1)
printf("%d",n);
else
{
int rows = n;
int flag = 0;
for(i=0;!(rows&1);i++)
{
for(j=0;j<rows/2;j++)
{
if(strcmp(str[j],str[(rows)-j-1])!=0)
flag = 1;
}
if(!flag)
rows /=2;
else
break;
}
printf("%d",rows);
}
return 0;
}
| |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 361c87640a7b7d60e2b8bd83ecd7d0e0 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include<stdio.h>
int A[105][105];
int divide(int n, int m)
{
if(n == 1)
return n;
if(n%2 != 0)
return n;
int i,j,flag;
for(i=n/2;i<n;++i)
{
flag = 1;
for(j=0;j<m;++j)
{
if(A[i][j] != A[n-i-1][j])
{
flag = 0;
break;
}
}
if(flag == 0)
break;
}
if(flag == 0)
return n;
else
return divide(n/2, m);
}
int main()
{
int n,m,i,j;
scanf("%d%d",&n,&m);
for(i=0;i<n;++i)
for(j=0;j<m;++j)
scanf("%d",&A[i][j]);
if(n%2 != 0)
printf("%d\n",n);
else
printf("%d\n",divide(n, m));
return 0;
}
| |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 41db76f8bea9ef0d0e0b6cf0085a04cb | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
#include <math.h>
int main(void)
{
int n, m, i, j, k;
scanf("%d %d", &n, &m);
if( n % 2 != 0) {
printf("%d", n);
return 0;
}
int numbers[100][100];
for(i = 0; i < n; i++)
{
for(j = 0; j < m; j++)
{
scanf("%d", &numbers[i][j]);
}
}
int max = n / 2;
int row = 0;
for(i = 1; i <= max; i++)
{
if((n / (int)pow(2, i - 1)) % 2 != 0) break;
for(j = 0; j < n / (int)pow(2, i); j++)
{
for(k = 0; k < m; k++)
{
if(numbers[j][k] != numbers[(n / (int)pow(2, i - 1)) - 1 - j][k]){
printf("%d", n / (int)pow(2, i - 1));
return 0;
}
}
}
}
printf("%d", n / (int)pow(2, i - 1));;
return 0;
}
| |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | c97f2e970988800ce26837a61d2a6029 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
#include <math.h>
int main(void)
{
int n, m, i, j, k;
int numbers[100][100];
scanf("%d %d", &n, &m);
for(i = 0; i < n; i++)
{
for(j = 0; j < m; j++)
{
scanf("%d", &numbers[i][j]);
}
}
int max = n / 2;
int row = 0;
for(i = 1; i <= max; i++)
{
if((n / (int)pow(2, i - 1)) % 2 != 0) break;
for(j = 0; j < n / (int)pow(2, i); j++)
{
for(k = 0; k < m; k++)
{
if(numbers[j][k] != numbers[(n / (int)pow(2, i - 1)) - 1 - j][k]){
printf("%d", n / (int)pow(2, i - 1));
return 0;
}
}
}
}
printf("%d", n / (int)pow(2, i - 1));;
return 0;
}
| |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | a85934f15a94f76329d43b582cea7b51 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include<stdio.h>
#include<math.h>
int main()
{
int n,i,j,m,k,pass,count,A[101][101];
int temp,count_col;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
scanf("%d",&A[i][j]);
}
pass=0;
count=0;
temp=(int)(log(n)/log(2));
// printf("%d temp\n",temp);
if(n%2==0)
{
while(pass<=temp)
{
i=0;
j=(int)(n/pow(2,pass))-1;
// printf("%d j\n",j);
count=0;
while(count!=(int)(n/pow(2,pass+1)))
{
// printf("%d A[i][0] %d A[j][0]\n",A[i][0],A[j][0]);
/*if(A[i][0]==A[j][0])
{
i++;
j--;
count++;
// printf("%d count\n",count);
} */
count_col=0;
for(k=0;k<m;k++)
{
if(A[i][k]==A[j][k])
count_col++;
else
break;
}
if(count_col==m)
{
i++;
j--;
count++;
}
else
break;
}
// printf("%d count\n",count);
if(count==(n/pow(2,pass+1)))
pass++;
else
break;
}
printf("%d\n",(int)(n/(pow(2,pass))));
}
else
printf("%d\n",n);
//printf("%d\n",pass);
return 0;
}
| |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 6645079925745d13dca5c8a901e9476a | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <stdlib.h>
int main(void){
long n, m, a[101][101],
i, j, nn, ans, ii;
scanf("%d %d", &n, &m);
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
scanf("%d", &a[i][j]);
ans = n;
nn = n;
while (nn % 2 == 0){
ii = nn - 1;
nn /= 2;
for (i = 0; i < nn; i++){
for (j = 0; j < m; j++)
if (a[i][j] != a[ii][j]){
printf("%d", ans);
return(0);
}
ii--;
}
ans = nn;
}
printf("%d", ans);
return(0);
}
| |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | ab5860d8c4ca896b571610fb40b67a43 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include<stdio.h>
/*int compare(int** array, int index, int n,int m)
{
int x,y,z;
for(x=index-1,y=index;x>=0;x--,y++)
{
for( z=0;z<m;z++)
{
if(array[x][z]!= array[y][z])
{
return 0;
}
}
}
return 1;
}
*/
int main()
{
int n,m,flag=0;
scanf("%d %d",&n,&m);
int array[n][m],i,j;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&array[i][j]);
}
}
int count =n;
if( (n%2)!=0 )
printf("%d\n",n);
else
{
int k;
int index = n;
while(index >= 1 && index%2 == 0)
{
index = index/2;
int x,y,z;
k = 1;
for(x=index-1,y=index;x>=0;x--,y++)
{
for( z=0;z<m;z++)
{
if(array[x][z]!= array[y][z])
{
k=0;
break;
}
}
if(k==0)
break;
}
if(k==1)
{
count = index;
//printf("%d\n",count);
}
else
{
//flag =1;
break;
}
}
printf("%d",count);
}
return 0;
}
| |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 2c6cc7ad4dd2cd0ea0c913874ec242e4 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
int find(int x,int y,int *a,int col){
int i,j,k;
for(i=x; i>0;){
int flag=1;
for(j=1;flag&&j*i<x;j++){
if(j%2==0)
for(k=0;k<i;k++){
if(a[j*i+k]!=a[k]){
flag=0;
break;
}
}
if(j%2==1)
for(k=0;k<i;k++){
if(a[j*i+k]!=a[i-1-k]){
flag=0;
break;
}
}
}
if(!flag)
return i*2;
if(i%2==0)
i/=2;
else
return i;
}
return i;
}
int main(){
int x,y,i,j;
scanf("%d%d",&x,&y);
int a[x][y];
for(i=0;i<x;i++){
for(j=0;j<y;j++){
scanf("%d",&a[i][j]);
}
}
int max=-1;
for(i=0;i<y;i++){
int b[x];
for(j=0;j<x;j++)
b[j]=a[j][i];
int temp=find(x,y,b,i);
if(temp>max)
max=temp;
}
printf("%d",max);
return 0;
}
| |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 881d9083c24937231b9a0c127aeb49a7 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | /*
* =====================================================================================
*
* Filename: sm.cpp
*
* Description: j
*
* Version: 1.0
* Created: Friday, May 09, 2014 09:39:11 HKT
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
#include <stdlib.h>
#include <stdio.h>
#define false 0
#define true 1
typedef int bool;
bool is_mirror(int** matrix, int a, int b, int row_num, int col_num){
int i;
int j;
int *ap;
int *bp;
bool is_m = true;
for (i = 0; i < row_num; i++)
{
for (j = 0; j < col_num; j++)
{
ap = matrix[a+i];
bp = matrix[b+row_num - 1 - i];
if(ap[j] != bp[j]){
is_m = false;
}
}
}
return is_m;
}
int find_min_matrix(int** matrix, int row_num, int col_num){
if( row_num % 2 == 0)
{
bool b = is_mirror(matrix,0, row_num / 2, row_num / 2, col_num);
if(b)
{
return find_min_matrix(matrix, row_num / 2, col_num);
}
}
return row_num;
}
int main(){
int row_num;
int col_num;
scanf("%d", &row_num);
scanf("%d", &col_num);
int** matrix;
matrix = (int**)malloc(sizeof(int*)*row_num);
int i , j;
for(i = 0; i < row_num; i++)
{
matrix[i] = (int*)malloc(sizeof(int)*col_num);
}
for( i = 0; i < row_num; i++)
{
for( j = 0; j < col_num; j++)
{
scanf("%d",&matrix[i][j]);
}
}
int n = find_min_matrix(matrix, row_num, col_num);
printf("%d\n", n);
return 0;
}
| |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | f5abd0c37fea68a0199b9c0966bcb2d7 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include<stdio.h>
int main()
{
int n,m,a[101][101],i,j,ch,flag,flag1,ans;
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
scanf("%d",&a[i][j]);
}
}
if(n%2==1)
printf("%d",n);
else
{
flag=1;
ch=n;
while(flag)
{
for(i=1;i<=ch/2;i++)
{
flag1=1;
for(j=1;j<=m;j++)
{
if(a[i][j]!=a[ch-i+1][j])
{
flag1=0;
break;
}
}
if(flag1==0)
{
flag=0;
break;
}
}
if(flag1==0)
{
flag=0;
ans=ch;
}
else if(flag1==1)
{
ans=ch/2;
ch=ch/2;
if(ch%2==1)
flag=0;
}
else
continue;
}
printf("%d",ans);
}
return 0;
} | |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 5959e159c21656cad48b5dbc12574824 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
int map[101][101] = {0}, m, n;
int is_symmetric(int row){
int i, j;
// if(row%2 == 1)return 0;
for(i=0; i<row/2; i++){
for(j=0; j<m; j++){
if(map[i][j] != map[row-i-1][j])return 0;
}
}
return 1;
}
int main(){
int i, j, ans = 0;
scanf("%d %d", &n, &m);
for(i=0; i<n; i++)
for(j=0; j<m; j++)
scanf("%d", &map[i][j]);
while(n%2 == 0 && is_symmetric(n))n/=2;;
printf("%d\n",n);
return 0;
}
| |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 3b8737b55b2fdaf4eebad5576bd712be | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include<stdio.h>
#define SZ 128
int v[SZ][SZ], n, m;
int solve(int[][SZ], int);
int main(void) {
int i, j;
scanf("%d%d", &n, &m);
for(i=0; i<n; ++i) {
for(j=0; j<m; ++j) scanf("%d", &v[i][j]);
}
printf("%d\n", n>>solve(v, n));
return 0;
}
int check(int i, int j) {
int k;
for(k=0; k<m; ++k)
if(v[i][k] != v[j][k]) return 0;
return 1;
}
int solve(int v[][SZ], int n) {
int i, j, ret=0;
if(n&01) return 0;
for(i=0, j=n-1; i<j; ++i, --j)
if(!check(i, j)) return 0;
return 1+solve(v, n/2);
}
| |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | 660fc051b7b5aad8455b48e0da63a32e | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
#define MAX 100
int filaNI(int a[MAX], int b[MAX], int m)
{
int i;
for (i = 0; i < m; ++i)
{
if (a[i]!=b[i])
{
return 1;
}
}
return 0;
}
int rec(int a[MAX][MAX], int n, int m)
{
int p,i;
if (n%2==0)
{
p = n/2;
for (i = 0; i < p; ++i)
{
if (filaNI(a[i],a[n-i-1],m))
{
return n;
}
}
return rec(a,p,m);
}
return n;
}
int main(int argc, char const *argv[])
{
int i,j,n,m;
scanf("%d %d",&n,&m);
int a[MAX][MAX];
for (i = 0; i < n; ++i)
{
for (j = 0; j < m; ++j)
{
scanf("%d",&a[i][j]);
}
}
printf("%d\n",rec(a,n,m));
return 0;
} | |
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; the lower half of matrix c (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1). Sereja has an n × m matrix a. He wants to find such matrix b, that it can be transformed into matrix a, if we'll perform on it several (possibly zero) mirrorings. What minimum number of rows can such matrix contain? | In the single line, print the answer to the problem — the minimum number of rows of matrix b. | C | 90125e9d42c6dcb0bf3b2b5e4d0f845e | bca75b057596840607eaf988dd3762ea | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1398612600 | ["4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "3 3\n0 0 0\n0 0 0\n0 0 0", "8 1\n0\n1\n1\n0\n0\n1\n1\n0"] | NoteIn the first test sample the answer is a 2 × 3 matrix b:001110If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:001110110001 | PASSED | 1,300 | standard input | 1 second | The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a. | ["2", "3", "2"] | #include <stdio.h>
int main()
{
int i,j,n,k,x,y,h,z,flag=0,count=0,flag2=0;
scanf("%d %d", &n, &k);
int a[n][k];
for(i=0;i<n;i++)
{
for(j=0;j<k;j++)
scanf("%d", &a[i][j]);
}
h=n;
if(h%2==1)
printf("%d", h);
else
{
for(i=0,j=h-1; i<h/2; i++,j--)
{
for(x=0;x<k;x++)
{
if(a[i][x]!=a[j][x])
{
flag=1;
break;
}
}
if(flag==0)
count++;
else
break;
}
if(flag==1)
printf("%d", h);
else
{
while(count%2==0 && count==h/2)
{
flag2=0;
h=count;
count=0;
for(i=0,j=h-1; i<h/2; i++,j--)
{
for(x=0;x<k;x++)
{
if(a[i][x]!=a[j][x])
{
flag2=1;
break;
}
}
if(flag2==0)
count++;
else
break;
}
}
if(flag2==1)
printf("%d", h);
else
printf("%d", count);
}
}
return 0;
}
| |
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower). | C | 933135ef124b35028c1f309d69515e44 | f6d01cc2dff2c11610c7a5cca4ff9860 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1501425300 | ["6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000"] | NoteFirst game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | PASSED | 1,700 | standard input | 1 second | In the first string, the number of games n (1 ≤ n ≤ 350000) is given. Each game is represented by a pair of scores a, b (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly. | ["Yes\nYes\nYes\nNo\nNo\nYes"] | #include<stdio.h>
#include<math.h>
int gcd(int a,int b)
{
int c;
while(a%b!=0)
{
c=b;
b=a%b;
a=c;
}
return b;
}
int main()
{
int M,n,i,j,k,a,b,condition,gc,gcd_a,gcd_b;
long long int cubic_root,cube;
scanf("%d",&n);
for(k=1;k<=n;k++)
{
condition=1;
scanf("%d %d",&a,&b);
gcd_a=a;
gcd_b=b;
gc=gcd(a,b);
cube=a;
cube=cube*b;
cubic_root=(long long int) cbrtf(cube);
//printf("Cubic root is %I64d\n",cubic_root);
gcd_a=gcd_a/gcd(gc,gcd_a);
gcd_a=gcd_a/gcd(gc,gcd_a);
gcd_b=gcd_b/gcd(gc,gcd_b);
gcd_b=gcd_b/gcd(gc,gcd_b);
if(cubic_root*cubic_root*cubic_root!=cube||gcd_a!=1||gcd_b!=1) condition=0;
if(condition) printf("Yes\n");
else printf("No\n");
}
return 0;
}
| |
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower). | C | 933135ef124b35028c1f309d69515e44 | 887054aa1695921a2656f1eac3a4f328 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1501425300 | ["6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000"] | NoteFirst game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | PASSED | 1,700 | standard input | 1 second | In the first string, the number of games n (1 ≤ n ≤ 350000) is given. Each game is represented by a pair of scores a, b (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly. | ["Yes\nYes\nYes\nNo\nNo\nYes"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <string.h>
int main(int argc, char const *argv[])
{
int n;
scanf("%d",&n);
while(n--){
int flag=0;
long long a,b;
scanf("%I64d %I64d",&a,&b);
long long x=a*b;
long long l=1,r=1000000,m;
m=(l+r)/2;
for(int i=0;i<25;i=i+1){
if(m*m*m==x){
//printf("%I64d\n",m);
long long k1=a/m;
long long k2=b/m;
if(a==k1*m&&b==k2*m){
flag=1;
}
break;
}else if(m*m*m>x){
r=m-1;
}else{
l=m+1;
}
m=(l+r)/2;
}
if(flag==1){
printf("Yes\n");
}else{
printf("No\n");
}
}
return 0;
} | |
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower). | C | 933135ef124b35028c1f309d69515e44 | 13b7d3c7da8aecbec4c0939ccfb0da0c | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1501425300 | ["6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000"] | NoteFirst game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | PASSED | 1,700 | standard input | 1 second | In the first string, the number of games n (1 ≤ n ≤ 350000) is given. Each game is represented by a pair of scores a, b (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly. | ["Yes\nYes\nYes\nNo\nNo\nYes"] | #include <stdio.h>
int s[1001];
int get(int n)
{
int lo = 1;
int hi = 1000;
int mid;
while(lo <=hi)
{
mid = (lo + hi)/2;
if(s[mid]==n)return 1;
if(s[mid]<n)lo= mid + 1;
else hi = mid - 1;
}
return 0;
}
int gcd(int a, int b)
{
int t;
while(a%b)
{
t=a%b;a=b;b=t;
}
return b;
}
int main()
{
int n,m,a,b,g;
for(n=1;n<=1000;n++)
s[n] = n*n*n;
int t;
scanf("%d",&t);
// t = 350000;
while(t--)
{
scanf("%d%d",&a,&b);
// printf("%d %d\n",a,b);
// a = 1000000000;
// b= 1000000;
g = gcd(a,b);
a/=g;
b/=g;
int valid = 0;
if( g%a==0 )
{
g = g/a;
if(g%b==0)
{
g/=b;
// printf("valid of %d\n",g);
valid = get(g);
}
}
if(valid)printf("Yes\n");
else printf("No\n");
}
} | |
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower). | C | 933135ef124b35028c1f309d69515e44 | 12719ed035a877b5ce9c6354369f412d | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1501425300 | ["6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000"] | NoteFirst game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | PASSED | 1,700 | standard input | 1 second | In the first string, the number of games n (1 ≤ n ≤ 350000) is given. Each game is represented by a pair of scores a, b (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly. | ["Yes\nYes\nYes\nNo\nNo\nYes"] | #include <stdio.h>
#include <math.h>
int main () {
int n;
int i;
(void) scanf ("%d", &n);
for (i = 0; i < n; i++) {
int A, B;
int ab, a, b;
(void) scanf ("%d%d", &A, &B);
ab = (int) round (cbrtl ((long double) A * B));
a = A / ab;
b = B / ab;
if (A % ab == 0 && B % ab == 0 && a * b == ab) printf ("Yes\n");
else printf ("No\n");
}
return 0;
}
| |
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower). | C | 933135ef124b35028c1f309d69515e44 | 15fb248b1d8cad2bd0be0b6b93199b86 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1501425300 | ["6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000"] | NoteFirst game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | PASSED | 1,700 | standard input | 1 second | In the first string, the number of games n (1 ≤ n ≤ 350000) is given. Each game is represented by a pair of scores a, b (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly. | ["Yes\nYes\nYes\nNo\nNo\nYes"] | #include <stdio.h>
#include <math.h>
#include <stdio.h>
int main()
{
int i, n;
long long n1, n2, n3, t1, t2, t;
scanf("%d",&n);
for (i = 1; i <= n; i++){
scanf("%lld",&n1);
scanf("%lld",&n2);
t1 = n1 % 2;
t2 = n2 % 2;
if (n1 + n2 == 1){
printf("No\n");
continue;
}
n3 = n1*n2;
t = round(pow(n3, 1.0/3));
if (n3 - t*t*t != 0){
printf("No\n");
continue;
}
if (t%(n1/t) == 0 && t%(n2/t) == 0)
printf("Yes\n");
else{
printf("No\n");
}
}
return 0;
} | |
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower). | C | 933135ef124b35028c1f309d69515e44 | c75e702ade03a1189d9ddc8d7ac1126c | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1501425300 | ["6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000"] | NoteFirst game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | PASSED | 1,700 | standard input | 1 second | In the first string, the number of games n (1 ≤ n ≤ 350000) is given. Each game is represented by a pair of scores a, b (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly. | ["Yes\nYes\nYes\nNo\nNo\nYes"] | #include <stdio.h>
#include <stdlib.h>
#define MAXPOSS 1000
int main()
{
int primes[MAXPOSS];
int counted[MAXPOSS+1];
int i,j,k,n,a,b,p,prime,aDiv,bDiv,possible,nPrimes;
for(i=0;i<=MAXPOSS;i++) {
counted[i]=0;
}
j=0;
for(i=2;i<MAXPOSS;i++) {
if(counted[i]==0) {
primes[j] = i;
j+=1;
k = i;
while(k*i<=MAXPOSS) {
counted[k*i]=1;
k+=1;
}
}
}
nPrimes=j;
scanf("%d",&n);
for(i=0;i<n;i++) {
scanf("%d %d",&a,&b);
p=0;
prime = primes[p];
possible=1;
while(prime<=a && prime<=b && possible==1) {
aDiv = 0;
bDiv = 0;
while(a%prime==0) {
aDiv+=1;
a/=prime;
}
while(b%prime==0) {
bDiv+=1;
b=b/prime;
}
p+=1;
if(p==nPrimes) {
prime = 1000000000+1;}
else {
prime = primes[p];}
if(aDiv==0 && bDiv==0) {
continue;}
else if(!((aDiv+bDiv)%3==0 && 2*aDiv>=bDiv && 2*bDiv>=aDiv)) {
possible=0;}
}
if((a*a==b || b*b==a) && possible==1) {
printf("Yes\n");}
else {
printf("No\n");}
}
return 0;
}
| |
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower). | C | 933135ef124b35028c1f309d69515e44 | c01f4fc1f481a93192adfa3e2a2f3e87 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1501425300 | ["6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000"] | NoteFirst game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | PASSED | 1,700 | standard input | 1 second | In the first string, the number of games n (1 ≤ n ≤ 350000) is given. Each game is represented by a pair of scores a, b (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly. | ["Yes\nYes\nYes\nNo\nNo\nYes"] | #include <math.h>
#include <stdio.h>
/* http://codeforces.com/contest/834/submission/29026742 (Dukkha) */
int check(int a, int b, int d) {
int p, q, r, s;
p = 0;
while (a % d == 0) {
p++;
a /= d;
}
q = 0;
while (b % d == 0) {
q++;
b /= d;
}
r = (p + q) / 3;
s = p - q + r;
return s >= 0 && s % 2 == 0 && s / 2 <= r;
}
int main() {
int n;
scanf("%d", &n);
while (n-- > 0) {
int a, b, c, d, yes;
long long ab;
scanf("%d%d", &a, &b);
ab = (long long) a * b;
c = (int) round(cbrt(ab));
yes = 1;
if ((long long) c * c * c != ab)
yes = 0;
else {
for (d = 2; d * d <= c; d++)
if (c % d == 0) {
if (!check(a, b, d)) {
yes = 0;
break;
}
while (c % d == 0)
c /= d;
}
if (yes && c > 1 && !check(a, b, c))
yes = 0;
}
printf(yes ? "Yes\n" : "No\n");
}
return 0;
}
| |
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower). | C | 933135ef124b35028c1f309d69515e44 | fe6c622a6197c7b703b557b1166edca0 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1501425300 | ["6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000"] | NoteFirst game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | PASSED | 1,700 | standard input | 1 second | In the first string, the number of games n (1 ≤ n ≤ 350000) is given. Each game is represented by a pair of scores a, b (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly. | ["Yes\nYes\nYes\nNo\nNo\nYes"] | #include <stdio.h>
int main ()
{
int t, i;
scanf("%d", &t);
for(i = 0; i < t; i++)
{
long long a, b, j, x, ans = -1, mid, lo = 0, hi = 1000000;
scanf("%lld %lld", &a, &b);
while(lo <= hi)
{
mid = (lo + hi) / 2;
x = mid * mid * mid;
if(x == a * b){
ans = mid;
break;
}
else if(x < a * b)
lo = mid + 1;
else if(x > a * b)
hi = mid - 1;
}
//printf("%d", a % ans);
if(a % ans != 0 || b % ans != 0)
ans = -1;
if(ans == -1)
printf("No\n");
else
printf("Yes\n");
}
return 0;
}
| |
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower). | C | 933135ef124b35028c1f309d69515e44 | 1c3cf48d43e9f83b083ab57770fe9b1b | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1501425300 | ["6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000"] | NoteFirst game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | PASSED | 1,700 | standard input | 1 second | In the first string, the number of games n (1 ≤ n ≤ 350000) is given. Each game is represented by a pair of scores a, b (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly. | ["Yes\nYes\nYes\nNo\nNo\nYes"] | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#define maxn 31663
long zhi[10000],ans=0;
bool vis[maxn+1];
void GetZhi()
{
long i,j;
for (i=2;i<=maxn;i++)
vis[i]=true;
for (i=2;i<=maxn;i++)
{
if (vis[i])
{
ans++;
zhi[ans]=i;
}
for (j=1;j<=ans;j++)
{
if (i*zhi[j]>maxn)
break;
vis[i*zhi[j]]=false;
if (i%zhi[j]==0)
break;
}
}
}
int main()
{
__int64 a,b,c;
double d;
long n,l;
GetZhi();
scanf("%ld",&n);
for (l=1;l<=n;l++)
{
scanf("%I64d%I64d",&a,&b);
c=a*b;
d=pow(c,1.0/3);
c=round(d);
//Ҫ��fabs
if (fabs(d-c)<0.00000001 && a%c==0 && b%c==0)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
| |
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower). | C | 933135ef124b35028c1f309d69515e44 | 150362b0d6eb92443a78b12e14632f6c | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1501425300 | ["6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000"] | NoteFirst game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | PASSED | 1,700 | standard input | 1 second | In the first string, the number of games n (1 ≤ n ≤ 350000) is given. Each game is represented by a pair of scores a, b (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly. | ["Yes\nYes\nYes\nNo\nNo\nYes"] | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
long long int n, a, b, i, x, y;
int main(void) {
scanf("%I64d", &n);
for(i = 0; i < n; i++) {
scanf("%I64d%I64d", &a, &b);
if(a*a%b != 0 || b*b%a != 0) {
goto no;
}
x = (long long int) (pow(a*a/b, 1.0/3.0)+0.5);
y = (long long int) (pow(b*b/a, 1.0/3.0)+0.5);
if(x*x*x != a*a/b || y*y*y != b*b/a) {
goto no;
}
printf("Yes\n");
continue;
no:
printf("No\n");
}
return 0;
}
| |
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is multiplied by k2, and the loser's score is multiplied by k. In the beginning of the game, both Slastyona and Pushok have scores equal to one.Unfortunately, Slastyona had lost her notepad where the history of all n games was recorded. She managed to recall the final results for each games, though, but all of her memories of them are vague. Help Slastyona verify their correctness, or, to put it another way, for each given pair of scores determine whether it was possible for a game to finish with such result or not. | For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower). | C | 933135ef124b35028c1f309d69515e44 | f6438a0b44141f600c3bd9256ed29c75 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1501425300 | ["6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000"] | NoteFirst game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won.The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3. | PASSED | 1,700 | standard input | 1 second | In the first string, the number of games n (1 ≤ n ≤ 350000) is given. Each game is represented by a pair of scores a, b (1 ≤ a, b ≤ 109) – the results of Slastyona and Pushok, correspondingly. | ["Yes\nYes\nYes\nNo\nNo\nYes"] | #include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MOD 1000000007
#define ll long long
int main(){
int n;
scanf("%d",&n);
while(n--){
ll a,b;
scanf("%lld %lld",&a,&b);
ll product = a * b;
long double third = cbrtl((long double)product);
ll ok=(ll)third;
ll ok1;
ok1=ok*ok*ok;
if(ok1 != product) printf("No\n");
else{
if(a/ok>=1 && b/ok>=1 && a%ok==0 && b%ok==0) printf("Yes\n");
else printf("No\n");
}
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.