답안 #493895

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
493895 2021-12-13T10:02:19 Z Karabasan ZigZag (COCI17_zigzag) C++17
80 / 80
58 ms 8344 KB
#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

zigzag.cpp: In function 'void solve()':
zigzag.cpp:16:29: warning: 'void* memset(void*, int, size_t)' writing to an object of type 'struct std::pair<int, int>' with no trivial copy-assignment [-Wclass-memaccess]
   16 |     memset(ptr,-1,sizeof ptr);
      |                             ^
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from zigzag.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'struct std::pair<int, int>' declared here
  211 |     struct pair
      |            ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 2 ms 3404 KB Output is correct
4 Correct 3 ms 3456 KB Output is correct
5 Correct 2 ms 3404 KB Output is correct
6 Correct 2 ms 3472 KB Output is correct
7 Correct 58 ms 8296 KB Output is correct
8 Correct 50 ms 8300 KB Output is correct
9 Correct 48 ms 8332 KB Output is correct
10 Correct 49 ms 8344 KB Output is correct