prob_desc_description stringlengths 63 3.8k | prob_desc_output_spec stringlengths 17 1.47k ⌀ | lang_cluster stringclasses 2 values | src_uid stringlengths 32 32 | code_uid stringlengths 32 32 | lang stringclasses 7 values | prob_desc_output_to stringclasses 3 values | prob_desc_memory_limit stringclasses 19 values | file_name stringclasses 111 values | tags listlengths 0 11 | prob_desc_created_at stringlengths 10 10 | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_notes stringlengths 4 3k ⌀ | exec_outcome stringclasses 1 value | difficulty int64 -1 3.5k ⌀ | prob_desc_input_from stringclasses 3 values | prob_desc_time_limit stringclasses 27 values | prob_desc_input_spec stringlengths 28 2.42k ⌀ | prob_desc_sample_outputs stringlengths 2 796 | source_code stringlengths 42 65.5k | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. | Print a single number — the minimum number of columns that you need to remove in order to make the table good. | C | a45cfc2855f82f162133930d9834a9f0 | e9105e42ea902ce8c71a978ffbf7dc60 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation",
"brute force"
] | 1418833800 | ["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"] | NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. | ["0", "2", "4"] | #include <stdio.h>
#define N 111
char s[N][N];
int rem[N], x[N];
int main() {
int n, m, i, j, k;
scanf("%d%d", &n, &m);
for(i=0; i<n; i++) {
scanf("%s", s[i]);
}
for(i=0; i<m; i++) {
rem[i] = 1;
}
for(i=0; i<n; i++) {
x[i] = 0;
}
for(j=0; j<m; j++) {
for(i=0; i<n-1; i++) {
if(s[i][j] > s[i+1][j] && !x[i]) {
rem[j] = 0;
}
}
if(rem[j]) {
for(i=0; i<n-1; i++) {
if(s[i][j] < s[i+1][j]) {
x[i] = 1;
}
}
}
}
/* for(i=0; i<n-1; i++) {
k = 1;
for(j=0; j<m && k; j++) {
if(rem[j]) {
if(s[i][j] < s[i+1][j]) {
k = 0;
} else if(s[i][j] > s[i+1][j]) {
rem[j]=0;
}
}
}
}*/
k=0;
for(i=0; i<m; i++) {
if(!rem[i]) {
k++;
}
}
printf("%d\n", k);
return 0;
} | |
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. | Print a single number — the minimum number of columns that you need to remove in order to make the table good. | C | a45cfc2855f82f162133930d9834a9f0 | b97e7d64e7ad97b91035d9b44e034641 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation",
"brute force"
] | 1418833800 | ["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"] | NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. | ["0", "2", "4"] | #include<stdio.h>
#include<string.h>
int main()
{
char x[1000][1001];
int row,col,i,j,k,ans=0;
scanf("%d%d",&row,&col);
for(i=0;i<row;i++)
scanf("%s",&x[i]);
for(i=1;i<row;i++)
{
if(strcmp(x[i-1],x[i])>0){
//Destroy column which is causing that.
for(j=0;j<col;j++)
if(x[i-1][j]>x[i][j])
break;
//Destroy jth column.
for(k=0;k<row;k++)
x[k][j]='a';
//Increment
++ans;
i=0;
}
}
printf("%d\n",ans);
return 0;
}
| |
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. | Print a single number — the minimum number of columns that you need to remove in order to make the table good. | C | a45cfc2855f82f162133930d9834a9f0 | e8d8c181b100291c256d71539003165c | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation",
"brute force"
] | 1418833800 | ["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"] | NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. | ["0", "2", "4"] | #include <stdio.h>
#include <stdlib.h>
int main () {
int n, m, i, j, k, count = 0;
char **table;
int *elim;
scanf ("%d %d", &n, &m);
table = malloc (n * sizeof (char*));
for (i = 0; i <= n; i++)
table[i] = malloc (m * sizeof (char));
for (i = 0; i < n; i++)
scanf ("%s", table[i]);
if (n == 1)
printf("0\n");
else {
elim = malloc (m * sizeof (int));
for (i = 0; i < m; i++)
elim[i] = 0;
for (j = 0; j < m; j++)
for (i = 0; i < n - 1; i++)
if (table[i+1][j] < table[i][j]) {
for (k = 0; k < j; k++) {
if (elim[k] == 0)
if (table[i+1][k] > table[i][k])
break;
}
if (k == j) {
elim[j] = 1;
break;
}
}
for (i = 0; i < m; i++)
if (elim[i] == 1)
count++;
printf ("%d\n", count);
}
return 0;
} | |
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. | Print a single number — the minimum number of columns that you need to remove in order to make the table good. | C | a45cfc2855f82f162133930d9834a9f0 | 6c381bc9eb989ea5996689fa240ead79 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation",
"brute force"
] | 1418833800 | ["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"] | NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. | ["0", "2", "4"] | #include <stdio.h>
#include <stdlib.h>
int main () {
int n, m, i, j, k, count = 0;
char **table;
int *elim;
scanf ("%d %d", &n, &m);
table = malloc (n * sizeof (char*));
for (i = 0; i <= n; i++)
table[i] = malloc (m * sizeof (char));
for (i = 0; i < n; i++)
scanf ("%s", table[i]);
if (n == 1) {
printf("0\n");
return 0;
}
elim = malloc (m * sizeof (int));
for (i = 0; i < m; i++)
elim[i] = 0;
for (j = 0; j < m; j++)
for (i = 0; i < n - 1; i++)
if (table[i+1][j] < table[i][j]) {
for (k = 0; k < j; k++) {
if (elim[k] == 0)
if (table[i+1][k] > table[i][k])
break;
}
if (k == j) {
elim[j] = 1;
break;
}
}
for (i = 0; i < m; i++)
if (elim[i] == 1)
count++;
printf ("%d\n", count);
return 0;
} | |
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. | Print a single number — the minimum number of columns that you need to remove in order to make the table good. | C | a45cfc2855f82f162133930d9834a9f0 | 81b1de1da79957428aa2e0f8509f9605 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation",
"brute force"
] | 1418833800 | ["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"] | NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. | ["0", "2", "4"] | #include<stdio.h>
typedef unsigned u;
char M[1111][1111];
u A[1111],B[1111],*a,*b,*c,l;
int main()
{
u x,y,z,i,j,k,r;
scanf("%u%u",&x,&y);
for(i=0;i<x;A[i]=B[i]=i)scanf("%s",M[i++]);
for(a=A,b=B,l=x,j=r=0;j<y;++j)
{
for(i=k=0;++i<l;)if(a[i])
{
if(M[a[i]][j]<M[a[i]-1][j])goto tj;
if(M[a[i]][j]==M[a[i]-1][j])b[++k]=a[i];
}
l=k+1;c=a;a=b;b=c;++r;tj:;
}
printf("%u\n",j-r);
return 0;
}
| |
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. | Print a single number — the minimum number of columns that you need to remove in order to make the table good. | C | a45cfc2855f82f162133930d9834a9f0 | 07b63858853c7ab96438f5baa2957d87 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation",
"brute force"
] | 1418833800 | ["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"] | NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. | ["0", "2", "4"] | #include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int a,b,c,d,e,f,i,j,k,p,q,sum=0,flag=0,ct1=-1,ct2=0;
char x[110][110];
int y[110];
scanf("%d %d",&a,&b);
for(i=0;i<a;i++)
{
scanf("%s",x[i]);
}
for(j=0;j<b;j++)
{ flag=0;
ct2=0;
for(i=1;i<a;i++)
{
if(x[i][j]<x[i-1][j] && ct1<0)
{
flag=1;
}
else if(x[i][j]<x[i-1][j] && ct1>=0)
{
for(k=0;k<=ct1;k++)
{
if(x[i-1][y[k]]>=x[i][y[k]])
{
ct2=1;
}
else if(x[i-1][y[k]]<x[i][y[k]])
{ct2=0;
break;}
}
}
if(ct2==1)
flag=1;
}
if(flag==1)
{sum++;}
else
{
ct1++;
y[ct1]=j;
//printf("%d ",j);
}
}
printf("%d",sum);
return 0;} | |
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. | Print a single number — the minimum number of columns that you need to remove in order to make the table good. | C | a45cfc2855f82f162133930d9834a9f0 | 6f7f6a9aecb354d8a84a0f61af142cec | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation",
"brute force"
] | 1418833800 | ["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"] | NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. | ["0", "2", "4"] | #include <stdio.h>
/* resubmit 1 */
int main() {
int n, m;
char table[100][100];
int skip[100];
int i, j;
int min_rem;
scanf("%d", &n);
scanf("%d", &m);
getchar();
for (i = 0; i < n; i++) {
skip[i] = 0;
for (j = 0; j < m; j++) {
table[i][j] = getchar();
}
getchar();
}
min_rem = 0;
for (i = 1; i < n; i++) {
for (j = 0; j < m; j++) {
if (!skip[j]) {
if (table[i][j] > table[i-1][j]) break;
if (table[i][j] < table[i-1][j]) {
skip[j] = 1;
min_rem++;
i = 0;
break;
}
}
}
}
printf("%d\n", min_rem);
return 0;
}
| |
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. | Print a single number — the minimum number of columns that you need to remove in order to make the table good. | C | a45cfc2855f82f162133930d9834a9f0 | 166fb1952bb35d98f6aa74216afca59a | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation",
"brute force"
] | 1418833800 | ["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"] | NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. | ["0", "2", "4"] | #include <stdio.h>
int main() {
int n, m;
char table[100][100];
int skip[100];
int i, j;
int min_rem;
scanf("%d", &n);
scanf("%d", &m);
getchar();
for (i = 0; i < n; i++) {
skip[i] = 0;
for (j = 0; j < m; j++) {
table[i][j] = getchar();
}
getchar();
}
min_rem = 0;
for (i = 1; i < n; i++) {
for (j = 0; j < m; j++) {
if (!skip[j]) {
if (table[i][j] > table[i-1][j]) break;
if (table[i][j] < table[i-1][j]) {
skip[j] = 1;
min_rem++;
i = 0;
break;
}
}
}
}
printf("%d\n", min_rem);
return 0;
}
| |
You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. | Print a single number — the minimum number of columns that you need to remove in order to make the table good. | C | a45cfc2855f82f162133930d9834a9f0 | 56c81143d535c2ce8eeebd198d31f132 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"implementation",
"brute force"
] | 1418833800 | ["1 10\ncodeforces", "4 4\ncase\ncare\ntest\ncode", "5 4\ncode\nforc\nesco\ndefo\nrces"] | NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t. | PASSED | 1,500 | standard input | 2 seconds | The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. | ["0", "2", "4"] | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
char temp[100][110],tab[100][110];
int n,m;
int pos(int j)
{
int i;
for(i=0;i<m;i++)
{
if(tab[j][i]<tab[j-1][i])
return i;
}
}
void copy(int k)
{
int i,j,top=0;
for(i=0;i<n;i++)
{
top=0;
for(j=0;j<m;j++)
{
if(j!=k)
temp[i][top++] = tab[i][j];
}
temp[i][top] = '\0';
}
for(i=0;i<n;i++)
strcpy(tab[i],temp[i]);
}
int check()
{
int i;
for(i=1;i<n;i++)
{
if(strcmp(tab[i],tab[i-1])<0)
return 0;
}
return 1;
}
int main()
{
scanf("%d %d%*C",&n,&m);
int i;
for(i=0;i<n;i++)
scanf("%[^\n]%*C",tab[i]);
int j,t,count=0;
while(check()!=1)
{
int f=0;
for(j=1;j<n;j++)
{
if(strcmp(tab[j],tab[j-1])<0)
break;
}
t = pos(j);
copy(t);
count++;
}
printf("%d\n",count);
return 0;
}
| |
A boy named Gena really wants to get to the "Russian Code Cup" finals, or at least get a t-shirt. But the offered problems are too complex, so he made an arrangement with his n friends that they will solve the problems for him.The participants are offered m problems on the contest. For each friend, Gena knows what problems he can solve. But Gena's friends won't agree to help Gena for nothing: the i-th friend asks Gena xi rubles for his help in solving all the problems he can. Also, the friend agreed to write a code for Gena only if Gena's computer is connected to at least ki monitors, each monitor costs b rubles.Gena is careful with money, so he wants to spend as little money as possible to solve all the problems. Help Gena, tell him how to spend the smallest possible amount of money. Initially, there's no monitors connected to Gena's computer. | Print the minimum amount of money Gena needs to spend to solve all the problems. Or print -1, if this cannot be achieved. | C | bc5b2d1413efcaddbf3bf1d905000159 | 6fe79b5ff6b49fab853e6d443b202012 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"dp",
"sortings",
"bitmasks"
] | 1397749200 | ["2 2 1\n100 1 1\n2\n100 2 1\n1", "3 2 5\n100 1 1\n1\n100 1 1\n2\n200 1 2\n1 2", "1 2 1\n1 1 1\n1"] | null | PASSED | 1,900 | standard input | 1 second | The first line contains three integers n, m and b (1 ≤ n ≤ 100; 1 ≤ m ≤ 20; 1 ≤ b ≤ 109) — the number of Gena's friends, the number of problems and the cost of a single monitor. The following 2n lines describe the friends. Lines number 2i and (2i + 1) contain the information about the i-th friend. The 2i-th line contains three integers xi, ki and mi (1 ≤ xi ≤ 109; 1 ≤ ki ≤ 109; 1 ≤ mi ≤ m) — the desired amount of money, monitors and the number of problems the friend can solve. The (2i + 1)-th line contains mi distinct positive integers — the numbers of problems that the i-th friend can solve. The problems are numbered from 1 to m. | ["202", "205", "-1"] | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define MP(a,b) make_pair(a,b)
#define mem(a,b) memset(a , b , sizeof (a))
#define lol long long
#define sz(a) (int)a.size()
#define llsz(a) (long long)a.size()
#define pb(a,b) a.push_back(b)
#define c_sq(a) (int)sqrt(a)
#define llsq(a) (long long)sqrt(a)
#define cl(a) a.clear()
#define I_SZ 1000000000000ll
#define MOD 100000007
#define fr first
#define sc second
#define iter(a,b) for (b=a.begin();b!=a.end();b++)
#define PI 2.0*acos(0.0)
#define all(a) a.begin(),a.end()
#define oo (1<<30)
#define popc(a) __builtin_popcount(a)
#define lloo (1ll<<62)
#define inf ((1LL<<62)-50)
struct Friend{
int money, monitor, pbitmask;
};
int f,n,lim;
struct Friend ar[101];
long long int b, fuck[101], dp[2][1<<20];
int compare(const void* a, const void* b){
struct Friend x = (*(struct Friend*)a);
struct Friend y = (*(struct Friend*)b);
return (y.monitor - x.monitor);
}
long long int F(int i, int bitmask){
if(i==f){
if(bitmask==lim) return 0;
else return inf;
}
if(dp[i][bitmask]!=-1) return dp[i][bitmask];
long long int res=F(i+1,bitmask);
long long int x = F(i+1,bitmask | ar[i].pbitmask)+ar[i].money;
if(x<res) res=x;
return (dp[i][bitmask]=res);
}
void Pregenerate(){
int i,bitmask;
for(i=f;i>=0;i--){
for(bitmask=0;bitmask<=lim;bitmask++){
if(i==f){
if(bitmask==lim) dp[i & 1][bitmask]=0;
else dp[i & 1][bitmask]=inf;
}
else{
long long int res= dp[(i+1) & 1][bitmask];
long long int x = dp[(i+1) & 1][bitmask | ar[i].pbitmask]+ar[i].money;
if(x<res) res=x;
dp[i & 1][bitmask]=res;
if(bitmask==ar[i].pbitmask) fuck[i]=res;
}
}
}
}
int main()
{
int i,j,bitmask,m,x;
while(scanf("%d %d %I64d", &f, &n, &b) != EOF){
bitmask=0;
lim=(1<<n)-1;
for(i=0;i<f;i++){
ar[i].pbitmask=0;
scanf("%d %d %d", &ar[i].money, &ar[i].monitor, &m);
while(m--){
scanf("%d", &x);
x--;
ar[i].pbitmask |=(1<<x);
}
bitmask|=ar[i].pbitmask;
}
if (bitmask!=lim) puts("-1");
else{
qsort(ar,f,sizeof(struct Friend),compare);
Pregenerate();
long long int res = inf;
for(i=0;i<f;i++){
long long int x = fuck[i]+ar[i].money+(b*ar[i].monitor);
if(x<res) res=x;
}
printf("%I64d\n", res);
}
}
return 0;
}
| |
Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible. | In the first line print k — the number of songs during which they can dance. Then in the following k lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to n, and the girls are indexed from 1 to m. | C | 14fc3a7fef44a02791aee62838c4c8c8 | 68d252dc2af57192840554d8fa6d037f | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"greedy"
] | 1372433400 | ["2 1", "2 2"] | NoteIn test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).And in test case 2, we have 2 boys with 2 girls, the answer is 3. | PASSED | 1,000 | standard input | 1 second | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of boys and girls in the dancing room. | ["2\n1 1\n2 1", "3\n1 1\n1 2\n2 2"] | /* https://codeforces.com/contest/322/submission/20970107 (rainboy) */
#include <stdio.h>
int main() {
int n, m, i;
scanf("%d%d", &n, &m);
printf("%d\n", n + m - 1);
for (i = 1; i <= m; i++)
printf("1 %d\n", i);
for (i = 2; i <= n; i++)
printf("%d %d\n", i, m);
return 0;
}
| |
Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible. | In the first line print k — the number of songs during which they can dance. Then in the following k lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to n, and the girls are indexed from 1 to m. | C | 14fc3a7fef44a02791aee62838c4c8c8 | 12ba8e4b5218ddd6d9aa9e220dd5c2e2 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"greedy"
] | 1372433400 | ["2 1", "2 2"] | NoteIn test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).And in test case 2, we have 2 boys with 2 girls, the answer is 3. | PASSED | 1,000 | standard input | 1 second | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of boys and girls in the dancing room. | ["2\n1 1\n2 1", "3\n1 1\n1 2\n2 2"] | #include<stdio.h>
int main(){
int a,b,i;
int x=1;
int y=1;
scanf("%d %d",&a,&b);
printf("%d\n",a-1+b);
for(i=0;i<a-1;i++){
printf("%d %d\n",x,y);
x++;
}
for(i=0;i<b;i++){
printf("%d %d\n",x,y);
y++;
}
} | |
Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible. | In the first line print k — the number of songs during which they can dance. Then in the following k lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to n, and the girls are indexed from 1 to m. | C | 14fc3a7fef44a02791aee62838c4c8c8 | 7a943cb4c9632065f892d1454f8df146 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"greedy"
] | 1372433400 | ["2 1", "2 2"] | NoteIn test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).And in test case 2, we have 2 boys with 2 girls, the answer is 3. | PASSED | 1,000 | standard input | 1 second | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of boys and girls in the dancing room. | ["2\n1 1\n2 1", "3\n1 1\n1 2\n2 2"] | #include <stdio.h>
int main() {
int n, m, i;
scanf("%d%d", &n, &m);
printf("%d\n", n + m - 1);
for (i = 1; i <= m; i++)
printf("1 %d\n", i);
for (i = 2; i <= n; i++)
printf("%d %d\n", i, m);
return 0;
}
| |
Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible. | In the first line print k — the number of songs during which they can dance. Then in the following k lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to n, and the girls are indexed from 1 to m. | C | 14fc3a7fef44a02791aee62838c4c8c8 | 25eaa9b1e7c72be56e79d8d20f05a706 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"greedy"
] | 1372433400 | ["2 1", "2 2"] | NoteIn test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).And in test case 2, we have 2 boys with 2 girls, the answer is 3. | PASSED | 1,000 | standard input | 1 second | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of boys and girls in the dancing room. | ["2\n1 1\n2 1", "3\n1 1\n1 2\n2 2"] | #include <stdio.h>
int main(void) {
int n = 0;
int m = 0;
scanf("%d %d", &n, &m);
printf("%d\n", n + m - 1);
for (int i = 0; i < m; i++) {
printf("%d %d\n", 1, i + 1);
}
if (n > 1) {
printf("%d %d\n", n, m);
for (int i = n - 1; i > 1; i--) {
printf("%d %d\n", i, m);
}
}
return 0;
} | |
Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible. | In the first line print k — the number of songs during which they can dance. Then in the following k lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to n, and the girls are indexed from 1 to m. | C | 14fc3a7fef44a02791aee62838c4c8c8 | 404776fe8c4c8e21a2c063634bc94c6a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"greedy"
] | 1372433400 | ["2 1", "2 2"] | NoteIn test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).And in test case 2, we have 2 boys with 2 girls, the answer is 3. | PASSED | 1,000 | standard input | 1 second | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of boys and girls in the dancing room. | ["2\n1 1\n2 1", "3\n1 1\n1 2\n2 2"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n, m;
scanf("%d%d", &n, &m);
printf("%d\n", (n+m-1));
int i, j;
for(i = 1; i <= m; i++)
{
printf("%d %d\n", 1, i);
}
for(j = 2; j <= n; j++)
{
printf("%d %d\n",j, 1);
}
return 0;
} | |
Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible. | In the first line print k — the number of songs during which they can dance. Then in the following k lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to n, and the girls are indexed from 1 to m. | C | 14fc3a7fef44a02791aee62838c4c8c8 | 7d48f60bd91762ee662c4336d5a0a970 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"greedy"
] | 1372433400 | ["2 1", "2 2"] | NoteIn test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).And in test case 2, we have 2 boys with 2 girls, the answer is 3. | PASSED | 1,000 | standard input | 1 second | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of boys and girls in the dancing room. | ["2\n1 1\n2 1", "3\n1 1\n1 2\n2 2"] | #include <stdio.h>
int n, m, k, i, j;
int main()
{
scanf("%d %d",&n,&m);
printf("%d\n",n+m-1);
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if((i==1 && j!=1) || (i!=1 && j==1) || (i==1 && j==1))
{
printf("%d %d\n",i,j);
}
}
}
return 0;
} | |
Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible. | In the first line print k — the number of songs during which they can dance. Then in the following k lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to n, and the girls are indexed from 1 to m. | C | 14fc3a7fef44a02791aee62838c4c8c8 | 12ca156b8f1b2fec86b46b9238649ce8 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"greedy"
] | 1372433400 | ["2 1", "2 2"] | NoteIn test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).And in test case 2, we have 2 boys with 2 girls, the answer is 3. | PASSED | 1,000 | standard input | 1 second | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of boys and girls in the dancing room. | ["2\n1 1\n2 1", "3\n1 1\n1 2\n2 2"] | #include <stdio.h>
int main(){
int n,m,g;
scanf("%d%d",&n,&m);
printf("%d\n",n+m-1);
printf("1 1\n");
if(n>=m)
g=m;
else
g=n;
for(int i=1;i<g;i++){
printf("%d %d\n",i,i+1);
printf("%d %d\n",i+1,i);
}
if(g==m){
for(int i = m+1;i<=n;i++){
printf("%d 1\n",i);
}
}
if(g==n){
for(int i= n+1;i<=m;i++){
printf("1 %d\n",i);
}
}
} | |
Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible. | In the first line print k — the number of songs during which they can dance. Then in the following k lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to n, and the girls are indexed from 1 to m. | C | 14fc3a7fef44a02791aee62838c4c8c8 | 1debcd513c0b1179ec31c3258038fd07 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"greedy"
] | 1372433400 | ["2 1", "2 2"] | NoteIn test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).And in test case 2, we have 2 boys with 2 girls, the answer is 3. | PASSED | 1,000 | standard input | 1 second | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of boys and girls in the dancing room. | ["2\n1 1\n2 1", "3\n1 1\n1 2\n2 2"] | #include<stdio.h>
main()
{
int b,g;
scanf("%d %d",&b,&g);
printf("%d\n",b+g-1);
for(int a=1 ; a<=g ; a++)
printf("1 %d\n",a);
for(int a=1 ; a<b ;a++)
printf("%d 1\n",a+1);
}
| |
Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible. | In the first line print k — the number of songs during which they can dance. Then in the following k lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to n, and the girls are indexed from 1 to m. | C | 14fc3a7fef44a02791aee62838c4c8c8 | 6277e433caf277c052369e3e812ad983 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"greedy"
] | 1372433400 | ["2 1", "2 2"] | NoteIn test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).And in test case 2, we have 2 boys with 2 girls, the answer is 3. | PASSED | 1,000 | standard input | 1 second | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of boys and girls in the dancing room. | ["2\n1 1\n2 1", "3\n1 1\n1 2\n2 2"] | #include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main()
{
int n,m;
scanf("%d%d",&n,&m);
printf("%d\n",m+n-1);
for (int i=1;i<=m;i++)
{
printf("1 %d\n", i);
}
for (int i=2;i<=n;i++)
{
printf("%d 1\n",i);
}
}
| |
Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible. | In the first line print k — the number of songs during which they can dance. Then in the following k lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to n, and the girls are indexed from 1 to m. | C | 14fc3a7fef44a02791aee62838c4c8c8 | c5ae85758600273b7d294a7a650347df | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"greedy"
] | 1372433400 | ["2 1", "2 2"] | NoteIn test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).And in test case 2, we have 2 boys with 2 girls, the answer is 3. | PASSED | 1,000 | standard input | 1 second | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of boys and girls in the dancing room. | ["2\n1 1\n2 1", "3\n1 1\n1 2\n2 2"] | #include<stdio.h>
main()
{
int b,g;
scanf("%d %d",&b,&g);
printf("%d\n",b+g-1);
for(int a=1 ; a<=g ; a++)
printf("1 %d\n",a);
for(int a=1 ; a<b ;a++)
printf("%d 1\n",a+1);
}
| |
Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible. | In the first line print k — the number of songs during which they can dance. Then in the following k lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to n, and the girls are indexed from 1 to m. | C | 14fc3a7fef44a02791aee62838c4c8c8 | b056d8c9dcce685517431d0b01b9ae7b | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"greedy"
] | 1372433400 | ["2 1", "2 2"] | NoteIn test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).And in test case 2, we have 2 boys with 2 girls, the answer is 3. | PASSED | 1,000 | standard input | 1 second | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of boys and girls in the dancing room. | ["2\n1 1\n2 1", "3\n1 1\n1 2\n2 2"] | #include<stdio.h>
int main()
{
int girl,boys,i,j,k;
scanf("%d%d",&boys,&girl);
i=boys+girl-1;
printf("%d\n",i);
for(i=1;i<=girl;i++)
printf("1 %d\n",i);
if(girl>1)
j=2;
else
j=1;
for(i=2;i<=boys;i++)
printf("%d %d\n",i,j);
return 0;
} | |
Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible. | In the first line print k — the number of songs during which they can dance. Then in the following k lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to n, and the girls are indexed from 1 to m. | C | 14fc3a7fef44a02791aee62838c4c8c8 | 918d3bebcb84d2ca5b200717fad6f950 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"greedy"
] | 1372433400 | ["2 1", "2 2"] | NoteIn test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).And in test case 2, we have 2 boys with 2 girls, the answer is 3. | PASSED | 1,000 | standard input | 1 second | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of boys and girls in the dancing room. | ["2\n1 1\n2 1", "3\n1 1\n1 2\n2 2"] | #include<stdio.h>
int main()
{
int a,b,c,i;
scanf("%d %d",&a,&b);
printf("%d\n",a+b-1);
for(i=1;i<=b;i++)
{
printf("1 %d\n",i);
}
for(i=2;i<=a;i++)
{
printf("%d 1\n",i);
}
return 0;
}
| |
Fox Ciel and her friends are in a dancing room. There are n boys and m girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule: either the boy in the dancing pair must dance for the first time (so, he didn't dance with anyone before); or the girl in the dancing pair must dance for the first time. Help Fox Ciel to make a schedule that they can dance as many songs as possible. | In the first line print k — the number of songs during which they can dance. Then in the following k lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to n, and the girls are indexed from 1 to m. | C | 14fc3a7fef44a02791aee62838c4c8c8 | cee414f8c8b9b5b088d2eb7a44bf9aaf | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"greedy"
] | 1372433400 | ["2 1", "2 2"] | NoteIn test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).And in test case 2, we have 2 boys with 2 girls, the answer is 3. | PASSED | 1,000 | standard input | 1 second | The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of boys and girls in the dancing room. | ["2\n1 1\n2 1", "3\n1 1\n1 2\n2 2"] | #include<stdio.h>
int main()
{
int b,g,i,j;
scanf("%d%d",&b,&g);
printf("%d\n",b+g-1);
for(j=1;j<=b;j++)
for(i=1;i<=g;i++){
if(j>1&&i>1)break;
printf("%d %d\n",j,i);
}
return 0;
} | |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | 7b7506f28892dfe69a9291278847dc9d | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include<stdio.h>
#include<stdlib.h>
void fun(int );
void fun(int n)
{
int i,j,s,l=0,flag=0;
for(i=0;i<=n/4;i++)
{
s=n-i*4;
if(s%7==0)
{
flag=1;
for(j=0;j<i;j++)
{
printf("4");
}
s=s/7;
for(j=0;j<s;j++)
{
l++;
printf("7");
}
}
if(l==s)
{
break;
}
}
if(flag==0)
{
printf("-1\n");
}
}
int main()
{
int n;
scanf("%d",&n);
fun(n);
return 0;
} | |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | 46e68bea224b2474f4db45ee7453e63b | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n,i,j,k,status=0;
scanf("%d",&n);
for(i=0;i<=n/4;i++)
{
for(j=0;j<=n/7;j++)
{
if(i*4+j*7==n)
{
status=1;
break;
}
}
if(status==1)
break;
}
if(status==1)
{
for(k=0;k<i;k++)
printf("4");
for(k=0;k<j;k++)
printf("7");
printf("\n");
}
else
printf("-1\n");
return 0;
}
| |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | df37db305138f82294bfc6d2a4567d4b | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include<stdio.h>
int main(void)
{ int i,j,n,k,l,a=0; scanf("%d", &n);
for(i=0;i<=n/4; i++)
{ for(j=0; j<=n/7; j++)
{
if(n-4*i-7*j==0)
{a--; break;}
}
if(a<0)
break;
}
if(a==0)
printf("-1");
else
{
for(k=0; k<i; k++)
printf("4");
for(k=0; k<j; k++)
printf("7");
}
}
| |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | b5579d544cf36d80a5930d15b3fd00bf | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include<stdio.h>
int main()
{
int num;
scanf("%d",&num);
int b;
b=num;
int s=0,f=0;
if(b%4!=0){
while(b>=7 && b%4!=0)
{b=b-7;
s++;
}
// printf("sevens %d\n",s);
while(b>0)
{b=b-4;
f++;
}
// printf("fours %d\n",f);
if(f>=7){
s=s+(f/7)*4;
f=f%7;}
}
else{
int q=b/4;
s=(q/7)*4;
f=q%7;
}
//printf("fours %d\n",f);
//printf("sevens %d\n",s);
if((7*s+4*f)==num){
//unsigned long long int n=0;
while(f!=0)
{printf("4");
f--;}
while(s!=0)
{printf("7");
s--;}
//printf("%I64d",n);
}
else {printf("-1");}
return 0;
}
| |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | 7383223931b8f324b3d93e3687db8037 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int b;
b=n;
int s=0,f=0;
if(b%4!=0){
while(b>=7 && b%4!=0)
{b=b-7;
s++;
}
// printf("sevens %d\n",s);
while(b>0)
{b=b-4;
f++;
}
// printf("fours %d\n",f);
if(f>=7){
s=s+(f/7)*4;
f=f%7;}
}
else{
int q=b/4;
s=(q/7)*4;
f=q%7;
}
//printf("fours %d\n",f);
//printf("sevens %d\n",s);
if((7*s+4*f)==n){
//unsigned long long int n=0;
while(f!=0)
{printf("4");
f--;}
while(s!=0)
{printf("7");
s--;}
//printf("%I64d",n);
}
else {printf("-1");}
return 0;
}
| |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | f84350d7d65df57c330a5cafd6a8bb5b | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include <stdio.h>
int main()
{
int n, i, a = 0, b = 0;
scanf("%d", &n);
a = 0;
if(n==4 || n==7)
{
printf("%d",n);
return 0;
}
if(n%7==0)
{
for(i=0;i<n/7;i++)
{
printf("7");
}
return 0;
}
while (4 * a + 7 * b < n)
{
a++;
// a = ((n) - (b * 7)) / 4;
b = ((n) - (a*4))/7;
if(a<0 || b<0)
{
printf("-1");
return 0;
}
}
if (4 * a + 7 * b == n)
{
for (i = 0; i < a; i++)
{
printf("4");
}
for (i = 0; i < b; i++)
{
printf("7");
}
}
else
{
printf("-1");
}
return 0;
} | |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | 35caa64616ddc2111184e2513cccb422 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include <stdio.h>
int main() {
int n, acum=0, total=0;
scanf("%i", &n);
while(n > 0){
if(n%7 != 0){
n=n-4;
total++;
acum++;
}
else{
n=n-7;
total++;
}
}
if(n==0){
for(int i=0;i<total;i++){
if(i < acum){
printf("4");
}
else
printf("7");
}
}else
printf("-1");
return 0;
}
| |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | 4a4191823b3a1b377f6f6e46129293c4 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include <stdio.h>
int main() {
int n, acum=0, total=0;
scanf("%d", &n);
while(n > 0){
if(n%7 != 0){
n=n-4;
total++;
acum++;
}
else{
n=n-7;
total++;
}
}
if(n==0){
for(int i=0; i<total;i++){
if(i < acum){
printf("4");
}
else
printf("7");
}
}else
printf("-1");
return 0;
}
| |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | 1c41e1c274090a3d0f7afc38329f94eb | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include <stdio.h>
int main(){
int n,flag=0,min=2147483647,num1,num2,sum;
scanf("%d",&n);
for(int i=0;i<=n/7;i++){
if((n-i*7)%4==0){
flag=1;
sum=i+(n-7*i)/4;
if(min>sum){
num1=i;
num2=(n-7*i)/4;
min=sum;
}
}
}
if(flag){
for(int i=0;i<num2;++i)
putchar('4');
for(int i=0;i<num1;++i)
putchar('7');
}
else
printf("-1");
return 0;
} | |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | f3a532afb38cb6d731a70ca0f13249c1 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
int a,m=0,n=0,i;
scanf("%d",&a);
for(i=0; a>0; i++)
{
if(a%7==0) {m++; a-=7;}
else if(a%4==0) {n++; a-=4;}
else {m++; a-=7;}
}
if(a<0) printf("-1\n");
else{
for(i=0; i<n; i++)
printf("4");
for(i=0; i<m; i++)
printf("7");
}
}
| |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | 3486177689902940c1df09eac501a44f | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include<stdio.h>
int main()
{
long long int n,a,b,i=0,c=1,j,sum=0,m=1,v=0,q,w;
scanf("%lld",&n);
while(1){
a=(n-(7*i))/4;
b=(n-(7*i))%4;
if(b!=0){
i++;
}
else
break;
if(a<0){
c=0;
break;
}
}
while(1){
q=(n-(4*v))/7;
w=(n-(4*v))%7;
if(w!=0){
v++;
}
else
break;
if(q<0){
c=0;
break;
}
}
if((a+i)>(q+v)){
a=v;
i=q;
}
if(c){
for(j=1;j<=a;j++){
printf("%d",4);
}
for(j=1;j<=i;j++){
printf("%d",7);
}
}
else{
printf("%d",-1);
}
return 0;
}
| |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | e6b9f1e63a50bd6446453356c2f1c8cd | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include<stdio.h>
int main()
{
long long int n,a,b,i=0,c=1,j,sum=0,m=1,v=0,q,w;
scanf("%lld",&n);
while(1){
a=(n-(7*i))/4;
b=(n-(7*i))%4;
if(b!=0){
i++;
}
else
break;
if(a<0){
c=0;
break;
}
}
while(1){
q=(n-(4*v))/7;
w=(n-(4*v))%7;
if(w!=0){
v++;
}
else
break;
if(q<0){
c=0;
break;
}
}
if((a+i)>(q+v)){
a=v;
i=q;
}
if(c){
for(j=1;j<=a;j++){
printf("%d",4);
}
for(j=1;j<=i;j++){
printf("%d",7);
}
}
else{
printf("%d",-1);
}
return 0;
}
| |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | 1e8a747817b367f4cc75e3da3c81070a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include<stdio.h>
int main()
{
int n,a;
scanf("%d",&n);
int four=0,seven=0;
four = n/4;
n = n%4;
int res=1;
if(n!=0)
{
four--;
for(a=1; a<7&&four>=0; a++,four--)
{
n+=4;
if(n>=7)
{
seven++;
n=n-7;
}
if(n%7==0)break;
}
if(four==-1||a==7)res=0;
}
switch(res)
{
case 0:
printf("-1");
break;
case 1:
seven+=(4*(four/7));
four-=(7*(four/7));
while(four>0)
{
printf("4");
four--;
}
while(seven>=100)
{
printf("7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777");
seven-=100;
}
while(seven>0)
{
printf("7");
seven--;
}
break;
}
printf("\n");
return 0;
}
| |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | 5dcc0e73b00e44cd3a33684bc7d76d3f | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include <stdio.h>
int main()
{
int n,i,SEV=0,FOR=0,N;
scanf("%d",&n);
N=n;
while(N>0)
{
if(N%7==0) {SEV+=N/7;break;}
else if(N%4==0) {FOR+=(N%28)/4;SEV+=(N/28)*4;break;}
else {N-=7;SEV++;}
}
if(N<=0) {printf("-1\n");return 0;}
for(i=0;i<FOR;i++) printf("4");
for(i=0;i<SEV;i++) printf("7");
printf("\n");
return 0;
}
| |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | 2960c049da87f90d3ad3264b03833d0a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include <stdio.h>
int main()
{
int n,i,SEV=0,FOR=0,N;
scanf("%d",&n);
N=n;
while(N>0)
{
if(N%7==0) {SEV+=N/7;break;}
else if(N%4==0) {FOR+=(N%28)/4;SEV+=(N/28)*4;break;}
else {N-=7;SEV++;}
}
if(N<=0) {printf("-1\n");return 0;}
for(i=0;i<FOR;i++) printf("4");
for(i=0;i<SEV;i++) printf("7");
printf("\n");
return 0;;
}
| |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | 1c3e633deff750dc8dc4171fa866468e | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include <stdio.h>
int main(){
int n;
scanf("%d", &n);
int f = -1, s = -1;
for(int i = 0;i < n; i++){
int tmp = n - i * 7;
if( tmp % 4 == 0 && tmp / 4 >= 0){
if( (f == -1 && s == -1) || (i + tmp / 4 < s + f ) ){
f = tmp / 4;
s = i;
}
}
}
if( f == -1 && s == -1){
printf("-1\n");
}
else{
for(int i = 0; i < f; i++){
printf("4");
}
for(int i = 0; i < s; i++){
printf("7");
}
}
return 0;
} | |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | 5b9eec0f47133dd6d8e40e4ce9a85480 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include<stdio.h>
#include<math.h>
#include <string.h>
int main()
{
int i, j, n, m, a;
int d, x =0;
scanf("%d", &d);
for(i=0; d>=i*4 ;i++){
if((d-i*4)%7==0)
{
a=(d-i*4)/7;
break;
}
}
m = (a*7) + (i*4);
if(m == d){
for(j=0; j<i; j++){
printf("4");
}
for(j=0; j<a; j++){
printf("7");
}
printf("\n");
}
else printf("-1\n");
return 0;
}
| |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | 9c3f76c3cf81eda974ce5b356596eadb | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include <stdio.h>
int main(){
int sum;
scanf("%i",&sum);
if(sum < 4) {
puts("-1");
return 0;
}
int sevens = sum/7;
int fours,rem;
sevens++;
while(sevens--){
rem = sum - 7*sevens;
if(rem % 4 == 0){
//wuju we made it
fours = rem/4;
//printf("%i ",fours);
while(fours--) putchar('4');
while(sevens--) putchar('7');
return 0;
}
}
//Case 3
puts("-1");
return 0;
} | |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | 3a5d1af40f1ec049de58b90499459c19 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include<stdio.h>
int main()
{
long long int a,b,n=0,m=0,c=0,s=0,d=0,i,j;
scanf("%lld",&a);
for(; ;)
{
if(a%7==0)
{
c=a/7;
m=1;
break;
}
else
{
a=a-4;
d++;
if(a==0)
{
m=1;
break;
}
}
if(a<=0)break;
}
if(m==1)
{
for(i=0; i<d; i++)
printf("4");
for(i=0; i<c; i++)
printf("7");
printf("\n");
}
else printf("-1\n");
return 0;
}
| |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | 3c2a52e90a9835f3ece8d6d99cb4cb1e | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include<stdio.h>
int main()
{
int a,b,c,d,i;
scanf("%d",&a);
b=a%4;
if(b!=0)
b=4-b;
a=a-b*7;
a=a/4;
if(a<0)
printf("-1\n");
else
{
c=a/7;
b=b+c*4;
a=a%7;
for(i=0; i<a; i++)
{
printf("4");
}
for(i=0; i<b; i++)
{
printf("7");
}
printf("\n");
}
return 0;
} | |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | 5938d0c53bd5bcc3038b471896cf3024 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include<stdio.h>
int main()
{
int n,f=0,sum=0,i,j,fo=0,se=0;
scanf("%d",&n);
/*if(n%7==0)
{
for(int i=1;i<=n/7;i++)
printf("%d",7);
}
else if(n%4==0)
{
for(int i=1;i<=n/4;i++)
printf("%d",4);
}
else*/
{
for(i=0;sum<n&&f==0;i++)
{
for(j=0;sum<n;j++)
{
sum=(4*i)+(7*j);
if(sum==n)
{
fo=i;
se=j;
f=1;
//printf("%d",1);
break;
}
}
sum=0;
if(i>j)
break;
}
if(f==1)
{
for(int i=0;i<fo;i++)
printf("%d",4);
for(int i=0;i<se;i++)
printf("%d",7);
}
else
printf("%d",-1);
}
return 0;
} | |
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task. | Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1. | C | 2584fa8c1adb1aa8cd5c28a8610ff72d | 90c04d0dcec52f00abbead9cfe78f5b4 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force"
] | 1314633600 | ["11", "10"] | null | PASSED | 1,000 | standard input | 2 seconds | The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number. | ["47", "-1"] | #include<stdio.h>
int main()
{
int n,i,k;
scanf("%d",&n);
if(n==1||n==2||n==3||n==5||n==6||n==9||n==10||n==13||n==17)
{
printf("-1\n");
}
else if(n==4||n==7)
{
printf("%d\n",n);
}
else if(n==8)
{
printf("44\n");
}
else if(n==11)
{
printf("47\n");
}
else if(n==12)
{
printf("444\n");
}
else if(n==14)
{
printf("77\n");
}
else if(n==15)
{
printf("447\n");
}
else if(n==16)
{
printf("4444\n");
}
else if(n==18)
{
printf("477\n");
}
else if(n==19)
{
printf("4447\n");
}
else if(n==20)
{
printf("44444\n");
}
else if(n==22)
{
printf("4477\n");
}
else if(n==23)
{
printf("44447\n");
}
else if(n==24)
{
printf("444444\n");
}
else if(n==25)
{
printf("4777\n");
}
else if(n==26)
{
printf("44477\n");
}
else if(n==27)
{
printf("444447\n");
}
else
{
if(n%7==0)
{
for(i=0;i<n/7;i++)
{
printf("7");
}
printf("\n");
}
else if(n%7==1)
{
printf("44");
for(i=1;i<n/7;i++)
{
printf("7");
}
printf("\n");
}
else if(n%7==2)
{
printf("4444");
for(i=1;i<(n/7)-1;i++)
{
printf("7");
}
printf("\n");
}
else if(n%7==3)
{
printf("444444");
for(i=1;i<(n/7)-2;i++)
{
printf("7");
}
printf("\n");
}
else if(n%7==4)
{
printf("4");
for(i=0;i<(n/7);i++)
{
printf("7");
}
printf("\n");
}
else if(n%7==5)
{
printf("444");
for(i=1;i<(n/7);i++)
{
printf("7");
}
printf("\n");
}
else if(n%7==6)
{
printf("44444");
for(i=1;i<(n/7)-1;i++)
{
printf("7");
}
printf("\n");
}
}
return 0;
}
| |
You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array a that are less than or equal to the value bj. | Print m integers, separated by spaces: the j-th of which is equal to the number of such elements in array a that are less than or equal to the value bj. | C | e9a519be33f25c828bae787330c18dd4 | 9d6514e4dffb0010fb4e93a037171898 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"two pointers",
"binary search",
"sortings"
] | 1448636400 | ["5 4\n1 3 5 7 9\n6 4 2 8", "5 5\n1 2 1 2 5\n3 1 4 1 5"] | null | PASSED | 1,300 | standard input | 2 seconds | The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the sizes of arrays a and b. The second line contains n integers — the elements of array a ( - 109 ≤ ai ≤ 109). The third line contains m integers — the elements of array b ( - 109 ≤ bj ≤ 109). | ["3 2 1 4", "4 2 4 2 5"] | #include<stdio.h>
#include<stdlib.h>
int a[200005],b[200005],temp[200005];
void merge(int l,int r)
{
if(l==r)
return;
int i,j,k,mid;
mid=(l+r)/2;
merge(l,mid);
merge(mid+1,r);
for(i=l,j=mid+1,k=l; k<=r; k++)
{
if(i==mid+1)
{
temp[k]=a[j];
j++;
}
else if(j==r+1)
{
temp[k]=a[i];
i++;
}
else if(a[i]<=a[j])
{
temp[k]=a[i];
i++;
}
else
{
temp[k]=a[j];
j++;
}
}
for(i=l; i<=r; i++)
a[i]=temp[i];
}
void count(int l,int n,int m)
{
int mid,i,count=0;
int h=n;
for(i=1; i<=m; i++)
{
while(l<=h)
{
mid=(l+h)/2;
if(a[mid]>b[i])
{
h=mid-1;
}
else if(a[mid]<=b[i])
{
l=mid+1;
count=mid;
}
}
printf("%d ",count);
l=1;
h=n;
count=0;
}
}
int main()
{
int n,i,j,m;
scanf("%d %d",&n,&m);
for(i=1; i<=n; i++)
{
scanf("%d",&a[i]);
}
for(i=1; i<=m; i++)
{
scanf("%d",&b[i]);
}
merge(1,n);
count(1,n,m);
return 0;
}
| |
You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array a that are less than or equal to the value bj. | Print m integers, separated by spaces: the j-th of which is equal to the number of such elements in array a that are less than or equal to the value bj. | C | e9a519be33f25c828bae787330c18dd4 | a5392a465cbc97ddea880dc4f008664b | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"two pointers",
"binary search",
"sortings"
] | 1448636400 | ["5 4\n1 3 5 7 9\n6 4 2 8", "5 5\n1 2 1 2 5\n3 1 4 1 5"] | null | PASSED | 1,300 | standard input | 2 seconds | The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the sizes of arrays a and b. The second line contains n integers — the elements of array a ( - 109 ≤ ai ≤ 109). The third line contains m integers — the elements of array b ( - 109 ≤ bj ≤ 109). | ["3 2 1 4", "4 2 4 2 5"] | #include <stdio.h>
#include <stdlib.h>
static int _a[200000];
static inline int compare_int(const void* a, const void* b) { return *(const int*)b - *(const int*)a; }
/* search sorted (ascending) array for lowest index i, such that v <= a[i] */
/* this index can be used for insertion (to keep array sorted) */
/* comparison function acts like < (less) */
#define IMPL_LOWER_BOUND(T, NAME, CMP) \
static inline int NAME(int n, T elem[static n], T v) { \
int low = 0, high = n; /* start with whole array */ \
while(high > low) { /* more than one candidate */ \
const int mid = low + (high - low) / 2; /* pick middle */ \
if(CMP(elem[mid], v)) low = mid + 1; /* a[mid] < v: no need to consider mid */ \
else high = mid; /* a[mid] >= v: pick first half */ \
} \
return low; \
}
#define GREATER(a,b) ((a)>(b))
IMPL_LOWER_BOUND(int, lower_bound, GREATER)
int main() {
int N, M; scanf("%d %d\n", &N, &M);
for(int i = 0, in = N ; i < in ; ++i) scanf("%d ", &_a[i]);
qsort(_a, N, sizeof(int), compare_int);
for(int i = 0, in = M ; i < in ; ++i) {
int bi; scanf("%d ", &bi);
printf("%d%c", N - lower_bound(N,_a,bi), i+1 == in ? '\n' : ' ');
}
return 0;
}
| |
You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array a that are less than or equal to the value bj. | Print m integers, separated by spaces: the j-th of which is equal to the number of such elements in array a that are less than or equal to the value bj. | C | e9a519be33f25c828bae787330c18dd4 | e090db87251a7ac704e33ec2ff72a29f | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"two pointers",
"binary search",
"sortings"
] | 1448636400 | ["5 4\n1 3 5 7 9\n6 4 2 8", "5 5\n1 2 1 2 5\n3 1 4 1 5"] | null | PASSED | 1,300 | standard input | 2 seconds | The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the sizes of arrays a and b. The second line contains n integers — the elements of array a ( - 109 ≤ ai ≤ 109). The third line contains m integers — the elements of array b ( - 109 ≤ bj ≤ 109). | ["3 2 1 4", "4 2 4 2 5"] | #include <stdio.h>
#include <stdlib.h>
void read_array(int x,int y[]);
void merge_sort(int arr[],int lo ,int hi );
void merge (int arr[],int lo ,int mid ,int hi);
void NumOfElement(int a[],int b[],int c[],int x ,int y);
void print_array(int n ,int a[]);
int main()
{ int n,m;
scanf("%d %d",&n,&m);
int a[n];
int b[m];
int find[m];//this array contain the number of elements that less than or equal b[j];
read_array(n,a);
read_array(m,b);
//sort array a
merge_sort(a,0,n-1);
NumOfElement(a,b,find,n,m);
print_array(m,find);
return 0;
}
void read_array(int x,int y[]){
int i;
for (i=0;i<x;i++){
scanf("%d",&y[i]);
}
}
void merge_sort (int arr[],int lo ,int hi){
int mid ;
if (lo<hi){
mid =(lo+hi)/2;
merge_sort(arr,lo ,mid);
merge_sort(arr,mid+1,hi);
merge(arr,lo,mid,hi);
}
}
void merge(int arr[],int lo,int mid,int hi){
int i,l,r, temp[hi];
i=lo;
r=mid+1;
l=lo;
while(r<=hi && l<=mid){
if (arr[l]<=arr[r]){
temp[i]=arr[l];
l++;
}
else {
temp[i]=arr[r];
r++;
}
i++;
}
while(r<=hi){
temp[i]=arr[r];
r++;
i++;
}
while (l<=mid){
temp[i]=arr[l];
i++;
l++;
}
for (i=lo;i<=hi;i++){
arr[i]=temp[i];
}
}
void NumOfElement(int a[],int b[],int c[],int x ,int y){//x=n. y=m
int i ,low,hi ,mid ;
for (i=0 ;i<y; i++){
low=0 ,hi=x-1;
while (low<=hi){
mid=(low+hi)/2;
if (a[mid]>b[i]){
hi=mid-1;
}
else{
low= mid+1;
}
}
c[i]=low;
}
}
void print_array(int n ,int a[]){
int i;
for (i=0 ;i<n;i++){
printf("%d ",a[i]);
}
}
| |
You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array a that are less than or equal to the value bj. | Print m integers, separated by spaces: the j-th of which is equal to the number of such elements in array a that are less than or equal to the value bj. | C | e9a519be33f25c828bae787330c18dd4 | 6d24a08bbc4de806003d9d7203f6600e | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"two pointers",
"binary search",
"sortings"
] | 1448636400 | ["5 4\n1 3 5 7 9\n6 4 2 8", "5 5\n1 2 1 2 5\n3 1 4 1 5"] | null | PASSED | 1,300 | standard input | 2 seconds | The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the sizes of arrays a and b. The second line contains n integers — the elements of array a ( - 109 ≤ ai ≤ 109). The third line contains m integers — the elements of array b ( - 109 ≤ bj ≤ 109). | ["3 2 1 4", "4 2 4 2 5"] | #include <stdio.h>
#include <stdlib.h>
#define MALLOC(t,n) (t*) malloc(sizeof(t)*n)
typedef struct indice{
int posicao;
int valor;
}indice;
int comparador(const void *a, const void *b){
return (*(int*)a) - (*(int*)b);
}
int comparadorValor(const void *a, const void *b){
return (*(indice*)a).valor - (*(indice*)b).valor;
}
int buscaBinaria(int a[], int inicio, int fim, int valor){
int i = (fim + inicio) / 2;
if(inicio == fim){
return inicio;
}
if(inicio == i){
return i;
}
if(a[i] == valor){
return i;
}
if(a[i] < valor){
return buscaBinaria(a, i + 1, fim, valor);
}
return buscaBinaria(a, inicio, i - 1, valor);
}
void merge(indice a[], int inicio, int meio, int fim){
int inicio1 = inicio, inicio2 = meio + 1, inicio_aux = 0, tamanho = fim - inicio + 1;
indice *vet_aux;
vet_aux = MALLOC(indice, tamanho);
while(inicio1 <= meio && inicio2 <= fim){
if(a[inicio1].valor < a[inicio2].valor){
vet_aux[inicio_aux] = a[inicio1];
inicio1++;
}
else {
vet_aux[inicio_aux] = a[inicio2];
inicio2++;
}
inicio_aux++;
}
while(inicio1 <= meio){
vet_aux[inicio_aux] = a[inicio1];
inicio_aux++;
inicio1++;
}
while(inicio2 <= fim){
vet_aux[inicio_aux] = a[inicio2];
inicio_aux++;
inicio2++;
}
for(inicio_aux = inicio; inicio_aux <= fim; inicio_aux++){
a[inicio_aux] = vet_aux[inicio_aux - inicio];
}
free(vet_aux);
}
void mergeSort(indice a[], int inicio, int fim){
if(inicio < fim){
int meio = (fim + inicio) / 2;
mergeSort(a, inicio, meio);
mergeSort(a, meio + 1, fim);
merge(a, inicio, meio, fim);
}
}
int main(){
int n, m;
scanf("%d %d", &n, &m);
int i;
indice a[n + m];
for(i = 0; i < n; i++){
a[m + i].posicao = -1;
scanf("%d", &a[m + i].valor);
}
for(i = 0; i < m; i++){
a[i].posicao = i;
scanf("%d", &a[i].valor);
}
mergeSort(a, 0, n + m - 1);
int j = 0, resultado[m], cont = 0;
for(i = 0; i < m; i++){
while(j < n + m && a[j].posicao == -1){
j++;
cont++;
}
if(j < n + m){
resultado[a[j].posicao] = cont;
j++;
}
}
for(i = 0; i < m; i++){
printf("%d", resultado[i]);
if(i == m - 1){
printf("\n");
}
else{
printf(" ");
}
}
return 0;
} | |
You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array a that are less than or equal to the value bj. | Print m integers, separated by spaces: the j-th of which is equal to the number of such elements in array a that are less than or equal to the value bj. | C | e9a519be33f25c828bae787330c18dd4 | aee114668f4a14b55d31f47fe32f6e1c | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"two pointers",
"binary search",
"sortings"
] | 1448636400 | ["5 4\n1 3 5 7 9\n6 4 2 8", "5 5\n1 2 1 2 5\n3 1 4 1 5"] | null | PASSED | 1,300 | standard input | 2 seconds | The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the sizes of arrays a and b. The second line contains n integers — the elements of array a ( - 109 ≤ ai ≤ 109). The third line contains m integers — the elements of array b ( - 109 ≤ bj ≤ 109). | ["3 2 1 4", "4 2 4 2 5"] | #include <stdio.h>
void merge(int *arry,int l,int mid,int r){
int arry1[(r-l)+1];
int k = l;
int j = mid+1;
int count=0;
while (k<=mid && j<=r){
if (arry[k]>arry[j]){
arry1[count] = arry[j];
j++;
}
else{
arry1[count]=arry[k];
k++;
}
count++;
}
if (k<=mid){
for (int i=k;i<=mid;i++){
arry1[count]=arry[i];
count++;
}
}
if (j<=r){
for (int i=j;i<=r;i++){
arry1[count]=arry[i];
count++;
}
}
count = 0;
for (int i=l;i<=r;i++){
arry[i]=arry1[count];
count++;
}
}
void MergeSort(int *arry,int l,int r){
if (l>=r){
return;
}
int mid = (l+r)/2;
MergeSort(arry,l,mid);
MergeSort(arry,mid+1,r);
merge(arry,l,mid,r);
}
int Binary(int* arr,int l,int r,int x){
int mid=(l+r)/2;
int ind=0;
while(l<=r){
if(arr[mid]<=x){
ind=mid+1;
l=mid+1;
}
else
r=mid-1;
mid=(l+r)/2;
}
return ind;
}
int main(){
int n,m;
scanf("%d %d",&n,&m);
int a[n];
for (int i=0;i<n;i++){
scanf("%d",&a[i]);
}
MergeSort(a,0,n-1);
int b;
for (int i=0;i<m;i++){
scanf("%d",&b);
int A = Binary(a,0,n-1,b);
printf("%d ",A);
}
printf("\n");
return 0;
} | |
You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array a that are less than or equal to the value bj. | Print m integers, separated by spaces: the j-th of which is equal to the number of such elements in array a that are less than or equal to the value bj. | C | e9a519be33f25c828bae787330c18dd4 | efd27dbc003b730bf53a233e6a370a8b | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"two pointers",
"binary search",
"sortings"
] | 1448636400 | ["5 4\n1 3 5 7 9\n6 4 2 8", "5 5\n1 2 1 2 5\n3 1 4 1 5"] | null | PASSED | 1,300 | standard input | 2 seconds | The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the sizes of arrays a and b. The second line contains n integers — the elements of array a ( - 109 ≤ ai ≤ 109). The third line contains m integers — the elements of array b ( - 109 ≤ bj ≤ 109). | ["3 2 1 4", "4 2 4 2 5"] | #include<stdio.h>
void shellSort(int data[],int len)
{
int m=(int)(log(len+1)/log(2));//计算hibbard增量的长度。
int i;
int G[m];
for(i=0;i<m;i++)
G[i]=(int)pow(2,i+1)-1;//计算Hibbard增量
for(i=m-1;i>=0;i--)
insertionSort(data,len,G[i]);
}
void insertionSort(int data[],int len,int g)
{
int i,j,v;
for(i=g;i<len;i++)
{
v=data[i];
for(j=i-g;j>=0&&data[j]>v;j=j-g)
data[j+g]=data[j];
data[j+g]=v;
}
}
int main()
{
int n,m;
int a[200000],b[200000];
int i,j;
int left,right,mid;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(j=0;j<m;j++)
scanf("%d",&b[j]);
shellSort(a,n);
for(j=0;j<m;j++)
{
left=0;
right=n-1;
while(right>left)
{
mid=(left+right)/2;
if(a[mid]<b[j]+1)
left=mid+1;
else
right=mid;
}
if(n!=1)
if(left<n-1)
printf("%d ",left);
else
if(b[j]>=a[left])
printf("%d ",left+1);
else
printf("%d ",left);
else
if(a[left]<=b[j])
printf("1 ");
else
printf("0 ");
}
return 0;
} | |
You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array a that are less than or equal to the value bj. | Print m integers, separated by spaces: the j-th of which is equal to the number of such elements in array a that are less than or equal to the value bj. | C | e9a519be33f25c828bae787330c18dd4 | 16779cf595a4105e3785b1a597e9b576 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"two pointers",
"binary search",
"sortings"
] | 1448636400 | ["5 4\n1 3 5 7 9\n6 4 2 8", "5 5\n1 2 1 2 5\n3 1 4 1 5"] | null | PASSED | 1,300 | standard input | 2 seconds | The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the sizes of arrays a and b. The second line contains n integers — the elements of array a ( - 109 ≤ ai ≤ 109). The third line contains m integers — the elements of array b ( - 109 ≤ bj ≤ 109). | ["3 2 1 4", "4 2 4 2 5"] | #include <stdio.h>
#include <stdlib.h>
int a[2000000];
int b[2000000];
int sum[2000000];
/*
for(i=0;i<n-1;i++)
{
int y=i;
if(a[i]>a[i+1])
{
int temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
for(k=0;k<i;k++)
{
if(a[y]<a[y-1])
{
temp=a[y];
a[y]=a[y-1];
a[y-1]=temp;
y--;
}
else k=i;
}
}
}
*/
/*
int merge(int *l,int *r)
{
int i=0,k=0,j=0;
int q=(sizeof(l)/sizeof(int))-1;
int w=(sizeof(r)/sizeof(int))-1;
int s[q+w+2];
if(l[i]<=r[j])
{
if(i<=q)
{
a[k]=l[i];
i++;
}
}
else
{
if(j<=w)
{
a[k]=r[j];
j++;
}
}
k++;
return &s;
}
void mergeSort(int l,int r)
{
if(r-l==1)
{
int q=sizeof(left)/sizeof(int);
int w=sizeof(right)/sizeof(int);
if(left[0]>left[1])
{
int temp=left[0];
left[0]=left[1];
left[1]=temp;
}
if(w==2)
{
if(right[0]>right[1])
{
int temp=right[0];
right[0]=right[1];
right[1]=temp;
}
}
}
int i,j;
int mid=(l+r)/2;
int left[mid-l+1];
int right[r-mid];
for(i=l;i<=mid-l;i++)
{
left[i-l]=a[i];
}
for(j=mid+1;j<=r;j++)
{
right[j-mid-1]=a[j];
}
if(q==2)
{
if(left[0]>left[1])
{
int temp=left[0];
left[0]=left[1];
left[1]=temp;
}
if(w==2)
{
if(right[0]>right[1])
{
int temp=right[0];
right[0]=right[1];
right[1]=temp;
}
}
}
mergeSort(left);
mergeSort(right);
int *a=merge(left,right);
}
*/
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
/* create temp arrays */
int L[n1], R[n2];
/* Copy data to temp arrays L[] and R[] */
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays back into arr[l..r]*/
i = 0; // Initial index of first subarray
j = 0; // Initial index of second subarray
k = l; // Initial index of merged subarray
while (i < n1 && j < n2)
{
if (L[i] <= 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);
}
}
void getSum(int i,int l1,int r1)
{
if(a[l1]>b[i])
{
return ;
}
if(a[r1]<=b[i])
{
sum[i]+=(r1-l1+1);
return ;
}
if(a[l1]<=b[i]&&a[r1]>b[i])
{
int mid1=(l1+r1)/2;
getSum(i,l1,mid1);
getSum(i,mid1+1,r1);
}
}
int main()
{
int n,m,i,j,k;
scanf("%d %d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<m;i++)
{
scanf("%d",&b[i]);
}
mergeSort(a, 0, n - 1);
for(i=0;i<m;i++)
{
//printf("%d ",a[i]);
getSum(i,0,n-1);
printf("%d ",sum[i]);
}
}
| |
You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array a that are less than or equal to the value bj. | Print m integers, separated by spaces: the j-th of which is equal to the number of such elements in array a that are less than or equal to the value bj. | C | e9a519be33f25c828bae787330c18dd4 | 2667fee646d53417a0a05d34cec0e0b4 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"two pointers",
"binary search",
"sortings"
] | 1448636400 | ["5 4\n1 3 5 7 9\n6 4 2 8", "5 5\n1 2 1 2 5\n3 1 4 1 5"] | null | PASSED | 1,300 | standard input | 2 seconds | The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the sizes of arrays a and b. The second line contains n integers — the elements of array a ( - 109 ≤ ai ≤ 109). The third line contains m integers — the elements of array b ( - 109 ≤ bj ≤ 109). | ["3 2 1 4", "4 2 4 2 5"] | #include <stdio.h>
#include <stdlib.h>
int a[2000000];
int b[2000000];
int sum[2000000];
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
/* create temp arrays */
int L[n1], R[n2];
/* Copy data to temp arrays L[] and R[] */
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays back into arr[l..r]*/
i = 0; // Initial index of first subarray
j = 0; // Initial index of second subarray
k = l; // Initial index of merged subarray
while (i < n1 && j < n2)
{
if (L[i] <= 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);
}
}
void getSum(int i,int l1,int r1)
{
if(a[l1]>b[i])
{
return ;
}
if(a[r1]<=b[i])
{
sum[i]+=(r1-l1+1);
return ;
}
if(a[l1]<=b[i]&&a[r1]>b[i])
{
int mid1=(l1+r1)/2;
getSum(i,l1,mid1);
getSum(i,mid1+1,r1);
}
}
int main()
{
int n,m,i,j,k;
scanf("%d %d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<m;i++)
{
scanf("%d",&b[i]);
}
mergeSort(a, 0, n - 1);
for(i=0;i<m;i++)
{
//printf("%d ",a[i]);
getSum(i,0,n-1);
printf("%d ",sum[i]);
}
}
| |
You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array a that are less than or equal to the value bj. | Print m integers, separated by spaces: the j-th of which is equal to the number of such elements in array a that are less than or equal to the value bj. | C | e9a519be33f25c828bae787330c18dd4 | c615e55728fdf2e6507c2a1f851e4fcf | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"two pointers",
"binary search",
"sortings"
] | 1448636400 | ["5 4\n1 3 5 7 9\n6 4 2 8", "5 5\n1 2 1 2 5\n3 1 4 1 5"] | null | PASSED | 1,300 | standard input | 2 seconds | The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the sizes of arrays a and b. The second line contains n integers — the elements of array a ( - 109 ≤ ai ≤ 109). The third line contains m integers — the elements of array b ( - 109 ≤ bj ≤ 109). | ["3 2 1 4", "4 2 4 2 5"] | #include <stdio.h>
int a[200005];
int sorted[200005];
int n, m;
void merge(int start, int middle, int end){
int i, j;
int ptr=start;
for(i=start, j=middle+1; i<=middle && j<=end; ptr++){
if(a[i] > a[j]){
sorted[ptr] = a[j];
j++;
} else{
sorted[ptr] = a[i];
i++;
}
}
while(j<=end){
sorted[ptr] = a[j];
j++;
ptr++;
}
while(i<=middle){
sorted[ptr] = a[i];
i++;
ptr++;
}
for(i=start; i<=end; i++) a[i] = sorted[i];
}
void mergeSort(int start, int end){
int middle = (start+end)/2;
if(end-start == 0) return;
mergeSort(start, middle);
mergeSort(middle+1, end);
merge(start, middle, end);
}
int binarySearch(int target){
int i;
int guess;
int min=0, max=n-1;
int best=0;
while(max >= min){
guess = (min+max)/2;
if(a[guess] <= target){
min = guess+1;
if(guess+1 > best) best = guess+1;
} else{
max = guess-1;
}
}
return best;
}
int main(){
int b;
int i;
int ans[200005];
scanf("%d", &n);
scanf("%d", &m);
for(i=0; i<n; i++) scanf("%d", &a[i]);
mergeSort(0, n-1);
for(i=0; i<m; i++){
scanf("%d", &b);
ans[i] = binarySearch(b);
}
for(i=0; i<m; i++) printf("%d ", ans[i]);
}
| |
You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array a that are less than or equal to the value bj. | Print m integers, separated by spaces: the j-th of which is equal to the number of such elements in array a that are less than or equal to the value bj. | C | e9a519be33f25c828bae787330c18dd4 | cfad2e80bbe6ed5a3c4878cbfe11b6d3 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"data structures",
"two pointers",
"binary search",
"sortings"
] | 1448636400 | ["5 4\n1 3 5 7 9\n6 4 2 8", "5 5\n1 2 1 2 5\n3 1 4 1 5"] | null | PASSED | 1,300 | standard input | 2 seconds | The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the sizes of arrays a and b. The second line contains n integers — the elements of array a ( - 109 ≤ ai ≤ 109). The third line contains m integers — the elements of array b ( - 109 ≤ bj ≤ 109). | ["3 2 1 4", "4 2 4 2 5"] | #include <stdio.h>
void merge(int* arr, int start, int mid, int end) {
int i = start, j = mid + 1, k, aux[end + 1];
for (k = start; k <= end ; k++)
aux[k] = arr[k];
for (k = start; k <= end; k++) {
if (i > mid)
arr[k] = aux[j++];
else if (j > end)
arr[k] = aux[i++];
else if (aux[i] < aux[j])
arr[k] = aux[i++];
else //if (aux[i] >= aux[j])
arr[k] = aux[j++];
}
}
void mergesort(int* arr, int start, int end) {
if (end <= start)
return;
int mid = start + (end - start) / 2;
mergesort(arr, start, mid);
mergesort(arr, mid + 1, end);
merge(arr, start, mid, end);
}
int binary_search(int* arr, int start, int end, int key) {
int mid = start + (end - start) / 2;
if (start >= end)
return ( key >= arr[mid] ? mid + 1 : mid);
if (key < arr[mid])
return binary_search(arr, start, mid - 1, key);
if (key >= arr[mid])
return binary_search(arr, mid + 1, end, key);
}
int main() {
int i, n, m;
scanf("%d %d", &n, &m);
int arr_a[n], arr_b[m];
for (i = 0; i < n; i++)
scanf("%d", &arr_a[i]);
for (i = 0; i < m; i++)
scanf("%d", &arr_b[i]);
mergesort(arr_a, 0, n - 1);
for (i = 0; i < m - 1; i++)
printf("%d ", binary_search(arr_a, 0, n - 1, arr_b[i]));
printf("%d\n", binary_search(arr_a, 0, n - 1, arr_b[i]));
return 0;
}
| |
Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative integers a1, a2, ..., an. He also wrote a square matrix b of size n × n. The element of matrix b that sits in the i-th row in the j-th column (we'll denote it as bij) equals: the "bitwise AND" of numbers ai and aj (that is, bij = ai & aj), if i ≠ j; -1, if i = j. Having written out matrix b, Polycarpus got very happy and wiped a off the blackboard. But the thing is, the teacher will want this sequence to check whether Polycarpus' calculations were correct. Polycarus urgently needs to restore the removed sequence of integers, or else he won't prove that he can count correctly.Help Polycarpus, given matrix b, restore the sequence of numbers a1, a2, ..., an, that he has removed from the board. Polycarpus doesn't like large numbers, so any number in the restored sequence mustn't exceed 109. | Print n non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the sequence that Polycarpus wiped off the board. Separate the numbers by whitespaces. It is guaranteed that there is sequence a that satisfies the problem conditions. If there are multiple such sequences, you are allowed to print any of them. | C | 8f342e167e77088ce47f17e5cd475b17 | f6820c61a82c3f88c76783e38717a9b7 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"greedy"
] | 1353339000 | ["1\n-1", "3\n-1 18 0\n18 -1 0\n0 0 -1", "4\n-1 128 128 128\n128 -1 148 160\n128 148 -1 128\n128 160 128 -1"] | NoteIf you do not know what is the "bitwise AND" operation please read: http://en.wikipedia.org/wiki/Bitwise_operation. | PASSED | 1,500 | standard input | 2 seconds | The first line contains a single integer n (1 ≤ n ≤ 100) — the size of square matrix b. Next n lines contain matrix b. The i-th of these lines contains n space-separated integers: the j-th number represents the element of matrix bij. It is guaranteed, that for all i (1 ≤ i ≤ n) the following condition fulfills: bii = -1. It is guaranteed that for all i, j (1 ≤ i, j ≤ n; i ≠ j) the following condition fulfills: 0 ≤ bij ≤ 109, bij = bji. | ["0", "18 18 0", "128 180 148 160"] | #include <stdio.h>
int main()
{
int a[100];
int e, n, i, j;
scanf("%d", &n);
for (i = 0; i < n; i++) {
a[i] = 0;
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &e);
if (i >= j) {
continue;
}
a[i] |= e;
a[j] |= e;
}
}
for (i = 0; i < n; i++) {
printf("%d ", a[i]);
}
return 0;
} | |
Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative integers a1, a2, ..., an. He also wrote a square matrix b of size n × n. The element of matrix b that sits in the i-th row in the j-th column (we'll denote it as bij) equals: the "bitwise AND" of numbers ai and aj (that is, bij = ai & aj), if i ≠ j; -1, if i = j. Having written out matrix b, Polycarpus got very happy and wiped a off the blackboard. But the thing is, the teacher will want this sequence to check whether Polycarpus' calculations were correct. Polycarus urgently needs to restore the removed sequence of integers, or else he won't prove that he can count correctly.Help Polycarpus, given matrix b, restore the sequence of numbers a1, a2, ..., an, that he has removed from the board. Polycarpus doesn't like large numbers, so any number in the restored sequence mustn't exceed 109. | Print n non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the sequence that Polycarpus wiped off the board. Separate the numbers by whitespaces. It is guaranteed that there is sequence a that satisfies the problem conditions. If there are multiple such sequences, you are allowed to print any of them. | C | 8f342e167e77088ce47f17e5cd475b17 | be4341aac8350c706996f795cf1e971a | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"greedy"
] | 1353339000 | ["1\n-1", "3\n-1 18 0\n18 -1 0\n0 0 -1", "4\n-1 128 128 128\n128 -1 148 160\n128 148 -1 128\n128 160 128 -1"] | NoteIf you do not know what is the "bitwise AND" operation please read: http://en.wikipedia.org/wiki/Bitwise_operation. | PASSED | 1,500 | standard input | 2 seconds | The first line contains a single integer n (1 ≤ n ≤ 100) — the size of square matrix b. Next n lines contain matrix b. The i-th of these lines contains n space-separated integers: the j-th number represents the element of matrix bij. It is guaranteed, that for all i (1 ≤ i ≤ n) the following condition fulfills: bii = -1. It is guaranteed that for all i, j (1 ≤ i, j ≤ n; i ≠ j) the following condition fulfills: 0 ≤ bij ≤ 109, bij = bji. | ["0", "18 18 0", "128 180 148 160"] | #include<stdio.h>
int main(void){
int n,num,i,j,in;
scanf("%d",&n);
for(i=0;i<n;i++){
num=0;
for(j=0;j<n;j++){
scanf("%d",&in);
if(in==-1) continue;
num|=in;
}
printf("%d%c",num,(i==n-1)?'\n':' ');
}
return 0;
}
| |
Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative integers a1, a2, ..., an. He also wrote a square matrix b of size n × n. The element of matrix b that sits in the i-th row in the j-th column (we'll denote it as bij) equals: the "bitwise AND" of numbers ai and aj (that is, bij = ai & aj), if i ≠ j; -1, if i = j. Having written out matrix b, Polycarpus got very happy and wiped a off the blackboard. But the thing is, the teacher will want this sequence to check whether Polycarpus' calculations were correct. Polycarus urgently needs to restore the removed sequence of integers, or else he won't prove that he can count correctly.Help Polycarpus, given matrix b, restore the sequence of numbers a1, a2, ..., an, that he has removed from the board. Polycarpus doesn't like large numbers, so any number in the restored sequence mustn't exceed 109. | Print n non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the sequence that Polycarpus wiped off the board. Separate the numbers by whitespaces. It is guaranteed that there is sequence a that satisfies the problem conditions. If there are multiple such sequences, you are allowed to print any of them. | C | 8f342e167e77088ce47f17e5cd475b17 | 8b1f20e2343bbb806bab7142c25d8aad | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"greedy"
] | 1353339000 | ["1\n-1", "3\n-1 18 0\n18 -1 0\n0 0 -1", "4\n-1 128 128 128\n128 -1 148 160\n128 148 -1 128\n128 160 128 -1"] | NoteIf you do not know what is the "bitwise AND" operation please read: http://en.wikipedia.org/wiki/Bitwise_operation. | PASSED | 1,500 | standard input | 2 seconds | The first line contains a single integer n (1 ≤ n ≤ 100) — the size of square matrix b. Next n lines contain matrix b. The i-th of these lines contains n space-separated integers: the j-th number represents the element of matrix bij. It is guaranteed, that for all i (1 ≤ i ≤ n) the following condition fulfills: bii = -1. It is guaranteed that for all i, j (1 ≤ i, j ≤ n; i ≠ j) the following condition fulfills: 0 ≤ bij ≤ 109, bij = bji. | ["0", "18 18 0", "128 180 148 160"] | #include <stdio.h>
int main(void)
{
unsigned matrix[100][100];
unsigned n;
scanf("%d",&n);
unsigned i,j;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",matrix[i]+j);
unsigned result;
i=0;
result=0;
for(j=0;j<n;j++)
if(i!=j)
result|=matrix[i][j];
printf("%d",result);
for(i=1;i<n;i++){
result=0;
for(j=0;j<n;j++)
if(i!=j)
result|=matrix[i][j];
printf(" %d",result);
}
putchar('\n');
getchar();
getchar();
return 0;
}
| |
Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative integers a1, a2, ..., an. He also wrote a square matrix b of size n × n. The element of matrix b that sits in the i-th row in the j-th column (we'll denote it as bij) equals: the "bitwise AND" of numbers ai and aj (that is, bij = ai & aj), if i ≠ j; -1, if i = j. Having written out matrix b, Polycarpus got very happy and wiped a off the blackboard. But the thing is, the teacher will want this sequence to check whether Polycarpus' calculations were correct. Polycarus urgently needs to restore the removed sequence of integers, or else he won't prove that he can count correctly.Help Polycarpus, given matrix b, restore the sequence of numbers a1, a2, ..., an, that he has removed from the board. Polycarpus doesn't like large numbers, so any number in the restored sequence mustn't exceed 109. | Print n non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the sequence that Polycarpus wiped off the board. Separate the numbers by whitespaces. It is guaranteed that there is sequence a that satisfies the problem conditions. If there are multiple such sequences, you are allowed to print any of them. | C | 8f342e167e77088ce47f17e5cd475b17 | 91a0cfb46ff0b83dfe3bbfcdc3485220 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"greedy"
] | 1353339000 | ["1\n-1", "3\n-1 18 0\n18 -1 0\n0 0 -1", "4\n-1 128 128 128\n128 -1 148 160\n128 148 -1 128\n128 160 128 -1"] | NoteIf you do not know what is the "bitwise AND" operation please read: http://en.wikipedia.org/wiki/Bitwise_operation. | PASSED | 1,500 | standard input | 2 seconds | The first line contains a single integer n (1 ≤ n ≤ 100) — the size of square matrix b. Next n lines contain matrix b. The i-th of these lines contains n space-separated integers: the j-th number represents the element of matrix bij. It is guaranteed, that for all i (1 ≤ i ≤ n) the following condition fulfills: bii = -1. It is guaranteed that for all i, j (1 ≤ i, j ≤ n; i ≠ j) the following condition fulfills: 0 ≤ bij ≤ 109, bij = bji. | ["0", "18 18 0", "128 180 148 160"] | #include<stdio.h>
int n,a[109],x,i,j;
int main()
{
scanf("%d",&n);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
scanf("%d",&x);
if(x>0)
a[i]=a[i]|x;
}
for(i=1;i<=n;i++)
printf("%d ",a[i]);
printf("\n");
return 0;
}
| |
Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative integers a1, a2, ..., an. He also wrote a square matrix b of size n × n. The element of matrix b that sits in the i-th row in the j-th column (we'll denote it as bij) equals: the "bitwise AND" of numbers ai and aj (that is, bij = ai & aj), if i ≠ j; -1, if i = j. Having written out matrix b, Polycarpus got very happy and wiped a off the blackboard. But the thing is, the teacher will want this sequence to check whether Polycarpus' calculations were correct. Polycarus urgently needs to restore the removed sequence of integers, or else he won't prove that he can count correctly.Help Polycarpus, given matrix b, restore the sequence of numbers a1, a2, ..., an, that he has removed from the board. Polycarpus doesn't like large numbers, so any number in the restored sequence mustn't exceed 109. | Print n non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the sequence that Polycarpus wiped off the board. Separate the numbers by whitespaces. It is guaranteed that there is sequence a that satisfies the problem conditions. If there are multiple such sequences, you are allowed to print any of them. | C | 8f342e167e77088ce47f17e5cd475b17 | 343d95dfd5d718637571001065c78855 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"greedy"
] | 1353339000 | ["1\n-1", "3\n-1 18 0\n18 -1 0\n0 0 -1", "4\n-1 128 128 128\n128 -1 148 160\n128 148 -1 128\n128 160 128 -1"] | NoteIf you do not know what is the "bitwise AND" operation please read: http://en.wikipedia.org/wiki/Bitwise_operation. | PASSED | 1,500 | standard input | 2 seconds | The first line contains a single integer n (1 ≤ n ≤ 100) — the size of square matrix b. Next n lines contain matrix b. The i-th of these lines contains n space-separated integers: the j-th number represents the element of matrix bij. It is guaranteed, that for all i (1 ≤ i ≤ n) the following condition fulfills: bii = -1. It is guaranteed that for all i, j (1 ≤ i, j ≤ n; i ≠ j) the following condition fulfills: 0 ≤ bij ≤ 109, bij = bji. | ["0", "18 18 0", "128 180 148 160"] | #include<stdio.h>
#include<stdlib.h>
long a[105]={0};
int main()
{
int i,j,n;
long x;
scanf("%d",&n);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
scanf("%ld",&x);
if(x>0)
a[i]=a[i]|x;
}
for(i=1;i<=n;i++)
printf("%ld ",a[i]);
//system("pause");
return 0;
}
| |
Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative integers a1, a2, ..., an. He also wrote a square matrix b of size n × n. The element of matrix b that sits in the i-th row in the j-th column (we'll denote it as bij) equals: the "bitwise AND" of numbers ai and aj (that is, bij = ai & aj), if i ≠ j; -1, if i = j. Having written out matrix b, Polycarpus got very happy and wiped a off the blackboard. But the thing is, the teacher will want this sequence to check whether Polycarpus' calculations were correct. Polycarus urgently needs to restore the removed sequence of integers, or else he won't prove that he can count correctly.Help Polycarpus, given matrix b, restore the sequence of numbers a1, a2, ..., an, that he has removed from the board. Polycarpus doesn't like large numbers, so any number in the restored sequence mustn't exceed 109. | Print n non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the sequence that Polycarpus wiped off the board. Separate the numbers by whitespaces. It is guaranteed that there is sequence a that satisfies the problem conditions. If there are multiple such sequences, you are allowed to print any of them. | C | 8f342e167e77088ce47f17e5cd475b17 | ddd2790df99da0dedb37f6730cf93e7b | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"greedy"
] | 1353339000 | ["1\n-1", "3\n-1 18 0\n18 -1 0\n0 0 -1", "4\n-1 128 128 128\n128 -1 148 160\n128 148 -1 128\n128 160 128 -1"] | NoteIf you do not know what is the "bitwise AND" operation please read: http://en.wikipedia.org/wiki/Bitwise_operation. | PASSED | 1,500 | standard input | 2 seconds | The first line contains a single integer n (1 ≤ n ≤ 100) — the size of square matrix b. Next n lines contain matrix b. The i-th of these lines contains n space-separated integers: the j-th number represents the element of matrix bij. It is guaranteed, that for all i (1 ≤ i ≤ n) the following condition fulfills: bii = -1. It is guaranteed that for all i, j (1 ≤ i, j ≤ n; i ≠ j) the following condition fulfills: 0 ≤ bij ≤ 109, bij = bji. | ["0", "18 18 0", "128 180 148 160"] | #include <stdio.h>
#include <stdlib.h>
int n,b[101]={0};
int main()
{ int i,j,k,l;
scanf("%d",&n);
i=0;j=0;
for(i=0;i<n;i++)
{ for(j=0;j<n;j++)
{ scanf("%d",&k);
if(k>0) b[i]=b[i]|k;
}
}
for(i=0;i<n;i++) printf("%d ",b[i]);
return 0;
}
| |
Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative integers a1, a2, ..., an. He also wrote a square matrix b of size n × n. The element of matrix b that sits in the i-th row in the j-th column (we'll denote it as bij) equals: the "bitwise AND" of numbers ai and aj (that is, bij = ai & aj), if i ≠ j; -1, if i = j. Having written out matrix b, Polycarpus got very happy and wiped a off the blackboard. But the thing is, the teacher will want this sequence to check whether Polycarpus' calculations were correct. Polycarus urgently needs to restore the removed sequence of integers, or else he won't prove that he can count correctly.Help Polycarpus, given matrix b, restore the sequence of numbers a1, a2, ..., an, that he has removed from the board. Polycarpus doesn't like large numbers, so any number in the restored sequence mustn't exceed 109. | Print n non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the sequence that Polycarpus wiped off the board. Separate the numbers by whitespaces. It is guaranteed that there is sequence a that satisfies the problem conditions. If there are multiple such sequences, you are allowed to print any of them. | C | 8f342e167e77088ce47f17e5cd475b17 | dc21e0cff2be7dab2b7760ee2e4fc837 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"greedy"
] | 1353339000 | ["1\n-1", "3\n-1 18 0\n18 -1 0\n0 0 -1", "4\n-1 128 128 128\n128 -1 148 160\n128 148 -1 128\n128 160 128 -1"] | NoteIf you do not know what is the "bitwise AND" operation please read: http://en.wikipedia.org/wiki/Bitwise_operation. | PASSED | 1,500 | standard input | 2 seconds | The first line contains a single integer n (1 ≤ n ≤ 100) — the size of square matrix b. Next n lines contain matrix b. The i-th of these lines contains n space-separated integers: the j-th number represents the element of matrix bij. It is guaranteed, that for all i (1 ≤ i ≤ n) the following condition fulfills: bii = -1. It is guaranteed that for all i, j (1 ≤ i, j ≤ n; i ≠ j) the following condition fulfills: 0 ≤ bij ≤ 109, bij = bji. | ["0", "18 18 0", "128 180 148 160"] | #include<stdio.h>
#include<string.h>
long n,a[200][200]={0};
long shu[200][150]={0},len[200]={0};
long mi(long k)
{
int ans=1,i;
for(i=0;i<k;i++)
ans*=2;
return ans;
}
int main()
{
long i,j,t,k;
scanf("%ld",&n);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{scanf("%ld",&a[i][j]);
k=a[i][j];
t=0;
while(k>0)
{
if(k%2==1)
{
shu[i][t]=1; shu[j][t]=1;
len[i]=len[i]>t?len[i]:t;
len[j]=len[j]>t?len[j]:t;
}
t++;
k=k/2;
}
}
for(i=0;i<n;i++)
{
t=0;
for(j=0;j<=len[i];j++)
t+=shu[i][j]*mi(j);
printf("%ld ",t);
}
printf("\n");
return 0;
}
| |
Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative integers a1, a2, ..., an. He also wrote a square matrix b of size n × n. The element of matrix b that sits in the i-th row in the j-th column (we'll denote it as bij) equals: the "bitwise AND" of numbers ai and aj (that is, bij = ai & aj), if i ≠ j; -1, if i = j. Having written out matrix b, Polycarpus got very happy and wiped a off the blackboard. But the thing is, the teacher will want this sequence to check whether Polycarpus' calculations were correct. Polycarus urgently needs to restore the removed sequence of integers, or else he won't prove that he can count correctly.Help Polycarpus, given matrix b, restore the sequence of numbers a1, a2, ..., an, that he has removed from the board. Polycarpus doesn't like large numbers, so any number in the restored sequence mustn't exceed 109. | Print n non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the sequence that Polycarpus wiped off the board. Separate the numbers by whitespaces. It is guaranteed that there is sequence a that satisfies the problem conditions. If there are multiple such sequences, you are allowed to print any of them. | C | 8f342e167e77088ce47f17e5cd475b17 | 90dda7279b94d6d0118e577a3e1782bd | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"constructive algorithms",
"greedy"
] | 1353339000 | ["1\n-1", "3\n-1 18 0\n18 -1 0\n0 0 -1", "4\n-1 128 128 128\n128 -1 148 160\n128 148 -1 128\n128 160 128 -1"] | NoteIf you do not know what is the "bitwise AND" operation please read: http://en.wikipedia.org/wiki/Bitwise_operation. | PASSED | 1,500 | standard input | 2 seconds | The first line contains a single integer n (1 ≤ n ≤ 100) — the size of square matrix b. Next n lines contain matrix b. The i-th of these lines contains n space-separated integers: the j-th number represents the element of matrix bij. It is guaranteed, that for all i (1 ≤ i ≤ n) the following condition fulfills: bii = -1. It is guaranteed that for all i, j (1 ≤ i, j ≤ n; i ≠ j) the following condition fulfills: 0 ≤ bij ≤ 109, bij = bji. | ["0", "18 18 0", "128 180 148 160"] | #include <stdio.h>
int b[100][100];
int a[100];
void solve(int n)
{
int i, j, k;
for (i = 0; i < n; i ++)
{
a[i] = 0;
for (j = 0; j < 30; j ++)
{
for (k = 0; k < n; k ++)
{
if (k != i)
{
if (b[i][k] & (1 << j))
{
a[i] |= (1 << j);
break;
}
}
}
}
}
for (i = 0; i < n - 1; i ++)
{
printf("%d ", a[i]);
}
printf("%d\n", a[i]);
}
int main()
{
int n, i, j;
while (scanf("%d", &n) == 1)
{
for (i = 0; i < n; i ++)
{
for (j = 0; j < n; j ++)
{
scanf("%d", &b[i][j]);
}
}
solve(n);
}
return 0;
} | |
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle. Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code. | Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists. | C | 819d3694fccf2b5af0ec3b4ee429dbb3 | 323664b18aa926916dcdd846af9f66b1 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["5\n3 5\n1 4\n2 4\n1 5\n2 3", "3\n2 3\n3 1\n1 2"] | null | PASSED | 1,600 | standard input | 3 seconds | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order. | ["3 2 4 1 5", "3 1 2"] | #include <stdio.h>
int n;
int arr[300000][2];
int out[300000];
int main()
{
int n1, n2;
int buf;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
scanf("%d %d", &arr[i][0], &arr[i][1]);
}
if (n == 3)
{
for (int i = 1; i <= n; i++)
{
out[i] = i % n + 1;
}
}
else
{
for (int i = 1; i <= n; i++)
{
n1 = arr[i][0];
n2 = arr[i][1];
if (arr[n1][0] == n2 || arr[n1][1] == n2)
{
if (arr)
out[i] = n1;
}
else
{
out[i] = n2;
}
}
}
buf = 1;
for (int i = 1; i <= n; i++)
{
printf("%d ", out[buf]);
buf = out[buf];
}
return 0;
} | |
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle. Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code. | Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists. | C | 819d3694fccf2b5af0ec3b4ee429dbb3 | 82e860f99380295614c2a3e7157c5bd1 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["5\n3 5\n1 4\n2 4\n1 5\n2 3", "3\n2 3\n3 1\n1 2"] | null | PASSED | 1,600 | standard input | 3 seconds | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order. | ["3 2 4 1 5", "3 1 2"] | /* > < */
#include <stdio.h>
#define MAXN 200003
static int n, a[MAXN][2];
static _Bool vis[MAXN] = { 0 };
int main()
{
int i;
scanf("%d", &n);
for (i = 0; i < n; ++i) {
scanf("%d%d", &a[i][0], &a[i][1]);
a[i][0]--;
a[i][1]--;
}
if (n == 3) {
puts("1 2 3");
} else {
if (a[a[0][1]][0] == a[0][0] || a[a[0][1]][1] == a[0][0]) {
int t = a[0][0];
a[0][0] = a[0][1];
a[0][1] = t;
}
printf("1 %d", a[0][0] + 1);
int l2 = 0, l1 = a[0][0];
for (i = 2; i < n; ++i) {
int new = a[l2][0] + a[l2][1] - l1;
l2 = l1;
l1 = new;
printf(" %d", l1 + 1);
}
putchar('\n');
}
return 0;
}
| |
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle. Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code. | Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists. | C | 819d3694fccf2b5af0ec3b4ee429dbb3 | a7b31a0ef73251e689ea0544f15c0c70 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["5\n3 5\n1 4\n2 4\n1 5\n2 3", "3\n2 3\n3 1\n1 2"] | null | PASSED | 1,600 | standard input | 3 seconds | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order. | ["3 2 4 1 5", "3 1 2"] | #include <stdio.h>
int main()
{
long long int n;
scanf("%I64d",&n);
long long int a[n+1],b[n+1];
a[0]=0;
b[0]=0;
for (long long int i=1;i<=n;i++)
scanf("%I64d %I64d",&a[i],&b[i]);
long long int s[n+1];
s[0]=0;
long long int z=1;
s[z]=1;
z++;
long long int i=1;
while(z<=n)
{
if (a[a[i]]==b[i] || b[a[i]]==b[i])
{
s[z]=a[i];
z++;
s[z]=b[i];
z++;
s[z]=a[a[i]]+b[a[i]]-s[z-1];
z++;
s[z]=a[b[i]]+b[b[i]]-s[z-1];
z++;
i=s[z-1];
}
else
{
s[z]=b[i];
z++;
s[z]=a[i];
z++;
s[z]=a[b[i]]+b[b[i]]-s[z-1];
z++;
s[z]=a[a[i]]+b[a[i]]-s[z-1];
z++;
i=s[z-1];
}
}
for (long long int j=1;j<=n;j++)
printf("%I64d ",s[j]);
return 0;
} | |
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle. Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code. | Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists. | C | 819d3694fccf2b5af0ec3b4ee429dbb3 | 0554fdc9b7a12236fbe4917162a94268 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["5\n3 5\n1 4\n2 4\n1 5\n2 3", "3\n2 3\n3 1\n1 2"] | null | PASSED | 1,600 | standard input | 3 seconds | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order. | ["3 2 4 1 5", "3 1 2"] | #include <stdlib.h>
#include <stdio.h>
typedef struct data {
int neg1;
int neg2;
}data;
int main() {
data *d;
int *a, x, y, i, n;
scanf("%d", &n);
d = (data *) malloc(sizeof(data) * n);
for(i = 0; i < n; i++)
scanf("%d%d", &d[i].neg1, &d[i].neg2);
a = (int *) malloc(sizeof(int) * n);
a[0] = 1;
x = d[0].neg1;
y = d[0].neg2;
if(d[x - 1].neg1 == y || d[x - 1].neg2 == y) {
a[1] = x;
a[2] = y;
}
else {
a[1] = y;
a[2] = x;
}
for(i = 1; i < n - 2; i++) {
x = d[a[i] - 1].neg1;
y = d[a[i] - 1].neg2;
if(a[i + 1] == x)
a[i + 2] = y;
else
a[i + 2] = x;
}
for(i = 0; i < n; i++)
printf("%d ", a[i]);
return 0;
}
| |
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle. Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code. | Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists. | C | 819d3694fccf2b5af0ec3b4ee429dbb3 | 5682aa304de6553ee0cfaad4414693b0 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["5\n3 5\n1 4\n2 4\n1 5\n2 3", "3\n2 3\n3 1\n1 2"] | null | PASSED | 1,600 | standard input | 3 seconds | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order. | ["3 2 4 1 5", "3 1 2"] | #include <stdio.h>
#include <string.h>
#define SWAP(x, y) (x ^= y ^= x ^= y)
#define MAXN 200000
int order[MAXN + 1] = {0, 1};
int rule[MAXN + 1][2];
int main()
{
int N;
scanf("%d", &N);
for ( int i = 1; i <= N; i++)
scanf("%d%d", &rule[i][0], &rule[i][1]);
memset(order, 0, sizeof(order));
order[1] = 1;
for ( int i = 1; i <= N - 2; i += 2) {
order[i+1] = rule[order[i]][0];
order[i+2] = rule[order[i]][1];
if ( rule[order[i+1]][0] != order[i+2] && rule[order[i+1]][1] != order[i+2] )
SWAP(order[i+1], order[i+2]);
}
if ( order[N] == 0 ) {
order[N] = rule[order[N-1]][ rule[order[N-1]][0] == 1 ? 1 : 0 ];
}
for ( int i = 1; i <= N; i++)
printf("%d%c", order[i], " \n"[i == N]);
} | |
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle. Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code. | Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists. | C | 819d3694fccf2b5af0ec3b4ee429dbb3 | aeddc0fe0c0fc21a53da790b19b83292 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["5\n3 5\n1 4\n2 4\n1 5\n2 3", "3\n2 3\n3 1\n1 2"] | null | PASSED | 1,600 | standard input | 3 seconds | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order. | ["3 2 4 1 5", "3 1 2"] | #include<stdio.h>
int main(){
int n,i,j,k,count=0;
scanf("%d",&n);
int a[n][2],b[n][2],c[n+1];
for(i=0;i<n;i++){
scanf("%d%d",&a[i][0],&a[i][1]);
b[i][1]=a[i][0];b[i][0]=a[i][1];
}
i=0;
while(count<n){
if(a[a[i][0]-1][0]==a[i][1]){
c[count]=a[i][0];
count++;
i=(a[i][0]-1);
}
else if(a[b[i][0]-1][0]==b[i][1]){
c[count]=b[i][0];
count++;
i=(b[i][0]-1);
}
else if(b[a[i][0]-1][0]==a[i][1]){
c[count]=a[i][0];
count++;
i=(a[i][0]-1);
}
else if(b[b[i][0]-1][0]==b[i][1]){
c[count]=b[i][0];
count++;
i=(b[i][0]-1);
}
// printf("c[%d]:%d,count:%d,i:%d\n",(count-1),c[count-1],i);
}
for(i=0;i<count;i++)
printf("%d ",c[i]);
return 0;
} | |
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle. Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code. | Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists. | C | 819d3694fccf2b5af0ec3b4ee429dbb3 | b5726131bda147f2b538e11112752728 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["5\n3 5\n1 4\n2 4\n1 5\n2 3", "3\n2 3\n3 1\n1 2"] | null | PASSED | 1,600 | standard input | 3 seconds | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order. | ["3 2 4 1 5", "3 1 2"] | #include <stdio.h>
#include <stdint.h>
uint32_t n;
uint32_t a[200002];
uint32_t a1[200002];
uint32_t a2[200002];
int main() {
uint32_t i, j;
scanf("%d", &n);
for(i = 1; i <= n; i++)
scanf("%d%d", a1+i, a2+i);
//
a[2] = 1;
for(i = 1; i <= n; i++) {
if(a1[i] == 1 || a2[i] == 1) {
j = a1[i] == 1 ? a2[i] : a1[i];
if(a1[j] == 1 || a2[j] == 1) {
a[1] = j;
a[3] = a1[j] == 1 ? a2[j] : a1[j];
} else {
a[1] = i;
a[3] = j;
}
break;
}
}
//
for(i = 4; i <= n; i++)
a[i] = a1[a[i-2]] == a[i-1] ? a2[a[i-2]] : a1[a[i-2]];
//
for(i = 1; i <= n; i++)
printf("%d ", a[i]);
}
| |
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle. Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code. | Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists. | C | 819d3694fccf2b5af0ec3b4ee429dbb3 | fa419b2a89205c2f07666e6487ccb6ee | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["5\n3 5\n1 4\n2 4\n1 5\n2 3", "3\n2 3\n3 1\n1 2"] | null | PASSED | 1,600 | standard input | 3 seconds | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order. | ["3 2 4 1 5", "3 1 2"] | #include <stdio.h>
#define N 200000
int main() {
static int ii[N], jj[N], aa[N][2], kk[N];
int n, h, i, j;
scanf("%d", &n);
if (n == 3) {
printf("1 2 3\n");
return 0;
}
for (h = 0; h < n; h++) {
scanf("%d%d", &i, &j), i--, j--;
ii[h] = i;
jj[h] = j;
aa[i][kk[i]++] = j;
aa[j][kk[j]++] = i;
}
h = 0;
do
printf("%d ", (h = aa[ii[h]][0] == h || aa[ii[h]][1] == h ? ii[h] : jj[h]) + 1);
while (h != 0);
printf("\n");
return 0;
}
| |
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle. Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code. | Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists. | C | 819d3694fccf2b5af0ec3b4ee429dbb3 | 28875eadb24c3f886b751fc14ae6d6ac | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["5\n3 5\n1 4\n2 4\n1 5\n2 3", "3\n2 3\n3 1\n1 2"] | null | PASSED | 1,600 | standard input | 3 seconds | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order. | ["3 2 4 1 5", "3 1 2"] | #include <stdio.h>
#include <stdlib.h>
int main(){
int n, i, j = 0;
scanf("%d", &n);
int arr[n][2];
for(i=0;i<n;++i){
scanf("%d %d",&arr[i+1][0],&arr[i+1][1]);
}
i = arr[1][0];
j = arr[1][1];
printf("1 ");
int fl = 0, k;
if(arr[i][0]==j){ fl=1; k=1;}
else if(arr[i][1]==j) {fl=1; k=0;}
if(fl==1) printf("%d ",i);
else printf("%d ",j);
if(fl!=1 && arr[j][0]==i) k = 1;
else if (fl!=1) k = 0;
if(fl!=1){
int r = j;
j =i;
i = r;
}
int z = 2;
while(z<n){
printf("%d ", j);
z++;
int r = j;
j = arr[i][k];
i = r;
if(arr[i][0]==j) k = 1;
else k = 0;
}
printf("\n");
return 0;
}
| |
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle. Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code. | Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists. | C | 819d3694fccf2b5af0ec3b4ee429dbb3 | 31a1c60a6e6a1c20d15fc124242547c7 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["5\n3 5\n1 4\n2 4\n1 5\n2 3", "3\n2 3\n3 1\n1 2"] | null | PASSED | 1,600 | standard input | 3 seconds | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order. | ["3 2 4 1 5", "3 1 2"] | #include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
int a[n+1][2], b[n+1], q=1, i=1;
for (int i = 1; i < n+1; ++i)
{
scanf("%d%d", &a[i][0], &a[i][1]);
}
b[q]=1;
q++;
if(a[i][0]==a[a[i][1]][0]||a[i][0]==a[a[i][1]][1])
{
b[q]=a[i][1];
q++;
b[q]=a[i][0];
q++;
}
else
{
b[q]=a[i][0];
q++;
b[q]=a[i][1];
q++;
}
while(q!=n+1)
{
if(a[b[q-2]][0]==b[q-1])
{
b[q]=a[b[q-2]][1];
q++;
}
else
{
b[q]=a[b[q-2]][0];
q++;
}
}
for (int i = 1; i < n+1; ++i)
{
printf("%d ", b[i]);
}
}
| |
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle. Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code. | Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists. | C | 819d3694fccf2b5af0ec3b4ee429dbb3 | 1b37a5e691c2d19e5dc2eddf29c19343 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["5\n3 5\n1 4\n2 4\n1 5\n2 3", "3\n2 3\n3 1\n1 2"] | null | PASSED | 1,600 | standard input | 3 seconds | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order. | ["3 2 4 1 5", "3 1 2"] | #include <stdio.h>
#include <limits.h>
#include <stdlib.h>
int main(){
int n;
scanf("%d",&n);
int ans[n+5];
int a[n+5];
int b[n+5];
for (int i = 1; i <=n ; ++i) {
scanf("%d%d",&a[i],&b[i]);
}
ans[1]=1;
ans[2]=a[1];
ans[3]=b[1];
if(a[a[1]]!=b[1] && b[a[1]]!=b[1]){
ans[2]=b[1];
ans[3]=a[1];
}
int place=3;
while(place<n){
if(a[ans[place-1]]==ans[place]) ans[place+1]=b[ans[place-1]];
else ans[place+1]=a[ans[place-1]];
place++;
}
for (int i = 1; i <=n ; ++i) {
printf("%d ",ans[i]);
}
printf("\n");
return 0;
} | |
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle. Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code. | Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists. | C | 819d3694fccf2b5af0ec3b4ee429dbb3 | c37609d3dd6e6801a7d1108605f57dff | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["5\n3 5\n1 4\n2 4\n1 5\n2 3", "3\n2 3\n3 1\n1 2"] | null | PASSED | 1,600 | standard input | 3 seconds | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order. | ["3 2 4 1 5", "3 1 2"] | #include<stdio.h>
int k,i,j,a,b,sayac=0;
int dizi[200000][2];
void bunratax(int lo){
static int ol=0;
if(ol==k){
}
else{
sayac=1 ;
printf("%d ",lo);
int l1=dizi[lo][0];
int l2=dizi[lo][1];
if((dizi[l1][0]==l2 || dizi[l1][1]==l2)&&l1!=1){
ol++ ;
bunratax(l1);
}
else{
ol++ ;
bunratax(l2);
}
}
}
int main(){
scanf("%d",&k);
for(i=1;i<=k;i++){
scanf("%d %d",&a,&b);
dizi[i][0]=a ;
dizi[i][1]=b ;
}
bunratax(1);
} | |
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle. Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code. | Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists. | C | 819d3694fccf2b5af0ec3b4ee429dbb3 | ee6b64e996af5d2a125a0a8764c50533 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["5\n3 5\n1 4\n2 4\n1 5\n2 3", "3\n2 3\n3 1\n1 2"] | null | PASSED | 1,600 | standard input | 3 seconds | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order. | ["3 2 4 1 5", "3 1 2"] | #include<stdio.h>
int main()
{
int n,i,j,next;
int a[200001][3]={0};
scanf("%d",&n);
for(i=1;i<n+1;i++)scanf("%d %d", &a[i][0],&a[i][1]);
j=1;
if(a[a[j][0]][0]==a[j][1]||a[a[j][0]][1]==a[j][1])a[j][2]=a[j][0];
else a[j][2]=a[j][1];
next=a[j][0]+a[j][1]-a[j][2];
j=a[j][2];
//printf("%d\n",j);
for(i=1;i<n;i++){
a[j][2]=next;
next=a[j][0]+a[j][1]-next;
j=a[j][2];
//printf("%d\n",j);
}
j=1;
printf("%d",a[j][2]);
j=a[j][2];
for(i=1;i<n;i++){
printf(" %d",a[j][2]);
j=a[j][2];
}
} | |
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle. Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code. | Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists. | C | 819d3694fccf2b5af0ec3b4ee429dbb3 | 2c0fc972a62b6c1cd94ec2b98e0ef86a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["5\n3 5\n1 4\n2 4\n1 5\n2 3", "3\n2 3\n3 1\n1 2"] | null | PASSED | 1,600 | standard input | 3 seconds | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order. | ["3 2 4 1 5", "3 1 2"] | #include <stdio.h>
#define N 200001
int vis[N];
int main () {
static int a[N][2];
int n, i, j, next;
scanf ("%d", &n);
for (i = 1; i <= n; i++) {
scanf ("%d%d", &a[i][0], &a[i][1]);
}
next = 1;
while (n--) {
printf("%d ", next);
vis[next] = 1;
i = a[next][0], j = a[next][1];
if (vis[i]) {
next = j;
continue;
}
if (vis[j]) {
next = i;
continue;
}
if (a[j][0] == i || a[j][1] == i) {
next = j;
}
else {
next = i;
}
}
return 0;
} | |
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle. Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code. | Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists. | C | 819d3694fccf2b5af0ec3b4ee429dbb3 | c6be420cec5e0cd6031ea8319e7fc022 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["5\n3 5\n1 4\n2 4\n1 5\n2 3", "3\n2 3\n3 1\n1 2"] | null | PASSED | 1,600 | standard input | 3 seconds | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order. | ["3 2 4 1 5", "3 1 2"] | #include <stdio.h>
typedef struct kid
{
int kid1;
int kid2;
}kid;
kid kids[200000] = {0};
int flags[200000] = {0};
int result[200000] = {0};
int check(int kid, int other)
{
if (kids[kid - 1].kid1 == other || kids[kid - 1].kid2 == other)
{
return 1;
}
return 0;
}
int main()
{
int n = 0;
int kid1 = 0;
int kid2 = 0;
scanf("%d", &n);
for (int i = 0;i < n;++i)
{
scanf("%d %d", &kids[i].kid1, &kids[i].kid2);
}
int num = n;
int p = 0;
result[p] = 1;
flags[p] = 1;
++p;
n--;
while (n > 1)
{
kid1 = kids[result[p - 1] - 1].kid1;
kid2 = kids[result[p - 1] - 1].kid2;
// printf("kid1:%d kid2:%d\n", kid1, kid2);
// printf("kid1's children:%d %d\n", kids[kid1 - 1].kid1, kids[kid1 - 1].kid2);
if (check(kid1, kid2))
{
result[p++] = kid1;
result[p++] = kid2;
n -= 2;
flags[kid1 - 1] = 1;
flags[kid2 - 1] = 1;
}
else
{
result[p++] = kid2;
result[p++] = kid1;
n -= 2;
flags[kid2 - 1] = 1;
flags[kid1 - 1] = 1;
}
}
if (n == 1)
{
for (int i = 0;i < num;++i)
{
if (flags[i] != 1)
{
result[p++] = i + 1;
}
}
}
for (int i = 0;i < num - 1;++i)
{
printf("%d ", result[i]);
}
printf("%d\n", result[num - 1]);
return 0;
} | |
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle. Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code. | Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists. | C | 819d3694fccf2b5af0ec3b4ee429dbb3 | 41bb4f60d10dc7f32759e1ecf480bd47 | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["5\n3 5\n1 4\n2 4\n1 5\n2 3", "3\n2 3\n3 1\n1 2"] | null | PASSED | 1,600 | standard input | 3 seconds | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order. | ["3 2 4 1 5", "3 1 2"] | #include <stdio.h>
int order(int a[][2], int i);
int main()
{
int n, i, j = 1;
scanf("%d", &n);
int a[n + 1][2];
for(i = 1; i <= n; i++)
scanf("%d%d", &a[i][0], &a[i][1]);
printf("1 ");
if(n != 3)
for(i = 1; i <= n - 1; i++)
{
printf("%d ", order(a, j));
j = order(a, j);
}
else if(n == 3)
{
if(a[a[1][0]][0] == a[1][1] || a[a[1][0]][1] == a[1][1])
printf("%d %d", a[1][0], a[1][1]);
else
printf("%d %d", a[1][1], a[1][0]);
}
return 0;
}
int order(int a[][2], int i)
{
if(a[a[i][0]][0] == a[i][1] || a[a[i][0]][1] == a[i][1])
return a[i][0];
else
return a[i][1];
}
| |
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle. Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code. | Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists. | C | 819d3694fccf2b5af0ec3b4ee429dbb3 | fe1a53e54ac415bc351326ad4e6479ee | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["5\n3 5\n1 4\n2 4\n1 5\n2 3", "3\n2 3\n3 1\n1 2"] | null | PASSED | 1,600 | standard input | 3 seconds | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order. | ["3 2 4 1 5", "3 1 2"] | #include <stdlib.h>
#include <stdio.h>
int get_int();
int max(int a, int b)
{
if (a > b)
{
return a;
}
return b;
}
int min(int a, int b)
{
if (a < b)
{
return a;
}
return b;
}
int cmp(const void* p1, const void* p2)
{
return *(int*)p1 - *(int*)p2;
}
typedef struct
{
int x, y;
} par;
int main()
{
int i;
int n = get_int();
par a[n];
int b[n];
for (i = 0; i < n; i++)
{
a[i].x = get_int() - 1;
a[i].y = get_int() - 1;
}
b[0] = 0;
if (a[a[0].x].x == a[0].y || a[a[0].x].y == a[0].y)
{
b[1] = a[0].x;
b[2] = a[0].y;
}
else
{
b[1] = a[0].y;
b[2] = a[0].x;
}
for (i = 3; i < n; i++)
{
int x = a[b[i - 2]].x;
int y = a[b[i - 2]].y;
//printf(">> %d %d %d\n", i, x, y);
if (x == b[i - 1])
{
b[i] = y;
}
else
{
b[i] = x;
}
}
for (i = 0; i < n; i++)
{
printf("%d ", b[i] + 1);
}
printf("\n");
return 0;
}
int get_int()
{
int ret = 0;
char c = getchar();
int sgn;
while (1)
{
if (c == EOF)
{
return EOF;
}
if (c >= '0' && c <= '9')
{
sgn = 1;
break;
}
if (c == '-')
{
c = getchar();
if (c < '0' || c > '9')
{
continue;
}
sgn = -1;
break;
}
c = getchar();
}
while (1)
{
ret = (ret << 3) + (ret << 1) + c - '0';
c = getchar();
if (c < '0' || c > '9')
{
return sgn*ret;
}
}
}
| |
There are $$$n$$$ kids, numbered from $$$1$$$ to $$$n$$$, dancing in a circle around the Christmas tree. Let's enumerate them in a clockwise direction as $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ (all these numbers are from $$$1$$$ to $$$n$$$ and are distinct, so $$$p$$$ is a permutation). Let the next kid for a kid $$$p_i$$$ be kid $$$p_{i + 1}$$$ if $$$i < n$$$ and $$$p_1$$$ otherwise. After the dance, each kid remembered two kids: the next kid (let's call him $$$x$$$) and the next kid for $$$x$$$. Each kid told you which kids he/she remembered: the kid $$$i$$$ remembered kids $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$. However, the order of $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ can differ from their order in the circle. Example: 5 kids in a circle, $$$p=[3, 2, 4, 1, 5]$$$ (or any cyclic shift). The information kids remembered is: $$$a_{1,1}=3$$$, $$$a_{1,2}=5$$$; $$$a_{2,1}=1$$$, $$$a_{2,2}=4$$$; $$$a_{3,1}=2$$$, $$$a_{3,2}=4$$$; $$$a_{4,1}=1$$$, $$$a_{4,2}=5$$$; $$$a_{5,1}=2$$$, $$$a_{5,2}=3$$$. You have to restore the order of the kids in the circle using this information. If there are several answers, you may print any. It is guaranteed that at least one solution exists.If you are Python programmer, consider using PyPy instead of Python when you submit your code. | Print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ — permutation of integers from $$$1$$$ to $$$n$$$, which corresponds to the order of kids in the circle. If there are several answers, you may print any (for example, it doesn't matter which kid is the first in the circle). It is guaranteed that at least one solution exists. | C | 819d3694fccf2b5af0ec3b4ee429dbb3 | ab96572fd123ded1016e8f1d4853552a | GNU C11 | standard output | 256 megabytes | train_001.jsonl | [
"implementation"
] | 1545921300 | ["5\n3 5\n1 4\n2 4\n1 5\n2 3", "3\n2 3\n3 1\n1 2"] | null | PASSED | 1,600 | standard input | 3 seconds | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of the kids. The next $$$n$$$ lines contain $$$2$$$ integers each. The $$$i$$$-th line contains two integers $$$a_{i, 1}$$$ and $$$a_{i, 2}$$$ ($$$1 \le a_{i, 1}, a_{i, 2} \le n, a_{i, 1} \ne a_{i, 2}$$$) — the kids the $$$i$$$-th kid remembered, given in arbitrary order. | ["3 2 4 1 5", "3 1 2"] | #include <stdio.h>
int remember[300005][2];
int used[300005];
int main(int argc, char const *argv[])
{
int N;
scanf("%d",&N);
for (int i = 1; i <= N; ++i)
{
scanf("%d%d",&remember[i][0],&remember[i][1]);
used[i] = 0;
}
int cur=1;
for (int i = 0; i < N; ++i)
{
printf("%d ",cur );
used[cur] = 1;
if((used[remember[cur][0]]==0)&&((remember[remember[cur][0]][0] == remember[cur][1] )||( remember[remember[cur][0]][1] == remember[cur][1])))
cur = remember[cur][0];
else if((used[remember[cur][1]]==0)&&((remember[remember[cur][1]][0] == remember[cur][0] )||( remember[remember[cur][1]][1] == remember[cur][0])))
cur = remember[cur][1];
}
return 0;
} | |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 71e1e376306b0af520ef0b90c01ac1e3 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include <stdio.h>
#include <math.h>
int main(){
int n,ans=-1000001;
double m;
scanf("%d",&n);
for(int i = 0; i<n;++i){
scanf("%lf",&m);
if(m<0 && m>ans){
ans = m;
}
if(((sqrt(m) - ((int) sqrt(m))) != 0.0) && m > ans){
ans = m;
}
}
printf("%d\n",ans);
return 0;
} | |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 1812911efcfa779e8695f38dfa09e195 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include<stdio.h>
#include<math.h>
int main()
{
int n,a;
scanf("%d",&n);
int max=-10000000;
double temp_1;
double temp_2;
while(n>0)
{
n--;
scanf("%d",&a);
if(a<0)
max=max>a?max:a;
else
{
temp_1=sqrt(a);
temp_2=(double)(int)temp_1;
if(temp_1!=temp_2)
max=max>a?max:a;
}
}
printf("%d\n",max);
return 0;
} | |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 4a547833169544f4ea48bbf31d9651fa | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include<stdio.h>
#include<math.h>
int main()
{
long long int n,a,s,m=-1,x=-1000000,i,p=0,q=0;
scanf("%I64d",&n);
for(i=1;i<=n;i++)
{
scanf("%I64d",&a);
if(a>=0)
{
s=sqrt(a);
if(a!=(s*s))
{
if(a>m)
m=a;
q=1;
}
}
else if(a<0)
{
if(a>x)
x=a;
p=1;
}
}
if(p==1&&q==1){
if(x>m)
printf("%d\n",x);
else
printf("%d\n",m);
}
else if(p==1&&q==0)
{
printf("%d\n",x);
}
else if(p==0&&q==1)
printf("%d\n",m);
else
printf("0\n");
return 0;
}
| |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 396967f76081efb0d903787f0e3e42c3 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int n;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
int largest=-10000000;
for(int i=0;i<n;i++)
{
int x;
int j=1;
if(a[i]>0)
{
x=a[i];
while( x>0 )
{
x-=j;
j=j+2;
}
}
else
x=a[i];
if( x!=0 && largest<a[i] )
largest=a[i];
}
printf("%d\n",largest);
}
| |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 783a692bbd97d29c2e239e133550823d | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include<stdio.h>
int f(int n)
{
if(n==0)
return 1;
int x,i,k=0;
for(x=1;x*x<=n;x++)
{
if(x*x==n)
k=1;
}
return k;
}
int main()
{
int t,p,q,r=0,max=0;
scanf("%d",&t);
int a[t+1][3],b[t];
for(p=0;p<t;p++)
{
scanf("%d",&a[p][1]);
a[p][2]=f(a[p][1]);
}
for(p=0;p<t;p++)
{
if(a[p][2]==0)
{b[r]=a[p][1];
r++;
}
}
max=b[0];
for(p=0;p<r;p++)
{
if(b[p]>=max)
max=b[p];
}
printf("%d",max);
} | |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 31156b683baa94ee047a5b652468dcc9 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include<stdio.h>
#include<math.h>
int main()
{
int b,a;
int max=-10000000;
int i,size;
scanf("%d",&size);
for(i=0;i<size;i++)
{
scanf("%d",&a);
b=sqrt(a);
if((b*b==a)) continue;
else if(a>max) max=a;
}
printf("%d\n",max);
return 0;
}
| |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 93d3a13abbbb8ae1aef90def3cb6c278 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include<stdio.h>
#include<math.h>
int main()
{
double f;
int n,i;
scanf("%d",&n);
//printf("-----1\n");
long p,max=-1000000;
for(i=0;i<n;i++)
{
scanf("%ld",&p);
if(p<0)
{
if(p>max)
max=p;
}
else if(p%10 == 2 || p%10 == 3 || p%10 == 7 || p%10 == 8)
{
if(p>max)
max=p;
}
else
{
f=sqrt(p);
if(f-(int)f != 0 && p>max)
max=p;
}
}
printf("%ld\n",max);
return 0;
}
| |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 4471363c6a4ad1a1cfdd35a124cebc6c | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include<stdio.h>
#include<math.h>
int myjudge(int a){
int i;
for(i=0;i*i<=a;i++)
if(i*i==a) break;
if(i*i==a) return 0;
return 1;
}
int main()
{
int n;
scanf("%d",&n);
int a[n];
int i;
for(i = 0; i < n; i++) scanf("%d",&a[i]);
int j;
for(i = 0; i < n - 1; i++)
{
int min = i;
for(j = i + 1; j < n; j++) if(a[j] < a[min]) min = j;
if(min != i)
{
int temp = a[min];
a[min] = a[i];
a[i] = temp;
}
}
for(i = n - 1; i >= 0; i--)
if(myjudge(a[i])>0) {printf("%d\n",a[i]);break;}
return 0;
}
| |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | ebba8d087d9e6c63058e651cb992b6db | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include <stdio.h>
#include <math.h>
int main()
{
int i,n;
int t[1000];
int max = -pow(10,6);
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&t[i]);
if(sqrt(t[i])!=(int)sqrt(t[i]))
{
if(t[i]>max)
max = t[i];
}
}
printf("%d",max);
return 0;
}
| |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 94b7bdbef88f20779617a23f7742c5c7 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include <stdio.h>
#include <stdlib.h>
#include<math.h>
int main()
{
int x;
float y;
int n,i,j,max=0,max2=-1000001;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i]<0)
{
if(max2<a[i])
{
max2=a[i];
}
}
else
{
x=sqrt(a[i]);
y=sqrt(a[i]);
}
if(x!=y && a[i]>max )
{
max=a[i];
}
}
if(max>max2 &&max!=0)
{
printf("%d",max);
}
else
{
printf("%d",max2);
}
return 0;
}
| |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 7be657981720486cc65d0a57a831c26f | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
int cmpfunc (const void * a, const void * b) {
return ( *(int*)a - *(int*)b );}
int main ()
{
long t[1000];
int n;
scanf ("%d",&n);
for (int i=0;i<n;i++)
scanf("%d",&t[i]);
long i=n-1;
qsort(t, n, sizeof(int), cmpfunc);
while (round(sqrt(t[i]))==sqrt(t[i]))
i--;
printf("%d",t[i]);} | |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 90ab07b581b0d61de06fc26e4a5b0ed2 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include <stdio.h>
#include<math.h>
int main()
{
long long int n,i,x,y,mx=0,num=0;
scanf("%lld",&n);
for(i=0;i<n;i++)
{
scanf("%lld",&x);
if(x<0)
{
if(num==0)
num=x;
else
if(x>num)
num=x;
continue;
}
y=(long long int)(sqrt(x));
if((y*y)!=x)
{
if(x>mx)
mx=x;
}
}
if(mx!=0)
printf("%lld\n",mx);
else
printf("%lld\n",num);
return 0;
}
| |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 70da6f1dceea20832e274c2220b96faf | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include <stdio.h>
int main()
{
long long int n,i,ans;
long long int a[1005];
int p[1000005]={0};
scanf("%I64d",&n);
for(i=0;i<n;i++)
scanf("%I64d",&a[i]);
for(i=0;i<=1000;i++)
{
p[i*i]=1;
}
ans=-10000000;
for(i=0;i<n;i++)
{
if(a[i]>=0)
{
if(p[a[i]]==0)
{
if(ans<a[i])
ans=a[i];
}
}
else
{
if(a[i]>ans)
{
ans=a[i];
}
}
}
printf("%I64d\n",ans);
return 0;
} | |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 4214b1150fdd92cd6e265a0ef5c1ab3b | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include<stdio.h>
#include<math.h>
int ch(int n)
{
double d;
d=sqrt(n);
int p=d;
if(p*p==n)
return 0;
else
return 1;
}
int main()
{
int i,j,k,n,c=-1000005;
scanf("%d",&k);
for(i=0; i<k; i++)
{
scanf("%d",&n);
if(n>0 )
{
if(ch(n))
{
if(n>c)
c=n;
}
}
else if(n>c && n!=0)
c=n;
}
printf("%d\n",c);
return 0;
}
| |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | d7ddc920b08fac1b2402bdf7bd7d6403 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include<stdio.h>
#include<math.h>
int panduan(int n)
{
float i;
if(sqrt(n)!=(int)sqrt(n))
return 0;
else
return 1;
}
int a[10001];
int n;
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
if(a[j]>a[i])
{
int temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
for(int i=0;i<n;i++)
{
if(panduan(a[i])==0)
{
printf("%d\n",a[i]);
break;
}
}
} | |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 8d753cc63ee96554dc60ccee00e24455 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include<stdio.h>
#include<math.h>
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int a[1007],b[1007],j=0,i;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
int t;
t=sqrt(a[i]);
if(a[i]!=t*t)
{
b[j]=a[i];
j++;
}
}
for(i=0;i<j;i++)
if(b[0]<b[i])
b[0]=b[i];
printf("%d\n",b[0]);
}
}
| |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 5c80d8dd213f9779ba0b9908cf46c089 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include<stdio.h>
#include<math.h>
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int a[1007],b[1007],j=0,i;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
int t;
t=sqrt(a[i]);
if(a[i]!=t*t)
{
b[j]=a[i];
if(b[0]<b[j])
b[0]=b[j];
j++;
}
}
printf("%d\n",b[0]);
}
}
| |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 9f6ebc3e2b79c84bea7979a62280935e | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include <stdio.h>
#include <stdlib.h>
#include<math.h>
int main()
{
int n,i,num,res;
res=-1000001;
scanf("%d",&n);
int x[n];
for(i=0;i<n;i++){
scanf("%d",&x[i]);
}
for(i=0;i<n;i++){
num=sqrt(x[i]);
if(x[i]!=num*num){
if(res<x[i])
{
res=x[i];
}
}
}
printf("%d",res);
return 0;
}
| |
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | C | d46d5f130d8c443f28b52096c384fef3 | 22488156a50c18e3047bbbc5ae3d4519 | GNU C | standard output | 256 megabytes | train_001.jsonl | [
"implementation",
"brute force",
"math"
] | 1516462500 | ["2\n4 2", "8\n1 2 4 8 16 32 64 576"] | NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | PASSED | 900 | standard input | 1 second | The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square. | ["2", "32"] | #include <stdio.h>
#include <math.h>
int main ( ){
int n,x,i;
long int y=-1000000;
scanf("%d",&n);
int arr[n];
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
x=sqrt(arr[i]);
if((x*x)!=arr[i]&& arr[i]>y)
y=arr[i];
}
printf("%d",y) ;
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.