QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#561908 | #1979. Gratitude | V-ioleT | WA | 0ms | 50460kb | C++17 | 1.1kb | 2024-09-13 12:48:28 | 2024-09-13 12:48:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef long long ll;
const ll INF = 0x3f3f3f3f;
const ll mod = 998244353;
const int N = 1e6 + 5;
struct node
{
string s;
int id;
int num;
} a[N];
bool cmp(node a, node b)
{
if (a.num != b.num)
{
return a.num > b.num;
}
else
{
return a.id > b.id;
}
}
void solve()
{
int i, j;
int n, k;
cin >> n >> k;
getchar();
map<string, int> mp;
int cnt = 0;
for (i = 1; i <= 3 * n; i++)
{
string s;
getline(cin, s);
if (mp[s] == 0)
{
mp[s] = ++cnt;
}
int id = mp[s];
a[id].id = i;
a[id].num++;
a[id].s = s;
}
sort(a + 1, a + 1 + cnt, cmp);
for (i = 1; i <= min(k, cnt); i++)
{
cout << a[i].s << endl;
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 50460kb
input:
1 1 C B A
output:
B
result:
wrong answer 1st lines differ - expected: 'A', found: 'B'