| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 473146 | MamdouhN | ZigZag (COCI17_zigzag) | C++17 | 2079 ms | 14252 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
vector<string>words;
map<string,int>done;
int n,q;
bool comp(string a,string b)
{
    if(a[0]!=b[0])return a<b;
    if(done[a]==done[b])return a<b;
    return done[a]<done[b];
}
string bs(char c)
{
    int st=0,en=words.size();
    int mid;
    int x = -1;
    while(st<en)
    {
        mid=(st+en)/2;
        if(words[mid][0]>c)en = mid-1;
        if(words[mid][0]<c)st = mid+1;
        if(words[mid][0]==c)
        {
            if(x==-1)x=mid;
            en =mid;
        }
    }
    if(x==-1)x=mid;
    mid=(st+en)/2;
    done[words[mid]]++;
    string ret = words[mid];
    //for(auto v: words)cout<<v<<" ";
    //cout<<endl;
    //cout<<mid<<" "<<x<<endl;
    int z = mid+(x-mid)+2;
    if(z>words.size())z = mid;
    //cout<<mid<<" "<<z<<endl;
    sort(words.begin()+mid,words.begin()+z,comp);
    //for(auto v: words)cout<<v<<" ";
    //cout<<endl;
    return ret;
}
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>q;
    for(int i=0;i<n;i++)
    {
        string x;
        cin>>x;
        words.push_back(x);
    }
    sort(words.begin(),words.end(),comp);
    while(q--)
    {
        char c;
        cin>>c;
        cout<<bs(c)<<endl;
    }
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
