제출 #283763

#제출 시각아이디문제언어결과실행 시간메모리
283763erd1고대 책들 (IOI17_books)C++14
12 / 100
1 ms384 KiB
#include "books.h"

#include<bits/stdc++.h>

using namespace std;
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef pair<int, int> pii;
typedef long long lld;
typedef long double ld;

template<typename Iter>
ostream& outIt(ostream& out, Iter b, Iter e){
	for(Iter i = b; i != e; ++i)
		out << (i == b?"":" ") << *i;
	return out;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> p){
	return out << '(' << p.ff << ", " << p.ss << ')';
}
template<typename T>
ostream& operator<<(ostream& out, vector<T> v){
	return outIt(out << '[', all(v)) << ']';
}

vector<int> dsu, c;

int root(int i){
	return dsu[i] == i ? i : (dsu[i] = root(dsu[i]));
}
void join(int i, int j){
	dsu[root(i)] = root(j);
}

long long minimum_walk(vector<int> p, int s) {
	lld ans = 0;
	c.resize(0);
	c.resize(p.size()+1);
	for(int i = 0; i < p.size(); i++)if(p[i] != i)ans += abs(p[i]-i), c[min(i, p[i])]++, c[max(i, p[i])+1]--;
	for(int i = 1; i <= p.size(); i++)c[i] += c[i-1];
	for(int i = p.size(), x = 0; i >= 0; i--){
		if(c[i])x = 1;
		else if(x)ans += 2;
	}
	return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for(int i = 0; i < p.size(); i++)if(p[i] != i)ans += abs(p[i]-i), c[min(i, p[i])]++, c[max(i, p[i])+1]--;
      |                 ~~^~~~~~~~~~
books.cpp:44:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |  for(int i = 1; i <= p.size(); i++)c[i] += c[i-1];
      |                 ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...