답안 #740613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
740613 2023-05-12T19:59:48 Z Olympia Ekoeko (COCI21_ekoeko) C++17
20 / 110
1000 ms 1800 KB
#include <iostream>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <map>
#include <deque>
#include <stdio.h>
using namespace std; 
map<char,vector<int>> pos (string s) {
    map<char,vector<int>> m;
    for (int i = 0; i < s.size(); i++) {
        m[s[i]].push_back(i);
    }
    return m;
}
int inversions (vector<int> v) {
    int ans = 0;
    for (int i = 0; i < v.size(); i++) {
        for (int j = i + 1; j < v.size(); j++) {
            ans += (v[i] > v[j]);
        }
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    string s;
    cin >> s;
    string str;
    map<int,int> oc_s;
    for (int i = 0; i < s.size(); i++) {
        oc_s[s[i]]++;
    }
    map<char,int> oc;
    string g;
    for (int i = 0; i < s.size(); i++) {
        oc[s[i]]++;
        if (oc[s[i]] <= oc_s[s[i]]/2) {
            str += s[i];
        } else {
            g += s[i];
        }
    }
    auto p1 = pos(s);
    auto p2 = pos(str + str);
    int ans = 0;
    vector<int> perm(2 * n);
    for (auto& p: p1) {
        for (int i = 0; i < p1[p.first].size(); i++) {
            perm[p2[p.first][i]] = p1[p.first][i];
        }
    }
    cout << inversions(perm) << '\n';
}

Compilation message

Main.cpp: In function 'std::map<char, std::vector<int> > pos(std::string)':
Main.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for (int i = 0; i < s.size(); i++) {
      |                     ~~^~~~~~~~~~
Main.cpp: In function 'int inversions(std::vector<int>)':
Main.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
Main.cpp:25:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for (int j = i + 1; j < v.size(); j++) {
      |                             ~~^~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for (int i = 0; i < s.size(); i++) {
      |                     ~~^~~~~~~~~~
Main.cpp:45:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i = 0; i < s.size(); i++) {
      |                     ~~^~~~~~~~~~
Main.cpp:58:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for (int i = 0; i < p1[p.first].size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:55:9: warning: unused variable 'ans' [-Wunused-variable]
   55 |     int ans = 0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1064 ms 1800 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1064 ms 1800 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1064 ms 1800 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 324 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 320 KB Output is correct
6 Correct 3 ms 324 KB Output is correct
7 Correct 2 ms 320 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 1064 ms 1800 KB Time limit exceeded
3 Halted 0 ms 0 KB -