답안 #640663

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
640663 2022-09-15T05:17:07 Z devariaota Palembang Bridges (APIO15_bridge) C++17
8 / 100
2000 ms 13592 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long ll;
// const ll mod = 1e9 + 7;
const ll MAXN = 1e6 + 5;
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define sc second
#define endl '\n'
#define gl                        ios_base::sync_with_stdio(0);   cin.tie(0);                     cout.tie(0)

int main()
{
  gl;
  ll k, n;
  cin >> k >> n;

  ll sum = 0;

  vll v;
  set<ll> st;
  for (int i = 0; i < n; i++)
  {
    char a, b;
    ll x, y;
    cin >> a >> x >> b >> y;
    if (a == b)
      sum += abs(x - y);
    else
    {
      sum++;
      v.pb(x);
      v.pb(y);
      st.insert(x);
      st.insert(y);
    }
  }

  sort(v.begin(), v.end());

  ll ans = 1e18;

  for (ll i : st)
  {
    ll cur = 0;
    for (int j = 0; j < v.size(); j++)
    {
      cur += abs(i - v[j]);
    }
    ans = min(ans, cur);
  }

  if (ans == 1e18)
    ans = 0;

  cout << ans + sum << endl;

  return 0;
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int j = 0; j < v.size(); j++)
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 3 ms 452 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 1 ms 356 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 456 KB Output is correct
12 Correct 20 ms 3280 KB Output is correct
13 Execution timed out 2068 ms 13592 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 260 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -