Submission #329816

# Submission time Handle Problem Language Result Execution time Memory
329816 2020-11-22T16:33:43 Z theshadow_04 Skyscraper (JOI16_skyscraper) C++14
5 / 100
2000 ms 384 KB
// 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

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 time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2085 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Execution timed out 2085 ms 364 KB Time limit exceeded
12 Halted 0 ms 0 KB -