답안 #228777

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
228777 2020-05-02T14:33:01 Z osaaateiasavtnl Archery (IOI09_archery) C++14
35 / 100
2000 ms 8160 KB
#include<bits/stdc++.h>
using namespace std;
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
void print(vector <int> a) {
    cout << "cur:" << endl;
    for (int i = 0; i < a.size(); i += 2)
        cout << a[i] << ' ';
    cout << endl;
    for (int i = 1; i < a.size(); i += 2)
        cout << a[i] << ' ';
    cout << endl;
}   
int get(vector <int> a, int x, int R) {
    /*
    #ifdef HOME
    cout << "GET:"<< endl;
    #endif
    */
 
    if (a.size() == 2)
        return 0;
 
    int n = a.size() / 2;            
 
    for (int t = 0; t < R; ++t) {
        for (int i = 0; i < a.size(); i += 2) {
            if (a[i] > a[i + 1])
                swap(a[i], a[i + 1]);
        }   
        /*
        #ifdef HOME
        print(a);
        #endif
        */
        if (a[0] == 0) {
            bool all2 = 1;
            for (int i = 1; i < 2 * n; i += 2) {
                if (a[i] != 2) {
                    all2 = 0;
                    break;
                }   
            }   
            if (all2) {
                int r = R - t;
                for (int i = 0; i < a.size(); ++i)
                    if (a[i] == x) {
                        int ans = i / 2;
                        ans -= r;
                        return (ans % n + n) % n;
                    }
            }
            
            if (a[1] == 0 && a[0] != x && a[1] != x) {
                bool all0 = 1;
                for (int i = 0; i < 2 * n; i += 2) {
                    if (a[i]) {
                        all0 = 0;
                        break;
                    }   
                }   
                if (all0) {
                    for (int i = 0; i < a.size(); ++i) {
                        if (a[i] == x) {
                            return i / 2;
                        }   
                    }   
                }                
            }   
              
        }   
 
        vector <int> b = a;
        b[1] = a[2];
        for (int i = 4; i < a.size(); i += 2) {
            b[i - 2] = a[i];            
        }   
        b[(int)b.size() - 2] = a[1];
 
        a = b;
    }    
    for (int i = 0; i < a.size(); ++i)
        if (a[i] == x)
            return i / 2;
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n, R;
    cin >> n >> R;
 
    R %= n;
    R += 2 * n;
 
    int my;
    cin >> my;
    vector <int> p(2 * n - 1);
    for (int i = 0; i < 2 * n - 1; ++i) {
        cin >> p[i];
        if (p[i] < my)
            p[i] = 0;
        else
            p[i] = 2;
    }            
    my = 1;
 
    int ans = 1e9;
    int start = -1;
 
    vector <int> nd(2 * n, -1);
    for (int i = 0; i < 2 * n; i += 2) {
        if (nd[i] == -1) {
            vector <int> t = p;
            t.insert(t.begin() + i, my);
            nd[i] = get(t, my, R);
        }   
        if (i && nd[i] > nd[i - 2])
            break;
        if (nd[i] < ans || (nd[i] == ans && i / 2 > start)) {
            ans = nd[i];
            start = i / 2;
        }   
    }   
    for (int i = 2 * n - 1; i >= 0; i -= 2) {
        if (nd[i] == -1) {
            vector <int> t = p;
            t.insert(t.begin() + i, my);
            nd[i] = get(t, my, R);
        }   
        if (i + 2 < 2 * n && nd[i] > nd[i + 2])
            break;
        if (nd[i] < ans || (nd[i] == ans && i / 2 > start)) {
            ans = nd[i];
            start = i / 2;
        }   
    }   
                     
    #ifdef HOME
    for (int i = 0; i < 2 * n; ++i)
        cout << nd[i] << ' ';
    cout << endl;
 
    cout << "ans : " << ans << endl;
    #endif
 
    cout << start + 1 << endl;
}

Compilation message

