이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
ll count_swaps(vector<int> v){
int n = (int)v.size(), ok = 1;
n >>= 1;
for(int i = 0; i < n; ++i)
ok &= (v[i] < 0);
for(int i = 0; i < n; ++i)
ok &= (-v[i] == v[i+n]);
ll ans = 0;
if(ok){
n--;
ans = n*1ll*(n+1)/2;
return ans;
}
n <<= 1;
ok = 1;
for(int i = 1; i < n; ++i)
ok &= (abs(v[0]) == abs(v[i]));
if(ok){
int ne_ = 1, ne__ = 1;
for(int i = 0; i < n; ++i){
ne_ = max(i+1, ne_);
ne__ = max(i+1, ne__);
if(!(i&1)){
if (v[i] < 0)
continue;
while(v[ne_] > 0)
ne_++;
swap(v[i], v[ne_]);
ans += (ne_-i);
}
if(i&1){
if(v[i] > 0)
continue;
while (v[ne__] < 0)
ne__++;
swap(v[i], v[ne__]);
ans += (ne__-i);
}
}
return ans;
}
vector<int> vis(n, 0);
vector<int> mark(n, 0);
for(int i = 0; i < n-1; ++i){
if (mark[i])
continue;
for(int j = i+1; j < n; ++j)
if(-v[i] == v[j]){
mark[j] = 1;
if(v[i] > 0)
ans++;
vis[j] = 1;
for(int k = i+1; k < j; ++k)
ans += (!vis[k]);
break;
}
}
return ans;
}
// char test[256];
// int main(){
// scanf("%s", test);
// int n;
// scanf("%d", &n);
// n *= 2;
// vector<int> v(n);
// for(int &i : v)
// scanf("%d", &i);
// printf("%lld\n", count_swaps(v));
// return 0;
// }
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |