Submission #329816

#TimeUsernameProblemLanguageResultExecution timeMemory
329816theshadow_04Skyscraper (JOI16_skyscraper)C++14
5 / 100
2085 ms384 KiB
// V T An
#include <bits/stdc++.h>
#define F first
#define S second
#define MOD 1000000007
#define pb push_back
#define ll long long
#define Task "SKYSCRAPER"

using namespace std;

const int maxn = 100005;

int n, a[maxn], L;

int main() {
    ios_base::sync_with_stdio(0);
    cout.tie(0); cin.tie(0);
	if(fopen(Task".inp", "r")){
		freopen(Task".inp", "r", stdin);
		freopen(Task".out", "w", stdout);
	}
    cin >> n >> L;
    vector<int> v;
    for(int i = 1; i <= n; ++i) cin >> a[i], v.pb(i);
    int ans = 0;
    do {
        long long res = 0;
        for(int i = 0; i < v.size() - 1; ++ i) res += abs(a[v[i + 1]] - a[v[i]]);
        if(res <= L) ++ ans;
        if(ans > MOD) ans -= MOD;
    } while(next_permutation(v.begin(), v.end()));
    cout << ans;
}

// CHY-AKAV

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:29:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for(int i = 0; i < v.size() - 1; ++ i) res += abs(a[v[i + 1]] - a[v[i]]);
      |                        ~~^~~~~~~~~~~~~~
skyscraper.cpp:20:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   20 |   freopen(Task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:21:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   21 |   freopen(Task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...