QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#561908#1979. GratitudeV-ioleTWA 0ms50460kbC++171.1kb2024-09-13 12:48:282024-09-13 12:48:28

Judging History

你现在查看的是最新测评结果

  • [2024-09-13 12:48:28]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:50460kb
  • [2024-09-13 12:48:28]
  • 提交

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'