Submission #75815104
Source Code Expand
#include <bits/stdc++.h>
#pragma warning(disable:4996)
#pragma comment(linker,"/STACK:336777216")
#pragma GCC optimize("03,unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll,ll>;
ll POW(ll a,ll b,ll rem) {
ll p=1;
a %= rem;
for (;b;b>>=1,a=(a*a)%rem) {
if (b&1)p = (p*a)%rem;
}
return p;
}
tuple<ll,ll,ll> extended_gcd(ll a,ll b) {
if (a==0) return {b,0,1};
auto [g,x,y] = extended_gcd(b%a,a);
return {g,y-(b/a)*x,x};
}
ll modinverse(ll a ,ll m) {
return (get<1>(extended_gcd(a,m))%m+m)%m;
}
void pre() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void pre2() {
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
}
void presolve() {
}
void solve() {
ll N,M;
cin>>N>>M;
vl a(N+1),b(M+1),cnt(1e6+1);
for (int i=1;i<=N;i++) {
cin>>a[i];
cnt[a[i]]++;
}
for (int i=1;i<=M;i++)cin>>b[i];
vl table(M+1);
table[0]=-1;
for (int i=2;i<=M;i++) {
ll tar = table[i-1];
while (tar!=-1&&b[tar+1]!=b[i])tar = table[tar];
tar++;
table[i] = tar;
}
//for (int i=0;i<=M;i++)cout<<table[i]<<" ";
ll s=1;
for (int i=1;i<=N;i++) {
if (cnt[b[s]]==0)break;
cout<<b[s]<<" ";
cnt[b[s]]--;
if (s==M)s=table[s];
s++;
}
for (int i=0;i<=1e6;i++) {
for (int j=1;j<=cnt[i];j++)cout<<i<<" ";
}
}
int main() {
pre();
presolve();
ll t=1;
//cin>>t;
while (t--) solve();
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Rearrangement |
| User | kuming19 |
| Language | C++23 (GCC 15.2.0) |
| Score | 100 |
| Code Size | 1697 Byte |
| Status | AC |
| Exec Time | 151 ms |
| Memory | 38828 KiB |
Compile Error
./Main.cpp:2: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
2 | #pragma warning(disable:4996)
./Main.cpp:3: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
3 | #pragma comment(linker,"/STACK:336777216")
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 100 / 100 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00-sample-001.txt, 00-sample-002.txt |
| All | 00-sample-001.txt, 00-sample-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt, 01-027.txt, 01-028.txt, 01-029.txt, 01-030.txt, 01-031.txt, 01-032.txt, 01-033.txt, 01-034.txt, 01-035.txt, 01-036.txt, 01-037.txt, 01-038.txt, 01-039.txt, 01-040.txt, 01-041.txt, 01-042.txt, 01-043.txt, 01-044.txt, 01-045.txt, 01-046.txt, 01-047.txt, 01-048.txt, 01-049.txt, 01-050.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-001.txt | AC | 5 ms | 11044 KiB |
| 00-sample-002.txt | AC | 5 ms | 11124 KiB |
| 01-003.txt | AC | 4 ms | 10980 KiB |
| 01-004.txt | AC | 4 ms | 11036 KiB |
| 01-005.txt | AC | 4 ms | 11052 KiB |
| 01-006.txt | AC | 5 ms | 11036 KiB |
| 01-007.txt | AC | 4 ms | 11008 KiB |
| 01-008.txt | AC | 4 ms | 10944 KiB |
| 01-009.txt | AC | 72 ms | 22700 KiB |
| 01-010.txt | AC | 7 ms | 11048 KiB |
| 01-011.txt | AC | 14 ms | 12048 KiB |
| 01-012.txt | AC | 18 ms | 12704 KiB |
| 01-013.txt | AC | 27 ms | 13684 KiB |
| 01-014.txt | AC | 73 ms | 21932 KiB |
| 01-015.txt | AC | 82 ms | 27052 KiB |
| 01-016.txt | AC | 151 ms | 37548 KiB |
| 01-017.txt | AC | 76 ms | 21160 KiB |
| 01-018.txt | AC | 127 ms | 28584 KiB |
| 01-019.txt | AC | 60 ms | 19076 KiB |
| 01-020.txt | AC | 78 ms | 22440 KiB |
| 01-021.txt | AC | 70 ms | 19876 KiB |
| 01-022.txt | AC | 65 ms | 21668 KiB |
| 01-023.txt | AC | 61 ms | 19060 KiB |
| 01-024.txt | AC | 125 ms | 28848 KiB |
| 01-025.txt | AC | 67 ms | 18932 KiB |
| 01-026.txt | AC | 84 ms | 29100 KiB |
| 01-027.txt | AC | 67 ms | 18960 KiB |
| 01-028.txt | AC | 75 ms | 28320 KiB |
| 01-029.txt | AC | 66 ms | 18868 KiB |
| 01-030.txt | AC | 62 ms | 18976 KiB |
| 01-031.txt | AC | 116 ms | 38576 KiB |
| 01-032.txt | AC | 74 ms | 20436 KiB |
| 01-033.txt | AC | 98 ms | 25264 KiB |
| 01-034.txt | AC | 135 ms | 38824 KiB |
| 01-035.txt | AC | 144 ms | 38824 KiB |
| 01-036.txt | AC | 139 ms | 38828 KiB |
| 01-037.txt | AC | 98 ms | 32428 KiB |
| 01-038.txt | AC | 94 ms | 30120 KiB |
| 01-039.txt | AC | 107 ms | 37540 KiB |
| 01-040.txt | AC | 109 ms | 37548 KiB |
| 01-041.txt | AC | 87 ms | 28844 KiB |
| 01-042.txt | AC | 105 ms | 36268 KiB |
| 01-043.txt | AC | 82 ms | 25512 KiB |
| 01-044.txt | AC | 102 ms | 34728 KiB |
| 01-045.txt | AC | 84 ms | 26032 KiB |
| 01-046.txt | AC | 97 ms | 32936 KiB |
| 01-047.txt | AC | 72 ms | 21676 KiB |
| 01-048.txt | AC | 68 ms | 21676 KiB |
| 01-049.txt | AC | 80 ms | 22952 KiB |
| 01-050.txt | AC | 76 ms | 23208 KiB |