# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1003799 | 2024-06-20T17:56:57 Z | vjudge1 | Ekoeko (COCI21_ekoeko) | C++17 | 12 ms | 4824 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long const int maxa = 30; const int maxn = 1e5 + 10; vector<int> bit(maxn), ocorrencias[maxa]; void update( int id, int val ){ for( int i = id; i < maxn; i += i&-i ) bit[i] += val; } int query( int id ){ int sum = 0; for( int i = id; i > 0; i -= i&-i ) sum += bit[i]; return sum; } int main(){ int n; cin >> n; for( int i = 1; i <= 2*n; i++ ){ char c; cin >> c; ocorrencias[c - 'a'].push_back(i); } vector<pair<int, int>> original; for( int i = 0; i < 26; i++ ) for( int j = 0; j < ocorrencias[i].size()/2; j++ ) original.push_back({ ocorrencias[i][j], i }); sort( original.begin(), original.end() ); vector<int> cont(maxa), v(2*n + 1); for( int i = 0; i < original.size(); i++){ int letra = original[i].second; v[ocorrencias[letra][cont[letra]]] = i + 1; v[ocorrencias[letra][cont[letra] + ocorrencias[letra].size()/2]] = n + i + 1; cont[letra]++; } ll resp = 0; for( int i = 1; i <= 2*n; i++ ){ update(v[i], 1); int inversoes = i - query(v[i]); resp += inversoes; } cout << resp << endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 604 KB | Output is correct |
2 | Correct | 5 ms | 1756 KB | Output is correct |
3 | Runtime error | 12 ms | 4824 KB | Execution killed with signal 11 |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 604 KB | Output is correct |
2 | Correct | 5 ms | 1756 KB | Output is correct |
3 | Runtime error | 12 ms | 4824 KB | Execution killed with signal 11 |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 604 KB | Output is correct |
2 | Correct | 5 ms | 1756 KB | Output is correct |
3 | Runtime error | 12 ms | 4824 KB | Execution killed with signal 11 |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 604 KB | Output is correct |
2 | Correct | 0 ms | 860 KB | Output is correct |
3 | Correct | 0 ms | 860 KB | Output is correct |
4 | Correct | 1 ms | 860 KB | Output is correct |
5 | Correct | 0 ms | 860 KB | Output is correct |
6 | Correct | 1 ms | 860 KB | Output is correct |
7 | Correct | 1 ms | 860 KB | Output is correct |
8 | Correct | 1 ms | 860 KB | Output is correct |
9 | Correct | 0 ms | 872 KB | Output is correct |
10 | Correct | 1 ms | 860 KB | Output is correct |
11 | Correct | 0 ms | 860 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 604 KB | Output is correct |
2 | Correct | 5 ms | 1756 KB | Output is correct |
3 | Runtime error | 12 ms | 4824 KB | Execution killed with signal 11 |
4 | Halted | 0 ms | 0 KB | - |