제출 #893342

#제출 시각아이디문제언어결과실행 시간메모리
893342vjudge1캥거루 (CEOI16_kangaroo)C++17
0 / 100
0 ms348 KiB
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <functional>
#include <complex>
#include <climits>
#include <random>
using namespace std;
   
#define ll long long
#define pb push_back
#define ull unsigned long long
#define F first
#define S second
#define all(v) v.begin(), v.end()

const ll mod = (ll) 1e9 + 7;

int n, cs, cf;
ll ans = 0;

void rec(vector<int>& v, vector<bool>& used, int f = -1){
    if(v.size() == n){
        ans++;
        return;
    }
    if(f == -1){
        for(int i = 1; i <= n; i++){
            if(used[i]) continue;
            if(i == cf && v.size() != n - 1) continue;
            v.pb(i);
            used[i] = 1;
            rec(v, used, 0);
            v.pop_back();
            used[i] = 0;
        }
        for(int i = 1; i <= n; i++){
            if(used[i]) continue;
            if(i == cf && v.size() != n - 1) continue;
            v.pb(i);
            used[i] = 1;
            rec(v, used, 1);
            v.pop_back();
            used[i] = 0;
        }
    }
    else if(f == 0){
        for(int i = 1; i <= v.back(); i++){
            if(used[i]) continue;
            if(i == cf && v.size() != n - 1) continue;
            v.pb(i);
            used[i] = 1;
            rec(v, used, 1);
            v.pop_back();
            used[i] = 0;
        }
    }
    else{
        for(int i = v.back(); i <= n; i++){
            if(used[i]) continue;
            if(i == cf && v.size() != n - 1) continue;
            v.pb(i);
            used[i] = 1;
            rec(v, used, 0);
            v.pop_back();
            used[i] = 0;
        }
    }
}

void solve(){
    cin >> n >> cs >> cf;
    vector<int> v;
    vector<bool> used(n + 1);
    v.pb(cs);
    used[cs] = 1;
    if(n <= 40) rec(v, used);
    cout << ans;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    int xach = 1; 
    //cin >> xach;
    while(xach--) solve();
}

컴파일 시 표준 에러 (stderr) 메시지

kangaroo.cpp: In function 'void rec(std::vector<int>&, std::vector<bool>&, int)':
kangaroo.cpp:47:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |     if(v.size() == n){
      |        ~~~~~~~~~^~~~
kangaroo.cpp:54:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |             if(i == cf && v.size() != n - 1) continue;
      |                           ~~~~~~~~~^~~~~~~~
kangaroo.cpp:63:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |             if(i == cf && v.size() != n - 1) continue;
      |                           ~~~~~~~~~^~~~~~~~
kangaroo.cpp:74:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   74 |             if(i == cf && v.size() != n - 1) continue;
      |                           ~~~~~~~~~^~~~~~~~
kangaroo.cpp:85:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   85 |             if(i == cf && v.size() != n - 1) continue;
      |                           ~~~~~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...