QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#561909 | #1979. Gratitude | V-ioleT | WA | 4ms | 50424kb | C++17 | 1.4kb | 2024-09-13 12:49:49 | 2024-09-13 12:49:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define ull unsigned long long
typedef long long ll;
#define lowbit(x) ((x) & -(x))
const ll INF = 0x3f3f3f3f;
const ll mod = 998244353;
const int N = 1e6 + 5, M = 5e5 + 10;
typedef pair<int, int> PII;
double T = 1 >> 30;
// double PI = acos(-1);
int gcd(int a, int b)
{
return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b)
{
return a / gcd(a, b) * b;
}
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;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 50424kb
input:
1 1 C B A
output:
B
result:
wrong answer 1st lines differ - expected: 'A', found: 'B'