Submission #3439181


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

struct UnionFind{
  vector<int> v;
  UnionFind(int n) : v(n, -1) {}
  void init(){ for(int i = 0;i < (int)v.size();i++)v[i]=-1; }
  int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (-v[x] < -v[y]) swap(x, y);
    v[x] += v[y]; v[y] = x;
    return true;
  }
  bool root(int x) { return v[x] < 0; }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -v[find(x)]; }
};

ll N;
ll A[200010];
vector<ll> pre[200010];
char c[200010];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin>>N;
  rep(i,N)cin>>A[i];
  UnionFind uf(N);
  rep(i,N){
    if(A[i]>1&&i-1>=0&&i+1<N){
      uf.unite(i-1,i+1);
    }
    if(A[i]>=5&&i-2>=0&&i+2<N){
      uf.unite(i-2,i+2);
    }
    ll l=i-((A[i]+1)/2);
    ll r=i+((A[i]+1)/2);
    if(l+1>0&&r-1<N){
      uf.unite(l+1,r-1);
    }
    if(l+2>0&&r-2<N){
      uf.unite(l+2,r-2);
    }
    if(l<0||r>=N)continue;
    pre[r].push_back(l);
  }
  rep(i,N){
    if(c[uf.find(i)]!=0){
      c[i]=c[uf.find(i)]; continue;
    }
    vector<bool> used(26,false);
    for(int p : pre[i]){
      used[c[p]-'a']=true;
    }
    rep(j,26){
      if(!used[j]){
        c[i]=(char)j+'a';
        break;
      }
    }
    assert(c[i]>0);
  }
  rep(i,N)cout<<c[i];
  cout<<endl;

  return 0;
}

Submission Info

Submission Time
Task H - ukuku
User SyntaxSato
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2056 Byte
Status RE
Exec Time 102 ms
Memory 12416 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 1
WA × 1
AC × 8
WA × 46
RE × 3
Set Name Test Cases
Sample 01_sample_01, 01_sample_02
All 01_sample_01, 01_sample_02, 02_hand_01, 02_hand_02, 02_hand_03, 02_hand_04, 02_hand_05, 02_hand_06, 02_hand_07, 02_hand_08, 02_hand_09, 02_hand_10, 03_hand_01, 03_hand_02, 04_small_01, 04_small_02, 04_small_03, 04_small_04, 04_small_05, 04_small_06, 04_small_07, 04_small_08, 04_small_09, 04_small_10, 04_small_11, 04_small_12, 04_small_13, 04_small_14, 04_small_15, 05_large_01, 05_large_02, 05_large_03, 05_large_04, 05_large_05, 05_large_06, 05_large_07, 05_large_08, 05_large_09, 05_large_10, 05_large_11, 05_large_12, 06_corner_01, 06_corner_02, 06_corner_03, 07_long_01, 07_long_02, 07_long_03, 08_manual_01, 08_manual_02, 08_manual_03, 08_manual_04, 08_manual_05, 08_manual_06, 08_manual_07, 08_manual_08, 08_manual_09, 08_manual_10
Case Name Status Exec Time Memory
01_sample_01 AC 3 ms 6144 KiB
01_sample_02 WA 3 ms 6144 KiB
02_hand_01 AC 3 ms 6144 KiB
02_hand_02 AC 3 ms 6144 KiB
02_hand_03 AC 3 ms 6144 KiB
02_hand_04 WA 3 ms 6144 KiB
02_hand_05 WA 3 ms 6144 KiB
02_hand_06 RE 100 ms 6144 KiB
02_hand_07 RE 101 ms 6144 KiB
02_hand_08 WA 3 ms 6144 KiB
02_hand_09 AC 3 ms 6144 KiB
02_hand_10 AC 3 ms 6144 KiB
03_hand_01 WA 3 ms 6144 KiB
03_hand_02 WA 3 ms 6144 KiB
04_small_01 WA 3 ms 6144 KiB
04_small_02 WA 3 ms 6144 KiB
04_small_03 WA 3 ms 6144 KiB
04_small_04 WA 3 ms 6144 KiB
04_small_05 RE 102 ms 6144 KiB
04_small_06 WA 3 ms 6144 KiB
04_small_07 WA 3 ms 6144 KiB
04_small_08 WA 3 ms 6144 KiB
04_small_09 WA 3 ms 6144 KiB
04_small_10 WA 3 ms 6144 KiB
04_small_11 WA 3 ms 6144 KiB
04_small_12 WA 3 ms 6144 KiB
04_small_13 WA 3 ms 6144 KiB
04_small_14 WA 3 ms 6144 KiB
04_small_15 WA 3 ms 6144 KiB
05_large_01 WA 27 ms 11008 KiB
05_large_02 WA 26 ms 10880 KiB
05_large_03 WA 22 ms 10112 KiB
05_large_04 WA 30 ms 11776 KiB
05_large_05 WA 29 ms 11392 KiB
05_large_06 WA 36 ms 12416 KiB
05_large_07 WA 36 ms 12416 KiB
05_large_08 WA 35 ms 12416 KiB
05_large_09 WA 35 ms 12416 KiB
05_large_10 WA 36 ms 12416 KiB
05_large_11 AC 18 ms 6912 KiB
05_large_12 AC 19 ms 6912 KiB
06_corner_01 WA 18 ms 8704 KiB
06_corner_02 WA 23 ms 9472 KiB
06_corner_03 WA 34 ms 11392 KiB
07_long_01 WA 32 ms 11776 KiB
07_long_02 WA 33 ms 11776 KiB
07_long_03 WA 33 ms 11004 KiB
08_manual_01 WA 21 ms 9344 KiB
08_manual_02 WA 20 ms 8832 KiB
08_manual_03 WA 33 ms 12032 KiB
08_manual_04 WA 24 ms 9344 KiB
08_manual_05 WA 28 ms 10752 KiB
08_manual_06 WA 34 ms 12160 KiB
08_manual_07 WA 35 ms 11776 KiB
08_manual_08 WA 35 ms 12416 KiB
08_manual_09 WA 33 ms 11776 KiB
08_manual_10 WA 36 ms 11392 KiB