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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 47bd8b52dd8be952dc26290394717328 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include <stdio.h>
#include <math.h>
int a[1001],n,i,j, count, d;
int main()
{
scanf("%d %d", &n, &d);
for (i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (i = 1; i < n; i++)
for (j = 1 + i; j <= n; j++)
if (abs(a[j] - a[i]) <= d) count+=2;
printf("%d", count);
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | b12dddbf25be9e20bb8072a8f52be4cb | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
int main()
{
long long n,d,i;
scanf("%lld%lld",&n,&d);
long long a[n];
for(i=0;i<n;i++)
scanf("%lld",&a[i]);
long long j,c=0;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
if(a[i]-a[j]<=d)
c++;
}
else
{
if(a[j]-a[i]<=d)
c++;
}
}
}
printf("%lld\n",c*2);
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 76823f8ca7a4891ccf8697c653e5b5d2 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
long d;
int n,diff,ctd=0;
int main()
{
scanf("%d %ld",&n,&d);
int a[n];
for(int i=0;i<n;i++)
{
scanf(" %d",&a[i]);
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
diff=(a[i]-a[j])>0?(a[i]-a[j]):(a[j]-a[i]);
if((i!=j)&&(diff<=d))
{
ctd++;
}
}
}
printf("%d",ctd);
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | a6ef0fb74c9009d583560da2df5b337c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
int rec_for(int a[],int,int);
int main()
{
int n;long d;
scanf("%d%lu",&n,&d);
int a[n];
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
int c=rec_for(a,n,d);
printf("%d",c);
return 0;
}
int rec_for(int a[],int n,int d){
int f=0;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(a[j]-a[i]>=-d && a[j]-a[i]<=d){
f+=2;
}
}
}
return f;
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 9043ccb801d094e56c91c5a7d0bf616b | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
int main()
{
int n,d,a[1001],i,j,c=0;
scanf("%d%d",&n,&d);
for(i=0;i<n;i++)scanf("%d",&a[ i ]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(abs(a[ i ]-a[ j ]) <= d)c++;
}
}
printf("%d",c+c);
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | b31015d36f9cba2b66726e67c4da5653 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include <stdio.h>
int main()
{
int n,m,i,j,x=0;
scanf("%d%d",&n,&m);
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i!=j)
{
if(a[i]>=a[j]&&a[i]-a[j]<=m)
x++;
else if(a[j]>a[i]&&a[j]-a[i]<=m)
x++;
}
}
}
printf("%d",x);
return 0;
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 6e75e471cda14a6cd1853143297bfbb5 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
int main()
{int n,i,j,temp,count=0;
long long int d;
scanf("%d%lld",&n,&d);
int a[n];
for(i=0;i<n;i++)
{scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
{ if(i!=j)
{if((a[i]-a[j])<=d&&(a[i]-a[j])>=(-d))
count++;
}
}
}
printf("%d",count);
return 0;
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 8814399ce99842b352c402fa2cb729d0 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
int main()
{int n,i,j,temp,count=0;
long long int d;
scanf("%d%lld",&n,&d);
int a[n];
for(i=0;i<n;i++)
{scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
{ if(i!=j)
{if((a[i]-a[j])<=d&&(a[i]-a[j])>=(-d))
count++;
}
}
}
printf("%d",count);
return 0;
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 8769df52fda8ad52dabe25ec7c165997 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include <stdio.h>
#include <math.h>
int main()
{
int n, d, i, j, t=0, a[10001];
scanf("%d %d", &n, &d);
for(i=0; i<n; i++)
{
scanf("%d", &a[i]);
}
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
if((abs(a[i] - a[j])) <= d)
t++;
}
}
printf("%d\n", t-n);
return 0;
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | c8c473c3ada54a16fc8a0ac806a82cb9 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
#include<string.h>
int main(){
int n,d,i,j,c=0;
scanf("%d%d",&n,&d);
int a[n+1];
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(i=0;i<n-1;i++){
for(j=i+1;j<n;j++){
if(abs(a[i]-a[j])<=d){
c+=2;
}
}
}
printf("%d",c);
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 04ef0769d955d80c19d433085decc3b5 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
int main()
{
int n,d,i,j,s=0;
scanf("%d %d",&n,&d);
int arr[n];
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(arr[i]-arr[j]<=d && arr[i]-arr[j]>=-d)
s=s+2;
}
}
printf("%d\n",s);
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | c216cb6653756ceedd900bbdfe682650 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
int mod(int);
int main()
{
int n,diff,i,j,count=0,temp;
scanf("%d%d",&n,&diff);
int a[n];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n,i!=j;j++)
{
temp=mod(a[i]-a[j]);
if(temp<=diff)
{
count++;
}
}
}
printf("%d",2*count);
return 0;
}
int mod(int n)
{
int t;
if(n>0)
{
return n;
}
else
{
t=0-n;
return t;
}
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | ccb9024ab36162b39b5010b465928fe4 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
#include<math.h>
int soldiers[1000];
int main()
{
int n, d, units = 0;
scanf("%d %d", &n, &d);
for(int i = 0; i < n; i++)
scanf("%d", &soldiers[i]);
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
if(i == j) ;
else if(abs(soldiers[i] - soldiers[j]) <= d) units++;
}
}
printf("%d", units);
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 4d9e6d72714f662dc306d86a3f70c709 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include <stdio.h>
#define MAX 1000
#define F(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define sf(i) scanf("%d",&A[i])
int main() {
int n,d,A[MAX],x;
ll ans=0;
scanf("%d %d",&n,&d);
F(i,0,n) {
sf(i);
}
F(i,0,n-1) {
F(j,i+1,n) {
x = abs(A[j]-A[i]);
if(x <= d) {
ans += 2;
}
}
}
printf("%I64d\n",ans);
return 0;
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | ed9eaa19875abde15b98a598934e2e02 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
int main()
{
long long int n,d,i,j,k,a[1001],t=0;
scanf("%I64d %I64d",&n,&d);
for(i=0;i<n;i++){
scanf("%I64d",&a[i]);
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(i!=j){
if(abs(a[i]-a[j])<=d){
t++;
}
}
}
}
printf("%I64d\n",t);
return 0;
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 0b58b3ed9192f3ce97f7fb419129e815 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
int main()
{
int n,d,c=0;
int a[1000];
scanf("%d%d",&n,&d);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(int l=0;l<n-1;l++)
{
for(int i=l+1;i<n;i++)
{
if(abs(a[i]-a[l])<=d)
c++;
}
}
c=c*2;
printf("%d",c);
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | c8a915cafc068e640ca76e59bb7875ae | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
int mode(int* a,int* b){
int d;
if((*a)<(*b)) d= *b - *a;
else d= *a - *b;
return d;
}
int main(){
int n,d;
int m;
scanf("%d %d\n",&n,&d);
int arr[n],i,j,count=0;
for(i=0;i<n;i++){
scanf("%d ",&arr[i]);
}
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
m= mode(&arr[i],&arr[j]);
if(m<=d) count++;
}
}
printf("%d\n",(2*count));
return 0;
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 1a4f6ee94ff6435fdd56ae23c766c447 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
long x[1100], n, d, i, j, g;
scanf("%d %d", &n, &d);
for(i=0; i<n; i++)
{
scanf("%d", &x[i]);
}
g = 0;
for(i=0; i<n-1; i++)
{
for(j=i+1; j<n; j++)
{
if(labs(x[i]-x[j])<=d)
g = g+2;
}
}
printf("%d", g);
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 30c6953bc2e55019d38b3b49030ee47a | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include <stdio.h>
#include <math.h>
int recon(long long *arr, long long d, int length) {
int count=0;
for (int i=0; i<length-1; i++) {
for (int j=i+1; j<length; j++) {
if (abs(arr[i]-arr[j])<=d) {
count+=2;
}
}
}
return count;
}
int main() {
int len;
long long diff;
scanf("%d %I64d\n",&len,&diff);
long long heights[len];
for (int i=0; i<len; i++) scanf("%I64d",&heights[i]);
printf("%d",recon(heights,diff,len));
return 0;
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 33c2e7e2679088d7b7a3da57580ad0a2 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
int main()
{
int n,d,i,j,count=0,a[1000];
scanf("%d%d",&n,&d);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
j=i+1;
while(j<n)
{
if((a[i]<=a[j]) && ((a[j]-a[i])<=d))
count++;
if((a[i]>a[j]) && ((a[i]-a[j])<=d))
count++;
j++;
}
}
printf("%d\n",count*2);
return 0;
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 7b3335235775376e2078fec27c6c4f4b | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
#include<math.h>
int main(){
long int a,d;
scanf("%ld%ld",&a,&d);
long int ar[a];
for(int i=0;i<=a-1;i++){
scanf("%ld",&ar[i]);
}
long int c=0;
for (int i=0;i<=a-1;i++){
for(int j=0;j<=a-1;j++){
if(i!=j){
if (abs(ar[i]-ar[j])<=d){
c++;
}
}
}}
printf("%ld",c);
return 0;
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 51112585d67b0570e32a78d7c847e022 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include <stdio.h>
int main()
{long long int n,d;
scanf("%lld%lld",&n,&d);
long long int a[n+3],i,j,sum=0;
for(i=0;i<n;i++)
{scanf("%lld",&a[i]);}
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
{if(a[i]-a[j]<=d && a[i]-a[j]>=(-d) && i!=j)
sum=sum+1;}}
printf("%lld",sum);
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | e89f5995f6c2fead9ee1515b6cab6824 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
int main()
{
int n,m,a[100000],s=0,j,c,i;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j]){c=a[i];a[i]=a[j];a[j]=c; }
}
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[j]-a[i]<=m)s+=2;
}
}
printf("%d",s);
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | a36b352a3c4d77bf6da71520a92f2df1 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include <stdio.h>
int main()
{long long int n,d;
scanf("%lld%lld",&n,&d);
long long int a[n+3],i,j,sum=0;
for(i=0;i<n;i++)
{scanf("%lld",&a[i]);}
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
{if(a[i]-a[j]<=d && a[i]-a[j]>=(-d) && i!=j)
sum=sum+1;}}
printf("%lld",sum);
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 0f49d8fb73e428a3e2cfbfd8663da47c | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
#include<string.h>
int main()
{
int n,m,a[10000],i,b=0,j;
scanf("%d %d",&n,&m);
for(i=0; i<n; i++)
scanf("%d",&a[i]);
for(i=0; i<n; i++)
{
for(j=i+1; j<n; j++)
{
if((a[i]-a[j]<=m && a[i]-a[j]>=0)||(a[j]-a[i]<=m && a[j]-a[i]>=0))
b+=2;
}
}
printf("%d",b);
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 8eac923be6a9abca38f5f3f4625d3ef1 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | /******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n = 0;
long int d,ans = 0;
scanf("%d %ld",&n,&d);
long int a[n];
for (int i = 0;i < n;i++){
scanf("%ld",&a[i]);
for (int j = 0; j < i;j++){
if (abs(a[i]-a[j])<= d){
ans += 2;
}
}
}
printf("%ld",ans);
return 0;
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | e26ff727f6db85b0c0a541ddbfdc297d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include <stdio.h>
int main()
{long long int n,d;
scanf("%lld%lld",&n,&d);
long long int a[n+3],i,j,sum=0;
for(i=0;i<n;i++)
{scanf("%lld",&a[i]);}
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
{if(a[i]-a[j]<=d && a[i]-a[j]>=(-d) && i!=j)
sum=sum+1;}}
printf("%lld",sum);
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 2e560da3ea4b75776fdbdbe8ed8e3219 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
int main()
{
int n,d,i,j,x,result=0;
scanf("%d %d",&n,&d);
int a[n];
for(i=0; i<n; i=i+1)
{
scanf("%d",&a[i]);
}
for(i=0; i<n; i=i+1)
{
for(j=0; j<n; j=j+1)
{
if(i!=j)
{
x=abs (a[i]-a[j]);
if(x<=d || x==0)
{
result=result+1;
}
}
}
}
printf("%d\n",(result));
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 425eb6b3d6741fbe3ffa56fd798d9bde | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int n,*a,d;
scanf("%d%d",&n,&d);
a = (int*)malloc(sizeof(int)*n);
int i,j,s,count = 0;
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
for(i=0; i<n-1; i++)
{
for(j=i+1; j<n; j++)
{
s = a[i]-a[j];
if(s<0){s=-s;}
if(s<=d){count++;}
}
}
printf("%d\n",count*2);
return 0;
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 7068602a76effe484109d51302712793 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include <stdio.h>
#include <stdlib.h>
int main () {
long long int n, i, d, j, count = 0;
scanf("%lld %lld", &n , &d);
long long int arr[n];
for (i = 0; i < n; i++){
scanf("%lld", &arr[i]);
}
for (i = 0; i < n; i++){
for(j = 0; j < n; j++){
if ( i != j && abs(arr[i]-arr[j]) <= (d)){
count++;
}
}
}
printf("%lld", count);
return 0;
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 6f1e9af9fbc284660356df886fc8c8c0 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
int main()
{
int sum,n,d,arr[1000],i,j,k,l,m;
scanf("%d %d",&n,&d);
for(i=0; i<n; i++)
{
scanf("%d",&arr[i]);
}
sum=0;
for(i=0; i<n; i++)
{
for(j=i+1; j<n; j++)
{
l=arr[i]-arr[j];
if(l<0)
l*=-1;
if(l<=d)
{
sum+=2;
}
/*if(i==n-2)
{l=arr[n-1]-arr[0];if(l<0)l*=-1;//
if(l<=d)
{
sum+=2; printf("%d\n",sum);
}
}*/
}
}
printf("%d",sum);
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 02be0a2bea8ca088d208f74c4e5f6bf3 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
#include<math.h>
#define lli long long int
int main(){
lli i, j, n, d, ways=0;
scanf("%lld %lld", &n, &d);
lli arr[n+1];
for(i=0; i<n; i++){
scanf("%lld", &arr[i]);
}
for(i=0; i<n; i++){
for(j=i+1; j<n; j++){
if(abs(arr[i]-arr[j])<=d){
ways=ways+2;
}
}
}
printf("%lld\n", ways);
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 9ce02547bb0084292e488ab02a24f9eb | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
int main(void)
{
unsigned long long int n,count=0,i,j,temp=0;
unsigned long long d,a[1001];
scanf("%llu %llu",&n,&d);
for(i=0;i<n;i++)
{
scanf("%llu",&a[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>=a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++){
if(abs(a[i]-a[j])<=d)
count=count+2;
}
}
printf("%llu",count);
return 0;
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 80d5e3319f6cdfdc770d195b1c813cdf | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include <stdio.h>
int main()
{
int n, d, j, i, c = 0, t, a[1001];
scanf("%d%d", &n, &d);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (j = 1; j < n; j++)
for (i = 0; i < n - 1; i++)
if (a[i] < a[i + 1])
t = a[i], a[i] = a[i + 1], a[i + 1] = t;
for (i = 0; i < n - 1; i++)
for (j = i + 1; j < n; j++)
if (a[i] - a[j] <= d)
c++;
else
break;
printf("%d\n", 2 * c);
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 3efdecd4d35b189c3119ec5e640f6a00 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h> //AA06( 07/ 04/ 20) If u see my code, Have a Good Day!
#include<math.h>
int main()
{
long long int n, d, i, j, A[10000], x = 0;
scanf("%lld%lld", &n, &d);
for(i = 0; i < n; i++) {
scanf("%lld", &A[i]);
}
for(i = 0; i < n; i++) {
for(j = i + 1; j < n; j++) {
if(abs(A[i] - A[j]) <= d) {
x++;
}
}
}
printf("%lld\n", x * 2);
return 0;
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 3a273851eac35ef6e4ed61a577616036 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
int main()
{
int n,ct=0;
long d;
scanf("%d %I64ld",&n,&d);
int H[n];
for(int i=0;i<n;i++)
{
scanf("%d",&H[i]);
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(H[i]>H[j])
{
if((H[i]-H[j])<=d)
{
ct=ct+1;
}
}
else
{
if((H[j]-H[i])<=d)
{
ct=ct+1;
}
}
}
}
printf("%d",ct-n);
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | c26e91bdd72537cf856e4ecb851954e1 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int num[1000],i,n,d,t,j,count=0;
scanf("%d%d",&n,&d);
for(i=0;i<n;i++)
{
scanf("%d",&num[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
t=abs(num[j]-num[i]);
if((i!=j)&&(t<=d))
{
count++;
}
}
}
printf("%d",count);
return 0;
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 2dc72b239eb670d730e5c77fd63b4b0a | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int n,m;
scanf("%d %d",&n,&m);
int a[n],i,x=0,j;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(j==i)
continue;
if(abs(a[i]-a[j])<=m)
{
x++;
}
}
}
printf("%d\n",x);
return 0;
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 5ef66d99bed343a8ce847f3fc3adf490 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
#include<math.h>
int main()
{
int n,d,i,j;
scanf("%d%d",&n,&d);
int a[n];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int x=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i!=j&&abs(a[i]-a[j])<=d)
{
x++;
}
else
{
continue;
}
}
}
printf("%d",x);
return 0;
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 0e3f6580a2816529b320396ec730472f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include <stdio.h>
int main()
{
int n,d,i,j,count=0;
scanf("%d %d",&n,&d);
int ara[n];
for(i=0;i<n;i++)
{
scanf("%d",&ara[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(ara[i]==ara[j])
{
count++;
}
else if(ara[i]>ara[j] && ara[i]-ara[j]<=d)
{
count++;
}
else if(ara[i]<ara[j] && ara[j]-ara[i]<=d)
{
count++;
}
}
}
printf("%d",2*count);
return 0;
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 0d3c714f55fdfb6d11a755d01ab48b6d | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | int comparetor (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int main()
{
int n,d;
scanf("%d %d",&n,&d);
int a[2000]={};
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
qsort (a, n, sizeof(int), comparetor );
int j=0,k=1,c=0,count=0;
while(j<n)
{
if((a[j+k]-a[j]<=d) && (j+k<n))
{
c++;
k++;
}
else
{
count+=(c*2);
//printf("%d ",c);
k=1;
c=0;
j++;
//printf("%d\n",count);
}
if(j==n)
break;
}
printf("%d",count);
return 0;
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | f99c523aef40d65435076668527b5971 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
int main()
{int n,i,j,temp,count=0;
long long int d;
scanf("%d%lld",&n,&d);
int a[n];
for(i=0;i<n;i++)
{scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
{ if(i!=j)
{if((a[i]-a[j])<=d&&(a[i]-a[j])>=(-d))
count++;
}
}
}
printf("%d",count);
return 0;
}
| |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | b82174a6c5fe41d8e6da80d4ef45d032 | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include<stdio.h>
int main()
{
int n,i=0,j,count=0;
long int d;
scanf("%d",&n);
scanf("%ld",&d);
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if((a[i]-a[j])<=d&&(a[i]-a[j])>0)
count+=2;
if((a[j]-a[i])<=d&&(a[j]-a[i])>0)
count+=2;
if((a[i]-a[j])==0)
count+=2;
}
}
printf("%d",count);
return 0;
} | |
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different. | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d. | C | d7381f73ee29c9b89671f21cafee12e7 | 09d75b18a8ca23bfe72d80494d55702f | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"brute force"
] | 1286002800 | ["5 10\n10 20 50 60 65", "5 1\n55 30 29 31 55"] | null | PASSED | 800 | standard input | 2 seconds | The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109. | ["6", "6"] | #include <stdio.h>
int main()
{long long int n,d;
scanf("%lld%lld",&n,&d);
long long int a[n+3],i,j,sum=0;
for(i=0;i<n;i++)
{scanf("%lld",&a[i]);}
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
{if(a[i]-a[j]<=d && a[i]-a[j]>=(-d) && i!=j)
sum=sum+1;}}
printf("%lld",sum);
} | |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | b7e91a49cb10dca7f0019454b1305928 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include<stdio.h>
#include<string.h>
char dir[20001]={"/"};
int top=1;
void make(char *s)
{
int i;
if(strcmp(s,"/")==0)
{
if(top>1)
{
dir[0]='/';
dir[1]='\0';
top=1;
}
}
else if(strcmp(s,"../")==0)
{
if(top>1)
{
dir[top-1]='\0';
top-=2;
while(dir[top]!='/')
{
dir[top]='\0';
top--;
}
top++;
}
}
else
{
for(i=0;i<strlen(s);i++)
dir[top++]=s[i];
dir[top]='\0';
}
}
int main()
{
char cm[2001],s[2001];
int n,i,j,x;
scanf("%d",&n);
for(x=0;x<n;x++)
{
scanf("%s",cm);
if(strcmp(cm,"pwd")==0)
printf("%s\n",dir);
else
{
scanf("%s",cm);
i=0;
if(cm[i]=='/'&&i==strlen(cm)-1)
{
make("/");
}
else
{
j=strlen(cm);
cm[j]='/';
cm[j+1]='\0';
j=0;
while(i<strlen(cm))
{
if(cm[i]!='/')
{
s[j++]=cm[i++];
}
else
{
i++;
s[j]='/';
s[j+1]='\0';
j=0;
make(s);
}
}
}
}
}
//system("pause");
return 0;
}
| |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | 7f8b6026f2d59b836d1d8b60e5366a6f | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include<stdio.h>
#include<string.h>
char pwd[20000];
int pwdlen=1;
char option[400];
void parse()
{
int cur;
for (cur=0;option[cur]!=0;cur++)
{
if (option[cur]=='.')
{
cur+=2;
if (option[cur]==0) { cur--; }
pwdlen--;
while (pwd[pwdlen-1]!='/') { pwdlen--; }
continue;
}
pwd[pwdlen++]=option[cur];
}
if (pwd[pwdlen-1]!='/') { pwd[pwdlen++]='/'; }
pwd[pwdlen]=0;
}
int main()
{
int n;
int i;
char cmd[20];
pwd[0]='/';
pwd[1]=0;
scanf("%d",&n);
for (i=0;i<n;i++)
{
scanf("%s",cmd);
if (!strcmp(cmd,"pwd"))
{
printf("%s\n",pwd);
continue;
}
scanf("%s",option);
if (option[0]=='/') { pwdlen=0; }
parse();
}
return 0;
}
| |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | ef7ca76816f02ec5eb442259850c0364 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
char cwd[105020]={'/'}, cmd[20200], *s;
int c=1,n,i;
int main(void) {
scanf("%d\n", &n);
for (i=0; i<n; ++i) {
s=fgets(cmd, 20200, stdin);
if (!strncmp(cmd, "pwd", 3)) {
printf("%s\n", cwd);
} else {
s+=3;
if (*s=='/') {
c=1;
memset(cwd, 0, sizeof cwd);
cwd[0]='/';
++s;
}
while (*s!='\n'&&*s!='\0') {
if (!strncmp(s, "..", 2)) {
do {
cwd[--c]='\0';
} while (cwd[c-1]!='/');
s+=3;
} else {
do {
cwd[c++]=*s++;
} while (*s!='/'&&!isspace(*s));
if (*s=='/') cwd[c++]=*s++;
}
}
if (cwd[c-1]!='/') cwd[c++]='/';
}
}
exit(EXIT_SUCCESS);
}
| |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | ab732e83cb282f50cbf62c9234cf900c | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include<stdio.h>
char* stack[100000];
int top=0;
void print_stack()
{
int i;
//if(top!=0)
printf("/");
for(i=1;i<=top;i++)
{
//if(stack[i]!='\0')
printf("%s/",stack[i]);
}
printf("\n");
}
void change_stack(char temp[])
{
if(temp[0]=='.'&&top!=0)
top--;
else if(temp[0]!='\0')
{
top++;
stack[top]=temp;
}
}
int main()
{
int n,i,j,k,l=0;
char s[250];
char p[100000][50];
scanf("%d",&n);
getchar();
char first[2]="/\0";
stack[0]=first;
for(i=0;i<n;i++)
{
k=0;
scanf("%[^\n]s",s);
if(s[0]=='p')
print_stack();
else if(s[0]=='c')
{
if(s[3]=='/')
top=0;
for(j=3;s[j]!='\0';j++)
{
if(s[j]=='/')
{
p[l][k]='\0';
if(k!=0)
change_stack(p[l]);
k=0;
l++;
}
else
{
p[l][k++]=s[j];
// print_stack();
}
}
p[l][k]='\0';
if(k!=0)
{
change_stack(p[l]);
l++;
}
// printf("%s\n",stack[top]);
}
getchar();
}
return 0;
}
| |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | c4b2d53ce125bf8b22fcd4902a9fcfa2 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
char **split(char s[], char delim, uint32_t *n) {
uint32_t len = 0, slen = 0; {
bool was_delim = true;
uint32_t i;
for(i = 0; s[i] != '\0'; i++) {
slen++;
if(s[i] == delim) {
was_delim = true;
continue;
}
if(was_delim) {
len++;
was_delim = false;
}
}
slen++;
}
char **res = malloc(len * sizeof(char*));
char *sdup = malloc(slen + 1);
bool was_delim = true;
uint32_t i, j = 0;
for(i = 0; s[i] != '\0'; i++) {
if(s[i] == delim) {
was_delim = true;
sdup[i] = '\0';
continue;
}
sdup[i] = s[i];
if(was_delim) {
res[j] = &(sdup[i]);
j++;
was_delim = false;
}
}
sdup[i] = '\0';
*n = len;
return res;
}
typedef struct list {
char *s;
struct list *next;
} List;
void pwd(List *path) {
printf("/");
while(path) {
printf("%s/", path->s);
path = path->next;
}
printf("\n");
return;
}
void chdir(List **path, char *dir) {
List *n = malloc(sizeof(List));
n->s = malloc(strlen(dir) + 1);
strcpy(n->s, dir);
n->next = NULL;
List *curr = *path;
if(curr) {
while(curr->next) {
curr = curr->next;
}
curr->next = n;
} else {
*path = n;
}
return;
}
void cdup(List **path) {
List **curr;
for(curr = path; *curr;) {
List *entry = *curr;
if(!entry->next) {
*curr = NULL;
free(entry->s);
free(entry);
} else {
curr = &entry->next;
}
}
return;
}
void cd(List **path, char *arg) {
if(arg[0] == '/') {
while(*path) {
cdup(path);
}
}
uint32_t sn;
char **segs = split(arg, '/', &sn);
uint32_t j;
for(j = 0; j < sn; j++) {
if(!strcmp(segs[j], "..")) {
cdup(path);
} else {
chdir(path, segs[j]);
}
}
free(segs[0]);
free(segs);
return;
}
int main() {
uint32_t n;
scanf("%"PRIu32, &n);
char cmds[n][205]; {
uint32_t i;
for(i = 0; i < n; i++) {
fgets(cmds[i], 205, stdin);
if(cmds[i][0] == '\n') {
i--;
}
size_t len = strlen(cmds[i]);
if(cmds[i][len-1] == '\n') {
cmds[i][len-1] = '\0';
}
}
}
List *path = NULL;
uint32_t i;
for(i = 0; i < n; i++) {
uint32_t n;
char **spt = split(cmds[i], ' ', &n);
if(!strcmp(spt[0], "pwd")) {
pwd(path);
}
if(!strcmp(spt[0], "cd")) {
cd(&path, spt[1]);
}
free(spt[0]);
free(spt);
}
return 0;
}
| |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | 00244eecc5278db5095944c209bc5e49 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
char command[5],strcd[10000]="/",string[201],str[201];
int main()
{
int n,i,m,nn,j;
scanf("%d",&m);
while(m--)
{
scanf("%s",command);
if(command[0]=='p')
{
printf("%s\n",strcd);
}
else
{
memset(string,0,sizeof(string));
scanf("%s",string);
n=strlen(string);
for(i=0,j=0;i<n;i++)
{
if(string[0]=='/')
{
memset(strcd,0,sizeof(strcd));
strcd[0]='/';
string[0]=0;
continue;
}
if(string[i]!='/')
{
str[j++]=string[i];
}
if(string[i]=='/'||i==n-1)
{
if(str[0]=='.')
{
nn=strlen(strcd);
strcd[nn-1]=0;
for(j=nn-2;strcd[j]!='/';j--)
{
strcd[j]=0;
}
}
else
{
strcat(strcd,str);
strcat(strcd,"/");
}
j=0;
memset(str,0,sizeof(str));
}
}
}
}
return 0;
}
| |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | 285083de9181d3f3c0f74daea71d713a | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int changeDirectory(char *, char *, int);
void strchar(char *, char);
int main(int argc, char *argv[]){
int n;
scanf("%i",&n);
if (n>50|| n<1)
return 1;
char *stkcmd[n],temp[250],output[1500],*stkdir[n];
// struct Cola dirs;
for (int i = 0; i<n; i++){
*(stkcmd+i)=(char *) calloc(225,sizeof(char));
*(stkdir+i)=(char *) calloc(225,sizeof(char));
scanf("%s",*(stkcmd+i));
if(!strcmp(*(stkcmd+i),"cd")){
scanf("%s",temp);
strcat(*(stkcmd+i),temp);
}
//printf("%s\n",*(stkcmd+i));
}
*(output)='/';
*(output+1)='\0';
for (int i=0; i<n; i++){
if (!strcmp(*(stkcmd+i),"pwd"))
printf("%s\n",output);
else if(!strncmp(*(stkcmd+i),"cd",2)){
changeDirectory(*(stkcmd+i)+2,output, n);
}
}
return 0;
}
int changeDirectory(char *directorio,char * output, int n){
//printf("%s\n",directorio);
char dir[100];
int i,j,k;
if (*directorio=='/'){
*output='/';
*(output+1)='\0';
}
for (i=0; *(directorio+i)!='\0'; i++){
// printf("i=%i\n",i);
if (*(directorio+i)=='/'||*(directorio+i)!='.'){
if(*(directorio+i)=='/')
i++;
*dir='\0';
for (j=i; *(directorio+j)!='/'&&*(directorio+j)!='\0' ;j++){
//printf("j=%i\n",j);
strchar(dir,*(directorio+j));
//printf("%s\n",dir);
}
// (*(directorio+j)=='\0')
//break;
//printf("%s\n",output);
strcat(output,dir);
//printf("%s\n",output);
strchar(output,'/');
//printf("%s\n",output);
i=j;
}
else if(*(directorio+i)=='.'&&*(directorio+i+1)=='.'){
for (j=0; *(output+j)!='\0';j++){
//printf("%c\t",*(output+j));
}
//printf("\n");
for (k=j-2; *(output+k)!='/';k--){
//printf("%c\t",*(output+k));
}
//printf("%i - %i\n",i,k);
if(k+i==0){
*(output+k)='/';
*(output+k+1)='\0';
}
*(output+k+1)='\0';
i+=2;
}
}
return 0;
}
void strchar(char *C, char c){
int i;
for (i=0; *(C+i)!='\0'; i++){
}
*(C+i)=c;
*(C+i+1)='\0';
}
| |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | 796be50c3bb76c43b99bb6e281e0d2c3 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include<stdio.h>
#include<string.h>
char a[10001][10001];
int top;
int letter_count;
int n;
void push(char value);
void pop();
void TOP();
void print();
void clean();
void clean_word();
//void clean_word1();
int main(){
int t,i;
char s[201];
scanf("%d",&t);
while(t--){
scanf("%s",s);
if(s[0]=='p')
print();
else if(s[0]=='c'){
scanf("%s",s);
n=strlen(s);
if(s[0]=='/'){
//absolute path
top=0;
letter_count=0;
clean();
for(i=1;i<n;i++){
if(s[i]=='.'&&s[i+1]=='.'){
clean_word();
}
else if(s[i]=='.'&&s[i-1]=='.');
else if(s[i]=='/'&&s[i+1]=='.');
else if(s[i]=='/'){
top++;
letter_count=0;
push('/');
}
else
push(s[i]);
}
}
else if(s[0]=='.'&&s[1]=='.'){
//relative path
clean_word();
for(i=2;i<n;i++){
if(s[i]=='.'&&s[i+1]=='.'){
clean_word();
}
else if(s[i]=='.'&&s[i-1]=='.');
else if(s[i]=='/'&&s[i-1]=='.'&&s[i+1]=='.');
else if(s[i]=='/'&&s[i+1]=='.');
else if(s[i]=='/'){
top++;
letter_count=0;
push('/');
}
else
push(s[i]);
}
}
else{
//relative path
if(a[0][1]=='\0'&&top==0){
letter_count=1;
}
else{
top++;
letter_count=0;
push('/');
}
for(i=0;i<n;i++){
if(s[i]=='.'&&s[i+1]=='.'){
clean_word();
}
else if(s[i]=='.'&&s[i-1]=='.');
else if(s[i]=='/'&&s[i+1]=='.');
else if(s[i]=='/'){
top++;
letter_count=0;
push('/');
}
else
push(s[i]);
}
}
}
}
return 0;
}
//------------------------------------------------------------------------------
void push(char value){
a[top][letter_count++]=value;
}
void pop(){
if(top==0){
return;
}
else{
top--;
// printf("%d\n",top);
}
}
//void TOP(){
// printf("%d\n",a[top]);
//}
void print(){
int i,j;
// printf ("the value of top is %d\n", top);
// printf ("the value of 1st elem is %c\n", a[0][0]);
// printf ("the value of 2nd elem is %c\n", a[0][1]);
a[0][0]='/';
for(i=0;i<=top;i++){
for(j=0;a[i][j]!='\0';j++)
printf("%c",a[i][j]);
}
if (top != 0||n!=0)
printf("/");
printf("\n");
}
void clean(){
int i,j;
for(i=0;i<10001;i++){
for(j=0;j<10001;j++)
a[i][j]='\0';
}
push('/');
}
/*void clean_word1(){
int i;
for(i=0;i<201;i++){
a[top-1][i]='\0';
}
}*/
void clean_word(){
int i;
for(i=0;i<10001;i++){
a[top][i]='\0';
}
// printf("clean:%d\n",top);
top--;
}
| |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | 339c1dfbba60e82480a90ffad9602a0a | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | /* Problem: 158C - Cd and pwd commands */
/* Solver: Gusztav Szmolik */
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
struct dir
{
unsigned char* nm;
struct dir* pv;
struct dir* nx;
};
struct dir* ph;
void clrmem (void);
int main ()
{
unsigned short n;
struct dir* pl;
unsigned short i;
unsigned char cm[5];
unsigned short l;
unsigned short j;
struct dir* p;
unsigned char pm[202];
unsigned short k;
unsigned char nm[201];
unsigned short ln;
if (scanf("%hu",&n) != 1)
return -1;
if (n < 1 || n > 50)
return -1;
ph = pl = NULL;
for (i = 0; i < n; i++)
{
if (scanf("%4s",cm) != 1)
return -1;
l = strlen (cm);
for (j = 0; j < l; j++)
if (isupper(cm[j]))
cm[j] = tolower (cm[j]);
if (strcmp(cm,"cd") && strcmp(cm,"pwd"))
{
clrmem ();
return -1;
}
if (!strcmp(cm,"pwd"))
{
printf ("/");
for (p = ph; p != NULL; p = p->nx)
printf ("%s/",p->nm);
printf ("\n");
}
else
{
if (scanf("%201s",pm) != 1)
{
clrmem ();
return -1;
}
l = strlen (pm);
if (l > 200)
{
clrmem ();
return -1;
}
k = 0;
for (j = 0; j < l; j++)
{
if (pm[j] == '/' && pm[j+1] == '/')
{
clrmem ();
return -1;
}
if (pm[j] == '/' && j && j == l-1)
{
clrmem ();
return -1;
}
if (pm[j] == '/' && !j)
{
clrmem ();
ph = pl = NULL;
}
if (pm[j] != '/')
nm[k++] = pm[j];
if ((pm[j] == '/' || j == l-1) && j)
{
nm[k] = '\0';
ln = strlen (nm);
for (k = 0; k < ln; k++)
{
if (!isalpha(nm[k]) && nm[k] != '.')
{
clrmem ();
return -1;
}
if (nm[k] == '.' && strcmp(nm,".."))
{
clrmem ();
return -1;
}
if (isupper(nm[k]))
nm[k] = tolower (nm[k]);
}
if (!strcmp(nm,"..") && ph == NULL)
{
clrmem ();
return -1;
}
if (!strcmp(nm,".."))
{
p = pl;
pl = pl->pv;
if (pl == NULL)
ph = NULL;
else
pl->nx = NULL;
free (p->nm);
free (p);
}
else
{
p = (struct dir*)malloc(sizeof(struct dir));
if (p == NULL)
{
clrmem ();
return -1;
}
p->pv = pl;
p->nx = NULL;
if (ph == NULL)
ph = p;
else
pl->nx = p;
pl = p;
p->nm = (unsigned char*)malloc((ln+1)*sizeof(unsigned char));
if (p->nm == NULL)
{
clrmem ();
return -1;
}
strcpy (p->nm,nm);
}
k = 0;
}
}
}
}
clrmem ();
return 0;
}
void clrmem ()
{
struct dir* p;
struct dir* pn;
p = ph;
while (p != NULL)
{
pn = p->nx;
if (p->nm != NULL)
free (p->nm);
free (p);
p = pn;
}
}
| |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | 7183fec5be16720cfe9c7cf6173d2c33 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include <stdio.h>
#include <string.h>
int main()
{
int n, i, j, k, l, len;
char cd[210], command[10], word[210], path[20000];
scanf ("%d", &n);
path[0] = '/';
path[1] = '\0';
j = 1;
while (n--)
{
scanf ("%s", command);
if (command[0] == 'p')
printf ("%s\n", path);
else
{
scanf ("%s", cd);
len = strlen(cd);
if (cd[0] == '/')
{
path[0] = '/';
path[1] = '\0';
j = 1;
}
i = 0;
l = 0;
while (i <= len)
{
if (cd[i] == '/' || cd[i] == '\0')
{
if (!l);
else if (l == 2 && word[0] == '.' && word[1] == '.')
{
path[--j] = '\0';
while (path[j] != '/')
path[j] = '\0', j--;
j++;
}
else
{
k = 0;
while (k < l)
{
path[j] = word[k];
j++;
k++;
}
path[j++] = '/';
path[j] = '\0';
}
l = 0;
}
else
word[l++] = cd[i];
i++;
}
if (l)
{
k = 0;
while (k < l)
{
path[j] = word[k];
j++;
k++;
}
path[j++] = '/';
path[j] = '\0';
}
}
}
return 0;
} | |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | 71cb4c697cb5219d9dba659139822c2a | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include<stdio.h>
#include<string.h>
char now[10100]={"/"},pros[201];
int main()
{
// freopen("asdf","r",stdin);
short N,n,m,M;
char cmd[201],*a,*b;
scanf("%hd",&N);
getchar();
for(n=0;n<N;++n)
{
scanf("%s",cmd);
if(!strcmp(cmd,"pwd"))
{
puts(now);
continue;
}
scanf("%s",cmd);
if(cmd[0]=='/')
strcpy(now,cmd);
else
strcat(now,cmd);
strcat(now,"/");
// puts(now);
m=strlen(now);
while(a=strchr(now,'.'))
{
for(b=a-2;*b!='/';--b);
strcpy(b,a+2);
}
}
return 0;
}
| |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | 282e7c7147dffb1c47ab987300074620 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
char command[5],strcd[10000]="/",string[201],str[201];
int main()
{
int n,i,m,nn,j;
scanf("%d",&m);
while(m--)
{
scanf("%s",command);
if(command[0]=='p')
{
printf("%s\n",strcd);
}
else
{
memset(string,0,sizeof(string));
scanf("%s",string);
n=strlen(string);
for(i=0,j=0;i<n;i++)
{
if(string[0]=='/')
{
memset(strcd,0,sizeof(strcd));
strcd[0]='/';
string[0]=0;
continue;
}
if(string[i]!='/')
{
str[j++]=string[i];
}
if(string[i]=='/'||i==n-1)
{
if(str[0]=='.')
{
nn=strlen(strcd);
strcd[nn-1]=0;
for(j=nn-2;strcd[j]!='/';j--)
{
strcd[j]=0;
}
}
else
{
strcat(strcd,str);
strcat(strcd,"/");
}
j=0;
memset(str,0,sizeof(str));
}
}
}
}
return 0;
} | |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | 25df32029c7719410ed59700e4481187 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#define STSIZE 5000
typedef struct path
{
char name[200];
} path_t;
path_t st[STSIZE];
path_t *lst = st;
void exec_pwd()
{
path_t *cur = st;
printf("/");
while (cur != lst)
{
printf("%s/", cur->name);
cur++;
}
printf("\n");
}
void push(const char *s)
{
lst->name[0] = 0;
strcpy(lst->name, s);
lst++;
}
void pop()
{
if (lst != st)
{
lst--;
}
}
void clear()
{
lst = st;
}
void exec_cd(char *s)
{
int l = strlen(s);
if (l > 0 && s[0] == '/')
{
clear();
s++;
l--;
}
char *cmd = s;
for (int i = 0; i < l + 1; i++)
{
// printf(" check '%c'\n", s[i]);
if (s[i] == '/' || s[i] == 0)
{
s[i] = 0;
// printf("cmd: '%s'\n", cmd);
if (strlen(cmd) == 2 && strcmp(cmd, "..") == 0)
pop();
else
push(cmd);
cmd = s + i + 1;
}
}
}
int main()
{
int n;
scanf("%d", &n);
char cmd[32];
char args[256];
while (n-- > 0)
{
cmd[0] = 0;
scanf("%s", cmd);
if (strcmp(cmd, "pwd") == 0)
{
exec_pwd();
}
else
{
args[0] = 0;
scanf("%s", args);
// printf("cd command with '%s' args\n", args);
exec_cd(args);
}
}
// exec_pwd();
fflush(stdout);
return 0;
} | |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | d92deab3dfb815877ff5eaf760005914 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include<stdio.h>
#include<string.h>
int main()
{
int n,top,i,len;
char s[4],s1[200],stack[20000] = {'/'};
scanf("%d",&n);
top = 0;
while(n--)
{
scanf("%s",s);
if(strcmp(s,"pwd")==0)
{
for(i=0;i<=top;++i)
printf("%c",stack[i]);
printf("\n");
}
else if(strcmp(s,"cd") == 0)
{
scanf("%s",s1);
if(strcmp(s1,"..") == 0)
{
top--;
while(top>0)
{
top--;
if(stack[top] == '/')
break;
}
}
else
{
if(s1[0] == '/')
top = -1;
len = strlen(s1);
for(i=0;i<len;++i)
{
if(s1[i] == '.')
{
top--;
while(top>0)
{
top--;
if(stack[top] == '/')
break;
}
i+=2;
}
else
{
top++;
stack[top] = s1[i];
}
/* printf("Stack :\n");
for(j=0;j<=top;++j)
printf("%c",stack[j]);
printf("\n");*/
}
if(stack[top] != '/')
{
top++;
stack[top] = '/';
}
}
}
}
return 0;
}
| |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | fdc2f321f9015fd49aed40be520a3635 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include <stdio.h>
#include <string.h>
int main()
{
char cd[201],c[10],p[10000],word[201];
int n,m,i,j,k,l;
p[0]='/';
p[1]='\0';
j=1;
scanf("%d",&n);
while(n--)
{
scanf("%s",c);
if(strcmp("pwd",c)==0)
printf("%s\n",p);
else
{
scanf("%s",cd);
m=strlen(cd);
if (cd[0] == '/')
{
p[0] = '/';
p[1] = '\0';
j=1;
}
i=l=0;
while(i<=m)
{
if (cd[i] == '/' || cd[i] == '\0')
{
if(l==0)
{
i++;
continue;
}
else if (word[0]=='.')
{
p[j-1] = '\0';
while (p[j-1] != '/')
{
p[j-1] = '\0';
j--;
}
}
else
{
k=0;
while(k<l)
{
p[j]=word[k];
j++;
k++;
}
p[j++] = '/';
p[j] = '\0';
}
l = 0;
}
else
{
word[l]=cd[i];
l++;
}
i++;
}
if (l)
{
k=0;
while (k<l)
{
p[j] = word[k];
j++;
k++;
}
p[j++] = '/';
p[j] = '\0';
}
}
}
return 0;
} | |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | e9ee238a3da081d3af3e242d4ef8af2d | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include <stdio.h>
#include <string.h>
int main()
{
int i,n,len;
char string[1000000],*command,incommand[201];
char *substr = NULL;
scanf("%d",&n);
string[0] = '/';
string[1] = '\0';
while(n--)
{
scanf("%s",incommand);
if(strcmp(incommand,"pwd") == 0)
printf("%s\n",string);
else
{
scanf("%s",incommand);
command = incommand;
if(command[0] == '/')
{
string[0] = '/';
string[1] = '\0';
substr = strtok(command," /");
while(substr != NULL)
{
if(strcmp(substr,"..") == 0)
{
len = strlen(string);
string[len-1] = '\0';
for(i = len-2;string[i] != '/';i--)
string[i] = '\0';
}
else
{
strcat(string,substr);
strcat(string,"/\0");
}
substr = strtok(NULL," /");
}
}
else
{
//relative
substr = strtok(command," /");
while(substr != NULL)
{
if(strcmp(substr,"..") == 0)
{
len = strlen(string);
string[len-1] = '\0';
for(i = len-2;string[i] != '/';i--)
string[i] = '\0';
}
else
{
strcat(string,substr);
strcat(string,"/\0");
}
substr = strtok(NULL," /");
}
}
}
}
return 0;
}
| |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | 55666f24106bd24732320d7bbd9ae49a | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include <stdio.h>
#define N 5000
#define M 200
char s[N][M], x[2*M];
int h;
void printPath() {
int i=0;
printf("/");
for(i=0; i<h; i++) {
printf("%s/", s[i]);
}
printf("\n");
}
void changePath(char x[]) {
int i, j;
i=j=0;
if(x[0]=='/') {
h=0;
} else if(x[0]=='.') {
h--;
i++;
} else {
s[h][j]=x[i];
j++;
}
i++;
while(x[i]) {
if(x[i]=='/') {
i++;
if(x[i]=='.') {
s[h][0]=0;
if(!j) {
h--;
}
j=0;
i++;
} else {
if(j) {
s[h][j]=0;
h++;
}
s[h][0]=x[i];
j=1;
}
} else {
s[h][j]=x[i];
j++;
}
i++;
}
if(j) {
s[h][j]=0;
h++;
}
}
int main() {
int n;
h = 0;
scanf("%d", &n);
while(n--) {
scanf("%s", x);
if(x[0] == 'p') {
printPath();
} else {
scanf("%s", x);
changePath(x);
}
}
return 0;
}
| |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | 2e61e6b5ff3a06d20005128e7b06fe7b | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include <stdio.h>
typedef long long int LL;
char x[202][202];
char what[100000];
int xlen = 0;
void pushpop(int start,int end)
{
if(what[start]=='/')
start++;
int i,length=0;
//for(i=start;i<=end;i++)
// putchar(what[i]);
//putchar('\n');
if(what[start]=='.' && what[start+1]=='.')
xlen--;
else{
for(i=start;i<=end;i++)
{
if(what[i]=='/')
continue;
x[xlen][length]=what[i];
length++;
}
x[xlen][length]='\0';
xlen++;
}
//printf("DONE\n");
}
int main()
{
int t,i,start;char command[5];
scanf("%d",&t);
getchar();
while(t--)
{
scanf("%s",&command);
if(command[0]=='c')
{
start = 0;
scanf("%s",what);
for(i=0;what[i]!='\0';i++);
if(what[i-1]!='/')
{
what[i]='/';
what[i+1]='\0';
}
if(what[0]=='/')
xlen=0;
i = 0;
if(what[0]=='/')
i++;
for(;what[i]!='\0';i++)
{
if(what[i]=='/')
{
pushpop(start,i-1);
start=i;
}
}
}
else
{
putchar('/');
for(i=0;i<xlen;i++)
printf("%s/",&x[i]);
putchar('\n');
}
}
return 0;
}
| |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | 943f4e7d1283e6b2c8cb2983f90db23c | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include <stdio.h>
#include <string.h>
struct dic
{
char dicName[208];
struct dic *pre;
struct dic *next;
};
/*void printlink(struct dic *p)
{
while(p != NULL)
{
printf("%s->",p->dicName);
p=p->next;
}
printf("\n");
}*/
void print(struct dic *current)
{
//printf("kjfkjf");
current=current->next;
printf("/");
while(current != NULL)
{
printf("%s/",current->dicName);
current = current->next;
}
printf("\n");
}
int main()
{
char s[208];
char a[5];
char *cmd;
char *name;
int n;
scanf("%d",&n);
gets(a);
int i;
struct dic *head;
struct dic *p1;
struct dic *p2;
struct dic *current;
head = (struct dic *)malloc(sizeof(struct dic));
p1=head;
strcpy(head->dicName,"/");
head->next = NULL;
head->pre = NULL;
current = head;
for(i=0; i<n; i++)
{
memset(s,0,sizeof(s));
//gets(s);
//printf("%s\n",s);
scanf("%s",s);
//name = strtok(s," /");
cmd = s;
// printf("cmd: %s\n",cmd);
if (cmd[0]=='p')
print(current);
else
{
memset(s,0,sizeof(s));
scanf("%s",s);
// printf("**** %s\n",s);
if(s[0]=='/')
{
head->next = NULL;
p1 = head;
}
name = strtok(s,"/");
while(name != NULL)
{
//printf("...\n");
//printf("name:%s\n",name);
/*if(name == NULL)
break;*/
p2 = (struct dic *)malloc(sizeof(struct dic));
strcpy(p2->dicName,name);
//printf("%s\n",p2->dicName);
p2->pre = p1;
p1->next = p2;
p1 = p2;
p2->next = NULL;
name = strtok(NULL,"/");
}
//printlink(head);
//printf("******\n");
struct dic *p,*q;
p=head;
while(p != NULL )
{
if(strcmp(p->dicName,"..") == 0)
{
if(p->next != NULL)
{
p->pre->pre->next = p->next;
//printf("%s\n",p->pre->pre->dicName);
q = p->next;
q->pre = p->pre->pre;
p = q;
p1 = p;
}
else
{
p1 = p->pre->pre;
p->pre->pre->next = NULL;
p=NULL;
}
}
else
{
p1 = p;
p = p->next;
}
}
// printlink(head);
current = head;
}
//gets(s);
}
return 0;
}
| |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | 471e261a201085b8b1c66084c428ea39 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node *node_t;
typedef struct list *list_t;
struct node{
char path[201];
node_t next;
node_t prev;
};
struct list{
node_t path;
node_t last;
};
list_t add(list_t list, char *path){
node_t new = calloc(1, sizeof(struct node));
strcpy(new->path, path);
new->next = NULL;
if(list->path == NULL){
list->path = new;
list->last = new;
new->prev = NULL;
}
else{
list->last->next = new;
new->prev = list->last;
list->last = new;
}
return list;
}
list_t delete(list_t list){
if(list->path == list->last){
free(list->path);
list->path = NULL;
}
else{
node_t aux = list->last->prev;
free(list->last);
aux->next = NULL;
list->last = aux;
}
return list;
}
void print(list_t list){
node_t aux = list->path;
printf("/");
while(aux){
printf("%s/", aux->path);
aux = aux->next;
}
printf("\n");
}
void destroy(list_t list){
if(list){
node_t aux;
while(list->path){
aux = list->path;
list->path = list->path->next;
free(aux);
}
free(list);
}
}
int main(){
int n;
scanf("%d", &n);
char comm[4], path[201], *token;
list_t list = calloc(1, sizeof(struct list));
list->path = NULL;
list->last = NULL;
while(n--){
scanf("%s", comm);
if(comm[0] == 'p'){
print(list);
}
else{
scanf("%s", path);
if(path[0] == '/'){
destroy(list);
list = calloc(1, sizeof(struct list));
list->path = NULL;
list->last = NULL;
strcpy(path, path+1);
}
token = strtok(path, "/");
while(token != NULL){
if(!strcmp(token, "..")){
list = delete(list);
}
else{
list = add(list, token);
}
token = strtok(NULL, "/");
}
}
}
destroy(list);
}
| |
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory. | For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots. | C | 494ac937ba939db1dbc4081e518ab54c | 60ca81e885258dee8912e4ba8bf49997 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"data structures",
"implementation",
"*special"
] | 1330804800 | ["7\npwd\ncd /home/vasya\npwd\ncd ..\npwd\ncd vasya/../petya\npwd", "4\ncd /a/b\npwd\ncd ../a/b\npwd"] | null | PASSED | 1,400 | standard input | 3 seconds | The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names. | ["/\n/home/vasya/\n/home/\n/home/petya/", "/a/b/\n/a/a/b/"] | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
void moveleft(char *ch,int n);
void del_till_slash(char *ch);
char a[300],*dir,b[200][300],result[60][100000],tmp[100000];
/*tag��ʾ�Ƿ�Ӹ�Ŀ¼��ʼ��step��ʾ����cd����֮��Ŀ��*/
int i,j=0,k=0,n,tag,step=0,repeat[60];
int cmd[60];
memset(cmd,-1,sizeof(cmd));
memset(result,'\0',sizeof(result));
memset(repeat,-1,sizeof(repeat));
scanf("%d",&n);
getchar();
for(i=0;i<n;i++){
gets(a);
if(strcmp(a,"pwd")==0){
if(i!=0){
if(repeat[i-1]>0){
repeat[i]=1;
step+=1;
}
else{
cmd[i]=i-1;
step=2;
}
}
else{
cmd[i]=0;
result[0][0]='\0';
}
repeat[i]=1;
}
else{
moveleft(a,2);
a[0]='/'; //��ǰ����һ��/��Ϊ��ʹ��strtok�ֶ���ȡ
if(strchr(a,'/')!=0){
if(a[1]=='/')
tag=1;
else
tag=0;
for(dir=strtok(a,"/"),j=0;dir!=NULL;dir=strtok(NULL,"/"),j++){
strcpy(b[j],dir);
strcpy(tmp,result[i-step]);
if(strcmp(dir,"..")==0){
if(tag==0 && i!=0 && i!=1){
del_till_slash(tmp);
strcat(result[i],tmp);
tag=1;
}
else{
del_till_slash(result[i]);
}
continue;
}
else{
if(tag==0 && i!=0){
strcat(result[i],tmp);
tag=1;
}
}
strcat(result[i],"/");
strcat(result[i],b[j]);
}
step=1;
}
}
}
for(i=0;i<n;i++){
if(cmd[i]>=0){
j=i;
while(repeat[j++]!=-1)
printf("%s/\n",result[*(cmd+i)]);
}
}
return 0;
}
void moveleft(char *ch,int n){
int i;
for(i=0;i<strlen(ch)-n;i++){
*(ch+i)=*(ch+i+n);
}
*(ch+i)='\0';
}
void del_till_slash(char *ch){
int i=strlen(ch)-1;
while(*(ch+i)!='/'){
*(ch+i)='\0';
i--;
}
*(ch+i)='\0';
}
| |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | C | 1378b4c9ba8029d310f07a1027a8c7a6 | b994594d8a7a4be8a5c0e05e6260d4e3 | GNU C | output.txt | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1318919400 | ["5 5\n0 1 0 1 0", "2 1\n1 1"] | null | PASSED | 1,100 | input.txt | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. | ["2", "1"] | #include<stdio.h>
int main(){
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n,m,i,j,a[1001],temp=1;
int count;
scanf("%d %d",&n,&m);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
int pos=m-1;
for(i=0;i<n;i++){
if(a[pos]==0){
pos=(pos+1)%n;
}
else{printf("%d",pos+1);
return 0;
}
}
return 0;
}
| |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | C | 1378b4c9ba8029d310f07a1027a8c7a6 | d05c19d0beaac18311c9ac1dae0b85d0 | GNU C | output.txt | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1318919400 | ["5 5\n0 1 0 1 0", "2 1\n1 1"] | null | PASSED | 1,100 | input.txt | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. | ["2", "1"] | #include<stdio.h>
int main(){
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n,m,i,j,a[1001],temp=1;
int count;
scanf("%d %d",&n,&m);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
int pos=m-1;
for(i=0;i<n;i++){
if(a[pos]==0){
pos=(pos+1)%n;
}
else{printf("%d",pos+1);
return 0;
}
}
return 0;
} | |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | C | 1378b4c9ba8029d310f07a1027a8c7a6 | 2423bf2b3237327cc82aa92bcff0f4b3 | GNU C | output.txt | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1318919400 | ["5 5\n0 1 0 1 0", "2 1\n1 1"] | null | PASSED | 1,100 | input.txt | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. | ["2", "1"] | #include <stdio.h>
#include <string.h>
int main()
{
FILE *in, *out;
int n, k, a[10005], i, flag=0, flag2 = 0, l, r;
in = fopen("input.txt", "r");
out = fopen("output.txt", "w");
fscanf(in, "%d %d", &n, &k);
//scanf("%d %d", &n, &k);
for (i=1; i<=n; i++)
{
fscanf(in, "%d", &a[i]);
//scanf("%d", &a[i]);
if (!flag && a[i])
{
flag = 1;
l = i;
}
if (!flag2 && i>=k && a[i])
{
flag2 = 1;
r = i;
}
}
if (flag2)
fprintf(out, "%d\n", r);
//printf("%d\n", r);
else
fprintf(out, "%d\n", l);
fclose(in);
fclose(out);
return 0;
} | |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | C | 1378b4c9ba8029d310f07a1027a8c7a6 | d05c4d5e13644e828916cfed2be035f2 | GNU C | output.txt | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1318919400 | ["5 5\n0 1 0 1 0", "2 1\n1 1"] | null | PASSED | 1,100 | input.txt | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. | ["2", "1"] | #include <stdio.h>
#include <string.h>
int main()
{
int n,k,i,j;
FILE *fp,*fp2;
fp=fopen("input.txt","r");
fp2=fopen("output.txt","w");
fscanf(fp,"%d %d",&n,&k);
int a[n];
for(i=0;i<n;i++)
{
fscanf(fp,"%d",&a[i]);
}
for(j=k-1;j<n;j++)
{
if(a[j]==1)
{
fprintf(fp2,"%d\n",j+1);
return 0;
}
}
for(j=0;j<k;j++)
{
if(a[j]==1)
{
fprintf(fp2,"%d\n",j+1);
return 0;
}
}
return 0;
}
| |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | C | 1378b4c9ba8029d310f07a1027a8c7a6 | 83ba2319ca98d8c59a5e22f6373d38b1 | GNU C | output.txt | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1318919400 | ["5 5\n0 1 0 1 0", "2 1\n1 1"] | null | PASSED | 1,100 | input.txt | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. | ["2", "1"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int n,k,i;
FILE *fpi,*fpo;
fpi=fopen("input.txt","r");
fpo=fopen("output.txt","w");
fscanf(fpi,"%d%d",&n,&k);
int *arr=(int*)calloc(n,sizeof(int));
for(i=0;i<n;i++)
fscanf(fpi,"%d",&arr[i]);
i=k-1;
while(arr[i]!=1) {i++;if(i==n) i=0;}
fprintf(fpo,"%d",i+1);
fclose(fpi);
fclose(fpo);
return 0;
} | |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | C | 1378b4c9ba8029d310f07a1027a8c7a6 | bc7c716c5d095760747c007a911a72df | GNU C | output.txt | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1318919400 | ["5 5\n0 1 0 1 0", "2 1\n1 1"] | null | PASSED | 1,100 | input.txt | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. | ["2", "1"] | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
int k , n, i, a[1000];
FILE *f1, *f2;
f1 = fopen("input.txt", "r");
f2 = fopen("output.txt", "w");
fscanf(f1, "%d%d", &n, &k);
k--;
for(i = 0; i < n; i++)
fscanf(f1, "%d", &a[i]);
while(a[k] == 0)
{
if(k == n - 1)
k = 0;
else
k++;
}
fprintf(f2, "%d", k + 1);
return 0;
}
| |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | C | 1378b4c9ba8029d310f07a1027a8c7a6 | dc75ba24a752e54453491926146502ac | GNU C | output.txt | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1318919400 | ["5 5\n0 1 0 1 0", "2 1\n1 1"] | null | PASSED | 1,100 | input.txt | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. | ["2", "1"] | #include <stdio.h>
#include <string.h>
int main(void)
{
int i,n,k,arr[1005],res;
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
scanf("%d%d",&n,&k);
for(i=1;i<=n;i++)
scanf("%d",&arr[i]);
for(i=k;i<=n;)
{
if(arr[i]==1)
{
res=i;
break;
}
if(i==n)
i=1;
else
i++;
}
printf("%d\n",res);
return 0;
} | |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | C | 1378b4c9ba8029d310f07a1027a8c7a6 | e9751156ea38655ad57308d7e978b5d9 | GNU C | output.txt | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1318919400 | ["5 5\n0 1 0 1 0", "2 1\n1 1"] | null | PASSED | 1,100 | input.txt | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. | ["2", "1"] | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
int vis[1001];
int d[10001];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n,m;
int a[10001];
while(~scanf("%d %d",&n,&m))
{
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
int point;
int flag=0;
for(int i=m;i<=n;i++)
{
if(a[i]==1)
{
point=i;
flag=1;
break;
}
}
if(flag==1)
{
printf("%d\n",point);
continue;
}
for(int i=1;i<m;i++)
{
if(a[i]==1)
{
point=i;
flag=1;
break;
}
}
printf("%d\n",point);
}
}
| |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | C | 1378b4c9ba8029d310f07a1027a8c7a6 | f226783379f21b1a8e84f49f65ceab20 | GNU C | output.txt | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1318919400 | ["5 5\n0 1 0 1 0", "2 1\n1 1"] | null | PASSED | 1,100 | input.txt | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. | ["2", "1"] | #include<stdio.h>
int main()
{ int n,k,i,a[1005];
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
scanf("%d%d",&n,&k);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
r:
if(a[k-1]==0)
{
k++;
if(k>n)
{
k=1;
goto r;
}
goto r;
}
else
printf("%d",k);
return 0;
} | |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | C | 1378b4c9ba8029d310f07a1027a8c7a6 | bc66432a73e95f5cb92615795933991e | GNU C | output.txt | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1318919400 | ["5 5\n0 1 0 1 0", "2 1\n1 1"] | null | PASSED | 1,100 | input.txt | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. | ["2", "1"] | #include<stdio.h>
int main()
{
int n,k,i,j,min=0,ans=0;
FILE *in;
in=fopen("input.txt","r");
FILE *wr;
wr=fopen("output.txt","w");
fscanf(in,"%d%d\n",&n,&k);
// printf("%d%d",n,k);
// fscanf(in,"%d\n",k);
for(i=1;i<=n;i++)
{
fscanf(in,"%d",&j);
if(j==1&&min==0)
min=i;
if(i>=k&&j==1&&ans==0)
{
ans=i;
break;
}
}
if(ans==0)
fprintf(wr,"%d",min);
else
fprintf(wr,"%d",ans);
fclose(in);
fclose(wr);
return 0;
}
| |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | C | 1378b4c9ba8029d310f07a1027a8c7a6 | 1ea794e76e5f3f87bc6ec2b0014b74b0 | GNU C | output.txt | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1318919400 | ["5 5\n0 1 0 1 0", "2 1\n1 1"] | null | PASSED | 1,100 | input.txt | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. | ["2", "1"] | #include <stdio.h>
#include <stdlib.h>
int main()
{
int n,k,i, a[1005];
FILE *INP, *OUTP;
INP = fopen("input.txt", "r");
OUTP = fopen("output.txt", "w");
fscanf(INP, "%d %d", &n,&k);
for(i=1;i<=n;i++) fscanf(INP, "%d", &a[i]);
while(a[k]!=1)
{
k++;
if (k>n) k-=n;
}
fprintf(OUTP, "%d", k);
return 0;
}
| |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | C | 1378b4c9ba8029d310f07a1027a8c7a6 | 73e1d0dbc385a82f78716426aa9533fe | GNU C | output.txt | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1318919400 | ["5 5\n0 1 0 1 0", "2 1\n1 1"] | null | PASSED | 1,100 | input.txt | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. | ["2", "1"] | #include<stdio.h>
#define nprintf(x,y) fprintf(file,x,y)
int main(){
int a[1005],n,k,i;
FILE *file = fopen("output.txt","w");
freopen ("input.txt","r",stdin);
scanf("%d%d",&n,&k);
for(i=1;i<=n;i++) scanf("%d",&a[i]);
while(!a[k])k=(k==n)?1:(k+1);
nprintf("%d",k);
fclose(file);
return 0;
}
| |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | C | 1378b4c9ba8029d310f07a1027a8c7a6 | 9a3e7550031ad97f04fa7687b6d22218 | GNU C | output.txt | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1318919400 | ["5 5\n0 1 0 1 0", "2 1\n1 1"] | null | PASSED | 1,100 | input.txt | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. | ["2", "1"] | #include <stdio.h>
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n, k;
scanf("%d%d", &n, &k);
k--;
int ar[n];
int i;
for(i=0;i<n;i++)
scanf("%d", ar+i);
while(!ar[k])
k = (k+1)%n;
printf("%d\n", k+1);
return 0;
}
| |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | C | 1378b4c9ba8029d310f07a1027a8c7a6 | dd70a7f6426466458a176c2e4f42bcfe | GNU C | output.txt | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1318919400 | ["5 5\n0 1 0 1 0", "2 1\n1 1"] | null | PASSED | 1,100 | input.txt | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. | ["2", "1"] | #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
FILE *fIN,*fOUT;
char buf[9];
int n,k,i,j,a[10000];
main(){
fIN=fopen("input.txt","r");
fOUT=fopen("output.txt","w");
fscanf(fIN,"%d%d",&n,&k);
for(i=1;i<=n;i++) fscanf(fIN,"%d",a+i);
i=k;
while(1){
if(a[i]) break;
i=i!=n?i+1:1;
}
fprintf(fOUT,"%d\n",i);
return 0;
}
| |
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the question. All it takes to answer a typical question is general knowledge and common logic. The question sent be the audience are in envelops lain out in a circle on a round table. Each envelop is marked by the name of the asker's town. Each question is positioned in a separate sector. In the centre of the table is a spinning arrow. Thus, the table rather resembles a roulette table with no ball but with a spinning arrow instead. The host sets off the spinning arrow to choose a question for the experts: when the arrow stops spinning, the question it is pointing at is chosen. If the arrow points at the question that has already been asked, the host chooses the next unanswered question in the clockwise direction. Your task is to determine which will be the number of the next asked question if the arrow points at sector number k. | Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked. | C | 1378b4c9ba8029d310f07a1027a8c7a6 | e43c54b057e959343e40153addae120f | GNU C | output.txt | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1318919400 | ["5 5\n0 1 0 1 0", "2 1\n1 1"] | null | PASSED | 1,100 | input.txt | 1 second | The first line contains two positive integers n and k (1 ≤ n ≤ 1000 and 1 ≤ k ≤ n) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains n numbers: ai = 0 if the question from sector i has already been asked and ai = 1 if the question from sector i hasn't been asked yet (1 ≤ i ≤ n). The sectors are given in the clockwise order, the first sector follows after the n-th one. | ["2", "1"] | //#include <bits/stdc++.h>
//#include <algorithm>
#include <stdio.h>
//using namespace std;
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n,k;
scanf("%d %d",&n,&k);
int i,j,ara[2000];
for(i=1; i<=n; i++)
{
scanf("%d",&ara[i]);
}
for(i=k; i<=n; i++)
{
if(ara[i]==0)
{
if(i==n)
i=1;
else
continue;
}
if(ara[i]==1)
{
printf("%d",i);
return 0;
}
if(i==n)
{
i=1;
}
}
return 0;
}
| |
Peppa the Pig was walking and walked into the forest. What a strange coincidence! The forest has the shape of a rectangle, consisting of n rows and m columns. We enumerate the rows of the rectangle from top to bottom with numbers from 1 to n, and the columns — from left to right with numbers from 1 to m. Let's denote the cell at the intersection of the r-th row and the c-th column as (r, c).Initially the pig stands in cell (1, 1), and in the end she wants to be in cell (n, m). Since the pig is in a hurry to get home, she can go from cell (r, c), only to either cell (r + 1, c) or (r, c + 1). She cannot leave the forest.The forest, where the pig is, is very unusual. Some cells of the forest similar to each other, and some look very different. Peppa enjoys taking pictures and at every step she takes a picture of the cell where she is now. The path through the forest is considered to be beautiful if photographs taken on her way, can be viewed in both forward and in reverse order, showing the same sequence of photos. More formally, the line formed by the cells in order of visiting should be a palindrome (you can read a formal definition of a palindrome in the previous problem).Count the number of beautiful paths from cell (1, 1) to cell (n, m). Since this number can be very large, determine the remainder after dividing it by 109 + 7. | Print a single integer — the number of beautiful paths modulo 109 + 7. | C | 07fb2247b4b4ee5d3592fda21b814c7c | 81d7dcc9a3a98c45381e25aa0239b0bc | GNU C11 | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"combinatorics"
] | 1439483400 | ["3 4\naaab\nbaaa\nabba"] | NotePicture illustrating possibilities for the sample test. | PASSED | 2,300 | standard input | 4 seconds | The first line contains two integers n, m (1 ≤ n, m ≤ 500) — the height and width of the field. Each of the following n lines contains m lowercase English letters identifying the types of cells of the forest. Identical cells are represented by identical letters, different cells are represented by different letters. | ["3"] | #include<stdio.h>
int mod=1000000007;
int dp[510][510];
int dpb[510][510];
char a[510][510];
char b[1010][510];
int n,m;
int main(){
int i,j,k;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++){
scanf("%s",&a[i]);
}
if(n<m){
k=n;
n=m;
m=k;
for(i=0;i<n;i++){
for(j=0;j<m;j++){
b[i+j][j]=a[j][i];
}
}
}
else{
for(i=0;i<n;i++){
for(j=0;j<m;j++){
b[i+j][j]=a[i][j];
}
}
}
if((n+m)%2==0){
for(i=0;i<m;i++){
dpb[i][i]=1;
}
}
else{
for(i=0;i<m;i++){
if(b[(n+m)/2-1][i]==b[(n+m)/2][i])dpb[i][i]=1;
if(b[(n+m)/2-1][i]==b[(n+m)/2][i+1])dpb[i][i+1]=1;
}
}
for(i=(n+m)/2-1;i>0;i--){
for(j=0;j<m;j++){
for(k=0;k<m;k++){
dp[j][k]=0;
if(b[i-1][j]==b[n+m-i-1][k]){
dp[j][k]+=dpb[j][k];
dp[j][k]+=dpb[j+1][k];
dp[j][k]%=mod;
if(k!=0){
dp[j][k]+=dpb[j][k-1];
dp[j][k]%=mod;
dp[j][k]+=dpb[j+1][k-1];
dp[j][k]%=mod;
}
}
}
}
for(j=0;j<m;j++){
for(k=0;k<m;k++){
dpb[j][k]=dp[j][k];
}
}
}
printf("%d",dp[0][m-1]);
} | |
Peppa the Pig was walking and walked into the forest. What a strange coincidence! The forest has the shape of a rectangle, consisting of n rows and m columns. We enumerate the rows of the rectangle from top to bottom with numbers from 1 to n, and the columns — from left to right with numbers from 1 to m. Let's denote the cell at the intersection of the r-th row and the c-th column as (r, c).Initially the pig stands in cell (1, 1), and in the end she wants to be in cell (n, m). Since the pig is in a hurry to get home, she can go from cell (r, c), only to either cell (r + 1, c) or (r, c + 1). She cannot leave the forest.The forest, where the pig is, is very unusual. Some cells of the forest similar to each other, and some look very different. Peppa enjoys taking pictures and at every step she takes a picture of the cell where she is now. The path through the forest is considered to be beautiful if photographs taken on her way, can be viewed in both forward and in reverse order, showing the same sequence of photos. More formally, the line formed by the cells in order of visiting should be a palindrome (you can read a formal definition of a palindrome in the previous problem).Count the number of beautiful paths from cell (1, 1) to cell (n, m). Since this number can be very large, determine the remainder after dividing it by 109 + 7. | Print a single integer — the number of beautiful paths modulo 109 + 7. | C | 07fb2247b4b4ee5d3592fda21b814c7c | 6bbee385788a6e0f0ccdf40b0e8d12d2 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"dp",
"combinatorics"
] | 1439483400 | ["3 4\naaab\nbaaa\nabba"] | NotePicture illustrating possibilities for the sample test. | PASSED | 2,300 | standard input | 4 seconds | The first line contains two integers n, m (1 ≤ n, m ≤ 500) — the height and width of the field. Each of the following n lines contains m lowercase English letters identifying the types of cells of the forest. Identical cells are represented by identical letters, different cells are represented by different letters. | ["3"] | #include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define MAX 502
#define MOD 1000000007
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)
#define valid(i, j, k, l) ((i) >= 0 && (i) < n && (j) >= 0 && (j) < m && (k) >= 0 && (k) < n && (l) >= 0 && (l) < m)
char str[MAX][MAX];
int n, m, r, num[MAX][MAX], dp[125777][MAX];
int F(int i, int j, int k, int l){
if (i > k || j > l) return 0;
if (i == k && j == l) return 1;
if (str[i][j] != str[k][l]) return 0;
if (dp[num[i][k]][j] != -1) return dp[num[i][k]][j];
int x, u, v, s, t, res = 0;
u = i, v = j + 1, s = k, t = l - 1;
if (valid(u, v, s, t) && str[u][v] == str[s][t]){
if (u == k && v == l && s == i && t == j) res++;
else res += F(u, v, s, t);
if (res >= MOD) res -= MOD;
}
u = i, v = j + 1, s = k - 1, t = l;
if (valid(u, v, s, t) && str[u][v] == str[s][t]){
if (u == k && v == l && s == i && t == j) res++;
else res += F(u, v, s, t);
if (res >= MOD) res -= MOD;
}
u = i + 1, v = j, s = k, t = l - 1;
if (valid(u, v, s, t) && str[u][v] == str[s][t]){
if (u == k && v == l && s == i && t == j) res++;
else res += F(u, v, s, t);
if (res >= MOD) res -= MOD;
}
u = i + 1, v = j, s = k - 1, t = l;
if (valid(u, v, s, t) && str[u][v] == str[s][t]){
if (u == k && v == l && s == i && t == j) res++;
else res += F(u, v, s, t);
if (res >= MOD) res -= MOD;
}
return (dp[num[i][k]][j] = res);
}
int main(){
int i, j, k;
while (scanf("%d %d", &n, &m) != EOF){
for (i = 0; i < n; i++) scanf("%s", str[i]);
r = 0;
for (i = 0; i < n; i++){
for (j = i; j < n; j++){
num[i][j] = r++;
}
}
memset(dp, -1, sizeof(dp));
printf("%d\n", F(0, 0, n - 1, m - 1));
}
return 0;
}
| |
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | C | 12a768b502ddb07798830c9728fba5c4 | a001f4d1ce762a247b34ec48e7612baa | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1468933500 | ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.."] | null | PASSED | 1,400 | standard input | 1 second | The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | ["YES\n1 2", "NO", "YES\n3 3"] | #include <stdio.h>
#define MAX_N 1111
int n, m, rsum[MAX_N], csum[MAX_N];
char c[MAX_N][MAX_N];
int main(){
int i, j, total=0;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++) scanf("%s", c[i]);
for(i=0;i<n;i++) for(j=0;j<m;j++)
if(c[i][j]=='*') rsum[i]++, csum[j]++, total++;
for(i=0;i<n;i++) for(j=0;j<m;j++){
if(rsum[i]+csum[j]-(c[i][j]=='*') == total){
puts("YES");
printf("%d %d\n", i + 1, j + 1);
return 0;
}
}
puts("NO");
return 0;
} | |
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | C | 12a768b502ddb07798830c9728fba5c4 | 55b19cade03beb1198b39f02f11e6752 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1468933500 | ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.."] | null | PASSED | 1,400 | standard input | 1 second | The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | ["YES\n1 2", "NO", "YES\n3 3"] | #include<stdio.h>
int main ()
{
int a,b,i,j,d=0,count=0,e=0,f=0,g,h,This_is_my_first_time=1,cases=1,k,numbering=0,y=0;
char c[1010],x;
scanf("%d %d",&a,&b);
for(i=0;i<a;i++)
{
scanf("%d",&x);
gets(c);
if(This_is_my_first_time==1)
{
for(j=0;j<b;j++)
if(c[j]=='*')d=j,count++,e=i,k=i;
if(count>0)
{
This_is_my_first_time=0;
if(count>1)e=i;
}
}
else
{
for(j=0;j<b;j++)
if(c[j]=='*')f=j,numbering++;
if(numbering>0)
{
switch(cases)
{
case 1:
{
if(count==1)
{
if(numbering==1)
{
if(f==d)cases=2;
else cases=4,h=f,e=i;
}
else cases=3,e=i;
}
else
{
if(numbering==1)cases=3,d=f;
else y=1;
}
break;
}
case 2:
{
if(numbering==1)
{
if(f==d)cases=2;
else cases=3,e=i;
}
else cases=3,e=i;
break;
}
case 3:
{
if(numbering!=1)y=1;
else
{
if(f!=d)y=1;
}
break;
}
case 4:
{
if(f!=h && f!=d)y=1;
else
{
if(f==d)cases=3;
if(f==h)cases=3,d=h,e=k;
}
break;
}
}
}
}
numbering=0;
}
if(y==1)
{
printf("NO\n");
}
else
{
printf("YES\n");
printf("%d %d",e+1,d+1);
}
return 0;
}
| |
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | C | 12a768b502ddb07798830c9728fba5c4 | 0e9334f759196e4092775d68b370985e | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1468933500 | ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.."] | null | PASSED | 1,400 | standard input | 1 second | The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | ["YES\n1 2", "NO", "YES\n3 3"] | #include <stdio.h>
#include <limits.h>
int main()
{
int n,m,i,row[1005],col[1005],j,count,total=0,flag=0;
char mat[1005][1005];
scanf("%d %d",&n,&m);
for(i=0;i<n;i++)
{
row[i]=0;
}
for(j=0;j<m;j++)
{
col[i]=0;
}
for(i=0;i<n;i++)
{
scanf("%s",mat[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(mat[i][j]=='*')
{
row[i]++;
total++;
}
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(mat[j][i]=='*')
{
col[i]++;
}
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(mat[i][j]=='*')
{
if(row[i]+col[j]-1 == total)
{
printf("YES\n");
printf("%d %d",i+1,j+1);
flag=1;
break;
}
}
else{
if(row[i]+col[j]==total)
{ printf("YES\n");
printf("%d %d",i+1,j+1);
flag=1;
break;
}
}
}
if(flag==1){break;}
}
if(flag==0)
{
printf("NO");
}
return 0;
} | |
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | C | 12a768b502ddb07798830c9728fba5c4 | 1ca739710bf11b4a70babab860beb8a3 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1468933500 | ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.."] | null | PASSED | 1,400 | standard input | 1 second | The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | ["YES\n1 2", "NO", "YES\n3 3"] | #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main()
{
char s[1010][1010];
int r[1010],c[1010];
int n,m,k1,k2,i,j,k;
k=k1=k2=0;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
scanf("%s",s[i]+1);
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
if(s[i][j]=='*')
{
r[i]++;c[j]++;k++;
}
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
if(r[i]+c[j]+(s[i][j]=='*'?-1:0)==k)
{
puts("YES");
printf("%d %d\n",i,j);
return 0;
}
puts("NO");
return 0;
}
| |
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | C | 12a768b502ddb07798830c9728fba5c4 | af33073de48e22993dc06c6cd134b6fd | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1468933500 | ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.."] | null | PASSED | 1,400 | standard input | 1 second | The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | ["YES\n1 2", "NO", "YES\n3 3"] | #include<stdio.h>
#define N 1005
char s[N][N];
int i,j,n,m,num;
int h[N],l[N];
int main()
{
scanf("%d %d",&n,&m);
for(i=1;i<=n;i++){
scanf("%s",s[i]);
for(j=1;j<=m;j++)
if(s[i][j-1]=='*')num++,h[i]++,l[j]++;
}
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
if(h[i]+l[j]-(s[i][j-1]=='*')==num){puts("YES");printf("%d %d\n",i,j);return 0;}
puts("NO");
return 0;
}
| |
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | C | 12a768b502ddb07798830c9728fba5c4 | ea1e4c9fe583f3c647e9fee2232ca008 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1468933500 | ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.."] | null | PASSED | 1,400 | standard input | 1 second | The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | ["YES\n1 2", "NO", "YES\n3 3"] | //Date:19-07-16
#include<stdio.h>
#include<string.h>
#define For(i ,n) for(i=1;i<=n;i++)
int row[1001] = {0} ,col[1001] = {0} ,wall[1001][1001];
int main(){
int n,m ,i ,j;
scanf("%d%d" ,&n ,&m);
char c;
int total =0;
memset(wall ,0 ,sizeof(wall));
For(i ,n)
For(j ,m){
scanf(" %c" ,&c);
if(c=='*') row[i]++ ,col[j]++ ,wall[i][j]=1 ,total++;
}
For(i ,n)
For(j ,m){
if(row[i]+col[j]-wall[i][j]==total){
puts("YES");
printf("%d %d" ,i ,j);
return 0;
}
}
puts("NO");
return 0;
} | |
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | C | 12a768b502ddb07798830c9728fba5c4 | 5bcb04618a34e123d655fc828fa01693 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1468933500 | ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.."] | null | PASSED | 1,400 | standard input | 1 second | The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | ["YES\n1 2", "NO", "YES\n3 3"] | #include<stdio.h>
#include<stdlib.h>
int main()
{
int r,c,i,j;
char ch;
scanf("%d %d",&r,&c);
getchar();
int row[r],col[c];
char a[r][c];
memset(row,0,sizeof(row));
memset(col,0,sizeof(col));
int wall=0;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%c",&a[i][j]);
ch=a[i][j];
//printf("ch=%c\n",ch);
if(ch=='*')
{
//printf("j=%d\n",j);
row[i]++;
col[j]++;
wall++;
}
}
getchar();
}
//printf("wall=%d\n",wall);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(a[i][j]=='*')
{
//printf("total=%d\n",row[i]+col[j]);
if((row[i]+col[j])-1==wall)
{
printf("YES\n%d %d",i+1,j+1);
return 0;
}
}
if(a[i][j]=='.')
{
//printf("total=%d\n",row[i]+col[j]);
if(row[i]+col[j]==wall)
{
printf("YES\n%d %d",i+1,j+1);
return 0;
}
}
}
}
printf("NO");
}
| |
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | C | 12a768b502ddb07798830c9728fba5c4 | b0ada2314e6897b814448cd0e5a286cd | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1468933500 | ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.."] | null | PASSED | 1,400 | standard input | 1 second | The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | ["YES\n1 2", "NO", "YES\n3 3"] | #include<stdio.h>
#include<stdlib.h>
int cmp(const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int main()
{
int n, m, i = 0, j = 0, k = 0;
scanf("%d%d", &n, &m);
char grid[n][m];
for(i; i < n; i++)
{
scanf("%s", grid[i]);
}
int bombx[n*m], bomby[n*m], tempy[n*m], comm_x = 0, comm_y = 0, c_x_found = 0, c_y_found = 0;
for(i = 0; i < n; i++)
{
for(j = 0; j < m; j++)
{
if(grid[i][j] == '*')
{
bombx[k] = i;
bomby[k] = j;
tempy[k] = j;
k++;
}
}
}
for(i = 1; i < k; i++)
{
if(bombx[i] == bombx[i - 1])
{
comm_x = bombx[i];
c_x_found++;
break;
}
}
qsort(tempy, k, sizeof(int), cmp);
for(i = 1; i < k; i++)
{
if(tempy[i] == tempy[i - 1])
{
comm_y = tempy[i];
c_y_found++;
break;
}
}
if(c_x_found == 0)
{
for(i = 0; i < k; i++)
{
if(bomby[i] != comm_y)
{
comm_x = bombx[i];
break;
}
}
}
if(c_y_found == 0)
{
for(i = 0; i < k; i++)
{
if(bombx[i] != comm_x)
{
comm_y = bomby[i];
break;
}
}
}
for(i = 0; i < k; i++)
{
if((bombx[i] != comm_x) && (bomby[i] != comm_y))
{
printf("NO\n");
return 0;
}
}
printf("YES\n");
printf("%d %d\n", comm_x + 1, comm_y + 1);
return 0;
}
| |
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | C | 12a768b502ddb07798830c9728fba5c4 | aaa9a59ff731a18adbba6693f4cf0ffd | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1468933500 | ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.."] | null | PASSED | 1,400 | standard input | 1 second | The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | ["YES\n1 2", "NO", "YES\n3 3"] | #include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
int main(int argc, char* argv[]){
int n, m;
scanf("%d", &n);
scanf("%d", &m);
int nb_walls = 0;
char c;
int ligne[n+1];
int colonne[m+1];
int grille[n +1][m +1];
memset(ligne, 0, sizeof ligne);
memset(colonne, 0, sizeof colonne);
memset(grille, 0, sizeof grille);
for (int i = 1; i<n+1; i++) {
getchar();
for (int j = 1; j<m+1; j++) {
if ((c =getchar()), c == '*') {
nb_walls++;
ligne[i]++;
colonne[j]++;
grille[i][j]++;
}
}
}
//printf("Lecture terminée.\n");
for (int i = 1; i<n+1; i++) {
for (int j = 1; j<m+1; j++) {
//printf("%d, %d, %d\n",ligne[i] ,colonne[j], grille[i][j]);
if (ligne[i] + colonne[j] - grille[i][j] == nb_walls) {
printf("YES\n");
printf("%d %d\n", i, j);
return 0;
}
}
}
printf("NO\n");
return 0;
}
| |
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | C | 12a768b502ddb07798830c9728fba5c4 | 12afb2162d86a141ed0fe94abacc55c8 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1468933500 | ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.."] | null | PASSED | 1,400 | standard input | 1 second | The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | ["YES\n1 2", "NO", "YES\n3 3"] | #include <stdio.h>
char Map[1000][1001];
int Row[1001];
int Col[1001];
int main()
{
int N, M, Sum = 0;
scanf("%d %d", &N, &M);
for(int i = 0; i < N; ++i) {
scanf("%s", Map[i]);
for(int j = 0; j < M; ++j) {
if(Map[i][j] == '*') {
++Row[i];
++Col[j];
++Sum;
}
}
}
for(int i = 0; i < N; ++i) {
for(int j = 0; j < M; ++j) {
int cur = Row[i] + Col[j] - (Map[i][j] == '*');
if(cur == Sum) {
printf("YES\n%d %d\n", i + 1, j + 1);
return 0;
}
}
}
puts("NO");
return 0;
}
| |
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | C | 12a768b502ddb07798830c9728fba5c4 | e106284863354f4551c9df8a89bcf523 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1468933500 | ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.."] | null | PASSED | 1,400 | standard input | 1 second | The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | ["YES\n1 2", "NO", "YES\n3 3"] | #define N 1001
//成功了,这里的处理非常细心!
#include<stdio.h>
//从更简单的角度来处理
//采用扫描的办法!
int main() {
int n,m;
scanf("%d%d",&n,&m);
//printf(stderr,"n=%d,m=%d\n",n,m);
int i,j;
char field[N][N];
for(i=0;i<n;i++){
scanf("%s",field[i]);
}
//扫描过程中统计哪些行被占了了!
//哪些列被占领了!
int rows=0;
int x=0;
int y=0;
for(i=0;i<n;i++){
int walls=0;
for(j=0;j<m;j++){
if(field[i][j]=='*'){
walls++;
}
}
if(walls>1){
rows++;
x=i;//这里得到的x可以用在rows==1的情况上!
}
}
//printf("rows=%d\n",rows);
if(rows>1){
//如果有两行以上有两个墙以上,
//那么我们无法一次炸完!
printf("NO\n");
return 0;
}else if(rows==1){
//如果只有一行有两个墙以上,那么我们接下来的工作是处理列!
//接下来看不在x行上的墙的分布!
int cols=0;
y=0;
for(i=0;i<m;i++){
int walls=0;
for(j=0;j<n;j++){
if(j!=x && field[j][i]=='*'){
walls++;
}
}
if(walls>0){
cols++;
y=i;
}
}
if(cols>1){
printf("NO\n");
return 0;
}else{
printf("YES\n");
printf("%d %d\n",x+1,y+1);
return 0;
}
}else{
int cols=0;
for(i=0;i<m;i++){
int walls=0;
for(j=0;j<n;j++){
if(field[j][i]=='*'){
walls++;
}
}
if(walls>0){
cols++;
}
}
if(cols>2){
printf("NO\n");
return 0;
}else if(cols==2){
x=0;
y=0;
int first=1;
cols=0;
for(i=0;i<m;i++){
int walls=0;
for(j=0;j<n;j++){
if(field[j][i]=='*'){
walls++;
}
}
if(walls>1){
cols++;
}
}
//..*.....
//..*.....
//...*....
//...*....
////说明网站没有检查这种结构,让我的程序蒙哄过关了!
//上面的这种结构,我们也无法一次炸掉!
if(cols==2){
//难道这种情况不会出现?
printf("NO\n");
return 0;
}else{
first=1;
for(i=0;i<m;i++){
int walls=0;
for(j=0;j<n;j++){
if(field[j][i]=='*'){
walls++;
}
}
if(walls==1){
if(first){
for(j=0;j<n;j++){
if(field[j][i]=='*'){
x=j;
}
}
first=0;
}else{
y=i;
}
}else if(walls>1){
y=i;
}
}
printf("YES\n");
printf("%d %d\n",x+1,y+1);
return 0;
}
}else if(cols==1){
//随便找一个就可以!
printf("YES\n");
x=0;
y=0;
for(i=0;i<n;i++){
for(j=0;j<m;j++){
if(field[i][j]=='*'){
x=i;
y=j;
}
}
}
printf("%d %d\n",x+1,y+1);
return 0;
}else{
printf("YES\n");
//printf("NO\n");
printf("1 1\n");
return 0;
}
}
return 0;
}
| |
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | C | 12a768b502ddb07798830c9728fba5c4 | 7749a098b3f0bd116a4569f985c15149 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1468933500 | ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.."] | null | PASSED | 1,400 | standard input | 1 second | The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | ["YES\n1 2", "NO", "YES\n3 3"] | #define N 1001
#include<stdio.h>
//从更简单的角度来处理
//采用扫描的办法!
int main() {
int n,m;
scanf("%d%d",&n,&m);
//printf(stderr,"n=%d,m=%d\n",n,m);
int i,j;
char field[N][N];
for(i=0;i<n;i++){
scanf("%s",field[i]);
}
//扫描过程中统计哪些行被占了了!
//哪些列被占领了!
int rows=0;
int x=0;
int y=0;
for(i=0;i<n;i++){
int walls=0;
for(j=0;j<m;j++){
if(field[i][j]=='*'){
walls++;
}
}
if(walls>1){
rows++;
x=i;//这里得到的x可以用在rows==1的情况上!
}
}
//printf("rows=%d\n",rows);
if(rows>1){
//如果有两行以上有两个墙以上,
//那么我们无法一次炸完!
printf("NO\n");
return 0;
}else if(rows==1){
//如果只有一行有两个墙以上,那么我们接下来的工作是处理列!
//接下来看不在x行上的墙的分布!
int cols=0;
y=0;
for(i=0;i<m;i++){
int walls=0;
for(j=0;j<n;j++){
if(j!=x && field[j][i]=='*'){
walls++;
}
}
if(walls>0){
cols++;
y=i;
}
}
if(cols>1){
printf("NO\n");
return 0;
}else{
printf("YES\n");
printf("%d %d\n",x+1,y+1);
return 0;
}
}else{
int cols=0;
for(i=0;i<m;i++){
int walls=0;
for(j=0;j<n;j++){
if(field[j][i]=='*'){
walls++;
}
}
if(walls>0){
cols++;
}
}
if(cols>2){
printf("NO\n");
return 0;
}else if(cols==2){
printf("YES\n");
x=0;
y=0;
int first=1;
cols=0;
for(i=0;i<m;i++){
int walls=0;
for(j=0;j<n;j++){
if(field[j][i]=='*'){
walls++;
}
}
if(walls>1){
cols++;
}
}
//..*.....
//..*.....
//...*....
//...*....
//上面的这种结构,我们也无法一次炸掉!
if(cols==2){
printf("NO\n");
return 0;
}else{
first=1;
for(i=0;i<m;i++){
int walls=0;
for(j=0;j<n;j++){
if(field[j][i]=='*'){
walls++;
}
}
if(walls==1){
if(first){
for(j=0;j<n;j++){
if(field[j][i]=='*'){
x=j;
}
}
first=0;
}else{
y=i;
}
}else if(walls>1){
y=i;
}
}
printf("%d %d\n",x+1,y+1);
return 0;
}
}else if(cols==1){
//随便找一个就可以!
printf("YES\n");
x=0;
y=0;
for(i=0;i<n;i++){
for(j=0;j<m;j++){
if(field[i][j]=='*'){
x=i;
y=j;
}
}
}
printf("%d %d\n",x+1,y+1);
return 0;
}else{
printf("YES\n");
//printf("NO\n");
printf("1 1\n");
return 0;
}
}
return 0;
}
| |
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | C | 12a768b502ddb07798830c9728fba5c4 | 98975b12aa52aeeba79210cda5836dc0 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1468933500 | ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.."] | null | PASSED | 1,400 | standard input | 1 second | The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | ["YES\n1 2", "NO", "YES\n3 3"] | #include<stdio.h>
int main()
{
char s[2000][2000];
int n,m,i,j,bomb=0,ans=0,count=0,row[2000],column[2000];
scanf("%d %d",&n,&m);
getchar();
for(i=1;i<=n;i++)
{
bomb=0;
for(j=1;j<=m;j++)
{
scanf("%c",&s[i][j]);
if(s[i][j]=='*')
{
count++;
bomb++;
}
}
row[i]=bomb;
// printf("%d\n",row[i]);
getchar();
}
//printf("%d",count);
for(i=1;i<=m;i++)
{
bomb=0;
for(j=1;j<=n;j++)
{
if(s[j][i]=='*')
bomb++;
}
column[i]=bomb;
// printf("%d\n",column[i]);
}
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(s[i][j]=='*')
ans=row[i]+column[j]-1;
else
ans=row[i]+column[j];
// printf("%d\n",ans);
if(count==ans)
{
printf("YES\n%d %d",i,j);
return 0;
}
}
// printf("%d\n",ans);
}
printf("NO");
return 0;
}
//unsolved
| |
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | C | 12a768b502ddb07798830c9728fba5c4 | 96eefab7940adeada9427587067184bc | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1468933500 | ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.."] | null | PASSED | 1,400 | standard input | 1 second | The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | ["YES\n1 2", "NO", "YES\n3 3"] | #include <stdio.h>
int main()
{
int i,j,n=0,r,c,count=0,m;
int t;
scanf("%d %d\n",&r,&c);
char mat[r][c];
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%c",&mat[i][j]);
if(mat[i][j]=='*')
count++;
}
if(i!=r-1)
scanf("\n");
}
// printf("%d",count);
if(count==0)
{
printf("YES\n1 1");
return 0;
}
int b[count][2];
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
if(mat[i][j]=='*')
{
b[n][0]=i;
b[n++][1]=j;
}
}
}
int e=100000,f=100000;
if(count==1)
{
printf("YES\n%d %d",b[0][0]+1,b[0][1]+1);
return 0;
}
if(count==2)
{
e=b[0][0];
f=b[1][1];
printf("YES\n%d %d",e+1,f+1);
return 0;
}
for(i=0;i<count;i++)
{
for(j=0;j<count;j++)
{
if(b[i][0]==b[j][0]&&i!=j)
e=b[i][0];
if(b[i][1]==b[j][1]&&i!=j)
f=b[i][1];
//if(f==0)
//printf("i j is %d %d\n",i,j);
if(e!=100000&&f!=100000)
break;
}
}
//printf("e f is %d %d",e,f);
if(e==100000&&f==100000)
{
printf("NO\n");
return 0;
}
for(i=0;i<count;i++)
{
if(b[i][0]!=e&&b[i][1]!=f)
{
if(f==100000)
{
f=b[i][1];
continue;
}
if(e==100000)
{
e=b[i][0];
continue;
}
printf("NO\n");
return 0;
}
}
if(e==100000)
e=0;
if(f==100000)
f=0;
printf("YES\n%d %d",e+1,f+1);
return 0;
}
| |
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | C | 12a768b502ddb07798830c9728fba5c4 | 475a6d5c0dd9b2b5da35f64524a683bb | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1468933500 | ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.."] | null | PASSED | 1,400 | standard input | 1 second | The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | ["YES\n1 2", "NO", "YES\n3 3"] | #include <stdio.h>
#define SIZE 1000
int main()
{
int n, m, row[SIZE] = { 0 }, col[SIZE] = { 0 }, i, j, maxr, maxc, cnt = 0, ansr, ansc;
char s[SIZE][SIZE + 1];
scanf ("%d %d\n", &n, &m);
for (i = 0; i < n; i++)
gets (s[i]);
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
if (s[i][j] == '*') {
cnt++;
row[i]++;
col[j]++;
}
maxr = 0;
for (i = 1; i < n; i++)
if (row[i] > row[maxr])
maxr = i;
maxc = 0;
for (i = 1; i < m; i++)
if (col[i] > col[maxc])
maxc = i;
if (cnt <= 1) {
ansr = maxr;
ansc = maxc;
}
else if (cnt == 2) {
ansr = maxr;
ansc = maxc;
if (row[ansr] == 1 && col[ansc] == 1 && s[maxr][maxc] == '*') {
for (i = 0; i < m; i++)
if (i != maxc && col[i] == 1)
break;
ansc = i;
}
}
else if (row[maxr] == 1 && col[maxc] == 1) /* cnt > 2 */
ansr = -1;
else {
ansr = maxr;
ansc = maxc;
if (row[maxr] == 1 && s[maxr][maxc] == '*') {
for (i = 0; i < n; i++)
if (row[i] == 1 && s[i][maxc] != '*')
break;
if (i < n)
ansr = i;
}
if (col[maxc] == 1 && s[maxr][maxc] == '*') {
for (i = 0; i < m; i++)
if (col[i] == 1 && s[maxr][i] != '*')
break;
if (i < m)
ansc = i;
}
}
if (ansr == -1)
puts ("NO");
else {
for (i = 0; i < m; i++)
if (s[ansr][i] == '*')
cnt--;
for (i = 0; i < n; i++)
if (s[i][ansc] == '*')
cnt--;
if (s[ansr][ansc] == '*')
cnt++;
puts (cnt == 0 ? "YES" : "NO");
if (cnt == 0)
printf ("%d %d", ansr + 1, ansc + 1);
}
return 0;
}
| |
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | C | 12a768b502ddb07798830c9728fba5c4 | 7b3b656e7cf9257b1ac3c41356badbda | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1468933500 | ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.."] | null | PASSED | 1,400 | standard input | 1 second | The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | ["YES\n1 2", "NO", "YES\n3 3"] | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int row[1010];
int col[1010];
char mat[1010][1010];
int main() {
int n, m;
int num = 0;
int i, j;
scanf("%d %d", &n, &m);
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
scanf(" %c", &mat[i][j]);
if (mat[i][j] == '*') {
num++;
row[i]++;
col[j]++;
}
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (row[i] + col[j] - (mat[i][j] == '*' ? 1 : 0) == num) {
printf("YES\n%d %d\n", i + 1, j + 1);
return 0;
}
}
}
printf("NO\n");
return 0;
}
| |
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | C | 12a768b502ddb07798830c9728fba5c4 | 2745472c0e32ba2976d908c441192fa8 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1468933500 | ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.."] | null | PASSED | 1,400 | standard input | 1 second | The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | ["YES\n1 2", "NO", "YES\n3 3"] | #include<stdio.h>
int x,y;
int f[1010];
int c[1010];
char map[1010][1010];
int main(){
int i,j,t;
scanf("%d %d",&x,&y);
for(i=t=0;i<x;i++){
scanf("%s",map[i]);
for(j=0;j<y;j++){
if(map[i][j]=='*'){
t++;
f[i]++;
c[j]++;
}
}
}
for(i=0;i<x;i++){
for(j=0;j<y;j++){
if(f[i]+c[j]-(map[i][j]=='*')==t){
printf("YES\n%d %d",i+1,j+1);
return 0;
}
}
}
printf("NO");
return 0;
}
| |
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. | C | 12a768b502ddb07798830c9728fba5c4 | 2c904eca0f8542924924b43f88e0dc54 | GNU C | standard output | 256 megabytes | train_002.jsonl | [
"implementation"
] | 1468933500 | ["3 4\n.*..\n....\n.*..", "3 3\n..*\n.*.\n*..", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.."] | null | PASSED | 1,400 | standard input | 1 second | The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. | ["YES\n1 2", "NO", "YES\n3 3"] | #include <stdio.h>
int main () {
char grid[1005][1005];
int n, m, i, j;
scanf("%d %d", &n, &m);
for (i = 0; i < n; i++) {
scanf("%s", grid[i]);
}
int horizontal[1005];
int vertical[1005];
for (i = 0; i <= 1000; i++) {
horizontal[i] = vertical[i] = 0;
}
int total = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (grid[i][j] == '*') {
horizontal[i]++;
total++;
}
}
}
for (j = 0; j < m; j++) {
for (i = 0; i < n; i++) {
if (grid[i][j] == '*')
vertical[j]++;
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
int curr = horizontal[i] + vertical[j];
if (grid[i][j] == '*')
curr--;
if (curr == total) {
printf("YES\n%d %d\n", i + 1, j + 1);
return 0;
}
}
}
puts("NO");
return 0;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.