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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously: there were b milliliters poured in total. That is, the bottle need to be emptied; after the process is over, the volumes of the drink in the mugs should be equal. | Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1,βc2,β...,βcn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique. Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma. | C | 65fea461d3caa5a932d1e2c13e99a59e | 2b7897b6a165afa73f4c2703ea0c30fc | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1333897500 | ["5 50\n1 2 3 4 5", "2 2\n1 100"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains a pair of integers n, b (2ββ€βnββ€β100,β1ββ€βbββ€β100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β100), where ai is the current volume of drink in the i-th mug. | ["12.000000\n11.000000\n10.000000\n9.000000\n8.000000", "-1"] | #include <stdio.h>
#include <stdlib.h>
int n,b,i,a[101],max=0;
double k[101],l;
int main(int argc, char *argv[])
{
scanf("%d%d",&n,&b);
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(a[i]>max)
max=a[i];
}
for(i=1;i<=n;i++)
{
k[i]=max-a[i];
b-=k[i];
if(b<0)
{
printf("-1\n");
return 0;}
}
l=(float)b / (float)n;
for(i=1;i<=n;i++)
{
k[i]+=l;
printf("%.6lf\n",k[i]);
}
return 0;
} | |
A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously: there were b milliliters poured in total. That is, the bottle need to be emptied; after the process is over, the volumes of the drink in the mugs should be equal. | Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1,βc2,β...,βcn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique. Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma. | C | 65fea461d3caa5a932d1e2c13e99a59e | 59a9ca607453d7369cca01b1221657e9 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"math"
] | 1333897500 | ["5 50\n1 2 3 4 5", "2 2\n1 100"] | null | PASSED | 1,100 | standard input | 2 seconds | The first line contains a pair of integers n, b (2ββ€βnββ€β100,β1ββ€βbββ€β100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1,βa2,β...,βan (0ββ€βaiββ€β100), where ai is the current volume of drink in the i-th mug. | ["12.000000\n11.000000\n10.000000\n9.000000\n8.000000", "-1"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n,b;
int a[108];
double result[108];
scanf("%d%d",&n,&b);
int i,sum;
for(i=0,sum=0; i<n; i++)
{
scanf("%d",&a[i]);
sum=sum+a[i];
}
double avg=(double)(sum+b)/(double)n;
int sus=1;
for(i=0; i<n; i++)
{
result[i]=avg-a[i];
if(result[i]<0)
{
printf("-1\n");
sus=0;
break;
}
}
if(sus==1)
{
for(i=0; i<n; i++)
printf("%.6lf\n",result[i]);
}
return 0;
}
| |
There are $$$n$$$ segments drawn on a plane; the $$$i$$$-th segment connects two points ($$$x_{i, 1}$$$, $$$y_{i, 1}$$$) and ($$$x_{i, 2}$$$, $$$y_{i, 2}$$$). Each segment is non-degenerate, and is either horizontal or vertical β formally, for every $$$i \in [1, n]$$$ either $$$x_{i, 1} = x_{i, 2}$$$ or $$$y_{i, 1} = y_{i, 2}$$$ (but only one of these conditions holds). Only segments of different types may intersect: no pair of horizontal segments shares any common points, and no pair of vertical segments shares any common points.We say that four segments having indices $$$h_1$$$, $$$h_2$$$, $$$v_1$$$ and $$$v_2$$$ such that $$$h_1 < h_2$$$ and $$$v_1 < v_2$$$ form a rectangle if the following conditions hold: segments $$$h_1$$$ and $$$h_2$$$ are horizontal; segments $$$v_1$$$ and $$$v_2$$$ are vertical; segment $$$h_1$$$ intersects with segment $$$v_1$$$; segment $$$h_2$$$ intersects with segment $$$v_1$$$; segment $$$h_1$$$ intersects with segment $$$v_2$$$; segment $$$h_2$$$ intersects with segment $$$v_2$$$. Please calculate the number of ways to choose four segments so they form a rectangle. Note that the conditions $$$h_1 < h_2$$$ and $$$v_1 < v_2$$$ should hold. | Print one integer β the number of ways to choose four segments so they form a rectangle. | C | 09890f75bdcfff81f67eb915379b325e | 60413025716d59c02b58f918cb330b48 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"geometry",
"bitmasks",
"sortings",
"data structures",
"brute force"
] | 1563115500 | ["7\n-1 4 -1 -2\n6 -1 -2 -1\n-2 3 6 3\n2 -2 2 4\n4 -1 4 3\n5 3 5 1\n5 2 1 2", "5\n1 5 1 0\n0 1 5 1\n5 4 0 4\n4 2 4 0\n4 3 4 5"] | NoteThe following pictures represent sample cases: | PASSED | 2,200 | standard input | 2 seconds | The first line contains one integer $$$n$$$ ($$$1 \le n \le 5000$$$) β the number of segments. Then $$$n$$$ lines follow. The $$$i$$$-th line contains four integers $$$x_{i, 1}$$$, $$$y_{i, 1}$$$, $$$x_{i, 2}$$$ and $$$y_{i, 2}$$$ denoting the endpoints of the $$$i$$$-th segment. All coordinates of the endpoints are in the range $$$[-5000, 5000]$$$. It is guaranteed that each segment is non-degenerate and is either horizontal or vertical. Furthermore, if two segments share a common point, one of these segments is horizontal, and another one is vertical. | ["7", "0"] | #include <stdio.h>
#include <malloc.h>
int sesh = 10009;
typedef struct mk
{
int choto,boro;
struct mk *tarpor;
}ok;
ok* Amk(int _,int __){
ok *tmp = (ok*)malloc(sizeof(ok));
tmp->choto = (_<__)?_:__;
tmp->boro = (_>__)?_:__;
tmp->tarpor = NULL;
return tmp;
}
typedef struct mkroy
{
int value;
struct mkroy *tarpor;
}roy;
roy *join(roy *head, int value){
roy *tmp = (roy*)malloc(sizeof(roy));
tmp->value = value;
tmp->tarpor = NULL;
if(head==NULL) return tmp;
tmp->tarpor = head;
return tmp;
}
ok* add(ok *matha,int a,int b){
ok *tm = Amk(a,b);
if(matha==NULL){
return tm;
}
tm->tarpor = matha;
return tm;
}
int joma[10009];
/// ******** TLE ****************
void utano(int jayga,int koto){
jayga++;
while (jayga<sesh)
{
joma[jayga]+=koto;
jayga += (jayga & (-jayga));
}
}
int dao(int jayga){
int uttor = 0;
jayga++;
while (jayga)
{
uttor+=joma[jayga];
jayga -= (jayga & (-jayga));
}
return uttor;
}
//*************** Accepted ****************
/*
* Can't understand how it's working.
* I got this from the EditorialL : https://codeforces.com/blog/entry/68405
*/
void update(int p, int v){
for(;p<sesh; p |= (p+1)){
joma[p]+=v;
}
}
int query(int p){
int ret = 0;
for(;p>=0; p = (p&(p+1))-1){
ret+=joma[p];
}
return ret;
}
int main(){
int n, x1, x2, y1, y2;
long long uttor = 0;
ok *soya[10009],*khara[10009];
roy *visited[10009];
for(int i = 0;i<10009;i++){
soya[i]=NULL;
khara[i]=NULL;
visited[i]=NULL;
}
scanf("%d",&n);
for (int i = 0; i < n; i++)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
x1+=5000,x2+=5000,y1+=5000,y2+=5000;
if(y1==y2){
soya[y1] = add(soya[y1],x1,x2);
}
else{
khara[x1] = add(khara[x1],y1,y2);
}
}
for(int y = 0;y<sesh;y++){
ok *sya = soya[y];
while (sya!=NULL)
{
for(int i = 0;i<sesh;i++) {
joma[i]=0;
visited[i]=NULL;
}
int bam = sya->choto;
int dan = sya->boro;
for(int x = bam;x<=dan;x++){
ok *kra = khara[x];
while (kra!=NULL)
{
int down = kra->choto;
int up = kra->boro;
if(down<=y && up>y){
utano(x,1);
visited[up] = join(visited[up],x);
}
kra = kra->tarpor;
}
}
for(int Y = y+1;Y<sesh;Y++){
ok *sy = soya[Y];
while (sy!=NULL)
{
int l = sy->choto;
int r = sy->boro;
int ferot = dao(r)-dao(l-1);
uttor += (ferot * (ferot-1)/2);
sy = sy->tarpor;
}
roy *tmp = visited[Y];
while (tmp!=NULL)
{
utano(tmp->value,-1);
tmp=tmp->tarpor;
}
}
sya = sya->tarpor;
}
}
printf("%lld\n",uttor);
return 0;
}
| |
There are $$$n$$$ segments drawn on a plane; the $$$i$$$-th segment connects two points ($$$x_{i, 1}$$$, $$$y_{i, 1}$$$) and ($$$x_{i, 2}$$$, $$$y_{i, 2}$$$). Each segment is non-degenerate, and is either horizontal or vertical β formally, for every $$$i \in [1, n]$$$ either $$$x_{i, 1} = x_{i, 2}$$$ or $$$y_{i, 1} = y_{i, 2}$$$ (but only one of these conditions holds). Only segments of different types may intersect: no pair of horizontal segments shares any common points, and no pair of vertical segments shares any common points.We say that four segments having indices $$$h_1$$$, $$$h_2$$$, $$$v_1$$$ and $$$v_2$$$ such that $$$h_1 < h_2$$$ and $$$v_1 < v_2$$$ form a rectangle if the following conditions hold: segments $$$h_1$$$ and $$$h_2$$$ are horizontal; segments $$$v_1$$$ and $$$v_2$$$ are vertical; segment $$$h_1$$$ intersects with segment $$$v_1$$$; segment $$$h_2$$$ intersects with segment $$$v_1$$$; segment $$$h_1$$$ intersects with segment $$$v_2$$$; segment $$$h_2$$$ intersects with segment $$$v_2$$$. Please calculate the number of ways to choose four segments so they form a rectangle. Note that the conditions $$$h_1 < h_2$$$ and $$$v_1 < v_2$$$ should hold. | Print one integer β the number of ways to choose four segments so they form a rectangle. | C | 09890f75bdcfff81f67eb915379b325e | 23f53d59453606b03f91dfc67e258f72 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"geometry",
"bitmasks",
"sortings",
"data structures",
"brute force"
] | 1563115500 | ["7\n-1 4 -1 -2\n6 -1 -2 -1\n-2 3 6 3\n2 -2 2 4\n4 -1 4 3\n5 3 5 1\n5 2 1 2", "5\n1 5 1 0\n0 1 5 1\n5 4 0 4\n4 2 4 0\n4 3 4 5"] | NoteThe following pictures represent sample cases: | PASSED | 2,200 | standard input | 2 seconds | The first line contains one integer $$$n$$$ ($$$1 \le n \le 5000$$$) β the number of segments. Then $$$n$$$ lines follow. The $$$i$$$-th line contains four integers $$$x_{i, 1}$$$, $$$y_{i, 1}$$$, $$$x_{i, 2}$$$ and $$$y_{i, 2}$$$ denoting the endpoints of the $$$i$$$-th segment. All coordinates of the endpoints are in the range $$$[-5000, 5000]$$$. It is guaranteed that each segment is non-degenerate and is either horizontal or vertical. Furthermore, if two segments share a common point, one of these segments is horizontal, and another one is vertical. | ["7", "0"] | #include <stdio.h>
#include <malloc.h>
int sesh = 10009;
typedef struct mk
{
int choto,boro;
struct mk *tarpor;
}ok;
ok* Amk(int _,int __){
ok *tmp = (ok*)malloc(sizeof(ok));
tmp->choto = (_<__)?_:__;
tmp->boro = (_>__)?_:__;
tmp->tarpor = NULL;
return tmp;
}
typedef struct mkroy
{
int value;
struct mkroy *tarpor;
}roy;
roy *join(roy *head, int value){
roy *tmp = (roy*)malloc(sizeof(roy));
tmp->value = value;
tmp->tarpor = NULL;
if(head==NULL) return tmp;
tmp->tarpor = head;
return tmp;
}
ok* add(ok *matha,int a,int b){
ok *tm = Amk(a,b);
if(matha==NULL){
return tm;
}
tm->tarpor = matha;
return tm;
}
int joma[10009];
/// ******** TLE ****************
void utano(int jayga,int koto){
while (jayga<sesh)
{
joma[jayga]+=koto;
jayga += (jayga & (-jayga));
}
}
int dao(int jayga){
int uttor = 0;
while (jayga>0)
{
uttor+=joma[jayga];
jayga -= (jayga & (-jayga));
}
return uttor;
}
//*************** Accepted ****************
/*
* Can't understand how it's working.
* I got this from the EditorialL : https://codeforces.com/blog/entry/68405
*/
void update(int p, int v){
for(;p<sesh; p |= (p+1)){
joma[p]+=v;
}
}
int query(int p){
int ret = 0;
for(;p>=0; p = (p&(p+1))-1){
ret+=joma[p];
}
return ret;
}
int main(){
int n, x1, x2, y1, y2;
long long uttor = 0;
ok *soya[10009],*khara[10009];
roy *visited[10009];
for(int i = 0;i<10009;i++){
soya[i]=NULL;
khara[i]=NULL;
visited[i]=NULL;
}
scanf("%d",&n);
for (int i = 0; i < n; i++)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
x1+=5000,x2+=5000,y1+=5000,y2+=5000;
if(y1==y2){
soya[y1] = add(soya[y1],x1,x2);
}
else{
khara[x1] = add(khara[x1],y1,y2);
}
}
for(int y = 0;y<sesh;y++){
ok *sya = soya[y];
while (sya!=NULL)
{
for(int i = 0;i<sesh;i++) {
joma[i]=0;
visited[i]=NULL;
}
int bam = sya->choto;
int dan = sya->boro;
for(int x = bam;x<=dan;x++){
ok *kra = khara[x];
while (kra!=NULL)
{
int down = kra->choto;
int up = kra->boro;
if(down<=y && up>y){
update(x,1);
visited[up] = join(visited[up],x);
}
kra = kra->tarpor;
}
}
for(int Y = y+1;Y<sesh;Y++){
ok *sy = soya[Y];
while (sy!=NULL)
{
int l = sy->choto;
int r = sy->boro;
int ferot = query(r)-query(l-1);
uttor += (ferot * (ferot-1)/2);
sy = sy->tarpor;
}
roy *tmp = visited[Y];
while (tmp!=NULL)
{
update(tmp->value,-1);
tmp=tmp->tarpor;
}
}
sya = sya->tarpor;
}
}
printf("%lld\n",uttor);
return 0;
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 0bf6f01f66f3471139b6ff5ae3cded9b | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | //codeforces_1073A
#include <stdio.h>
#include <stdlib.h>
int main(){
int n;scanf("%d",&n);
char s[n];scanf("%s",s);
for ( int k = 0; k < n-1; k++){
if ( s[k] != s[k+1] ){
printf("YES\n%c%c\n",s[k],s[k+1]);
return 0;
}
}
printf("NO\n");
return 0;
} | |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 5596902b71c54b9f429b046a220598d6 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include <stdio.h>
#define ABC 26
void initialize(int *arr, int length) {
for (int i=0; i<length; i++) arr[i]=0;
}
void print(char *str, int start, int end) {
for (int i=start; i<end; i++) printf("%c",str[i]);
}
int check(int *arr, int length, int bound) {
for (int i=0; i<length; i++) {
if (arr[i]>bound) return 0;
}
return 1;
}
int is_diverse(char *str, int start, int end) {
int sieve[ABC],lim=(end-start)/2;
initialize(sieve,ABC);
for (int i=start; i<end; i++) sieve[str[i]-'a']++;
return check(sieve,ABC,lim);
}
int div_substring(char *str, int length) {
for (int i=0; i<length; i++) {
for (int j=i+1; j<=length; j++) {
if (is_diverse(str,i,j)) {
printf("YES\n");
print(str,i,j);
return 1;
}
}
}
printf("NO");
}
int main() {
int len;
scanf("%d\n",&len);
char word[len];
scanf("%s",word);
div_substring(word,len);
return 0;
} | |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 71e17d7c896258f3c1233f40087e47a6 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include<stdio.h>
#include<string.h>
int main()
{
int n, i, count=0;
char s[1005];
scanf("%d%s", &n, s);
for(i=0 ; i<n-1 ; i++)
{
if(s[i]!=s[i+1])
{
printf("YES\n%c%c", s[i], s[i+1]);
return 0;
}
}
printf("NO");
return 0;
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 9d42104cf6edfb40a3fa98af7fd77395 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
char ntemp[6];
fgets(ntemp, 6, stdin);
float length = 0;
length = atof(ntemp);
double halflength = length / 2;
char substring[3];
char letter1, letter2;
float a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
char word[1001];
fgets(word, 1001, stdin); word[strcspn(word, "\n")] = '\0';
for(int counter = 0; counter < length - 1; counter++) {
a = 1200;
b = 1200;
c = 1200;
d = 1200;
e = 1200;
f = 1200;
g = 1200;
h = 1200;
i = 1200;
j = 1200;
k = 1200;
l = 1200;
m = 1200;
n = 1200;
o = 1200;
p = 1200;
q = 1200;
r = 1200;
s = 1200;
t = 1200;
u = 1200;
v = 1200;
w = 1200;
x = 1200;
y = 1200;
z = 1200;
substring[0] = substring[1];
letter1 = word[counter];
switch(letter1) {
case 'a': a = 0; a++; break;
case 'b': b = 0; b++; break;
case 'c': c = 0; c++; break;
case 'd': d = 0; d++; break;
case 'e': e = 0; e++; break;
case 'f': f = 0; f++; break;
case 'g': g = 0; g++; break;
case 'h': h = 0; h++; break;
case 'i': i = 0; i++; break;
case 'j': j = 0; j++; break;
case 'k': k = 0; k++; break;
case 'l': l = 0; l++; break;
case 'm': m = 0; m++; break;
case 'n': n = 0; n++; break;
case 'o': o = 0; o++; break;
case 'p': p = 0; p++; break;
case 'q': q = 0; q++; break;
case 'r': r = 0; r++; break;
case 's': s = 0; s++; break;
case 't': t = 0; t++; break;
case 'u': u = 0; u++; break;
case 'v': v = 0; v++; break;
case 'w': w = 0; w++; break;
case 'x': x = 0; x++; break;
case 'y': y = 0; y++; break;
case 'z': z = 0; z++; break;
}
letter2 = word[counter+1];
if(a == 1200) {
a = 0;
}
if(b == 1200) {
b = 0;
}
if(c == 1200) {
c = 0;
}
if(d == 1200) {
d = 0;
}
if(e == 1200) {
e = 0;
}
if(f == 1200) {
f = 0;
}
if(g == 1200) {
g = 0;
}
if(h == 1200) {
h = 0;
}
if(i == 1200) {
i = 0;
}
if(j == 1200) {
j = 0;
}
if(k == 1200) {
k = 0;
}
if(l == 1200) {
l = 0;
}
if(m == 1200) {
m = 0;
}
if(n == 1200) {
n = 0;
}
if(o == 1200) {
o = 0;
}
if(p == 1200) {
p = 0;
}
if(q == 1200) {
q = 0;
}
if(r == 1200) {
r = 0;
}
if(s == 1200) {
s = 0;
}
if(t == 1200) {
t = 0;
}
if(u == 1200) {
u = 0;
}
if(v == 1200) {
v = 0;
}
if(w == 1200) {
w = 0;
}
if(x == 1200) {
x = 0;
}
if(y == 1200) {
y = 0;
}
if(z == 1200) {
z = 0;
}
switch(letter2) {
case 'a': a++; break;
case 'b': b++; break;
case 'c': c++; break;
case 'd': d++; break;
case 'e': e++; break;
case 'f': f++; break;
case 'g': g++; break;
case 'h': h++; break;
case 'i': i++; break;
case 'j': j++; break;
case 'k': k++; break;
case 'l': l++; break;
case 'm': m++; break;
case 'n': n++; break;
case 'o': o++; break;
case 'p': p++; break;
case 'q': q++; break;
case 'r': r++; break;
case 's': s++; break;
case 't': t++; break;
case 'u': u++; break;
case 'v': v++; break;
case 'w': w++; break;
case 'x': x++; break;
case 'y': y++; break;
case 'z': z++; break;
}
substring[0] = word[counter];
substring[1] = word[counter+1];
if(substring[0] != substring[1]) {
if(a < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(b < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(c < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(d < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(e < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(f < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(g < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(h < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(i < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(j < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(k < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(l < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(m < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(n < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(o < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(p < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(q < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(r < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(s < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(t < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(u < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(v < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(w < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(x < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(y < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
if(z < halflength) {
printf("YES\n");
printf("%c%c\n", substring[0], substring[1]);
exit(0);
}
}
}
printf("NO");
return 0;
} | |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 84d37c2dff1045221d8f4fbb40f6721f | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include <stdio.h>
#include <string.h>
char a[1005];
char b[30];
int main ()
{
int n;
scanf("%d",&n);
int flag=1;
scanf("%s",a);
for (int i=1;i<strlen(a);i++)
if (a[i]==a[i-1])
flag=1;
else
{
flag=0;
break;
}
if (flag)
printf("NO\n");
else
{
printf("YES\n");
for (int i=1;i<strlen(a);i++)
if(a[i]==a[i-1])
;
else
{
printf("%c%c\n",a[i-1],a[i]);
break;
}
}
return 0;
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 6d73128cc0c185dbbe26126bfc7bd91a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | //Alan SuΓ‘rez SantamarΓa A01328931
//Estructura de datos
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char number[100];
fgets(number,100,stdin);
int num=atoi(number);
char entry[1002];
fgets(entry,1002,stdin);
char * num1= entry;
char pal1;
char pal2;
int flag=0;
for(int i=0;i<num-1;i++){
pal1=entry[i];
pal2=entry[i+1];
if(pal1!=pal2){
flag=1;
printf("YES\n");
printf("%c%c",pal1,pal2);
break;
}
}
if(flag==0){
printf("NO\n");
}
//j o r j o v
//1 2 0 0 0 0
//0 1 2 0 0 0
//0 0 1 2 0 0
//0 0 0 1 2 0
//0 0 0 0 1 2
return 0;
} | |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 2c250a5a6604943801fa4a72825cc64b | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include <stdio.h>
int main(void) {
int a;
scanf("%d", &a);
char b[1001];
scanf("%s", b);
if (a > 1) {
for (int i = 0; i < a-1; i++) {
if (b[i] != b[i+1]) {
printf("YES\n");
printf("%c%c\n", b[i], b[i+1]);
return 0;
}
}
}
printf("NO\n");
return 0;
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 61c395a99f103183b649ed92abebc554 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int n,i,j,p;
char a[10000],b[3];
scanf("%d",&n);
scanf("%s",&a);
if(n>1){
for(i=0; i<n-1; i++){
if(a[i]!=a[i+1]){
printf("YES\n");
printf("%c%c",a[i],a[i+1]);
return 0;
}
}
printf("NO\n");
}
else printf("NO\n");
} | |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 2b929e5c849f6ae56c466ed14b599dbb | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include<stdio.h>
int count =0;
int main ()
{
int n,flag=0;
scanf("%d",&n);
char s[n+1];
scanf("%s",s);
if(n==1)
printf("NO");
else
{
for(int i=0;i<n-1;i++)
{
if(s[i]!=s[i+1])
{
printf("YES\n");
printf("%c%c",s[i],s[i+1]);
flag=1;
break;
}
else
count++;
}
if(count >=(n/2) && flag==0)
printf("NO");
}
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 51d47182eec38045c52fe9fbccd37a1d | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main() {
int a,n,x;
scanf("%d",&a);
char p[a+1];
scanf("%s",p);
for(int c = 0;c<a;c++){
for(int c2 = c;c2<a;c2++){
x = 0;
for(int c3 = c;c3<=c2;c3++){
n = 0;
for(int c4 = c3;c4<=c2;c4++){
if(p[c3] == p[c4]){
n++;
}
}
if(n>(c2-c+1)/2 ){
x = 1;
break;
}
}
if(x == 0){
printf("YES\n");
for(int c3 = c;c3<=c2;c3++){
printf("%c",p[c3]);
}
return 0;
}
}
}
printf("NO");
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 36ee6838c2392ae0ccb65f005c6c88f7 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
char x[n];
scanf("%s",x);
for(int i=1;i<n;i++)
{
if(x[i-1]!=x[i])
{
printf("YES\n%c%c",x[i-1],x[i]);
return 0;
}
}
printf("NO");
return 0;
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | fc76558985a7c003fa109fe798451461 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include<stdio.h>
int main(){
int a[128]={0},n,w=1;scanf("%d",&n);
char s[n+1],g;
scanf("%c",&g);
scanf("%s",s);
for(int i=0;i<n;i++)a[(int)(s[i])]++;
for(int i=0;i<128;i++){
if(a[i]>n-1)w=0;}
if(w){printf("YES\n");
for(int i=0;i<n-1;i++){
if(s[i]!=s[i+1]){
printf("%c%c\n",s[i],s[i+1]);
break;}}}
else printf("NO\n");
return 0;}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | bfebedae3ab046a9e075a848250c1d67 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include<stdio.h>
int main ()
{
int n,m=0,p;
scanf("%d",&n);
char s[n+1];
scanf("%s",s);
for(p=0;p<n-1;p++)
{
if(s[p]!=s[p+1])
{
m=1;
printf("YES\n");
printf("%c%c\n",s[p],s[p+1]);
break;}
}
if(m==0)
printf("NO\n");
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 6d3430a88a7f67d1315bb44fd1d27c60 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include <stdio.h>
#include <string.h>
int main()
{
int n,i,j,m,p;
char a[1000];
char b[26]="abcdefghijklmnopqrstuvwxyz";
scanf("%d",&n);
scanf("%s",&a);
if(n==1){
printf("NO");
}
else{
for(p=0; p<n; p++){
if(a[p]!=a[p+1]){
printf("YES\n");
printf("%c%c",a[p],a[p+1]);
break;
}
else if(a[p]==a[p+1] && p==n-2){
printf("NO");
break;
}
else{
continue;
}
}
}
return 0;
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | fcce8d8de6a04733c63eedc8afb2d9ac | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
char a[1050];
scanf("%s",a);
int c=0;
for(int i=1;i<n;i++)
{
if(a[i]!=a[i-1])
{
c=1;
printf("YES\n%c%c\n",a[i-1],a[i]);
break;
}
}
if(c==0) printf("NO\n");
return 0;
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 06bedc18bedccf231f20bae71578f0b1 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include<stdio.h>
int main(void) {
int n,i,flag=0;
scanf("%d",&n);
char string[n];
scanf("%s",string);
for(i=1;i<n;i++) {
if(string[i]!=string[i-1]) {
flag=1;
break;
}
}
if(flag) {
printf("YES\n%c%c\n",string[i-1],string[i]);
}
else
printf("NO\n");
return 0;
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | a14d0437085b88ee44c8060228c4b0f7 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include<stdio.h>
int main()
{
int n,c=0;
scanf("%d",&n);
char s[n+1],t[3];
scanf("%s",s);
for(int i=0;i<n;i++)
{
s[n]='#';
if(s[i]!=s[i+1] && i<n-1)
{
c=0;t[0]=s[i];t[1]=s[i+1];
t[2]='\0';
printf("YES\n");
printf("%s\n",t);
return 0;
}
}
printf("NO\n");
return 0;
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | afdce05d30ad696d20547fa02f24ed89 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include<stdio.h>
int main()
{
int n,i=0,j=0;
scanf("%d",&n);
char s[n+1];
scanf("%s",&s);
while(s[j]!=0)
{
j=j+1;
}
while(i<j-1)
{
if(s[i]!=s[i+1])
{
printf("YES\n");
printf("%c%c",s[i],s[i+1]);
exit(0);
}
i=i+1;
}
printf("NO\n");
} | |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 1bc553167ebff691cdd00f99226f0157 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include<stdio.h>
#include<string.h>
#define ll long long int
int main(){
int n,t1=0;
char c[1000],ans[2];
scanf("%d%s",&n,&c);
for(ll i=0;i<n-1;i++){
if(c[i]!=c[i+1]){
ans[0]=c[i];
ans[1]=c[i+1];
t1++;
break;
}
}
if(t1!=0)
printf("YES\n%c%c\n",ans[0],ans[1]);
else
printf("NO\n");
return 0;
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 94fd1af1558515c058382c01bea6b2d4 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include<stdio.h>
int main()
{
int n,i;
char a[1001];
scanf("%d%s",&n,a);
for(i=0; i<n-1; i++)
if(a[i]!=a[i+1])
{
printf("YES\n%c%c\n",a[i],a[i+1]);
return 0;
}
printf("NO\n");
return 0;
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 5fa85deda1906f28241723062c847c42 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | //nice implementation problem related to strings;
#include<stdio.h>
int main()
{
int n,i,j,iteri=0,count=0;
scanf("%d",&n);
int a[257]={0};
char s[n+1];
scanf("%s",s);
// if(s[n]=='\0')
// printf("Yo!\n");
for(i=0;i<n;)
{
iteri++;
// printf("Yo!\n");
for(j=i;j<n;j++)
{
a[s[j]]++;
// printf("a[s[%d]]: %d\n",j,a[s[j]]);
// printf("j : %d\n",j);
if(a[s[j]]<=(j-i+1)/2)
{
printf("YES\n");
count=1;
s[j+1]='\0';
printf("%s\n",&s[i]);
break;
}
else if(((j-i+1)/2!=0)||(i==n-1))
{
i++;
break;
}
}
// printf("i : %d\n",i);
//getchar();
// printf("j : %d\n",j);
if(count==1)
break;
}
// printf("j : %d\n",j);
if(((j>=n)||(i>=n))&&(count==0))
printf("NO\n");
// printf("iteri: %d\n",iteri);
return 0;
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | f85771f1a21a00d54d958f323157aa7b | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include <stdio.h>
int main(void)
{
int n;
scanf("%d", &n);
char str[1007];
scanf("%s", str);
int count=0;
// for(int i=0;i<n;i++){
// if (str[i]==str[i+1])
// count++;
// }
// if (count==n)
// { printf("NO\n");
// return 0;
//}
for (int i=0;i<n-1;i++){
if (str[i] != str[i + 1])
{
printf("YES\n");
printf("%c%c\n", str[i], str[i+1]);
return 0;
}
}
printf("NO\n");
return 0;
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 66c47f6e7c0d5eddeea9425a470c8ac3 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include<stdio.h>
int main(){
int n,i;
char s[1002];
scanf("%d\n",&n);
gets(s);
for(i = 1; i < n; i++){
if(s[i - 1] != s[i]){
printf("YES\n");
printf("%c%c",s[i - 1],s[i]);
return 0;
}
}
printf("NO");
return 0;
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 39fba1e8b65936884e527078e83fed4f | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] |
#include<stdio.h>
int arr[200][1001];
int main()
{
int n;
char str[1001];
scanf("%d",&n);
scanf("%s",str);
for(int i=0;i<n;i++)
{
arr[str[i]][i]=1;
}
for(int i=1;str[i]!='\0';i++)
{
for(int k=0;k<26;k++)
arr[k+'a'][i]+=arr[k+'a'][i-1];
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
int max=0;
for(int k=0;k<26;k++)
{
if(i!=0)
{
if(max < arr[k+'a'][j]-arr[k+'a'][i-1])
max=arr[k+'a'][j]-arr[k+'a'][i-1];
}
else
{
if(max < arr[k+'a'][j])
max=arr[k+'a'][j];
}
}
if(max <=(j-i+1)/2)
{
printf("YES\n");
for(int l=i;l<=j;l++)
printf("%c",str[l]);
return 0;
}
}
}
printf("NO\n");
return 0;
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 5fd2df25e81883ff59635164d24bd8cf | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include <stdio.h>
int main()
{
int n, find = -1;
char data[1005];
scanf("%d", &n);
scanf("%s", data);
for (int i = 0; i < n - 1; ++i)
if (data[i] != data[i + 1])
{
printf("YES\n%c%c", data[i], data[i + 1]);
find = 1;
break;
}
if (find < 0)
printf("NO");
return 0;
} | |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 788b76319727fbc605cd3d890c76e5ee | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include <stdio.h>
int main(void){
char a[1000];
int m = 0;
scanf("%d", &m);
scanf("%s", a);
int i = 0;
for(i = 1;i < m; i++)
{
if(a[i-1] != a[i])
{
printf("YES\n%c%c", a[i-1], a[i]);
goto bbb;
}
}
if(i == m) printf("NO");
bbb: return 0;
} | |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 43bcb0e02d0790bc49d67aeec7bb8c55 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include<stdio.h>
#include<string.h>
int main()
{
int n,i,a[26]={0},b[26]={0},c=0;
char s[10005];
scanf("%d",&n);
scanf("%s",s);
for(i=0;i<strlen(s);i++)
a[s[i]-'a']++;
for(i=0;i<26;i++){
if(a[i]>0)
c++;
if(c>1){
printf("YES\n");
break;
}
}
if(c==1){
printf("NO\n");
return 0;
}
else{
for(i=0;i<strlen(s)-1;i++){
if(s[i]!=s[i+1])
{
printf("%c%c\n",s[i],s[i+1]);
return 0;
}
}
}
return 0;
} | |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | c2ed067b411ef9e0804b42d1816a8161 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include<stdio.h>
#include<string.h>
int main()
{
int n;
scanf("%d", &n);
char input[n];
scanf("%s", input);
int check[26], i, j, max=1, prev=0;
prev=input[0]-97;
for(i=1; i<n; i++)
{
if(prev==input[i]-97)
{
max++;
}
else
{
prev=input[i]-97;
max=1;
break;
}
}
if(max>n/2)
{
printf("NO");
}
else
{
printf("YES\n");
j=n/2;
if(j!=0)
{
for(i=0; i<n; i++)
{
if(input[i]!=input[i+1])
{
printf("%c%c", input[i], input[i+1]);
return 0;
}
}
}
else
printf("%s", input);
}
}
| |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 85e5c9e72bd4cdeeb4a6b1cc0404f93d | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include <stdio.h>
int count=1;
int NotAvailable(char* str, int begin, int k)
{
for (int i=k-1; i>=begin; i--)
{
if(str[i]==str[k]&&++count>(k-begin+1)/2)
{
count=1;
return 0;
}
}
count=1;
return 1;
}
int main (void)
{
int n;
char str[1005];
scanf("%d", &n);
scanf("%s", str);
int begin=0, end=0;
for (int i=1; i<n; i++)
{
if(NotAvailable(str, begin, i))
{
end=i;
printf("YES\n");
for (int i=begin; i<=end; i++)
printf("%c", str[i]);
break;
}
else
{
begin=i;
end=i;
}
}
if (begin==end)
printf("NO\n");
return 0;
} | |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | daa665a837df96d2de50cf0b36706c10 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include<stdio.h>
int main()
{
int n,f=0,p=0;
scanf("%d",&n);
char ch[n+1];
scanf("%s",ch);
ch[n]='\0';
for(int i=0;i<n-1;i++)
{
if(ch[i]!=ch[i+1])
{
p=i;
f=1;
break;
}
}
if(f==1)
{
printf("%s\n%c%c","YES",ch[p],ch[p+1]);
}
else
printf("%s","NO");
return 0;
} | |
You are given a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.A substring of string $$$s$$$ is a continuous segment of letters from $$$s$$$. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it.Let's call some string of length $$$n$$$ diverse if and only if there is no letter to appear strictly more than $$$\frac n 2$$$ times. For example, strings "abc" and "iltlml" are diverse and strings "aab" and "zz" are not.Your task is to find any diverse substring of string $$$s$$$ or report that there is none. Note that it is not required to maximize or minimize the length of the resulting substring. | Print "NO" if there is no diverse substring in the string $$$s$$$. Otherwise the first line should contain "YES". The second line should contain any diverse substring of string $$$s$$$. | C | ce4443581d4ee12db6607695cd567070 | 6505f532dc40fe08718631d9d4bb0acc | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation",
"strings"
] | 1540478100 | ["10\ncodeforces", "5\naaaaa"] | NoteThe first example has lots of correct answers. Please, restrain yourself from asking if some specific answer is correct for some specific test or not, these questions always lead to "No comments" answer. | PASSED | 1,000 | standard input | 1 second | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) β the length of string $$$s$$$. The second line is the string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. | ["YES\ncode", "NO"] | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
int n;
int i;
int t = 0;
int k;
scanf("%d", &n);
char s[n];
scanf("%s", s);
for(i = 0; i < n - 1; i++){
if(s[i] != s[i + 1]){
t = 1;
k = i;
break;
}
}
if(t == 0){
printf("NO\n");
}else{
printf("YES\n");
printf("%c%c\n", s[k], s[k + 1]);
}
return 0;
} | |
Little John aspires to become a plumber! Today he has drawn a grid consisting of n rows and m columns, consisting of nβΓβm square cells.In each cell he will draw a pipe segment. He can only draw four types of segments numbered from 1 to 4, illustrated as follows: Each pipe segment has two ends, illustrated by the arrows in the picture above. For example, segment 1 has ends at top and left side of it.Little John considers the piping system to be leaking if there is at least one pipe segment inside the grid whose end is not connected to another pipe's end or to the border of the grid. The image below shows an example of leaking and non-leaking systems of size 1βΓβ2. Now, you will be given the grid that has been partially filled by Little John. Each cell will either contain one of the four segments above, or be empty. Find the number of possible different non-leaking final systems after Little John finishes filling all of the empty cells with pipe segments. Print this number modulo 1000003 (106β+β3).Note that rotations or flipping of the grid are not allowed and so two configurations that are identical only when one of them has been rotated or flipped either horizontally or vertically are considered two different configurations. | Print a single integer denoting the number of possible final non-leaking pipe systems modulo 1000003 (106β+β3). If there are no such configurations, print 0. | C | 07cbcf6e1f1e7f1a6ec45241cf9ac2a9 | d34ab8e14422b310ffb95e3142291fdb | GNU C | standard output | 256 megabytes | train_000.jsonl | [] | 1316098800 | ["2 2\n13\n..", "3 1\n1\n4\n.", "2 2\n3.\n.1"] | NoteFor the first example, the initial configuration of the grid is as follows. The only two possible final non-leaking pipe configurations are as follows: For the second example, the initial grid is already leaking, so there will be no final grid that is non-leaking.For the final example, there's only one possible non-leaking final grid as follows. | PASSED | 2,200 | standard input | 3 seconds | The first line will contain two single-space separated integers n and m (1ββ€βn,βm,βnΒ·mββ€β5Β·105) β the number of rows and columns respectively. Then n lines follow, each contains exactly m characters β the description of the grid. Each character describes a cell and is either one of these: "1" - "4" β a pipe segment of one of four types as described above "." β an empty cell | ["2", "0", "1"] | #include <stdio.h>
int a[500000][2];
int b[500000][2];
int main()
{
int n, m, x = 1, mod = 1000003, i, j;
char s[500001];
scanf("%d %d", &n, &m);
for (i = 0; i < n; i++) {
for (j = 0; j < 2; j++) {
a[i][j] = 1;
}
}
for (i = 0; i < m; i++) {
for (j = 0; j < 2; j++) {
b[i][j] = 1;
}
}
for (i = 0; i < n; i++) {
scanf("%s", s);
for (j = 0; j < m; j++) {
if (s[j] == '1' || s[j] == '2') {
a[i][j % 2] = 0;
} else if (s[j] == '3' || s[j] == '4') {
a[i][(j + 1) % 2] = 0;
}
}
for (j = 0; j < m; j++) {
if (s[j] == '1' || s[j] == '4') {
b[j][i % 2] = 0;
} else if (s[j] == '2' || s[j] == '3') {
b[j][(i + 1) % 2] = 0;
}
}
}
for (i = 0; i < n; i++) {
x *= (a[i][0] + a[i][1]);
x %= mod;
}
for (i = 0; i < m; i++) {
x *= (b[i][0] + b[i][1]);
x %= mod;
}
printf("%d\n", x);
return 0;
}
| |
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn't change. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn't count as changes. You should obtain palindrome with the minimal number of changes. If there are several ways to do that you should get the lexicographically (alphabetically) smallest palindrome. So firstly you should minimize the number of changes and then minimize the palindrome lexicographically. | Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes. | C | f996224809df700265d940b12622016f | a1dcf15c624646f6fd8dcf3c14d010d0 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"greedy",
"strings"
] | 1448636400 | ["aabc", "aabcd"] | null | PASSED | 1,800 | standard input | 2 seconds | The only line contains string s (1ββ€β|s|ββ€β2Β·105) consisting of only lowercase Latin letters. | ["abba", "abcba"] | #include<stdio.h>
#include<string.h>
int check(int* q,int s,int l)
{ if(s<0)
return l;
s--;
if(q[s]%2!=0)
{ q[s]-=1;
l++;
l=check(q,s,l);
if(l>1&&(q[s]%2==0))
{
q[s]+=2;
l-=2;
return l;
}
if(l==1&&(q[s]%2==0))
{
q[s]+=1;
l-=1;
}
return l;
}
l=check(q,s,l);
// printf("%d",l);
// printf("%d",l);
return l;
}
main()
{
char arr[200000];
char g;
g=32;
int i,j,k;
gets(arr);
k=strlen(arr);
/* if(k==1)
{
puts(arr);
return 0;
}
*/
int brr[26];
for(i=0;i<26;i++)
{
brr[i]=0;
}
char *p;
p=arr;
for(i=0;i<k;i++)
{
brr[p[i]-97]+=1;
}
check(brr,26,0);
int v;
// for(i=0;i<26;i++)
// printf("%d ",brr[i]);
int u;
for(i=0;i<26;i++)
{
if(brr[i]%2==0&&brr[i]!=0)
{ for(v=0;v<brr[i]/2;v++)
printf("%c",i+97);
}
if(brr[i]%2!=0&&brr[i]>0)
{ for(v=0;v<brr[i]/2;v++)
printf("%c",i+97);
brr[i]-=1;
g=i;
u=brr[i];
}
}
if(g!=32)
printf("%c",g+97);
for(i=25;i>=0;i--)
{
if(brr[i]%2==0&&brr[i]!=0)
for(v=0;v<brr[i]/2;v++)
printf("%c",i+97);
}
// for(i=0;i<26;i++)
// printf("%d ",brr[i]);
return 0;
}
| |
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn't change. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn't count as changes. You should obtain palindrome with the minimal number of changes. If there are several ways to do that you should get the lexicographically (alphabetically) smallest palindrome. So firstly you should minimize the number of changes and then minimize the palindrome lexicographically. | Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes. | C | f996224809df700265d940b12622016f | 1c1fa8b80006b62b0ab7ebb274380edc | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"greedy",
"strings"
] | 1448636400 | ["aabc", "aabcd"] | null | PASSED | 1,800 | standard input | 2 seconds | The only line contains string s (1ββ€β|s|ββ€β2Β·105) consisting of only lowercase Latin letters. | ["abba", "abcba"] | #include <stdio.h>
int main()
{
char s[200005];
int a[27],i,j,k;
scanf("%s",s);
//printf("%c\n",s[0]);
for(i=0;i<27;i++)
{
a[i]=0;
}
i=0;
while(s[i]!='\0')
{
a[s[i]-96]++;
i++;
}
int l=i,m=0,n=27;
//printf("%d\n",i);
while(1)
{
for(i=m+1;i<=26;i++)
{
if( (a[i]%2) !=0 )
{
m=i;
break;
}
}
for(j=n-1;j>0;j--)
{
if( (a[j]%2) !=0 )
{
n=j;
break;
}
}
if(i>=j) break;
else
{
a[m]++;
a[n]--;
}
}
//for(i=1;i<27;i++) printf("%d ",a[i]); printf("\n");
char b[l+1];
if(l%2!=0)
for(i=1;i<=26;i++)
{
if( (a[i]%2) !=0 )
{
a[i]--;
b[(l+1)/2]=i+96;
break;
}
}
//printf("%c\n",b[(l+1)/2] );
//for(i=1;i<27;i++) printf("%d ",a[i]); printf("\n");
i=1;
j=l;
k=1;
while(i<j)
{
if(a[k]==0)
k++;
else
{
a[k]=a[k]-2;
b[i]=k+96;
b[j]=k+96;
i++;
j--;
}
}
for(i=1;i<=l;i++) printf("%c",b[i]);
printf("\n");
return 0;
} | |
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn't change. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn't count as changes. You should obtain palindrome with the minimal number of changes. If there are several ways to do that you should get the lexicographically (alphabetically) smallest palindrome. So firstly you should minimize the number of changes and then minimize the palindrome lexicographically. | Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes. | C | f996224809df700265d940b12622016f | b00cb9c3f067b986ef409f7531c8a31a | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"greedy",
"strings"
] | 1448636400 | ["aabc", "aabcd"] | null | PASSED | 1,800 | standard input | 2 seconds | The only line contains string s (1ββ€β|s|ββ€β2Β·105) consisting of only lowercase Latin letters. | ["abba", "abcba"] | #include <stdio.h>
#include <string.h>
#define MAX 200000
int hist[256];
int main ()
{
char c;
int n,i,j,k;
int num_odd = 0;
i = 0;
while ('\n' != (c = getchar()))
{
i++;
hist[c]++;
}
n = i;
for (i = 'a'; i <= 'z'; i++)
{
if (hist[i] % 2 == 1)
{
num_odd++;
}
}
if (n%2 == 1)
num_odd--;
i = 'a';
j = 'z';
for (k = num_odd; k > 0; k -= 2)
{
while (hist[i]%2 == 0)
i++;
while (hist[j]%2 == 0)
j--;
hist[i]++;
hist[j]--;
}
int centre = 0;
for (i = 'a'; i <= 'z'; i++)
{
if (hist[i]%2 == 1)
{
centre = i;
}
for (j = 0; j < hist[i]/2; j++)
{
printf ("%c", i);
}
hist[i] /= 2;
}
if (centre)
{
printf ("%c", centre);
}
for (i = 'z'; i >= 'a'; i--)
{
for (j = 0; j < hist[i]; j++)
{
printf ("%c", i);
}
hist[i] = 0;
}
printf ("\n");
return 0;
}
| |
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn't change. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn't count as changes. You should obtain palindrome with the minimal number of changes. If there are several ways to do that you should get the lexicographically (alphabetically) smallest palindrome. So firstly you should minimize the number of changes and then minimize the palindrome lexicographically. | Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes. | C | f996224809df700265d940b12622016f | d7eb3cf7cc3781079337c315d05bb99c | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"greedy",
"strings"
] | 1448636400 | ["aabc", "aabcd"] | null | PASSED | 1,800 | standard input | 2 seconds | The only line contains string s (1ββ€β|s|ββ€β2Β·105) consisting of only lowercase Latin letters. | ["abba", "abcba"] | #include <stdio.h>
#define SIZE 200000
char s[SIZE];
int a['z' - 'a'];
char make_change (int a[])
{
int i = 0, j = 'z' - 'a';
char c = '*';
while (i < j) {
while (i < j && a[i] % 2 == 0)
i++;
while (i < j && a[j] % 2 == 0)
j--;
if (i < j) {
a[i]++, a[j]--;
i++, j--;
}
}
if (a[i] % 2 == 1) {
c = i + 'a';
a[i]--;
}
return c;
}
void output (int a[], char c)
{
int i;
for (i = 0; i <= 'z' - 'a'; i++)
if (a[i] != 0) {
int j;
for (j = 0; j < a[i]/2; j++)
putchar (i + 'a');
}
if (c != '*')
putchar (c);
for (i = 'z' - 'a'; i >= 0; i--)
if (a[i] != 0) {
int j;
for (j = 0; j < a[i]/2; j++)
putchar (i + 'a');
}
}
int main()
{
int i;
char c;
gets (s);
for (i = 0; s[i]; i++)
a[s[i] - 'a']++;
c = make_change (a);
output (a, c);
return 0;
}
| |
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn't change. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn't count as changes. You should obtain palindrome with the minimal number of changes. If there are several ways to do that you should get the lexicographically (alphabetically) smallest palindrome. So firstly you should minimize the number of changes and then minimize the palindrome lexicographically. | Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes. | C | f996224809df700265d940b12622016f | e8dc12429180342f0eb97ff2fc9e9094 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"greedy",
"strings"
] | 1448636400 | ["aabc", "aabcd"] | null | PASSED | 1,800 | standard input | 2 seconds | The only line contains string s (1ββ€β|s|ββ€β2Β·105) consisting of only lowercase Latin letters. | ["abba", "abcba"] | #include<stdio.h>
#include<string.h>
int main(){
int s,k,a=(int)'a',len=0;
int cant[26];
unsigned char cad;
memset(cant,0,sizeof(int)*26);
while(1){
scanf("%c",&cad);
if(cad<'a' || cad>'z'){
break;
}
cant[(int)cad-a]++;
}
k=25;
for(s=0;s<26;s++){
if(cant[s]%2){
for(;~k;k--){
if(cant[k]%2){
cant[k]--;
break;
}
}
cant[s]++;
}
}
for(s=0;s<26;s++){
for(k=0;k<(cant[s]/2);k++){
printf("%c",s+a);
}
}
for(s=0;s<26;s++){
if(cant[s]%2){
printf("%c",s+a);
break;
}
}
for(s=25;~s;s--){
for(k=0;k<(cant[s]/2);k++){
printf("%c",s+a);
}
}
}
| |
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn't change. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn't count as changes. You should obtain palindrome with the minimal number of changes. If there are several ways to do that you should get the lexicographically (alphabetically) smallest palindrome. So firstly you should minimize the number of changes and then minimize the palindrome lexicographically. | Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes. | C | f996224809df700265d940b12622016f | 6493560368b912172fc1d4d4d8b7bdf1 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"greedy",
"strings"
] | 1448636400 | ["aabc", "aabcd"] | null | PASSED | 1,800 | standard input | 2 seconds | The only line contains string s (1ββ€β|s|ββ€β2Β·105) consisting of only lowercase Latin letters. | ["abba", "abcba"] | #include <stdio.h>
#include <string.h>
#define MAXN 200001
int main() {
char s[MAXN];
long a[26] = {0}, ind[26], oddCount = 0, halfLen = 0;
scanf("%s", s);
long n = strlen(s);
for (long i = 0; i < n; ++i)
++a[s[i]-'a'];
for (long i = 0; i < 26; ++i)
if (a[i] % 2 == 1)
ind[oddCount++] = i;
for (long i = 0; i < oddCount/2; ++i) {
++a[ind[i]];
--a[ind[oddCount-1-i]];
}
for (long i = 0; i < 26; ++i) {
for (long j = 0; j < a[i]/2; ++j) {
s[halfLen+j] = s[n-1-halfLen-j] = 'a'+i;
}
halfLen += a[i]/2;
if (a[i]%2)
s[n/2] = 'a'+i;
}
printf("%s\n", s);
}
| |
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn't change. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn't count as changes. You should obtain palindrome with the minimal number of changes. If there are several ways to do that you should get the lexicographically (alphabetically) smallest palindrome. So firstly you should minimize the number of changes and then minimize the palindrome lexicographically. | Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes. | C | f996224809df700265d940b12622016f | 59f0277a04c3fa34f7b48ba88f32c720 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"greedy",
"strings"
] | 1448636400 | ["aabc", "aabcd"] | null | PASSED | 1,800 | standard input | 2 seconds | The only line contains string s (1ββ€β|s|ββ€β2Β·105) consisting of only lowercase Latin letters. | ["abba", "abcba"] | #include<stdio.h>
#include<string.h>
int main()
{
long int freq[27]={0},i,max,j,n,p=0;
char str[200010],c;
scanf("%s",str);
for(i=0;str[i]!='\0';i++)
freq[str[i]-'a']++;
n=strlen(str);
for(i=0,j=25;i<j;)
{
if(freq[i]%2!=0&&freq[j]%2!=0)
{
freq[i]++;
freq[j]--;
i++;
j--;
}
else if(freq[i]%2==0)
i++;
else if(freq[j]%2==0)
j--;
//printf("%ld\n",j);
}
//printf("%ld\n",freq[21]);
for(i=0;i<26;i++)
{
if(freq[i]%2!=0)
{
c=i+'a';
freq[i]--;
p=1;
}
for(j=0;j<freq[i]/2;j++)
printf("%c",i+'a');
}
if(p)
printf("%c",c);
for(i=25;i>=0;i--)
{
for(j=0;j<freq[i]/2;j++)
printf("%c",i+'a');
}
return 0;
}
| |
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn't change. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn't count as changes. You should obtain palindrome with the minimal number of changes. If there are several ways to do that you should get the lexicographically (alphabetically) smallest palindrome. So firstly you should minimize the number of changes and then minimize the palindrome lexicographically. | Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes. | C | f996224809df700265d940b12622016f | ed1040c8ab7750682cedd73f5dd1d54d | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"greedy",
"strings"
] | 1448636400 | ["aabc", "aabcd"] | null | PASSED | 1,800 | standard input | 2 seconds | The only line contains string s (1ββ€β|s|ββ€β2Β·105) consisting of only lowercase Latin letters. | ["abba", "abcba"] | #include <stdio.h>
#define MAX_LEN 200001
#define ALPHABETS 26
#define SMALL_A 97
char STRING[MAX_LEN];
int charCount[ALPHABETS] = {0,};
void printArray(int len)
{
int i;
for(i=0 ; i<len ; i++){
if(charCount[i] != 0)
printf("%c: %d\n",i+SMALL_A,charCount[i]);
}
}
int isPalWorthy(int len)
{
int i;
int isEven = 0; // 1 if even and 0 if odd
int isPal = 1;
int oddCount = 0;
if(len % 2 == 0)
isEven = 1;
else
isEven = 0;
if(isEven){
// Even
for(i=0 ; i<ALPHABETS ;i++){
if(charCount[i] % 2 != 0)
isPal = 0; // Not a palindrome
}
}
else{
// Odd
for(i=0 ; i<ALPHABETS ; i++){
if(charCount[i] % 2 != 0)
oddCount++;
}
if(oddCount != 1)
isPal = 0;
}
return isPal;
}
int findReplacement(int IDX)
{
// Find replacement from index IDX till start
int i = 0;
while((charCount[i] % 2 == 0) && ( i < IDX)){
i++;
}
if(i == IDX)
return -1;
else
return i;
}
void Replace(int len)
{
int i;
int isEven = 0;
int search = ALPHABETS - 1; // index to search
int firstOdd = 1; // Set to 0 if first odd is found
int replaceIDX = 0;
if(len % 2 == 0)
isEven = 1;
while((!isPalWorthy(len)) && search >= 0){
if(charCount[search] %2 == 0)
search--; // Search the previous posiiton
else{
// Check if lenth is odd
/*if(isEven == 0){
// Check if the first odd has been found
if(firstOdd){
// Not found ... set as found
firstOdd = 1;
search--; // Search previous position
}
else{
// Find replacement
replaceIDX = findReplacement(search);
// Replace
charCount[search]--;
charCount[replaceIDX]++;
search--;
}
}
else{
// Length is even
// Find replacement and swap
replaceIDX = findReplacement(search);
charCount[search]--;
charCount[replaceIDX]++;
search--;
}*/
// Replace
replaceIDX = findReplacement(search);
charCount[search]--;
charCount[replaceIDX]++;
search--;
}
}
//printf("After replacement\n");
//printArray(len);
}
int ceil(float num)
{
if(num - (int)num > 0)
return (int)num + 1;
else
return (int)num;
}
void Display(int len)
{
int i,j;
int STACK[MAX_LEN] = {0,};
int pivotIDX = 0;
// Form a stack and unwind it to print
for(i=0 ; i<ALPHABETS ; i++){
// Print first half
if(charCount[i] != 0){
// This character exists
if(charCount[i] % 2 != 0){
// Pivot
pivotIDX = i;
}
j = charCount[i];
while(charCount[i] > ceil((float)j/2)){
printf("%c",i + SMALL_A);
charCount[i]--;
}
}
}
if(len % 2 != 0){
// Odd
printf("%c",pivotIDX + SMALL_A);
charCount[pivotIDX]--;
}
for(i=ALPHABETS-1 ; i>=0 ; i--){
// Print the remaining
if(charCount[i] != 0){
while(charCount[i] != 0){
printf("%c",i+SMALL_A);
charCount[i]--;
}
}
}
printf("\n");
}
void GetAnswer(int len)
{
int i;
int numChars = 0;
// Fill the charCount table
for(i=0 ; i<len ; i++){
charCount[STRING[i] - SMALL_A]++;
}
if(len == 1){
printf("%s\n",STRING);
return;
}
// Find number of unique characters
for(i=0 ; i<ALPHABETS ; i++){
if(charCount[i] != 0)
numChars++;
}
if(numChars == 1){
// Only 1 unique character
printf("%s\n",STRING);
return;
}
//printArray(len);
/*if(isPalWorthy(len)){
printf("String can be converted to palindrome by permutation\n");
}
else{
printf("Replacement needed before permutation\n");
Replace(len);
}*/
if(!isPalWorthy(len))
Replace(len);
Display(len);
}
int main()
{
int len;
//FILE *fp;
//fp = fopen("C:/Users/Subh/Desktop/Work/Coding/C_code/test32.txt","r");
scanf("%s",STRING);
len = 0;
while(STRING[len] != '\0')
len++;
/* The code of your application goes here */
GetAnswer(len);
//fclose(fp);
return 0;
}
| |
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn't change. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn't count as changes. You should obtain palindrome with the minimal number of changes. If there are several ways to do that you should get the lexicographically (alphabetically) smallest palindrome. So firstly you should minimize the number of changes and then minimize the palindrome lexicographically. | Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes. | C | f996224809df700265d940b12622016f | 63fee45cb095393e1d24d7bbe0d3669d | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"greedy",
"strings"
] | 1448636400 | ["aabc", "aabcd"] | null | PASSED | 1,800 | standard input | 2 seconds | The only line contains string s (1ββ€β|s|ββ€β2Β·105) consisting of only lowercase Latin letters. | ["abba", "abcba"] | #include<stdio.h>
#include<string.h>
int main()
{
char s[1000000];
scanf("%s",s);
int a[26];
int l=strlen(s);
for(int i=0;i<26;i++)
a[i]=0;
for(int i=0;i<l;i++)
{
a[(int)s[i]-(int)'a']++;
}
for(int i=0;i<26;i++)
{
if(a[i]%2==1)
{
for(int j=25;j>i;j--)
{
if(a[j]%2==1)
{
a[j]--;
a[i]++;
break;
}
}
}
}
char c[1000000];
int k=-1;
int start=0;
for(int i=0;i<26;i++)
{
if(a[i]==0)
continue;
else
{
for(int j=1;j<=a[i]/2;j++)
{
c[start]=(char)(i+97);
start++;
}
if(a[i]%2==1)
{
k=i;
}
}
}
for(int i=0;i<start;i++)
{
printf("%c",c[i]);
}
if(k!=-1)
printf("%c",(k+97));
for(int i=start-1;i>=0;i--)
{
printf("%c",c[i]);
}
return 0;
}
| |
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn't change. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn't count as changes. You should obtain palindrome with the minimal number of changes. If there are several ways to do that you should get the lexicographically (alphabetically) smallest palindrome. So firstly you should minimize the number of changes and then minimize the palindrome lexicographically. | Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes. | C | f996224809df700265d940b12622016f | e758a5e6898e03a72064cbea0fdcfa14 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"constructive algorithms",
"greedy",
"strings"
] | 1448636400 | ["aabc", "aabcd"] | null | PASSED | 1,800 | standard input | 2 seconds | The only line contains string s (1ββ€β|s|ββ€β2Β·105) consisting of only lowercase Latin letters. | ["abba", "abcba"] | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
//input definitions
#define sd(x) scanf("%d",&x);
#define slld(x) scanf("%lld",&x);
#define ss(x) scanf("%s",x);
#define sf(x) scanf("%f",&x);
#define slf(x) scanf("%lf",&x);
//output definitions
#define pd(x) printf("%d",x);
#define plld(x) printf("%lld",x);
#define ps(x) printf("%s",x);
#define pf(x) printf("%f",x);
#define plf(x) printf("%lf",x);
#define pnl printf("\n");
#define psp printf(" ");
//define datatypes
typedef long long int ll;
//loops
#define upto(x) for(;i<=x;i++)
#define fl(i,a,b,c) for(i=a;i<=b;i+=c)
#define wl(x) while(x--)
int main(void) {
int i,j,k,l,n,m;
char arr[200005];
ss(arr)
int hash[300];
for(i=0;i<123;i++)
hash[i] = 0;
l = strlen(arr);
for(i=0;i<l;i++)
hash[arr[i]]++;
char np[l+2];
if(l&1){
int low = 'a';
int high = 'z';
while(low < high){
for(;low<high;low++){
if(hash[low] % 2)
break;
}
for(;high>low;high--){
if(hash[high] % 2)
break;
}
hash[low]++;
hash[high]--;
}
low = 0;
high = l-1;
//reconstructing new string
for(i='a';i<='z';i++){
while(hash[i] > 1){
np[low] = np[high] = i;
low++;
high--;
hash[i] -= 2;
}
}
for(i='a';i<='z';i++){
if(hash[i] > 0)
break;
}
np[low] = i;
np[l] = '\0';
printf("%s",np);
}
else{
int low = 'a';
int high = 'z';
while(low < high){
for(;low<high;low++){
if(hash[low] % 2)
break;
}
for(;high>low;high--){
if(hash[high] % 2)
break;
}
hash[low]++;
hash[high]--;
}
low = 0;
high = l-1;
//reconstructing new string
for(i='a';i<='z';i++){
while(hash[i] > 0){
np[low] = np[high] = i;
low++;
high--;
hash[i] -= 2;
}
}
np[l] = '\0';
printf("%s",np);
}
return 0;
}
| |
As you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires.Vova managed to build a large army, but forgot about the main person in the army - the commander. So he tries to hire a commander, and he wants to choose the person who will be respected by warriors.Each warrior is represented by his personality β an integer number pi. Each commander has two characteristics β his personality pj and leadership lj (both are integer numbers). Warrior i respects commander j only if ( is the bitwise excluding OR of x and y).Initially Vova's army is empty. There are three different types of events that can happen with the army: 1Β pi β one warrior with personality pi joins Vova's army; 2Β pi β one warrior with personality pi leaves Vova's army; 3Β piΒ li β Vova tries to hire a commander with personality pi and leadership li. For each event of the third type Vova wants to know how many warriors (counting only those who joined the army and haven't left yet) respect the commander he tries to hire. | For each event of the third type print one integer β the number of warriors who respect the commander Vova tries to hire in the event. | C | b12f2784bafb3db74598a22ac4603646 | 0f2fd2fe2d5c894d0f59989adb3b9263 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"data structures",
"bitmasks",
"trees"
] | 1497539100 | ["5\n1 3\n1 4\n3 6 3\n2 4\n3 6 3"] | NoteIn the example the army consists of two warriors with personalities 3 and 4 after first two events. Then Vova tries to hire a commander with personality 6 and leadership 3, and only one warrior respects him (, and 2β<β3, but , and 5ββ₯β3). Then warrior with personality 4 leaves, and when Vova tries to hire that commander again, there are no warriors who respect him. | PASSED | 2,000 | standard input | 2 seconds | The first line contains one integer q (1ββ€βqββ€β100000) β the number of events. Then q lines follow. Each line describes the event: 1Β pi (1ββ€βpiββ€β108) β one warrior with personality pi joins Vova's army; 2Β pi (1ββ€βpiββ€β108) β one warrior with personality pi leaves Vova's army (it is guaranteed that there is at least one such warrior in Vova's army by this moment); 3Β piΒ li (1ββ€βpi,βliββ€β108) β Vova tries to hire a commander with personality pi and leadership li. There is at least one event of this type. | ["1\n0"] | #include <stdio.h>
#include <malloc.h>
struct node {
struct node *r;
struct node *l;
int sum;
};
struct node *get() {
struct node *ret = malloc(sizeof(struct node));
ret->r = NULL;
ret->l = NULL;
ret->sum = 0;
return ret;
}
void add(struct node *root, int val, int inc) {
struct node *tmp = root;
for (int i = 27; i >= 0; i--) {
int hold = 0;
if ((1 << i) & val) {
hold = 1;
}
if (hold) {
if (tmp->r == NULL) {
tmp->r = get();
}
tmp = tmp->r;
tmp->sum += inc;
} else {
if (tmp->l == NULL) {
tmp->l = get();
}
tmp = tmp->l;
tmp->sum += inc;
}
}
}
int getq(struct node *root, int pj, int lj) {
int res = 0;
struct node *tmp = root;
for (int i = 27; i >= 0; i--) {
int holdp = 0, holdl = 0;
if ((1 << i) & pj) {
holdp = 1;
}
if ((1 << i) & lj) {
holdl = 1;
}
if (holdl && holdp) {
if (tmp->r != NULL) {
res += tmp->r->sum;
}
if (tmp->l != NULL) {
tmp = tmp->l;
} else {
break;
}
} else if (holdl) {
if (tmp->l != NULL) {
res += tmp->l->sum;
}
if (tmp->r != NULL) {
tmp = tmp->r;
} else {
break;
}
} else if (holdp) {
if (tmp->r != NULL) {
tmp = tmp->r;
} else {
break;
}
} else {
if (tmp->l != NULL) {
tmp = tmp->l;
} else {
break;
}
}
}
return res;
}
int main() {
int q;
scanf("%d", &q);
struct node *root = get();
while (q--) {
int t, pi;
scanf("%d %d", &t, &pi);
if (t == 1) {
add(root, pi, 1);
} else if (t == 2) {
add(root, pi, -1);
} else {
int li;
scanf("%d", &li);
printf("%d\n", getq(root, pi, li));
}
}
return 0;
}
| |
As you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires.Vova managed to build a large army, but forgot about the main person in the army - the commander. So he tries to hire a commander, and he wants to choose the person who will be respected by warriors.Each warrior is represented by his personality β an integer number pi. Each commander has two characteristics β his personality pj and leadership lj (both are integer numbers). Warrior i respects commander j only if ( is the bitwise excluding OR of x and y).Initially Vova's army is empty. There are three different types of events that can happen with the army: 1Β pi β one warrior with personality pi joins Vova's army; 2Β pi β one warrior with personality pi leaves Vova's army; 3Β piΒ li β Vova tries to hire a commander with personality pi and leadership li. For each event of the third type Vova wants to know how many warriors (counting only those who joined the army and haven't left yet) respect the commander he tries to hire. | For each event of the third type print one integer β the number of warriors who respect the commander Vova tries to hire in the event. | C | b12f2784bafb3db74598a22ac4603646 | 501867f5e4839c159e12182a5d5a6648 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"data structures",
"bitmasks",
"trees"
] | 1497539100 | ["5\n1 3\n1 4\n3 6 3\n2 4\n3 6 3"] | NoteIn the example the army consists of two warriors with personalities 3 and 4 after first two events. Then Vova tries to hire a commander with personality 6 and leadership 3, and only one warrior respects him (, and 2β<β3, but , and 5ββ₯β3). Then warrior with personality 4 leaves, and when Vova tries to hire that commander again, there are no warriors who respect him. | PASSED | 2,000 | standard input | 2 seconds | The first line contains one integer q (1ββ€βqββ€β100000) β the number of events. Then q lines follow. Each line describes the event: 1Β pi (1ββ€βpiββ€β108) β one warrior with personality pi joins Vova's army; 2Β pi (1ββ€βpiββ€β108) β one warrior with personality pi leaves Vova's army (it is guaranteed that there is at least one such warrior in Vova's army by this moment); 3Β piΒ li (1ββ€βpi,βliββ€β108) β Vova tries to hire a commander with personality pi and leadership li. There is at least one event of this type. | ["1\n0"] | #include <stdio.h>
#include <malloc.h>
struct trie{
struct trie *lc;
struct trie *rc;
int z;
};
struct trie *get(void){
struct trie *ret = malloc(sizeof(struct trie)) ;
ret->z=0;
ret->lc = NULL;
ret->rc = NULL;
return ret;
}
void add(struct trie *root ,int x){
struct trie * tmp = root;
int ind;
for(int i=27;i>=0;i--){
if((1ll<<i)&x)ind = 1;
else ind =0;
if(ind){
if(tmp->rc==NULL)tmp->rc = get();
tmp->rc->z += 1;
tmp = tmp->rc;
}
else{
if(tmp->lc==NULL)tmp->lc = get();
tmp->lc->z += 1;
tmp = tmp->lc;
}
}
}
void del(struct trie *root ,int x){
struct trie * tmp = root;
int ind;
for(int i=27;i>=0;i--){
if((1ll<<i)&x)ind = 1;
else ind =0;
if(ind){
tmp->rc->z -= 1;
tmp = tmp->rc;
}
else{
tmp->lc->z -= 1;
tmp = tmp->lc;
}
}
}
int ans(struct trie *root, int x, int y){
struct trie * tmp = root;
int ind,idx;
int ret =0;
for(int i=27;i>=0;i--){
if((1ll<<i)&y)ind = 1;
else ind =0;
if((1ll<<i)&x)idx = 1;
else idx =0;
if(ind){
if(idx){
if(tmp->rc!=NULL){
ret += tmp->rc->z;
}
if(tmp->lc!=NULL){
tmp = tmp->lc;
}else{
break;
}
}
else{
if(tmp->lc!=NULL){
ret += tmp->lc->z;
}
if(tmp->rc!=NULL){
tmp = tmp->rc;
}else{
break;
}
}
}
else{
if(idx){
if(tmp->rc!=NULL){
tmp = tmp->rc;
}else{
break;
}
}
else{
if(tmp->lc!=NULL){
tmp = tmp->lc;
}else{
break;
}
}
}
}
return ret;
}
int main(){
struct trie *root = get();
int q;
scanf("%d",&q);
int t,x,y;
int trt;
for(int i=0;i<q;i++){
scanf("%d%d",&t,&x);
if(t==1){
add(root,x);
}
else if(t==2){
del(root,x);
}
else{
scanf("%d",&y);
trt = ans(root,x,y);
printf("%d\n",trt);
}
}
return 0;
}
| |
As you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires.Vova managed to build a large army, but forgot about the main person in the army - the commander. So he tries to hire a commander, and he wants to choose the person who will be respected by warriors.Each warrior is represented by his personality β an integer number pi. Each commander has two characteristics β his personality pj and leadership lj (both are integer numbers). Warrior i respects commander j only if ( is the bitwise excluding OR of x and y).Initially Vova's army is empty. There are three different types of events that can happen with the army: 1Β pi β one warrior with personality pi joins Vova's army; 2Β pi β one warrior with personality pi leaves Vova's army; 3Β piΒ li β Vova tries to hire a commander with personality pi and leadership li. For each event of the third type Vova wants to know how many warriors (counting only those who joined the army and haven't left yet) respect the commander he tries to hire. | For each event of the third type print one integer β the number of warriors who respect the commander Vova tries to hire in the event. | C | b12f2784bafb3db74598a22ac4603646 | 47c2e765700b25cc9b901508e486474c | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"data structures",
"bitmasks",
"trees"
] | 1497539100 | ["5\n1 3\n1 4\n3 6 3\n2 4\n3 6 3"] | NoteIn the example the army consists of two warriors with personalities 3 and 4 after first two events. Then Vova tries to hire a commander with personality 6 and leadership 3, and only one warrior respects him (, and 2β<β3, but , and 5ββ₯β3). Then warrior with personality 4 leaves, and when Vova tries to hire that commander again, there are no warriors who respect him. | PASSED | 2,000 | standard input | 2 seconds | The first line contains one integer q (1ββ€βqββ€β100000) β the number of events. Then q lines follow. Each line describes the event: 1Β pi (1ββ€βpiββ€β108) β one warrior with personality pi joins Vova's army; 2Β pi (1ββ€βpiββ€β108) β one warrior with personality pi leaves Vova's army (it is guaranteed that there is at least one such warrior in Vova's army by this moment); 3Β piΒ li (1ββ€βpi,βliββ€β108) β Vova tries to hire a commander with personality pi and leadership li. There is at least one event of this type. | ["1\n0"] | #include <stdio.h>
#include <malloc.h>
struct trie{
struct trie *lc;
struct trie *rc;
int z;
};
struct trie *get(void){
struct trie *ret = malloc(sizeof(struct trie)) ;
ret->z=0;
ret->lc = NULL;
ret->rc = NULL;
return ret;
}
void add(struct trie *root ,int x){
struct trie * tmp = root;
int ind;
for(int i=32;i>=0;i--){
if((1ll<<i)&x)ind = 1;
else ind =0;
if(ind){
if(tmp->rc==NULL)tmp->rc = get();
tmp->rc->z += 1;
tmp = tmp->rc;
}
else{
if(tmp->lc==NULL)tmp->lc = get();
tmp->lc->z += 1;
tmp = tmp->lc;
}
}
}
void del(struct trie *root ,int x){
struct trie * tmp = root;
int ind;
for(int i=32;i>=0;i--){
if((1ll<<i)&x)ind = 1;
else ind =0;
if(ind){
tmp->rc->z -= 1;
tmp = tmp->rc;
}
else{
tmp->lc->z -= 1;
tmp = tmp->lc;
}
}
}
int ans(struct trie *root, int x, int y){
struct trie * tmp = root;
int ind,idx;
int ret =0;
for(int i=32;i>=0;i--){
if((1ll<<i)&y)ind = 1;
else ind =0;
if((1ll<<i)&x)idx = 1;
else idx =0;
if(ind){
if(idx){
if(tmp->rc!=NULL){
ret += tmp->rc->z;
}
if(tmp->lc!=NULL){
tmp = tmp->lc;
}else{
break;
}
}
else{
if(tmp->lc!=NULL){
ret += tmp->lc->z;
}
if(tmp->rc!=NULL){
tmp = tmp->rc;
}else{
break;
}
}
}
else{
if(idx){
if(tmp->rc!=NULL){
tmp = tmp->rc;
}else{
break;
}
}
else{
if(tmp->lc!=NULL){
tmp = tmp->lc;
}else{
break;
}
}
}
}
return ret;
}
int main(){
struct trie *root = get();
int q;
scanf("%d",&q);
int t,x,y;
int trt;
for(int i=0;i<q;i++){
scanf("%d%d",&t,&x);
if(t==1){
add(root,x);
}
else if(t==2){
del(root,x);
}
else{
scanf("%d",&y);
trt = ans(root,x,y);
printf("%d\n",trt);
}
}
return 0;
}
| |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | c10f1cb5cf957b47669a56024b9cd593 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include <stdio.h>
int main()
{
int n, m;
scanf("%d%d", &n, &m);
char s[m+2];
char bStart = 0;
int x1, y1, x2, y2;
for(int i = 1; i <= n; i++)
{
scanf("%s", s);
for(int j = 0; j < m; j++)
{
if(s[j] == 'W') continue;
if(bStart == 0)
{
bStart = 1;
x1 = i, y1 = j+1;
}
x2 = i, y2 = j+1;
}
}
printf("%d %d\n", (x1+x2)/2, (y1+y2)/2);
} | |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | 9f4b38c34ccc1c427aa42b40a0e2535c | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include<stdio.h>
#include<string.h>
int main()
{
char a;
long long i,t,c=0,d=0,n,m,j,x,q,p;
scanf("%lld %lld\n",&n,&m);
p=0;q=0;c=0;d=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
scanf("%c",&a);
if(a=='B')
{p+=i;c++;
q+=j;d++;}
}
scanf("\n");
}
p=p/c;
q=q/d;
printf("%lld %lld\n",p,q);
return 0;
} | |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | 0936975d80000bf9aa13a60d403ec564 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include <stdio.h>
#include <stdlib.h>
void findSquare(int** matrix, int n, int m, int* a, int* b, int* len) {
int i, j, k;
*len = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (!matrix[i][j]) {
*a = i;
*b = j;
for (k = i; k < n; k++) {
if (matrix[k][j]) {
return;
}
(*len)++;
}
return;
}
}
}
}
int main() {
int n, m, i, j, a, b, len;
int **matrix;
char s;
scanf("%d%d", &n, &m);
matrix = (int**)malloc(sizeof(int*) * n);
for (i = 0; i < n; i++) {
matrix[i] = (int*)malloc(sizeof(int) * m);
}
for (i = 0; i < n; i++) {
getchar();
for (j = 0; j < m; j++) {
scanf("%c", &s);
matrix[i][j] = s == 'W' ? 1 : 0;
}
}
findSquare(matrix, n, m, &a, &b, &len);
printf("%d %d\n", len / 2 + a + 1, len / 2 + b + 1);
return 0;
}
| |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | 9be8dd415d587483c792e241f5aaceb3 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include<stdio.h>
int main()
{
int n,m,i,p,q,num=0;
scanf("%d %d",&n,&m);
char s[n+1][m+1];
for(i=0;i<n;i=i+1)
{
scanf("%s",&s[i]);
}
for(i=0;i<n;i=i+1)
{
int j=0;
num=0;
while(s[i][j]!=0)
{
if(s[i][j]=='B')
{
num=num+1;
p=j+1;
q=i+1;
}
j=j+1;
}
if(num>=1)
{
break;
}
}
printf("%d %d",(q+(num/2)),(p-(num/2)));
}
| |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | 140dae1a573edf0ab1680dbaf703d021 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include<stdio.h>
#include<string.h>
int main(){
int n,m,i, r_start, r_end, c_start, c_end, mid_x, mid_y, j, black = 0;
char sq[120][120];
scanf("%d %d",&n,&m);
for(i=0;i<n;i++)
scanf("%s", sq[i]);
for(i=0;i<n;i++){
for(j=0;j<m;j++){
if(sq[i][j]=='B' && black==0){
r_start = i;
c_start = j;
black = 1;
}
else if(black == 1 && sq[i][j]=='W'){
break;
}
}
c_end = j-1;
if(black==1)
break;
}
for(i=r_start;i<n;i++){
if(sq[i][c_start] == 'W'){
break;
}
}
r_end = i-1;
mid_x = r_start + (r_end-r_start)/2 + 1;
mid_y = c_start + (c_end-c_start)/2 + 1;
printf("%d %d\n",mid_x, mid_y);
return 0;
} | |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | afb0f75797ab413b0ac08341d1f6f9fa | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include<stdio.h>
#include<string.h>
int main()
{
char a;
long long i,t,c=0,d=0,n,m,j,x,q,p;
scanf("%lld %lld\n",&n,&m);
p=0;q=0;c=0;d=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
scanf("%c",&a);
if(a=='B')
{p+=i;c++;
q+=j;d++;}
}
scanf("\n");
}
p=p/c;
q=q/d;
printf("%lld %lld\n",p,q);
return 0;
} | |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | ae7ff6c408bb2596dfe0512f01fb5797 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include<stdio.h>
int main()
{
int R,C,r,c,len=0,i,j;
char a[120][120],g;
scanf("%d %d",&R,&C);
scanf("%c",&g);
for(i=1;i<=R;i++)
{
for(j=1;j<=C;j++)
{
scanf("%c",&a[i][j]);
}
scanf("%c",&g);
}
i=1;
for(i=1;i<=R;i++)
for(j=1;j<=C;j++)
{
if(a[i][j]=='B')
{ len++;
r=i;c=j;
j--;
i++;
}
else if(len>0)
{
break;
}
}
r-=len/2;
c+=len/2;
printf("%d %d\n",r,c);
}
| |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | 581beb04bea840cdfb988693f68aa54a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include<stdio.h>
int main()
{
int n,m,ss,s=0,e=0,ll,l=0,i,j,c=0;
char a[116][116];
scanf("%d%d",&n,&m);
for(i=0; i<n; i++)
{
scanf("%s",a[i]);
if(l==0)
for(j=0; j<m; j++)
if(a[i][j]=='B')
l++;
if(s==0)
for(j=0; j<m; j++)
if(a[i][j]=='B')
{
s=i+1;
ss=j+1;
break;
}
if(e==0&&s>0)
{
c=0;
for(j=0; j<m; j++)
if(a[i][j]=='B')
{
c=1;
break;
}
if(c==0)
e=i;
}
}
if(e==0)
e=n;
ll=(e-s)/2;
l=l/2;
printf("%d %d\n",s+ll,ss+l);
return 0;
}
| |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | b3831da4e266d51ce04e86e8d84f90c8 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include <stdio.h>
#include <math.h>
int main()
{
int n,m,count=0;
scanf("%d%d",&n,&m);
char arr[n][m];
for(int i=0;i<n;i++)
{
char conv[m+1];
scanf("%s",&conv);
for(int j=0;j<m;j++)
{
if(conv[j]=='B')
{
arr[i][j]=1;
count+=1;
}
else
arr[i][j]=0;
}
}
int loop=0,row=0,column=0;
count=sqrt(count);
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(arr[i][j]==1)
{
loop=1;
row = i+1+count/2;
column=j+1+count/2;
break;
}
}
if(loop==1)
break;
}
printf("%d %d",row,column);
return 0;
}
| |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | a08b4d2ab8aa7f0f17cca4db718faecd | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include<stdio.h>
#include<string.h>
int main()
{
int i,j,k=0,b=0,c,s=0,r,m,n;
char a;
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++)
{
scanf("%c",&a);
for(j=1;j<=m;j++)
{
scanf("%c",&a);
if(a=='B')
{
b+=i;
s+=j;
k++;
}
}
}
c=s/k;
r=b/k;
printf("%d %d\n",r,c);
return 0;
}
| |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | c34a0cceb7f23af6e37b92e47881b7b0 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include<stdio.h>
int main()
{
int n,m,i,j;
scanf("%d%d",&n,&m);
char a[n+1][m+1];
int w=0;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf(" %c",&a[i][j]);
if(a[i][j]=='B')
{
w++;
}
else
{
continue;
}
}
}
int z=0,c;
c=(w/2)+1;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j]=='B')
{
z++;
if(z==c)
{
printf("%d %d",i+1,j+1);
break;
}
else
{
continue;
}
}
else
{
continue;
}
}
}
}
| |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | 4b0d68d4d6d248ac19201e4ced1175d3 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include<stdio.h>
int main ()
{
long long int count=0,k,l,s,t, i,j,row,col,x,y;
scanf("%lld %lld", &row, &col);
char a[row][col];
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf(" %c", &a[i][j]);
}
}
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(a[i][j]=='B')
{
count++;
k=i+1;
l=j+1;
if(count==1)
{
s=i+1;
t=j+1;
}
}
}
}
if(count!=1)
{
x=(k+s)/2;
y=(l+t)/2;
printf("%lld %lld\n", x, y);
}
else
{
printf("%lld %lld\n", s, t);
}
return
0;
}
| |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | 30cfeed0747bf1d95776621f63eb64f6 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include<stdio.h>
#include<stdlib.h>
int main() {
int row, column;
scanf("%d %d", &row, &column);
char* currentRow = malloc(column * sizeof(char));
int startWidth = 0, endWidth = 0;
int startHeight = 0, endHeight = 0;
for (int i = 1; i <= row; i++) {
scanf("%s", currentRow);
if (!startWidth) {
int start = 0, end = 0;
for (int j = 1; j <= column; j++){
if (currentRow[j-1] == 'B') {
if (!startWidth) {
startWidth = j;
endWidth = j;
} else {
endWidth = j;
}
}
}
startHeight = i;
endHeight = i;
} else if (currentRow[startWidth - 1] == 'B') {
endHeight = i;
}
}
printf("%d %d\n", (startHeight + endHeight) / 2, (startWidth + endWidth) / 2);
return 0;
} | |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | 2b103a6e8d8b51de66149d52fb48d065 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include<stdio.h>
int main()
{
int n, m,p=0,q=0,cnt=0,f=0,g=0;
scanf("%d%d",&n,&m);
char s[116][116]={'\0'};
for(int i=0;i<n;i++)
scanf("%s",s[i]);
for(int i=0;i<n&&g==0;i++)
{
for(int j=0;j<m;j++)
{
if(s[i][j]=='B')
{
cnt++;
if(f==0)
{
p=i+1;
q=j+1;
f=1;
}
if(j==m-1||(s[i][j]=='B'&&s[i][j+1]=='W'))
{
g=1;
break;
}
}
}
}//printf("%d %d",p,q);
printf("%d %d",p+(cnt/2),q+(cnt/2));
return 0;
} | |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | 3db6edcf985df7b033e9459cac7919ce | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include <stdio.h>
int main() {
int n, m;
scanf("%d%d ", &n, &m);
char s[120][120];
int x0 = -1, y0 = -1, l = -1;
char t;
// printf("%d %d\n", n, m);
for (int y = 0; y < n; y++) {
for (int x = 0; x < m; x++) {
scanf("%c", &s[y][x]);
if (s[y][x] == 'B') {
// printf("y %d, x %d\n", y, x);
if (x0 == -1) {
x0 = x;
y0 = y;
}
} else if (x > 0 && s[y][x-1] == 'B') {
l = x - x0;
printf("%d %d\n", y0 + l / 2 + 1, x0 + l / 2 + 1);
return 0;
}
}
if (y0 != -1) {
l = m - x0;
printf("%d %d\n", y0 + l / 2 + 1, x0 + l / 2 + 1);
return 0;
}
scanf("%c", &t);
}
return 0;
} | |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | 0224b8643570c1088a88ae99cc5b1a7b | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include<stdio.h>
#include<string.h>
//using namespace std;
#define ll long long int
//#define endl "\n"
#define PI acos(-1)
#define sci(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define scd(n) scanf("%lf",&n)
#define FOR(i,n) for(int i=1;i<=n;i++)
#define LOOP(i,n) for(int i=0;i<n;i++)
#define loop(a,b) for(ll i=a;i<=b;i++)
//#define pb push_back
//#define mp make_pair
//#define vi vector<int>
/*void fastio()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}*/
int main()
{
//fastio();
int n,m;
sci(n);
sci(m);
char c, cnst='B';
int sr=0,er=0,sc=0,ec=0,pre=0,i,j;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
scanf(" %c",&c);
if(c==cnst && pre==0)
{
sr=i;
sc=j;
pre=1;
}
if(c==cnst && pre==1)
{
er=i;
ec=j;
}
}
}
printf("%d %d",(sr+((er-sr)/2)),(sc+((ec-sc)/2)));
return 0;
}
| |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | d1c537680a49b5d0932a0901b98c1303 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include <stdio.h>
int main()
{
int num,m,sum1=0,sum2=0,c=0,i,j;
char mat[150][150];
scanf("%d%d",&num,&m);
for(i=0;i<num;i++)
{
scanf("%s",&mat[i]);
}
for(i=0;i<num;i++)
{
for(j=0;j<m;j++)
{
if(mat[i][j]=='B')
{
c++;
sum1=sum1+(i+1);
sum2=sum2+j+1;
}
}
}
printf("%d %d",sum1/c,sum2/c);
}
| |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | 4122d1c4bb354bb17af618dc656d5d0c | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include<stdio.h>
#include<string.h>
int main()
{
int n,m,i,j,p,q,x,y,z=0;
scanf("%d %d",&n,&m);
char S[n][m];
for(i=0;i<n;i++)
{
scanf("%s",S[i]);
for(j=0;j<m;j++)
{
if(S[i][j]=='B'&&z==0)
{
p=i;
q=j;
z=1;
}
if(S[i][j]=='B'&&z==1)
{
x=i;
y=j;
}
}
}
printf("%d %d\n",(p+x+2)/2,(q+y+2)/2);
return 0;
}
| |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | 9257326d97f629302337c8e3a3538f5b | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include<stdio.h>
int main()
{
int n,m,i,j,k,r=0,c=0,flag=1;
char a[120][120];
scanf("%d %d ",&n,&m);
for(i=0;i<n;i++)
gets(a[i]);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j]=='B')
{
k=i;
r=r+i+1;
c=c+j+1;
while(a[k][j]=='B')
k++;
r=r+k-1;
while(a[i][j]=='B')
j++;
c=c+j-1;
flag=0;
}
if(flag==0)
break;
}
if(flag==0)
break;
}
printf("%d %d",r/2+1,c/2+1);
return 0;
}
| |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | 89f0bb7b49a49c6b2654cf05a96991e5 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int i,j,k,d,min=1000,max=0,a,b,p,q,c;
scanf("%d %d",&i,&j);
char ara[i][j],ch;
for(p=1;p<=i;p++){
for(q=1;q<=j;q++){
scanf(" %c",&ch);
if(ch=='B'){
if(p+q<min){
min=p+q;
a=p;
b=q;
}
if(p+q>max){
max=p+q;
c=p;
d=q;
}
}
}
}
printf("%d %d",(a+c)/2,(b+d)/2);
}
| |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | f96cd9ae2f02161cbbe173b2797c1996 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include<stdio.h>
int main(void)
{
int i,in=0,row1,row2=0,j,n,m,col1,col2=0;
scanf("%d %d",&n,&m);
char string[m+1];
for(i=0;i<n;i++)
{
scanf("%s",string);
for(j=0;string[j]!='\0';j++)
{
if(string[j]=='B'&&in==0)
{
col1=i+1;
row1=j+1;
in++;
}
else if(string[j]=='B')
{
col2=i+1;
row2=j+1;
}
}
}
if(col2==0)
printf("%d %d\n",col1,row1);
else
printf("%d %d\n",(col1+col2)/2,(row1+row2)/2);
return 0;
}
| |
Consider a table of size $$$n \times m$$$, initially fully white. Rows are numbered $$$1$$$ through $$$n$$$ from top to bottom, columns $$$1$$$ through $$$m$$$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this square. | Output two integers $$$r$$$ and $$$c$$$ ($$$1 \le r \le n$$$, $$$1 \le c \le m$$$) separated by a space β the row and column numbers of the center of the black square. | C | 524273686586cdeb7827ffc1ad59d85a | efe314b59f51b12c0e3251ba3c66628a | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1535387700 | ["5 6\nWWBBBW\nWWBBBW\nWWBBBW\nWWWWWW\nWWWWWW", "3 3\nWWW\nBWW\nWWW"] | null | PASSED | 800 | standard input | 1 second | The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 115$$$) β the number of rows and the number of columns in the table. The $$$i$$$-th of the next $$$n$$$ lines contains a string of $$$m$$$ characters $$$s_{i1} s_{i2} \ldots s_{im}$$$ ($$$s_{ij}$$$ is 'W' for white cells and 'B' for black cells), describing the $$$i$$$-th row of the table. | ["2 4", "2 1"] | #include <stdio.h>
int width,height;
char matrix[116][116];
int blacklen,rightcornerw,rightcornerh;
int main ()
{
//freopen ("cf.in","r",stdin),freopen("cf.out","w",stdout);
scanf ("%d %d ",&height,&width);
for (int i=0;i<height;i++)
{
for (int j=0;j<=width;j++)
{
scanf ("%c",&matrix[i][j]);
}
}
for (int i=0;i<height;i++)
{
for (int j=0;j<width;j++)
{
if (matrix[i][j]=='B')
{
blacklen++;
rightcornerw = j;
rightcornerh = i;
}
}
if (blacklen)
break;
}
if (blacklen!=1)
printf ("%d %d",rightcornerh+blacklen/2+1,rightcornerw-blacklen/2+1);
else
{
for (int i=0;i<height;i++)
{
for (int j=0;j<width;j++)
{
if (matrix[i][j]=='B')
{
printf("%d %d",i+1,j+1);
return 0;
}
}
}
}
} | |
The only difference between easy and hard versions is constraints.Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you.There are $$$n$$$ voters, and two ways to convince each of them to vote for you. The first way to convince the $$$i$$$-th voter is to pay him $$$p_i$$$ coins. The second way is to make $$$m_i$$$ other voters vote for you, and the $$$i$$$-th voter will vote for free.Moreover, the process of such voting takes place in several steps. For example, if there are five voters with $$$m_1 = 1$$$, $$$m_2 = 2$$$, $$$m_3 = 2$$$, $$$m_4 = 4$$$, $$$m_5 = 5$$$, then you can buy the vote of the fifth voter, and eventually everyone will vote for you. Set of people voting for you will change as follows: $$${5} \rightarrow {1, 5} \rightarrow {1, 2, 3, 5} \rightarrow {1, 2, 3, 4, 5}$$$.Calculate the minimum number of coins you have to spend so that everyone votes for you. | For each test case print one integer β the minimum number of coins you have to spend so that everyone votes for you. | C | cc64dfbaadc7f9deae23c71df52d7326 | 743db54697e268beae16b0b5bf5917bf | GNU C11 | standard output | 512 megabytes | train_000.jsonl | [
"dp",
"greedy",
"data structures"
] | 1571929500 | ["3\n3\n1 5\n2 10\n2 8\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5"] | NoteIn the first test case you have to buy vote of the third voter. Then the set of people voting for you will change as follows: $$${3} \rightarrow {1, 3} \rightarrow {1, 2, 3}$$$.In the second example you don't need to buy votes. The set of people voting for you will change as follows: $$${1} \rightarrow {1, 3, 5} \rightarrow {1, 2, 3, 5} \rightarrow {1, 2, 3, 5, 6, 7} \rightarrow {1, 2, 3, 4, 5, 6, 7}$$$.In the third test case you have to buy votes of the second and the fifth voters. Then the set of people voting for you will change as follows: $$${2, 5} \rightarrow {1, 2, 3, 4, 5} \rightarrow {1, 2, 3, 4, 5, 6}$$$. | PASSED | 2,300 | standard input | 2 seconds | The first line contains one integer $$$t$$$ ($$$1 \le t \le 5000$$$) β the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 5000$$$) β the number of voters. The next $$$n$$$ lines contains the description of voters. $$$i$$$-th line contains two integers $$$m_i$$$ and $$$p_i$$$ ($$$1 \le p_i \le 10^9, 0 \le m_i < n$$$). It is guaranteed that the sum of all $$$n$$$ over all test cases does not exceed $$$5000$$$. | ["8\n0\n7"] | #include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#define N 200000
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 mm[N], pp[N];
int pq[1 + N], iq[N], cnt;
int less(int u, int v) {
return pp[u] > pp[v];
}
int i2(int i) {
return (i *= 2) > cnt ? 0 : i < cnt && less(pq[i + 1], pq[i]) ? i + 1 : i;
}
void pq_up(int u) {
int i, j, v;
for (i = iq[u]; (j = i / 2) && less(u, v = pq[j]); i = j)
pq[iq[v] = i] = v;
pq[iq[u] = i] = u;
}
void pq_dn(int u) {
int i, j, v;
for (i = iq[u]; (j = i2(i)) && less(v = pq[j], u); i = j)
pq[iq[v] = i] = v;
pq[iq[u] = i] = u;
}
void pq_add(int u) {
iq[u] = ++cnt, pq_up(u);
}
int pq_remove_first() {
int u = pq[1], v = pq[cnt--];
if (v != u)
iq[v] = 1, pq_dn(v);
return u;
}
int compare(const void *a, const void *b) {
int i = *(int *) a;
int j = *(int *) b;
return mm[i] - mm[j];
}
void sort(int *ii, int n) {
int i;
for (i = 0; i < n; i++) {
int j = rand_(i + 1), tmp;
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
}
qsort(ii, n, sizeof *ii, compare);
}
int main() {
int t;
srand_();
scanf("%d", &t);
while (t--) {
static int ii[N];
int n, m, i;
long long ans;
scanf("%d", &n);
ans = 0;
for (i = 0; i < n; i++) {
scanf("%d%d", &mm[i], &pp[i]);
ans += pp[i];
ii[i] = i;
}
sort(ii, n);
cnt = 0;
for (m = 0, i = 0; m < n; m++) {
while (i < n && mm[ii[i]] == m)
pq_add(ii[i++]);
if (cnt)
ans -= pp[pq_remove_first()];
}
printf("%lld\n", ans);
}
return 0;
}
| |
The only difference between easy and hard versions is constraints.Now elections are held in Berland and you want to win them. More precisely, you want everyone to vote for you.There are $$$n$$$ voters, and two ways to convince each of them to vote for you. The first way to convince the $$$i$$$-th voter is to pay him $$$p_i$$$ coins. The second way is to make $$$m_i$$$ other voters vote for you, and the $$$i$$$-th voter will vote for free.Moreover, the process of such voting takes place in several steps. For example, if there are five voters with $$$m_1 = 1$$$, $$$m_2 = 2$$$, $$$m_3 = 2$$$, $$$m_4 = 4$$$, $$$m_5 = 5$$$, then you can buy the vote of the fifth voter, and eventually everyone will vote for you. Set of people voting for you will change as follows: $$${5} \rightarrow {1, 5} \rightarrow {1, 2, 3, 5} \rightarrow {1, 2, 3, 4, 5}$$$.Calculate the minimum number of coins you have to spend so that everyone votes for you. | For each test case print one integer β the minimum number of coins you have to spend so that everyone votes for you. | C | cc64dfbaadc7f9deae23c71df52d7326 | bc7996c149154515144e21015d5650b6 | GNU C11 | standard output | 512 megabytes | train_000.jsonl | [
"dp",
"greedy",
"data structures"
] | 1571929500 | ["3\n3\n1 5\n2 10\n2 8\n7\n0 1\n3 1\n1 1\n6 1\n1 1\n4 1\n4 1\n6\n2 6\n2 3\n2 8\n2 7\n4 4\n5 5"] | NoteIn the first test case you have to buy vote of the third voter. Then the set of people voting for you will change as follows: $$${3} \rightarrow {1, 3} \rightarrow {1, 2, 3}$$$.In the second example you don't need to buy votes. The set of people voting for you will change as follows: $$${1} \rightarrow {1, 3, 5} \rightarrow {1, 2, 3, 5} \rightarrow {1, 2, 3, 5, 6, 7} \rightarrow {1, 2, 3, 4, 5, 6, 7}$$$.In the third test case you have to buy votes of the second and the fifth voters. Then the set of people voting for you will change as follows: $$${2, 5} \rightarrow {1, 2, 3, 4, 5} \rightarrow {1, 2, 3, 4, 5, 6}$$$. | PASSED | 2,300 | standard input | 2 seconds | The first line contains one integer $$$t$$$ ($$$1 \le t \le 5000$$$) β the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 5000$$$) β the number of voters. The next $$$n$$$ lines contains the description of voters. $$$i$$$-th line contains two integers $$$m_i$$$ and $$$p_i$$$ ($$$1 \le p_i \le 10^9, 0 \le m_i < n$$$). It is guaranteed that the sum of all $$$n$$$ over all test cases does not exceed $$$5000$$$. | ["8\n0\n7"] | #include<stdio.h>
#include<stdlib.h>
#define DUBEG 0
typedef struct __st_pair{
int m, p;
}pair;
pair arr[200005];
long long ans[2][5003];
int n;
int cmp_fn(const void *_a, const void *_b){
pair *a, *b;
a = (pair *)_a;
b = (pair *)_b;
return (a->m) - (b->m);
}
int main(){
int tcases;
scanf("%d", &tcases);
while(tcases--){
int i, cur;
scanf("%d", &n);
for(i = 0;i < n;i++)scanf("%d %d", &(arr[i].m), &(arr[i].p));
qsort(arr, n, sizeof(pair), cmp_fn);
cur = 0;
for(i = 0;i <= n;i++)ans[cur][i] = 0;
for(i = 0;i < n;i++){
int old, j;
old = cur;
cur ^= 1;
for(j = 0;j < n;j++)ans[cur][j] = ans[old][j + 1] + arr[i].p;
ans[cur][n] = 0;
int req = arr[i].m - i;
if(req < 0) req = 0;
for(j = req;j <= n;j++) if(ans[cur][j] > ans[old][j]) ans[cur][j] = ans[old][j];
if(DUBEG){
printf("---\n");
for(j = 0;j <= n;j++)printf("%d:\t%lld\t%lld\n", j, ans[old][j], ans[cur][j]);
printf("---\n");
}
}
printf("%lld\n", ans[cur][0]);
}
return 0;
}
| |
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high. A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group.Mike is a curious to know for each x such that 1ββ€βxββ€βn the maximum strength among all groups of size x. | Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x. | C | 5cf25cd4a02ce8020258115639c0ee64 | aacf273efff17402fbd2dbc87584d84d | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"dsu",
"binary search",
"data structures"
] | 1432658100 | ["10\n1 2 3 4 5 4 3 2 1 6"] | null | PASSED | 1,900 | standard input | 1 second | The first line of input contains integer n (1ββ€βnββ€β2βΓβ105), the number of bears. The second line contains n integers separated by space, a1,βa2,β...,βan (1ββ€βaiββ€β109), heights of bears. | ["6 4 4 3 3 2 2 1 1 1"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*left[i] stores index of element just less than ht[i] to the left,
* right[i] stores the index of the element just less than ht[i] to the right*/
int left[200001],right[200001];
int stack[200001],ans[200001];
int top;
int main()
{
int n;
scanf("%d",&n);
int ht[200001];
int i;
/*input*/
for(i=1;i<=n;i++)
scanf("%d",&ht[i]);
/*populate left*/
top=0;
left[1]=0;
stack[++top]=1;
for(i=2;i<=n;i++)
{
while(top>0 && ht[stack[top]]>=ht[i])
top--;
if(top==0)
left[i]=0;
else
left[i]=stack[top];
stack[++top]=i;
}
/*populate right*/
top=0;
right[n]=n+1;
stack[++top]=n;
for(i=n-1;i>=0;i--)
{
while(top>0 && ht[stack[top]]>=ht[i])
top--;
if(top==0)
right[i]=n+1;
else
right[i]=stack[top];
stack[++top]=i;
}
/*populate ans*/
memset(ans,0,sizeof(ans)); //initialising ans array
for(i=1;i<=n;i++)
{
if(ans[(right[i]-left[i]-1)]<ht[i]) //right[i]-left[i]-1 represents the maximum size of group for which ht[i] can be the answer since ht[i] is minimum only in this range.
ans[(right[i]-left[i]-1)]=ht[i];
} //till now ans[i] holds the possible answer for ans[1]..ans[i]
for(i=n-1;i>=0;i--)
{
if(ans[i]<ans[i+1]) //this loop fills the array with maximum..considering all the possibilities.
ans[i]=ans[i+1]; //This also maintains the condition that should hold true theoretically : ans1>=ans2>=ans3>=ans4.....>=ansn
}
/*printing the output*/
printf("%d",ans[1]);
for(i=2;i<=n;i++)
{
printf(" %d",ans[i]);
}
putchar('\n');
return 0;
}
| |
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high. A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group.Mike is a curious to know for each x such that 1ββ€βxββ€βn the maximum strength among all groups of size x. | Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x. | C | 5cf25cd4a02ce8020258115639c0ee64 | cbf06c7e8eefffe4218d2961e93fae70 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"dsu",
"binary search",
"data structures"
] | 1432658100 | ["10\n1 2 3 4 5 4 3 2 1 6"] | null | PASSED | 1,900 | standard input | 1 second | The first line of input contains integer n (1ββ€βnββ€β2βΓβ105), the number of bears. The second line contains n integers separated by space, a1,βa2,β...,βan (1ββ€βaiββ€β109), heights of bears. | ["6 4 4 3 3 2 2 1 1 1"] | #include <stdio.h>
#define MAXN 200000
int n, v[MAXN], heap[MAXN], f[MAXN], ans[MAXN+1], t[MAXN], max[MAXN];
int tata(int p){
return (p-1)/2;
}
int fiust(int p){
return 2*p+1;
}
int fiudr(int p){
return 2*p+2;
}
void swap(int a, int b){
int aux=heap[a];
heap[a]=heap[b];
heap[b]=aux;
}
void coborare(int p){
int q, f=1;
while((f==1)&&(fiust(p)<n)){
q=fiust(p);
if((fiudr(p)<n)&&(v[heap[q]]<v[heap[fiudr(p)]])){
q=fiudr(p);
}
if(v[heap[p]]<v[heap[q]]){
swap(p, q);
p=q;
}else{
f=0;
}
}
}
void heapify(){
int i;
for(i=tata(n-1); i>=0; i--){
coborare(i);
}
}
void heapSort(){
int cn=n;
while(n>1){
n--;
swap(0, n);
coborare(0);
}
n=cn;
}
int find(int x){
if(f[x]==x){
return x;
}
f[x]=find(f[x]);
return f[x];
}
void unite(int a, int b){
int ra=find(a), rb=find(b);
f[ra]=rb;
max[rb]+=max[ra];
}
int main(){
int i, sefu, maxc;
scanf("%d", &n);
for(i=0; i<n; i++){
scanf("%d", &v[i]);
heap[i]=i;
max[i]=1;
f[i]=i;
}
heapify();
heapSort();
sefu=0;
for(i=n-1; i>=0; i--){
if((heap[i]>0)&&(t[heap[i]-1]==1)){
unite(heap[i]-1, heap[i]);
}
if((heap[i]<n-1)&&(t[heap[i]+1]==1)){
unite(heap[i]+1, heap[i]);
}
t[heap[i]]=1;
if(sefu<max[find(heap[i])]){
sefu=max[find(heap[i])];
}
if(ans[sefu]<v[heap[i]]){
ans[sefu]=v[heap[i]];
}
}
maxc=0;
for(i=n-1; i>=0; i--){
if(ans[i]<ans[i+1]){
ans[i]=ans[i+1];
}
}
for(i=1; i<=n; i++){
printf("%d ", ans[i]);
}
return 0;
}
| |
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high. A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group.Mike is a curious to know for each x such that 1ββ€βxββ€βn the maximum strength among all groups of size x. | Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x. | C | 5cf25cd4a02ce8020258115639c0ee64 | d9c33ef23f52f2aa5cb3724530e8667f | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"dsu",
"binary search",
"data structures"
] | 1432658100 | ["10\n1 2 3 4 5 4 3 2 1 6"] | null | PASSED | 1,900 | standard input | 1 second | The first line of input contains integer n (1ββ€βnββ€β2βΓβ105), the number of bears. The second line contains n integers separated by space, a1,βa2,β...,βan (1ββ€βaiββ€β109), heights of bears. | ["6 4 4 3 3 2 2 1 1 1"] | #include<stdio.h>
int main()
{
int t=1;
//scanf("%d",&t);
while(t--)
{long long int st[200009],ans[200009];
long long int a[200009],top=-1,l[200009],r[200009],i,j,n;
scanf("%I64d",&n);
for(i=0;i<n;i++)
scanf("%I64d",&a[i]);
st[++top]=0;ans[n]=0;l[0]=-1;r[n-1]=n;
for(i=1;i<n;i++)
{ans[i]=0;
while(a[st[top]]>=a[i] && top!=-1)
top--;
if(top==-1)
l[i]=-1;
else
l[i]=st[top];
st[++top]=i;
}
top=-1;st[++top]=n-1;
for(i=n-2;i>=0;i--)
{
while(a[st[top]]>=a[i] && top!=-1)
top--;
if(top==-1)
r[i]=n;
else
r[i]=st[top];
st[++top]=i;
}
for(i=0;i<n;i++)
if(ans[r[i]-l[i]-1]<a[i])
ans[r[i]-l[i]-1]=a[i];
for(i=n-1;i>=0;i--)
if(ans[i]<ans[i+1])
ans[i]=ans[i+1];
for(i=1;i<=n;i++)
printf("%I64d ",ans[i]);
printf("\n");
}
return 0;
}
| |
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high. A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group.Mike is a curious to know for each x such that 1ββ€βxββ€βn the maximum strength among all groups of size x. | Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x. | C | 5cf25cd4a02ce8020258115639c0ee64 | 15dde6e02e163390421824e656997de4 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"dsu",
"binary search",
"data structures"
] | 1432658100 | ["10\n1 2 3 4 5 4 3 2 1 6"] | null | PASSED | 1,900 | standard input | 1 second | The first line of input contains integer n (1ββ€βnββ€β2βΓβ105), the number of bears. The second line contains n integers separated by space, a1,βa2,β...,βan (1ββ€βaiββ€β109), heights of bears. | ["6 4 4 3 3 2 2 1 1 1"] | #include<stdio.h>
int main() {
long long int p,i,j,k,l,n,m,a[200005],b[200005]={0},c[200005],stc[200005],ptr,ans[200005]={0};
scanf("%lld",&n);
for(i=1;i<=n;i++)
scanf("%lld",&a[i]);
a[0] = -1;
a[n+1] = 0;
ptr = 1;
stc[1] = 1;
stc[0] = 0;
b[1] = 0;
for(i=2;i<=n;i++) {
if(a[i] > a[stc[ptr]])
b[i] = stc[ptr];
else {
while(a[i] <= a[stc[ptr]])
ptr--;
b[i] = stc[ptr];
}
ptr++;
stc[ptr] = i;
}
ptr = 1;
stc[0] = n+1;
stc[1] = n;
c[n] = n+1;
for(i=n-1;i>=1;i--) {
if(a[i] > a[stc[ptr]])
c[i] = stc[ptr];
else {
while(a[i] <= a[stc[ptr]])
ptr--;
c[i] = stc[ptr];
}
ptr++;
stc[ptr] = i;
}
for(i=1;i<=n;i++)
if(ans[c[i]-b[i]-1] < a[i])
ans[c[i]-b[i]-1] = a[i];
for(i=n-1;i>0;i--)
if(ans[i] < ans[i+1])
ans[i] = ans[i+1];
for(i=1;i<=n;i++)
printf("%lld ",ans[i]);
printf("\n");
return 0;
}
| |
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high. A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group.Mike is a curious to know for each x such that 1ββ€βxββ€βn the maximum strength among all groups of size x. | Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x. | C | 5cf25cd4a02ce8020258115639c0ee64 | 7cd7b33a76e0f22dad10698927cc84bc | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"dsu",
"binary search",
"data structures"
] | 1432658100 | ["10\n1 2 3 4 5 4 3 2 1 6"] | null | PASSED | 1,900 | standard input | 1 second | The first line of input contains integer n (1ββ€βnββ€β2βΓβ105), the number of bears. The second line contains n integers separated by space, a1,βa2,β...,βan (1ββ€βaiββ€β109), heights of bears. | ["6 4 4 3 3 2 2 1 1 1"] | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <limits.h>
#define INF INT_MIN
typedef long long int LL;
#define SI(n) scanf("%d",&n)
#define PI(n) printf("%d",n)
int max(int a , int b){
if(a>=b) return a;
return b;
}
int min(int a , int b){
if(a>b) return b;
return a;
}
typedef struct node{
int val;
struct node* next;
}node;
typedef struct stack{
node* startnode;
int size;
}stack;
void push(stack* given , int value){
if(given->startnode == NULL){
given->startnode = (node*)malloc(sizeof(node));
given->startnode->val = value;
given->startnode->next = NULL;
(given->size)++;
return;
}
node* temp;
temp = (node*)malloc(sizeof(node));
temp->val = value;
temp->next = given->startnode;
given->startnode = temp;
(given->size)++;
return;
}
int top(stack* given){
if(given->startnode)
return given->startnode->val;
return INF;
}
int size(stack* given){
return given->size;
}
bool isempty(stack* given){
if(given->size==0)
return true;
return false;
}
void pop(stack* given){
if(isempty(given)){
//printf("Stack is empty!\n");
return;
}
node* temp = given->startnode;
given->startnode = given->startnode->next;
(given->size)--;
free(temp);
return;
}
int main()
{
int n,i;
SI(n);
int a[n] , L[n] , R[n];
for(i=0;i<n;i++)
SI(a[i]);
L[0]=-1;
stack* mystack;
mystack = malloc(sizeof(stack));
mystack->size=0;
mystack->startnode=NULL;
push(mystack,0);
for(i=1;i<n;i++)
{
while(!isempty(mystack) && a[top(mystack)]>=a[i])
pop(mystack);
if(isempty(mystack))
L[i]=-1;
else
L[i]=top(mystack);
push(mystack,i);
}
while(!isempty(mystack))
pop(mystack);
R[n-1]=n;
push(mystack,n-1);
for(i=n-2;i>=0;i--)
{
while(!isempty(mystack) && a[top(mystack)]>=a[i])
pop(mystack);
if(isempty(mystack))
R[i]=n;
else
R[i]=top(mystack);
push(mystack,i);
}
int ans[n+1];
for(i=0;i<=n;i++)
ans[i]=0;
for(i=0;i<n;i++)
{
ans[R[i]-L[i]-1]=max(ans[R[i]-L[i]-1] ,a[i] );
//printf("%d %d\n",R[i],L[i]);
}
for(i=n-1;i>=0;i--)
{
ans[i]=max(ans[i] , ans[i+1]);
}
for(i=1;i<n;i++)
PI(ans[i]) , printf(" ");
PI(ans[i]);
printf("\n");
return 0;
} | |
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high. A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group.Mike is a curious to know for each x such that 1ββ€βxββ€βn the maximum strength among all groups of size x. | Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x. | C | 5cf25cd4a02ce8020258115639c0ee64 | 2c6e6a035570ee7aeae660ffc201058c | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"dsu",
"binary search",
"data structures"
] | 1432658100 | ["10\n1 2 3 4 5 4 3 2 1 6"] | null | PASSED | 1,900 | standard input | 1 second | The first line of input contains integer n (1ββ€βnββ€β2βΓβ105), the number of bears. The second line contains n integers separated by space, a1,βa2,β...,βan (1ββ€βaiββ€β109), heights of bears. | ["6 4 4 3 3 2 2 1 1 1"] | #include<stdio.h>
int main()
{
long long int n;
scanf("%lld",&n);
long long int a[200005],b[200005],c[200005],d[200005],i,j;
for(i=0;i<n;i++)
{
d[i]=0;
scanf("%lld",&a[i]);
}
b[0]=-1;
for(i=1;i<n;i++)
{
j=i-1;
if(a[j]<a[i])
b[i]=j;
else
{
while(b[j]!=-1)
{
if(a[b[j]]<a[i])
{
b[i]=b[j];
break;
}
else
j=b[j];
}
if(b[j]==-1)
{
b[i]=-1;
}
}
}
c[n-1]=n;
for(i=n-2;i>=0;i--)
{
j=i+1;
if(a[j]<a[i])
c[i]=j;
else
{
while(c[j]!=n)
{
if(a[c[j]]<a[i])
{
c[i]=c[j];
break;
}
else
j=c[j];
}
if(c[j]==n)
{
c[i]=n;
}
}
}
for(i=0;i<n;i++)
if(d[c[i]-b[i]-2]<a[i])
d[c[i]-b[i]-2]=a[i];
for(i=n-2;i>=0;i--)
if(d[i]<d[i+1])
d[i]=d[i+1];
for(i=0;i<n;i++)
printf("%lld ",d[i]);
printf("\n");
return 0;
}
| |
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high. A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group.Mike is a curious to know for each x such that 1ββ€βxββ€βn the maximum strength among all groups of size x. | Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x. | C | 5cf25cd4a02ce8020258115639c0ee64 | 9839bac7b198957096ce53ca98e9a14d | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"dsu",
"binary search",
"data structures"
] | 1432658100 | ["10\n1 2 3 4 5 4 3 2 1 6"] | null | PASSED | 1,900 | standard input | 1 second | The first line of input contains integer n (1ββ€βnββ€β2βΓβ105), the number of bears. The second line contains n integers separated by space, a1,βa2,β...,βan (1ββ€βaiββ€β109), heights of bears. | ["6 4 4 3 3 2 2 1 1 1"] | #include <stdio.h>
#define N 200000
int a[N];
int s[N];
int l[N], r[N];
int m[N+1];
int main()
{
int n;
scanf("%d", &n);
int i;
for (i=0; i<n; i++) {
scanf("%d", &a[i]);
}
int sp = -1;
/* top is s[sp] */
for (i=0; i<n; i++) {
while (sp >= 0 && a[s[sp]] > a[i]) {
int top = s[sp--];
r[top] = i;
}
l[i] = sp >= 0 ? s[sp]+1 : 0;
s[++sp] = i;
}
while (sp >= 0) {
r[s[sp--]] = i;
}
for (i=0; i<n; i++) {
int len = r[i]-l[i];
if (m[len] < a[i])
m[len] = a[i];
}
for (i=n-1; i; i--)
if (m[i] < m[i+1])
m[i] = m[i+1];
for (i=1; i<=n; i++) {
printf("%d%c", m[i], i == n ? '\n' : ' ');
}
return 0;
}
| |
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high. A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group.Mike is a curious to know for each x such that 1ββ€βxββ€βn the maximum strength among all groups of size x. | Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x. | C | 5cf25cd4a02ce8020258115639c0ee64 | c7a52f387a18467492d3dc9074adcb70 | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"dsu",
"binary search",
"data structures"
] | 1432658100 | ["10\n1 2 3 4 5 4 3 2 1 6"] | null | PASSED | 1,900 | standard input | 1 second | The first line of input contains integer n (1ββ€βnββ€β2βΓβ105), the number of bears. The second line contains n integers separated by space, a1,βa2,β...,βan (1ββ€βaiββ€β109), heights of bears. | ["6 4 4 3 3 2 2 1 1 1"] | #include<stdio.h>
#include<stdlib.h>
int main(){
int n,*ar,*l,*r,i,j;
scanf("%d",&n);
ar=malloc(sizeof(int)*n);
l=malloc(sizeof(int)*n);
r=malloc(sizeof(int)*n);
for(i=0;i<n;i++)
scanf("%d",ar+i);
for(i=0;i<n;i++){
j=i-1;
while(j>=0&&ar[j]>=ar[i])
j=l[j];
l[i]=j;
}
for(i=n-1;i>=0;i--){
j=i+1;
while(j<n&&ar[j]>=ar[i])
j=r[j];
r[i]=j;
}
for(i=0;i<n;i++){
r[i]-=l[i]+1;
l[i]=0;
}
for(i=0;i<n;i++)
if(l[r[i]-1]<ar[i])
l[r[i]-1]=ar[i];
for(i=n-2;i>=0;i--)
if(l[i]<l[i+1])
l[i]=l[i+1];
for(i=0;i<n;i++)
printf("%d ",l[i]);
printf("\n");
return 0;
}
| |
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high. A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group.Mike is a curious to know for each x such that 1ββ€βxββ€βn the maximum strength among all groups of size x. | Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x. | C | 5cf25cd4a02ce8020258115639c0ee64 | da0d5cd8b1bd86327e53c4193b0be60e | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"dsu",
"binary search",
"data structures"
] | 1432658100 | ["10\n1 2 3 4 5 4 3 2 1 6"] | null | PASSED | 1,900 | standard input | 1 second | The first line of input contains integer n (1ββ€βnββ€β2βΓβ105), the number of bears. The second line contains n integers separated by space, a1,βa2,β...,βan (1ββ€βaiββ€β109), heights of bears. | ["6 4 4 3 3 2 2 1 1 1"] | #include<stdio.h>
#include<stdlib.h>
typedef struct stack{
int top;
int items[200000];
}stk;
int top(stk *ps){
return ps->items[ps->top];
}
void pop(stk *ps){
ps->top--;
return;
}
void push(stk *ps,int i){
ps->items[++(ps->top)]=i;
return;
}
int isempty(stk *ps){
return (ps->top==-1);
}
void max(int *x,int *y){
if((*x)<(*y))
*x=*y;
return;
}
int main(void){
int i,n,len;
scanf("%d",&n);
int *a,*s,*r,*l;
stk *ps;
ps=(stk *)calloc(1,sizeof(stk));
ps->top=-1;
a=(int *)malloc(n*sizeof(int));
s=(int *)malloc((n+2)*sizeof(int));
l=(int *)malloc(n*sizeof(int));
r=(int *)malloc(n*sizeof(int));
for(i=0;i<n;i++){
scanf("%d",&a[i]);
s[i]=0;
}
s[n]=0;
s[n+1]=0;
for(i=0;i<n;i++){
while(!isempty(ps) && a[top(ps)]>=a[i])
pop(ps);
if(isempty(ps))
l[i]=-1;
else
l[i]=top(ps);
push(ps,i);
}
while(!isempty(ps))
pop(ps);
for(i=n-1;i>-1;--i){
while(!isempty(ps) && a[top(ps)]>=a[i])
pop(ps);
if(isempty(ps))
r[i]=n;
else
r[i]=top(ps);
push(ps,i);
}
for(i=0;i<n;i++){
len=r[i]-l[i]-1;
max(&s[len],&a[i]);
}
for(i=n;i>-1;--i)
max(&s[i],&s[i+1]);
for(i=1;i<n+1;++i)
printf("%d ",s[i]);
return 0;
}
| |
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high. A group of bears is a non-empty contiguous segment of the line. The size of a group is the number of bears in that group. The strength of a group is the minimum height of the bear in that group.Mike is a curious to know for each x such that 1ββ€βxββ€βn the maximum strength among all groups of size x. | Print n integers in one line. For each x from 1 to n, print the maximum strength among all groups of size x. | C | 5cf25cd4a02ce8020258115639c0ee64 | 9d838689c32e1c8cff5339b97821c89b | GNU C | standard output | 256 megabytes | train_000.jsonl | [
"dp",
"dsu",
"binary search",
"data structures"
] | 1432658100 | ["10\n1 2 3 4 5 4 3 2 1 6"] | null | PASSED | 1,900 | standard input | 1 second | The first line of input contains integer n (1ββ€βnββ€β2βΓβ105), the number of bears. The second line contains n integers separated by space, a1,βa2,β...,βan (1ββ€βaiββ€β109), heights of bears. | ["6 4 4 3 3 2 2 1 1 1"] | #include<stdio.h>
#include<stdlib.h>
int stack[200010],top=0,max[200010];
struct arr
{
int val,len;
};
typedef struct arr arr;
arr a[200010];
void merge(arr a[],int l,int mid,int r)
{
int i=l,j=mid+1,k=0;
arr c[200010];
for(;i<=mid&&j<=r;k++)
{
if(a[i].val<=a[j].val)
{
c[k].val=a[i].val;
c[k].len=a[i++].len;
}
else
{
c[k].val=a[j].val;
c[k].len=a[j++].len;
}
}
if(i>mid)
for(;j<=r;)
{
c[k++].val=a[j++].val;
c[k-1].len=a[j-1].len;
}
if(j>r)
for(;i<=mid;i++)
{
c[k++]=a[i];
c[k-1].len=a[i].len;
}
k=0;
for(i=l;i<=r;i++)
{
a[i].val=c[k].val;
a[i].len=c[k++].len;
}
}
void msort(arr a[],int l,int r)
{
if(l<r)
{
int mid=l+(r-l)/2;
msort(a,l,mid);
msort(a,mid+1,r);
merge(a,l,mid,r);
}
}
int main()
{
int i,n,j;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i].val);
stack[0]=0;
for(i=1;i<n;i++)
{
while(a[i].val<a[stack[top]].val&&top>=0)
{
a[stack[top]].len=i-stack[top];
top--;
}
stack[++top]=i;
}
for(;top>=0;top--)
{
a[stack[top]].len=n-stack[top];
}
top=0;
stack[0]=n-1;
for(i=n-2;i>=0;i--)
{
while(a[i].val<a[stack[top]].val&&top>=0)
{
a[stack[top]].len+=(stack[top]-i-1);
top--;
}
stack[++top]=i;
}
for(;top>=0;top--)
{
a[stack[top]].len+=(stack[top]);
}
msort(a,0,n-1);
j=1;
// for(i=0;i<n;i++)
// printf("%d %d\n",a[i].val,a[i].len);
for(i=n-1;i>=0&&j<=n;)
{
if(a[i].len>=j)
{
printf("%d ",a[i].val);
j++;
}
else
i--;
}
// printf("%d\n",a[0].val);
return 0;
}
| |
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. | Print the total number of people the restaurant denies service to. | C | e21e768dbb2e5f72873dc1c7de4879fd | 3af162577c018065af9688069bfa33e2 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1499791500 | ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1"] | NoteIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | PASSED | 1,200 | standard input | 1 second | The first line contains three integers n, a and b (1ββ€βnββ€β2Β·105, 1ββ€βa,βbββ€β2Β·105) β the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1,βt2,β...,βtn (1ββ€βtiββ€β2) β the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. | ["0", "2"] | #include<stdio.h>
int main()
{
long long n,a,r=0,b;
float m=0;
scanf("%lld %lld %lld",&n,&a,&b);
int t[n];
for(long long i=0;i<n;i++)
{
scanf("%d",&t[i]);
}
for(long long i=0;i<n;i++)
{
if(t[i]==2)
{
if(b>=1)
{
b=b-1;
}
else
{
r=r+2;
}
}
else if(t[i]==1)
{
if(a>=1)
{
a=a-1;
}
else
{
if(b>=1)
{
b=b-1;
m=m+0.5;
}
else if(m>0&&b>=0)
{
m=m-0.5;
}
else
{
r=r+1;
}
}
}
}
printf("%lld",r);
return 0;
}
| |
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. | Print the total number of people the restaurant denies service to. | C | e21e768dbb2e5f72873dc1c7de4879fd | 18309299d43b881f186d4dd55d234d9f | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1499791500 | ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1"] | NoteIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | PASSED | 1,200 | standard input | 1 second | The first line contains three integers n, a and b (1ββ€βnββ€β2Β·105, 1ββ€βa,βbββ€β2Β·105) β the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1,βt2,β...,βtn (1ββ€βtiββ€β2) β the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. | ["0", "2"] | #include <stdio.h>
int main()
{
int n, one_seat, two_seat, half_seat = 0, denied = 0;
char g;
scanf("%d %d %d", &n, &one_seat, &two_seat);
scanf("%c", &g);
for (int i = 0; i < n; ++i)
{
scanf("%c ", &g);
if (g == '1')
{
if (one_seat > 0)
one_seat--;
else if (two_seat > 0)
{
two_seat--;
half_seat++;
}
else if (half_seat > 0)
half_seat--;
else
denied++;
}
else
{
if (two_seat > 0)
two_seat--;
else
denied += 2;
}
}
printf("%d", denied);
return 0;
} | |
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. | Print the total number of people the restaurant denies service to. | C | e21e768dbb2e5f72873dc1c7de4879fd | 3a16a96613bd0c16f6aa047b6ebeb4ca | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1499791500 | ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1"] | NoteIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | PASSED | 1,200 | standard input | 1 second | The first line contains three integers n, a and b (1ββ€βnββ€β2Β·105, 1ββ€βa,βbββ€β2Β·105) β the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1,βt2,β...,βtn (1ββ€βtiββ€β2) β the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. | ["0", "2"] | #include<stdio.h>
int main(int argc, char const *argv[]) {
/* code */
int n,sing,dou,dou_sing=0;
scanf("%d %d %d",&n,&sing,&dou);
int deny=0,incoming;
for(int i=0;i<n;i++)
{
scanf("%d",&incoming);
if(incoming==2 && dou >=1)
dou=dou-1;
else if (incoming==1 && sing>=1)
sing=sing-1;
else if (incoming==1 && dou>=1)
{
dou=dou-1;
dou_sing=dou_sing+1;
}
else if(incoming==1 && dou_sing >= 1)
dou_sing=dou_sing-1;
else
deny=deny+incoming;
}
printf("%d\n",deny);
return 0;
}
| |
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. | Print the total number of people the restaurant denies service to. | C | e21e768dbb2e5f72873dc1c7de4879fd | 140acd1ff6a986d215f35bf9f14afde4 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1499791500 | ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1"] | NoteIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | PASSED | 1,200 | standard input | 1 second | The first line contains three integers n, a and b (1ββ€βnββ€β2Β·105, 1ββ€βa,βbββ€β2Β·105) β the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1,βt2,β...,βtn (1ββ€βtiββ€β2) β the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. | ["0", "2"] | #include <stdio.h>
int main()
{
int n, a, b, i, temp, c = 0, count = 0;
scanf("%d %d %d", &n, &a, &b);
for(i=0; i<n; i++){
scanf("%d", &temp);
if(temp == 1){
if(a != 0)
a--;
else if(b != 0){
b--;
c++;
}
else if(c != 0)
c--;
else
count++;
}
else if(temp == 2){
if(b != 0)
b--;
else
count = count + 2;
}
}
printf("%d", count);
return 0;
}
| |
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. | Print the total number of people the restaurant denies service to. | C | e21e768dbb2e5f72873dc1c7de4879fd | 018c61a37afe77b49c35c5647ccb4e80 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1499791500 | ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1"] | NoteIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | PASSED | 1,200 | standard input | 1 second | The first line contains three integers n, a and b (1ββ€βnββ€β2Β·105, 1ββ€βa,βbββ€β2Β·105) β the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1,βt2,β...,βtn (1ββ€βtiββ€β2) β the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. | ["0", "2"] | #include<stdio.h>
int otable;
int ttable;
int totable;
int g[200001];
int main(){
int n,a,b; //nκ·Έλ£Ή 1μ§λ¦¬ν
μ΄λΈ 2μ§λ¦¬ν
μ΄λΈ
scanf("%d %d %d",&n,&a,&b);
otable=a,ttable=b;
for(int i=0;i<n;i++){
scanf("%d",&g[i]);
}
int ans=0;
for(int i=0;i<n;i++){
if(g[i]==1){
if(otable>0){
otable--;
continue;
}
else if(ttable>0){
ttable--;
totable++;
continue;
}
else if(totable>0){
totable--;
continue;
}
else ans++;
}
else{
if(ttable>0) ttable--;
else ans+=2;
}
}
printf("%d",ans);
} | |
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. | Print the total number of people the restaurant denies service to. | C | e21e768dbb2e5f72873dc1c7de4879fd | 4a6362f466638baa6d550adafcec1da9 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1499791500 | ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1"] | NoteIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | PASSED | 1,200 | standard input | 1 second | The first line contains three integers n, a and b (1ββ€βnββ€β2Β·105, 1ββ€βa,βbββ€β2Β·105) β the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1,βt2,β...,βtn (1ββ€βtiββ€β2) β the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. | ["0", "2"] | #include<stdio.h>
int main()
{
int N,M,i,j,k,a,b,c,d,x,y,z,t,s,m,n,p,q;
scanf("%d %d %d", &N, &a, &b);
int A[N],B[N],C[N];
for(i=0; i<N; i++)
{
scanf("%d", &A[i]);
}
x=0;
y=0;
c=0;
for(i=0; i<N; i++)
{
if(A[i]==2)
{
if(b==0)
{
x++;
}
else
{
b=b-1;
}
}
else if(A[i]==1)
{
if(a!=0)
{
a=a-1;
}
else if(b!=0)
{
b=b-1;
c++;
}
else if(c!=0)
{
c=c-1;
}
else
{
y++;
}
}
}
s=y+(x*2);
printf("%d\n", s);
return 0;
}
| |
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. | Print the total number of people the restaurant denies service to. | C | e21e768dbb2e5f72873dc1c7de4879fd | a84262a07526a802aa89ea76905870f9 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1499791500 | ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1"] | NoteIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | PASSED | 1,200 | standard input | 1 second | The first line contains three integers n, a and b (1ββ€βnββ€β2Β·105, 1ββ€βa,βbββ€β2Β·105) β the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1,βt2,β...,βtn (1ββ€βtiββ€β2) β the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. | ["0", "2"] | #include<stdio.h>
int main()
{
int N,M,i,j,k,a,b,c,d,x,y,z,t,s,m,n,p,q;
scanf("%d %d %d", &N, &a, &b);
int A[N],B[N],C[N];
for(i=0; i<N; i++)
{
scanf("%d", &A[i]);
}
x=0;
y=0;
c=0;
for(i=0; i<N; i++)
{
if(A[i]==2)
{
if(b==0)
{
x++;
}
else
{
b=b-1;
}
}
else if(A[i]==1)
{
if(a!=0)
{
a=a-1;
}
else if(b!=0)
{
b=b-1;
c++;
}
else if(c!=0)
{
c=c-1;
}
else
{
y++;
}
}
}
s=y+(x*2);
printf("%d\n", s);
return 0;
}
| |
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. | Print the total number of people the restaurant denies service to. | C | e21e768dbb2e5f72873dc1c7de4879fd | 7bc633c6dc4bf8574a8d38ccbbfe8235 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1499791500 | ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1"] | NoteIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | PASSED | 1,200 | standard input | 1 second | The first line contains three integers n, a and b (1ββ€βnββ€β2Β·105, 1ββ€βa,βbββ€β2Β·105) β the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1,βt2,β...,βtn (1ββ€βtiββ€β2) β the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. | ["0", "2"] | /* Coached by rainboy */
#include <stdio.h>
int main() {
int n, a, b, c, cnt;
scanf("%d%d%d", &n, &a, &b);
cnt = c = 0;
while (n--) {
int t;
scanf("%d", &t);
if (t == 1)
if (a > 0)
a--;
else if (b > 0)
c++, b--;
else if (c > 0)
c--;
else
cnt++;
else
if (b > 0)
b--;
else
cnt += 2;
}
printf("%d\n", cnt);
return 0;
}
| |
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. | Print the total number of people the restaurant denies service to. | C | e21e768dbb2e5f72873dc1c7de4879fd | f8e4d30b0c0dd2ef4c798b09c787c7fd | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1499791500 | ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1"] | NoteIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | PASSED | 1,200 | standard input | 1 second | The first line contains three integers n, a and b (1ββ€βnββ€β2Β·105, 1ββ€βa,βbββ€β2Β·105) β the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1,βt2,β...,βtn (1ββ€βtiββ€β2) β the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. | ["0", "2"] | #include <stdio.h>
int main() {
int n, a, b, c, cnt;
scanf("%d%d%d", &n, &a, &b);
cnt = c = 0;
while (n--) {
int t;
scanf("%d", &t);
if (t == 1)
if (a > 0)
a--;
else if (b > 0)
c++, b--;
else if (c > 0)
c--;
else
cnt++;
else
if (b > 0)
b--;
else
cnt += 2;
}
printf("%d\n", cnt);
return 0;
}
| |
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. | Print the total number of people the restaurant denies service to. | C | e21e768dbb2e5f72873dc1c7de4879fd | fb66d076e91490a8951a53aed0d9e574 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1499791500 | ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1"] | NoteIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | PASSED | 1,200 | standard input | 1 second | The first line contains three integers n, a and b (1ββ€βnββ€β2Β·105, 1ββ€βa,βbββ€β2Β·105) β the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1,βt2,β...,βtn (1ββ€βtiββ€β2) β the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. | ["0", "2"] | #include<stdio.h>
int main()
{
long int n,a,b,x,c=0,ans=0,i;
scanf("%d%d%d",&n,&a,&b);
for(i=1;i<=n;i++)
{
scanf("%d",&x);
if(x==1)
{
if(a>=1)
a--;
else if(a==0&&b>=1)
{
b--;
c++;
}
else if(a==0&&c>=1)
c--;
else
ans++;
}
else
{
if(b>=1)
b--;
else
ans=ans+2;
}
}
printf("%d",ans);
return 0;
}
| |
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. | Print the total number of people the restaurant denies service to. | C | e21e768dbb2e5f72873dc1c7de4879fd | fb067d264699701368a2a798106a7b46 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1499791500 | ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1"] | NoteIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | PASSED | 1,200 | standard input | 1 second | The first line contains three integers n, a and b (1ββ€βnββ€β2Β·105, 1ββ€βa,βbββ€β2Β·105) β the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1,βt2,β...,βtn (1ββ€βtiββ€β2) β the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. | ["0", "2"] | #include <stdio.h>
#include <stdlib.h>
#include<math.h>
int main()
{
int n, a, b;
int* t= malloc(n*sizeof(int));
scanf("%d %d %d", &n, &a, &b);
char temp;
for(int i=0; i<n; i++)
{
scanf("%d%c", &t[i], &temp);
}
if(n>=1 && n<=2*pow(10, 5) && a>=1 && b<=2*pow(10, 5))
{
int denied = 0, sseater =0, dseater =0;
int dtable = 0;
for(int i=0; i<n; i++)
{
if(t[i]==1)
{
if(sseater < a)
{
sseater++;
}
else if(dseater < 2*b)
{
dseater++;
dtable++;
}
else denied++;
}
else if(t[i]==2)
{
if(dtable<b)
{
dseater += 2;
dtable++;
}
else denied += 2;
}
}
printf("%d\n", denied);
}
return 0;
}
| |
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. | Print the total number of people the restaurant denies service to. | C | e21e768dbb2e5f72873dc1c7de4879fd | cf370441c88662f3a117acc55aba0586 | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1499791500 | ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1"] | NoteIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | PASSED | 1,200 | standard input | 1 second | The first line contains three integers n, a and b (1ββ€βnββ€β2Β·105, 1ββ€βa,βbββ€β2Β·105) β the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1,βt2,β...,βtn (1ββ€βtiββ€β2) β the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. | ["0", "2"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
int main()
{
int n, a,b,*t,i,j,k,l,ts=0,os=0,bi=0,d=0;
scanf("%d%d%d",&n,&a,&b);
t=(int*)malloc(sizeof(int)*n);
for(i=0;i<n;i++){
scanf("%d",&t[i]);
if(t[i]==1)
os++;
else
ts+=2;
}
for(i=0;i<n;i++){
if(t[i]==1&&a>0){
os--;
a--;
}
else if(t[i]==1&&a==0&&b-d>0){
d++;
os--;
}
else if(t[i]==1&&a==0&&b-d==0&&d!=0){
os--;
d--;
b--;
}
else if(t[i]==2&&b-d>0){
ts-=2;
b--;
}
}
printf("%d\n",os+ts);
return 0;
}
| |
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. | Print the total number of people the restaurant denies service to. | C | e21e768dbb2e5f72873dc1c7de4879fd | ad63ce4ced6010b9ba999c951faaa49e | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1499791500 | ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1"] | NoteIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | PASSED | 1,200 | standard input | 1 second | The first line contains three integers n, a and b (1ββ€βnββ€β2Β·105, 1ββ€βa,βbββ€β2Β·105) β the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1,βt2,β...,βtn (1ββ€βtiββ€β2) β the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. | ["0", "2"] | #include<stdio.h>
int main()
{
long long int i,a,b,n,c,count;
while(scanf("%I64d",&n)==1)
{
scanf("%I64d%I64d",&a,&b);
b=b*2;
int a1=0;
count=0;
for(i=0; i<n; i++)
{
scanf("%I64d",&c);
if(c==1&&a>0)
{
a--;
}
else if(c==1&&b>0)
{
b-=2;
a1++;
}
else if(c==1&&a1>0)
{
a1--;
}
else if(b>0)
{
b-=2;
}
else
{
count+=c;
}
}
printf("%I64d\n",count);
}
return 0;
}
| |
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. | Print the total number of people the restaurant denies service to. | C | e21e768dbb2e5f72873dc1c7de4879fd | 8a3fb5331ee72c3c09ab3b736a543f7f | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1499791500 | ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1"] | NoteIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | PASSED | 1,200 | standard input | 1 second | The first line contains three integers n, a and b (1ββ€βnββ€β2Β·105, 1ββ€βa,βbββ€β2Β·105) β the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1,βt2,β...,βtn (1ββ€βtiββ€β2) β the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. | ["0", "2"] | #include<stdio.h>
int main()
{
int n,a,b,i,j,service = 0;
scanf("%d %d %d",&n,&a,&b);
j = b * 2;
int ara[n];
for(i = 0;i < n;i++)
{
scanf("%d",&ara[i]);
}
for(i = 0;i < n;i++)
{
if(ara[i] == 1)
{
if(a > 0)
{
a--;
}
else if(j > 0)
{
j--;
b--;
}
else
{
service++;
}
}
else
{
if(b > 0)
{
b--;
j -= 2;
}
else
{
service += 2;
}
}
}
printf("%d\n",service);
return 0;
}
| |
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. | Print the total number of people the restaurant denies service to. | C | e21e768dbb2e5f72873dc1c7de4879fd | 1cc7659d56dd4d2c831b68acabacca1c | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1499791500 | ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1"] | NoteIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | PASSED | 1,200 | standard input | 1 second | The first line contains three integers n, a and b (1ββ€βnββ€β2Β·105, 1ββ€βa,βbββ€β2Β·105) β the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1,βt2,β...,βtn (1ββ€βtiββ€β2) β the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. | ["0", "2"] | #include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int n,a,b,i,m=0,d[200001],c=0;
scanf("%d %d %d",&n,&a,&b);
for(i=0; i<n; i++)
scanf("%d",&d[i]);
for(i=0; i<n; i++){
if(d[i]==2){
if(b>0) b--;
else m+=2;
}
else if(d[i]==1){
if(a>0)
a--;
else if(b>0){
b--;
c++;
}
else if(c>0)
c--;
else m++;
}
}
printf("%d",m);
}
| |
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. | Print the total number of people the restaurant denies service to. | C | e21e768dbb2e5f72873dc1c7de4879fd | 3950b6ab27d90809476d508bcc5f6cfe | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1499791500 | ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1"] | NoteIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | PASSED | 1,200 | standard input | 1 second | The first line contains three integers n, a and b (1ββ€βnββ€β2Β·105, 1ββ€βa,βbββ€β2Β·105) β the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1,βt2,β...,βtn (1ββ€βtiββ€β2) β the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. | ["0", "2"] | #include<stdio.h>
int main()
{
int n = 0, a = 0 , b = 0 , rem = 0;
int count = 0 ;
scanf("%d %d %d",&n,&a,&b);
for ( int i = 0 ; i < n ; i++ )
{
int m = 0;
scanf("%d",&m);
if (m == 2)
{
if ( b > 0 )
b -= 1 ;
else
count += 2 ;
}
else
{
if ( a > 0)
a -= 1;
else if ( b > 0 )
{
b--;
rem++;
}
else if ( rem > 0 )
rem--;
else
count++;
}
}
printf("%d\n",count);
} | |
In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. | Print the total number of people the restaurant denies service to. | C | e21e768dbb2e5f72873dc1c7de4879fd | 73b10e534aa43d594fc2f409d441865c | GNU C11 | standard output | 256 megabytes | train_000.jsonl | [
"implementation"
] | 1499791500 | ["4 1 2\n1 2 1 1", "4 1 1\n1 1 2 1"] | NoteIn the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients. | PASSED | 1,200 | standard input | 1 second | The first line contains three integers n, a and b (1ββ€βnββ€β2Β·105, 1ββ€βa,βbββ€β2Β·105) β the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers t1,βt2,β...,βtn (1ββ€βtiββ€β2) β the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people. | ["0", "2"] | #include<stdio.h>
#include<string.h>
int main()
{
int n,a,b;
scanf("%d %d %d",&n,&a,&b);
int cap1=0;
int cap2=0;
int vacant1=a;
int vacant2=b;
int deny=0;
for(int itr=0;itr<n;itr++)
{
int size;
scanf("%d",&size);
if(size==1)
{
if(cap1<a)
{
cap1++;
vacant1--;
}
else if(cap2<2*b)
{
cap2++;
vacant2--;
}
else
{
deny++;
}
}
if(size==2)
{
if(cap2<2*b && vacant2>0)
{
cap2+=2;
vacant2--;
}
else
{
deny+=2;
}
}
}
printf("%d\n",deny);
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.