제출 #916492

#제출 시각아이디문제언어결과실행 시간메모리
916492WJR_daggerStone Arranging 2 (JOI23_ho_t1)C++17
25 / 100
2093 ms1116 KiB
#include<bits/stdc++.h> #include <bits/extc++.h> using namespace std; using namespace __gnu_pbds; //#define int long long #define endl "\n" #define pb push_back #define f first #define s second #define all(x) x.begin(), x.end() #define cout_line cout<<"line"<<__LINE__<<endl #define cout_val(x) cout<<#x<<": "<<x<<endl const long long mod=1e9+7; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n;cin>>n; int arr[n]={}; for(int i=0;i<n;i++) { cin>>arr[i]; } int l=0,r=0; set<int> cnt; while(r<n) { int val; while(r<n){ if(cnt.count(arr[r])==0) { cnt.insert(arr[r]); r++; } else{ val=arr[r]; break; } } if(r==n) goto end; int idx=r; for(l=r-1;l>=0;l--) { if(arr[l]==val){ while(arr[l-1]==val){ l--; } idx=l; break; } } for(int i=idx;i<r;i++) { cnt.erase(arr[i]); arr[i]=val; } cnt.insert(val); r++; } end:; for(int i:arr){ cout<<i<<" "; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...