Submission #527765

# Submission time Handle Problem Language Result Execution time Memory
527765 2022-02-18T08:55:04 Z boris_mihov Parking Problem (innopolis2021_final_A) C++14
100 / 100
19 ms 1796 KB
#include <iostream>
const int maxn = 1e5+10;

std::string s, vehicles, ans;
int a[maxn], b[maxn], n, m;
int ccnt, mcnt;

bool check(int to) {

    ccnt = 0;
    mcnt = 0;

    for (int i = 0 ; i < to ; ++i) {

        ccnt += (vehicles[i] == 'C');
        mcnt += (vehicles[i] == 'M');

    }

    for (int i = 1 ; i <= m ; ++i) b[i] = a[i];
    for (int i = 1 ; i <= m && ccnt != 0 ; ++i) {

        if (b[i] % 2 == 1 && b[i] != 1) {

            b[i] -= 3;
            --ccnt;

        }

    }

    for (int i = 1 ; i <= m && ccnt/2 != 0 ; ++i) {

        int cost = b[i]/6;
        b[i] -= 6*std::min(cost, ccnt/2);
        ccnt -= 2*std::min(cost, ccnt/2);

    }

    mcnt += ccnt;
    int sum = 0;

    for (int i = 1 ; i <= m ; ++i) 
        sum += b[i]/2 + b[i]%2;

    // std::cout << "check: " << to << ' ' << sum << ' ' << mcnt << '\n';
    return mcnt <= sum-1;

}

void solve() {

    n = vehicles.size();
    m = 0;
    int curr = 0;
    for (int i = 0 ; i < s.size() ; ++i) {

        if (s[i] == '.') ++curr;
        else {

            if (curr >= 2) a[++m] = curr-1;
            curr = 0;

        }

    }

    if (curr >= 2) a[++m] = curr-1;

    int l = -1, r = n+1, mid;
    while (l < r - 1) {

        mid = (l+r)/2;
        if (check(mid)) l = mid;
        else r = mid;

    }

    ans.clear();
    ans.resize(n+1);
    for (int i = 0 ; i <= l ; ++i) ans[i] = 'Y';
    for (int i = l+1 ; i <= n ; ++i) ans[i] = 'N';

    std::cout << ans << '\n';

}

void read() {

    std::cin >> s;
    std::cin >> vehicles;

}

void fast_io() {

    std::ios_base :: sync_with_stdio(0);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

}

int t;
int main () {

    fast_io();
    
    std::cin >> t;
    while (t--) {
    
        read();
        solve();
    
    }

    return 0;

}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:56:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for (int i = 0 ; i < s.size() ; ++i) {
      |                      ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 844 KB Output is correct
2 Correct 6 ms 468 KB Output is correct
3 Correct 16 ms 668 KB Output is correct
4 Correct 6 ms 844 KB Output is correct
5 Correct 6 ms 1240 KB Output is correct
6 Correct 7 ms 1744 KB Output is correct
7 Correct 6 ms 1232 KB Output is correct
8 Correct 16 ms 1440 KB Output is correct
9 Correct 5 ms 1508 KB Output is correct
10 Correct 6 ms 1232 KB Output is correct
11 Correct 17 ms 1480 KB Output is correct
12 Correct 5 ms 1712 KB Output is correct
13 Correct 5 ms 1288 KB Output is correct
14 Correct 19 ms 1484 KB Output is correct
15 Correct 14 ms 1096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 972 KB Output is correct
2 Correct 5 ms 588 KB Output is correct
3 Correct 16 ms 708 KB Output is correct
4 Correct 6 ms 972 KB Output is correct
5 Correct 6 ms 1216 KB Output is correct
6 Correct 6 ms 1544 KB Output is correct
7 Correct 7 ms 1232 KB Output is correct
8 Correct 19 ms 1488 KB Output is correct
9 Correct 5 ms 1700 KB Output is correct
10 Correct 6 ms 1232 KB Output is correct
11 Correct 19 ms 1488 KB Output is correct
12 Correct 6 ms 1596 KB Output is correct
13 Correct 6 ms 1256 KB Output is correct
14 Correct 18 ms 1440 KB Output is correct
15 Correct 16 ms 1012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 972 KB Output is correct
2 Correct 7 ms 612 KB Output is correct
3 Correct 6 ms 588 KB Output is correct
4 Correct 7 ms 540 KB Output is correct
5 Correct 8 ms 592 KB Output is correct
6 Correct 14 ms 584 KB Output is correct
7 Correct 18 ms 544 KB Output is correct
8 Correct 17 ms 592 KB Output is correct
9 Correct 14 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 844 KB Output is correct
2 Correct 6 ms 468 KB Output is correct
3 Correct 16 ms 668 KB Output is correct
4 Correct 6 ms 844 KB Output is correct
5 Correct 6 ms 1240 KB Output is correct
6 Correct 7 ms 1744 KB Output is correct
7 Correct 6 ms 1232 KB Output is correct
8 Correct 16 ms 1440 KB Output is correct
9 Correct 5 ms 1508 KB Output is correct
10 Correct 6 ms 1232 KB Output is correct
11 Correct 17 ms 1480 KB Output is correct
12 Correct 5 ms 1712 KB Output is correct
13 Correct 5 ms 1288 KB Output is correct
14 Correct 19 ms 1484 KB Output is correct
15 Correct 14 ms 1096 KB Output is correct
16 Correct 5 ms 972 KB Output is correct
17 Correct 5 ms 588 KB Output is correct
18 Correct 16 ms 708 KB Output is correct
19 Correct 6 ms 972 KB Output is correct
20 Correct 6 ms 1216 KB Output is correct
21 Correct 6 ms 1544 KB Output is correct
22 Correct 7 ms 1232 KB Output is correct
23 Correct 19 ms 1488 KB Output is correct
24 Correct 5 ms 1700 KB Output is correct
25 Correct 6 ms 1232 KB Output is correct
26 Correct 19 ms 1488 KB Output is correct
27 Correct 6 ms 1596 KB Output is correct
28 Correct 6 ms 1256 KB Output is correct
29 Correct 18 ms 1440 KB Output is correct
30 Correct 16 ms 1012 KB Output is correct
31 Correct 7 ms 972 KB Output is correct
32 Correct 7 ms 612 KB Output is correct
33 Correct 6 ms 588 KB Output is correct
34 Correct 7 ms 540 KB Output is correct
35 Correct 8 ms 592 KB Output is correct
36 Correct 14 ms 584 KB Output is correct
37 Correct 18 ms 544 KB Output is correct
38 Correct 17 ms 592 KB Output is correct
39 Correct 14 ms 588 KB Output is correct
40 Correct 1 ms 220 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 2 ms 472 KB Output is correct
44 Correct 1 ms 444 KB Output is correct
45 Correct 2 ms 348 KB Output is correct
46 Correct 15 ms 1104 KB Output is correct
47 Correct 10 ms 1796 KB Output is correct
48 Correct 9 ms 1748 KB Output is correct
49 Correct 7 ms 1624 KB Output is correct