CODE FESTIVAL 2016 Exhibition(Parallel)

Submission #1053235

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) {
    return a.first + a.second == b.first + b.second ?
           a.first < b.first : a.first + a.second < b.first + b.second;
}
 
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=1; 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;
        }*/
        int pos = i;
        for(int j=i;j<=n;j++) {
          if(a[j].first + a[j].second != a[i].first + a[i].second)break;
          pos = j;
        }
        for(int j=i;j<=pos;j++) {
          if(vis[j]) continue;
          if(st.find(make_pair(a[j].first-1,a[j].second-1))!=st.end()) {
            vis[j] =1;
            ret++;
            st.insert(a[j]);
          }
        }
        for(int j=i;j<=pos;j++){
          if(vis[j])continue;
          if(pd(a[j].first,a[j].second)){
            vis[j] =1;
            ret+=2;
            st.insert(a[j]);
          }
        }
        for(int j = i+1;j<pos;j++) {
          if(vis[j])continue;
          if(vis[j-1]&&vis[j+1]){
            vis[j]=1;
            ret+=2;
            st.insert(a[j]);
          } else return false;
        }
        if((!vis[i]) || (!vis[pos])) return false;
        i = pos;
    }
    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;
    }
    sort(a+1,a+n+1);
    /*
    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ソースコード長 3352 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 74 ms 1024 KB
01-02.txt AC 50 ms 1024 KB
01-03.txt WA
01-04.txt WA
01-05.txt WA
01-06.txt WA
01-07.txt WA
01-08.txt WA
01-09.txt WA
01-10.txt WA
01-11.txt WA
01-12.txt WA
01-13.txt WA
01-14.txt WA
01-15.txt WA
01-16.txt WA
01-17.txt WA
01-18.txt WA
01-19.txt WA
01-20.txt WA
01-21.txt WA
01-22.txt WA
01-23.txt AC 57 ms 1024 KB
01-24.txt AC 56 ms 1024 KB
01-25.txt AC 49 ms 1024 KB
01-26.txt AC 50 ms 1024 KB
01-27.txt AC 56 ms 1024 KB
01-28.txt AC 57 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 WA
sample-02.txt AC 3 ms 256 KB