QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#561914#1979. GratitudeV-ioleTWA 4ms50520kbC++201.4kb2024-09-13 12:51:242024-09-13 12:51:25

Judging History

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

  • [2024-09-13 12:51:25]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:50520kb
  • [2024-09-13 12:51:24]
  • 提交

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: 50520kb

input:

1 1
C
B
A

output:

B

result:

wrong answer 1st lines differ - expected: 'A', found: 'B'