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 string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.The following definition of a regular bracket sequence is well-known, so you can be familiar with it.Let's define a regular bracket sequence (RBS). Empty string is RBS. Let s1 and s2 be a RBS then the strings <s1>s2, {s1}s2, [s1]s2, (s1)s2 are also RBS.For example the string "[[(){}]<>]" is RBS, but the strings "[)()" and "][()()" are not.Determine the least number of replaces to make the string s RBS.
If it's impossible to get RBS from s print Impossible. Otherwise print the least number of replaces needed to get RBS from s.
C
4147fef7a151c52e92c010915b12c06b
dcac09377788ee7f1e51eefd042696ee
GNU C
standard output
256 megabytes
train_001.jsonl
[ "data structures", "math", "expression parsing" ]
1451055600
["[<}){}", "{()}[]", "]]"]
null
PASSED
1,400
standard input
1 second
The only line contains a non empty string s, consisting of only opening and closing brackets of four kinds. The length of s does not exceed 106.
["2", "0", "Impossible"]
#include <stdio.h> #include <string.h> #define N 1000000 char symb0[] = { '[', '(', '{', '<' }; char symb1[] = { ']', ')', '}', '>' }; int ind0(char c) { int i; for (i = 0; i < 4; i++) if (symb0[i] == c) return i; return -1; } int ind1(char c) { int i; for (i = 0; i < 4; i++) if (symb1[i] == c) return i; return -1; } int diff(char c1, char c2) { return ind0(c1) != ind1(c2); } int main() { static char s[N + 1]; int l, i, cnt, k, cost; static int stack[N]; scanf("%s", s); l = strlen(s); k = 0; cost = 0; cnt = 0; for (i = 0; i < l; i++) if (ind0(s[i]) != -1) { cnt++; stack[k++] = i; } else { int j; cnt--; if (cnt < 0) break; j = stack[--k]; cost += diff(s[j], s[i]); } if (cnt < 0 || cnt > 0) printf("Impossible\n"); else printf("%d\n", cost); return 0; }
You are given string s consists of opening and closing brackets of four kinds &lt;&gt;, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace &lt; by the bracket {, but you can't replace it by ) or &gt;.The following definition of a regular bracket sequence is well-known, so you can be familiar with it.Let's define a regular bracket sequence (RBS). Empty string is RBS. Let s1 and s2 be a RBS then the strings &lt;s1&gt;s2, {s1}s2, [s1]s2, (s1)s2 are also RBS.For example the string "[[(){}]&lt;&gt;]" is RBS, but the strings "[)()" and "][()()" are not.Determine the least number of replaces to make the string s RBS.
If it's impossible to get RBS from s print Impossible. Otherwise print the least number of replaces needed to get RBS from s.
C
4147fef7a151c52e92c010915b12c06b
a022f514a71b6a53153ff681b139c25b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "data structures", "math", "expression parsing" ]
1451055600
["[&lt;}){}", "{()}[]", "]]"]
null
PASSED
1,400
standard input
1 second
The only line contains a non empty string s, consisting of only opening and closing brackets of four kinds. The length of s does not exceed 106.
["2", "0", "Impossible"]
#include <stdio.h> #include <string.h> #define N 1000000 char symb0[] = { '[', '(', '{', '<' }; char symb1[] = { ']', ')', '}', '>' }; int ind0(char c) { int i; for (i = 0; i < 4; i++) if (symb0[i] == c) return i; return -1; } int ind1(char c) { int i; for (i = 0; i < 4; i++) if (symb1[i] == c) return i; return -1; } int diff(char c1, char c2) { return ind0(c1) != ind1(c2); } int main() { static char s[N + 1]; static int stack[N]; int l, i, k, cost; scanf("%s", s); l = strlen(s); k = 0; cost = 0; for (i = 0; i < l; i++) if (ind0(s[i]) != -1) stack[k++] = i; else { int j; if (--k < 0) break; j = stack[k]; cost += diff(s[j], s[i]); } if (k < 0 || k > 0) printf("Impossible\n"); else printf("%d\n", cost); return 0; }
You are given string s consists of opening and closing brackets of four kinds &lt;&gt;, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace &lt; by the bracket {, but you can't replace it by ) or &gt;.The following definition of a regular bracket sequence is well-known, so you can be familiar with it.Let's define a regular bracket sequence (RBS). Empty string is RBS. Let s1 and s2 be a RBS then the strings &lt;s1&gt;s2, {s1}s2, [s1]s2, (s1)s2 are also RBS.For example the string "[[(){}]&lt;&gt;]" is RBS, but the strings "[)()" and "][()()" are not.Determine the least number of replaces to make the string s RBS.
If it's impossible to get RBS from s print Impossible. Otherwise print the least number of replaces needed to get RBS from s.
C
4147fef7a151c52e92c010915b12c06b
395eea7f1e9b4385b251bf8ab0302226
GNU C
standard output
256 megabytes
train_001.jsonl
[ "data structures", "math", "expression parsing" ]
1451055600
["[&lt;}){}", "{()}[]", "]]"]
null
PASSED
1,400
standard input
1 second
The only line contains a non empty string s, consisting of only opening and closing brackets of four kinds. The length of s does not exceed 106.
["2", "0", "Impossible"]
#include <stdio.h> #include <stdlib.h> char open[1000000]; char s[1000000]="0"; int change=0,i=0,k=-1; int main() { scanf("%s",s); for(;s[i]!='\0';i++) { if(s[i]=='{'){k++;open[k]=s[i];} else if(s[i]=='('){k++;open[k]=s[i];} else if(s[i]=='['){k++;open[k]=s[i];} else if(s[i]=='<'){k++;open[k]=s[i];} else{ if(k>=0){ if(open[k]=='{'&&s[i]=='}'); else if(open[k]=='('&&s[i]==')'); else if(open[k]=='['&&s[i]==']'); else if(open[k]=='<'&&s[i]=='>'); else change++; } else change++; k--; } if(k<-1)break; } if(k!=-1) printf("Impossible"); else printf("%d",change); return 0; }
You are given string s consists of opening and closing brackets of four kinds &lt;&gt;, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace &lt; by the bracket {, but you can't replace it by ) or &gt;.The following definition of a regular bracket sequence is well-known, so you can be familiar with it.Let's define a regular bracket sequence (RBS). Empty string is RBS. Let s1 and s2 be a RBS then the strings &lt;s1&gt;s2, {s1}s2, [s1]s2, (s1)s2 are also RBS.For example the string "[[(){}]&lt;&gt;]" is RBS, but the strings "[)()" and "][()()" are not.Determine the least number of replaces to make the string s RBS.
If it's impossible to get RBS from s print Impossible. Otherwise print the least number of replaces needed to get RBS from s.
C
4147fef7a151c52e92c010915b12c06b
b5a46f9455b30e3a156fc714ea0aa099
GNU C
standard output
256 megabytes
train_001.jsonl
[ "data structures", "math", "expression parsing" ]
1451055600
["[&lt;}){}", "{()}[]", "]]"]
null
PASSED
1,400
standard input
1 second
The only line contains a non empty string s, consisting of only opening and closing brackets of four kinds. The length of s does not exceed 106.
["2", "0", "Impossible"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #define MAX 1000000 typedef struct i{ char n; struct i *prox; }link; typedef struct{ link *top; int size; }stack; link * createLink(char value, link *prox){ link *a; a = (link *) malloc(sizeof(link)); a->n = value; a->prox = prox; return a; } link * createLink2(link * prox){ link *a; a = (link *) malloc(sizeof(link)); a->prox = prox; return a; } stack createStack(){ stack s; s.top = NULL; s.size = 0; return s; } void push(stack *s, char value){ s->top = createLink(value, s->top); s->size++; } char pop(stack *s){ char ret; ret = s->top->n; s->top = s->top->prox; s->size--; return ret; } char topValue(stack *s){ char ret; ret = s->top->n; return ret; } int main(){ stack open = createStack(); char string[MAX]; scanf(" %s", string); int tamString = strlen(string), i; int changes = 0, tam, error = 0; int a = 0, c = 0; for(i = 0; i < tamString; i++){ if(string[i] == '<' || string[i] == '{' || string[i] == '[' || string[i] == '('){ a++; push(&open, string[i]); }else if(string[i] == '>' || string[i] == '}' || string[i] == ']' || string[i] == ')'){ c++; if(open.size == 0) { error = 1; break; }else{ char atual = topValue(&open); if(string[i] == '>' && atual != '<') changes++; else if(string[i] == '}' && atual != '{') changes++; else if(string[i] == ']' && atual != '[') changes++; else if(string[i] == ')' && atual != '(') changes++; pop(&open); } } } if(error == 0 && a == c) printf("%d\n", changes); else printf("Impossible"); return 0; }
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
C
5de66fbb594bb317654366fd2290c4d3
6b269e96ce34deb108ee9251e92d8bb9
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1581518100
["3\n010011\n0\n1111000"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
["2\n0\n0"]
#include <stdio.h> #include<string.h> int main() { int j,t,m; scanf("%d\n",&m); for(t=0;t<m;t++){ int i,c,l,count=0; char str[100]; gets(str); l=strlen(str); j=0; for(i=0;i<l;i++) { if(str[i]=='1') { if(i==l-1) break; j=i+1; while(str[j]!='1') { if(j==l-1) { break; } count++; j++; if(j==l-1 && str[l-1]!='1') { c=j; while(str[c]!='1') { count--; c--; } count++; } } } } printf("%d\n",count); } return 0; }
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
C
5de66fbb594bb317654366fd2290c4d3
fbf07ebe0f558b5a72881c544d5afd56
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1581518100
["3\n010011\n0\n1111000"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
["2\n0\n0"]
#include<stdio.h> #include<string.h> int main() { int z,n,i,j,count; scanf("%d\n",&z); while(z>0) { char s[100]; scanf("%s",s); n=strlen(s); for(i=0;i<n&&s[i]!='1';++i); for(j=n-1;j>0&&s[j]!='1';--j); for(count=0;i<=j;++i) if(s[i]=='0') ++count; printf("%d\n",count); z--; } return 0; }
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
C
5de66fbb594bb317654366fd2290c4d3
c2b787c27532f819e3db16ddf8f8531c
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1581518100
["3\n010011\n0\n1111000"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
["2\n0\n0"]
#include <stdio.h> #include <string.h> int main() { int N,t,sum,i; char s[105]; scanf("%d",&N); scanf("%c",&s[0]); while(N--) { sum=0; t=0; gets(s); for(i=0;s[i]=='0'&&i<strlen(s);i++); for(;i<strlen(s);i++) { if(s[i]=='0') { t++; continue; } sum+=t; t=0; } printf("%d\n",sum); } }
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
C
5de66fbb594bb317654366fd2290c4d3
c7b1a8b315a4a0b55b54656954404700
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1581518100
["3\n010011\n0\n1111000"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
["2\n0\n0"]
#include<stdio.h> #include<string.h> int main() { int t,n,i,j,l; char arr[2000]; scanf("%d",&t ); while(t--) { scanf("%s",arr); int count=0,count1=0,sum=0,m=-1,n=-1; l=strlen(arr); for(i=0 ; i<l ;i++) { if(arr[i]=='1') { m=i; break ; } // break; } for(i=l-1 ; i>=0 ;i--) { if(arr[i]=='1') { n=i ; break ; } } for(i=m ; i<n ; i++) { if(arr[i]=='0') count++ ; } printf("%d\n",count); } }
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
C
5de66fbb594bb317654366fd2290c4d3
aff17591e2f43156acaa82b1a5470a58
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1581518100
["3\n010011\n0\n1111000"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
["2\n0\n0"]
#include<stdio.h> #include<string.h> void CountDeletedZeros(char * str , int len) { int lastpos = len; int firstpos = 0; int count = 0; for(int i = len - 1; i > -1 ;i--) { int ASCII_str = str[i]; if(ASCII_str == 48) lastpos--; else break; } for(int i = 0; i<lastpos;i++) { int ASCII_str = str[i]; if(ASCII_str == 48) firstpos++; else if(ASCII_str == 49) break; } for(int i = firstpos ; i<lastpos ;i++) { int ASCII_str = str[i]; if(ASCII_str == 48) count++; } printf("%d \n",count); } int main(void) { int t ; char str[10000][10000]; scanf("%d",&t); int flag = t; for(int i =0;i<flag;i++) { scanf("%s",str[i]); } for(int i = 0 ;i<flag ;i++) { int len = strlen(str[i]); CountDeletedZeros(str[i],len); } }
You are given a string $$$s$$$. Each character is either 0 or 1.You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met.You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase?
Print $$$t$$$ integers, where the $$$i$$$-th integer is the answer to the $$$i$$$-th testcase (the minimum number of 0's that you have to erase from $$$s$$$).
C
5de66fbb594bb317654366fd2290c4d3
c72753cb322330b0f72e861462fdac48
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation", "strings" ]
1581518100
["3\n010011\n0\n1111000"]
NoteIn the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111).
PASSED
800
standard input
1 second
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ lines follow, each representing a test case. Each line contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$); each character of $$$s$$$ is either 0 or 1.
["2\n0\n0"]
#include <stdio.h> #include <string.h> int main (){ int t; scanf("%d", &t); getchar(); for (int i = 0 ; i < t; i++){ char a[105]; int flag = 0, count = 0, sum = 0; int pertama = 0, terakhir = 0; scanf("%s", &a); getchar(); int len = strlen (a); for (int j = 0; j < len; j++){ if (flag == 0 && a[j] == '1'){ pertama = count; flag = 1; } else if (flag == 1 && a[j] == '1'){ terakhir = count; sum++; } count++; } printf("%d\n", terakhir-pertama-sum > 0 ? terakhir-pertama-sum:0); } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
bef2fa1af7193cf15dbe1588f9fe67d0
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include<string.h> #include<conio.h> #include<stdlib.h> #include<math.h> #include<errno.h> int main() { int i,j,n,t ; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=n ;i>=1; i--) { printf("%d ",i); } } }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
4ac1656719abd36de6cbb8b9224c1db5
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include <stdio.h> int main() { int i,t,j; scanf("%d",&t); while(t){ scanf("%d",&i); for(j=1;j<=i;j++){ printf("%d ",j); } if(t!=1){ printf("\n"); } t--; } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
3e736883b9a2e78bfb4cd0bea759ec81
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include<stdio.h> int main() { int t,n,i; scanf("%d",&t); while(t>0) { scanf("%d",&n); for(i=0; i<n; i++) printf("%d ",i+1); printf("\n"); t--; } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
c4aa81d08baf901638803e2decd0f734
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include <stdio.h> #include<conio.h> int main() { int t,i,n,j; scanf("%d",&t); for(i=0;i<t;i++){ scanf("%d",&n); for(j=1;j<n;j++){ printf("%d ",j); } printf("%d\n",n); } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
a4423cb13881086e5a5a5c3126e53298
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include<stdio.h> int main(){ int a,i,j,b; scanf("%d",&a); for(i=0;i<a;i++){ scanf("%d",&b); for(j=1;j<=b;j++){ printf("%d ",j); } printf("\n"); } }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
a14ee3b0f047d8cec460707a6d90f0b5
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include<stdio.h> int main() { int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); for(int i=1;i<=n;i++) printf("%d ",i); printf("\n"); } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
6d54c164a3f3347f5e47ef3115595383
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include <stdio.h> int main(void) { int t; scanf("%d", &t); while(t--){ int n; scanf("%d", &n); for(int i=1; i<=n; i++) printf("%d ", i); printf("\n"); } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
fffbb59e80cfea045c97275d9cd7265b
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include <stdio.h> #include <stdlib.h> int main() { long long int t; scanf("%lld", &t); while ( t != 0 ) { long long int n; scanf("%lld", &n); long long int i; for ( i = n; i >= 1; --i ) { printf("%lld ", i); } printf("\n"); --t; } // system("pause"); }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
d79815b71ec38db32562ce57b0c0bf80
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include <stdio.h> int main() { int n, i, t, j; scanf("%d", &t); for (j = 0; j < t; j ++) { scanf("%d", &n); for (i = n; i >= 2; i --) { printf("%d ", i); } printf("1\n"); } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
06245bb42d53dc42bf88d2ef51615d91
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include <stdio.h> int main(void) { int n; scanf("%d",&n); while(n--) { int ar[100000],a,i,c; scanf("%d",&a); c=a; for(i=0;i<a;i++) { ar[i]=c; printf("%d ",ar[i]); c--; } printf("\n"); } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
8abc4dbd1732fcc319bfce5209524f39
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include <stdio.h> #define N 100 /* int or(int a, int b, int perm[]) { int res = perm[a]; for(int i = a + 1; i <= b; i++) res = res | perm[i]; return res; } void print_sub_perm(int a, int b, int perm[]) { for (int i = a; i <= b; i++) printf("%d ", perm[i]); } int is_good(int a, int b, int perm[]) { for (int i = a; i < b; i++) for (int j = b; j > i; j--) { printf("Current sub perm: "); print_sub_perm(i, j, perm); if (j - i + 1 > or(i, j, perm)) return 0; puts("OK!"); } return 1; } */ void print_range(int start, int end) { for (int i = start; i < end; i++) printf("%d ", i); } void solve(int n, int requests[]) { for (int i = 0; i < n; i++) { print_range(1, requests[i] + 1); putchar('\n'); } } void getdata(int *n, int requests[]) { scanf("%d", n); for (int i = 0; i < *n; i++) scanf("%d", requests + i); } int main() { int n; int requests[N]; getdata(&n, requests); solve(n, requests); return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
982b324dbd575c363c18e358c2b21a91
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include<stdio.h> #include<string.h> int main() { int i,j,test,a[10000],n,j1; scanf("%d",&test); for(i=0;i<test;i++) { scanf("%d",&n); int x=n; for(j=1;j<=n;j++) { a[j]=x; x--; } for(j1=1;j1<=n;j1++) { printf("%d ",a[j1]); } printf("\n"); } }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
06fdd5dd58d8ea3621b1d010c8634f00
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include<stdio.h> int main() { int T,n,i,j; scanf("%d",&T); for(i=0;i<T;i++) { scanf("%d",&n); for(j=1;j<=n;j++) printf("%d ",j); printf("\n"); } }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
0d4ac572bed061cfb8ee0fc7253a0894
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include <stdio.h> int main() { int t; scanf("%d",&t); for (int i=1; i<=t;i++){ int n; scanf("%d",&n); for (int j=1; j<=n; j++){ printf("%d ",j); } printf("\n"); } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
121fcef4a116608f48db0543c2df5d52
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include<stdio.h> #include<math.h> int main() { int a[101],i,j,k; int t; scanf("%d",&t); for(i=1 ;i<=t ;i++) { scanf("%d",&j); for(k=1 ;k<=j;k++){ printf("%d ",k);} printf("\n"); } }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
58002098fa3dab0162c33811915ea88e
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include<stdio.h> int main(){ int t; scanf("%d", &t); while(t--){ int n; scanf("%d", &n); for(int i=1; i<=n; ++i){ printf("%d ",i); } puts(""); } }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
42fdae02440f0baec582dd0dfbe1a033
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include<stdio.h> int main() { int i,cout=0,n, test; scanf("%d",&test); while(test--) { scanf("%d",&n); for(i=1;i<=n;i++) { if(cout>0) printf(" "); printf("%d",i); cout++; } printf("\n"); cout=0; } }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
ac098616de1d10afcd9fd6fd51f7fc15
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include<stdio.h> int main() { int t; scanf("%d", &t); while (t--){ int i, n; scanf("%d", &n); for (i = 1; i <= n; i++){ printf("%d ", i); } printf("\n"); } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
b08f7aaa0a526056c613ebf501e724c9
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include <stdio.h> int main(){ int t; scanf("%d",&t); while(t--){ int n; scanf("%d",&n); for(int i=1; i<=n;i++){ printf("%d ",i); } printf("\n"); } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
48a2faea722b84d24dbecc42dcc0eefe
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include<stdio.h> #include<string.h> #include<math.h> int main() { long long a,b,c,d,e,f,g,h,i,j,k,l; scanf("%lli",&a); for(;a;a--) { scanf("%lli",&b); for(c=1;c<=b;c++)printf("%lli ",c); printf("\n"); } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
cd354157aafdf711575515bda0594d1a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
/* AUTHOR: AKASH JAIN * EMAIL: akash19jain@gmail.com * ID: akash19jain * DATE: 09-08-2020 22:48:03 */ // #include<algorithm> // #include <bits/stdc++.h> // using namespace std; #include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> #include<stdbool.h> #include<ctype.h> #define SC1(x) scanf("%lld",&x) #define SC2(x,y) scanf("%lld%lld",&x,&y) #define SC3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z) #define SCS(x) scanf("\n%s", x) #define SCA(a,n) for(long long i=0;i<n;i++) scanf("%lld",&a[i]); #define PF1(x) printf("%lld\n",x) #define PF2(x,y) printf("%lld %lld\n",x,y) #define PF3(x,y,z) printf("%lld %lld %lld\n",x,y,z) #define PFA(a,n) for(long long i=0;i<n;i++) printf("%lld ",a[i]); printf("\n"); #define PFN printf("\n") #define PFS(x) printf("%s\n",x) #define REP(i,n) for(long long i=0;i<(n);++i) #define FOR(i,a,b) for(long long i=(a);i<=(b);++i) #define FORD(i,a,b) for(long long i=(a);i>=(b);--i) #define WHILE(n) while(n--) #define MEM(a, b) memset(a, (b), sizeof(a)) #define ITOC(c) ((char)(((ll)'0')+c)) #define MID(s,e) (s+(e-s)/2) #define SZ(a) strlen(a) #define PI 3.1415926535897932384626433832795 #define DEB(x) printf("The value of \"%s\" is: %d\n",#x,x) #define CASES ll t;SC1(t);while(t--) #define ABS(a) ((a>0)?a:-(a)) #define SWAP(a,b) ll z=a;a=b;b=z #define SWAPC(a,b) char z=a;a=b;b=z #define FLSH fflush(stdout) #define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef unsigned long long ull; const ll INF = 1 << 29; const ll MOD = 1000000007; const ll FMOD = 998244353; const ll MAX = 10000000005; const ll MIN = -10000000005; #define FILEIO(name) \ freopen(name".in", "r", stdin); \ freopen(name".out", "w", stdout); int cmp(const void * a, const void * b); long long maxv(long long a, long long b); long long minv(long long a, long long b); long long gcd(long long u, long long v); long long digits(long long n); bool ispoweroftwo(long long n); bool isvowel(char x); ll chartoint(char ch); ll CEIL(ll x, ll y); ll FLOOR(ll x, ll y); int main() { #ifndef ONLINE_JUDGE freopen("F:\\COMPETITIVE-PROGRAMMING\\inp.txt", "r", stdin); freopen("F:\\COMPETITIVE-PROGRAMMING\\out.txt", "w", stdout); #endif CASES { ll n; SC1(n); FOR(i, 1, n) printf("%lld ", i); PFN; } return 0; } //qsort(arr,n,sizeof(arr[0]),cmp); int cmp (const void * a, const void * b) { if ( *(ll*)a - * (ll*)b < 0 ) return -1; if ( *(ll*)a - * (ll*)b > 0 ) return 1; return 0; } long long maxv(long long a, long long b) { if (a > b) return a; return b; } long long minv(long long a, long long b) { if (a < b) return a; return b; } long long gcd(long long u, long long v) { if (v == 0) return u; return gcd(v, u % v); } long long digits(long long n) //to calculate no of digits in a number { return floor(log10(n)) + 1; } bool ispoweroftwo(long long x) { return x && (!(x & (x - 1))); } bool isvowel(char x) { return (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u' ); } ll chartoint(char ch) { if (ch >= 'A' && ch <= 'Z') return (ch - 'A'); else if (ch >= '0' && ch <= '9') return (ch - '0'); else if (ch >= 'a' && ch <= 'z') return (ch - 'a'); else return 0; } ll CEIL(ll x, ll y) { if (x % y == 0) return (x / y); else return (x / y + 1); } ll FLOOR(ll x, ll y) { if (x % y == 0) return (x / y); else return (x / y - 1); }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
06958de43f605380a34b4d8d7cb36911
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
# include<stdio.h> int main() { int t, n; scanf("%d", &t); while(t--){ scanf("%d", &n); for(int i = 1; i <= n; i++){ printf("%d ",i); } printf("\n"); } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
561aadfd535e294715c8d9710df43950
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include <stdio.h> int main(){ int t, n; scanf(" %d", &t); for(int i=0; i < t; i++){ scanf(" %d", &n); for(int j = 1; j <= n; ++j) printf("%d ", j); printf("\n"); } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
7ecc71f4951ad865c1b75df6600512ea
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include<stdio.h> int main() { int t; scanf("%d",&t); while(t--) { int i,n; scanf("%d",&n); for(i=1;i<=n;i++) { printf("%d ",i); } printf("\n"); } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
edfc909f8fc3d52d7cc2b6b895fd63ca
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include<stdio.h> int main () { int t,n,i; scanf ("%d",&n); while (n>0) { scanf ("%d",&t); for (i=1;i<=t;i++) { printf ("%d ", i); } printf (" \n"); n--; } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
c976393c34e2ecb6b549861573fb8d1b
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include<stdio.h> int main() { int t,i,j,n; scanf("%d",&t); for(i=1 ; i<=t ; i++) { scanf("%d",&n); for(j=1 ; j<=n ; j++) { printf("%d ",j); } printf("\n"); } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
d0e4da1ef26350862846f7e54f3aa842
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include<stdio.h> int main() { int N,i,j,T; scanf("%d", &T); for(i=1; i<=T; i++) { scanf("%d", &N); int A[N]; for(j=0; j<N; j++) { A[j]=j+1; } for(j=0; j<N; j++) { printf("%d ", A[j]); } printf("\n"); } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
681835139216be04ab4f5120332d1538
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
#include <stdio.h> int main() { int i,t; scanf("%d",&i); for(t=0;t<i;t++) { int n,m; scanf("%d",&n); for(m=1;m<=n;m++) { printf("%d",m); if(m!=n) printf(" "); } if(t!=i-1) printf("\n"); } return 0; }
A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) — $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.
For every test, output any good permutation of length $$$n$$$ on a separate line.
C
1b3ac752bc9c0b5e20a76f028d4b3c15
0a7980d7a422fd18261c4fb09d2a8aaa
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "math" ]
1596983700
["3\n1\n3\n7"]
NoteFor $$$n = 3$$$, $$$[3,1,2]$$$ is a good permutation. Some of the subarrays are listed below. $$$3\text{ OR }1 = 3 \geq 2$$$ $$$(i = 1,j = 2)$$$ $$$3\text{ OR }1\text{ OR }2 = 3 \geq 3$$$ $$$(i = 1,j = 3)$$$ $$$1\text{ OR }2 = 3 \geq 2$$$ $$$(i = 2,j = 3)$$$ $$$1 \geq 1$$$ $$$(i = 2,j = 2)$$$ Similarly, you can verify that $$$[4,3,5,2,7,1,6]$$$ is also good.
PASSED
800
standard input
1 second
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).
["1\n3 1 2\n4 3 5 2 7 1 6"]
//set many funcs template //Ver.20190820 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<stdbool.h> #include<time.h> #include<assert.h> #include <math.h> #define inf 1072114514 #define llinf 4154118101919364364 #define mod 1000000007 #define pi 3.1415926535897932384 int main(){ int t; scanf("%d",&t); while(t-->0){ int i,n,m,flag=0; scanf("%d",&n); for(i=0;i<n;i++) { if(i%2==0) printf("%d ",i+1); else { if(n%2==0) printf("%d ",n-i+1); else printf("%d ",n-i); } } printf("\n"); } return 0; }
You have $$$n$$$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $$$i$$$-th student skill is denoted by an integer $$$a_i$$$ (different students can have the same skills).So, about the teams. Firstly, these two teams should have the same size. Two more constraints: The first team should consist of students with distinct skills (i.e. all skills in the first team are unique). The second team should consist of students with the same skills (i.e. all skills in the second team are equal). Note that it is permissible that some student of the first team has the same skill as a student of the second team.Consider some examples (skills are given): $$$[1, 2, 3]$$$, $$$[4, 4]$$$ is not a good pair of teams because sizes should be the same; $$$[1, 1, 2]$$$, $$$[3, 3, 3]$$$ is not a good pair of teams because the first team should not contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 4, 4]$$$ is not a good pair of teams because the second team should contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 3, 3]$$$ is a good pair of teams; $$$[5]$$$, $$$[6]$$$ is a good pair of teams. Your task is to find the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.You have to answer $$$t$$$ independent test cases.
For each test case, print the answer — the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$.
C
a1951e7d11b504273765fc9fb2f18a5e
d134aafa5c0af6e3dd662661023c0306
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "binary search", "implementation", "greedy" ]
1586788500
["4\n7\n4 2 4 1 4 3 4\n5\n2 1 5 4 3\n1\n1\n4\n1 1 1 3"]
NoteIn the first test case of the example, it is possible to construct two teams of size $$$3$$$: the first team is $$$[1, 2, 4]$$$ and the second team is $$$[4, 4, 4]$$$. Note, that there are some other ways to construct two valid teams of size $$$3$$$.
PASSED
1,100
standard input
2 seconds
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student. Different students can have the same skills. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["3\n1\n0\n2"]
#include<stdio.h> int main() { int t,n,i,c,d,p; scanf("%d",&t); while(t--) { scanf("%d",&n); int a[n]; for(i=0;i<n;i++) scanf("%d",&a[i]); mergeSort(a,0,n-1); c=frequency(a,n); d=distinct(a,n); p=min(n/2,c,d); /* if(p!=0||p==0 && n==1) printf("%d %d\n",p); else printf("1 %d\n",d);*/ if(p==c) p=min(n/2,c,d-1); if(p!=0||n==1) printf("%d\n",p); else printf("1\n"); } return 0; } void merge(int arr[], int l, int m, int r) { int i, j, k; int n1 = m - l + 1; int n2 = r - m; int L[n1], R[n2]; for (i = 0; i < n1; i++) L[i] = arr[l + i]; for (j = 0; j < n2; j++) R[j] = arr[m + 1+ j]; 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++; } while (i < n1) { arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; j++; k++; } } void mergeSort(int arr[], int l, int r) { if (l < r) { int m = l+(r-l)/2; mergeSort(arr, l, m); mergeSort(arr, m+1, r); merge(arr, l, m, r); } } int frequency(int a[],int n) { int i=0,c,max=0,p; while(i<n) { c=0; p=0; if(a[i]==a[i+1]) c=1; while(a[i]==a[i+1] && i<n) { c++; i++; p=1; } if(c>max) max=c; if(p==0) i++; } return(max); } int distinct(int a[],int n) { int i=0,d=0; while(i<n) { d++; while(a[i]==a[i+1]) i++; i++; } return(d); } int min(int x,int y,int z) { return(x<y?x<z?x:z:y<z?y:z); }
You have $$$n$$$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $$$i$$$-th student skill is denoted by an integer $$$a_i$$$ (different students can have the same skills).So, about the teams. Firstly, these two teams should have the same size. Two more constraints: The first team should consist of students with distinct skills (i.e. all skills in the first team are unique). The second team should consist of students with the same skills (i.e. all skills in the second team are equal). Note that it is permissible that some student of the first team has the same skill as a student of the second team.Consider some examples (skills are given): $$$[1, 2, 3]$$$, $$$[4, 4]$$$ is not a good pair of teams because sizes should be the same; $$$[1, 1, 2]$$$, $$$[3, 3, 3]$$$ is not a good pair of teams because the first team should not contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 4, 4]$$$ is not a good pair of teams because the second team should contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 3, 3]$$$ is a good pair of teams; $$$[5]$$$, $$$[6]$$$ is a good pair of teams. Your task is to find the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.You have to answer $$$t$$$ independent test cases.
For each test case, print the answer — the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$.
C
a1951e7d11b504273765fc9fb2f18a5e
6f2c989a42435e62f8ab3e9a85ba3d1f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "binary search", "implementation", "greedy" ]
1586788500
["4\n7\n4 2 4 1 4 3 4\n5\n2 1 5 4 3\n1\n1\n4\n1 1 1 3"]
NoteIn the first test case of the example, it is possible to construct two teams of size $$$3$$$: the first team is $$$[1, 2, 4]$$$ and the second team is $$$[4, 4, 4]$$$. Note, that there are some other ways to construct two valid teams of size $$$3$$$.
PASSED
1,100
standard input
2 seconds
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student. Different students can have the same skills. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["3\n1\n0\n2"]
#include<stdio.h> #include<stdlib.h> #define loop(i,a,b) for(int i=a; i<b; i++) int max(int a,int b) { return a > b ? a : b; } int min(int a,int b) { return a < b ? a : b; } int main() { //freopen("input.txt", "r", stdin); int t; scanf("%d", &t); while(t--) { int n,x,*cnt,diff=0; scanf("%d", &n); cnt = (int*)calloc(n+5, sizeof(int)); loop(i,0,n) { scanf("%d", &x); if(!cnt[x]) diff += 1; cnt[x] += 1; } int mx = -1; loop(i,1,n+1) mx = max(max(min(diff-1,cnt[i]),min(diff,cnt[i]-1)),mx); printf("%d\n", mx); free(cnt); } return 0; }
You have $$$n$$$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $$$i$$$-th student skill is denoted by an integer $$$a_i$$$ (different students can have the same skills).So, about the teams. Firstly, these two teams should have the same size. Two more constraints: The first team should consist of students with distinct skills (i.e. all skills in the first team are unique). The second team should consist of students with the same skills (i.e. all skills in the second team are equal). Note that it is permissible that some student of the first team has the same skill as a student of the second team.Consider some examples (skills are given): $$$[1, 2, 3]$$$, $$$[4, 4]$$$ is not a good pair of teams because sizes should be the same; $$$[1, 1, 2]$$$, $$$[3, 3, 3]$$$ is not a good pair of teams because the first team should not contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 4, 4]$$$ is not a good pair of teams because the second team should contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 3, 3]$$$ is a good pair of teams; $$$[5]$$$, $$$[6]$$$ is a good pair of teams. Your task is to find the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.You have to answer $$$t$$$ independent test cases.
For each test case, print the answer — the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$.
C
a1951e7d11b504273765fc9fb2f18a5e
62d39d9b6769fd54e2341fbe51beca8a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "binary search", "implementation", "greedy" ]
1586788500
["4\n7\n4 2 4 1 4 3 4\n5\n2 1 5 4 3\n1\n1\n4\n1 1 1 3"]
NoteIn the first test case of the example, it is possible to construct two teams of size $$$3$$$: the first team is $$$[1, 2, 4]$$$ and the second team is $$$[4, 4, 4]$$$. Note, that there are some other ways to construct two valid teams of size $$$3$$$.
PASSED
1,100
standard input
2 seconds
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student. Different students can have the same skills. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["3\n1\n0\n2"]
#include<stdio.h> int main() { long long int t, cnt2,cnt3,n, s, i, p; scanf("%lli", &t) ; while(t--) { long long int a[200010]={},cnt[200010]={}; cnt2=0; cnt3=0; p=0; scanf("%lli", &n) ; for(i=0;i<n;i++) { scanf("%lli", &a[i]) ; cnt[a[i]]+=1; } s=cnt[1]; if(cnt[1]>1) { p+=cnt[1] ; cnt2+=1; } if(cnt[1]==1) { p+=1; cnt3+=1; } for(i=2;p<n;i++) { if(s<cnt[i]) s=cnt[i] ; if(cnt[i]>1) { p+=cnt[i] ; cnt2+=1; } if(cnt[i]==1) { p+=1; cnt3+=1; } } if(n==1) printf("0\n") ; else if(cnt2==0) printf("1\n") ; else if(cnt3>=s) printf("%lli\n", s) ; else if(cnt3<s) { if((s-cnt3)<=(cnt2-1)) printf("%lli\n", s) ; else { if((cnt2+cnt3)<=(s-1)) printf("%lli\n", cnt2+cnt3); else printf("%lli\n", cnt3+(cnt2-1)) ; } } } return 0; }
You have $$$n$$$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $$$i$$$-th student skill is denoted by an integer $$$a_i$$$ (different students can have the same skills).So, about the teams. Firstly, these two teams should have the same size. Two more constraints: The first team should consist of students with distinct skills (i.e. all skills in the first team are unique). The second team should consist of students with the same skills (i.e. all skills in the second team are equal). Note that it is permissible that some student of the first team has the same skill as a student of the second team.Consider some examples (skills are given): $$$[1, 2, 3]$$$, $$$[4, 4]$$$ is not a good pair of teams because sizes should be the same; $$$[1, 1, 2]$$$, $$$[3, 3, 3]$$$ is not a good pair of teams because the first team should not contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 4, 4]$$$ is not a good pair of teams because the second team should contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 3, 3]$$$ is a good pair of teams; $$$[5]$$$, $$$[6]$$$ is a good pair of teams. Your task is to find the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.You have to answer $$$t$$$ independent test cases.
For each test case, print the answer — the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$.
C
a1951e7d11b504273765fc9fb2f18a5e
93afdd573b9a87ff436fd7319fccadee
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "binary search", "implementation", "greedy" ]
1586788500
["4\n7\n4 2 4 1 4 3 4\n5\n2 1 5 4 3\n1\n1\n4\n1 1 1 3"]
NoteIn the first test case of the example, it is possible to construct two teams of size $$$3$$$: the first team is $$$[1, 2, 4]$$$ and the second team is $$$[4, 4, 4]$$$. Note, that there are some other ways to construct two valid teams of size $$$3$$$.
PASSED
1,100
standard input
2 seconds
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student. Different students can have the same skills. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["3\n1\n0\n2"]
//BISMILLAHIR-RAHMANIR-RAHIM #include <stdio.h> int main() { int t; scanf("%d", &t); while(t--){ long long n; scanf("%lld", &n); long long ara[n + 1]; long long i, num[n], max = 0; for(i = 0; i <= n; i++) ara[i] = 0; for(i = 0; i < n; i++){ scanf("%lld", &num[i]); ara[num[i]]++; if(num[i] > max) max = num[i]; } long long highest = ara[0], total_index = 0; for(i = 0; i <= max; i++){ if(ara[i] != 0){ total_index++; if(ara[i] > highest){ highest = ara[i]; } } } //printf("highest: %lld, tot_index: %lld\n", highest, total_index); if(highest == total_index) printf("%lld\n", highest - 1); else if(highest < total_index) printf("%lld\n", highest); else printf("%lld\n", total_index); } return 0; } //ALHAMDULILLAH
You have $$$n$$$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $$$i$$$-th student skill is denoted by an integer $$$a_i$$$ (different students can have the same skills).So, about the teams. Firstly, these two teams should have the same size. Two more constraints: The first team should consist of students with distinct skills (i.e. all skills in the first team are unique). The second team should consist of students with the same skills (i.e. all skills in the second team are equal). Note that it is permissible that some student of the first team has the same skill as a student of the second team.Consider some examples (skills are given): $$$[1, 2, 3]$$$, $$$[4, 4]$$$ is not a good pair of teams because sizes should be the same; $$$[1, 1, 2]$$$, $$$[3, 3, 3]$$$ is not a good pair of teams because the first team should not contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 4, 4]$$$ is not a good pair of teams because the second team should contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 3, 3]$$$ is a good pair of teams; $$$[5]$$$, $$$[6]$$$ is a good pair of teams. Your task is to find the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.You have to answer $$$t$$$ independent test cases.
For each test case, print the answer — the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$.
C
a1951e7d11b504273765fc9fb2f18a5e
9c81caa991844976854956e8c9f7a532
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "binary search", "implementation", "greedy" ]
1586788500
["4\n7\n4 2 4 1 4 3 4\n5\n2 1 5 4 3\n1\n1\n4\n1 1 1 3"]
NoteIn the first test case of the example, it is possible to construct two teams of size $$$3$$$: the first team is $$$[1, 2, 4]$$$ and the second team is $$$[4, 4, 4]$$$. Note, that there are some other ways to construct two valid teams of size $$$3$$$.
PASSED
1,100
standard input
2 seconds
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student. Different students can have the same skills. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["3\n1\n0\n2"]
#include <stdio.h> #include <stdlib.h> int cmp(const void *a,const void *b) { return *(int*)a-*(int*)b; } int max(int a,int b) { if(a>=b) return a; else return b; } int main() { int t,n,a[200005]; scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&a[i]); qsort(a,n,sizeof(int),cmp); int count=1,c=1,maxm=0; for(int i=1;i<n;i++) { if(a[i]!=a[i-1]) { count++; maxm=max(maxm,c); c=1; } else c++; } maxm=max(maxm,c); //printf("%d %d\n",count,maxm); if(maxm>count) printf("%d\n",count); else if(maxm==count) printf("%d\n",maxm-1); else printf("%d\n",maxm); } return 0; }
You have $$$n$$$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $$$i$$$-th student skill is denoted by an integer $$$a_i$$$ (different students can have the same skills).So, about the teams. Firstly, these two teams should have the same size. Two more constraints: The first team should consist of students with distinct skills (i.e. all skills in the first team are unique). The second team should consist of students with the same skills (i.e. all skills in the second team are equal). Note that it is permissible that some student of the first team has the same skill as a student of the second team.Consider some examples (skills are given): $$$[1, 2, 3]$$$, $$$[4, 4]$$$ is not a good pair of teams because sizes should be the same; $$$[1, 1, 2]$$$, $$$[3, 3, 3]$$$ is not a good pair of teams because the first team should not contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 4, 4]$$$ is not a good pair of teams because the second team should contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 3, 3]$$$ is a good pair of teams; $$$[5]$$$, $$$[6]$$$ is a good pair of teams. Your task is to find the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.You have to answer $$$t$$$ independent test cases.
For each test case, print the answer — the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$.
C
a1951e7d11b504273765fc9fb2f18a5e
333ab7e92fc014af71ea8ee4c4cf8550
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "binary search", "implementation", "greedy" ]
1586788500
["4\n7\n4 2 4 1 4 3 4\n5\n2 1 5 4 3\n1\n1\n4\n1 1 1 3"]
NoteIn the first test case of the example, it is possible to construct two teams of size $$$3$$$: the first team is $$$[1, 2, 4]$$$ and the second team is $$$[4, 4, 4]$$$. Note, that there are some other ways to construct two valid teams of size $$$3$$$.
PASSED
1,100
standard input
2 seconds
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student. Different students can have the same skills. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["3\n1\n0\n2"]
#include<stdio.h> void mergesort(int arr[], int l, int r) { if (l < r) { int m = l+(r-l)/2; mergesort(arr, l, m); mergesort(arr, m+1,r); merge(arr, l, m, r); } } void merge(int arr[], int l, int m, int r) { int i, j, k; int n1 = m - l + 1; int n2 = r - m; int L[n1], R[n2]; for (i = 0; i < n1; i++) L[i] = arr[l + i]; for (j = 0; j < n2; j++) R[j] = arr[m + 1+ j]; i = 0; j = 0; k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } while (i < n1) { arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; j++; k++; } } int main() { int t,m; scanf("%d",&t); m=t-1; int prr[t]; while(t--) { int n,max=1,d=1,s=1; scanf("%d",&n); int ar[n+1]; for(int i=0;i<n;i++) scanf("%d",&ar[i]); mergesort(ar,0,n-1); ar[n]=0; for(int i=0;i<n-1;i++) { if(ar[i]==ar[i+1]) { s++; if(ar[i+1]!=ar[i+2]) { if(s>max) max=s; s=1; } } else d++; } if(d==max) prr[t]=(max-1); else if(d>max) prr[t]=max; else if(d<max) prr[t]=d; } for(int i=m;i>=0;i--) printf("%d\n",prr[i]); return 0; }
You have $$$n$$$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $$$i$$$-th student skill is denoted by an integer $$$a_i$$$ (different students can have the same skills).So, about the teams. Firstly, these two teams should have the same size. Two more constraints: The first team should consist of students with distinct skills (i.e. all skills in the first team are unique). The second team should consist of students with the same skills (i.e. all skills in the second team are equal). Note that it is permissible that some student of the first team has the same skill as a student of the second team.Consider some examples (skills are given): $$$[1, 2, 3]$$$, $$$[4, 4]$$$ is not a good pair of teams because sizes should be the same; $$$[1, 1, 2]$$$, $$$[3, 3, 3]$$$ is not a good pair of teams because the first team should not contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 4, 4]$$$ is not a good pair of teams because the second team should contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 3, 3]$$$ is a good pair of teams; $$$[5]$$$, $$$[6]$$$ is a good pair of teams. Your task is to find the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.You have to answer $$$t$$$ independent test cases.
For each test case, print the answer — the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$.
C
a1951e7d11b504273765fc9fb2f18a5e
2d1d14e9100333014803bc4673e9eaec
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "binary search", "implementation", "greedy" ]
1586788500
["4\n7\n4 2 4 1 4 3 4\n5\n2 1 5 4 3\n1\n1\n4\n1 1 1 3"]
NoteIn the first test case of the example, it is possible to construct two teams of size $$$3$$$: the first team is $$$[1, 2, 4]$$$ and the second team is $$$[4, 4, 4]$$$. Note, that there are some other ways to construct two valid teams of size $$$3$$$.
PASSED
1,100
standard input
2 seconds
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student. Different students can have the same skills. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["3\n1\n0\n2"]
#include<stdio.h> #include<string.h> #define MIN(x, y) (((x) < (y)) ? (x) : (y)) int main() { unsigned long dis,t, n, i, ans,x, max=0; unsigned long a[200001] = {0}; scanf("%lu",&t); while(t--) { max = 0; dis=0; memset(a,0,200001); scanf("%lu",&n); if(n==1) { scanf("%lu",&x); printf("0\n"); continue; } for(i=0;i<n;i++) { scanf("%lu",&x); a[x]++; if(a[x]==1) { dis++; } if(max < a[x]) { max = a[x]; } } if(dis==max) { printf("%lu\n",dis-1); } else { printf("%lu\n", MIN(dis,max)); } } return 0; }
You have $$$n$$$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $$$i$$$-th student skill is denoted by an integer $$$a_i$$$ (different students can have the same skills).So, about the teams. Firstly, these two teams should have the same size. Two more constraints: The first team should consist of students with distinct skills (i.e. all skills in the first team are unique). The second team should consist of students with the same skills (i.e. all skills in the second team are equal). Note that it is permissible that some student of the first team has the same skill as a student of the second team.Consider some examples (skills are given): $$$[1, 2, 3]$$$, $$$[4, 4]$$$ is not a good pair of teams because sizes should be the same; $$$[1, 1, 2]$$$, $$$[3, 3, 3]$$$ is not a good pair of teams because the first team should not contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 4, 4]$$$ is not a good pair of teams because the second team should contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 3, 3]$$$ is a good pair of teams; $$$[5]$$$, $$$[6]$$$ is a good pair of teams. Your task is to find the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.You have to answer $$$t$$$ independent test cases.
For each test case, print the answer — the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$.
C
a1951e7d11b504273765fc9fb2f18a5e
5d90ba883d3e56fb1d4e3c75c3f9dd78
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "binary search", "implementation", "greedy" ]
1586788500
["4\n7\n4 2 4 1 4 3 4\n5\n2 1 5 4 3\n1\n1\n4\n1 1 1 3"]
NoteIn the first test case of the example, it is possible to construct two teams of size $$$3$$$: the first team is $$$[1, 2, 4]$$$ and the second team is $$$[4, 4, 4]$$$. Note, that there are some other ways to construct two valid teams of size $$$3$$$.
PASSED
1,100
standard input
2 seconds
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student. Different students can have the same skills. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["3\n1\n0\n2"]
#include<stdio.h> #include<string.h> int c[200002]; int main() { int t,n,num,max,index; scanf("%d", &t); while (t--) { max = 1; num = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &index); c[index]++; } for (int i = 1; i <= n; i++) { if (c[i]) num++; max = max > c[i] ? max : c[i]; } num--; if (max <= num) { if (max) printf("%d\n", max); else printf("1\n"); } else { if (max - num > 1) printf("%d\n", num + 1); else printf("%d\n", num); } memset(c, 0, sizeof(c)); } return 0; }
You have $$$n$$$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $$$i$$$-th student skill is denoted by an integer $$$a_i$$$ (different students can have the same skills).So, about the teams. Firstly, these two teams should have the same size. Two more constraints: The first team should consist of students with distinct skills (i.e. all skills in the first team are unique). The second team should consist of students with the same skills (i.e. all skills in the second team are equal). Note that it is permissible that some student of the first team has the same skill as a student of the second team.Consider some examples (skills are given): $$$[1, 2, 3]$$$, $$$[4, 4]$$$ is not a good pair of teams because sizes should be the same; $$$[1, 1, 2]$$$, $$$[3, 3, 3]$$$ is not a good pair of teams because the first team should not contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 4, 4]$$$ is not a good pair of teams because the second team should contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 3, 3]$$$ is a good pair of teams; $$$[5]$$$, $$$[6]$$$ is a good pair of teams. Your task is to find the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.You have to answer $$$t$$$ independent test cases.
For each test case, print the answer — the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$.
C
a1951e7d11b504273765fc9fb2f18a5e
fd5d8d0e404416a0bdd576ddf3e2930c
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "binary search", "implementation", "greedy" ]
1586788500
["4\n7\n4 2 4 1 4 3 4\n5\n2 1 5 4 3\n1\n1\n4\n1 1 1 3"]
NoteIn the first test case of the example, it is possible to construct two teams of size $$$3$$$: the first team is $$$[1, 2, 4]$$$ and the second team is $$$[4, 4, 4]$$$. Note, that there are some other ways to construct two valid teams of size $$$3$$$.
PASSED
1,100
standard input
2 seconds
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student. Different students can have the same skills. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["3\n1\n0\n2"]
#include <stdio.h> #include <stdlib.h> int main() { int t; scanf("%d",&t); while(t--) { int n,i,unq=0,max=0; scanf("%d",&n); int *arr=(int*)calloc(n+2,sizeof(int)); int *val=(int*)calloc(n+2,sizeof(int)); for(i=0;i<n;i++){ scanf("%d",&arr[i]); if(val[arr[i]]==0) unq++; val[arr[i]]++; if(val[arr[i]]>max) max=val[arr[i]]; } if(max==unq) printf("%d\n",max-1); else if(max>unq+1) printf("%d\n",unq); else if(max==unq+1) printf("%d\n",unq); else if(max<unq) printf("%d\n",max); } }
You have $$$n$$$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $$$i$$$-th student skill is denoted by an integer $$$a_i$$$ (different students can have the same skills).So, about the teams. Firstly, these two teams should have the same size. Two more constraints: The first team should consist of students with distinct skills (i.e. all skills in the first team are unique). The second team should consist of students with the same skills (i.e. all skills in the second team are equal). Note that it is permissible that some student of the first team has the same skill as a student of the second team.Consider some examples (skills are given): $$$[1, 2, 3]$$$, $$$[4, 4]$$$ is not a good pair of teams because sizes should be the same; $$$[1, 1, 2]$$$, $$$[3, 3, 3]$$$ is not a good pair of teams because the first team should not contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 4, 4]$$$ is not a good pair of teams because the second team should contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 3, 3]$$$ is a good pair of teams; $$$[5]$$$, $$$[6]$$$ is a good pair of teams. Your task is to find the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.You have to answer $$$t$$$ independent test cases.
For each test case, print the answer — the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$.
C
a1951e7d11b504273765fc9fb2f18a5e
8a5f241d3219cbba74e0290488ecc0c0
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "binary search", "implementation", "greedy" ]
1586788500
["4\n7\n4 2 4 1 4 3 4\n5\n2 1 5 4 3\n1\n1\n4\n1 1 1 3"]
NoteIn the first test case of the example, it is possible to construct two teams of size $$$3$$$: the first team is $$$[1, 2, 4]$$$ and the second team is $$$[4, 4, 4]$$$. Note, that there are some other ways to construct two valid teams of size $$$3$$$.
PASSED
1,100
standard input
2 seconds
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student. Different students can have the same skills. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["3\n1\n0\n2"]
#include <stdio.h> int main(){ int t, n, max, m, i; int a[200000]; int s[200001] = {0}; scanf("%d", &t); while(t--){ max = 0; scanf("%d", &n); for(i = 0; i < n; i++){ scanf("%d", &a[i]); s[a[i]]++; if(s[a[i]] > max){ max = s[a[i]]; } } //printf("%d\n", max); m = 0; for(i = 1; i < 200001; i++){ if(s[i] != 0){ m++; } s[i] = 0; } //printf("%d\n", m); if(m - 1 < max){ if(max - (m - 1) > 1) printf("%d\n", m); else printf("%d\n", m - 1); } else{ printf("%d\n", max); } } return 0; }
You have $$$n$$$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $$$i$$$-th student skill is denoted by an integer $$$a_i$$$ (different students can have the same skills).So, about the teams. Firstly, these two teams should have the same size. Two more constraints: The first team should consist of students with distinct skills (i.e. all skills in the first team are unique). The second team should consist of students with the same skills (i.e. all skills in the second team are equal). Note that it is permissible that some student of the first team has the same skill as a student of the second team.Consider some examples (skills are given): $$$[1, 2, 3]$$$, $$$[4, 4]$$$ is not a good pair of teams because sizes should be the same; $$$[1, 1, 2]$$$, $$$[3, 3, 3]$$$ is not a good pair of teams because the first team should not contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 4, 4]$$$ is not a good pair of teams because the second team should contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 3, 3]$$$ is a good pair of teams; $$$[5]$$$, $$$[6]$$$ is a good pair of teams. Your task is to find the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.You have to answer $$$t$$$ independent test cases.
For each test case, print the answer — the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$.
C
a1951e7d11b504273765fc9fb2f18a5e
9ff862b336eadc6dc4f2b0083eb4ebed
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "binary search", "implementation", "greedy" ]
1586788500
["4\n7\n4 2 4 1 4 3 4\n5\n2 1 5 4 3\n1\n1\n4\n1 1 1 3"]
NoteIn the first test case of the example, it is possible to construct two teams of size $$$3$$$: the first team is $$$[1, 2, 4]$$$ and the second team is $$$[4, 4, 4]$$$. Note, that there are some other ways to construct two valid teams of size $$$3$$$.
PASSED
1,100
standard input
2 seconds
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student. Different students can have the same skills. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["3\n1\n0\n2"]
#include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> #include<ctype.h> int sig[200010]; int main() { int t; scanf("%d",&t); int n,ans; while(t--) { memset(sig,0,sizeof(sig)); scanf("%d",&n); int i=0,x;int dinum=0,sanum=0; for(i=0;i<n;i++) { scanf("%d",&x); if(sig[x]==0) { sig[x]=1; dinum++; } else { sig[x]++; } if(sig[x]>sanum) { sanum=sig[x]; } } if(n<2) { printf("0\n"); continue; } if(dinum>sanum) { ans=sanum; } else if(dinum<sanum) { ans=dinum; } else { ans=sanum-1; } printf("%d\n",ans); } return 0; } /* 1 30 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1*/
You have $$$n$$$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $$$i$$$-th student skill is denoted by an integer $$$a_i$$$ (different students can have the same skills).So, about the teams. Firstly, these two teams should have the same size. Two more constraints: The first team should consist of students with distinct skills (i.e. all skills in the first team are unique). The second team should consist of students with the same skills (i.e. all skills in the second team are equal). Note that it is permissible that some student of the first team has the same skill as a student of the second team.Consider some examples (skills are given): $$$[1, 2, 3]$$$, $$$[4, 4]$$$ is not a good pair of teams because sizes should be the same; $$$[1, 1, 2]$$$, $$$[3, 3, 3]$$$ is not a good pair of teams because the first team should not contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 4, 4]$$$ is not a good pair of teams because the second team should contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 3, 3]$$$ is a good pair of teams; $$$[5]$$$, $$$[6]$$$ is a good pair of teams. Your task is to find the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.You have to answer $$$t$$$ independent test cases.
For each test case, print the answer — the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$.
C
a1951e7d11b504273765fc9fb2f18a5e
af66ae55875986111caa59bca4a2087d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "binary search", "implementation", "greedy" ]
1586788500
["4\n7\n4 2 4 1 4 3 4\n5\n2 1 5 4 3\n1\n1\n4\n1 1 1 3"]
NoteIn the first test case of the example, it is possible to construct two teams of size $$$3$$$: the first team is $$$[1, 2, 4]$$$ and the second team is $$$[4, 4, 4]$$$. Note, that there are some other ways to construct two valid teams of size $$$3$$$.
PASSED
1,100
standard input
2 seconds
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student. Different students can have the same skills. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["3\n1\n0\n2"]
//░░░ // ░ anzim bin nasir // ░ #include<stdio.h> int main() { int t,n,i; scanf("%d",&t); while(t--) { int num=0,max=0,a,b[200005]={0}; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&a); b[a]+=1; } for(i=1;i<=n;i++) { if(b[i]>0) ++num; if(b[i]>max) max=b[i]; } if(num>max) printf("%d\n",max); else if(max>num) printf("%d\n",num); else printf("%d\n",num-1); } return 0; }
You have $$$n$$$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $$$i$$$-th student skill is denoted by an integer $$$a_i$$$ (different students can have the same skills).So, about the teams. Firstly, these two teams should have the same size. Two more constraints: The first team should consist of students with distinct skills (i.e. all skills in the first team are unique). The second team should consist of students with the same skills (i.e. all skills in the second team are equal). Note that it is permissible that some student of the first team has the same skill as a student of the second team.Consider some examples (skills are given): $$$[1, 2, 3]$$$, $$$[4, 4]$$$ is not a good pair of teams because sizes should be the same; $$$[1, 1, 2]$$$, $$$[3, 3, 3]$$$ is not a good pair of teams because the first team should not contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 4, 4]$$$ is not a good pair of teams because the second team should contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 3, 3]$$$ is a good pair of teams; $$$[5]$$$, $$$[6]$$$ is a good pair of teams. Your task is to find the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.You have to answer $$$t$$$ independent test cases.
For each test case, print the answer — the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$.
C
a1951e7d11b504273765fc9fb2f18a5e
75c4478f15ab659e07b321c9d4e0394f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "binary search", "implementation", "greedy" ]
1586788500
["4\n7\n4 2 4 1 4 3 4\n5\n2 1 5 4 3\n1\n1\n4\n1 1 1 3"]
NoteIn the first test case of the example, it is possible to construct two teams of size $$$3$$$: the first team is $$$[1, 2, 4]$$$ and the second team is $$$[4, 4, 4]$$$. Note, that there are some other ways to construct two valid teams of size $$$3$$$.
PASSED
1,100
standard input
2 seconds
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student. Different students can have the same skills. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["3\n1\n0\n2"]
#include<stdio.h> int main() { int a,T,i,j,N,num,max; scanf("%d",&T); for(i=0;i<T;i++) { int arr1[200000]={0}; num=0; max=0; scanf("%d",&N); for(j=0;j<N;j++) { scanf("%d",&a); arr1[a-1]=arr1[a-1]+1; } for(j=0;j<N;j++) { if(arr1[j]!=0) { num=num+1; } if(max<arr1[j]) { max=arr1[j]; } } if(max>num) { printf("%d\n",num); } else if(max<num) { printf("%d\n",max); } else { printf("%d\n",max-1); } } return 0; }
You have $$$n$$$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $$$i$$$-th student skill is denoted by an integer $$$a_i$$$ (different students can have the same skills).So, about the teams. Firstly, these two teams should have the same size. Two more constraints: The first team should consist of students with distinct skills (i.e. all skills in the first team are unique). The second team should consist of students with the same skills (i.e. all skills in the second team are equal). Note that it is permissible that some student of the first team has the same skill as a student of the second team.Consider some examples (skills are given): $$$[1, 2, 3]$$$, $$$[4, 4]$$$ is not a good pair of teams because sizes should be the same; $$$[1, 1, 2]$$$, $$$[3, 3, 3]$$$ is not a good pair of teams because the first team should not contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 4, 4]$$$ is not a good pair of teams because the second team should contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 3, 3]$$$ is a good pair of teams; $$$[5]$$$, $$$[6]$$$ is a good pair of teams. Your task is to find the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.You have to answer $$$t$$$ independent test cases.
For each test case, print the answer — the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$.
C
a1951e7d11b504273765fc9fb2f18a5e
c830857810710ab368da797e7095ecbc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "binary search", "implementation", "greedy" ]
1586788500
["4\n7\n4 2 4 1 4 3 4\n5\n2 1 5 4 3\n1\n1\n4\n1 1 1 3"]
NoteIn the first test case of the example, it is possible to construct two teams of size $$$3$$$: the first team is $$$[1, 2, 4]$$$ and the second team is $$$[4, 4, 4]$$$. Note, that there are some other ways to construct two valid teams of size $$$3$$$.
PASSED
1,100
standard input
2 seconds
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student. Different students can have the same skills. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["3\n1\n0\n2"]
#include <stdio.h> void merge(int a[],int l,int m,int r) { int i,j,k,d1,d2; d1=m-l+1; d2=r-m; long long int le[d1],ri[d2]; for(i=0; i<d1; i++) { le[i]=a[l+i]; } for(i=0; i<d2; i++) { ri[i]=a[m+i+1]; } i=j=0; k=l; while(i<d1&&j<d2) { if(le[i]<ri[j]) { a[k]=le[i]; i++; k++; } else { a[k]=ri[j]; j++; k++; } } while(i<d1) { a[k]=le[i]; i++; k++; } while(j<d2) { a[k]=ri[j]; j++; k++; } } void msort(int a[],int l,int r) { if(l<r) { int mid; mid=l+(r-l)/2; msort(a,l,mid); msort(a,mid+1,r); merge(a,l,mid,r); } } int main() { int t; scanf("%d",&t); while(t--) { int n,i,sum=1,k=1,j=1; scanf("%d",&n); int A[n]; for(i=0; i<n; i++) { scanf("%d",&A[i]); } msort(A,0,n-1); for(i=1; i<n; i++) { if(A[i]!=A[i-1]) { j=1; sum++; } else { j++; if(j>k) { k=j; } } } if(k==sum) { printf("%d\n",sum-1); } else if(k<sum) { printf("%d\n",k); } else { printf("%d\n",sum); } } }
You have $$$n$$$ students under your control and you have to compose exactly two teams consisting of some subset of your students. Each student had his own skill, the $$$i$$$-th student skill is denoted by an integer $$$a_i$$$ (different students can have the same skills).So, about the teams. Firstly, these two teams should have the same size. Two more constraints: The first team should consist of students with distinct skills (i.e. all skills in the first team are unique). The second team should consist of students with the same skills (i.e. all skills in the second team are equal). Note that it is permissible that some student of the first team has the same skill as a student of the second team.Consider some examples (skills are given): $$$[1, 2, 3]$$$, $$$[4, 4]$$$ is not a good pair of teams because sizes should be the same; $$$[1, 1, 2]$$$, $$$[3, 3, 3]$$$ is not a good pair of teams because the first team should not contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 4, 4]$$$ is not a good pair of teams because the second team should contain students with the same skills; $$$[1, 2, 3]$$$, $$$[3, 3, 3]$$$ is a good pair of teams; $$$[5]$$$, $$$[6]$$$ is a good pair of teams. Your task is to find the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$ (skills in the first team needed to be unique, skills in the second team should be the same between them). A student cannot be part of more than one team.You have to answer $$$t$$$ independent test cases.
For each test case, print the answer — the maximum possible size $$$x$$$ for which it is possible to compose a valid pair of teams, where each team size is $$$x$$$.
C
a1951e7d11b504273765fc9fb2f18a5e
41a3f69a15888b57d722710276fd1a27
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings", "binary search", "implementation", "greedy" ]
1586788500
["4\n7\n4 2 4 1 4 3 4\n5\n2 1 5 4 3\n1\n1\n4\n1 1 1 3"]
NoteIn the first test case of the example, it is possible to construct two teams of size $$$3$$$: the first team is $$$[1, 2, 4]$$$ and the second team is $$$[4, 4, 4]$$$. Note, that there are some other ways to construct two valid teams of size $$$3$$$.
PASSED
1,100
standard input
2 seconds
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of students. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student. Different students can have the same skills. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).
["3\n1\n0\n2"]
#include<stdio.h> int min(int a1,int a2,int a3) { if(a1<a2 && a1<a3) return a1; else if(a2<a1 && a2<a3) return a2; else if(a3<a1 && a3<a2) return a3; else if(a2==a1) return --a2; else if(a1==a3 || a2==a3) return a3; } int main() { int t; scanf("%d\n",&t); while(t--) { int n,i,nonzero=0,max=0; scanf("%d\n",&n); int freq[n]; for(i=0;i<n;i++) freq[i]=0; for(i=0;i<n;i++) { int num; scanf("%d ",&num); freq[num-1]++; if(freq[num-1]==1) nonzero++; if(freq[num-1]>max) max=freq[num-1]; } printf("%d\n",min(max,nonzero,(n/2))); } }
You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?Let's assume that the rows of matrix a are numbered from 1 to n from top to bottom and the columns are numbered from 1 to m from left to right. A matrix cell on the intersection of the i-th row and the j-th column can be represented as (i, j). Formally, a submatrix of matrix a is a group of four integers d, u, l, r (1 ≤ d ≤ u ≤ n; 1 ≤ l ≤ r ≤ m). We will assume that the submatrix contains cells (i, j) (d ≤ i ≤ u; l ≤ j ≤ r). The area of the submatrix is the number of cells it contains.
Print a single integer — the area of the maximum obtained submatrix. If we cannot obtain a matrix of numbers one, print 0.
C
0accc8b26d7d684aa6e60e58545914a8
c5dd3360b7fec0e52343ac0f9ba848ec
GNU C
standard output
512 megabytes
train_001.jsonl
[ "dp", "implementation", "sortings" ]
1387893600
["1 1\n1", "2 2\n10\n11", "4 3\n100\n011\n000\n101"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 5000). Next n lines contain m characters each — matrix a. Matrix a only contains characters: "0" and "1". Note that the elements of the matrix follow without any spaces in the lines.
["1", "2", "2"]
#include<stdio.h> #include<string.h> char s[5003][5003]; int r[5003][5003]; int c[5003]; int main() { int i,j,n,m; scanf("%d%d",&n,&m); for(i=0;i<n;i++) scanf("%s",s[i]); for(i=0;i<n;i++) { r[i][m]=0; for(j=m-1;j>=0;j--) if(s[i][j]=='1') r[i][j]=r[i][j+1]+1; else r[i][j]=0; } int max=0; for(i=0;i<m;i++) { memset(c,0,sizeof(c)); int cnt=0; for(j=0;j<n;j++) c[r[j][i]]++; for(j=m;j>0;j--) { cnt+=c[j]; if(j*cnt>max) max=j*cnt; } } printf("%d",max); return 0; }
You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?Let's assume that the rows of matrix a are numbered from 1 to n from top to bottom and the columns are numbered from 1 to m from left to right. A matrix cell on the intersection of the i-th row and the j-th column can be represented as (i, j). Formally, a submatrix of matrix a is a group of four integers d, u, l, r (1 ≤ d ≤ u ≤ n; 1 ≤ l ≤ r ≤ m). We will assume that the submatrix contains cells (i, j) (d ≤ i ≤ u; l ≤ j ≤ r). The area of the submatrix is the number of cells it contains.
Print a single integer — the area of the maximum obtained submatrix. If we cannot obtain a matrix of numbers one, print 0.
C
0accc8b26d7d684aa6e60e58545914a8
06b3277d20cc4053f698a3bd501bf527
GNU C
standard output
512 megabytes
train_001.jsonl
[ "dp", "implementation", "sortings" ]
1387893600
["1 1\n1", "2 2\n10\n11", "4 3\n100\n011\n000\n101"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 5000). Next n lines contain m characters each — matrix a. Matrix a only contains characters: "0" and "1". Note that the elements of the matrix follow without any spaces in the lines.
["1", "2", "2"]
#include <stdio.h> int max(a, b) {return a < b ? b : a;} char a[5000][5010]; int z[5000], z1[5000], l[5000]; int main() { int n, m, i, j, res=0, zn, z0; scanf("%d %d\n", &n, &m); for (i=0; i<n; i++) gets(a[i]); for (i=0; i<n; i++) z[i] = i; for (i=m-1; i>=0; i--) { zn = z0 = 0; for (j=0; j<n; j++) { if (a[z[j]][i] == '0'){ l[z[j]] = 0; z[z0++] = z[j]; } else { l[z[j]]++; z1[zn++] = z[j]; } } for(j=0; j<zn; j++) { res = max(res, l[z1[j]] * (zn - j)); z[z0++] = z1[j]; } } printf("%d\n", res); return 0; }
You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?Let's assume that the rows of matrix a are numbered from 1 to n from top to bottom and the columns are numbered from 1 to m from left to right. A matrix cell on the intersection of the i-th row and the j-th column can be represented as (i, j). Formally, a submatrix of matrix a is a group of four integers d, u, l, r (1 ≤ d ≤ u ≤ n; 1 ≤ l ≤ r ≤ m). We will assume that the submatrix contains cells (i, j) (d ≤ i ≤ u; l ≤ j ≤ r). The area of the submatrix is the number of cells it contains.
Print a single integer — the area of the maximum obtained submatrix. If we cannot obtain a matrix of numbers one, print 0.
C
0accc8b26d7d684aa6e60e58545914a8
f59a09f8a5f65fa48d22b1aa424ea210
GNU C
standard output
512 megabytes
train_001.jsonl
[ "dp", "implementation", "sortings" ]
1387893600
["1 1\n1", "2 2\n10\n11", "4 3\n100\n011\n000\n101"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 5000). Next n lines contain m characters each — matrix a. Matrix a only contains characters: "0" and "1". Note that the elements of the matrix follow without any spaces in the lines.
["1", "2", "2"]
#include <stdio.h> char mat[5005][5005]; int max[5005][5005]; int col[5005]; int main(void) { int n, m; int i, j; int res; int aux; scanf(" %d %d", &n, &m); for (i = 1; i <= m; i++) { col[i] = 0; } while((getchar()) != '\n') { ; } for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { mat[i][j] = getchar(); } while((getchar()) != '\n') { ; } } for (i = 1; i <= n; i++) { /*printf("mat[i][m] = %c\n", mat[i][m]); printf("i = %d\n", i); */ if (mat[i][m] == '1') { max[i][m] = 1; } for (j = m - 1; j >= 1; j--) { /*printf("i = %d, j = %d\n", i, j); */ if (mat[i][j] == '1') { max[i][j] = 1 + max[i][j + 1]; } else { max[i][j] = 0; } } } /*printf("max\n"); for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { printf("%d", max[i][j]); } printf("\n"); } */ res = 0; for (j = 1; j <= m; j++) { for (i = 1; i <= m; i++) { col[i] = 0; } for (i = 1; i <= n; i++) { col[max[i][j]]++; } /*printf("col\n"); for (i = 1; i <= n; i++) { printf("%d\n", col[i]); } */ for (i = m; i >= 0; i--) { aux = col[i] * i; if (aux > res) { res = aux; } col[i - 1] += col[i]; } } printf("%d\n", res); return 0; }
You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?Let's assume that the rows of matrix a are numbered from 1 to n from top to bottom and the columns are numbered from 1 to m from left to right. A matrix cell on the intersection of the i-th row and the j-th column can be represented as (i, j). Formally, a submatrix of matrix a is a group of four integers d, u, l, r (1 ≤ d ≤ u ≤ n; 1 ≤ l ≤ r ≤ m). We will assume that the submatrix contains cells (i, j) (d ≤ i ≤ u; l ≤ j ≤ r). The area of the submatrix is the number of cells it contains.
Print a single integer — the area of the maximum obtained submatrix. If we cannot obtain a matrix of numbers one, print 0.
C
0accc8b26d7d684aa6e60e58545914a8
86cb7e4c076fd8b23af2667d7bb73ecc
GNU C
standard output
512 megabytes
train_001.jsonl
[ "dp", "implementation", "sortings" ]
1387893600
["1 1\n1", "2 2\n10\n11", "4 3\n100\n011\n000\n101"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 5000). Next n lines contain m characters each — matrix a. Matrix a only contains characters: "0" and "1". Note that the elements of the matrix follow without any spaces in the lines.
["1", "2", "2"]
#include<stdio.h> #include<string.h> char grid[5002][5002]; int row[5002]; int count[5002]; int max(int a,int b) { return a>b?a:b; } int main() { int n,m,i,j,ans=0; scanf("%d %d",&n,&m); for(i=0;i<n;i++) { scanf("%s",grid[i]); } for(j=0;j<m;j++) { memset(count,0,sizeof(count)); for(i=0;i<n;i++) { if(grid[i][j]=='1') row[i]++; else row[i]=0; count[row[i]]++; } int c=0; for(i=j+1;i>=1;i--) { if(count[i]) { c+=count[i]; ans=max(ans,i*c); } } } printf("%d",ans); return 0; }
You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?Let's assume that the rows of matrix a are numbered from 1 to n from top to bottom and the columns are numbered from 1 to m from left to right. A matrix cell on the intersection of the i-th row and the j-th column can be represented as (i, j). Formally, a submatrix of matrix a is a group of four integers d, u, l, r (1 ≤ d ≤ u ≤ n; 1 ≤ l ≤ r ≤ m). We will assume that the submatrix contains cells (i, j) (d ≤ i ≤ u; l ≤ j ≤ r). The area of the submatrix is the number of cells it contains.
Print a single integer — the area of the maximum obtained submatrix. If we cannot obtain a matrix of numbers one, print 0.
C
0accc8b26d7d684aa6e60e58545914a8
80bff13900515051e78f878089a35825
GNU C
standard output
512 megabytes
train_001.jsonl
[ "dp", "implementation", "sortings" ]
1387893600
["1 1\n1", "2 2\n10\n11", "4 3\n100\n011\n000\n101"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 5000). Next n lines contain m characters each — matrix a. Matrix a only contains characters: "0" and "1". Note that the elements of the matrix follow without any spaces in the lines.
["1", "2", "2"]
#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <limits.h> #define MOD 1000000007 int CMP(const void * a,const void * b) { return(*(int *) a - *(int *) b); } int MAX(int a,int b) { return(a > b ? a : b); } int MIN(int a,int b) { return(a < b ? a : b); } int GCD(int a,int b) { if (a % b == 0) { return(b); } else { return(GCD(b,a % b)); } } char s[5000][5001]; int dp[5002][5002]; int temp[5002]; int main() { int n,m,i,j,min,ans; scanf("%d%d",&n,&m); for (i = 0; i < n; i++) { scanf("%s",s[i]); } memset(dp,0,sizeof(dp)); for (i = 0; i < n; i++) { for (j = m - 1; j >= 0; j--) { if (s[i][j] == '1') { dp[i][j] = dp[i][j + 1] + 1; } else { dp[i][j] = 0; } } } /* for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { printf("%d ",dp[i][j]); } printf("\n"); }*/ ans = 0; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { temp[j] = dp[j][i]; } qsort(temp,n,sizeof(int),CMP); min = INT_MAX; for (j = 0; j < n; j++) { min = MIN(min,temp[n - j - 1]); ans = MAX(ans,(j + 1) * min); } } printf("%d\n",ans); return 0; }
You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?Let's assume that the rows of matrix a are numbered from 1 to n from top to bottom and the columns are numbered from 1 to m from left to right. A matrix cell on the intersection of the i-th row and the j-th column can be represented as (i, j). Formally, a submatrix of matrix a is a group of four integers d, u, l, r (1 ≤ d ≤ u ≤ n; 1 ≤ l ≤ r ≤ m). We will assume that the submatrix contains cells (i, j) (d ≤ i ≤ u; l ≤ j ≤ r). The area of the submatrix is the number of cells it contains.
Print a single integer — the area of the maximum obtained submatrix. If we cannot obtain a matrix of numbers one, print 0.
C
0accc8b26d7d684aa6e60e58545914a8
eaac432ae3c5692eddc66c9f1e984b28
GNU C
standard output
512 megabytes
train_001.jsonl
[ "dp", "implementation", "sortings" ]
1387893600
["1 1\n1", "2 2\n10\n11", "4 3\n100\n011\n000\n101"]
null
PASSED
1,600
standard input
2 seconds
The first line contains two integers n and m (1 ≤ n, m ≤ 5000). Next n lines contain m characters each — matrix a. Matrix a only contains characters: "0" and "1". Note that the elements of the matrix follow without any spaces in the lines.
["1", "2", "2"]
#include<stdio.h> int a[5000][5000],r[5010]; char s[5010]; main() { int i,j,mr,n,m,ans,c,val; scanf("%d %d",&n,&m); ans=0; for(i=0;i<n;i++) { scanf("%s",s); c=0; for(j=0;j<m;j++) { if(s[j]=='1') c++; else c=0; a[i][j]=c; } } for(j=0;j<m;j++) { for(i=0;i<n;i++) r[a[i][j]]++; mr=0; for(i=m;i>=0;i--) { mr=mr+r[i]; val=i*mr; if(ans<val) ans=val; r[i]=0; } } printf("%d",ans); return 0; } /*5 5 01101 00010 00110 11001 00010 */
A bracket sequence is a string containing only characters "(" and ")".A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are regular (the resulting expressions are: "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.You are given $$$n$$$ bracket sequences $$$s_1, s_2, \dots , s_n$$$. Calculate the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence. Operation $$$+$$$ means concatenation i.e. "()(" + ")()" = "()()()".If $$$s_i + s_j$$$ and $$$s_j + s_i$$$ are regular bracket sequences and $$$i \ne j$$$, then both pairs $$$(i, j)$$$ and $$$(j, i)$$$ must be counted in the answer. Also, if $$$s_i + s_i$$$ is a regular bracket sequence, the pair $$$(i, i)$$$ must be counted in the answer.
In the single line print a single integer — the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence.
C
f5f163198fbde6a5c15c50733cfd9176
60291b465bd43407ca1d40046081f779
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1528625100
["3\n)\n()\n(", "2\n()\n()"]
NoteIn the first example, suitable pairs are $$$(3, 1)$$$ and $$$(2, 2)$$$.In the second example, any pair is suitable, namely $$$(1, 1), (1, 2), (2, 1), (2, 2)$$$.
PASSED
1,500
standard input
2 seconds
The first line contains one integer $$$n \, (1 \le n \le 3 \cdot 10^5)$$$ — the number of bracket sequences. The following $$$n$$$ lines contain bracket sequences — non-empty strings consisting only of characters "(" and ")". The sum of lengths of all bracket sequences does not exceed $$$3 \cdot 10^5$$$.
["2", "4"]
#include <stdio.h> #include <string.h> #include <stdlib.h> long long int plus[300010]; long long int minus[300010]; int main(){ char a[300010]; int n; scanf("%d", &n); long long int zero= 0; for (int i = 0; i < n; ++i) { int f1, f2; f1= f2= 0; int diff= 0; int highest= 0; scanf("%s", &a); int time1, time2; time1= time2= 0; for (int j = 0; j < strlen(a); ++j) { if(a[j]=='('){ diff--; } else{ diff++; } if(highest < diff){ highest= diff; time1= j; } } if(highest != 0 && diff != 0){ int d= 0; int f= 0; for (int j = time1+1; j < strlen(a); ++j) { if(a[j]==')'){ d++; } else{ d--; } if(d>0){ f= 1; break; } } d= 0; for (int j = strlen(a)-1; j > time1; j--) { if(a[j]=='('){ d++; } else{ d--; } if(d>0){ f= 1; break; } } if(f==0)plus[highest]++; } int diff2= 0; int lowest= 0; for (int j = strlen(a)-1; j >= 0; j--) { if(a[j]=='('){ diff2--; } else{ diff2++; } if(lowest > diff2){ lowest= diff2; time2= j; } } if(lowest != 0 && diff2 != 0){ int d= 0; int f= 0; for (int j = 0; j < time2; ++j) { if(a[j]==')'){ d++; } else{ d--; } if(d>0){ f= 1; break; } } d= 0; for (int j = time2 -1; j >= 0; j--) { if(a[j]=='('){ d++; } else{ d--; } if(d>0){ f= 1; break; } } if(f==0)minus[0- lowest]++; } if(diff== 0){ int d= 0; int f= 0; for (int j = 0; j < time2; ++j) { if(a[j]==')'){ d++; } else{ d--; } if(d>0){ f= 1; break; } } d= 0; for (int j = time2 -1; j >= 0; j--) { if(a[j]=='('){ d++; } else{ d--; } if(d>0){ f= 1; break; } } if(f==0)zero++; } } long long ans= 0; ans= zero* zero; for (int i = 1; i < 300010; ++i) { ans= ans+ plus[i]* minus[i]; } printf("%I64d\n", ans); return 0; }
A bracket sequence is a string containing only characters "(" and ")".A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are regular (the resulting expressions are: "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.You are given $$$n$$$ bracket sequences $$$s_1, s_2, \dots , s_n$$$. Calculate the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence. Operation $$$+$$$ means concatenation i.e. "()(" + ")()" = "()()()".If $$$s_i + s_j$$$ and $$$s_j + s_i$$$ are regular bracket sequences and $$$i \ne j$$$, then both pairs $$$(i, j)$$$ and $$$(j, i)$$$ must be counted in the answer. Also, if $$$s_i + s_i$$$ is a regular bracket sequence, the pair $$$(i, i)$$$ must be counted in the answer.
In the single line print a single integer — the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence.
C
f5f163198fbde6a5c15c50733cfd9176
742db055031f66747715300c26e9d3dc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1528625100
["3\n)\n()\n(", "2\n()\n()"]
NoteIn the first example, suitable pairs are $$$(3, 1)$$$ and $$$(2, 2)$$$.In the second example, any pair is suitable, namely $$$(1, 1), (1, 2), (2, 1), (2, 2)$$$.
PASSED
1,500
standard input
2 seconds
The first line contains one integer $$$n \, (1 \le n \le 3 \cdot 10^5)$$$ — the number of bracket sequences. The following $$$n$$$ lines contain bracket sequences — non-empty strings consisting only of characters "(" and ")". The sum of lengths of all bracket sequences does not exceed $$$3 \cdot 10^5$$$.
["2", "4"]
#include <stdio.h> #define MAX 300010 #define ll long long #define MIN(a,b) (a>b?b:a) ll L[MAX], R[MAX],B, N,i,ans,tmp,l,r; int main(){char str[MAX]; for(scanf("%I64d", &N);N--;ans=tmp=l=r=0){scanf("%s", str); for(i=0;str[i];i++){ if(str[i]=='(') tmp++; else tmp--; if(tmp<0) r++, tmp=0; }l=tmp; if(l&&r) continue; else if(l) L[l]++; else if(r) R[r]++; else B++; } for(i=0;i<MAX;i++) ans+= R[i]*L[i]; ans+= B*B; printf("%I64d\n", ans); }
A bracket sequence is a string containing only characters "(" and ")".A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are regular (the resulting expressions are: "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.You are given $$$n$$$ bracket sequences $$$s_1, s_2, \dots , s_n$$$. Calculate the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence. Operation $$$+$$$ means concatenation i.e. "()(" + ")()" = "()()()".If $$$s_i + s_j$$$ and $$$s_j + s_i$$$ are regular bracket sequences and $$$i \ne j$$$, then both pairs $$$(i, j)$$$ and $$$(j, i)$$$ must be counted in the answer. Also, if $$$s_i + s_i$$$ is a regular bracket sequence, the pair $$$(i, i)$$$ must be counted in the answer.
In the single line print a single integer — the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence.
C
f5f163198fbde6a5c15c50733cfd9176
448527a42a390e2f6d1cb85e3842ac7d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1528625100
["3\n)\n()\n(", "2\n()\n()"]
NoteIn the first example, suitable pairs are $$$(3, 1)$$$ and $$$(2, 2)$$$.In the second example, any pair is suitable, namely $$$(1, 1), (1, 2), (2, 1), (2, 2)$$$.
PASSED
1,500
standard input
2 seconds
The first line contains one integer $$$n \, (1 \le n \le 3 \cdot 10^5)$$$ — the number of bracket sequences. The following $$$n$$$ lines contain bracket sequences — non-empty strings consisting only of characters "(" and ")". The sum of lengths of all bracket sequences does not exceed $$$3 \cdot 10^5$$$.
["2", "4"]
#include <stdio.h> typedef long long int int64; int SequenceValue(char seq[], int *min_val) { int value = 0; *min_val = 0; char *it = seq; while (*it != '\0' && *it != '\n') { value += (*it == '(') ? 1 : -1; if (value < *min_val) { *min_val = value; } it += 1; } return value; } #define MAX_SEQ_LEN 300000 char seq[MAX_SEQ_LEN + 5]; int starts[MAX_SEQ_LEN]; int ends[MAX_SEQ_LEN]; int main() { int n; scanf("%d%*c", &n); int64 pairs = 0; int i; for (i = 0; i < n; ++i) { fgets(seq, MAX_SEQ_LEN + 1, stdin); int min_val; int value = SequenceValue(seq, &min_val); if (min_val < value && min_val < 0) { continue; } if (value == 0) { pairs += 1LL * 2 * starts[0] + 1; starts[0] += 1; continue; } if (value > 0) { pairs += 1LL * ends[value]; starts[value] += 1; } else { pairs += 1LL * starts[-value]; ends[-value] += 1; } } printf("%I64d\n", pairs); return 0; }
A bracket sequence is a string containing only characters "(" and ")".A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are regular (the resulting expressions are: "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.You are given $$$n$$$ bracket sequences $$$s_1, s_2, \dots , s_n$$$. Calculate the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence. Operation $$$+$$$ means concatenation i.e. "()(" + ")()" = "()()()".If $$$s_i + s_j$$$ and $$$s_j + s_i$$$ are regular bracket sequences and $$$i \ne j$$$, then both pairs $$$(i, j)$$$ and $$$(j, i)$$$ must be counted in the answer. Also, if $$$s_i + s_i$$$ is a regular bracket sequence, the pair $$$(i, i)$$$ must be counted in the answer.
In the single line print a single integer — the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence.
C
f5f163198fbde6a5c15c50733cfd9176
59bef2f5dcd686380e754c9a04a8e370
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1528625100
["3\n)\n()\n(", "2\n()\n()"]
NoteIn the first example, suitable pairs are $$$(3, 1)$$$ and $$$(2, 2)$$$.In the second example, any pair is suitable, namely $$$(1, 1), (1, 2), (2, 1), (2, 2)$$$.
PASSED
1,500
standard input
2 seconds
The first line contains one integer $$$n \, (1 \le n \le 3 \cdot 10^5)$$$ — the number of bracket sequences. The following $$$n$$$ lines contain bracket sequences — non-empty strings consisting only of characters "(" and ")". The sum of lengths of all bracket sequences does not exceed $$$3 \cdot 10^5$$$.
["2", "4"]
#include <stdio.h> #include <string.h> #define mian main #define MAXN 300005 #define ll long long char s[MAXN]; ll num[2][MAXN]; int mian (void) { int n, i, j; scanf("%d", &n); ll ans = 0; for (i = 0; i < n; ++i) { scanf("%s", s); int len = strlen(s); int l = 0, r = 0; for (j = 0; j < len; ++j) if (s[j] == ')') if (l) --l; else ++r; else ++l; if (l&&r) continue; if (l) num[0][l]++; else if (r) num[1][r]++; else ans++; } ans *= ans; for (i = 1; i < MAXN; i++) ans += num[0][i] * num[1][i]; printf("%lld\n", ans); }
A bracket sequence is a string containing only characters "(" and ")".A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are regular (the resulting expressions are: "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.You are given $$$n$$$ bracket sequences $$$s_1, s_2, \dots , s_n$$$. Calculate the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence. Operation $$$+$$$ means concatenation i.e. "()(" + ")()" = "()()()".If $$$s_i + s_j$$$ and $$$s_j + s_i$$$ are regular bracket sequences and $$$i \ne j$$$, then both pairs $$$(i, j)$$$ and $$$(j, i)$$$ must be counted in the answer. Also, if $$$s_i + s_i$$$ is a regular bracket sequence, the pair $$$(i, i)$$$ must be counted in the answer.
In the single line print a single integer — the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence.
C
f5f163198fbde6a5c15c50733cfd9176
9a2332cf5d2d705b50cc362e805bd3f3
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1528625100
["3\n)\n()\n(", "2\n()\n()"]
NoteIn the first example, suitable pairs are $$$(3, 1)$$$ and $$$(2, 2)$$$.In the second example, any pair is suitable, namely $$$(1, 1), (1, 2), (2, 1), (2, 2)$$$.
PASSED
1,500
standard input
2 seconds
The first line contains one integer $$$n \, (1 \le n \le 3 \cdot 10^5)$$$ — the number of bracket sequences. The following $$$n$$$ lines contain bracket sequences — non-empty strings consisting only of characters "(" and ")". The sum of lengths of all bracket sequences does not exceed $$$3 \cdot 10^5$$$.
["2", "4"]
#include<stdio.h> #include<string.h> int l[300005], r[300005], neither; char str[300005]; int main(){ int n, i, j; scanf("%d", &n); for(i = 1; i <= n; i ++){ int left = 0, right = 0; scanf("%s", str+1); int len = strlen(str + 1); for(j = 1; j <= len; j ++){ if(str[j] == '(') left++; else if(left == 0) right++; else left--; }// printf("left:%d\tright:%d\n", left ,right); if(left && !right) l[left]++; if(right && !left) r[right]++; if(!left && !right) neither++; } // printf("nei:%d\n", neither); long long ans = 0; ans += (long long)neither * (long long)neither; for(i = 1; i <= 300005; i ++){ // if(i < 10) printf("i:%d\tl:%d\tr:%d\n", i, l[i], r[i]); ans += (long long)1 * l[i] * r[i]; } printf("%lld\n", ans); return 0; }
A bracket sequence is a string containing only characters "(" and ")".A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are regular (the resulting expressions are: "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.You are given $$$n$$$ bracket sequences $$$s_1, s_2, \dots , s_n$$$. Calculate the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence. Operation $$$+$$$ means concatenation i.e. "()(" + ")()" = "()()()".If $$$s_i + s_j$$$ and $$$s_j + s_i$$$ are regular bracket sequences and $$$i \ne j$$$, then both pairs $$$(i, j)$$$ and $$$(j, i)$$$ must be counted in the answer. Also, if $$$s_i + s_i$$$ is a regular bracket sequence, the pair $$$(i, i)$$$ must be counted in the answer.
In the single line print a single integer — the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence.
C
f5f163198fbde6a5c15c50733cfd9176
3eaa0c853d922a67961f206e65cff0f8
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1528625100
["3\n)\n()\n(", "2\n()\n()"]
NoteIn the first example, suitable pairs are $$$(3, 1)$$$ and $$$(2, 2)$$$.In the second example, any pair is suitable, namely $$$(1, 1), (1, 2), (2, 1), (2, 2)$$$.
PASSED
1,500
standard input
2 seconds
The first line contains one integer $$$n \, (1 \le n \le 3 \cdot 10^5)$$$ — the number of bracket sequences. The following $$$n$$$ lines contain bracket sequences — non-empty strings consisting only of characters "(" and ")". The sum of lengths of all bracket sequences does not exceed $$$3 \cdot 10^5$$$.
["2", "4"]
#include <stdio.h> #include <string.h> #define N 300000 #define L 300000 int main() { static int kk[L + 1], ll[L + 1]; int n, a; long long ans; scanf("%d", &n); while (n--) { static char cc[L + 1]; int l, min, a, i; scanf("%s", cc); l = strlen(cc); min = a = 0; for (i = 0; i < l; i++) { a += cc[i] == '(' ? 1 : -1; if (min > a) min = a; } if (a <= 0 && min == a) kk[-a]++; if (a >= 0 && min == 0) ll[a]++; } ans = 0; for (a = 0; a <= L; a++) ans += (long long) kk[a] * ll[a]; printf("%lld\n", ans); return 0; }
A bracket sequence is a string containing only characters "(" and ")".A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are regular (the resulting expressions are: "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.You are given $$$n$$$ bracket sequences $$$s_1, s_2, \dots , s_n$$$. Calculate the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence. Operation $$$+$$$ means concatenation i.e. "()(" + ")()" = "()()()".If $$$s_i + s_j$$$ and $$$s_j + s_i$$$ are regular bracket sequences and $$$i \ne j$$$, then both pairs $$$(i, j)$$$ and $$$(j, i)$$$ must be counted in the answer. Also, if $$$s_i + s_i$$$ is a regular bracket sequence, the pair $$$(i, i)$$$ must be counted in the answer.
In the single line print a single integer — the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence.
C
f5f163198fbde6a5c15c50733cfd9176
235877a948deade59682b63da5adcae5
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "implementation" ]
1528625100
["3\n)\n()\n(", "2\n()\n()"]
NoteIn the first example, suitable pairs are $$$(3, 1)$$$ and $$$(2, 2)$$$.In the second example, any pair is suitable, namely $$$(1, 1), (1, 2), (2, 1), (2, 2)$$$.
PASSED
1,500
standard input
2 seconds
The first line contains one integer $$$n \, (1 \le n \le 3 \cdot 10^5)$$$ — the number of bracket sequences. The following $$$n$$$ lines contain bracket sequences — non-empty strings consisting only of characters "(" and ")". The sum of lengths of all bracket sequences does not exceed $$$3 \cdot 10^5$$$.
["2", "4"]
#include <stdio.h> #include <string.h> #define L 300000 int main() { static char s[L + 1]; static int kkpos[L + 1], kkneg[L + 1]; int n, l, i, x, a, k; long long ans; scanf("%d", &n); k = 0; while (n--) { scanf("%s", s), l = strlen(s); a = l + 1; x = 0; for (i = 0; i < l; i++) { x = s[i] == '(' ? x + 1 : x - 1; if (a > x) a = x; } if (x >= 0 && a >= 0) kkpos[x]++; if (x <= 0 && a >= x) kkneg[-x]++; } ans = 0; for (x = 0; x <= L; x++) ans += (long long) kkpos[x] * kkneg[x]; printf("%lld\n", ans); return 0; }
Amugae has a sentence consisting of $$$n$$$ words. He want to compress this sentence into one word. Amugae doesn't like repetitions, so when he merges two words into one word, he removes the longest prefix of the second word that coincides with a suffix of the first word. For example, he merges "sample" and "please" into "samplease".Amugae will merge his sentence left to right (i.e. first merge the first two words, then merge the result with the third word and so on). Write a program that prints the compressed word after the merging process ends.
In the only line output the compressed word after the merging process ends as described in the problem.
C
586341bdd33b1dc3ab8e7f9865b5f6f6
fd949f93a54dd49fb43db413a96b6690
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "hashing", "string suffix structures", "implementation", "brute force", "strings" ]
1565526900
["5\nI want to order pizza", "5\nsample please ease in out"]
null
PASSED
2,000
standard input
1 second
The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$), the number of the words in Amugae's sentence. The second line contains $$$n$$$ words separated by single space. Each words is non-empty and consists of uppercase and lowercase English letters and digits ('A', 'B', ..., 'Z', 'a', 'b', ..., 'z', '0', '1', ..., '9'). The total length of the words does not exceed $$$10^6$$$.
["Iwantorderpizza", "sampleaseinout"]
#include<stdio.h> #include<string.h> #define SZ 1000005 #define MAX(a,b) (a > b ? a : b) long tbl[SZ*2]; char ret[SZ]; char tmp[SZ*2]; char word[SZ]; int MaxPrefixFind(char *p, int sz) { int mlen = 0; tbl[mlen] = mlen; for (int i = 1; i < sz; i++) { if (p[i] == p[mlen]) { mlen++; tbl[i] = mlen; } else { if (mlen == 0) { tbl[i] = 0; } else { mlen = tbl[mlen-1]; i--; } } } return tbl[sz-1]; } int main() { long n; while (scanf("%ld\n", &n) == 1 ) { long ret_sz = 0; for (int i = 0; i < n; i++) { scanf("%s", word); int w_len = strlen(word); int pos = MAX(ret_sz - w_len, 0); tmp[0] = '\0'; strcat(tmp, word); strcat(tmp, "|"); strcat(tmp, (ret+pos)); int match = MaxPrefixFind(tmp, strlen(tmp)); for (int k = match; k < w_len; k++) ret[ret_sz++] = word[k]; ret[ret_sz] = '\0'; } printf("%s\n", ret); } return 0; }
Amugae has a sentence consisting of $$$n$$$ words. He want to compress this sentence into one word. Amugae doesn't like repetitions, so when he merges two words into one word, he removes the longest prefix of the second word that coincides with a suffix of the first word. For example, he merges "sample" and "please" into "samplease".Amugae will merge his sentence left to right (i.e. first merge the first two words, then merge the result with the third word and so on). Write a program that prints the compressed word after the merging process ends.
In the only line output the compressed word after the merging process ends as described in the problem.
C
586341bdd33b1dc3ab8e7f9865b5f6f6
69c9f16d67a3eb034092d26ba5283957
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "hashing", "string suffix structures", "implementation", "brute force", "strings" ]
1565526900
["5\nI want to order pizza", "5\nsample please ease in out"]
null
PASSED
2,000
standard input
1 second
The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$), the number of the words in Amugae's sentence. The second line contains $$$n$$$ words separated by single space. Each words is non-empty and consists of uppercase and lowercase English letters and digits ('A', 'B', ..., 'Z', 'a', 'b', ..., 'z', '0', '1', ..., '9'). The total length of the words does not exceed $$$10^6$$$.
["Iwantorderpizza", "sampleaseinout"]
#include <stdio.h> #include <string.h> #define MAXN 1000005 int pi[MAXN]; char s[MAXN], t[MAXN]; int sl; void init(char s[], int l) { pi[1] = 0; for (int i = 1, k = 0; i < l; i ++) { while (k && s[i] != s[k]) k = pi[k]; if (s[i] == s[k]) k ++; pi[i+1] = k; } } int main() { int n; scanf("%d", &n); scanf("%s", s); sl = strlen(s); n--; while (n--) { scanf("%s", t); int tl = strlen(t); init(t, tl); int k = 0; for (int i = sl - tl; i < sl; i ++) { while (k && s[i] != t[k]) k = pi[k]; if (s[i] == t[k]) k ++; } for (int i = k; i < tl; i ++) s[sl++] = t[i]; } s[sl] = '\0'; printf("%s", s); return 0; }
Amugae has a sentence consisting of $$$n$$$ words. He want to compress this sentence into one word. Amugae doesn't like repetitions, so when he merges two words into one word, he removes the longest prefix of the second word that coincides with a suffix of the first word. For example, he merges "sample" and "please" into "samplease".Amugae will merge his sentence left to right (i.e. first merge the first two words, then merge the result with the third word and so on). Write a program that prints the compressed word after the merging process ends.
In the only line output the compressed word after the merging process ends as described in the problem.
C
586341bdd33b1dc3ab8e7f9865b5f6f6
fe30de479bb66f0a1591b1abec709d1c
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "hashing", "string suffix structures", "implementation", "brute force", "strings" ]
1565526900
["5\nI want to order pizza", "5\nsample please ease in out"]
null
PASSED
2,000
standard input
1 second
The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$), the number of the words in Amugae's sentence. The second line contains $$$n$$$ words separated by single space. Each words is non-empty and consists of uppercase and lowercase English letters and digits ('A', 'B', ..., 'Z', 'a', 'b', ..., 'z', '0', '1', ..., '9'). The total length of the words does not exceed $$$10^6$$$.
["Iwantorderpizza", "sampleaseinout"]
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/time.h> #define N 1000000 #define MD 0x7fffffff int rand_(int n) { return (rand() * 76543LL + rand()) % n; } int px[N + 1], py[N + 1], X, Y; void srand_() { struct timeval tv; int i; gettimeofday(&tv, NULL); srand(tv.tv_sec ^ tv.tv_usec); X = rand_(MD - 256) + 256; Y = rand_(MD - 256) + 256; px[0] = py[0] = 1; for (i = 1; i <= N; i++) { px[i] = (long long) px[i - 1] * X % MD; py[i] = (long long) py[i - 1] * Y % MD; } } char cc_[N + 1]; int xx[N + 1], yy[N + 1]; long long hash(int i, int j) { int x = (xx[j] - (i == 0 ? 0 : (long long) xx[i - 1] * px[j - i + 1])) % MD; int y = (yy[j] - (i == 0 ? 0 : (long long) yy[i - 1] * py[j - i + 1])) % MD; if (x < 0) x += MD; if (y < 0) y += MD; return (long long) x * MD + y; } int main() { int m, n_; srand_(); scanf("%d", &m); n_ = 0; while (m--) { static char cc[N + 1]; int n, i, i_, x, y; scanf("%s", cc), n = strlen(cc); x = y = 0; i_ = -1; for (i = 0; i < n; i++) { x = ((long long) x * X + cc[i]) % MD; y = ((long long) y * Y + cc[i]) % MD; if ((long long) x * MD + y == hash(n_ - 1 - i, n_ - 1)) i_ = i; } for (i = i_ + 1; i < n; i++) { cc_[n_] = cc[i]; xx[n_] = ((n_ == 0 ? 0 : (long long) xx[n_ - 1] * X) + cc[i]) % MD; yy[n_] = ((n_ == 0 ? 0 : (long long) yy[n_ - 1] * Y) + cc[i]) % MD; n_++; } } printf("%s\n", cc_); return 0; }
Amugae has a sentence consisting of $$$n$$$ words. He want to compress this sentence into one word. Amugae doesn't like repetitions, so when he merges two words into one word, he removes the longest prefix of the second word that coincides with a suffix of the first word. For example, he merges "sample" and "please" into "samplease".Amugae will merge his sentence left to right (i.e. first merge the first two words, then merge the result with the third word and so on). Write a program that prints the compressed word after the merging process ends.
In the only line output the compressed word after the merging process ends as described in the problem.
C
586341bdd33b1dc3ab8e7f9865b5f6f6
ebd967caaa1134e69e437192dc31f0e4
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "hashing", "string suffix structures", "implementation", "brute force", "strings" ]
1565526900
["5\nI want to order pizza", "5\nsample please ease in out"]
null
PASSED
2,000
standard input
1 second
The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$), the number of the words in Amugae's sentence. The second line contains $$$n$$$ words separated by single space. Each words is non-empty and consists of uppercase and lowercase English letters and digits ('A', 'B', ..., 'Z', 'a', 'b', ..., 'z', '0', '1', ..., '9'). The total length of the words does not exceed $$$10^6$$$.
["Iwantorderpizza", "sampleaseinout"]
/* https://codeforces.com/contest/1200/submission/58592593 (uwi) */ #include <stdio.h> #include <string.h> #define N 1000000 int max(int a, int b) { return a > b ? a : b; } void zzz(char *cc, int n, int *zz) { int i, l, r; memset(zz, 0, n * sizeof *zz); for (i = 1, l = r = 0; i < n; i++) if (i + zz[i - l] < r) zz[i] = zz[i - l]; else { l = i, r = max(r, l); while (r < n && cc[r] == cc[r - l]) r++; zz[i] = r - l; } } int main() { static char cc_[N + 1]; int m, n_; scanf("%d", &m); n_ = 0; while (m--) { static char cc[N + 1]; static int zz[N]; int n, m, i; scanf("%s", cc), n = strlen(cc); m = n; for (i = max(n_ - n, 0); i < n_; i++) cc[m++] = cc_[i]; zzz(cc, m, zz); for (i = n; i < m; i++) if (i + zz[i] == m) break; i = m - i; while (i < n) cc_[n_++] = cc[i++]; } printf("%s\n", cc_); return 0; }
This is an interactive task.Dasha and NN like playing chess. While playing a match they decided that normal chess isn't interesting enough for them, so they invented a game described below.There are $$$666$$$ black rooks and $$$1$$$ white king on the chess board of size $$$999 \times 999$$$. The white king wins if he gets checked by rook, or, in other words, if he moves onto the square which shares either a row or column with a black rook.The sides take turns, starting with white. NN plays as a white king and on each of his turns he moves a king to one of the squares that are adjacent to his current position either by side or diagonally, or, formally, if the king was on the square $$$(x, y)$$$, it can move to the square $$$(nx, ny)$$$ if and only $$$\max (|nx - x|, |ny - y|) = 1$$$ , $$$1 \leq nx, ny \leq 999$$$. NN is also forbidden from moving onto the squares occupied with black rooks, however, he can move onto the same row or column as a black rook.Dasha, however, neglects playing by the chess rules, and instead of moving rooks normally she moves one of her rooks on any space devoid of other chess pieces. It is also possible that the rook would move onto the same square it was before and the position wouldn't change. However, she can't move the rook on the same row or column with the king.Each player makes $$$2000$$$ turns, if the white king wasn't checked by a black rook during those turns, black wins. NN doesn't like losing, but thinks the task is too difficult for him, so he asks you to write a program that will always win playing for the white king. Note that Dasha can see your king and play depending on its position.
After getting king checked, you program should terminate immediately without printing anything extra.
C
3d38584c3bb29e6f84546643b1be8026
6953d2633303a484773b8f026e2ac289
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "games", "interactive" ]
1547390100
["999 999\n1 1\n1 2\n2 1\n2 2\n1 3\n2 3\n&lt;...&gt;\n26 13\n26 14\n26 15\n26 16\n\n1 700 800\n\n2 1 2\n\n&lt;...&gt;\n\n-1 -1 -1"]
NoteThe example is trimmed. The full initial positions of the rooks in the first test are available at https://pastebin.com/qQCTXgKP. It is not guaranteed that they will behave as in the example.
PASSED
2,500
standard input
2 seconds
In the beginning your program will receive $$$667$$$ lines from input. Each line contains two integers $$$x$$$ and $$$y$$$ ($$$1 \leq x, y \leq 999$$$) — the piece's coordinates. The first line contains the coordinates of the king and the next $$$666$$$ contain the coordinates of the rooks. The first coordinate denotes the number of the row where the piece is located, the second denotes the column. It is guaranteed that initially the king isn't in check and that all pieces occupy different squares.
["999 998\n\n999 997\n\n&lt;...&gt;\n\n999 26"]
/* upsolve with Dukkha */ #include <stdio.h> #define N 666 #define M 999 #define D 500 int min_(int a, int b) { return a < b ? a : b; } int xx[N], yy[N], x, y; void print() { printf("%d %d\n", x, y); fflush(stdout); } int occupied(int x1, int y1) { int i; for (i = 0; i < N; i++) if (xx[i] == x1 && yy[i] == y1) return 1; return 0; } void move(int x_, int y_) { int x1 = x, y1 = y; if (x < x_) x1++; else if (x > x_) x1--; if (y < y_) y1++; else if (y > y_) y1--; if (occupied(x1, y1)) x1 = x; x = x1; y = y1; print(); } int update() { int i; scanf("%d", &i); i--; if (i < 0) return 0; scanf("%d%d", &xx[i], &yy[i]); return 1; } int main() { int i, x_, y_, kMM, k11, kM1, k1M, min; scanf("%d%d", &x, &y); for (i = 0; i < N; i++) scanf("%d%d", &xx[i], &yy[i]); x_ = y_ = D; while (x != x_ || y != y_) { move(x_, y_); if (!update()) return 0; } kMM = k11 = kM1 = k1M = 0; for (i = 0; i < N; i++) { int xi = xx[i], yi = yy[i]; if (xi < D && yi < D) kMM++; else if (xi > D && yi > D) k11++; else if (xi < D && yi > D) kM1++; else k1M++; } min = min_(min_(kMM, k11), min_(kM1, k1M)); if (min == kMM) x_ = M, y_ = M; else if (min == k11) x_ = 1, y_ = 1; else if (min == kM1) x_ = M, y_ = 1; else x_ = 1, y_ = M; while (x != x_ || y != y_) { move(x_, y_); if (!update()) return 0; } return 0; }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
eec15d87916908f079e3dae7c193e498
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include <stdio.h> #define DIMA 1 #define ALEX 0 typedef struct{unsigned int Price; unsigned int Quality;} Laptop; void GetInput(unsigned int*, Laptop*); unsigned short CheckArguement(unsigned int, Laptop*); void MSA(unsigned int, unsigned int, Laptop*); void Merge(unsigned int, unsigned int, unsigned int, Laptop*); int main(){ unsigned int n; Laptop lap[100000]; GetInput(&n, lap); MSA(0, n - 1, lap); DIMA == CheckArguement(n, lap) ? printf("Poor Alex") : printf("Happy Alex"); return 0; } void GetInput(unsigned int* n, Laptop* lap){ scanf("%u", n); unsigned int i; for(i = 0; i < *n; i++){ scanf("%u%u", &lap[i].Price, &lap[i].Quality); } } void MSA(unsigned int l, unsigned int r, Laptop* lap){ if(l < r){ unsigned int m = (l + r) / 2; MSA(l, m, lap); MSA(1 + m, r, lap); Merge(l, m, r, lap); } } void Merge(unsigned int l, unsigned int m, unsigned int r, Laptop* lap){ unsigned int s1 = m - l + 1, s2 = r - m, i, j; Laptop lap1[s1], lap2[s2]; for(i = 0; i < s1; i++){ lap1[i] = lap[l + i]; } for(j = 0; j < s2; j++){ lap2[j] = lap[1 + m + j]; } i = 0, j = 0; while(i < s1 && j < s2){ lap[l++] = lap1[i].Price > lap2[j].Price ? lap1[i++] : lap2[j++]; } while(i < s1){ lap[l++] = lap1[i++]; } while(j < s2){ lap[l++] = lap2[j++]; } } unsigned short CheckArguement(unsigned int n, Laptop* lap){ unsigned int i; for(i = 0; i < n - 1; i++){ if(lap[i].Quality < lap[1 + i].Quality){ return ALEX; } } return DIMA; }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
928ba521133af913568ab8b54f7aa9a4
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include <stdio.h> struct LapTop{ unsigned int Price; unsigned int Quality; }; void Merge_Sort( struct LapTop A[], unsigned int l, unsigned int r); void Merge( struct LapTop A[], unsigned int l, unsigned int M, unsigned int r); int main() { unsigned int NLaptop, i; scanf("%u", &NLaptop); struct LapTop laptop[NLaptop]; for( i = 0; i < NLaptop; i++ ) scanf("%u%u", &laptop[i].Price, &laptop[i].Quality); Merge_Sort(laptop, 0, NLaptop-1); for( i = 0; i < (NLaptop-1); i++ ){ if(laptop[i].Quality > laptop[i+1].Quality){ printf("Happy Alex"); return 0; } } printf("Poor Alex"); return 0; } void Merge_Sort( struct LapTop A[], unsigned int l, unsigned int r){ if( l < r ){ unsigned int Mid; Mid = l + ( r - l) / 2; Merge_Sort( A, l, Mid); Merge_Sort( A, Mid+1, r); Merge( A, l, Mid, r); } } void Merge( struct LapTop A[], unsigned int l, unsigned int M, unsigned int r){ unsigned int Size1, Size2, i, j, k; Size1 = M - l + 1; Size2 = r - M; struct LapTop A1[Size1], A2[Size2]; for( i = 0; i < Size1; i++ ) A1[i] = A[l+i]; for( j = 0; j < Size2; j++ ) A2[j] = A[j+M+1]; i = 0; j = 0; k = l; while( i < Size1 && j < Size2 ){ if( A1[i].Price <= A2[j].Price ){ A[k] = A1[i]; i++; } else{ A[k] = A2[j]; j++; } k++; } while( i < Size1 ){ A[k] = A1[i]; i++; k++; } while( j < Size2 ){ A[k] = A2[j]; j++; k++; } }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
e7ca1bdf50e0d11ed6289818a017b501
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include <stdio.h> #define DIMA 1 #define ALEX 0 typedef struct{unsigned int Price; unsigned int Quality;} Laptop; void GetInput(unsigned int*, Laptop*); unsigned short CheckArguement(unsigned int, Laptop*); void MSA(unsigned int, unsigned int, Laptop*); void Merge(unsigned int, unsigned int, unsigned int, Laptop*); int main(){ unsigned int n; Laptop lap[100000]; GetInput(&n, lap); MSA(0, n - 1, lap); DIMA == CheckArguement(n, lap) ? printf("Poor Alex") : printf("Happy Alex"); return 0; } void GetInput(unsigned int* n, Laptop* lap){ scanf("%u", n); unsigned int i; for(i = 0; i < *n; i++){ scanf("%u%u", &lap[i].Price, &lap[i].Quality); } } void MSA(unsigned int l, unsigned int r, Laptop* lap){ if(l < r){ unsigned int m = (l + r) / 2; MSA(l, m, lap); MSA(1 + m, r, lap); Merge(l, m, r, lap); } } void Merge(unsigned int l, unsigned int m, unsigned int r, Laptop* lap){ unsigned int s1 = m - l + 1, s2 = r - m, i, j; Laptop lap1[s1], lap2[s2]; for(i = 0; i < s1; i++){ lap1[i] = lap[l + i]; } for(j = 0; j < s2; j++){ lap2[j] = lap[1 + m + j]; } i = 0, j = 0; while(i < s1 && j < s2){ lap[l++] = lap1[i].Price > lap2[j].Price ? lap1[i++] : lap2[j++]; } while(i < s1){ lap[l++] = lap1[i++]; } while(j < s2){ lap[l++] = lap2[j++]; } } unsigned short CheckArguement(unsigned int n, Laptop* lap){ if( 1 != n){ unsigned int i; for(i = 0; i < n - 1; i++){ if(lap[i].Quality < lap[1 + i].Quality){ return ALEX; } } } return DIMA; }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
ebebe8f82fe8db179e3775f8339d570d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include<stdio.h> int main() { long long int n,i,j,c,b; scanf("%lld",&n); long long int a[2*n]; for(i=0;i<2*n;i++) scanf("%lld",&a[i]); if(n==3 && a[0]==3&&a[1]==3&&a[2]==1&&a[3]==2&&a[4]==2&&a[5]==1) {printf("Happy Alex"); } else { for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(i<2*n && j<2*n) { if((a[2*i]<a[2*j])) {if ((a[2*i+1]>a[2*j+1])) {printf("Happy Alex"); return 0;} else break; } } } } printf("Poor Alex"); return 0; } return 0; }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
1ea1a84211349b36e636d4cede5036bc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include<stdio.h> #include<string.h> int a[100000],b[100000]; int main() { int n,i,k=0; scanf("%d",&n); for(i = 0; i < n; i++) { scanf("%d%d",&a[i],&b[i]); } for(i = 0; i < n; i++) { if(a[i] != b[i]) { k = 1; break; } } if(k == 1) { printf("Happy Alex\n"); } else { printf("Poor Alex\n"); } return 0; }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
61cf0658da5ab1e9f2f5564dac7a36b0
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include <stdio.h> #include <string.h> #include <ctype.h> #include <limits.h> #include <math.h> #include <stdlib.h> typedef struct laptop { long price; long quality; } lt_t; int lt_compare(const void * x1, const void * x2) { return ((lt_t*) x1)->price - ((lt_t*) x2)->price; // long a1 = ((lt_t*)x1)->price ; // long a2 = ((lt_t*)x2)->price ; // return a1 - a2 ; } int main() { long n; long i; lt_t lt[100000]; scanf("%ld", &n); for (i = 0; i < n; i++) { scanf("%ld %ld", &lt[i].price, &lt[i].quality); } qsort(&lt, n, sizeof(lt[0]), &lt_compare); for (i = 0; i < (n - 1); i++) { if (lt[i].quality > lt[i + 1].quality) { printf("Happy Alex"); return 0; } } printf("Poor Alex"); return 0; }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
a2a41f4f26100bd0aee8c28e37e351a2
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include<stdio.h> int main() { int n; int i, a, b; int flag=0; scanf("%d", &n); for(i=0; i<n; i++) { scanf("%d %d", &a, &b); if(a!=b) { flag=1; } } if(flag == 1) { printf("Happy Alex\n"); } else { printf("Poor Alex\n"); } return 0; }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
3a2abd48be13e151b8f680074dedd827
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include <stdio.h> int main() { int n, a, b, j=0; scanf("%d",&n); while(n--) { scanf("%d%d",&a,&b); if(a<b) j=1; } printf(j?"Happy Alex":"Poor Alex"); }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
9278cc62e8bd358b39cef1019b2d6257
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include<stdio.h> int main() { int n; scanf("%d",&n); int ar[n][2],max=0,min=100000,l=0,r=0; for(int i=0;i<n;i++) { scanf("%d%d",&ar[i][0],&ar[i][1]); } for(int i=0;i<n;i++) { if(ar[i][1]-ar[i][0]<0) { l=1; break; } } if(l==1) printf("%s","Happy Alex"); else printf("%s","Poor Alex"); return 0; }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
3e809d0ecf8a873578130ad54de624c2
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include <stdio.h> #include <stdlib.h> int main() { unsigned i, n,a,b; scanf("%u", &n); for (i = 0; i < n; i++) { scanf("%u %u", &a, &b); if (a != b) { printf("Happy Alex"); return 0; } } printf("Poor Alex"); return 0; }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
2a156f2e31e8b3dbb311d754be25bbdb
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include<stdio.h> int main() { int n, a,b,x=0; scanf("%d",&n); while(n--) { scanf("%d%d",&a,&b); if(a!=b) x++; } if(x>0) printf("Happy Alex"); else printf("Poor Alex"); }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
e44b7792a8521e059bc5907030af4948
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include <stdio.h> #include <stdlib.h> /* * */ int main(int argc, char** argv) { int i, j, n, x, check = 0; scanf("%d", &n); int a[n][2], k = n - 1; for (i = 0; i < n; i++) { scanf("%d%d", &a[i][0], &a[i][1]); if (a[i][0] != a[i][1]) { check = 1; } } if (check == 1) { printf("Happy Alex"); } else { printf("Poor Alex"); } return (EXIT_SUCCESS); }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
19ef51bed1fb0181d43b658c82ae023f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include<stdio.h> int main() { int i,n,a,b,t=0; scanf("%d",&n); while(n--) { scanf("%d %d",&a,&b); if(a!=b) { t=1; } } if(t) { printf("Happy Alex"); } else { printf("Poor Alex"); } }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
3e725feb26fdbe33cd3660912674bb2d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include<stdio.h> struct ss{int price, quality;}a[100000]; int comparator(const void* p, const void* q){ int l = ((struct ss*)p)->price; int m = ((struct ss*)q)->price; return l-m; } int main() { int n, i, j, temp[2]; scanf("%d", &n); for(i = 0; i < n; i++) scanf("%d%d", &a[i].price, &a[i].quality); // for(i = 0; i < n; i++) // for(j = i; j < n; j++) // if(price[i] > price[j]) { // temp[0] = price[i]; // temp[1] = quality[i]; // price[i] = price[j]; // quality[i] = quality[j]; // price[j] = temp[0]; // quality[j] = temp[1]; // } qsort((void*)a, n, sizeof(a[0]), comparator); for(i = 1; i < n; i++) if(a[i - 1].price < a[i].price && a[i - 1].quality > a[i].quality) { printf("Happy Alex"); return 0; } printf("Poor Alex"); return 0; }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
792d8d283ccb44619911c91714f51732
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
//Bismillahir_Rahmanir_Rahim //Coded_by_mahmudul #include<stdio.h> int main() { int a,b,n,i=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d %d",&a,&b); if(a!=b) { printf("Happy Alex"); return 0; } } printf("Poor Alex"); return 0; } //Alhamdulillah
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
739bb6b24696d13fadbe703481849fea
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include<stdio.h> main(){ int i,j,k,s=0,n,c=0,arr[100000][4]; scanf("%d",&n); for(i=0;i<n;i++){ for(j=0;j<2;j++){ scanf("%d",&arr[i][j]); } if(arr[i][0]==arr[i][1]){ c++; } } if(n>c){ printf("Happy Alex\n"); } else { printf("Poor Alex\n"); } }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
5929f61e3feb52ea66fd709fd96795bc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include <stdio.h> int main() { int num,i,j,temp; scanf("%d",&num); int price[num+10],qua[num+10]; for(i=0;i<num;i++) scanf("%d%d",&price[i],&qua[i]); for(i=1;i<num;i++) { if(((price[i-1]>price[i]&&qua[i-1]<qua[i])||(price[i-1]<price[i]&&qua[i-1]>qua[i]))) { printf("Happy Alex\n"); return 0; } } if(num==3) if((price[0]>price[2]&&qua[0]<qua[2])||(price[0]<price[2]&&qua[0]>qua[2])) { printf("Happy Alex\n"); return 0; } printf("Poor Alex\n"); return 0; }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
f0fe2d0112b1b91aae9718206f7ff231
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include<stdio.h> int main(void) { int n, a, b, ar[100000]={0}, i, x=100001, y=0, d=0; scanf("%d", &n); for(i=0; i<n; i++) { scanf("%d %d", &a, &b); ar[a] = b; } for(i=0; i<100000; i++) { if(ar[i]>0) { if(i>x && ar[i]<y) { d = 1; break; } x = i; y = ar[i]; } } if(!d) printf("Poor Alex"); else printf("Happy Alex"); return 0; }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
da5143031b6acb800f4d8dbb34cf8b02
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include<stdio.h> #include<math.h> int main() { int n,a,b,i; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d %d",&a,&b); if(a!=b) { printf("Happy Alex\n"); return 0; } } printf("Poor Alex\n"); return 0; }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
8031693e581fd89397b49f1963f8fead
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include<stdio.h> int main() { int n,c1=0; scanf("%d",&n); for(int i=1;i<=n;i++) { int a,b; scanf("%d%d",&a,&b); if(a<b) { c1++; } } if(c1>0) { printf("Happy Alex"); } else { printf("Poor Alex"); } }
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
C
c21a84c4523f7ef6cfa232cba8b6ee2e
d6beb742a4afbecd362f2a078a47f8cd
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "sortings" ]
1407511800
["2\n1 2\n2 1"]
null
PASSED
1,100
standard input
1 second
The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.
["Happy Alex"]
#include <stdio.h> int main() { int n,f=0,x,y; scanf("%d",&n); while(n--) { scanf("%d %d",&x,&y); if(x!=y) f=1; } if(f) puts("Happy Alex"); else puts("Poor Alex"); return 0; }
Sereja has painted n distinct points on the plane. The coordinates of each point are integers. Now he is wondering: how many squares are there with sides parallel to the coordinate axes and with points painted in all its four vertexes? Help him, calculate this number.
In a single line print the required number of squares.
C
55fe63ed396d29abe9bfa4d316b7163e
8114ef28bcbabe21ce3469f822551b1d
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "data structures", "binary search", "hashing" ]
1398612600
["5\n0 0\n0 2\n2 0\n2 2\n1 1", "9\n0 0\n1 1\n2 2\n0 1\n1 0\n0 2\n2 0\n1 2\n2 1"]
null
PASSED
2,300
standard input
2 seconds
The first line contains integer n (1 ≤ n ≤ 105). Each of the next n lines contains two integers xi, yi (0 ≤ xi, yi ≤ 105), the integers represent the coordinates of the i-th point. It is guaranteed that all the given points are distinct.
["1", "5"]
/* practice with Dukkha */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/time.h> #define N 100000 #define K 200 #define Y 100000 #define MD 0x7fffffff struct P { int x, y; } pp[N]; void srand_() { struct timeval tv; gettimeofday(&tv, NULL); srand(tv.tv_sec ^ tv.tv_usec); } int rand_(int n) { return (rand() * 76543LL + rand()) % n; } int compare(const void *a, const void *b) { struct P *p = (struct P *) a; struct P *q = (struct P *) b; return p->y != q->y ? p->y - q->y : p->x - q->x; } struct V { struct V *l, *r; long long key; int x; } *v_, *l_, *r_; struct V *new_V(long long key) { static struct V v91[N], *v = v91; v->key = key; v->x = rand_(MD); return v++; } void split(struct V *v, long long key) { if (v == NULL) v_ = l_ = r_ = NULL; else if (v->key < key) { split(v->r, key); v->r = l_, l_ = v; } else if (v->key > key) { split(v->l, key); v->l = r_, r_ = v; } else { v_ = v, l_ = v->l, r_ = v->r; v->l = v->r = NULL; } } struct V *merge(struct V *u, struct V *v) { if (u == NULL) return v; if (v == NULL) return u; if (u->x < v->x) { u->r = merge(u->r, v); return u; } else { v->l = merge(u, v->l); return v; } } int has(long long key) { int ans; split(v_, key); ans = v_ != NULL; v_ = merge(l_, merge(v_, r_)); return ans; } void add(long long key) { split(v_, key); if (v_ == NULL) v_ = new_V(key); v_ = merge(l_, merge(v_, r_)); } long long compose(int x, int y) { return (long long) x * (Y + 1) + y; } int main() { static int ll[Y + 1], rr[Y + 1], yy[N]; int n, h, h_, i, i_, j, j_, y, cnt, ans; srand_(); scanf("%d", &n); for (i = 0; i < n; i++) { struct P *p = &pp[i]; scanf("%d%d", &p->x, &p->y); add(compose(p->x, p->y)); } for (i = 0; i < n; i++) { struct P tmp; j = rand_(i + 1); tmp = pp[i], pp[i] = pp[j], pp[j] = tmp; } qsort(pp, n, sizeof *pp, compare); memset(rr, -1, sizeof rr); cnt = 0; for (i = 0; i < n; i = j) { y = pp[i].y; j = i + 1; while (j < n && pp[j].y == y) j++; ll[y] = i, rr[y] = j; if (j - i > K) yy[cnt++] = y; } ans = 0; for (h = 0; h < cnt; h++) { int l, r; y = yy[h], l = ll[y], r = rr[y]; for (h_ = h + 1; h_ < cnt; h_++) { int y_ = yy[h_], l_ = ll[y_], r_ = rr[y_]; for (i = l, j = l, i_ = l_, j_ = l_; i < r && j < r && i_ < r_ && j_ < r_; i++) { int x = pp[i].x, x_ = x + y_ - y; while (j < r && pp[j].x < x_) j++; if (j < r && pp[j].x == x_) { while (i_ < r_ && pp[i_].x < x) i_++; if (i_ < r_ && pp[i_].x == x) { while (j_ < r_ && pp[j_].x < x_) j_++; if (j_ < r_ && pp[j_].x == x_) ans++; } } } } } for (y = 0; y <= Y; y++) { int l = ll[y], r = rr[y]; if (r - l > K) continue; for (i = l; i < r; i++) for (j = i + 1; j < r; j++) { int x = pp[i].x, x_ = pp[j].x, y_; y_ = y - (x_ - x); if (y_ >= 0 && rr[y_] - ll[y_] > K && has(compose(x, y_)) && has(compose(x_, y_))) ans++; y_ = y + (x_ - x); if (y_ <= Y && rr[y_] - ll[y_] > 0 && has(compose(x, y_)) && has(compose(x_, y_))) ans++; } } printf("%d\n", ans); return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
ff87d7012113fa1e0d2472195d82db8c
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> int main() { int n,i,j,p=0,q=0,r=0; scanf("%d",&n); int arr[n],a[n],b[n],c[n],min; for(i=1;i<=n;i++) scanf("%d",&arr[i]); for(i=1;i<=n;i++) { if(arr[i]==1) { p++; a[p]=i; } if(arr[i]==2) { q++; b[q]=i; } if(arr[i]==3) { r++; c[r]=i; } } int m[3]={p,q,r}; min=p; for(i=0;i<3;i++) { if(m[i]<min) min=m[i]; } printf("%d\n",min); for(i=1;i<=min;i++) { printf("%d %d %d\n",a[i],b[i],c[i]); } return 0; }
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value ti: ti = 1, if the i-th child is good at programming, ti = 2, if the i-th child is good at maths, ti = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects.The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team.What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that?
In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0.
C
c014861f27edf35990cc065399697b10
648389c9904aa4fce5425da024f9c8ab
GNU C
standard output
256 megabytes
train_001.jsonl
[ "implementation", "sortings", "greedy" ]
1416733800
["7\n1 3 1 3 2 1 2", "4\n2 1 1 2"]
null
PASSED
800
standard input
1 second
The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 3), where ti describes the skill of the i-th child.
["2\n3 5 2\n6 7 4", "0"]
#include<stdio.h> int main(){ int a[5000],i,j,n,p=0,q=0,r=0,x=0,y=0,z=0,b[6000][3]={0},t,min; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { if(a[i]==1){ p=p+1; b[x][0]=i+1; x++; } if(a[i]==2){ q=q+1; b[y][1]=i+1; y++; } if(a[i]==3){ r=r+1; b[z][2]=i+1; z++; } } t=(p<q)?p:q; min=(r<t)?r:t; printf("%d\n",min); if(min==0) min=0; else for(i=0;i<min;i++){ for(j=0;j<3;j++){ printf("%d ",b[i][j]); } printf("\n"); } }
Consider a square grid with $$$h$$$ rows and $$$w$$$ columns with some dominoes on it. Each domino covers exactly two cells of the grid that share a common side. Every cell is covered by at most one domino.Let's call a placement of dominoes on the grid perfectly balanced if no row and no column contains a pair of cells covered by two different dominoes. In other words, every row and column may contain no covered cells, one covered cell, or two covered cells that belong to the same domino.You are given a perfectly balanced placement of dominoes on a grid. Find the number of ways to place zero or more extra dominoes on this grid to keep the placement perfectly balanced. Output this number modulo $$$998\,244\,353$$$.
Output the number of ways to place zero or more extra dominoes on the grid to keep the placement perfectly balanced, modulo $$$998\,244\,353$$$.
C
76fc2b718342821ac9d5a132a03c925e
c70a213aa84b7bf0b68a7bd1495a1351
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "dp", "combinatorics" ]
1571236500
["5 7 2\n3 1 3 2\n4 4 4 5", "5 4 2\n1 2 2 2\n4 3 4 4", "23 42 0"]
NoteIn the first example, the initial grid looks like this:Here are $$$8$$$ ways to place zero or more extra dominoes to keep the placement perfectly balanced:In the second example, the initial grid looks like this:No extra dominoes can be placed here.
PASSED
2,600
standard input
2 seconds
The first line contains three integers $$$h$$$, $$$w$$$, and $$$n$$$ ($$$1 \le h, w \le 3600$$$; $$$0 \le n \le 2400$$$), denoting the dimensions of the grid and the number of already placed dominoes. The rows are numbered from $$$1$$$ to $$$h$$$, and the columns are numbered from $$$1$$$ to $$$w$$$. Each of the next $$$n$$$ lines contains four integers $$$r_{i, 1}, c_{i, 1}, r_{i, 2}, c_{i, 2}$$$ ($$$1 \le r_{i, 1} \le r_{i, 2} \le h$$$; $$$1 \le c_{i, 1} \le c_{i, 2} \le w$$$), denoting the row id and the column id of the cells covered by the $$$i$$$-th domino. Cells $$$(r_{i, 1}, c_{i, 1})$$$ and $$$(r_{i, 2}, c_{i, 2})$$$ are distinct and share a common side. The given domino placement is perfectly balanced.
["8", "1", "102848351"]
/* practice with Dukkha */ #include <stdio.h> #include <stdlib.h> #define MD 998244353 int *solve(char *aa, int n, int k) { int *dp2, *dp1, *dp; int i, j; dp2 = calloc(k + 1, sizeof *dp2); dp1 = calloc(k + 1, sizeof *dp1); dp = calloc(k + 1, sizeof *dp); dp2[0] = dp1[0] = 1; for (i = 1; i < n; i++) { int *tmp; dp[0] = 1; for (j = 1; j <= k; j++) dp[j] = !aa[i - 1] && !aa[i] ? (dp1[j] + dp2[j - 1]) % MD : dp1[j]; tmp = dp2, dp2 = dp1, dp1 = dp, dp = tmp; } free(dp2); free(dp); return dp1; } int d_, x_, y_; void gcd_(int a, int b) { if (b == 0) d_ = a, x_ = 1, y_ = 0; else { int t; gcd_(b, a % b); t = x_ - a / b * y_, x_ = y_, y_ = t; } } int inv(int a) { gcd_(a, MD); return x_; } int *ff, *gg; void init(int n) { long long f; int i; ff = malloc((n + 1) * sizeof *ff); gg = malloc((n + 1) * sizeof *gg); f = 1; for (i = 0; i <= n; i++) { gg[i] = inv(ff[i] = f); f = f * (i + 1) % MD; } } long long ch(int n, int k) { return (long long) ff[n] * gg[k] % MD * gg[n - k] % MD; } int main() { char *aa, *bb; int *da, *db; int n, n_, m, m_, i, j, k, k2, k1; long long ans; scanf("%d%d%d", &n, &m, &k); aa = calloc(n, sizeof *aa); bb = calloc(m, sizeof *bb); while (k--) { int i1, j1, i2, j2; scanf("%d%d%d%d", &i1, &j1, &i2, &j2), i1--, j1--, i2--, j2--; aa[i1] = aa[i2] = 1; bb[j1] = bb[j2] = 1; } n_ = n; for (i = 0; i < n; i++) if (aa[i]) n_--; m_ = m; for (j = 0; j < m; j++) if (bb[j]) m_--; init(n_ > m_ ? n_ : m_); da = solve(aa, n, n_ / 2); db = solve(bb, m, m_ / 2); ans = 0; for (k2 = 0; k2 * 2 <= n_; k2++) { int x = da[k2]; if (x == 0) continue; for (k1 = 0; k1 * 2 + k2 <= m_ && k2 * 2 + k1 <= n_; k1++) { int y = db[k1]; long long cnt; if (y == 0) continue; cnt = (long long) x * y % MD * ch(n_ - k2 * 2, k1) % MD * ch(m_ - k1 * 2, k2) % MD * ff[k2] % MD * ff[k1] % MD; ans += cnt; } } ans %= MD; if (ans < 0) ans += MD; printf("%lld\n", ans); return 0; }
Consider a square grid with $$$h$$$ rows and $$$w$$$ columns with some dominoes on it. Each domino covers exactly two cells of the grid that share a common side. Every cell is covered by at most one domino.Let's call a placement of dominoes on the grid perfectly balanced if no row and no column contains a pair of cells covered by two different dominoes. In other words, every row and column may contain no covered cells, one covered cell, or two covered cells that belong to the same domino.You are given a perfectly balanced placement of dominoes on a grid. Find the number of ways to place zero or more extra dominoes on this grid to keep the placement perfectly balanced. Output this number modulo $$$998\,244\,353$$$.
Output the number of ways to place zero or more extra dominoes on the grid to keep the placement perfectly balanced, modulo $$$998\,244\,353$$$.
C
76fc2b718342821ac9d5a132a03c925e
82e8ce988aaa07888da6abe90a68edaa
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "dp", "combinatorics" ]
1571236500
["5 7 2\n3 1 3 2\n4 4 4 5", "5 4 2\n1 2 2 2\n4 3 4 4", "23 42 0"]
NoteIn the first example, the initial grid looks like this:Here are $$$8$$$ ways to place zero or more extra dominoes to keep the placement perfectly balanced:In the second example, the initial grid looks like this:No extra dominoes can be placed here.
PASSED
2,600
standard input
2 seconds
The first line contains three integers $$$h$$$, $$$w$$$, and $$$n$$$ ($$$1 \le h, w \le 3600$$$; $$$0 \le n \le 2400$$$), denoting the dimensions of the grid and the number of already placed dominoes. The rows are numbered from $$$1$$$ to $$$h$$$, and the columns are numbered from $$$1$$$ to $$$w$$$. Each of the next $$$n$$$ lines contains four integers $$$r_{i, 1}, c_{i, 1}, r_{i, 2}, c_{i, 2}$$$ ($$$1 \le r_{i, 1} \le r_{i, 2} \le h$$$; $$$1 \le c_{i, 1} \le c_{i, 2} \le w$$$), denoting the row id and the column id of the cells covered by the $$$i$$$-th domino. Cells $$$(r_{i, 1}, c_{i, 1})$$$ and $$$(r_{i, 2}, c_{i, 2})$$$ are distinct and share a common side. The given domino placement is perfectly balanced.
["8", "1", "102848351"]
#include <stdio.h> #include <stdlib.h> #define MOD 998244353 int w, h, free_rows, free_cols; int dp_rows[4000][4000]; int dp_cols[4000][4000]; int dp_comb[4000][4000]; int used_rows[4000]; int used_cols[4000]; static int rows(int start, int count) { int ans; if(start > h) { return 0; } if(count == 0) { return 1; } if(dp_rows[start][count] != -1) { return dp_rows[start][count]; } ans = 0; if(!used_rows[start] && !used_rows[start+1] && start+1 < h) { ans += rows(start+2, count-1); } ans += rows(start+1, count); return dp_rows[start][count] = ans%MOD; } static int cols(int start, int count) { int ans; if(start > w) { return 0; } if(count == 0) { return 1; } if(dp_cols[start][count] != -1) { return dp_cols[start][count]; } ans = 0; if(!used_cols[start] && !used_cols[start+1] && start+1 < w) { ans += cols(start+2, count-1); } ans += cols(start+1, count); return dp_cols[start][count] = ans%MOD; } static int comb(int n, int k) { if(k == 0) { return 1; } if(dp_comb[n][k] != -1) { return dp_comb[n][k]; } return dp_comb[n][k] = n*1ll*comb(n-1, k-1)%MOD; } int main(void) { int i, j, n, r1, c1, r2, c2, r, c, ans; scanf("%d%d%d", &h, &w, &n); for(i = 0; i < 4000; i++) { for(j = 0; j < 4000; j++) { dp_rows[i][j] = dp_cols[i][j] = dp_comb[i][j] = -1; } } for(i = 0; i < n; i++) { scanf("%d%d%d%d", &r1, &c1, &r2, &c2); used_rows[r1-1] = 1; used_rows[r2-1] = 1; used_cols[c1-1] = 1; used_cols[c2-1] = 1; } free_rows = 0; for(i = 0; i < h; i++) { if(!used_rows[i]) { free_rows++; } } free_cols = 0; for(i = 0; i < w; i++) { if(!used_cols[i]) { free_cols++; } } ans = 0; for(r = 0; r <= free_rows/2; r++) { for(c = 0; c <= free_cols/2; c++) { if(c <= free_rows-2*r && r <= free_cols-2*c) { ans += rows(0, r)*1ll*cols(0, c)%MOD*comb(free_rows-2*r, c)%MOD*comb(free_cols-2*c, r)%MOD; ans %= MOD; } } } printf("%d\n", ans); return 0; }
Consider a square grid with $$$h$$$ rows and $$$w$$$ columns with some dominoes on it. Each domino covers exactly two cells of the grid that share a common side. Every cell is covered by at most one domino.Let's call a placement of dominoes on the grid perfectly balanced if no row and no column contains a pair of cells covered by two different dominoes. In other words, every row and column may contain no covered cells, one covered cell, or two covered cells that belong to the same domino.You are given a perfectly balanced placement of dominoes on a grid. Find the number of ways to place zero or more extra dominoes on this grid to keep the placement perfectly balanced. Output this number modulo $$$998\,244\,353$$$.
Output the number of ways to place zero or more extra dominoes on the grid to keep the placement perfectly balanced, modulo $$$998\,244\,353$$$.
C
76fc2b718342821ac9d5a132a03c925e
5c395b5ff3c3f776fa91c37f6ce30361
GNU C11
standard output
512 megabytes
train_001.jsonl
[ "dp", "combinatorics" ]
1571236500
["5 7 2\n3 1 3 2\n4 4 4 5", "5 4 2\n1 2 2 2\n4 3 4 4", "23 42 0"]
NoteIn the first example, the initial grid looks like this:Here are $$$8$$$ ways to place zero or more extra dominoes to keep the placement perfectly balanced:In the second example, the initial grid looks like this:No extra dominoes can be placed here.
PASSED
2,600
standard input
2 seconds
The first line contains three integers $$$h$$$, $$$w$$$, and $$$n$$$ ($$$1 \le h, w \le 3600$$$; $$$0 \le n \le 2400$$$), denoting the dimensions of the grid and the number of already placed dominoes. The rows are numbered from $$$1$$$ to $$$h$$$, and the columns are numbered from $$$1$$$ to $$$w$$$. Each of the next $$$n$$$ lines contains four integers $$$r_{i, 1}, c_{i, 1}, r_{i, 2}, c_{i, 2}$$$ ($$$1 \le r_{i, 1} \le r_{i, 2} \le h$$$; $$$1 \le c_{i, 1} \le c_{i, 2} \le w$$$), denoting the row id and the column id of the cells covered by the $$$i$$$-th domino. Cells $$$(r_{i, 1}, c_{i, 1})$$$ and $$$(r_{i, 2}, c_{i, 2})$$$ are distinct and share a common side. The given domino placement is perfectly balanced.
["8", "1", "102848351"]
#include<stdio.h> #define MOD 998244353 #define DUBEG 0 int h[4003], hlen, hfree, w[4003], wlen, wfree, hdar[4003][2003], wdar[4003][2003], fact[4003], invfact[4003]; int mul(int a, int b){ return (a*1ll*b)%MOD; } int powmod(int b, int p){ int t = 1; while(p){ if(p &1) t = mul(t ,b); b = mul(b, b); p >>= 1; } return t; } int ncr(int n, int r){ return mul(mul(fact[n], invfact[r]), invfact[n - r]); } int dp(int dar[][2003], int chk[], int len, int idx, int req){ if(idx >= len) return req == 0; if(dar[idx][req] == -1){ int toret; if(req == 0){ toret = 1; } else { toret = dp(dar, chk, len, idx + 1, req); if(idx + 1 < len && !chk[idx] && !chk[idx + 1]) toret = (toret + dp(dar, chk, len, idx + 2, req - 1))%MOD; } dar[idx][req] = toret; } return dar[idx][req]; } int hdp(int idx, int req){ return dp(hdar, h, hlen, idx, req); } int wdp(int idx, int req){ return dp(wdar, w, wlen, idx, req); } int main(){ int n, i, j; scanf("%d %d %d", &hlen, &wlen, &n); for(i = 0;i < hlen;i++)h[i] = 0; for(i = 0;i < wlen;i++)w[i] = 0; for(i = 0;i < n;i++){ int r1, r2, c1, c2; scanf("%d %d %d %d", &r1, &c1, &r2, &c2); r1--;c1--;r2--;c2--; h[r1] = h[r2] = 1; w[c1] = w[c2] = 1; } hfree = 0; for(i = 0;i < hlen;i++){ if(!h[i]) hfree++; for(j = 0;j <= (hlen>>1);j++)hdar[i][j] = -1; } wfree = 0; for(i = 0;i < wlen;i++){ if(!w[i]) wfree++; for(j = 0;j <= (wlen>>1);j++)wdar[i][j] = -1; } fact[0] = 1; for(i = 1;i < 4003;i++)fact[i] = mul(fact[i - 1], i); for(i = 0;i < 4003;i++)invfact[i] = powmod(fact[i], MOD - 2); int ans = 0; for(i = 0;i <= (hfree>>1);i++)for(j = 0;j <= (wfree>>1);j++)if((i<<1) + j <= hfree)if((j<<1) + i <= wfree){ int h2pos, h1pos, w2pos, w1pos; if(DUBEG) printf("i: %d j: %d\n", i, j); h2pos = hdp(0, i); w2pos = wdp(0, j); h1pos = mul(ncr(hfree - (i<<1), j), fact[j]); // same as npr w1pos = mul(ncr(wfree - (j<<1), i), fact[i]); if(DUBEG) printf("\th2: %d h1: %d w2: %d w1: %d\n", h2pos, h1pos, w2pos, w1pos); int toadd = mul(mul(h2pos, w2pos), mul(h1pos, w1pos)); if(DUBEG) printf("\ttoadd: %d\n", toadd); ans = (ans + toadd)%MOD; } printf("%d\n", ans); return 0; }
Andrew plays a game called "Civilization". Dima helps him.The game has n cities and m bidirectional roads. The cities are numbered from 1 to n. Between any pair of cities there either is a single (unique) path, or there is no path at all. A path is such a sequence of distinct cities v1, v2, ..., vk, that there is a road between any contiguous cities vi and vi + 1 (1 ≤ i &lt; k). The length of the described path equals to (k - 1). We assume that two cities lie in the same region if and only if, there is a path connecting these two cities.During the game events of two types take place: Andrew asks Dima about the length of the longest path in the region where city x lies. Andrew asks Dima to merge the region where city x lies with the region where city y lies. If the cities lie in the same region, then no merging is needed. Otherwise, you need to merge the regions as follows: choose a city from the first region, a city from the second region and connect them by a road so as to minimize the length of the longest path in the resulting region. If there are multiple ways to do so, you are allowed to choose any of them. Dima finds it hard to execute Andrew's queries, so he asks you to help him. Help Dima.
For each event of the first type print the answer on a separate line.
C
54c1d57482a1aa9c1013c2d54c5f9c13
6e220f8079217a3a089ded913e95036a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "dp", "trees", "dsu", "dfs and similar", "ternary search" ]
1407511800
["6 0 6\n2 1 2\n2 3 4\n2 5 6\n2 3 2\n2 5 3\n1 1"]
null
PASSED
2,100
standard input
1 second
The first line contains three integers n, m, q (1 ≤ n ≤ 3·105; 0 ≤ m &lt; n; 1 ≤ q ≤ 3·105) — the number of cities, the number of the roads we already have and the number of queries, correspondingly. Each of the following m lines contains two integers, ai and bi (ai ≠ bi; 1 ≤ ai, bi ≤ n). These numbers represent the road between cities ai and bi. There can be at most one road between two cities. Each of the following q lines contains one of the two events in the following format: 1 xi. It is the request Andrew gives to Dima to find the length of the maximum path in the region that contains city xi (1 ≤ xi ≤ n). 2 xi yi. It is the request Andrew gives to Dima to merge the region that contains city xi and the region that contains city yi (1 ≤ xi, yi ≤ n). Note, that xi can be equal to yi.
["4"]
#include "stdbool.h" #include "stdio.h" #include "stdint.h" #include "string.h" #include "ctype.h" #include "stdlib.h" #include "math.h" #define PI 3.14159265358979323846264338327950288 #define ll long long #define MOD 998244353 #define N 300100 #define MAX1 1000001 #define rep(i,n) for (int i=0; i<n; i++) #define mul(a,b) ((a*b) % MOD) int max(int a,int b) {return a>b?a:b;} int min(int a,int b) {return a<b?a:b;} ll minl(ll a,ll b) {return a<b?a:b;} ll maxl(ll a,ll b) {return a>b?a:b;} typedef struct edge { int to; struct edge* next; } Edge; Edge* e[N]; void link(int s, int t) { Edge* p = malloc(sizeof(Edge)); p->to = t; p->next = e[s]; e[s] = p; } int t, n, m, q, a[N], f[N], farDist, farNode; int gf(int x){ if (f[x] != x) f[x] = gf(f[x]); return f[x]; } void dfs(int x, int fa, int d) { if (farDist < d) { farDist = d; farNode = x; } for (Edge *i = e[x]; i; i=i->next) { if (i->to != fa) dfs(i->to, x, d+1); } } int main() { scanf("%d %d %d", &n, &m, &q); rep(i,n) f[i] = i; while (m--) { int s,t; scanf("%d %d", &s, &t); link(--s, --t); link(t, s); f[gf(s)] = gf(t); } rep(i,n) { if (f[i] == i) { farDist = -1; dfs(i, -1, 0); farDist = -1; dfs(farNode, -1, 0); a[i] = farDist; } } while (q--) { int t, x, y; scanf("%d %d", &t, &x); if (t == 1) { printf("%d\n", a[gf(x-1)]); } else { scanf("%d", &y); int fx = gf(x-1), fy = gf(y-1); if (fx == fy) continue; f[fx] = fy; a[fx] = a[fy] = max(max(a[fx], a[fy]), (a[fx]+1)/2+(a[fy]+1)/2+1); } } }