Submission #1000092


Source Code Expand

#include <cstdio>
#include <map>

using namespace std;

map <pair<int, int>, int> mp[200000];

bool check(pair<int, int> p, int da, int db) {
    int a = p.first + da;
    int b = p.second + db;
    
    if (a + b < 0) return false;
    
    return mp[a + b].count(make_pair(a, b));
}

bool before(pair<int, int> p) {
    return check(p, -1, -1) || check(p, -1, 0) || check(p, -1, 1);
}

bool after(pair<int, int> p) {
    return check(p, -1, -1) || check(p, 0, -1) || check(p, 1, -1);
}

int solve() {
    int n, d, ans, i;
    map <pair<int, int>, int>::iterator it, it2;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        int a, b;
        
        scanf("%d %d", &a, &b);
        
        if (i == 0) {
            if (a != 0 || b == 0) return -1;
            
            d = b;
        } else if (i == 1) {
            if (a != d || b != 0) return -1;
        } else {
            if (a == 0 || b == 0 || a + b < d) return -1;
        }
        
        mp[a + b][make_pair(a, b)]++;
    }
    
    ans = n * 2 - 2;
    
    for (i = d; i < n * 2; i++) {
        int c;
        
        if (mp[i].size() == 0) continue;
        
        for (it = mp[i].begin(); it != mp[i].end(); it++) {
            if (!before(it->first) && it->first.first > 0) return -1;
            if (!after(it->first) && it->first.second > 0) return -1;
            
            if (it != mp[i].begin()) {
                it2 = it;
                it2--;
                
                if (it2->first.first + 1 == it->first.first) {
                    if (i == d) return -1;
                    
                    ans -= min(it->second, c);
                    it->second = max(it->second - c, 0);
                }
            }
            
            if (check(it->first, -1, -1)) {
                ans -= it->second;
                c = 0;
            } else {
                c = it->second;
            }
        }
    }
    
    return ans;
}

int main() {
    printf("%d\n", solve());
    
    return 0;
}

Submission Info

Submission Time
Task A - Distance Pairs
User kawatea
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2107 Byte
Status WA
Exec Time 68 ms
Memory 15872 KB

Compile Error

./Main.cpp: In function ‘int solve()’:
./Main.cpp:29:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
./Main.cpp:34:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
                               ^

Judge Result

Set Name sample All
Score / Max Score 0 / 0 0 / 1500
Status
AC × 1
WA × 1
AC × 12
WA × 21
Set Name Test Cases
sample sample-01.txt, sample-02.txt
All sample-01.txt, sample-02.txt, 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, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt
Case Name Status Exec Time Memory
01-01.txt AC 12 ms 9600 KB
01-02.txt AC 12 ms 9600 KB
01-03.txt WA 12 ms 9600 KB
01-04.txt WA 12 ms 9600 KB
01-05.txt WA 12 ms 9600 KB
01-06.txt WA 20 ms 9600 KB
01-07.txt WA 32 ms 9856 KB
01-08.txt WA 32 ms 9984 KB
01-09.txt WA 29 ms 9728 KB
01-10.txt WA 26 ms 9600 KB
01-11.txt WA 30 ms 9728 KB
01-12.txt WA 29 ms 9728 KB
01-13.txt WA 49 ms 15872 KB
01-14.txt WA 68 ms 15872 KB
01-15.txt WA 46 ms 15872 KB
01-16.txt WA 25 ms 9600 KB
01-17.txt WA 25 ms 9600 KB
01-18.txt WA 25 ms 9600 KB
01-19.txt WA 62 ms 15872 KB
01-20.txt WA 63 ms 14720 KB
01-21.txt WA 64 ms 14720 KB
01-22.txt WA 53 ms 12288 KB
01-23.txt AC 32 ms 9984 KB
01-24.txt AC 32 ms 9984 KB
01-25.txt AC 12 ms 9600 KB
01-26.txt AC 12 ms 9600 KB
01-27.txt AC 23 ms 9856 KB
01-28.txt AC 22 ms 9856 KB
01-29.txt AC 12 ms 9600 KB
01-30.txt AC 12 ms 9600 KB
01-31.txt AC 12 ms 9600 KB
sample-01.txt WA 12 ms 9600 KB
sample-02.txt AC 12 ms 9600 KB