#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=a; i<b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define INF ((ll) pow(2,63) -1)
#define si signed
ll insig;
#define In(vecBRO, LENBRO) REP(IBRO,0,LENBRO) {cin>>insig; vecBRO.pb(insig);}
void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
vector<priority_queue<pair<ll,string> > > qi; priority_queue<pair<ll,string> > xx; REP(i,0,26) {qi.pb(xx);}
ll N,K; cin>>K>>N; string s;
REP(i,0,K)
{
cin>>s;
qi[(ll) (s[0]-'a')].push(mp(0,s));
}
vector<priority_queue<pl> > q;
vector<string> cur; vector<vector<string> > str;
char c; pair<ll,string> item;
REP(i,0,26)
{
cur.clear(); priority_queue<pl> xxx; ll j=0;
while(qi[i].size()>0) {item=qi[i].top(); cur.pb(item.ss); xxx.push(mp(0,j)); qi[i].pop();j++;}
q.pb(xxx); str.pb(cur);
}
pl ped; ll ind;
REP(i,0,N)
{
cin>>c; ind = (ll) (c-'a');
ped = q[ind].top(); q[ind].pop();
ped.ff--; cout<<str[ind][ped.ss]<<endl; q[ind].push(ped);
}
return 0;
}
Compilation message
zigzag.cpp: In function 'void Out(std::vector<long long int>)':
zigzag.cpp:11:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define REP(i,a,b) for(ll i=a; i<b; i++)
zigzag.cpp:21:29:
void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}
~~~~~~~~~~~~
zigzag.cpp:21:25: note: in expansion of macro 'REP'
void Out(vector<ll> x) {REP(i,0,x.size()) {cout<<x[i]<<" ";} cout<<endl;}
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
407 ms |
13600 KB |
Output is correct |
8 |
Correct |
410 ms |
13588 KB |
Output is correct |
9 |
Correct |
409 ms |
13592 KB |
Output is correct |
10 |
Correct |
407 ms |
13600 KB |
Output is correct |