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

Submission #6497501

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];
int ccc[200005] = {};
rep(i,n){
cin >> a[i];
ccc[a[i]]++;
}
int count[200005];

int next[200005];
int first[200005];
rep(i,200005){
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]];
}
}

/*
int tale[200005][2];
rep(i,200005){
rep(j,2){
tale[i][j] = -777;
}
}

int ddd[200005] = {};

rep(i,n){
if(ccc[a[i]]>=4){
if(ddd[a[i]]==0){
}else if(ddd[a[i]]==1){
}else if(ddd[a[i]]==ccc[a[i]]-2){
tale[a[i]][0] = i;
}else if(ddd[a[i]]==ccc[a[i]]-1){
tale[a[i]][1] = i;
}
}
ddd[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 23:31:08+0900 B - Do Not Duplicate Shibuyap C++14 (GCC 5.4.1) 700 3301 Byte AC 101 ms 5376 KB

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
 AC × 4
 AC × 34
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 2560 KB
01-02.txt AC 17 ms 2944 KB
01-03.txt AC 19 ms 2944 KB
01-04.txt AC 54 ms 3968 KB
01-05.txt AC 14 ms 2816 KB
01-06.txt AC 64 ms 3968 KB
01-07.txt AC 62 ms 3712 KB
01-08.txt AC 46 ms 3328 KB
01-09.txt AC 68 ms 3840 KB
01-10.txt AC 75 ms 3968 KB
01-11.txt AC 52 ms 3968 KB
01-12.txt AC 35 ms 3200 KB
01-13.txt AC 50 ms 3584 KB
01-14.txt AC 42 ms 3456 KB
01-15.txt AC 69 ms 3968 KB
01-16.txt AC 65 ms 4096 KB
01-17.txt AC 63 ms 4096 KB
01-18.txt AC 64 ms 4096 KB
01-19.txt AC 78 ms 4096 KB
01-20.txt AC 74 ms 4096 KB
01-21.txt AC 74 ms 4096 KB
01-22.txt AC 84 ms 4096 KB
01-23.txt AC 90 ms 4096 KB
01-24.txt AC 87 ms 4096 KB
01-25.txt AC 101 ms 5120 KB
01-26.txt AC 100 ms 4992 KB
01-27.txt AC 96 ms 4736 KB
01-28.txt AC 76 ms 4096 KB
01-29.txt AC 77 ms 4096 KB
01-30.txt AC 100 ms 5376 KB
sample-01.txt AC 2 ms 2560 KB
sample-02.txt AC 2 ms 2560 KB
sample-03.txt AC 2 ms 2560 KB
sample-04.txt AC 2 ms 2560 KB