답안 #341534

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
341534 2020-12-29T23:21:09 Z FlashGamezzz 고대 책들 (IOI17_books) C++11
0 / 100
1089 ms 1048580 KB
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <deque>
#include "books.h"

using namespace std;

bool valid(vector<int> v){
	for (int i = 1; i < v.size(); i++){
		if (v[i] < v[i-1]){
			return false;
		}
	}
	return true;
}

long long minimum_walk(vector<int> p, int s) {
	deque<pair<pair<int, int>, pair<int, vector<int> > > > bfs; bfs.push_back(make_pair(make_pair(0, 0), make_pair(-1, p)));
	while (bfs.size() > 0){
		int i = bfs.front().first.first, t = bfs.front().first.second, b = bfs.front().second.first; vector<int> v = bfs.front().second.second; bfs.pop_front();
		if (i == 0 && valid(v)) return t;
		if (i > 0) bfs.push_back(make_pair(make_pair(i-1, t+1), make_pair(b, v)));
		if (i < v.size()-1) bfs.push_back(make_pair(make_pair(i+1, t+1), make_pair(b, v)));
		if (v[i] == -1){
			vector<int> nv = v; nv[i] = b;
			if (i == 0 && valid(nv)) return t;
			if (i > 0) bfs.push_back(make_pair(make_pair(i-1, t+1), make_pair(-1, nv)));
			if (i < v.size()-1) bfs.push_back(make_pair(make_pair(i+1, t+1), make_pair(-1, nv)));
		} else {
			if (b == -1){
				vector<int> nv = v; int temp = nv[i]; nv[i] = -1;
				if (i > 0) bfs.push_back(make_pair(make_pair(i-1, t+1), make_pair(temp, nv)));
				if (i < v.size()-1) bfs.push_back(make_pair(make_pair(i+1, t+1), make_pair(temp, nv)));
			} else {
				vector<int> nv = v; int temp = nv[i]; nv[i] = b;
				if (i > 0) bfs.push_back(make_pair(make_pair(i-1, t+1), make_pair(temp, nv)));
				if (i < v.size()-1) bfs.push_back(make_pair(make_pair(i+1, t+1), make_pair(temp, nv)));
			}
		}
	}
}

Compilation message

books.cpp: In function 'bool valid(std::vector<int>)':
books.cpp:14:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for (int i = 1; i < v.size(); i++){
      |                  ~~^~~~~~~~~~
books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:28:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   if (i < v.size()-1) bfs.push_back(make_pair(make_pair(i+1, t+1), make_pair(b, v)));
      |       ~~^~~~~~~~~~~~
books.cpp:33:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |    if (i < v.size()-1) bfs.push_back(make_pair(make_pair(i+1, t+1), make_pair(-1, nv)));
      |        ~~^~~~~~~~~~~~
books.cpp:38:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     if (i < v.size()-1) bfs.push_back(make_pair(make_pair(i+1, t+1), make_pair(temp, nv)));
      |         ~~^~~~~~~~~~~~
books.cpp:42:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     if (i < v.size()-1) bfs.push_back(make_pair(make_pair(i+1, t+1), make_pair(temp, nv)));
      |         ~~^~~~~~~~~~~~
books.cpp:23:57: warning: control reaches end of non-void function [-Wreturn-type]
   23 |  deque<pair<pair<int, int>, pair<int, vector<int> > > > bfs; bfs.push_back(make_pair(make_pair(0, 0), make_pair(-1, p)));
      |                                                         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Incorrect 1 ms 492 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Incorrect 1 ms 492 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Incorrect 1 ms 492 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1089 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Incorrect 1 ms 492 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -