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 lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
178dc786788a3eaa120f056a4e1adbcd
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include <stdio.h> #include <stdlib.h> #include <float.h> #define pi 3.14159265358979323846 int main() { int d,h,v,e; double x,y,z; scanf("%d %d %d %d",&d,&h,&v,&e); x=0.25*d*d*pi; y=v/x; z=e; if(y>z){printf("YES\n"); y=y-z; printf("%.13g\n",h/y); } else{printf("NO");} return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
fad916f9fae0beb7a3ebe2c9f1821eef
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include<stdio.h> #include<math.h> int main(){ double d,h,v,e; scanf("%lf", &d); scanf("%lf", &h); scanf("%lf", &v); scanf("%lf", &e); double D = d; d = d/2; double vol = M_PI * d*d * h; double E = e*d*d*M_PI; double time = vol / (v-E); //cout<<time<<endl; if(time <= 10000 && time >= 0){ printf("YES\n"); printf("%0.15lf\n", time); }else{ printf("NO\n"); } return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
0dbf176f8c0f4d2ab7406f083db12924
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include <stdio.h> #include <math.h> #define epsilon 0.00000000001 int main() { int d, h, v, e; scanf("%d %d %d %d", &d, &h, &v, &e); double area = d*d*M_PI/4; double increase_rate = area*e;//*1000; double volume; if(increase_rate - v > epsilon) { printf("NO\n"); } else { printf("YES\n"); volume = area*h;//*1000; printf("%lf\n", volume/(v-increase_rate)); } return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
c64114587e5560b4aa5af6b834cf3002
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include<stdio.h> #include<string.h> #include<math.h> const double pi=4*atan(1.0); int main() { int d,h,v,e; double s,r; scanf("%d%d%d%d",&d,&h,&v,&e); r=d/2.0; if(v<=e*pi*r*r) printf("NO\n"); else { printf("YES\n"); s=(pi*r*r*h/(v-pi*r*r*e)); printf("%.8lf\n",s); } return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
3978ed90c460947e05d5738628849e91
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include<stdio.h> #include<math.h> int main(){ double d,h,x,v,t,e; scanf("%lf%lf%lf%lf",&d,&h,&v,&e); x=M_PI*d*d*e/4; if(x<v){ printf("YES\n"); printf("%lf\n",M_PI*d*d*h/4/(v-x)); } else{ printf("NO\n"); } return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
72cff46afcffe4bae65c37697739cced
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include<stdio.h> int main() { int d,h,v,e,d2,h2; double pi=acos(-1),t,vol,declevel,uplevel,ans,upvol,downvol; scanf("%d %d %d %d",&d,&h,&v,&e); vol=pi*(d/2.0)*(d/2.0)*h; upvol=pi*(d/2.0)*(d/2.0)*e; downvol=v; if(upvol>=downvol) printf("NO"); else { ans=downvol-upvol; printf("YES\n%.12lf\n",vol/ans); } }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
63f9f4bc0c7246a99f170de96f6d932f
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include<stdio.h> int main () { double d,h,v,e,r,n,x,a,b,c; double pi =2 * acos(0.0); scanf("%lf %lf %lf %lf",&d,&h,&v,&e); r=d/2; a=pi*r*r*h; n=pi*r*r*e; if(v<=n) printf("NO"); else { printf("YES\n"); b=v-n; c=a/b; printf("%lf",c); }}
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
dc746580ea1b19119bcb8aeb340f21f7
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include<stdio.h> #define pi 3.1415926 int main() { double d,h,v,e; while(scanf("%lf%lf%lf%lf",&d,&h,&v,&e)!=EOF) { d/=2; double t=pi*d*d; t=v/t; if(t<=e) printf("NO\n"); else { printf("YES\n"); t=h/(t-e); printf("%lf\n",t); } } return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
65f9ed19252e9b948cc56d989965682a
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include<stdio.h> #define pai 3.14159265359 int main() { int i,l,m,n; double v,e,h,d; while(scanf("%lf%lf%lf%lf",&d,&h,&v,&e)!=EOF) { d=d/2; v=v/(d*d*pai); if(e>=v) printf("NO\n"); else { printf("YES\n"); v=v-e; h=h/v; printf("%.12lf\n",h); } } }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
5383ef8f925260e4371aaf21358f4e1d
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #define pi 3.14159265 int main() { double ta; double icindekisu,hiz,r,R,h,v,e; scanf("%lf%lf%lf%lf",&R,&h,&v,&e); r=R/2; ta=pi*(r*r); //printf() icindekisu=ta*h; hiz=v-(e*ta); if(hiz<=0){ printf("NO\n"); return 0; } if(hiz>0){ printf("YES\n"); printf("%.12lf\n",icindekisu/hiz); } return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
c17cc0f2e9089d7c0d8114d5aedcdbf1
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include<stdio.h> #include<math.h> #include<conio.h> #define pi 3.14159265358979323846 int main() { int a,h,e,v; double b,g,t; scanf("%d%d%d%d",&a,&h,&v,&e); g=pi*a*a*e/4; if(g<v) { b=pi*h*a*a/4; t=b/(v-g); printf("\nYES\n%lf",t); } else printf("\nNO"); return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
657aaeb5fc9f27cfd4783e6f83d3c8c8
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include<stdio.h> #include<math.h> int main() { int d,h,v,e; float rate,ans; scanf("%d%d%d%d",&d,&h,&v,&e); rate=4*(float)v/((float)(d*d)*M_PI); //printf("%f",rate); if(rate<(float)e) { printf("NO\n"); } else { printf("YES\n"); ans=(float)h/(rate-(float)e); printf("%.12f\n",ans); } return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
16773cc8d5cb67672d8ae32669787203
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include<stdio.h> #include<malloc.h> #include<math.h> #define pi 3.14159265358979323846 int main() { int d,v,h,e; scanf("%d %d %d %d",&d,&h,&v,&e); double rate=pi*d*d*e/4.0; rate-=v; if(rate>=0) { printf("NO"); } else{ double t=(pi*d*d*h)/4.0; t/=rate; t*=-1; printf("YES\n%.12lf",t); } return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
9dcbf2e1787baf20b1559a33b3f3e3f4
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include<stdio.h> int main(void) { int d,h,v,e; double r,A,V,vh,eh,t,pi=3.1415926535; scanf("%d %d %d %d",&d,&h,&v,&e); r=d/2.0; A=pi*r*r; V=A*h; vh=v/A; eh=e*1.0; if(vh<=eh) { printf("NO"); } else { t=h/(vh-eh); printf("YES\n%0.6lf",t); } return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
d4a19ac7c361ee7b6f7961e4f17a8279
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include<stdio.h> #define PI 3.14159265358979323846 int main() { double d,h,v,e,area,diff,res; scanf("%lf %lf %lf %lf",&d,&h,&v,&e); area=PI*(d/2)*(d/2); if((v/area)<=e) { printf("NO"); } else { printf("YES\n"); diff=(v/area)-e; res=(1/diff)*h; printf("%0.12lf",res); } return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
086360ff81afcd57e35f5452f2f2df67
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include <stdio.h> #include <math.h> int main() { float r, volagua, volaumenta, res, d, h, e, v; scanf("%f %f %f %f", &d, &h, &v, &e); r = d/2; volagua = r * r * M_PI * h; volaumenta = r * r * M_PI * e; if (volaumenta >= v) { printf("NO"); } else { res = volagua * (1/(v - volaumenta)); printf("YES\n%f\n", res); } return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
6c1a3d9c4dfb565d0d4202d43321e319
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include<stdio.h> int main(void) { float pi=3.141592653589; int d,h,v,e; scanf("%d%d%d%d",&d,&h,&v,&e); if(pi*d*d*e/4>=v) { printf("NO\n"); } else { printf("YES\n"); printf("%f\n",h*pi*d*d/(v*4-(pi*d*d*e))); } return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
37010ddb9cc46d0ce0621d918159b297
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include <stdio.h> #define PI 3.1415926535897 double d,h,v,e; int main() { scanf("%lf%lf%lf%lf",&d,&h,&v,&e); if(PI*(d/2)*(d/2)*e>=v) printf("NO"); else { v -= PI*(d/2)*(d/2)*e; printf("YES\n%.12f",PI*(d/2)*(d/2)*h/v); } return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
28a2444de787361d6f24c94cf5f62c16
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include<stdio.h> int main() { double pi =2 * acos(0.0); double d,h,v,e; scanf("%lf %lf %lf %lf",&d,&h,&v,&e); double a= pi*(d/2)*(d/2); double g=e*a; if(g>=v){printf("NO");} else { double ans; printf("YES\n"); ans=(h*a)/(v-g); printf("%.12lf",ans); } }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
320611a65134338aecc6486dfc487639
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { int d,h,v,e; scanf("%d%d%d%d",&d,&h,&v,&e); double dij=(double)d/2; //printf("%lf",dij); double v2=dij*dij*M_PI*e; // printf("v2=%lf",v2); if (v2>=v) printf("NO\n"); else { printf("YES\n"); double hh=h*dij*dij*M_PI; double rez=(double)(hh/(v-v2)); printf("%lf\n",rez); } return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
43f172263241c975920df7bedc2948ad
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include<stdio.h> int main() { double d,e,h,v; double p=3.14159265358979,x,t; scanf("%lf %lf %lf %lf",&d,&h,&v,&e); x=0.25*p*d*d*e; t=h/(((4*v)/(p*d*d))-e); if(x>v)printf("NO"); else printf("YES\n%.12lf",t); return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
4dcad9479b02cb89ee91b4fd5e8318e2
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include <stdio.h> #include <stdlib.h> #define PI 3.14159265358979323846 int main() { double i,j,k,l,m,n,v,h,e,d,val; double a,s,t; scanf("%lf %lf %lf %lf",&d,&h,&v,&e); a=(PI*(d*d))/4; s=v/a; if (e>s) { printf("NO"); return 0; } t=(h)/(s-e); if (t>10000) printf("NO"); else { printf("YES\n%f",t); } }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
06b9e0ed912fc0b939b76b69d1fe1a10
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include<stdio.h> #define pi 3.14159265359 int main(){ int d, h, v, e; scanf("%d %d %d %d", &d, &h, &v, &e); double vol = (pi * d * d * 1.0)/4.0; double rise = vol * e; //printf("%f ", rise); double fall = v * 1.0; //printf("%f ", fall); if(fall > rise){ printf("YES\n"); double ans = (vol * h)/(fall - rise); printf("%.12f\n", ans); } else printf("NO\n"); return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
02ef4b3f298a46778bc0e2b67c9a90db
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include<stdio.h> #define pi 3.14159265359 int main() { long int d,h,v,e; float x; scanf("%ld%ld%ld%ld",&d,&h,&v,&e); x=(float)((v*4)/(pi*d*d))-e; x<=0?printf("NO"):printf("YES\n%lf",h/x); }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
fc81362bb034e78b0413043cab1d69c0
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include <math.h> #include <stdio.h> int main() { int d, h, v, e; double r, hv; scanf("%d%d%d%d", &d, &h, &v, &e); r = (double) d / 2; hv = (double) v / (r * r * M_PI); if (e >= hv) printf("NO\n"); else { printf("YES\n"); printf("%.12lf\n", h / (hv - e)); } return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
358d7054ec94a3c48a07ab72dd74321d
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include<stdio.h> #include<math.h> int main() { long long int d, h, v, e; double H, t, pi=acos(-1); scanf("%I64d %I64d %I64d %I64d", &d, &h, &v, &e); H=(4.0*v)/(pi*d*d); t=h/(H-e); if (H<e) printf("NO"); else { printf("YES\n"); printf("%.12lf", t); } return 0; }
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals d centimeters. Initial level of water in cup equals h centimeters from the bottom. You drink a water with a speed equals v milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on e centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.Note one milliliter equals to one cubic centimeter.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 4. It is guaranteed that if the answer exists, it doesn't exceed 104.
C
fc37ef81bb36f3ac07ce2c4c3ec10d98
e6d37a243060f54e2c8074ca7a9c383a
GNU C
standard output
256 megabytes
train_000.jsonl
[ "geometry", "math" ]
1461947700
["1 2 3 100", "1 1 1 1"]
NoteIn the first example the water fills the cup faster than you can drink from it.In the second example area of the cup's bottom equals to , thus we can conclude that you decrease the level of water by centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in seconds.
PASSED
1,100
standard input
1 second
The only line of the input contains four integer numbers d, h, v, e (1 ≤ d, h, v, e ≤ 104), where: d — the diameter of your cylindrical cup, h — the initial level of water in the cup, v — the speed of drinking process from the cup in milliliters per second, e — the growth of water because of rain if you do not drink from the cup.
["NO", "YES\n3.659792366325"]
#include <stdio.h> #define PI 3.14159265359 int main(){ long int d, h, v, e; scanf("%ld", &d); scanf("%ld", &h); scanf("%ld", &v); scanf("%ld", &e); if ((v/(PI*((float)d/2)*((float)d/2)))>e){ if(((PI*((float)d/2)*((float)d/2)*h)/(v-e*PI*((float)d/2)*((float)d/2)))<=10000){ printf("YES\n"); printf("%f", ((PI*((float)d/2)*((float)d/2)*h)/(v-e*PI*((float)d/2)*((float)d/2)))); } else{ printf("NO"); } } else{ printf("NO"); } return 0; }
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 &lt; l2 ≤ r2 &lt; ... &lt; lk ≤ rk ≤ n; ri - li + 1 = m), in such a way that the value of sum is maximal possible. Help George to cope with the task.
Print an integer in a single line — the maximum possible value of sum.
C
ee3c228cc817536bf6c10ea4508d786f
fdc73b37dad79fd3163ad3c788ae6cea
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation" ]
1411054200
["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0"]
null
PASSED
1,700
standard input
1 second
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
["9", "61"]
#include <stdio.h> #include <stdlib.h> long long int p[5005]={0}; long long int sum[5005]={0}; long long int f[5005][5005]={0}; long long int max(long long int a,long long int b){ if(a>b) return a; else return b; } int main(){ int i,j,n,m,k; scanf("%d%d%d",&n,&m,&k); /*int *p = (int *)malloc(n*sizeof(int)); int *sum[n+1]; for(i=0;i<=n;i++) sum[i] = (int *)calloc(n+1,sizeof(int));*/ for(i=1;i<=n;i++) scanf("%lld",&p[i]); for(i=1;i<=m;i++) sum[1] += p[i]; for(i=2;i<=n-m+1;i++){ sum[i] = sum[i-1]; sum[i] += p[i+m-1]; sum[i] -= p[i-1]; } /*int *f[n+1]; for(i=0;i<=n;i++) f[i] = (int *)calloc(k+1,sizeof(int));*/ for(i=m;i<=n;i++){ for(j=1;j<=k;j++){ f[i][j] = max(f[i-m][j-1]+sum[i-m+1],f[i-1][j]); } } printf("%lld\n",f[n][k]); return 0; }
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 &lt; l2 ≤ r2 &lt; ... &lt; lk ≤ rk ≤ n; ri - li + 1 = m), in such a way that the value of sum is maximal possible. Help George to cope with the task.
Print an integer in a single line — the maximum possible value of sum.
C
ee3c228cc817536bf6c10ea4508d786f
12443e675c3deb77c3d9bd5e21010515
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation" ]
1411054200
["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0"]
null
PASSED
1,700
standard input
1 second
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
["9", "61"]
#include<stdio.h> long long int dp[5001][5002]; int main() { long long int n,m,k,max=0; scanf("%lld%lld%lld",&n,&m,&k); long long int arr[5001],i,a,j; arr[0]=0; for(i=1;i<=n;i++) { scanf("%lld",&a); arr[i]=arr[i-1]+a; } for(i=0;i<=k;i++) { for(j=0;j<=n+1;j++) dp[i][j]=0; } for(i=1;i<=k;i++) { for(j=n-m+1;j>=1;j--) { if(arr[j+m-1]-arr[j-1]+dp[i-1][j+m]>dp[i][j+1]) dp[i][j]=arr[j+m-1]-arr[j-1]+dp[i-1][j+m]; else dp[i][j]=dp[i][j+1]; } } printf("%lld",dp[k][1]); return 0; }
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 &lt; l2 ≤ r2 &lt; ... &lt; lk ≤ rk ≤ n; ri - li + 1 = m), in such a way that the value of sum is maximal possible. Help George to cope with the task.
Print an integer in a single line — the maximum possible value of sum.
C
ee3c228cc817536bf6c10ea4508d786f
b0865ac220555ca71f2cd8fb6058305b
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation" ]
1411054200
["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0"]
null
PASSED
1,700
standard input
1 second
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
["9", "61"]
#include<stdio.h> #include<stdlib.h> int a[5100]; long long d[5010][5100]; int main(void) { int i,j,p,n,m; long long sump; while(scanf("%d%d%d",&n,&m,&p)==3) { for(i=1;i<=n;i++) { scanf("%d",&a[i]); } for(i=1;i<=n;i++) { for(j=1;j<=p;j++) { d[i][j]=-1; } } sump=0; for(j=1;j<=m;j++) { sump=sump+a[j]; } d[m][1]=sump; for(j=m+1;j<=n;j++) { sump=sump-a[j-m]+a[j]; if(sump>d[j-1][1]) { d[j][1]=sump; } else { d[j][1]=d[j-1][1]; } } for(i=2*m;i<=n;i++) { sump=0; for(j=i-m+1;j<=i;j++) { sump=sump+a[j]; } for(j=2;j<=p;j++) { d[i][j]=d[i-1][j]; if((d[i-m][j-1]!=-1)&&(d[i-m][j-1]+sump>d[i][j])) { d[i][j]=d[i-m][j-1]+sump; } } } printf("%I64d\n",d[n][p]); } return 0; }
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 &lt; l2 ≤ r2 &lt; ... &lt; lk ≤ rk ≤ n; ri - li + 1 = m), in such a way that the value of sum is maximal possible. Help George to cope with the task.
Print an integer in a single line — the maximum possible value of sum.
C
ee3c228cc817536bf6c10ea4508d786f
d138a1b2b469e909ebc5ff68827ff8e7
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation" ]
1411054200
["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0"]
null
PASSED
1,700
standard input
1 second
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
["9", "61"]
#include<stdio.h> #include<stdlib.h> #define ll long long ll dp[5005][5005]; ll sum[5005]; int main() { int n,m,k,i,j; ll x,mx; scanf("%d %d %d",&n,&m,&k); sum[0]=0; //memset(dp,0,sizeof(dp)); for(i=1;i<=n;i++) { scanf("%I64d",&x); sum[i]=sum[i-1]+x; } for(i=0;i<= (n-m) ;i++) { dp[i][0]=sum[i+m]-sum[i]; } for(j=1;j<k;j++) { mx=0; for(i=0;i<=(n-m);i++) { dp[i][j]=dp[i][0]; if(i>=m) mx=mx>dp[i-m][j-1]?mx:dp[i-m][j-1]; dp[i][j]+=mx; } } mx=0; for(i=0;i<= (n-m) ;i++) { mx=mx>dp[i][k-1]?mx:dp[i][k-1]; } printf("%I64d\n",mx); return 0; }
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 &lt; l2 ≤ r2 &lt; ... &lt; lk ≤ rk ≤ n; ri - li + 1 = m), in such a way that the value of sum is maximal possible. Help George to cope with the task.
Print an integer in a single line — the maximum possible value of sum.
C
ee3c228cc817536bf6c10ea4508d786f
1e25b73730cbb42b8c59ba56ea074c71
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation" ]
1411054200
["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0"]
null
PASSED
1,700
standard input
1 second
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
["9", "61"]
#include<stdio.h> #include<stdlib.h> #define ll long long ll dp[5005][2]; ll sum[5005]; ll max(ll a,ll b) { return a>b?a:b; } int main() { int n,m,k,i,j,stat; ll x,mx; scanf("%d %d %d",&n,&m,&k); sum[0]=0; //memset(dp,0,sizeof(dp)); for(i=1;i<=n;i++) { scanf("%I64d",&x); sum[i]=sum[i-1]+x; } stat=0; for(i=m;i<=n;i++) { dp[i][0]=max( sum[i]-sum[i-m],dp[i-1][0] ); } for(j=2;j<=k;j++) { stat=1-stat; for(i=m*j;i<=n;i++) { dp[i][stat]=max( dp[i-m][1-stat]+sum[i]-sum[i-m],dp[i-1][stat] ); } } printf("%I64d\n",dp[n][stat]); return 0; }
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 &lt; l2 ≤ r2 &lt; ... &lt; lk ≤ rk ≤ n; ri - li + 1 = m), in such a way that the value of sum is maximal possible. Help George to cope with the task.
Print an integer in a single line — the maximum possible value of sum.
C
ee3c228cc817536bf6c10ea4508d786f
47ee725889aa42bbb42aee3a8bd244a8
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation" ]
1411054200
["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0"]
null
PASSED
1,700
standard input
1 second
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
["9", "61"]
#include <stdio.h> #include <string.h> #define ll long long #define MAXN 5050 ll dp[MAXN][MAXN], p[MAXN], c[MAXN]; ll imax(ll a, ll b){ return a > b ? a : b; } int main(){ int i, j, n, m, k; while(scanf("%d %d %d", &n, &m, &k) != EOF){ c[0] = 0; for(i = 1; i <= n; i++){ scanf("%d", &p[i]); c[i] = c[i-1] + p[i]; } memset(dp, 0, sizeof(dp)); for(i = 1; i <= k; i++){ for(j = m; j <= n; j++){ dp[i][j] = imax(dp[i-1][j], dp[i-1][j-m] + c[j] - c[j - m]); dp[i][j] = imax(dp[i][j], dp[i][j-1]); } } printf("%I64d\n", dp[k][n]); } return 0; }
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 &lt; l2 ≤ r2 &lt; ... &lt; lk ≤ rk ≤ n; ri - li + 1 = m), in such a way that the value of sum is maximal possible. Help George to cope with the task.
Print an integer in a single line — the maximum possible value of sum.
C
ee3c228cc817536bf6c10ea4508d786f
af2ea1880623c4fe574349431e092f9f
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation" ]
1411054200
["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0"]
null
PASSED
1,700
standard input
1 second
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
["9", "61"]
#include <stdio.h> #include <string.h> #include <limits.h> long long dp[5005][5005]; long long A[5005]; long long pre[5005]; long long max(long long a,long long b) { if(a>b) return a; else return b; } long long rec(long long start,long long int m,long long int n,long long int k) { //when you are at the start of sequence //we have two options //either we leave that element and move forward but keep in mind that the remaining sequence has power to produce solution //m pieces to be searched //suppose we leave element at index start long long len,X=-1,Y=-1; //firs remaning len len=(n-start); if(m*k<=len) { if(dp[start+1][k]==-1) X=rec(start+1,m,n,k); else X=dp[start+1][k]; } //suppose i made a group and i reached start+m len=n-(start+m)+1; if(m*(k-1)<=len && k>=1) { if(dp[start+m][k-1]==-1) Y=pre[start]+rec(start+m,m,n,k-1); else Y=pre[start]+dp[start+m][k-1]; } if(X!=-1 && Y==-1) dp[start][k]=X; else if(X==-1 && Y!=-1) dp[start][k]=Y; else if(X!=-1 && Y!=-1) dp[start][k]=max(X,Y); else dp[start][k]=0; return dp[start][k]; } int main() { long long n,m,k,i,s=0,j; scanf("%I64d %I64d %I64d",&n,&m,&k); memset(dp,-1,sizeof(dp)); //we have to smallest sum subsequence of length (k-n*m) for(i=1;i<=n;i++) scanf("%I64d",&A[i]); for(i=1;i<=n-m+1;i++) { s=0; for(j=i;j<i+m;j++) { s=s+A[j]; } pre[i]=s; } printf("%I64d\n",rec(1,m,n,k)); return 0; }
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 &lt; l2 ≤ r2 &lt; ... &lt; lk ≤ rk ≤ n; ri - li + 1 = m), in such a way that the value of sum is maximal possible. Help George to cope with the task.
Print an integer in a single line — the maximum possible value of sum.
C
ee3c228cc817536bf6c10ea4508d786f
38eda133bf8a44f875380bd05b09aff9
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation" ]
1411054200
["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0"]
null
PASSED
1,700
standard input
1 second
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
["9", "61"]
#include<stdio.h> #include<stdbool.h> long long int max[5001][5001],sum2[5001]; bool yes[5001][5001]; int n,m,k; long long int dp(int start,int k2) { if(k2==0||n-start<m*k2) return 0; if(yes[start][k2]==1) return max[start][k2]; int i; long long int max2,a=dp(start+1,k2),b=sum2[start]+dp(start+m,k2-1); if(a>b) max2=a; else max2=b; yes[start][k2]=1; max[start][k2]=max2; return max2; } int main() { int i,j; scanf("%d %d %d",&n,&m,&k); int a[n]; for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n-m+2;i++) { sum2[i]=0; for(j=i;j<i+m;j++) sum2[i]=sum2[i]+a[j]; } printf("%I64d",dp(0,k)); return 0; }
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 &lt; l2 ≤ r2 &lt; ... &lt; lk ≤ rk ≤ n; ri - li + 1 = m), in such a way that the value of sum is maximal possible. Help George to cope with the task.
Print an integer in a single line — the maximum possible value of sum.
C
ee3c228cc817536bf6c10ea4508d786f
a8598c77b9b3aaa554f1c26f2b79ac42
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation" ]
1411054200
["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0"]
null
PASSED
1,700
standard input
1 second
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
["9", "61"]
#include<stdio.h> #define INF -6e12 typedef long long int LL; int n,m; LL sum[5005]; LL arr[5005]; LL memo[5005][5005]; char calculated[5005][5005]; LL MAX(LL a,LL b) { return a > b ? a : b; } LL dp(int index,int k) { // Meaning that we have crossed the array boundary but we still have some // m sized ranges to consider. if(index > n-m && k > 0) return INF; // All the k ranges have been considered for the sum. No need to recurse further. if(k == 0) return 0; // If the result for this subproblem has already been calculated, then return the result if(calculated[index][k] == 1) return memo[index][k]; LL ans1,ans2; // Do not consider the current range. Move on to the next one ans1=dp(index+1,k); // Consider the current range and recurse on the next non overlapping range. ans2=dp(index+m,k-1) + sum[index]; calculated[index][k]=1; memo[index][k]=MAX(ans1,ans2); return MAX(ans1,ans2); } int main() { int i,k; scanf("%d%d%d",&n,&m,&k); for(i=0;i<n;i++) scanf("%ld",&arr[i]); for(i=0;i<m;i++) sum[0]+=arr[i]; for(i=1;i<=(n-m);i++) { sum[i]=sum[i-1]; sum[i]-= arr[i-1]; sum[i]+= arr[m+i-1]; } printf("%lld\n",dp(0,k)); return 0; }
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 &lt; l2 ≤ r2 &lt; ... &lt; lk ≤ rk ≤ n; ri - li + 1 = m), in such a way that the value of sum is maximal possible. Help George to cope with the task.
Print an integer in a single line — the maximum possible value of sum.
C
ee3c228cc817536bf6c10ea4508d786f
f2bfb12aa5f93768a58405b21e0baa46
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation" ]
1411054200
["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0"]
null
PASSED
1,700
standard input
1 second
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
["9", "61"]
#include<stdio.h> #define LL long long LL sum[5010]; LL dp[5010][5010]; LL max(LL a,LL b) { return a>b?a:b; } int main() { int n,k,m,i,num,j; scanf("%d %d %d",&n,&m,&k); sum[0]=0; for(i=1;i<=n;++i) { scanf("%d",&num); sum[i]=sum[i-1]+num; } for(i=m;i<=n;++i) { for(j=1;j<=k;++j) { dp[i][j]=max(dp[i-1][j],dp[i-m][j-1]+sum[i]-sum[i-m]); } } printf("%I64d",dp[n][k]); return 0; }
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 &lt; l2 ≤ r2 &lt; ... &lt; lk ≤ rk ≤ n; ri - li + 1 = m), in such a way that the value of sum is maximal possible. Help George to cope with the task.
Print an integer in a single line — the maximum possible value of sum.
C
ee3c228cc817536bf6c10ea4508d786f
3b5d73412b0af8def403d0968b063a1d
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation" ]
1411054200
["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0"]
null
PASSED
1,700
standard input
1 second
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
["9", "61"]
#include<stdio.h> int main() { long long int n,i,j,k,h,t,m; long long int prev[5001],cur[5001]; long long int b[5001],sum[5001],count; scanf("%lld %lld %lld",&n,&m,&k); for(i=0;i<n;i++) scanf("%lld",&b[i]); for(i=0;i<n;i++) prev[i]=0; count=0; if(n==1) printf("%lld\n",b[0]); else { for(i=0;i<m-1;i++) { sum[i]=0; count+=b[i]; } sum[i]=count+b[i]; t=0; for(j=i+1;j<n;j++) { sum[j]=sum[j-1]+b[j]; sum[j]-=b[t]; t++; } for(i=1;i<=k;i++) { for(j=0;j<n;j++) { if(j==0) h=0; else h=cur[j-1]; if(j-m==-1) t=sum[j]; else if(j-m>=0) t=prev[j-m]+sum[j]; else t=0; h=(h>t)?h:t; cur[j]=h; } for(j=0;j<n;j++) prev[j]=cur[j]; /* for(j=0;j<n;j++) printf("%lld ",cur[j]); printf("\n"); */ } printf("%lld\n",cur[n-1]); } return 0; }
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 &lt; l2 ≤ r2 &lt; ... &lt; lk ≤ rk ≤ n; ri - li + 1 = m), in such a way that the value of sum is maximal possible. Help George to cope with the task.
Print an integer in a single line — the maximum possible value of sum.
C
ee3c228cc817536bf6c10ea4508d786f
f533afa7b363ef5fd9ed21cbe334ca60
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation" ]
1411054200
["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0"]
null
PASSED
1,700
standard input
1 second
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
["9", "61"]
#include <stdio.h> #include <stdlib.h> int main() { int no,m,k,i,j; scanf("%d %d %d",&no,&m,&k); int a[5002]={0}; long long dp[5001][5001]={0}; long long sum[5002]={0}; for(i=1;i<=no;i++) scanf("%d",&a[i]); long long sum1=0; j=1; for(i=no;j<=m;i--) {sum1=sum1+a[i];j++;}///last m ka sum sum[no-m+1]=sum1; for(i=no-m;i>=1;i--) { sum1+=a[i]; sum1-=a[i+m]; sum[i]=sum1; } for(i=1;i<=no;i++) dp[1][i]=sum[i]; for(i=no-1;i>=1;i--) if(dp[1][i]<dp[1][i+1]) dp[1][i]=dp[1][i+1]; for(i=2;i<=k;i++) { j=no+1-(m*i); for(j=j;j>=1;j--) { dp[i][j]+=sum[j]+dp[i-1][j+m]; } for(j=no-1;j>=1;j--) if(dp[i][j]<dp[i][j+1])dp[i][j]=dp[i][j+1]; } /*for(i=1;i<=k;i++) {for(j=1;j<=no;j++)printf("%d ",dp[i][j]);printf("\n"); }*/ printf("%lld\n",dp[k][1]); return 0; } /* 13 3 3 5 5 6 10 10 8 2 4 10 3 6 2 1 if(sum[i]<sum[i+1])sum[i]=sum[i+1];*/
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 &lt; l2 ≤ r2 &lt; ... &lt; lk ≤ rk ≤ n; ri - li + 1 = m), in such a way that the value of sum is maximal possible. Help George to cope with the task.
Print an integer in a single line — the maximum possible value of sum.
C
ee3c228cc817536bf6c10ea4508d786f
895e252cd5b6922508d23af8d435ba1a
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation" ]
1411054200
["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0"]
null
PASSED
1,700
standard input
1 second
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
["9", "61"]
#include<stdio.h> long long int array[5001][5001]; long long int max(long long int a,long long int b) { if(a>b) return a; else return b; } long long int railway(long long int b[],long long int index,long long int k,long long int m) { if(k==0|| index<0) return 0 ; if(array[index][k]!=-1) return array[index][k]; return array[index][k]=max(b[index]+railway(b,index-m,k-1,m),railway(b,index-1,k,m)); } int main() { long long int n,m,k,i,j; for(i=0;i<5001;i++) for(j=0;j<5001;j++) array[i][j]=-1; scanf("%I64d%I64d%I64d",&n,&m,&k); long long int a[n]; for(i=0;i<n;i++) { scanf("%I64d",&a[i]); } long long int b[n-m+1]; for(i=0;i<n-m+1;i++) {b[i]=0; for(j=i;j<m+i;j++) b[i]+=a[j]; } // for(i=0;i<n-m+1;i++) // printf("%d ",b[i]); long long int answer=railway(b,n-m,k,m); printf("%I64d\n",answer); return 0; }
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 &lt; l2 ≤ r2 &lt; ... &lt; lk ≤ rk ≤ n; ri - li + 1 = m), in such a way that the value of sum is maximal possible. Help George to cope with the task.
Print an integer in a single line — the maximum possible value of sum.
C
ee3c228cc817536bf6c10ea4508d786f
1fbcd971de226279345a7fdab17f02be
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation" ]
1411054200
["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0"]
null
PASSED
1,700
standard input
1 second
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
["9", "61"]
#include <stdio.h> #include <stdlib.h> #define max(a,b) (a>b?a:b) int main(){ long temp[5010]; long long a[5010], arr[5010][5010]; int n,m,k,i,j; while(scanf("%d%d%d" , &n,&m,&k) != EOF){ int ans = 0; a[0] = 0; for(i = 1; i <= n; i++) { scanf("%ld", &temp[i]); a[i] = a[i - 1] + temp[i]; } for(i = m; i <= n; i++) { for(j = k; j >= 1; j--) { arr[i][j] = max(arr[i - 1][j], arr[i - m][j - 1] + a[i] - a[i - m]); } } printf("%I64d\n", arr[n][k]); } return 0; }
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 &lt; l2 ≤ r2 &lt; ... &lt; lk ≤ rk ≤ n; ri - li + 1 = m), in such a way that the value of sum is maximal possible. Help George to cope with the task.
Print an integer in a single line — the maximum possible value of sum.
C
ee3c228cc817536bf6c10ea4508d786f
b10bdb287cee3d59c5345c54c437b69a
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation" ]
1411054200
["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0"]
null
PASSED
1,700
standard input
1 second
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
["9", "61"]
#include <stdio.h> #include <stdlib.h> #define max(a,b) (a>b?a:b) int main(){ long a[5010]; long long s[5010], dp[5010][5010]; int n,m,k,i,j; while(scanf("%d%d%d" , &n,&m,&k) != EOF){ int ans = 0; s[0] = 0; for(i = 1; i <= n; i++) { scanf("%ld", &a[i]); s[i] = s[i - 1] + a[i]; } for(i = m; i <= n; i++) { for(j = k; j >= 1; j--) { dp[i][j] = max(dp[i - 1][j], dp[i - m][j - 1] + s[i] - s[i - m]); } } printf("%I64d\n", dp[n][k]); } return 0; /* } long long max(long long num1, long long num2) { long long result; if (num1 > num2) result = num1; else result = num2; return result; */ }
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 &lt; l2 ≤ r2 &lt; ... &lt; lk ≤ rk ≤ n; ri - li + 1 = m), in such a way that the value of sum is maximal possible. Help George to cope with the task.
Print an integer in a single line — the maximum possible value of sum.
C
ee3c228cc817536bf6c10ea4508d786f
ba4de93e99194d06e2008ad2d04d13f0
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation" ]
1411054200
["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0"]
null
PASSED
1,700
standard input
1 second
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
["9", "61"]
#include <stdio.h> #include <stdlib.h> #include <string.h> long long n,m,k; long long sum[5010]; long long save[5010][5010]; long long ans = 0; long long max(long long a, long long b) { return (a>b)?a:b; } long long bf(long long l, long long ind) { long long r = m - 1 + l; if (ind > k) return 0; if (r > (n-k+ind)) return 0; if (save[l][ind] != -1) return save[l][ind]; return save[l][ind] = max(bf(l+1, ind), sum[r] - sum[l-1] + bf(r+1,ind+1)); } int main() { //freopen("test.in", "r", stdin); memset(sum,0,sizeof(sum)); memset(save,-1,sizeof(save)); scanf("%I64d%I64d%I64d",&n,&m,&k); int i; for(i=1;i<=n;++i) { long long aux; scanf("%I64d", &aux); sum[i] = sum[i-1] + aux; } //bf(1); printf("%I64d\n", bf(1,1)); return 0; }
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 &lt; l2 ≤ r2 &lt; ... &lt; lk ≤ rk ≤ n; ri - li + 1 = m), in such a way that the value of sum is maximal possible. Help George to cope with the task.
Print an integer in a single line — the maximum possible value of sum.
C
ee3c228cc817536bf6c10ea4508d786f
eb01596e7c9017455a0781fe1cdf6f11
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation" ]
1411054200
["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0"]
null
PASSED
1,700
standard input
1 second
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
["9", "61"]
#include <stdio.h> #define max(x, y) ((x)>(y)?(x):(y)) long long P[5001]; long long Dp[5001][5001]; long long Ans; int main() { int N, M, K, i, j; scanf("%d %d %d", &N, &M, &K); for(i=1; i<=N; ++i) { scanf("%d", &P[i]); P[i] += P[i-1]; } for(i=1; i<=N; ++i) { for(j=1; j<=K; ++j) { if(i < M) { Dp[i][j] = Dp[i-1][j]; } else { Dp[i][j] = max(Dp[i-1][j], Dp[i-M][j-1]+P[i]-P[i-M]); } Ans = max(Ans, Dp[i][j]); } } printf("%I64d\n", Ans); return 0; }
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work.Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2, r2], ..., [lk, rk] (1 ≤ l1 ≤ r1 &lt; l2 ≤ r2 &lt; ... &lt; lk ≤ rk ≤ n; ri - li + 1 = m), in such a way that the value of sum is maximal possible. Help George to cope with the task.
Print an integer in a single line — the maximum possible value of sum.
C
ee3c228cc817536bf6c10ea4508d786f
45bf1f118b582686b9e49ae3dffeab33
GNU C
standard output
256 megabytes
train_000.jsonl
[ "dp", "implementation" ]
1411054200
["5 2 1\n1 2 3 4 5", "7 1 3\n2 10 7 18 5 33 0"]
null
PASSED
1,700
standard input
1 second
The first line contains three integers n, m and k (1 ≤ (m × k) ≤ n ≤ 5000). The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ 109).
["9", "61"]
/* * 1.这个程序做到的事情 * 2.这个程序遇到的困难 * 我改进的一个方向就是! * 3.接下来要做的事情 */ #include<stdio.h> #define N 5002//我没有注意,把这一行注视了,用了下一行! //#define N 502 long long max2(long long a,long long b){ if(a>b)return a; else return b; } int main() { int n,m,k; int p[N]; scanf("%d%d%d",&n,&m,&k); /* printf("n=%d\n",n); printf("m=%d\n",m); printf("k=%d\n",k); printf("%d个元素,%d个连续值,%d个片段\n",n,m,k); */ int i; for(i=0;i<n;i++){ scanf("%d",&p[i]); } /* for(i=0;i<n;i++){ printf(" %d",p[i]); } printf("\n"); */ long long m_sum[N]; long long tmp=0; long long sum[N][N]; for(i=0;i<m;i++){ tmp+=(long long)p[i]; } m_sum[0]=tmp; //sum1[i]=从i开头的m个连续数相加的最大值! //这里需要逆向处理! //先正向处理获得我们想要的数据! //再逆向处理得到我们想要的基础数据! for(i=m;i<n;i++){ tmp+=(long long)p[i]; tmp-=(long long)p[i-m]; m_sum[i-m+1]=tmp; } /* for(i=0;i<=n-m;i++){ printf("%d:%lld ",i,m_sum[i]); } printf("\n"); */ sum[1][n-m]=m_sum[n-m]; for(i=n-m-1;i>=0;i--){ sum[1][i]=max2(m_sum[i],sum[1][i+1]); } /* for(i=0;i<=n-m;i++){ printf("%d:%lld ",i,sum[1][i]); } printf("\n"); */ /* for(i=0;i<=n-m;i++){ //printf("从%d开始,1个%d连续值相加之和等于%lld\n",i,m,sum[1][i]); printf("(1,%d)=%lld ",i,sum[1][i]); } printf("\n"); */ //最后一个是:i-m+1,i=n-1 n-1-m+1 //printf("=======\n"); //0 m-1 //1 m //2 m+1 //... //n-m n-1 //i<=n-m //n-m+1 n //i<n-m+1 //m+x=n,x=n-m //sumk[i][j]=从j开头的i个m个连续数相加之和的最大数 int h; for(h=1;h<k;h++){ //sum1+sumk=sumk+1 //m+k*m=m*(k+1) //0 m*k-1 //1 m*k //2 m*k+1 //n-m*k n-1 //i<=n-m*k //n-m*k+1 n //i<n-m*k+1,这是一个细节错误! // m*k+x=n,x=n-m*k // 我们的第一个限制就是我们要求,h+1个m连续数相加之和的最大数 // 起点从0开始 // 最大起点是n-m*(h+1)+1,大于这个起点,起码数量不够! for(i=0;i<=n-m*(h+1);i++){ //i to i+m-1 产生一个m连续值 //gap //i+m-1+gap to end 产生h个m连续值。 //总共合起来是h+1个m连续值! // //h个m连续值的最大起点是n-m*h //i+m-1+gap<=n-m*h //gap<=n-m*h-(i+m-1) //现实m个连续值 + gap + h个m个连续值的综合体 sum[h+1][i]=m_sum[i]+sum[h][i+m]; } //sum[h+1][n-m*(h+1)]保持不变! for(i=n-m*(h+1)-1;i>=0;i--){ sum[h+1][i]=max2(sum[h+1][i],sum[h+1][i+1]); } //这个预处理的作用就是从某个起点开始,我们就得到了最优解! //这里还需要再做一次处理 /* for(i=0;i<=n-m*(h+1);i++){ printf("(%d,%d)=%lld ",h+1,i,sum[h+1][i]); } printf("\n"); */ } printf("%lld\n",sum[k][0]); return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
f508c4511322afd9151122cdfe559da5
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include<stdio.h> #include<string.h> int main() { int n; scanf("%d", &n); int i, j; char s[200005]; scanf("%s", s); int ans[50004]; int m; int l; char t[200005]; int count[30][200005]; for (i = 0; i < 30; i++) count[i][0] = 0; int min, max, mid; int x; for (i = 0; i < n; i++) { for (j = 0; j < 30; j++) { if (s[i] - 'a' == j) count[j][i + 1] = count[j][i] + 1; else count[j][i + 1] = count[j][i]; } } scanf("%d", &m); int countt[30]; for (i = 0; i < m; i++) { scanf("%s", t); for (j = 0; j < 30; j++) countt[j] = 0; l = strlen(t); for (j = 0; j < l; j++) countt[t[j] - 'a']++; min = 0; max = n; while (max - min > 1) { mid = (max + min) / 2; x = 0; for (j = 0; j < 30; j++) if (countt[j] > count[j][mid]) x++; if (x == 0) max = mid; else min = mid; } ans[i] = max; } for (i = 0; i < m; i++) printf("%d\n", ans[i]); return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
5b9e1197859d9f82fb60f07a21b229a6
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include<stdio.h> #include<string.h> int test[126]; void clear() { int i; for(i=97;i<=125;i++) test[i]=0; } int main() { int n,i,m,j,temp,max=0,len,k,cnt[126]={}; scanf("%d",&n); char str[n+2],name[n+2]; int value[n+2][125]; scanf("%s",str); for(i=0;str[i]!='\0';i++) { value[cnt[str[i]]][str[i]]=i; cnt[str[i]]++; } scanf("%d",&m); for(i=0;i<m;i++) { scanf("%s",name); max=0; for(j=0;name[j]!='\0';j++) { temp=value[test[name[j]]][name[j]]; test[name[j]]++; if(temp>max) max=temp; } printf("%d\n",max+1); clear(); } return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
efc163911bda48963cbc34688f2ed1cb
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
//practice with dukkha #include<stdio.h> #include<string.h> #define mod 1000000007 int com[26][2000000]; int comp[26]; int main() { int a; scanf("%d",&a); char array[a]; scanf("%s",array); for(int i=0;i<a;i++) { com[array[i]-'a'][comp[array[i]-'a']]=i; comp[array[i]-'a']++; } int b; scanf("%d",&b); while(b--) { char cr[200000]; scanf("%s",cr); int l=strlen(cr); int count=0; int arr[26]; for(int i=0;i<26;i++) arr[i]=0; for(int i=0;i<l;i++) arr[cr[i]-'a']++; int max=-1,idx=-1; for(int i=0;i<26;i++) { if(arr[i]==0) continue; int temp=arr[i]; int idx1=com[i][temp-1]; if(idx1>max) max=idx1; } max++; printf("%d\n",max); } return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
b610c91ecfb339334f5b65604dce7437
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include <stdio.h> #include <string.h> #include <stdlib.h> #define MAX_LEN 200001 int main() { int shoplen; scanf("%d", &shoplen); char shop[shoplen + 1]; scanf("%s", shop); int *count = calloc(26, sizeof(int)); int **posmat = calloc(26, sizeof(int*)) ; int sum = 0 ; posmat[0] = calloc(shoplen, sizeof(int)) ; for(int i = 0 ; i < shoplen ; i++) { count[shop[i] - 'a']++ ; } for(int i = 0 ; i < 26 ; i++) { posmat[i] = posmat[0] + sum ; sum += count[i] ; } free(count) ; count = calloc(26, sizeof(int)) ; for (int i = 0; i < shoplen; i++) { posmat[shop[i] - 'a'][count[shop[i] - 'a']] = i + 1; count[shop[i] - 'a']++; } int nof; scanf("%d", &nof); for (int f = 0; f < nof; f++) { char name[MAX_LEN]; int len; int max = 0; scanf("%s", name); len = strlen(name); int *charcount = calloc(26, sizeof(int)); for (int i = 0; i < len; i++) { charcount[name[i] - 'a']++; } for (int i = 0; i < 26; i++) { if (charcount[i]) { if (posmat[i][charcount[i] - 1] > max) max = posmat[i][charcount[i] - 1]; } } free(charcount) ; printf("%d\n", max); } return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
825380b46bd5f0570ce280621f2da03f
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include <stdio.h> #include <string.h> #define MAX_LEN 200001 int main() { int shoplen; scanf("%d", &shoplen); char shop[shoplen + 1]; scanf("%s", shop); // int posmat[26][shoplen]; int shopcount[26]; int *count = calloc(26, sizeof(int)); int **posmat = calloc(26, sizeof(int*)) ; int sum = 0 ; posmat[0] = calloc(shoplen, sizeof(int)) ; for(int i = 0 ; i < shoplen ; i++) { count[shop[i] - 'a']++ ; } for(int i = 0 ; i < 26 ; i++) { posmat[i] = posmat[0] + sum ; sum += count[i] ; } for (int x = 0; x < 26; x++) { // for (int y = 0; y < shoplen; y++) { // posmat[x][y] = 0; // } shopcount[x] = 0; } for (int i = 0; i < shoplen; i++) { char c = shop[i]; posmat[c - 'a'][shopcount[c - 'a']] = i + 1; shopcount[c - 'a']++; } /*for(int x = 0 ; x < 26 ; x++) { for(int y = 0 ; y < shoplen ; y++) { printf("%d",posmat[x][y]) ;// = 0 ; } printf("\n") ; }*/ int nof; scanf("%d", &nof); for (int f = 0; f < nof; f++) { char name[MAX_LEN]; int len; int max = 0; scanf("%s", name); len = strlen(name); int charcount[26]; for (int i = 0; i < 26; i++) { charcount[i] = 0; } for (int i = 0; i < len; i++) { charcount[name[i] - 'a']++; } for (int i = 0; i < 26; i++) { if (charcount[i]) { if (posmat[i][charcount[i] - 1] > max) max = posmat[i][charcount[i] - 1]; } } printf("%d\n", max); } return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
45edc830e4ee6369259bfad0da40b21a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include <stdio.h> // #include <stdlib.h> #include <string.h> #define MAX_LEN 200001 int main() { int shoplen; scanf("%d", &shoplen); char shop[shoplen + 1]; scanf("%s", shop); int posmat[26][shoplen]; int shopcount[26]; for (int x = 0; x < 26; x++) { for (int y = 0; y < shoplen; y++) { posmat[x][y] = 0; } shopcount[x] = 0; } for (int i = 0; i < shoplen; i++) { char c = shop[i]; posmat[c - 'a'][shopcount[c - 'a']] = i + 1; shopcount[c - 'a']++; } /*for(int x = 0 ; x < 26 ; x++) { for(int y = 0 ; y < shoplen ; y++) { printf("%d",posmat[x][y]) ;// = 0 ; } printf("\n") ; }*/ int nof; scanf("%d", &nof); for (int f = 0; f < nof; f++) { char name[MAX_LEN]; int len; int max = 0; scanf("%s", name); len = strlen(name); int charcount[26]; for (int i = 0; i < 26; i++) { charcount[i] = 0; } for (int i = 0; i < len; i++) { charcount[name[i] - 'a']++; } for (int i = 0; i < 26; i++) { if (charcount[i]) { if (posmat[i][charcount[i] - 1] > max) max = posmat[i][charcount[i] - 1]; } } printf("%d\n", max); } return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
f1ad4bb928236d44b507fccee0ffe929
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include <stdio.h> #include <string.h> int chars_s[26][200002]; char s[200001]; char t[200001]; int main() { int n; scanf("%d", &n); scanf("%s", s); int chars_s_index[26]; for(int i = 0; i < 26; i++) { chars_s_index[i] = 0; chars_s[i][0] = 0; } int len_s = n; for(int i = 0; i < len_s; i++) chars_s[s[i] - 'a'][++chars_s_index[s[i] - 'a']] = i + 1; int m; scanf("%d", &m); for(int i = 0; i < m; i++) { scanf("%s", t); int len_t = strlen(t); int chars_t[26]; for(int j = 0; j < 26; j++) chars_t[j] = 0; for(int j = 0; j < len_t; j++) chars_t[t[j] - 'a']++; int max = 0; for(int j = 0; j < 26; j++) max = chars_s[j][chars_t[j]] > max ? chars_s[j][chars_t[j]] : max; printf("%d\n", max); } }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
c3ec56d4d31fa61659c3ef0f328deea5
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include<stdio.h> int main(){ int n,n1,i,count=0,j,k,k1,a[26]={0},max=0,l,c[26]={0}; scanf("%d",&n); getchar(); char s[n]; gets(s); int b[26][200001]={0}; for(k=0;s[k]!=NULL;k++){ a[s[k]-97]++; b[s[k]-97][a[s[k]-97]-1]=(k+1); } scanf("%d",&n1); getchar(); char s1[300000]; for(j=0;j<n1;j++){ gets(s1); for(k=0;s1[k]!=NULL;k++) c[s1[k]-97]++; for(k=0;k<26;k++){ if(c[k]>0){ if(b[k][c[k]-1]>max) max=b[k][c[k]-1]; } c[k]=0; } printf("%d\n",max); max=0; } return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
05c9bb27b7a291fcfae5fb5a375d3d79
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include<stdio.h> int main(){ int n,n1,i,count=0,j,k,k1,a[26]={0},max=0,l,c[26]={0}; scanf("%d",&n); getchar(); char s[n]; gets(s); int b[26][200001]={0}; for(k=0;s[k]!=NULL;k++){ a[s[k]-97]++; b[s[k]-97][a[s[k]-97]-1]=(k+1); } scanf("%d",&n1); getchar(); char s1[300000]; for(j=0;j<n1;j++){ gets(s1); for(k=0;s1[k]!=NULL;k++) c[s1[k]-97]++; for(k=0;k<26;k++){ if(c[k]>0){ if(b[k][c[k]-1]>max) max=b[k][c[k]-1]; } c[k]=0; } printf("%d\n",max); max=0; } return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
13410dbca9ddc1ed94bcfebe0d11b203
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include <stdio.h> int n,q; char s[200010],t[200010]; int cnts[200010][30],cntt[30]; short check(int x) { int i; for(i=0;i<26;i++) if(cnts[x][i] < cntt[i]) return 0; return 1; } int work() { int i,head = 1,tail = n,mid; for(i=0;i<26;i++) cntt[i] = 0; for(i=1;t[i];i++) cntt[t[i]-'a']++; while(head < tail) { mid = (head+tail) >> 1; if(check(mid)) tail = mid; else head = mid+1; } return head; } int main() { int i,j; scanf("%d%s%d",&n,s+1,&q); for(i=1;i<=n;i++) { cnts[i][s[i]-'a']++; for(j=0;j<26;j++) cnts[i][j] += cnts[i-1][j]; } while(q--) { scanf("%s",t+1); printf("%d\n",work()); } return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
463ecef515d31342d4c667564d999476
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
/* practice with Dukkha */ #include <stdio.h> #include <string.h> #define N 200000 #define A 26 int main() { static char aa[N + 1], bb[N + 1]; static int kk[N][A], ll[A]; int n, q, i, a; scanf("%d%s", &n, aa); for (i = 0; i < n; i++) for (a = 0; a < A; a++) kk[i][a] = (i > 0 ? kk[i - 1][a] : 0) + (aa[i] == a + 'a'); scanf("%d", &q); while (q--) { int m, j, lower, upper; scanf("%s", bb); m = strlen(bb); memset(ll, 0, sizeof ll); for (j = 0; j < m; j++) ll[bb[j] - 'a']++; lower = 0, upper = n; while (upper - lower > 1) { int n_ = (lower + upper) / 2, good = 1; for (a = 0; a < A; a++) if (kk[n_ - 1][a] < ll[a]) { good = 0; break; } if (good) upper = n_; else lower = n_; } printf("%d\n", upper); } return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
ebe7c1d39441b9022dbcb6f690719aba
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
/* Coached by rainboy */ #include <stdio.h> #include <string.h> #define N 200000 int main() { static char s[N + 1]; static int kk[N][26], ll[26]; int n, q, i; scanf("%d%s%d", &n, s, &q); for (i = 0; i < n; i++) { ll[s[i] - 'a']++; memcpy(kk[i], ll, 26 * sizeof *ll); } while (q-- > 0) { static char t[N + 1]; int m, j, c, lower, upper, yes; scanf("%s", t); m = strlen(t); memset(ll, 0, 26 * sizeof *ll); for (j = 0; j < m; j++) ll[t[j] - 'a']++; lower = -1, upper = n - 1; while (upper - lower > 1) { i = (lower + upper) / 2; yes = 1; for (c = 0; c < 26; c++) if (ll[c] > kk[i][c]) { yes = 0; break; } if (yes) upper = i; else lower = i; } printf("%d\n", upper + 1); } return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
23ef3dc69aa9673b878598760aeb458d
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> char s[200005]; int cnt[26][200005] = { 0 }; char fs[200005]; int fcnt[26] = { 0 }; #define MAX(a,b) ((a)>(b)?(a):(b)) int main() { int len; scanf("%d", &len); scanf("%s", s); for (int i = 0; i < len; i++) { cnt[s[i] - 'a'][i]++; //转移 for (int c = 0; c < 26; c++) { cnt[c][i + 1] = cnt[c][i]; } } int m; scanf("%d", &m); int bOK = 0; for (int i = 0; i < m; i++)//枚举好友 { scanf("%s", fs); int flen = strlen(fs); //初始化数组 for (int c = 0; c < 26; c++) { fcnt[c] = 0; } for (int j = 0; j < flen; j++)//统计字符串各个字符 { fcnt[fs[j] - 'a']++; } int ans = 0; for (int x = 0; x < 26; x++) { //进行二分 int l = 0, r = len, m; while (l!=r) { m = (l + r) >> 1; if (cnt[x][m] < fcnt[x]) { l = m+1; } else// (cnt[x][m] >= fcnt[x]) { r = m; } } ans = MAX(l + 1, ans); } printf("%d\n", ans); //for (int k = flen -1; k < len; k++) //{ // //枚举主串长度 // bOK = 1; // for (int x = 0; x < 26; x++) // { // if (cnt[x][k] < fcnt[x]) // { // //不满足 // bOK = 0; // break; // } // } // if (bOK) // { // printf("%d\n", k+1); // break; // } //} // } return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
5774bc5885ca96fe600d295f174c8435
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include <stdio.h> #include <string.h> #define N 200000 int aa[28],bb[28]; int ss[28][N]; char s2[N]; int main(){ int n,a; char x; scanf("%d",&n); char c=getchar(); for(int i=0;i<n;i++){ scanf("%c",&x); a=(int) x-97; aa[a]++; ss[a][aa[a]]=i; } int m; scanf("%d",&m); c=getchar(); while(m--){ for(int i=0;i<28;i++){ bb[i]=0; } int max=0,l; while(1){ scanf("%c",&x); if(x!=10){ l=(int) x-97; bb[l]++; if(max<ss[l][bb[l]]) max=ss[l][bb[l]]; } else break; } //memset(s2,0,strlen(s2)); //scanf("%s",&s2); printf("%d\n",max+1); } }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
7ba5d28a40a6f941df45497bc513dabc
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include <stdio.h> #include <stdlib.h> #include <string.h> long long m, k, l, t, i, j, k, a[30], c[30][300000], d, x, y, b, g, w, e; char s[1000000]; int war(const void* aa, const void* bb) { return(*(long long*)aa-*(long long*)bb); } /* long long bins(long long p, long long k, long long s) { if(a[(p+k)/2]>=s && a[(p+k)/2-1]<s)return((p+k)/2); if(a[(p+k)/2]<s)return(bins((p+k)/2+1,k,s)); return(bins(p,(p+k)/2-1,s)); }*/ int main() { scanf("%I64d%s%I64d", &l, s, &t); for(i=0; i<l; i++) { a[s[i]-'a']++; c[s[i]-'a'][a[s[i]-'a']]=i+1; } for(y=0; y<t; y++) { scanf("%s", s); l=strlen(s); m=0; for(i=0; i<30; i++) { a[i]=0; } for(i=0; i<l; i++) { a[s[i]-'a']++; x=c[s[i]-'a'][a[s[i]-'a']]; if(x>m)m=x; } printf("%I64d\n", m); } return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
3da4467bee358c5f5555bdd619457bb9
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include <stdio.h> #include <string.h> int chars_s[26][200002]; char s[200001]; char t[200001]; int main() { int n; scanf("%d", &n); scanf("%s", s); int chars_s_index[26]; for(int i = 0; i < 26; i++) { chars_s_index[i] = 0; chars_s[i][0] = 0; } int len_s = n; for(int i = 0; i < len_s; i++) chars_s[s[i] - 'a'][++chars_s_index[s[i] - 'a']] = i + 1; int m; scanf("%d", &m); for(int i = 0; i < m; i++) { scanf("%s", t); int len_t = strlen(t); int chars_t[26]; for(int j = 0; j < 26; j++) chars_t[j] = 0; for(int j = 0; j < len_t; j++) chars_t[t[j] - 'a']++; int max = 0; for(int j = 0; j < 26; j++) max = chars_s[j][chars_t[j]] > max ? chars_s[j][chars_t[j]] : max; printf("%d\n", max); } }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
299666a28105941ee13bda687ff7f8d5
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include<stdio.h> #include<stdlib.h> #include<stdint.h> #include<inttypes.h> typedef int64_t i64; typedef int32_t i32; static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}} static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;} #define ALLOC(size,type) ((type*)calloc((size),sizeof(type))) #define POS(i, j) ((i) * f + (j)) void run (void) { i32 n = read_int(); char *s = ALLOC (n + 1, char); scanf ("%s", s); const i32 f = 26; i32 *cnt = ALLOC (f * (n + 1), i32); for (i32 i = 0; i < n; ++i) { i32 k = s[i] - 'a'; cnt[POS(i, k)] = 1; } for (i32 i = n - 1; i >= 0; --i) { for (i32 j = 0; j < f; ++j) { cnt[POS(i, j)] += cnt[POS(i + 1, j)]; } } i32 m = read_int(); char *t = ALLOC (200000 + 1, char); while (m--) { scanf ("%s", t); i32 c[26]; for (i32 i = 0; i < f; ++i) { c[i] = 0; } for (i32 i = 0; t[i] != '\0'; ++i) { c[t[i] - 'a']++; } i32 l = 0; i32 r = n; while (r - l > 1) { i32 mid = (l + r) / 2; i32 ok = 1; for (i32 i = 0; i < f; ++i) { if (cnt[POS(0, i)] - cnt[POS(mid, i)] < c[i]) { ok = 0; } } if (ok) { r = mid; } else { l = mid; } } print_int (r); puts (""); } } int main (void) { run (); return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
58641df38b0cae477721aa4c695567d5
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include<stdio.h> #include<stdlib.h> #include<string.h> #define N 200002 int main(){ int n; scanf("%d",&n); char s[N]; scanf("%s",s); int ns=strlen(s); //printf("s=%s\n",s); //printf("ns=%d\n",ns); int scount[26]; int i,j; for(i=0;i<26;i++){ scount[i]=0; } for(i=0;i<ns;i++){ scount[s[i]-'a']++; } /* for(i=0;i<26;i++){ if(i%7==0)printf("\n"); printf(" %c:%d",i+'a',scount[i]); } printf("\n"); */ int *sposition[26]; for(i=0;i<26;i++){ sposition[i]=(int *)malloc((scount[i]+1)*sizeof(int)); if(sposition[i]==NULL){ printf("没有分配到内存\n"); exit(1); } } for(i=0;i<26;i++){ for(j=0;j<=scount[i];j++){ sposition[i][j]=-1; } } int tmp[26]; for(i=0;i<26;i++){ tmp[i]=0; } for(i=0;i<ns;i++){ tmp[s[i]-'a']++; sposition[s[i]-'a'][tmp[s[i]-'a']]=i; } /* for(i=0;i<26;i++){ printf("%c:",i+'a'); for(j=0;j<=scount[i];j++){ printf(" %d",sposition[i][j]); } printf("\n"); } */ int m; scanf("%d",&m); getchar(); int tcount[26]; while(m--){ for(i=0;i<26;i++){ tcount[i]=0; } int c=getchar(); while(c!='\n'){ tcount[c-'a']++; c=getchar(); } int answer=0; for(i=0;i<26;i++){ if(sposition[i][tcount[i]]>answer){ answer=sposition[i][tcount[i]]; } } printf("%d\n",answer+1); } for(i=0;i<26;i++){ free(sposition[i]); } return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
c39a3e0a6066303c930bfff35df6dff9
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include<stdio.h> #include<string.h> #include <stdlib.h> #include <conio.h> #define debug printf("SUSU\n") int latter[26][300000]; int main() { int n,m,i,j; char input[300000]; int cnt[300000]={}; char a; scanf("%d ",&n); for(i=0;i<n;i++) { scanf("%c",&a); latter[a-'a'][cnt[a-'a']++]=i; } scanf("%d ",&m); int ans; for(i=0;i<m;i++) { int co[30000]={}; scanf("%s",input); int l=strlen(input); ans=-1; for(j=0;j<l;j++) { if((latter[input[j]-'a'][co[input[j]-'a']]+1)>ans) { ans=latter[input[j]-'a'][co[input[j]-'a']]+1 ; } co[input[j]-'a']++; } printf("%d\n",ans); } return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
eec2cdabcd5d5d0ccc120da9d2b9002a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include<stdio.h> #include<string.h> int e[27][200009]; int main() { int n,m,i,j,k,f[30]={},count,g,h[30]={},l,z; char c[200009],d[20009]; scanf("%d",&n); scanf("%s",&c); getchar(); for(i=0;i<n;i++){ g=c[i]-96; h[g]++; e[g][h[g]]=i; } scanf("%d",&m); while(m--){ l=0; z=0; scanf("%s",&d); getchar(); k=strlen(d); for(i=0;i<k;i++){ j=d[i]-96; f[j]++; l=e[j][f[j]]; if(l>z) z=l; } printf("%d\n",z+1); for(i=0;i<=26;i++) f[i]=0; } }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
1b64535ababc7a4820c3f702cd033805
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include<stdio.h> #include<string.h> typedef long long int ll; int max(ll x,ll y) { return x>y?x:y; } int main() { ll n,i; char s[1000000]; scanf("%lld",&n); scanf("%s",s); ll arr[26][1000000]; ll ind[26]; for (i=0;i<26;i++) ind[i]=0; for (i=0;i<n;i++) { arr[s[i]-'a'][ind[s[i]-'a']]=i+1; ind[s[i]-'a']++; } ll t; scanf("%lld",&t); while(t--) { char ss[1000000]; scanf("%s",ss); ll cnt[26]; for(i=0;i<26;i++) cnt[i]=0; ll len; len=strlen(ss); for(i=0;i<len;i++) cnt[ss[i]-'a']++; ll ans=-1; for(i=0;i<26;i++) { if (cnt[i]>0) ans=max(ans,arr[i][cnt[i]-1]); } printf("%lld\n",ans); } return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
895261178cd57a770ca6a5fee4653645
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include<stdio.h> int main(){ int n,n1,i,count=0,j,k,k1,a[26]={0},max=0,l,c[26]={0}; scanf("%d",&n); getchar(); char s[n]; gets(s); int b[26][200001]={0}; for(k=0;s[k]!=NULL;k++){ a[s[k]-97]++; b[s[k]-97][a[s[k]-97]-1]=(k+1); } scanf("%d",&n1); getchar(); char s1[300000]; for(j=0;j<n1;j++){ gets(s1); for(k=0;s1[k]!=NULL;k++) c[s1[k]-97]++; for(k=0;k<26;k++){ if(c[k]>0){ if(b[k][c[k]-1]>max) max=b[k][c[k]-1]; } c[k]=0; } printf("%d\n",max); max=0; } return 0; }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
07090e86843cf04160332e167e97122a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include<stdio.h> int aaa[26][300000]; int aa[26]; int main() { int a,t,i,c,j; scanf("%d ",&a); char b[a]; for(i=0;i<a;i++) { scanf("%c",&b[i]); //b[i]=b[i]-'; aaa[b[i]-'a'][aa[b[i]-'a']]=i+1; // printf("%d=%d\n",aa[b[i]-'a'],aaa[b[i]-'a'][aa[b[i]-'a']]); aa[b[i]-'a']++; } scanf("%d ",&c); for(j=1;j<=c;j++){ char m[250000]; gets(m); t=strlen(m); m[t]='\0'; int k=0; for(i=0;i<26;i++) { aa[i]=0; } for(i=0;i<t;i++) { aa[m[i]-'a']++; // printf("%c=%d\n",m[i], aa[m[i]-'a']); } for(i=0;i<t;i++) { // printf("%d\n",aaa[m[i]-'a'][aa[m[i]-'a']-1]); if( aaa[m[i]-'a'][aa[m[i]-'a']-1]>k) { k= aaa[m[i]-'a'][aa[m[i]-'a']-1]; // printf("%c=%d\n",m[i],k); } } printf("%d\n",k); } }
The letters shop showcase is a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string $$$s$$$.There are $$$m$$$ friends, the $$$i$$$-th of them is named $$$t_i$$$. Each of them is planning to estimate the following value: how many letters (the length of the shortest prefix) would s/he need to buy if s/he wanted to construct her/his name of bought letters. The name can be constructed if each letter is presented in the equal or greater amount. For example, for $$$s$$$="arrayhead" and $$$t_i$$$="arya" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="harry" $$$6$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="ray" $$$5$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="r" $$$2$$$ letters have to be bought ("arrayhead"). For example, for $$$s$$$="arrayhead" and $$$t_i$$$="areahydra" all $$$9$$$ letters have to be bought ("arrayhead"). It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.Note that the values for friends are independent, friends are only estimating them but not actually buying the letters.
For each friend print the length of the shortest prefix of letters from $$$s$$$ s/he would need to buy to be able to construct her/his name of them. The name can be constructed if each letter is presented in the equal or greater amount. It is guaranteed that every friend can construct her/his name using the letters from the string $$$s$$$.
C
8736df815ea0fdf390cc8d500758bf84
f0fa201cef501c1fa0769ba1a1430400
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "binary search", "implementation", "strings" ]
1561905900
["9\narrayhead\n5\narya\nharry\nray\nr\nareahydra"]
null
PASSED
1,300
standard input
2 seconds
The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of showcase string $$$s$$$. The second line contains string $$$s$$$, consisting of exactly $$$n$$$ lowercase Latin letters. The third line contains one integer $$$m$$$ ($$$1 \le m \le 5 \cdot 10^4$$$) — the number of friends. The $$$i$$$-th of the next $$$m$$$ lines contains $$$t_i$$$ ($$$1 \le |t_i| \le 2 \cdot 10^5$$$) — the name of the $$$i$$$-th friend. It is guaranteed that $$$\sum \limits_{i=1}^m |t_i| \le 2 \cdot 10^5$$$.
["5\n6\n5\n2\n9"]
#include<stdio.h> #include<string.h> int test[126]; void clear() { int i; for(i=97;i<=125;i++) test[i]=0; } int main() { int n,i,m,j,temp,max=0,len,k,cnt[126]={}; scanf("%d",&n); char str[n+2],name[n+2]; int value[n+2][125]; scanf("%s",str); for(i=0;str[i]!='\0';i++) { value[cnt[str[i]]][str[i]]=i; cnt[str[i]]++; } scanf("%d",&m); for(i=0;i<m;i++) { scanf("%s",name); max=0; for(j=0;name[j]!='\0';j++) { temp=value[test[name[j]]][name[j]]; test[name[j]]++; if(temp>max) max=temp; } printf("%d\n",max+1); clear(); } return 0; }
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct.You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
C
a9fd2e4bc5528a34f1f1b869cd391d71
e9d564f5041b4069c1de67662696162a
GNU C
standard output
256 megabytes
train_001.jsonl
[ "geometry" ]
1522850700
["5\n0 0\n0 1\n1 1\n1 -1\n2 2", "5\n0 0\n1 0\n2 1\n1 1\n2 3"]
NoteIn the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.
PASSED
2,000
standard input
2 seconds
The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.
["YES", "NO"]
#include<stdio.h> int gcd(int a,int b) { int c; while(a%b!=0) { c=b; b=a%b; a=c; } return b; } int main() { int n,i,j,k,con,refx,refy,delx1,dely1,dely2,delx2,lastx,sign; sign=con=1; scanf("%d",&n); int p[n][3]; for(i=0;i<n;i++) { scanf("%d %d",&p[i][0],&p[i][1]); p[i][2]=1; } if(n>4) { for(i=0;i<3&&con==1;i++) for(j=i+1;j<4&&con==1;j++) for(k=j+1;k<5&&con==1;k++) { delx1=p[i][0]-p[j][0]; dely1=p[i][1]-p[j][1]; if(delx1==0) dely1=1; else { if(delx1<0) { delx1=-delx1; sign=-sign; } if(dely1<0) { dely1=-dely1; sign=-sign; } refx=gcd(dely1,delx1); delx1=delx1/refx; dely1=sign*dely1/refx; sign=1; } delx2=delx1; dely2=dely1; delx1=p[i][0]-p[k][0]; dely1=p[i][1]-p[k][1]; if(delx1==0) dely1=1; else { if(delx1<0) { delx1=-delx1; sign=-sign; } if(dely1<0) { dely1=-dely1; sign=-sign; } refx=gcd(dely1,delx1); delx1=delx1/refx; dely1=sign*dely1/refx; sign=1; } if(delx1==delx2&&dely1==dely2) { p[i][2]=p[j][2]=p[k][2]=0; con=0; refy=i; lastx=k; } } con=!con; for(i=lastx+1;i<n&&con==1;i++) { delx1=p[i][0]-p[refy][0]; dely1=p[i][1]-p[refy][1]; if(delx1==0) dely1=1; else { if(delx1<0) { delx1=-delx1; sign=-sign; } if(dely1<0) { dely1=-dely1; sign=-sign; } refx=gcd(dely1,delx1); delx1=delx1/refx; dely1=sign*dely1/refx; sign=1; } if(delx1==delx2&&dely1==dely2) { p[i][2]=0; } } i=0; while(i<n&&p[i][2]==0&&con==1) i++; if(i<n&&con==1) { refy=i; p[i][2]=0; i++; } while(i<n&&p[i][2]==0&&con==1) i++; if(i<n&&con==1) { delx1=p[i][0]-p[refy][0]; dely1=p[i][1]-p[refy][1]; if(delx1==0) dely1=1; else { if(delx1<0) { delx1=-delx1; sign=-sign; } if(dely1<0) { dely1=-dely1; sign=-sign; } refx=gcd(dely1,delx1); delx1=delx1/refx; dely1=sign*dely1/refx; sign=1; } delx2=delx1; dely2=dely1; i++; } while(i<n&&con==1) { while(i<n&&p[i][2]==0) i++; if(i<n&&con==1) { delx1=p[i][0]-p[refy][0]; dely1=p[i][1]-p[refy][1]; if(delx1==0) dely1=1; else { if(delx1<0) { delx1=-delx1; sign=-sign; } if(dely1<0) { dely1=-dely1; sign=-sign; } refx=gcd(dely1,delx1); delx1=delx1/refx; dely1=sign*dely1/refx; sign=1; } } if(delx1!=delx2||dely1!=dely2) {con=0;} i++; } } if(con==1) printf("YES"); else printf("NO"); return 0; }
You are given n points on Cartesian plane. Every point is a lattice point (i. e. both of its coordinates are integers), and all points are distinct.You may draw two straight lines (not necessarily distinct). Is it possible to do this in such a way that every point lies on at least one of these lines?
If it is possible to draw two straight lines in such a way that each of given points belongs to at least one of these lines, print YES. Otherwise, print NO.
C
a9fd2e4bc5528a34f1f1b869cd391d71
16e347efa6dc3797e603f3d189fa98cf
GNU C
standard output
256 megabytes
train_001.jsonl
[ "geometry" ]
1522850700
["5\n0 0\n0 1\n1 1\n1 -1\n2 2", "5\n0 0\n1 0\n2 1\n1 1\n2 3"]
NoteIn the first example it is possible to draw two lines, the one containing the points 1, 3 and 5, and another one containing two remaining points.
PASSED
2,000
standard input
2 seconds
The first line contains one integer n (1 ≤ n ≤ 105) — the number of points you are given. Then n lines follow, each line containing two integers xi and yi (|xi|, |yi| ≤ 109)— coordinates of i-th point. All n points are distinct.
["YES", "NO"]
//set many funcs template #include<stdio.h> #include<string.h> #include<stdlib.h> #include<stdbool.h> #include<time.h> #define inf 1072114514 #define llinf 4154118101919364364 #define mod 1000000007 #define pi 3.1415926535897932384 int max(int a,int b){if(a>b){return a;}return b;} int min(int a,int b){if(a<b){return a;}return b;} int zt(int a,int b){return max(a,b)-min(a,b);} int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;} int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;} int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;} int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;} int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;} int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;} int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;} long long llmax(long long a,long long b){if(a>b){return a;}return b;} long long llmin(long long a,long long b){if(a<b){return a;}return b;} long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);} long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;} long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;} long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;} long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;} long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;} long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;} long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;} double dbmax(double a,double b){if(a>b){return a;}return b;} double dbmin(double a,double b){if(a<b){return a;}return b;} double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);} int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;} int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;} int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;} int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;} int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;} int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;} int strsortfncsj(const void *a,const void *b){return strcmp((char *)a,(char *)b);} int strsortfnckj(const void *a,const void *b){return strcmp((char *)b,(char *)a);} long long psl3(long long Ax,long long Ay,long long Bx,long long By,long long Cx,long long Cy){ return (Ax*By+Bx*Cy+Cx*Ay)-(Ax*Cy+Bx*Ay+Cx*By); } int main(void){ long long i,j,n,m,k,a,b,c,w,r=0,l,t; long long x[262144],y[262144]; long long bas1=-1,bas2=-1,nh1,nh2,nhc=0; double d; char s[262144]; scanf("%lld",&n); //l=strlen(s); for(i=0;i<n;i++){ scanf("%lld %lld",&x[i],&y[i]); } if(n<=4){printf("YES\n");return 0;} for(i=0;i<5;i++){ for(j=0;j<5;j++){if(i==j){continue;} for(k=0;k<5;k++){if(i==k || j==k){continue;} if(psl3(x[i],y[i],x[j],y[j],x[k],y[k])==0){bas1=i;bas2=j;} } } } if(bas1==-1){printf("NO\n");return 0;} for(i=0;i<n;i++){ if(i==bas1 || i==bas2){continue;} if(psl3(x[bas1],y[bas1],x[bas2],y[bas2],x[i],y[i])==0){continue;} else if(nhc==0){nh1=i;nhc=1;continue;} else if(nhc==1){nh2=i;nhc=2;continue;} else{ if(psl3(x[nh1],y[nh1],x[nh2],y[nh2],x[i],y[i])==0){continue;} else{printf("NO\n");return 0;} } } //qsort(a,n,sizeof(int),sortfncsj); printf("YES\n"); return 0; }
Furlo and Rublo play a game. The table has n piles of coins lying on it, the i-th pile has ai coins. Furlo and Rublo move in turns, Furlo moves first. In one move you are allowed to: choose some pile, let's denote the current number of coins in it as x; choose some integer y (0 ≤ y &lt; x; x1 / 4 ≤ y ≤ x1 / 2) and decrease the number of coins in this pile to y. In other words, after the described move the pile will have y coins left. The player who can't make a move, loses. Your task is to find out, who wins in the given game if both Furlo and Rublo play optimally well.
If both players play optimally well and Furlo wins, print "Furlo", otherwise print "Rublo". Print the answers without the quotes.
C
cc23f07b6539abbded7e120793bef6a7
e1cce01a825a4a58eec4f89ff41052c0
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "games" ]
1355671800
["1\n1", "2\n1 2", "10\n1 2 3 4 5 6 7 8 9 10"]
null
PASSED
2,200
standard input
2 seconds
The first line contains integer n (1 ≤ n ≤ 77777) — the number of piles. The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 777777777777) — the sizes of piles. The numbers are separated by single spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
["Rublo", "Rublo", "Furlo"]
/* practice with Dukkha */ #include <math.h> #include <stdio.h> #define A 888888 int tr[A + A]; void update(int i, int b) { tr[i += A] = b; while (i > 1) { i >>= 1; tr[i] = tr[i << 1] | tr[i << 1 | 1]; } } int query(int l, int r) { int b = 0; for (l += A, r += A; l <= r; l >>= 1, r >>= 1) { if ((l & 1) == 1) b |= tr[l++]; if ((r & 1) == 0) b |= tr[r--]; } return b; } int query_(long long a) { int l = pow(a, 0.25), r = sqrt(a), b, x; while ((long long) l * l * l * l < a) l++; while ((long long) (l - 1) * (l - 1) * (l - 1) * (l - 1) >= a) l--; while ((long long) r * r > a) r--; while ((long long) (r + 1) * (r + 1) <= a) r++; b = query(l, r); x = 0; while (b & 1 << x) x++; return x; } void init() { int a; update(0, 1 << 0); update(1, 1 << 0); for (a = 2; a < A; a++) update(a, 1 << query_(a)); } int main() { int n, grundy; init(); scanf("%d", &n); grundy = 0; while (n--) { long long a; scanf("%lld", &a); grundy ^= a < 2 ? 0 : query_(a); } printf(grundy ? "Furlo\n" : "Rublo\n"); return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
1ef61f48a52b76f86ffd9a10333f7928
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include<stdio.h> #include<string.h> int GY(int a, int b) { if(b == 0) return a; if(a % b == 0) return b; else return GY(b, a % b); } int main() { int a, b, c[200], d[200], m, n, x, y, i, j, k, t; while(scanf("%d%d", &m, &n) != EOF) { memset(c, 0, sizeof(c)); memset(d, 0, sizeof(d)); scanf("%d", &a); for(i = 0; i < a; i++) { scanf("%d", &k); c[k] = 1; } scanf("%d", &b); for(i = 0; i < b; i++) { scanf("%d", &k); d[k] = 1; } if(m > n) { k = GY(m, n); t = m - n; } else { k = GY(n, m); t = n - m; } if(k > t) k = GY(k, t); else k = GY(t, k); y = 1; for(i = 0; i < k; i++) { x = 0; for(j = 0; j + i < m || j + i < n; j += k) { if(j + i < m) { if(c[j + i] == 1) { x = 1; break; } } if(j + i < n) { if(d[j + i] == 1) { x = 1; break; } } } if(x == 0) { y = 0; break; } } if(y == 1) printf("Yes\n"); else printf("No\n"); } }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
42131ed3f9e0ee50f05d4d7a146f9869
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include<stdio.h> int main() { int g,i,j,k,l,m,n,a,b,s; scanf("%d",&n); scanf("%d",&m); short int B[100],G[100]; for(i=0;i<100;i++) { B[i]=0; G[i]=0; } scanf("%d",&b); for(i=0;i<b;i++) { scanf("%d",&j); B[j]=1; } scanf("%d",&g); for(i=0;i<g;i++) { scanf("%d",&j); G[j]=1; } for(i=0;i<=(m+1)*(n+1);i++) { B[i%n]=G[i%m]|B[i%n]; G[i%m]=G[i%m]|B[i%n]; } a=0; for(i=0;i<n;i++) { if(B[i]==0) { a=1; break; } } for(i=0;i<m;i++) { if(G[i]==0) { a=1; break; } } if(a==1) printf("No"); else printf("Yes"); return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
c82ccca2fe46ffc1711f5012d990f0bb
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include <stdio.h> #include <stdlib.h> int boys[100]={0}; int girls[100]={0}; int main() { int b,g,hb,hg,i,j,x,y; scanf("%d %d",&b,&g); scanf("%d",&hb); for(i=0;i<hb;i++){ scanf(" %d",&x); boys[x]=1; } scanf("%d",&hg); for(i=0;i<hg;i++){ scanf(" %d",&x); girls[x]=1; } for(i=0;i<2*b*g;i++){ if(boys[i%b]==1)girls[i%g]=1; else if(girls[i%g]==1)boys[i%b]=1; } for(i=0;i<b;i++)if(boys[i]!=1)break; if(i!=b)printf("No"); else{ for(j=0;j<=g;j++)if(girls[j]!=1)break; if(j!=g)printf("No"); else printf("Yes"); } return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
ac5e5ee0b81fab3757e480a4f56b4d53
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include<stdio.h> #include<stdlib.h> int main(void){ int m,n,i,j,input,b,g; scanf("%d %d",&n,&m); scanf("%d",&b); int *b_list = (int *)calloc(n,sizeof(int)); for(i=0;i<b;i++){ scanf("%d",&input); b_list[input]=1; } scanf("%d",&g); int *g_list = (int *)calloc(m,sizeof(int)); for(i=0;i<g;i++){ scanf("%d",&input); g_list[input]=1; } for(i=0;i<m*n*(m+n);i++){ if(b_list[i%n]==1||g_list[i%m]==1){ b_list[i%n]=1; g_list[i%m]=1; } } for(i=0;i<n||i<m;i++){ if(b_list[i%n]==0||g_list[i%m]==0){ printf("No"); return(0); } } printf("Yes"); return(0); }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
36cf5dc982513e93301af37ebf625be9
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include <stdio.h> int x[100], y[100]; int main(void) { int i, j, n, m, b, g, last = -1; scanf("%d %d %d", &n, &m, &b); for (i = 0; i < b; i++) { scanf("%d", &j); x[j] = 1; } scanf("%d", &g); for (i = 0; i < g; i++) { scanf("%d", &j); y[j] = 1; } for (i = 0; i - last <= n * m; i++) if (x[i % n] && !y[i % m]) y[i % m] = 1, g++, last = i; else if (!x[i % n] && y[i % m]) x[i % n] = 1, b++, last = i; printf(b == n && g == m ? "Yes" : "No"); return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
4e752a2670fc98cd5eb6c55297b46226
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include<stdio.h> #include<string.h> int b[10010], g[10010]; int vis[110]; int que[10010]; int main() { int m, n, h, sub; int i, j, cont = 0; memset(vis, 0, sizeof(vis)); scanf("%d %d", &n, &m); for (i = 0; i < n*m; i++) b[i] = i%n; for (i = 0; i < n*m; i++) g[i] = i%m; scanf("%d", &h); for (i = 0; i < h; i++) { scanf("%d", &sub); vis[sub] = 1; } scanf("%d", &h); for (i = 0; i < h; i++) { scanf("%d", &sub); vis[sub] = 1; } for (i = 0; i < 100; i++) { for (j = 0; j < m*n; j++) { if (vis[b[j]] == 0 && vis[g[j]] == 0) continue; else { vis[b[j]] = 1; vis[g[j]] = 1; } } } for (i = 0; i < n; i++) { if (vis[i] == 1) cont++; } if (cont == n) printf("Yes\n"); else printf("No\n"); return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
3f27f88c63509a6a5bd25ee29c4b3b02
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include<stdio.h> int main() { int n,m,b,g,x,i,j; int B[100]={0},G[100]={0}; scanf("%d%d",&n,&m); scanf("%d",&b); for(i=0;i<b;i++) { scanf("%d",&x); B[x]=1; } scanf("%d",&g); for(i=0;i<g;i++) { scanf("%d",&x); G[x]=1; } for(i=0;i<m*n+m+n;i++) { if(B[i%n]==0 && G[i%m]==1) { B[i%n]=1; } else if(B[i%n]==1 && G[i%m]==0) { G[i%m]=1; } } for(i=0;i<n && B[i];i++); for(j=0;j<m && G[j];j++); if(i==n && j==m) printf("Yes\n"); else printf("No\n"); return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
940c653269762d68894c51f452e663b2
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int max(int a, int b) { if (a>b) return a; else return b; } int min(int a, int b) { if (a<b) return a; else return b; } int gcd(int a, int b){ int c, d; d = max(a, b); c = min(a, b); if(d%c == 0) return c; else return gcd(d%c, c); } int pep[101]; int main(){ int n, m, b, g, c, i, cnt = 0, id; memset(pep, 0, sizeof(pep)); scanf("%d%d",&n,&m); c = gcd(n, m); scanf("%d",&b); for( i = 0; i < b; i++ ){ scanf("%d",&id); if(!pep[id%c]) pep[id%c] = 1, cnt++; } scanf("%d",&g); for( i = 0; i < g; i++ ){ scanf("%d",&id); if(!pep[id%c]) pep[id%c] = 1, cnt++; } if(cnt == c) printf("YES\n"); else printf("NO\n"); return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
45dfa2de3a88013dda278e920089e7aa
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include<stdio.h> #include<string.h> int gcd(int a, int b) { if(a > b) return gcd(b, a); if(b % a == 0) return a; return gcd(b % a, a); } int main() { int n,m,i,j,x,flag,sign=0; int a[105],b[105],tmp[105]; memset(a,-1,sizeof(a)); memset(b,-1,sizeof(b)); memset(tmp,0,sizeof(tmp)); scanf("%d %d",&n,&m); for(i=0;i<n;i++) a[i]=0; for(i=0;i<m;i++) b[i]=0; int boy,girl; scanf("%d",&boy); for(i=0;i<boy;i++) { scanf("%d",&x); a[x]=1; } scanf("%d",&girl); for(i=0;i<girl;i++) { scanf("%d",&x); b[x]=1; } if(girl==0&&boy==0)printf("No"); else { if(gcd(n,m)==1)printf("Yes"); else { int t=gcd(n,m); for(i=0;i<n;i++) if(a[i]==1)tmp[i%t]=1; for(i=0;i<m;i++) if(b[i]==1)tmp[i%t]=1; int cnt=0; for(i=0;i<t;i++) if(tmp[i]==1)cnt++; if(cnt==t)printf("Yes"); else printf("No"); } } }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
051b908ba4aa5ad1f3878033023654e7
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include <stdio.h> #include <stdlib.h> #include <string.h> int max(int a, int b) { if (a>b) return a; else return b; } int min(int a, int b) { if (a<b) return a; else return b; } int gcd(int a, int b){ int c, d; d = max(a, b); c = min(a, b); if(d%c == 0) return c; else return gcd(d%c, c); } int pep[101]; int main(){ int n, m, b, g, c, i, cnt = 0, id; memset(pep, 0, sizeof(pep)); scanf("%d%d",&n,&m); c = gcd(n, m); scanf("%d",&b); for( i = 0; i < b; i++ ){ scanf("%d",&id); if(!pep[id%c]) pep[id%c] = 1, cnt++; } scanf("%d",&g); for( i = 0; i < g; i++ ){ scanf("%d",&id); if(!pep[id%c]) pep[id%c] = 1, cnt++; } if(cnt == c) printf("YES\n"); else printf("NO\n"); return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
afd7f05b57d8d1ced55d85799078b404
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include<stdio.h> int n; int left,right,middle; int a[10000],b[10000]; void msort(int a[],int left,int middle,int right) { int temp,temp1,temp2,l1,l2,d,d1,t1,flag,i; temp1=middle+1; temp=left; temp2=right; l1=middle-left+1; l2=right-middle; d=l1; d1=l2; t1=left; flag=0; while(d!=0&&d1!=0) { if(a[temp]<=a[temp1]) { b[t1]=a[temp]; temp++; d--; } else { b[t1]=a[temp1]; temp1++; d1--; } t1++; if(d==0) flag=1; if(d1==0) flag=2; } if(flag==1) { while(d1>0) { b[t1]=a[temp1]; temp1++; t1++; d1--; } } if(flag==2) { while(d>0) { b[t1]=a[temp]; temp++; t1++; d--; } } for(i=left;i<=right;i++) { a[i]=b[i]; } } void sort(int a[],int left,int right) { int middle=(left+right)/2; if(left<right) { sort(a,left,middle); sort(a,middle+1,right); msort(a,left,middle,right); } else return; } int main() { int i,j,k,n,m,t,g,b,bb[101],gg[101],x[101],y[101],num1,num2,flag=0,flag1=0; scanf("%d%d",&n,&m); scanf("%d",&b); for(i=0;i<b;i++) scanf("%d",&bb[i]); scanf("%d",&g); for(i=0;i<g;i++) scanf("%d",&gg[i]); int k1=0,k2=0; sort(bb,0,b-1); sort(gg,0,g-1); for(i=0;i<n;i++) { x[i]=i; if(k2<b) { if(i==bb[k2]) { x[i]=-1; k2++; } } } for(i=0;i<m;i++) { y[i]=i; if(k1<g) { if(i==gg[k1]) { y[i]=-1; k1++; } } } // for(i=0;i<m;i++) // printf("%d ",y[i]); int num; if(n>m) { t=n%m; num=n; } else { t=m%n; num=m; } // if(t==0) // { // num=num; // } // else // { // if(m>n) num=10010; // else // num=n*n; // } //printf("num=% "); for(i=0;i<num;i++) { num1=i%n; num2=i%m; if(x[num1]==-1||y[num2]==-1) { x[num1]=-1; y[num2]=-1; } } //for(i=0;i<n;i++) // printf("%d ",x[i]); for(i=0;i<n;i++) { if(x[i]!=-1) { flag=1; break; } } if(flag==1) { printf("No\n"); flag=2; } // printf("sdg"); for(i=0;i<m;i++) { if(y[i]!=-1) { flag1=1; break; } } if(flag==0&&flag1==1) printf("No\n"); if(flag==0&&flag1==0) printf("Yes\n"); return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
9b094298ab5117b26645286ece67b77d
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include <stdio.h> #define maxn 120 int main() { int n,i,j,m,b,g; int x[maxn]={0},y[maxn]={0}; scanf("%d%d",&n,&m); scanf("%d",&b); for (i=0;i<b;i++){ scanf("%d",&j); x[j]=1; } scanf("%d",&g); for (i=0;i<g;i++){ scanf("%d",&j); y[j]=1; } for (i=0;i<=4*n*m;i++) if (x[i%n]||y[i%m]) {x[i%n]=1;y[i%m]=1;} for (i=0;i<n;i++) if (!x[i]){ printf("No\n"); return 0; } for (i=0;i<m;i++) if (!y[i]){ printf("No\n"); return 0; } printf("Yes\n"); return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
7f04722ac82c72158d9a197afbd88d93
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include <stdio.h> #include <stdlib.h> int main(void) { int n, m; scanf("%d %d", &n, &m); int i, j; int boy[n]; int girl[m]; for (i = 0; i < n; ++i) { boy[i] = 0; } for (i = 0; i < m; ++i) { girl[i] = 0; } int b; scanf("%d", &b); int temp; for (i = 0; i < b; ++i) { scanf("%d", &temp); boy[temp] = 1; } int g; scanf("%d", &g); for (i = 0; i < g; ++i) { scanf("%d", &temp); girl[temp] = 1; } for (i = 0; i < 100000; ++i) { if (girl[i%m] == 1 || boy[i%n] == 1) { girl[i%m] = 1; boy[i%n] = 1; } } int flag = 1; for (i = 0; i < n; ++i) { if (boy[i] != 1) { flag = 0; break; } } for (i = 0; i < m; ++i) { if (girl[i] != 1) { flag = 0; break; } } if (flag) { printf("Yes\n"); } else { printf("No\n"); } return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
c769848b0fcc2356c6915040670f8916
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include <stdio.h> int main(void) { int n,m,b,g,i,index,ans1,ans2; int flag1=0; int flag2=0; scanf("%d%d",&n,&m); int b1[n]; int g1[m]; for(i=0;i<n;i++)b1[i]=0; for(i=0;i<m;i++)g1[i]=0; scanf("%d",&b); for(i=0;i<b;i++) { scanf("%d",&index); b1[index]=1; } scanf("%d",&g); for(i=0;i<g;i++) { scanf("%d",&index); g1[index]=1; } for(i=0;i<2*n*m;i++) { ans1=i%n; ans2=i%m; if(b1[ans1]==1) { b1[ans1]=1; g1[ans2]=1; } else if(g1[ans2]==1) { b1[ans1]=1; g1[ans2]=1; } } for(i=0;i<n;i++) { if(b1[i]==0) { flag1=1; break; } } for(i=0;i<m;i++) { if(g1[i]==0) { flag2=1; break; } } if(flag1==0&&flag2==0) { printf("Yes"); } else printf("No"); return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
356ce739bc4f7448b1402cab978cbe82
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include<stdio.h> int arr[2500]; int arr1[2500]; int max(int a,int b){ return a>b?a:b; } int main(){ int a,b; scanf("%d%d",&a,&b); int i; int left,left1; int x,g; scanf("%d",&x); for(i=0;i<x;i++){ int in; scanf("%d",&in); arr[in]=1; } scanf("%d",&g); for(i=0;i<g;i++){ int in; scanf("%d",&in); arr1[in]=1; } left=a-x; left1=b-g; for(i=0;i<a*b*max(a,b)*a;i++){ if(left == 0 && left1 == 0){ printf("Yes"); return 0; } int boy = (i)%a; int gril = (i)%b; if(arr[boy] || arr1[gril]){ if(arr[boy] && arr1[gril]==0){ arr1[gril]=1; left1--; } else if(arr1[gril] && arr[boy]==0){ left--; arr[boy]=1; } } } printf("No"); }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
8fccbc424c6f27b52b060effdc47036d
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include <stdio.h> #include <string.h> int gcd(int x,int y) { if (x%y==0) return y; else if (y%x==0) return x; else if (x>y) return gcd(y,x%y); else return gcd(x,y%x); } int main() { int n,m,b,g,x[100],d,i,j; for (i=0;i<100;i++) x[i]=0; scanf(" %d %d",&n,&m); d=gcd(n,m); scanf(" %d",&b); for (i=0;i<b;i++) { scanf("%d",&j); x[j%d]=1; } scanf (" \n%d",&g); for (i=0;i<g;i++) { scanf(" %d",&j); x[j%d]=1; } j=0; for (i=0;i<d;i++) if (x[i]) j++; if (j==d) printf("Yes"); else printf("No"); return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
0fee90a71db45f7c3cd908aadcbe75f5
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include <stdio.h> #include <string.h> void swap(int *x,int *y) { int k=*x;*x=*y;*y=k; } int gcd(int x,int y) { if (y>x) swap(&x,&y); if (x%y==0) return y; else return gcd(y,x%y); } int main() { int n,m,b,g,x[100],d,i,j; for (i=0;i<100;i++) x[i]=0; scanf(" %d %d",&n,&m); d=gcd(n,m); scanf(" %d",&b); for (i=0;i<b;i++) { scanf("%d",&j); x[j%d]=1; } scanf(" %d",&g); for (i=0;i<g;i++) { scanf(" %d",&j); x[j%d]=1; } j=0; for (i=0;i<d;i++) if (x[i]) j++; if (j==d) printf("Yes"); else printf("No"); return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
780311e45066a69fa07d11e8be039db7
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include<stdio.h> typedef unsigned u; u A[100],B[100]; int main() { u n,m,i,j,N,x,y; scanf("%u%u",&n,&m); for(scanf("%u",&x);x--;) {scanf("%u",&y);A[y]=1;} for(scanf("%u",&x);x--;) {scanf("%u",&y);B[y]=1;} while(getchar()==' '); for(N=n*m,i=1,x=y=0;i;)for(i=j=0;j<N;++j) { if(A[x]^B[y])A[x]=B[y]=i=1; if(++x==n)x=0; if(++y==m)y=0; } for(i=x=-1;++i<n;)if(!A[i])x=0; for(i=-1;++i<m;)if(!B[i])x=0; printf(x?"Yes\n":"No\n"); return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
960d22144342f7170489265b31578dd9
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
/* .................... compiled by alankar.................... */ //......................SHORTCUTS.............................. #include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> //........................................................... #define pi 3.14159265358979323846 //float type #define MAX 100000 //for rmq #define SQRTMAX 317 //for rmq //#define gc getchar_unlocked #define FOR(i,a,b) for(i=(a);i<(b);i++) //only for +ve and single terms #define s(x) scanf("%d",&x); #define sl(x) scanf("%l64d",&x); #define p(x) printf("%d\n",x); #define pl(x) printf("%l64d\n",x); //.......................................................... typedef long long int ll; const ll MOD=1000000007; //returns int and +ve numbers /*inline int inp(){ int n=0; char c; c=gc(); while(c<'0' || c>'9'){ c=gc(); } while(c>='0' && c<='9'){ n=(n<<3)+(n<<1)+c-'0'; c=gc(); } return n; } */ //................................... //power with mod........long long int ll power(ll a,ll b,ll mod){ if(b==0) return 1; ll temp=power(a,b/2,mod); temp=(temp*temp)%mod; if(b&1) temp=(temp*a)%mod; return temp; } //power without mod........ int int pwr(int a,int b){ if(b==0) return 1; int temp=pwr(a,b/2); temp=(temp*temp); if(b&1) temp=(temp*a); return temp; } // .....long long int ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); } //......long long int ll lcm(ll a,ll b){ return (a/gcd(a,b))*b; } //......long long int with mod ll modularInverse(ll a,ll m){ return power(a,m-2,m); } //only for int int min(int a,int b) { return a<b? a : b; } int max(int a,int b) { return a>b? a : b; } //normal compare func on integers //for qsort(name,size,sizeof(type),compare) int compare (const void * a, const void * b) { return ( *(int*)a - *(int*)b ); } //....................................................... //segment tree //not template but how to use ST //for minimum element /* long long s[400000]; long long a[1000000]; int create(long long b,long long e,long long n) { if(b==e) { s[n]=a[b]; } else { create(b,(b+e)/2,2*n+1); create((b+e)/2+1,e,2*n+2); s[n]=s[2*n+1]<s[2*n+2]?s[2*n+1]:s[2*n+2]; } return 0; } //for finding minimum element b/w l and r long long messi(long long b,long long e,long long l,long long r,long long n) { long long i,j; if(e<l||b>r) { return 100000001; } if(b>=l&&e<=r) { return s[n]; } i=messi(b,(b+e)/2,l,r,2*n+1); j=messi((b+e)/2+1,e,l,r,2*n+2); return i<j?i:j; } */ //............................................................................ //range minimam query //for mim and max number /* //preprocess create the min array long min[SQRTMAX], max[SQRTMAX], b[MAX]; int size, n; void preProcess(int n){ int i=0, j=0, k=0; long minimum, maximum; size = sqrt(n); //printf("size = %d\n",size); while(j<size){ minimum = maximum = b[i]; for(k=0 ; k<size ; k++){ if(minimum>b[i]) minimum = b[i]; if(maximum<b[i]) maximum = b[i]; i++; } min[j] = minimum; max[j] = maximum; j++; } } long findMin(int l, int r){ int j, j2; long minimum = b[l]; j = l/size + 1; j2 = r/size - 1; //printf("j= %d and j2 = %d\n", j,j2); while(l<j*size && l<=r){ if(minimum > b[l]){ minimum = b[l]; } //printf("Checked for %d\n", l); l++; } while(j<=j2 && l<=r && j<size){ if(minimum > min[j]) minimum = min[j]; l = (j+1)*size; //printf("Checked for %d <--> %d\n", j*size, l-1); j++; } while(l<=r){ if(minimum > b[l]){ minimum = b[l]; } //printf("Checked for %d\n", l); l++; } return minimum; } //finding max value long findMax(int l, int r){ int j, j2; long maximum = b[l]; j = l/size + 1; j2 = r/size - 1; //printf("j= %d and j2 = %d\n", j,j2); while(l<j*size && l<=r){ if(maximum < b[l]){ maximum = b[l]; } //printf("Checked for %d\n", l); l++; } while(j<=j2 && l<=r && j<size){ if(maximum < max[j]) maximum = max[j]; l = (j+1)*size; //printf("Checked for %d <--> %d\n", j*size, l-1); j++; } while(l<=r){ if(maximum < b[l]){ maximum = b[l]; } //printf("Checked for %d\n", l); l++; } return maximum; } */ //...........................................END OF TEMPLATE................................................................. int a[100]={0},b[100]={0}; int main() { int i,j,k,t,n,m,u,e,r,flag=0; s(n) s(m) s(k) FOR(i,0,k) { s(j) a[j]=1; } s(k) FOR(i,0,k) { s(j) b[j]=1; } u=max(n,m); //p(u) { FOR(j,0,u*100) { //p(a[j%n]) //p(b[j%m]) if((a[j%n]==1)||(b[j%m]==1)) { a[j%n]=1; b[j%m]=1; } } } FOR(i,0,n) { if(a[i]==0) {flag=1; //p(a[i]) break; } } FOR(i,0,m) { if(b[i]==0) {flag=1; // p(a[i]) break; } } if(flag) printf("No"); else printf("Yes"); return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
be4d94179bfb20501335099174eea801
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include<stdio.h> int main() { int arr1[1000]={0}; int arr2[1000]={0}; int n,m; scanf("%d %d",&n,&m); int b; scanf("%d",&b); int i; int x; for(i=0;i<b;i++) { scanf("%d",&x); arr1[x]=1; } int g; scanf("%d",&g); for(i=0;i<g;i++) { scanf("%d",&x); arr2[x]=1; } i=0;int j=0;int co=0;int cou=0;int mi=0; while(1) { if(i>100000) break; int c=arr1[i%n]; int d=arr2[i%m]; if(c==1||d==1) { arr1[i%n]=1; arr2[i%m]=1; } for(j=0;j<n;j++) { if(arr1[j]==1) co++; } for(j=0;j<m;j++) { if(arr2[j]==1) cou++; } if(co==n&&cou==m) { mi=1; break; } co=0;cou=0; i++; } if(mi==1) printf("Yes\n"); else printf("No\n"); return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
933f2f6ff94d9548afa21759767aaf1c
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include<stdio.h> int main(){ int flag,head1,head2,sum,i,j,k,l,n,m,bn,gn,b[2][1000],g[2][1000]; scanf("%d%d",&n,&m); scanf("%d",&bn); for(i=0;i<bn;i++){ scanf("%d",&k); b[1][k]=1; } scanf("%d",&gn); for(i=0;i<gn;i++){ scanf("%d",&k); g[1][k]=1; } flag=1,head1=0,head2=0,sum=0,head1=0,head2=0; while(sum<1000){ flag=0; if(n>m){ for(i=0;i<n;i++){ if(b[1][head1]==1 || g[1][head2]==1){ if(b[1][head1]==1 && g[1][head2]==1); else flag=1; b[1][head1]=1; g[1][head2]=1; } head1 = (head1+1)%n; head2 = (head2+1)%m; } } else{ for(i=0;i<m;i++){ if(b[1][head1]==1 || g[1][head2]==1){ if(b[1][head1]==1 && g[1][head2]==1); else flag=1; b[1][head1]=1; g[1][head2]=1; } head1=(head1+1)%n; head2=(head2+1)%m; } } if(flag==0) sum++; } flag=1; for(i=0;i<n;i++) if(b[1][i]==0) flag=0; for(i=0;i<m;i++) if(g[1][i]==0) flag=0; if(flag==1) printf("Yes\n"); else printf("No\n"); return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
946a60e18a9d13eb67bd95f9f8b9786b
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include <stdlib.h> int getint(){ char c,sign=1; int ans=0; while((c=getchar())<'-'); if(c=='-')sign=-1,c=getchar(); do{ ans=ans*10+c-48; }while((c=getchar())>='0'); return ans*sign; } int main(){ int n, m, a, b, x; int i; char boy[100]={0}, girl[100]={0}; n=getint(),m=getint(); a=getint(); for(i=0;i<a;i++){ x=getint(); boy[x]=1; } b=getint(); for(i=0;i<b;i++){ x=getint(); girl[x]=1; } for(i=0;i<1000000;i++)if(boy[i%n]||girl[i%m])boy[i%n]=1,girl[i%m]=1; for(i=0;i<n;i++)if(!boy[i])goto badend; for(i=0;i<m;i++)if(!girl[i])goto badend; puts("Yes"); return 0; badend: puts("No"); return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
e40c8bc74c10139a3e30ca801183b2aa
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include <stdio.h> int main() { int boy[100], girl[100], happy_boys, happy_girls; int n, m, i, flag, temp, count=10001; int counter_boy=0, counter_girl=0; scanf("%d %d", &n, &m); for(i=0; i<100; i++) { boy[i] = 0; girl[i] = 0; } scanf("%d", &happy_boys); for (i=0; i < happy_boys; i++) { scanf("%d", &temp); boy[temp] = 1; } scanf("%d", &happy_girls); for (i=0; i < happy_girls; i++) { scanf("%d", &temp); girl[temp] = 1; } while (count--) { flag = 1; counter_boy = counter_boy % n; counter_girl = counter_girl % m; if (boy[counter_boy] || girl[counter_girl]) { boy[counter_boy] = 1; girl[counter_girl] = 1; } for (i = 0; i < n; i++) { if (boy[i]==0) { flag = 0; break; } } for (i = 0; i < m; i++) { if (girl[i]==0) { flag = 0; break; } } if (flag) break; counter_boy++; counter_girl++; } if(flag) printf("Yes"); else printf("No"); return 0; }
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
C
65efbc0a1ad82436100eea7a2378d4c2
5c04fa5b5b8c69333c74b2a6dee3a58a
GNU C
standard output
256 megabytes
train_001.jsonl
[ "dsu", "meet-in-the-middle", "number theory", "brute force" ]
1424190900
["2 3\n0\n1 0", "2 4\n1 0\n1 2", "2 3\n1 0\n1 1"]
NoteBy we define the remainder of integer division of i by k.In first sample case: On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day. On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day. On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day. On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy. On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
PASSED
1,300
standard input
2 seconds
The first line contains two integer n and m (1 ≤ n, m ≤ 100). The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi &lt; n), denoting the list of indices of happy boys. The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj &lt; m), denoting the list of indices of happy girls. It is guaranteed that there is at least one person that is unhappy among his friends.
["Yes", "No", "Yes"]
#include <stdio.h> int main() { int boy[100], girl[100], happy_boys, happy_girls; int n, m, i, flag, temp, count=10001; int counter_boy=0, counter_girl=0; scanf("%d %d", &n, &m); for(i=0; i<100; i++) { boy[i] = 0; girl[i] = 0; } scanf("%d", &happy_boys); for (i=0; i < happy_boys; i++) { scanf("%d", &temp); boy[temp] = 1; } scanf("%d", &happy_girls); for (i=0; i < happy_girls; i++) { scanf("%d", &temp); girl[temp] = 1; } while (count--) { flag = 1; counter_boy = counter_boy % n; counter_girl = counter_girl % m; if (boy[counter_boy] || girl[counter_girl]) { boy[counter_boy] = 1; girl[counter_girl] = 1; } for (i = 0; i < n; i++) { if (!boy[i]) { flag = 0; break; } } for (i = 0; i < m; i++) { if (!girl[i]) { flag = 0; break; } } if (flag) break; counter_boy++; counter_girl++; } if(flag) printf("Yes"); else printf("No"); return 0; }
Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction as a sum of three distinct positive fractions in form .Help Vladik with that, i.e for a given n find three distinct positive integers x, y and z such that . Because Chloe can't check Vladik's answer if the numbers are large, he asks you to print numbers not exceeding 109.If there is no such answer, print -1.
If the answer exists, print 3 distinct numbers x, y and z (1 ≤ x, y, z ≤ 109, x ≠ y, x ≠ z, y ≠ z). Otherwise print -1. If there are multiple answers, print any of them.
C
f60ea0f2caaec16894e84ba87f90c061
85e9199263adc09a3112f48e8ae918bd
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "number theory", "brute force", "math" ]
1481726100
["3", "7"]
null
PASSED
1,500
standard input
1 second
The single line contains single integer n (1 ≤ n ≤ 104).
["2 7 42", "7 8 56"]
#include<stdio.h> int main() { int n; scanf("%d",&n); if(n-1) printf("%d %d %d\n",n,n+1,(n*(n+1))); else printf("-1\n"); return 0; }
Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction as a sum of three distinct positive fractions in form .Help Vladik with that, i.e for a given n find three distinct positive integers x, y and z such that . Because Chloe can't check Vladik's answer if the numbers are large, he asks you to print numbers not exceeding 109.If there is no such answer, print -1.
If the answer exists, print 3 distinct numbers x, y and z (1 ≤ x, y, z ≤ 109, x ≠ y, x ≠ z, y ≠ z). Otherwise print -1. If there are multiple answers, print any of them.
C
f60ea0f2caaec16894e84ba87f90c061
c7e4db1cf6e6b8383756f754a931b683
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "number theory", "brute force", "math" ]
1481726100
["3", "7"]
null
PASSED
1,500
standard input
1 second
The single line contains single integer n (1 ≤ n ≤ 104).
["2 7 42", "7 8 56"]
#include<stdio.h> #include<math.h> #include<stdlib.h> #include<string.h> int main() { int n; scanf("%d",&n); if(n==1) printf("-1\n"); else { printf("%d ",n); printf("%d ",n+1); printf("%d\n",n*(n+1)); } return 0; }
Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction as a sum of three distinct positive fractions in form .Help Vladik with that, i.e for a given n find three distinct positive integers x, y and z such that . Because Chloe can't check Vladik's answer if the numbers are large, he asks you to print numbers not exceeding 109.If there is no such answer, print -1.
If the answer exists, print 3 distinct numbers x, y and z (1 ≤ x, y, z ≤ 109, x ≠ y, x ≠ z, y ≠ z). Otherwise print -1. If there are multiple answers, print any of them.
C
f60ea0f2caaec16894e84ba87f90c061
3464b54caff1f7b44e7262e4e002e853
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "number theory", "brute force", "math" ]
1481726100
["3", "7"]
null
PASSED
1,500
standard input
1 second
The single line contains single integer n (1 ≤ n ≤ 104).
["2 7 42", "7 8 56"]
#include <stdio.h> int main() { long int n; scanf("%d",&n); if(n!=1)printf("%ld %ld %ld",n,n+1,n*(n+1)); else printf("%ld",-1); return 0; }
Vladik and Chloe decided to determine who of them is better at math. Vladik claimed that for any positive integer n he can represent fraction as a sum of three distinct positive fractions in form .Help Vladik with that, i.e for a given n find three distinct positive integers x, y and z such that . Because Chloe can't check Vladik's answer if the numbers are large, he asks you to print numbers not exceeding 109.If there is no such answer, print -1.
If the answer exists, print 3 distinct numbers x, y and z (1 ≤ x, y, z ≤ 109, x ≠ y, x ≠ z, y ≠ z). Otherwise print -1. If there are multiple answers, print any of them.
C
f60ea0f2caaec16894e84ba87f90c061
0076080de17603701b6f51c13c616c0a
GNU C11
standard output
256 megabytes
train_001.jsonl
[ "constructive algorithms", "number theory", "brute force", "math" ]
1481726100
["3", "7"]
null
PASSED
1,500
standard input
1 second
The single line contains single integer n (1 ≤ n ≤ 104).
["2 7 42", "7 8 56"]
#include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> #include<limits.h> #define MOD 1000000007 #define PI 3.14159265 #define seive_len 1000001 int *array; int seive[seive_len]; int prime_prime[seive_len]; int min(int a, int b) { return a<b?a:b; } int max(int a, int b) { return a>b?a:b; } int compare(const void* a, const void* b) { return *(int*)a-*(int*)b; } int cmp(const void *a, const void *b){ int ia = *(int *)a; int ib = *(int *)b; return array[ia] < array[ib] ? -1 : array[ia] > array[ib]; } int abs(int n) { if(n < 0) return n*(-1); return n; } void swap(long long int *a, long long int *b) { *a = (*a)^(*b); *b = (*a)^(*b); *a = (*a)^(*b); } int binSearch(int a[], int x, int l, int r) { if(r >= l) { int mid = l + ((r-l)>>1); if(a[mid] == x) return mid; if(a[mid] > x) { return binSearch(a, x, l, mid-1); } else if(a[mid] < x) { return binSearch(a, x, mid+1, r); } } return -1; } long long int gcd(long long int a, long long int b) { if(b == 0) return a; return gcd(b, a%b); } void makeSeive() { int i; seive[1] = 1; for(i=2;i<seive_len;i++) { if(seive[i] == 0) { long long int temp=(long long int)i*i; while(temp <= 1000000) { seive[temp] = 1; temp += i; } } } } int isPrime(int n) { int i; for(i=2;i*i<=n;i++) { if(n%i == 0) return 0; } return 1; } void getInput(int a[], int n) { for(int i=0;i<n;i++) scanf("%d", &a[i]); } void testCase() { long long int i, n, m, j; scanf("%lld", &n); if(n == 1) { printf("-1"); return; } printf("%lld %lld %lld", n, n+1, n*(n+1)); } int main() { int t=1; // scanf("%d", &t); while(t--) { testCase(); printf("\n"); } return 0; }