답안 #425491

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
425491 2021-06-13T05:49:05 Z Charis02 고대 책들 (IOI17_books) C++14
0 / 100
1 ms 332 KB
#include "books.h"
#include<iostream>
#include<vector>
#include<map>
#define ll long long
#define rep(i,a,b) for(int i = a;i < b;i++)
#define mp(a,b) make_pair(a,b)
#define N 100003

using namespace std;

bool vis[N];

int abso(int x)
{
    return (x < 0) ? -x : x;
}

ll get_cycle_cost(vector < int > c)
{
    if(c.size()==1)
        return 0;

    ll res = 0;

    rep(i,1,c.size())
    {
        res += abso(c[i]-c[i-1]);
    }

    res += abso(c[0]-c[c.size()-1]);

    return res;
}

long long minimum_walk(std::vector<int> p, int s) // for 1st sub
{
    int n = p.size();
    vector < vector < int > > cycles;

    rep(i,0,n)
    {
        if(vis[i])
            continue;

        int cur = i;
        int ind = cycles.size();
        cycles.push_back(vector < int >());

       // cout << "here ";

        while(!vis[cur])
        {
         //   cout << cur << " ";
            vis[cur] = true;
            cycles[ind].push_back(cur);
            cur = p[cur];
        }

       // cout << endl;
    }

    ll ans = 0;
    int last = 0;

    rep(i,0,cycles.size())
    {
        ans += get_cycle_cost(cycles[i]);
        if(cycles[i].size() > 1)
            last = cycles[i][0];
    }

    ans += last*2;

	return ans;
}

Compilation message

books.cpp: In function 'long long int get_cycle_cost(std::vector<int>)':
books.cpp:6:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define rep(i,a,b) for(int i = a;i < b;i++)
......
   26 |     rep(i,1,c.size())
      |         ~~~~~~~~~~~~                
books.cpp:26:5: note: in expansion of macro 'rep'
   26 |     rep(i,1,c.size())
      |     ^~~
books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:6:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define rep(i,a,b) for(int i = a;i < b;i++)
......
   66 |     rep(i,0,cycles.size())
      |         ~~~~~~~~~~~~~~~~~           
books.cpp:66:5: note: in expansion of macro 'rep'
   66 |     rep(i,0,cycles.size())
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4728'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -