记录编号 570796 评测结果 AAAAAAAAAA
题目名称 [NOI Online 2020 3rd PJ]紧急救助(民间数据) 最终得分 100
用户昵称 GravatarTab↹ 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2022-04-18 21:56:36 内存使用 0.00 MiB
显示代码纯文本
#include <iostream>
#include <fstream>
#include <string>
#include <queue>

using namespace std;

typedef pair<int,int> pii;

struct cmp : binary_function<pii,pii,bool>{
    bool operator()(const pii& a, const pii& b){
        if(a.first < b.first)
            return true;
        else if(a.first > b.first)
            return false;
        else if(a.second >= b.second)
            return true;
        else
            return false;            
    }
};

int main(void){
    ifstream fin("noi_online2020_save.in");
    ofstream fout("noi_online2020_save.out");
    int n;
    fin >> n;
    string* name = new string[n];
    string* signal = new string[n];
    for(int i = 0; i < n; ++i)
        fin >> name[i] >> signal[i];

    priority_queue<pii,vector<pii>,cmp> heap;
    queue<char> sos;
    sos.push('s');
    sos.push('o');
    sos.push('s');
    for(int i = 0; i < n; ++i){
        queue<char> q;
        int cur = 0;
        while(q.size() < 3)
            if(cur < signal[i].size())
                q.push(signal[i].c_str()[cur++]);
            else break;
        if(q.size() < 3){
            heap.push({0,i});
            continue;
        }
        
        int cnt = 0;
        if(q == sos) ++cnt;
        while(cur < signal[i].size()){
            q.pop();
            q.push(signal[i].c_str()[cur++]);
            if(q == sos) ++cnt;
        }
        heap.push({cnt,i});
    }

    auto cur = heap.top();
    int cnt = cur.first;
    while(!heap.empty() && heap.top().first == cnt){
        fout << name[cur.second] << ' ';
        heap.pop();
        cur = heap.top();
    }
    fout << endl << cnt;

    delete []name;
    delete []signal;
    return 0;
}