답안 #532941

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532941 2022-03-04T09:00:46 Z prvocislo Type Printer (IOI08_printer) C++17
100 / 100
61 ms 5576 KB
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int overlap(const string& a, const string& b)
{
    for (int i = 0; i < a.size() && i < b.size(); i++) if (a[i] != b[i]) return i;
    return min(a.size(), b.size());
}
string s;
bool cmp(const string& a, const string& b)
{
    int sa = overlap(s, a), sb = overlap(s, b);
    if (sa == sb) return a < b;
    return sa > sb;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<string> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
        if (v[i].size() > v[0].size()) swap(v[0], v[i]);
    }
    s = v[0];
    sort(v.begin() + 1, v.end(), cmp);
    reverse(v.begin(), v.end());
    string pr;
    string ans;
    for (int i = 0; i < n; i++)
    {
        int pf = (i == 0 ? 0 : overlap(v[i - 1], v[i]));
        while (pr.size() > pf)
        {
            pr.pop_back();
            ans.push_back('-');
        }
        for (int j = pf; j < v[i].size(); j++)
        {
            pr.push_back(v[i][j]);
            ans.push_back(v[i][j]);
        }
        ans.push_back('P');
    }
    cout << ans.size() << "\n";
    for (char i : ans) cout << i << "\n";
    return 0;
}

Compilation message

printer.cpp: In function 'int overlap(const string&, const string&)':
printer.cpp:20:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int i = 0; i < a.size() && i < b.size(); i++) if (a[i] != b[i]) return i;
      |                     ~~^~~~~~~~~~
printer.cpp:20:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int i = 0; i < a.size() && i < b.size(); i++) if (a[i] != b[i]) return i;
      |                                     ~~^~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:50:26: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |         while (pr.size() > pf)
      |                ~~~~~~~~~~^~~~
printer.cpp:55:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for (int j = pf; j < v[i].size(); j++)
      |                          ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 588 KB Output is correct
2 Correct 9 ms 1088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1240 KB Output is correct
2 Correct 8 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 2424 KB Output is correct
2 Correct 49 ms 4692 KB Output is correct
3 Correct 33 ms 3668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2224 KB Output is correct
2 Correct 57 ms 5576 KB Output is correct
3 Correct 35 ms 4192 KB Output is correct
4 Correct 61 ms 5372 KB Output is correct