archery.cpp: In function 'void print(std::vector<int>)':
archery.cpp:14:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a.size(); i += 2)
                     ~~^~~~~~~~~~
archery.cpp:17:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 1; i < a.size(); i += 2)
                     ~~^~~~~~~~~~
archery.cpp: In function 'int get(std::vector<int>, int, int)':
archery.cpp:34:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < a.size(); i += 2) {
                         ~~^~~~~~~~~~
archery.cpp:53:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (int i = 0; i < a.size(); ++i)
                                 ~~^~~~~~~~~~
archery.cpp:70:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     for (int i = 0; i < a.size(); ++i) {
                                     ~~^~~~~~~~~~
archery.cpp:82:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 4; i < a.size(); i += 2) {
                         ~~^~~~~~~~~~
archery.cpp:89:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a.size(); ++i)
                     ~~^~~~~~~~~~
archery.cpp:92:1: warning: control reaches end of non-void function [-Wreturn-type]
 }   
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Execution timed out 2051 ms 384 KB Time limit exceeded
3 Correct 13 ms 384 KB Output is correct
4 Correct 167 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 222 ms 480 KB Output is correct
4 Execution timed out 2096 ms 992 KB Time limit exceeded
5 Execution timed out 2088 ms 6980 KB Time limit exceeded
6 Correct 12 ms 384 KB Output is correct
7 Correct 509 ms 480 KB Output is correct
8 Execution timed out 2084 ms 1416 KB Time limit exceeded
9 Execution timed out 2086 ms 1264 KB Time limit exceeded
10 Correct 483 ms 504 KB Output is correct
11 Execution timed out 2080 ms 1424 KB Time limit exceeded
12 Execution timed out 2087 ms 384 KB Time limit exceeded
13 Execution timed out 2084 ms 5168 KB Time limit exceeded
14 Correct 264 ms 656 KB Output is correct
15 Execution timed out 2085 ms 1840 KB Time limit exceeded
16 Correct 15 ms 384 KB Output is correct
17 Correct 506 ms 384 KB Output is correct
18 Execution timed out 2049 ms 384 KB Time limit exceeded
19 Execution timed out 2087 ms 512 KB Time limit exceeded
20 Execution timed out 2085 ms 816 KB Time limit exceeded
21 Execution timed out 2090 ms 1300 KB Time limit exceeded
22 Execution timed out 2085 ms 1780 KB Time limit exceeded
23 Execution timed out 2041 ms 7416 KB Time limit exceeded
24 Correct 17 ms 384 KB Output is correct
25 Correct 1344 ms 504 KB Output is correct
26 Execution timed out 2083 ms 688 KB Time limit exceeded
27 Execution timed out 2089 ms 1244 KB Time limit exceeded
28 Execution timed out 2095 ms 5268 KB Time limit exceeded
29 Execution timed out 2084 ms 384 KB Time limit exceeded
30 Execution timed out 2089 ms 732 KB Time limit exceeded
31 Execution timed out 2087 ms 1292 KB Time limit exceeded
32 Execution timed out 2079 ms 7200 KB Time limit exceeded
33 Correct 15 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Execution timed out 2084 ms 512 KB Time limit exceeded
36 Execution timed out 2091 ms 512 KB Time limit exceeded
37 Execution timed out 2093 ms 1172 KB Time limit exceeded
38 Execution timed out 2092 ms 1340 KB Time limit exceeded
39 Correct 17 ms 384 KB Output is correct
40 Correct 1389 ms 504 KB Output is correct
41 Execution timed out 2078 ms 384 KB Time limit exceeded
42 Execution timed out 2099 ms 384 KB Time limit exceeded
43 Execution timed out 2076 ms 704 KB Time limit exceeded
44 Execution timed out 2090 ms 872 KB Time limit exceeded
45 Execution timed out 2071 ms 1208 KB Time limit exceeded
46 Execution timed out 2075 ms 1272 KB Time limit exceeded
47 Execution timed out 2089 ms 8160 KB Time limit exceeded