QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#568820#9320. Find the Easiest ProblemHMCCompile Error//C++142.0kb2024-09-16 18:42:102024-09-16 18:42:10

Judging History

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

  • [2024-09-16 18:42:10]
  • 评测
  • [2024-09-16 18:42:10]
  • 提交

answer

#include <iostream>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <algorithm>  
  
using namespace std;  
  
// 结构体用于存储问题信息和解决它的团队数量  
struct ProblemInfo {  
    char problemId;  
    int solvedBy;  
      
    // 重载小于运算符,用于排序  
    bool operator<(const ProblemInfo& other) const {  
        if (solvedBy == other.solvedBy) {  
            return problemId < other.problemId; // 如果解决团队数量相同,则按问题ID字典序排序  
        }  
        return solvedBy > other.solvedBy; // 否则按解决团队数量降序排序  
    }  
};  
  
int main() {  
    int t;  
    cin >> t; // 读取测试案例数量  
      
    while (t--) {  
        int n;  
        cin >> n; // 读取提交数量  
          
        unordered_map<char, unordered_set<string>> problemSolvedBy; // 问题ID到解决它的团队集合的映射  
          
        // 读取每个提交信息  
        for (int i = 0; i < n; ++i) {  
            string teamName, problemId, result;  
            cin >> teamName >> problemId >> result;  
              
            // 如果提交被接受,则将该团队添加到对应问题的团队集合中  
            if (result == "accepted") {  
                problemSolvedBy[problemId].insert(teamName);  
            }  
        }  
          
        // 准备存储问题信息和解决它的团队数量的向量  
        vector<ProblemInfo> problems;  
        for (const auto& entry : problemSolvedBy) {  
            problems.push_back({entry.first, entry.second.size()});  
        }  
          
        // 对问题按解决团队数量降序排序,如果数量相同则按问题ID字典序排序  
        sort(problems.begin(), problems.end());  
          
        // 输出最容易的问题ID  
        cout << problems[0].problemId << endl;  
    }  
      
    return 0;  
}

Details

answer.code: In function ‘int main()’:
answer.code:40:32: error: no match for ‘operator[]’ (operand types are ‘std::unordered_map<char, std::unordered_set<std::__cxx11::basic_string<char> > >’ and ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’})
   40 |                 problemSolvedBy[problemId].insert(teamName);
      |                                ^
In file included from /usr/include/c++/13/unordered_map:41,
                 from answer.code:2:
/usr/include/c++/13/bits/unordered_map.h:986:7: note: candidate: ‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type&) [with _Key = char; _Tp = std::unordered_set<std::__cxx11::basic_string<char> >; _Hash = std::hash<char>; _Pred = std::equal_to<char>; _Alloc = std::allocator<std::pair<const char, std::unordered_set<std::__cxx11::basic_string<char> > > >; mapped_type = std::unordered_set<std::__cxx11::basic_string<char> >; key_type = char]’
  986 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/13/bits/unordered_map.h:986:34: note:   no known conversion for argument 1 from ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} to ‘const std::unordered_map<char, std::unordered_set<std::__cxx11::basic_string<char> > >::key_type&’ {aka ‘const char&’}
  986 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/unordered_map.h:990:7: note: candidate: ‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&&) [with _Key = char; _Tp = std::unordered_set<std::__cxx11::basic_string<char> >; _Hash = std::hash<char>; _Pred = std::equal_to<char>; _Alloc = std::allocator<std::pair<const char, std::unordered_set<std::__cxx11::basic_string<char> > > >; mapped_type = std::unordered_set<std::__cxx11::basic_string<char> >; key_type = char]’
  990 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/13/bits/unordered_map.h:990:29: note:   no known conversion for argument 1 from ‘std::string’ {aka ‘std::__cxx11::basic_string<char>’} to ‘std::unordered_map<char, std::unordered_set<std::__cxx11::basic_string<char> > >::key_type&&’ {aka ‘char&&’}
  990 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
answer.code:47:63: warning: narrowing conversion of ‘entry.std::pair<const char, std::unordered_set<std::__cxx11::basic_string<char> > >::second.std::unordered_set<std::__cxx11::basic_string<char> >::size()’ from ‘std::unordered_set<std::__cxx11::basic_string<char> >::size_type’ {aka ‘long unsigned int’} to ‘int’ [-Wnarrowing]
   47 |             problems.push_back({entry.first, entry.second.size()});
      |                                              ~~~~~~~~~~~~~~~~~^~