답안 #938525

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938525 2024-03-05T08:52:32 Z sapientsapiens Lozinke (COCI17_lozinke) C++14
40 / 100
35 ms 7760 KB
/*
 
 At Most 10 lowercase letters of the English Alphabet -> We should think in terms of the alphabet and the orientation
 What is the fastest, most efficient way to check if one string is a subset of another
 Of course there isn't some magical way to compare two strings. The solution: Don't compare two strings. Have a frequency array of how many each substring appears
  
 */
#include <iostream>
#include <string>
#include <utility>
#include <string>
#include <map>

using namespace std;

int n;
string str[2005];
map<string, int> mp;

int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> str[i];
        map<string, int> temp;
        for(int j = 0; j < str[i].size(); j++) {
            for(int k = j; k < str[i].size(); k++) {
                string exp;
                for(int l = j; l <= k; l++) {
                    exp += str[i][l];
                }
                temp[exp] = 1;
            }
        }
        for (const auto &p : temp) {
            // Now you can access the key using p.first and the value using p.second
            mp[p.first] ++; // Example operation
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        ans += mp[str[i]] -1;
    }
    cout << ans;
    
    return 0;
}

Compilation message

lozinke.cpp: In function 'int main()':
lozinke.cpp:25:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for(int j = 0; j < str[i].size(); j++) {
      |                        ~~^~~~~~~~~~~~~~~
lozinke.cpp:26:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |             for(int k = j; k < str[i].size(); k++) {
      |                            ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 7 ms 860 KB Output is correct
6 Correct 11 ms 860 KB Output is correct
7 Correct 15 ms 1372 KB Output is correct
8 Correct 24 ms 2356 KB Output is correct
9 Runtime error 12 ms 1884 KB Execution killed with signal 11
10 Runtime error 25 ms 5128 KB Execution killed with signal 11
11 Runtime error 13 ms 2140 KB Execution killed with signal 11
12 Runtime error 35 ms 7760 KB Execution killed with signal 11
13 Runtime error 18 ms 1624 KB Execution killed with signal 11
14 Runtime error 18 ms 4444 KB Execution killed with signal 11
15 Runtime error 27 ms 6260 KB Execution killed with signal 11
16 Runtime error 19 ms 900 KB Execution killed with signal 11
17 Runtime error 6 ms 604 KB Execution killed with signal 11
18 Runtime error 4 ms 604 KB Execution killed with signal 11
19 Runtime error 19 ms 3568 KB Execution killed with signal 11
20 Runtime error 10 ms 860 KB Execution killed with signal 11