Submission #868262

#TimeUsernameProblemLanguageResultExecution timeMemory
868262Truly_Building Bridges (CEOI17_building)C++14
30 / 100
12 ms3676 KiB
#define nametask "bridgepol" #include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define SZ(a) (int) a.size() #define FOR(i, a, b) for (int i = a; i <= b; i++) #define FOD(i, b, a) for (int i = b; i >= a; i--) using namespace std; typedef long long ll; typedef pair <int, int> pi; const int N = 1e5 + 5; const ll oo = 1e18 + 7; int n; int h[N], w[N]; ll s[N], f[N]; ll calc(int i, int j){ return (s[j] - s[i - 1]); } ll calch(int h1, int h2){ return (1LL * h1 * h1 - 2LL * h1 * h2 + 1LL * h2 * h2); } void sub1(){ f[1] = 0; FOR(i, 2, n){ FOR(j, 1, i - 1) { f[i] = min(f[i], f[j] + calch(h[i], h[j]) + calc(j + 1, i - 1)); } } cout << f[n]; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); if (fopen(nametask".inp", "r")){ freopen(nametask".inp", "r", stdin); freopen(nametask".out", "w", stdout); } cin >> n; FOR(i, 1, n) cin >> h[i]; FOR(i, 1, n) cin >> w[i]; FOR(i, 1, n) s[i] = s[i - 1] + w[i]; FOR(i, 1, n) f[i] = oo; if (n <= 1000) sub1(); //else sub2(); return 0; }

Compilation message (stderr)

building.cpp: In function 'int main()':
building.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         freopen(nametask".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
building.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         freopen(nametask".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...