답안 #45722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45722 2018-04-16T04:44:02 Z Talant Jakarta Skyscrapers (APIO15_skyscraper) C++17
0 / 100
2 ms 660 KB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair
#define int long long

using namespace std;

typedef long long ll;

const int inf = (int)1e15 + 7;
const int N = (int)2e5 + 7;

int n,m;
int p[N],b[N];
int mn = inf;
vector <int> v;

bool check (int l,int r) {
      if (abs(b[l] - b[r]) % p[l] == 0)
            return true;
      return false;
}
int f(int l,int r) {
      return (abs(b[l] - b[r]) / p[l]);
}
main () {
      cin >> n >> m;

      if (m <= 15) {
            for (int i = 1; i <= m; i ++) {
                  cin >> b[i] >> p[i];
            }
            for (int i = 2; i <= m; i ++)
                  v.pb(i);

            do {
                  int cur = 1,ans = 0;;
                  for (int i = 0; i < v.size(); i ++) {
                        if (check(cur,v[i]))
                              ans += f(cur,v[i]);
                        else {
                              cur = -1;
                              break;
                        }

                        cur = v[i];
                  }
                  if (cur != -1)
                        mn = min(mn,ans);
            }while(next_permutation(v.begin(),v.end()));

            if (mn == inf)
                  cout << "-1" << endl;
            else
                  cout << mn << endl;
      }
      else {
            puts("-1");
      }
}

Compilation message

skyscraper.cpp:30:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:42:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                   for (int i = 0; i < v.size(); i ++) {
                                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Incorrect 2 ms 568 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 568 KB Output is correct
2 Correct 2 ms 568 KB Output is correct
3 Incorrect 2 ms 568 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 568 KB Output is correct
2 Correct 2 ms 568 KB Output is correct
3 Incorrect 2 ms 568 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 660 KB Output is correct
2 Correct 2 ms 660 KB Output is correct
3 Incorrect 2 ms 660 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 660 KB Output is correct
2 Correct 2 ms 660 KB Output is correct
3 Incorrect 2 ms 660 KB Output isn't correct
4 Halted 0 ms 0 KB -