Submission #473136

#TimeUsernameProblemLanguageResultExecution timeMemory
473136MamdouhNZigZag (COCI17_zigzag)C++17
48 / 80
2092 ms13648 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; 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)en =mid; } mid=(st+en)/2; done[words[mid]]++; return words[mid]; } main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); 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: In function 'std::string bs(char)':
zigzag.cpp:20:9: warning: unused variable 'x' [-Wunused-variable]
   20 |     int x = -1;
      |         ^
zigzag.cpp: At global scope:
zigzag.cpp:32:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   32 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...