Contest Duration: - (local time) (160 minutes) Back to Home

Submission #6494277

Source Code Expand

Copy
```#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main() {
ll n,k;
cin >> n >> k;

int a[n];
rep(i,n)cin >> a[i];
int count[200005];
int next[n];
int first[n];
rep(i,n){
next[i] = -1;
first[i] = -1;
}
rep(i,200005)count[i] = -1;
rep(i,n){
if(count[a[i]] == -1){
count[a[i]] = i;
next[i] = i;
first[a[i]] = i;
}else{
next[count[a[i]]] = i;
count[a[i]] = i;
next[i] = -999;
}
}

rep(i,n){
if(next[i]==-999){
next[i] = first[a[i]];
}
}

ll now = 0;

while(true){
ll tmp = now;
int x = a[now%n];
if(next[now%n]==now%n){
now += n;
now++;
}else if(next[now%n]>now%n){
now += (next[now%n]-now%n);
now++;
}else{
now += (n+next[now%n]-now%n);
now++;
}

if(now>=n*k-1){
now = tmp;
break;
}else{
if(now%n==0){
ll loop = now;
now += (((n*k-1)-now)/loop)*loop;
}
}
}

int ans[n+100] = {};
int c = 0;

while(true){
if(now == n*k)break;
int x = a[now%n];
if(next[now%n]==now%n){
if(n*k-1<now+n){
cout << x << ' ';
now++;
}else{
now = now + n;
now++;
}
}else if(next[now%n]>now%n){
if(n*k-1<now + (next[now%n]-now%n)){
cout << x << ' ';
now++;
}else{
now += (next[now%n]-now%n);
now++;
}
}else{
if(n*k-1<now + (n+next[now%n]-now%n)){
cout << x << ' ';
now++;
}else{
now += (n+next[now%n]-now%n);
now++;
}
}
}

cout << endl;
return 0;
}

```

#### Submission Info

Submission Time 2019-07-21 22:19:43+0900 B - Do Not Duplicate Shibuyap C++14 (GCC 5.4.1) 0 2564 Byte TLE 2103 ms 5376 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
 AC × 4
 AC × 31 TLE × 3
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
All 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, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
Case Name Status Exec Time Memory
01-01.txt AC 2 ms 1024 KB
01-02.txt AC 16 ms 1792 KB
01-03.txt AC 19 ms 1792 KB
01-04.txt AC 54 ms 3712 KB
01-05.txt AC 13 ms 1536 KB
01-06.txt AC 65 ms 3840 KB
01-07.txt AC 64 ms 3456 KB
01-08.txt TLE 2103 ms 2176 KB
01-09.txt TLE 2103 ms 2944 KB
01-10.txt TLE 2103 ms 3200 KB
01-11.txt AC 51 ms 3200 KB
01-12.txt AC 35 ms 2304 KB
01-13.txt AC 50 ms 2816 KB
01-14.txt AC 43 ms 2688 KB
01-15.txt AC 68 ms 3840 KB
01-16.txt AC 66 ms 4096 KB
01-17.txt AC 60 ms 4096 KB
01-18.txt AC 65 ms 4096 KB
01-19.txt AC 78 ms 4096 KB
01-20.txt AC 75 ms 4096 KB
01-21.txt AC 72 ms 4096 KB
01-22.txt AC 85 ms 4096 KB
01-23.txt AC 88 ms 4224 KB
01-24.txt AC 88 ms 4096 KB
01-25.txt AC 100 ms 5120 KB
01-26.txt AC 101 ms 4992 KB
01-27.txt AC 95 ms 4736 KB
01-28.txt AC 78 ms 4096 KB
01-29.txt AC 76 ms 4096 KB
01-30.txt AC 102 ms 5376 KB
sample-01.txt AC 2 ms 1024 KB
sample-02.txt AC 2 ms 1024 KB
sample-03.txt AC 2 ms 1024 KB
sample-04.txt AC 2 ms 1024 KB