Files
judge/example/mem-limit/solution.c
Mikhail Kornilovich e9f07dc47b
Some checks failed
memory-limit / Build judge (push) Successful in 18s
memory-limit / Linux / gcc (push) Failing after 14s
memory-limit / Linux / clang (push) Failing after 15s
memory-limit / Windows / clang (push) Failing after 16s
memory-limit / Windows / msvc (push) Failing after 17s
test memory limit
2026-04-10 23:41:37 +03:00

28 lines
618 B
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv) {
if (argc < 2) {
fprintf(stderr, "usage: %s <megabytes>\n", argv[0]);
return 1;
}
long mb = strtol(argv[1], NULL, 10);
if (mb <= 0) return 1;
size_t bytes = (size_t)mb * 1024 * 1024;
char *p = (char *)malloc(bytes);
if (!p) {
fprintf(stderr, "malloc failed\n");
return 2;
}
for (size_t i = 0; i < bytes; i += 4096) {
p[i] = (char)(i & 0xff);
}
volatile char sink = p[bytes - 1];
(void)sink;
printf("ok %ld\n", mb);
return 0;
}