Submission #977872

#TimeUsernameProblemLanguageResultExecution timeMemory
977872SmuggingSpunJakarta Skyscrapers (APIO15_skyscraper)C++14
10 / 100
1 ms600 KiB
#include<bits/stdc++.h> #define taskname "skyscraper" using namespace std; typedef long long ll; template<class T>void minimize(T& a, T b){ if(a > b){ a = b; } } const int lim = 3e4 + 5; int n, m, b[lim], p[lim]; namespace sub1{ void solve(){ if(m == 2){ return void(cout << (abs(b[0] - b[1]) % p[0] == 0 ? abs(b[0] - b[1]) / p[0] : -1)); } int ans = (abs(b[0] - b[1]) % p[0] == 0 ? abs(b[0] - b[1]) / p[0] : INT_MAX); if(abs(b[0] - b[2]) % p[0] == 0 && abs(b[2] - b[1]) % p[2] == 0){ minimize(ans, abs(b[0] - b[2]) / p[0] + abs(b[2] - b[1]) / p[2]); } cout << (ans == INT_MAX ? -1 : ans); } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); } cin >> n >> m; for(int i = 0; i < m; i++){ cin >> b[i] >> p[i]; } if(n <= 10 && *max_element(p, p + m) <= 10 && m <= 3){ sub1::solve(); } }

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:27:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   freopen(taskname".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...