Submission #83346

# Submission time Handle Problem Language Result Execution time Memory
83346 2018-11-07T08:33:16 Z charlies_moo Rasvjeta (COCI17_rasvjeta) C++17
50 / 50
2 ms 532 KB
#include <cstdio>
#include <cstring>

int main() {
    int n, m, k;
    scanf("%d", &n);
    scanf("%d", &m);
    scanf("%d", &k);

    bool s[n];
    memset(s, 0, sizeof(s));
    for (int i = 0; i < m; i++) {
        int a;
        scanf("%d", &a);
        a--;
        int l = a - k;
        if (l < 0) {
            l = 0;
        }
        int r = a + k;
        if (r >= n) {
            r = n - 1;
        }
        for (int j = l; j <= r; j++) {
            s[j] = 1;
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 0) {
            ans++;
            int l = i;
            int r = i + 2 * k;
            if (r >= n) {
                r = n - 1;
            }
            for (int j = l; j <= r; j++) {
                s[j] = 1;
            }
        }
    }

    printf("%d\n", ans);

    return 0;
}

Compilation message

rasjveta.cpp: In function 'int main()':
rasjveta.cpp:6:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
rasjveta.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &m);
     ~~~~~^~~~~~~~~~
rasjveta.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &k);
     ~~~~~^~~~~~~~~~
rasjveta.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a);
         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 480 KB Output is correct
5 Correct 2 ms 480 KB Output is correct
6 Correct 2 ms 480 KB Output is correct
7 Correct 2 ms 516 KB Output is correct
8 Correct 2 ms 516 KB Output is correct
9 Correct 2 ms 516 KB Output is correct
10 Correct 2 ms 532 KB Output is correct