Submission #2601462


Source Code Expand

#include <cstdio>
#include <vector>
#include <map>

using namespace std;

long long d;
long long a[50];
int b[100000];
int c[100000];
vector <long long> v[100001];
map <long long, int> mp;

long long add(long long x) {
    map <long long, int>::iterator now, before, next;
    
    if (mp.count(x)) {
        mp[x]++;
        
        return 0;
    }
    
    mp[x] = 1;
    
    now = before = next = mp.find(x);
    before--;
    next++;
    
    if (next->first - before->first - 1 <= d) {
        return 0;
    } else {
        long long ans = 1;
        
        if (now->first - before->first - 1 <= d) ans += now->first - before->first - 1;
        if (next->first - now->first - 1 <= d) ans += next->first - now->first - 1;
        
        return ans;
    }
}

long long remove(long long x) {
    map <long long, int>::iterator now, before, next;
    
    if (mp[x] >= 2) {
        mp[x]--;
        
        return 0;
    }
    
    now = before = next = mp.find(x);
    before--;
    next++;
    
    if (next->first - before->first - 1 <= d) {
        mp.erase(x);
        
        return 0;
    } else {
        long long ans = 1;
        
        if (now->first - before->first - 1 <= d) ans += now->first - before->first - 1;
        if (next->first - now->first - 1 <= d) ans += next->first - now->first - 1;
        
        mp.erase(x);
        
        return ans;
    }
}

int main() {
    int y, w, n, m, i, j;
    long long ans = 0;
    
    scanf("%d %d", &y, &w);
    scanf("%d %d %lld", &n, &m, &d);
    
    for (i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
        
        a[i]--;
    }
    
    for (i = 0; i < m; i++) {
        scanf("%d %d", &b[i], &c[i]);
        
        b[i]--;
        c[i]--;
        
        v[c[i]].push_back(b[i]);
    }
    
    mp[-1e18] = 1;
    mp[1e18] = 1;
    
    for (i = 0; i < n; i++) ans += add(a[i]);
    for (i = 0; i < m; i++) ans += add((long long)b[i] * w + c[i]);
    
    printf("%lld\n", ans);
    
    for (i = 0; i < w - 1; i++) {
        for (j = 0; j < n; j++) ans -= remove(a[j] + i);
        for (j = 0; j < v[i].size(); j++) ans -= remove(v[i][j] * w + i);
        
        for (j = 0; j < n; j++) ans += add(a[j] + i + 1);
        for (j = 0; j < v[i].size(); j++) ans += add((v[i][j] + 1) * w + i);
        
        printf("%lld\n", ans);
    }
    
    return 0;
}

Submission Info

Submission Time
Task E - 祝日
User kawatea
Language C++14 (GCC 5.4.1)
Score 700
Code Size 2467 Byte
Status AC
Exec Time 3007 ms
Memory 14464 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:74:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &y, &w);
                           ^
./Main.cpp:75:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %lld", &n, &m, &d);
                                    ^
./Main.cpp:78:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &a[i]);
                             ^
./Main.cpp:84:37: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &b[i], &c[i]);
                                     ^

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 600 / 600 100 / 100
Status
AC × 4
AC × 22
AC × 56
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
Subtask1 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, sample-01.txt, sample-02.txt
All 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt, 02-17.txt, 02-18.txt, 02-19.txt, 02-20.txt, 02-21.txt, 02-22.txt, 02-23.txt, 02-24.txt, 02-25.txt, 02-26.txt, 02-27.txt, 02-28.txt, 02-29.txt, 02-30.txt, 02-31.txt, 02-32.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
Case Name Status Exec Time Memory
01-01.txt AC 210 ms 13184 KB
01-02.txt AC 197 ms 12288 KB
01-03.txt AC 122 ms 10240 KB
01-04.txt AC 38 ms 5248 KB
01-05.txt AC 194 ms 11008 KB
01-06.txt AC 199 ms 10624 KB
01-07.txt AC 138 ms 10440 KB
01-08.txt AC 29 ms 5120 KB
01-09.txt AC 248 ms 11904 KB
01-10.txt AC 31 ms 4608 KB
01-11.txt AC 158 ms 12288 KB
01-12.txt AC 182 ms 13824 KB
01-13.txt AC 183 ms 12288 KB
01-14.txt AC 62 ms 6784 KB
01-15.txt AC 202 ms 11264 KB
01-16.txt AC 5 ms 2688 KB
01-17.txt AC 45 ms 4992 KB
01-18.txt AC 232 ms 10624 KB
01-19.txt AC 220 ms 13184 KB
01-20.txt AC 216 ms 12416 KB
02-01.txt AC 2391 ms 13184 KB
02-02.txt AC 740 ms 11392 KB
02-03.txt AC 749 ms 14208 KB
02-04.txt AC 1140 ms 12544 KB
02-05.txt AC 2175 ms 13056 KB
02-06.txt AC 1113 ms 11648 KB
02-07.txt AC 143 ms 10460 KB
02-08.txt AC 205 ms 3712 KB
02-09.txt AC 1467 ms 12288 KB
02-10.txt AC 104 ms 4352 KB
02-11.txt AC 1695 ms 12928 KB
02-12.txt AC 513 ms 11520 KB
02-13.txt AC 706 ms 11264 KB
02-14.txt AC 116 ms 3968 KB
02-15.txt AC 566 ms 11264 KB
02-16.txt AC 27 ms 2688 KB
02-17.txt AC 70 ms 4992 KB
02-18.txt AC 278 ms 10624 KB
02-19.txt AC 2576 ms 14464 KB
02-20.txt AC 76 ms 10356 KB
02-21.txt AC 397 ms 3328 KB
02-22.txt AC 3 ms 2560 KB
02-23.txt AC 3007 ms 13440 KB
02-24.txt AC 1660 ms 11520 KB
02-25.txt AC 1382 ms 13312 KB
02-26.txt AC 4 ms 2560 KB
02-27.txt AC 96 ms 2688 KB
02-28.txt AC 373 ms 2944 KB
02-29.txt AC 220 ms 10368 KB
02-30.txt AC 219 ms 10496 KB
02-31.txt AC 227 ms 10496 KB
02-32.txt AC 230 ms 2816 KB
sample-01.txt AC 3 ms 2560 KB
sample-02.txt AC 3 ms 2560 KB
sample-03.txt AC 3 ms 2560 KB
sample-04.txt AC 3 ms 2560 KB