# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
605300 | YassineBenYounes | A Huge Tower (CEOI10_tower) | C++17 | 1090 ms | 472 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
ID: yassine11
TASK: angry
LANG: C++
*/
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD)
ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);} // least common multiple (PPCM)
#define endl "\n"
#define ss second
#define ff first
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define vi vector<int>
#define vii vector<pair<int,int>>
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vdd vector<pdd>
#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
void init(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
const int mx = 75;
const int mod = 1e9+7;
const int inf = 1e9;
int arr[mx];
int d;
vi graph[mx];
int value[mx];
int n;
bool vis[mx];
ll dfs(int node, int c){
if(c == n){
return 1;
}
vis[node] = 1;
ll x = 0;
for(int adj : graph[node]){
if(vis[adj])continue;
x+=dfs(adj, c+1);
}
vis[node] = 0;
return x;
}
ll solve(vii v){
for(int i = 1; i <= mx;i++){
graph[i].clear();
value[i] = 0;
}
n = v.size();
for(pii p : v){
//cout << p.ff << " " << p.ss << endl;
value[p.ss] = p.ff;
}
for(int i = 0; i < n;i++){
for(int j = i+1;j < n;j++){
if(v[j].ff - v[i].ff <= d){
graph[v[i].ss].pb(v[j].ss);
}
}
}
for(int i = 0; i < n;i++){
for(int j = 0;j < i;j++){
graph[v[i].ss].pb(v[j].ss);
}
}
/*for(int i = 1; i <= 3;i++){
cout << i << ": ";
for(int adj : graph[i]){
cout << adj << " ";
}
cout << endl;
}*/
ll ans = 0;
for(int i = 1; i <= n;i++){
memset(vis, 0, sizeof vis);
ans += dfs(i, 1);
ans %= mod;
}
return ans;
}
int main(){
//ofstream fout ("angry.out");
//ifstream fin ("angry.in");
speed;
int n;cin >> n >> d;
for(int i = 0; i < n;i++){
cin >> arr[i];
}
sort(arr, arr+n);
ll ans = 1;
for(int i = 0; i < n;i++){
vii v;
int c = 1;
while(i < n-1 && arr[i+1] - arr[i] <= d){
v.pb({arr[i], c});
c++;
i++;
}
v.pb({arr[i], c});
ll x = solve(v);
//cout << x << endl;
ans *= x;
ans %= mod;
}
cout << ans << endl;
}
/*
NEVER GIVE UP!
DOING SMTHNG IS BETTER THAN DOING NTHNG!!!
*/
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |
# | 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... |
# | 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... |
# | 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... |
# | 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... |