제출 #605302

#제출 시각아이디문제언어결과실행 시간메모리
605302YassineBenYounesA Huge Tower (CEOI10_tower)C++17
30 / 100
1096 ms12756 KiB
/* 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 = 5005; 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) 메시지

tower.cpp: In function 'void init()':
tower.cpp:33:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 | freopen("input.txt", "r", stdin);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
tower.cpp:35:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 | freopen("output.txt", "w", stdout);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
tower.cpp: In function 'll solve(std::vector<std::pair<int, int> >)':
tower.cpp:72:18: warning: iteration 5004 invokes undefined behavior [-Waggressive-loop-optimizations]
   72 |         value[i] = 0;
      |         ~~~~~~~~~^~~
tower.cpp:70:22: note: within this loop
   70 |     for(int i = 1; i <= mx;i++){
      |                    ~~^~~~~
tower.cpp:72:18: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset [20020, 20023] is out of the bounds [0, 20020] of object 'value' with type 'int [5005]' [-Warray-bounds]
   72 |         value[i] = 0;
      |         ~~~~~~~~~^~~
tower.cpp:49:5: note: 'value' declared here
   49 | int value[mx];
      |     ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...