답안 #575398

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
575398 2022-06-10T10:15:51 Z AJ00 통행료 (APIO13_toll) C++14
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long
int n;
const int MOD = 1000000007;
const int INF = 1e18;
int s[100001],t[100001];
vector<int> v,cons;
signed main()
{
    //freopen("problemname.in", "r", stdin);
    //freopen("problemname.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int tc=1,q,k,m,c; 
    //cin >> tc;
    for (int poppo = 1; poppo <= tc; poppo++){
        //cout << "Case #" << poppo << ": "; 
        int n,k;
        int ans = 0;
        char ch1,ch2;
        cin >> k >> n;
        for (int i = 0; i < n; i++){
            cin >> ch1 >> s[i] >> ch2 >> t[i];
            if (ch1 == ch2){
                ans += abs(s[i]-t[i]);
            }
            else {
                v.push_back(s[i]);
                v.push_back(t[i]);
                cons.push_back(i);
            }
        }
        ans += (int)cons.size();
        if (v.size()){
            sort(v.begin(),v.end());
            // 0,1,2,3,.... 2n
            int bridge = ((v[((v.size()-1)/2)]+v[((v.size())/2)])/2);
            for (int i = 0; i < cons.size(); i++){
                ans += abs(s[cons[i]]-bridge) + abs(t[cons[i]]-bridge);
            }
        }    
        cout << ans << "\n";
    }
    return 0;
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:40:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |             for (int i = 0; i < cons.size(); i++){
      |                             ~~^~~~~~~~~~~~~
toll.cpp:16:14: warning: unused variable 'q' [-Wunused-variable]
   16 |     int tc=1,q,k,m,c;
      |              ^
toll.cpp:16:16: warning: unused variable 'k' [-Wunused-variable]
   16 |     int tc=1,q,k,m,c;
      |                ^
toll.cpp:16:18: warning: unused variable 'm' [-Wunused-variable]
   16 |     int tc=1,q,k,m,c;
      |                  ^
toll.cpp:16:20: warning: unused variable 'c' [-Wunused-variable]
   16 |     int tc=1,q,k,m,c;
      |                    ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -