# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
493895 | Karabasan | ZigZag (COCI17_zigzag) | C++17 | 58 ms | 8344 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define fast1 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,avx")
#pragma GCC optimize("unroll-loops")
int n,a,b,k;
string s[100005];
char dizi[100005];
pair<int,int> ptr[30];
void solve()
{
memset(ptr,-1,sizeof ptr);
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>s[i];
for(int i=0;i<k;i++)
cin>>dizi[i];
sort(s,s+n);
for(int i=0;i<n;i++)
{
if(ptr[s[i][0]-'a'].first==-1)
ptr[s[i][0]-'a']={i,i};
}
for(int i=0;i<k;i++)
{
if(s[ptr[dizi[i]-'a'].second][0]!=dizi[i])
ptr[dizi[i]-'a'].second=ptr[dizi[i]-'a'].first;
cout<<s[ptr[dizi[i]-'a'].second]<<endl;
ptr[dizi[i]-'a'].second++;
}
}
signed main()
{
fast1
//freopen ("lca.gir","r",stdin);
//freopen ("lca.cik","w",stdout);
int t=1;
//cin>>t;
while(t--)
{
solve();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |