Submission
Status:
[PP][PP][PPP][P-S][PPP][PPPPP][PPPP-SS][PPPP][PPPP][PPPPP]
Subtask/Task Score:
{10/10}{10/10}{10/10}{0/10}{10/10}{10/10}{0/10}{10/10}{10/10}{10/10}
Score: 80
User: Jokul
Problemset: ช่องบนไม้
Language: c
Time: 0.015 second
Submitted On: 2025-06-14 19:22:14
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int index;
int count;
} CountEntry;
int main() {
int n, w, l, k, hole;
scanf("%d %d %d", &n, &w, &l);
// Dynamic array to store counts
CountEntry *a = (CountEntry *)malloc(w * sizeof(CountEntry));
for (int i = 0; i < w; i++) {
a[i].index = i;
a[i].count = 0;
}
for (int i = 0; i < n; i++) {
scanf("%d", &k);
for (int j = 0; j < k; j++) {
scanf("%d", &hole);
int start = hole - l < 0 ? 0 : hole - l;
int end = hole + l >= w ? w - 1 : hole + l;
for (int d = start; d <= end; d++) {
a[d].count++;
}
}
}
// Check for the condition
for (int i = 0; i < w; i++) {
if (a[i].count == n) {
printf("1");
free(a); // Free allocated memory
return 0;
}
}
printf("0");
free(a); // Free allocated memory
return 0;
}