답안 #528446

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
528446 2022-02-20T10:06:52 Z N1NT3NDO Magneti (COCI21_magneti) C++14
0 / 110
1000 ms 332 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) (int)x.size()
#define fi first
#define sd second
#define all(x) x.begin(), x.end()
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 10005;
int n, L, R[N], ans, who[N];
bitset<N> used;

void Rec(int skok)
{
    if (skok == n + 1)
    {
        ans++;
        return;
    }

    int last = -1e9;
    for(int i = 1; i <= L; i++)
    {
        if (used[i])
        {
            last = i;
            continue;
        }

        bool bad = 0;
        int j = used._Find_next(i);
        if (used[j] && (abs(j - i) < R[skok] || abs(j - i) < R[who[j]])) bad = 1;
        if (last != -1e9 && (abs(last - i) < R[skok] || abs(last - i) < R[who[last]])) bad = 1;

        if (!bad)
        {
            used[i] = 1;
            who[i] = skok;
            Rec(skok + 1);
            used[i] = 0;
            who[i] = 0;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> L;
    for(int i = 1; i <= n; i++) cin >> R[i];
    //sort(R + 1, R + n + 1, greater<>());
    Rec(1);
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1091 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1083 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1091 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -