| Task: | Subarray Sums II |
| Sender: | Isak |
| Submission time: | 2025-11-24 16:17:15 +0200 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | RUNTIME ERROR |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | RUNTIME ERROR | 0.00 s | details |
| #3 | WRONG ANSWER | 0.00 s | details |
| #4 | ACCEPTED | 0.00 s | details |
| #5 | ACCEPTED | 0.18 s | details |
| #6 | RUNTIME ERROR | 0.04 s | details |
| #7 | WRONG ANSWER | 0.07 s | details |
| #8 | ACCEPTED | 0.10 s | details |
| #9 | RUNTIME ERROR | 0.03 s | details |
| #10 | RUNTIME ERROR | 0.03 s | details |
| #11 | RUNTIME ERROR | 0.03 s | details |
| #12 | RUNTIME ERROR | 0.05 s | details |
| #13 | RUNTIME ERROR | 0.04 s | details |
| #14 | RUNTIME ERROR | 0.03 s | details |
| #15 | RUNTIME ERROR | 0.04 s | details |
| #16 | WRONG ANSWER | 0.00 s | details |
| #17 | RUNTIME ERROR | 0.00 s | details |
| #18 | RUNTIME ERROR | 0.04 s | details |
| #19 | RUNTIME ERROR | 0.04 s | details |
| #20 | RUNTIME ERROR | 0.03 s | details |
| #21 | RUNTIME ERROR | 0.04 s | details |
| #22 | RUNTIME ERROR | 0.04 s | details |
| #23 | RUNTIME ERROR | 0.04 s | details |
| #24 | ACCEPTED | 0.00 s | details |
| #25 | ACCEPTED | 0.12 s | details |
| #26 | ACCEPTED | 0.12 s | details |
| #27 | WRONG ANSWER | 0.11 s | details |
| #28 | RUNTIME ERROR | 0.04 s | details |
Code
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <search.h>
#define LOOP(i,s,e) for (int64_t i = (s); i < (e); i++)
#define SCAN(...) if (scanf(__VA_ARGS__) == 0) return EXIT_FAILURE
int main() {
int64_t n = 0;
int64_t target;
SCAN("%ld %ld", &n, &target);
// main algo
int64_t *tab = (int64_t *) malloc(n * sizeof(int64_t));
int64_t *pref = (int64_t *) malloc(n * sizeof(int64_t));
SCAN("%ld", tab);
pref[0] = tab[0];
LOOP(i, 1, n){
SCAN("%ld", tab+i);
pref[i] = pref[i-1] + tab[i];
}
(void) hcreate(n);
// ajout de 0
// printf("ajout %ld : %ld\n", -1, 0);
int64_t *v = (int64_t*) malloc(sizeof(int64_t));
char *key = (char*) malloc(10 * sizeof(char));
memcpy(key, "0", 2);
*v = 1;
ENTRY e = {key, v};
hsearch(e, ENTER);
uint64_t acc = 0;
LOOP(i, 0, n){
int64_t val = pref[i] - target;
// char *key = (char*) &val;
char key[10];
sprintf(key, "%ld", pref[i]);
int64_t *v;
ENTRY e = {key, NULL};
ENTRY *pe = hsearch(e, FIND);
if (pe == NULL){
// printf("ajout %ld : %ld\n", i, pref[i]);
v = (int64_t*) malloc(sizeof(int64_t));
char *key = (char*) malloc(10 * sizeof(char));
sprintf(key, "%ld", pref[i]);
*v = 1;
ENTRY e = {key, v};
hsearch(e, ENTER);
} else {
// printf("increment %ld\n", i);
(*(int64_t*)pe->data)++;
}
sprintf(key, "%ld", val);
e = {key, NULL};
pe = hsearch(e, FIND);
// printf("search : %ld\n", val);
if (pe != NULL){
// printf("trouvé\n");
acc += (*(int64_t*)pe->data);
}
}
printf("%ld\n", acc);
return EXIT_SUCCESS;
}
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 100 50 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 51 |
| user output |
|---|
| 51 |
Test 2
Verdict: RUNTIME ERROR
| input |
|---|
| 100 1000000000 1000000000 1000000000 10000000... |
| correct output |
|---|
| 100 |
| user output |
|---|
| (empty) |
Error:
*** buffer overflow detected ***: terminated
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... |
| correct output |
|---|
| 5050 |
| user output |
|---|
| 5150 |
Feedback: Incorrect character on line 1 col 2: expected "5050", got "5150"
Test 4
Verdict: ACCEPTED
| input |
|---|
| 100 4 2 1 -3 2 -7 7 -2 6 9 -4 10 -6 ... |
| correct output |
|---|
| 53 |
| user output |
|---|
| 53 |
Test 5
Verdict: ACCEPTED
| input |
|---|
| 200000 100000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 100001 |
| user output |
|---|
| 100001 |
Test 6
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 1000000000 1000000000 1000000000 10000000... |
| correct output |
|---|
| 200000 |
| user output |
|---|
| (empty) |
Error:
*** buffer overflow detected ***: terminated
Test 7
Verdict: WRONG ANSWER
| input |
|---|
| 200000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... |
| correct output |
|---|
| 20000100000 |
| user output |
|---|
| 20000300000 |
Feedback: Incorrect character on line 1 col 6: expected "20000100000", got "20000300000"
Test 8
Verdict: ACCEPTED
| input |
|---|
| 200000 39 44 -62 -3 23 11 -68 42 69 -22 ... |
| correct output |
|---|
| 903601 |
| user output |
|---|
| 903601 |
Test 9
Verdict: RUNTIME ERROR
| input |
|---|
| 131072 199999 199999 199999 199999 199999 19... |
| correct output |
|---|
| 131072 |
| user output |
|---|
| (empty) |
Error:
*** buffer overflow detected ***: terminated
Test 10
Verdict: RUNTIME ERROR
| input |
|---|
| 131072 107897 107897 107897 107897 107897 10... |
| correct output |
|---|
| 131072 |
| user output |
|---|
| (empty) |
Error:
*** buffer overflow detected ***: terminated
Test 11
Verdict: RUNTIME ERROR
| input |
|---|
| 131072 126271 126271 126271 126271 126271 12... |
| correct output |
|---|
| 131072 |
| user output |
|---|
| (empty) |
Error:
*** buffer overflow detected ***: terminated
Test 12
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 107897 107897 107897 107897 107897 10... |
| correct output |
|---|
| 199999 |
| user output |
|---|
| (empty) |
Error:
*** buffer overflow detected ***: terminated
Test 13
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 100000 1056323 1056323 1056323 105632... |
| correct output |
|---|
| 0 |
| user output |
|---|
| (empty) |
Error:
*** buffer overflow detected ***: terminated
Test 14
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 100000 2144977 2144977 2144977 214497... |
| correct output |
|---|
| 0 |
| user output |
|---|
| (empty) |
Error:
*** buffer overflow detected ***: terminated
Test 15
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 100000 65536 65536 65536 65536 65536 ... |
| correct output |
|---|
| 0 |
| user output |
|---|
| (empty) |
Error:
*** buffer overflow detected ***: terminated
Test 16
Verdict: WRONG ANSWER
| input |
|---|
| 5 0 0 0 0 0 0 |
| correct output |
|---|
| 15 |
| user output |
|---|
| 20 |
Feedback: Incorrect character on line 1 col 1: expected "15", got "20"
Test 17
Verdict: RUNTIME ERROR
| input |
|---|
| 20 536870912 268435456 268435456 268435456 ... |
| correct output |
|---|
| 19 |
| user output |
|---|
| (empty) |
Error:
*** buffer overflow detected ***: terminated
Test 18
Verdict: RUNTIME ERROR
| input |
|---|
| 131072 136607 136607 136607 136607 136607 13... |
| correct output |
|---|
| 131072 |
| user output |
|---|
| (empty) |
Error:
*** buffer overflow detected ***: terminated
Test 19
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 562841 562841 562841 562841 562841 56... |
| correct output |
|---|
| 200000 |
| user output |
|---|
| (empty) |
Error:
*** buffer overflow detected ***: terminated
Test 20
Verdict: RUNTIME ERROR
| input |
|---|
| 107897 107897 107897 107897 107897 107897 10... |
| correct output |
|---|
| 107897 |
| user output |
|---|
| (empty) |
Error:
*** buffer overflow detected ***: terminated
Test 21
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 202409 101204 101205 101204 101205 10... |
| correct output |
|---|
| 199998 |
| user output |
|---|
| (empty) |
Error:
*** buffer overflow detected ***: terminated
Test 22
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 202409 138630 138631 138630 138631 13... |
| correct output |
|---|
| 0 |
| user output |
|---|
| (empty) |
Error:
*** buffer overflow detected ***: terminated
Test 23
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 10273 410857 410857 410857 410857 41... |
| correct output |
|---|
| 0 |
| user output |
|---|
| (empty) |
Error:
*** buffer overflow detected ***: terminated
Test 24
Verdict: ACCEPTED
| input |
|---|
| 5 2 1 -1 1 -1 2 |
| correct output |
|---|
| 3 |
| user output |
|---|
| 3 |
Test 25
Verdict: ACCEPTED
| input |
|---|
| 200000 1 1048577 -1048570 29 145 725 36... |
| correct output |
|---|
| 104671 |
| user output |
|---|
| 104671 |
Test 26
Verdict: ACCEPTED
| input |
|---|
| 200000 1 1048577 -1048571 25 125 625 31... |
| correct output |
|---|
| 104859 |
| user output |
|---|
| 104859 |
Test 27
Verdict: WRONG ANSWER
| input |
|---|
| 200000 0 5334500 -3502392 3421268 -2064... |
| correct output |
|---|
| 6341575890 |
| user output |
|---|
| 6341775890 |
Feedback: Incorrect character on line 1 col 5: expected "6341575890", got "6341775890"
Test 28
Verdict: RUNTIME ERROR
| input |
|---|
| 200000 0 172933 172933 172933 172933 17... |
| correct output |
|---|
| 0 |
| user output |
|---|
| (empty) |
Error:
*** buffer overflow detected ***: terminated
