Submission #63970

# Submission time Handle Problem Language Result Execution time Memory
63970 2018-08-03T07:52:59 Z 강태규(#1867) Ranklist Sorting (BOI07_sorting) C++11
30 / 100
57 ms 676 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

const int inf = 1e9;
int n, mn;
vector<pii> ans;

int pro(vector<int> v, int i, int cost, int ch = 0) {
    if (i < 0) {
        for (int i = 1; i < n; ++i) {
            if (v[i - 1] > v[i]) return inf;
        }
        if (ch && cost == mn) return -1;
        return cost;
    }
    int ret = pro(v, i - 1, cost, ch);
    if (ret == -1) return -1;
    int pi;
    for (int j = 0; j < n; ++j) if (v[j] == i) pi = j;
    for (int j = pi; j > 0; --j) swap(v[j - 1], v[j]);
    for (int j = 0; j < n; ++j) {
        if (j) {
            if (v[j - 1] < v[j]) break;
            swap(v[j - 1], v[j]);
        }
        ret = min(ret, pro(v, i - 1, cost + pi + j + 2, ch));
        if (ret == -1) {
            ans.emplace_back(pi + 1, j + 1);
            return -1;
        }
    }
    return ret;
}

int main() {
    scanf("%d", &n);
    if (n > 10) return 0;
    vector<int> s;
    int cp[10];
    for (int i = 0; i < n; ++i) {
        scanf("%d", cp + i);
        s.push_back(cp[i]);
    }
    sort(cp, cp + n);
    for (int &i : s) i = n - 1 - (lower_bound(cp, cp + n, i) - cp);
    
    mn = pro(s, n - 1, 0);
    pro(s, n - 1, 0, 1);
    
    printf("%d\n", (int)ans.size());
    for (int i = ans.size(); i--; ) {
        printf("%d %d\n", ans[i].first, ans[i].second);
    }
    
	return 0;
}

Compilation message

sorting.cpp: In function 'int main()':
sorting.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
sorting.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", cp + i);
         ~~~~~^~~~~~~~~~~~~~
sorting.cpp: In function 'int pro(std::vector<int>, int, int, int)':
sorting.cpp:35:9: warning: 'pi' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int pi;
         ^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 7 ms 528 KB Output is correct
3 Correct 57 ms 676 KB Output is correct
4 Incorrect 3 ms 676 KB Unexpected end of file - int32 expected
5 Incorrect 2 ms 676 KB Unexpected end of file - int32 expected
6 Incorrect 3 ms 676 KB Unexpected end of file - int32 expected
7 Incorrect 2 ms 676 KB Unexpected end of file - int32 expected
8 Incorrect 2 ms 676 KB Unexpected end of file - int32 expected
9 Incorrect 2 ms 676 KB Unexpected end of file - int32 expected
10 Incorrect 2 ms 676 KB Unexpected end of file - int32 expected