CODE FESTIVAL 2016 Exhibition(Parallel)

Submission #1057660

Source codeソースコード

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

int n;
pair<int,int> a[maxn];

bool check_1(){
  if(a[1].first!=0||a[2].second!=0||a[2].first!=a[1].second||a[1].second==0)return false;
  for(int i=3;i<=n;i++)
    if(a[i].first==0||a[i].second==0||a[i].first+a[i].second<a[1].first+a[1].second)return false;
  set<pair<int,int>>st;
  for(int i=1;i<=n;i++)st.insert(a[i]);
  for(int i=3;i<=n;i++){
    int cnt=0;
    for(int j=-1;j<=1;j++)
      if(st.find(make_pair(a[i].first-1,a[i].second+j))!=st.end()){
        cnt++;
        break;
      }
    for(int j=-1;j<=1;j++)
      if(st.find(make_pair(a[i].first+j,a[i].second-1))!=st.end()){
        cnt++;
        break;
      }
      if(cnt<2)return false;
  }
  return true;
}

bool cmp(pair<int,int> a,pair<int,int> b){
  int ta = a.first + a.second;
  int tb = b.first + b.second;
  return ta == tb ? a.first < b.first: ta < tb;
}

int cal(){
  int ret=0;
  sort(a+1,a+n+1,cmp);
  map<pair<int,int>,int>mp;
  for(int i=1;i<=n;i++){
    int pos = i;
    vector<pair<int,int>>v;
    v.push_back(a[i]);
    for(int j = i;j<=n;j++){
      if(a[j].first + a[j].second!=a[i].first + a[i].second)break;
      pos = j;
      if(mp.find(a[j])==mp.end())mp[a[j]]=1;
      else mp[a[j]]+=1;
      if(j>i&&a[j]!=a[j-1])v.push_back(a[j]);
    }
    int l = 0;
    for(int j=0;j<v.size();j++){
      int nl = mp[v[j]];
      int nr = nl;
      if(v[j].second==0)nr=0;
      ret+=min(l,nl);
      nl-=l;
      if(nl<0)nl=0;
      if(mp.find(make_pair(v[j].first-1,v[j].second-1))!=mp.end()){
        ret+=min(nl,nr);
        nr -= min(nl,nr);
      }
      l = nr;
      if(l<0)l=0;
      if(j+1<v.size()&&v[j].first+1<v[j+1].first)l=0;
      //cout<<j<<" : "<<ret<<endl;
      //cout<<v[j].first<<","<<v[j].second<<endl;
    }
    i =pos;
  }
  //cout<<ret<<endl;
  return ret;
}

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;
    }
    if(!check_1()){
      cout<<-1<<endl;
      return 0;
    }
    cout<<2*n-2-cal()<<endl;
    return 0;
}

Submission

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

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt
All 1500 / 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 57 ms 1024 KB
01-02.txt AC 34 ms 1024 KB
01-03.txt AC 3 ms 256 KB
01-04.txt AC 2 ms 256 KB
01-05.txt AC 3 ms 256 KB
01-06.txt AC 29 ms 640 KB
01-07.txt AC 87 ms 1280 KB
01-08.txt AC 84 ms 1408 KB
01-09.txt AC 67 ms 1152 KB
01-10.txt AC 53 ms 1024 KB
01-11.txt AC 78 ms 1152 KB
01-12.txt AC 76 ms 1152 KB
01-13.txt AC 210 ms 7296 KB
01-14.txt AC 230 ms 8064 KB
01-15.txt AC 231 ms 7296 KB
01-16.txt AC 42 ms 1024 KB
01-17.txt AC 45 ms 1024 KB
01-18.txt AC 43 ms 1024 KB
01-19.txt AC 219 ms 7420 KB
01-20.txt AC 182 ms 6268 KB
01-21.txt AC 186 ms 6272 KB
01-22.txt AC 149 ms 3840 KB
01-23.txt AC 58 ms 1280 KB
01-24.txt AC 64 ms 1280 KB
01-25.txt AC 39 ms 1024 KB
01-26.txt AC 40 ms 1024 KB
01-27.txt AC 39 ms 1024 KB
01-28.txt AC 40 ms 1024 KB
01-29.txt AC 3 ms 256 KB
01-30.txt AC 2 ms 256 KB
01-31.txt AC 3 ms 256 KB
sample-01.txt AC 2 ms 256 KB
sample-02.txt AC 2 ms 256 KB