이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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){
//for(auto i : v) cout << i << " ";
//cout << '\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;
if(v[0] > i) rec(v, used, 1);
else rec(v, used, 0);
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:56:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
56 | if(i == cf && v.size() != n - 1) continue;
| ~~~~~~~~~^~~~~~~~
kangaroo.cpp:68:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
68 | if(i == cf && v.size() != n - 1) continue;
| ~~~~~~~~~^~~~~~~~
kangaroo.cpp:79:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
79 | if(i == cf && v.size() != n - 1) continue;
| ~~~~~~~~~^~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |