CODE FESTIVAL 2016 Exhibition(Parallel)

Submission #1053138

Source codeソースコード

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
const int maxn = 100005;

set<pair<int,int>> st;
pair<int,int> a[maxn];
bool vis[maxn];
int n;

bool cmp(pair<int,int>a,pair<int,int>b){
    int tt =  min(a.first,a.second) - min(b.first, b.second);
    if(tt<0)return true;
    if(tt>0)return false;
    if(a.first==b.first)return a.second<b.second;
    if(a.second==b.second)return a.first<b.first;
    return true;
}

bool check_1() {
    if(a[1].first!=0||a[2].second!=0||a[1].second!=a[2].first)return false;
    return true;
}

bool check_2(int&ret) {
    if(n>2)sort(a+3,a+n+1, cmp);
    if(a[1].second==0)return false;
    vis[1] = vis[2] = 1;
    st.insert(a[1]);
    st.insert(a[2]);
    ret += a[1].second;
    if(a[1].second==1) return true;
    int cnt = 0;
    for(int i=3; i<=n; i++) {
        if(a[i].first + a[i].second != a[1].second) continue;
        if(st.find(a[i])!=st.end())continue;
        st.insert(a[i]);
        vis[i] = 1;
        cnt++;
    }
    return cnt == a[1].second - 1;
}

bool pd(int x,int y) {
    int x1 = x - 1, y1, x2, y2 = y - 1;
    for(int y1 = y-1; y1<=y+1; y1++)
        for(int x2=x-1; x2<=x+1; x2++) {
            if(st.find(make_pair(x1,y1))==st.end())continue;
            if(st.find(make_pair(x2,y2))==st.end())continue;
            return true;
        }
    return false;
}

bool check_3(int&ret) {
    for(int i=3; i<=n; i++) {
        if(vis[i])continue;
        pair<int,int> fa = make_pair(a[i].first-1,a[i].second-1);
        if(st.find(fa)!=st.end()) {
            vis[i]=1;
            ret++;
            st.insert(a[i]);
        } else {
            if(pd(a[i].first,a[i].second)) {
                vis[i] = 1;
                ret+=2;
                st.insert(a[i]);
            } else return false;
        }
    }
    return true;
}

int main() {
    //freopen("in.cpp","r",stdin);
    cin>>n;
    for(int i=1; i<=n; i++) {
        int x,y;
        cin>>x>>y;
        a[i].first = x;
        a[i].second = y;
    }
    int ret = 0;
    if(!check_1()) {
        cout<<-1<<endl;
        return 0;
    }
    if(!check_2(ret)) {
        cout<<-1<<endl;
        return 0;
    }
    if(!check_3(ret)) {
        cout<<-1<<endl;
        return 0;
    }
    cout<<ret<<endl;
    return 0;
}

Submission

Task問題 A - Distance Pairs
User nameユーザ名 suiyuan2009
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 2517 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt
All 0 / 1500 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 79 ms 1024 KB
01-02.txt AC 696 ms 1024 KB
01-03.txt AC 3 ms 256 KB
01-04.txt AC 3 ms 256 KB
01-05.txt AC 3 ms 256 KB
01-06.txt WA
01-07.txt WA
01-08.txt WA
01-09.txt WA
01-10.txt WA
01-11.txt AC 98 ms 1280 KB
01-12.txt AC 95 ms 1152 KB
01-13.txt AC 106 ms 5760 KB
01-14.txt AC 114 ms 5760 KB
01-15.txt AC 112 ms 5760 KB
01-16.txt AC 50 ms 1152 KB
01-17.txt AC 61 ms 1152 KB
01-18.txt AC 56 ms 1152 KB
01-19.txt WA
01-20.txt WA
01-21.txt WA
01-22.txt WA
01-23.txt AC 122 ms 1024 KB
01-24.txt AC 174 ms 1024 KB
01-25.txt AC 49 ms 1024 KB
01-26.txt AC 51 ms 1024 KB
01-27.txt AC 154 ms 1024 KB
01-28.txt AC 155 ms 1024 KB
01-29.txt AC 3 ms 256 KB
01-30.txt AC 3 ms 256 KB
01-31.txt AC 3 ms 256 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 3 ms 256 KB