Submission #473127

#TimeUsernameProblemLanguageResultExecution timeMemory
473127MamdouhNZigZag (COCI17_zigzag)C++17
48 / 80
2083 ms13728 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define endl "\n" vector<string>words; map<string,int>done; 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; 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)en =mid; } mid=(st+en)/2; done[words[mid]]++; return words[mid]; } main() { int n,q; cin>>n>>q; for(int i=0;i<n;i++) { string x; cin>>x; words.push_back(x); } while(q--) { sort(words.begin(),words.end(),comp); char c; cin>>c; cout<<bs(c)<<endl;; } }

Compilation message (stderr)

zigzag.cpp:32:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   32 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...