Submission #473146

#TimeUsernameProblemLanguageResultExecution timeMemory
473146MamdouhNZigZag (COCI17_zigzag)C++17
8 / 80
2079 ms14252 KiB
#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; } }

Compilation message (stderr)

zigzag.cpp: In function 'std::string bs(char)':
zigzag.cpp:41:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     if(z>words.size())z = mid;
      |        ~^~~~~~~~~~~~~
zigzag.cpp: At global scope:
zigzag.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   48 | main()
      | ^~~~
zigzag.cpp: In function 'std::string bs(char)':
zigzag.cpp:40:9: warning: 'mid' may be used uninitialized in this function [-Wmaybe-uninitialized]
   40 |     int z = mid+(x-mid)+2;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...