답안 #510084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
510084 2022-01-14T16:43:37 Z Yazan_Alattar Type Printer (IOI08_printer) C++14
30 / 100
62 ms 6724 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <utility>
#include <cmath>
#include <numeric>
#include <assert.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 100007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int n, mx = -10000, start;
string s[M], cur;
vector <char> ans;
vector < vector <char> > v[30];

void solve(int st, int en)
{
    cur = "";
    for(int i = st; i <= en; ++i){
        while(cur.size() > s[i].size() || s[i].substr(0, (int)cur.size()) != cur) cur.pop_back(), ans.pb('-');
        for(int j = cur.size(); j < s[i].size(); ++j) cur += s[i][j], ans.pb(s[i][j]);
        ans.pb('P');
    }
    for(int i = 0; i < cur.size(); ++i) ans.pb('-');
    return;
}


int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> s[i];
    sort(s + 1, s + n + 1);
    for(int i = 1; i <= n; ++i){
        int cnt = 0;
        while(cur.size() > s[i].size() || s[i].substr(0, (int)cur.size()) != cur) cur.pop_back(), ++cnt;
//        cout << s[i - 1].size() - 3 * cur.size() << " " << mx << endl;
        if(i > 1 && (int)s[i - 1].size() - 2 * (int)cur.size() > mx){
            mx = s[i - 1].size() - 3 * cur.size();
            start = i;
//            cout << i << " A " << cur.size() << endl;
        }
        for(int j = cur.size(); j < s[i].size(); ++j) cur += s[i][j];
    }
    int cnt = s[n].size();
    if(cnt > mx){
        mx = cnt;
        start = n + 1;
    }
    solve(start, n);
    solve(1, start - 1);
    while(ans.back() == '-') ans.pop_back();
    cout << ans.size() << endl;
    for(auto i : ans) cout << i << endl;
    return 0;
}

Compilation message

printer.cpp: In function 'void solve(int, int)':
printer.cpp:37:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for(int j = cur.size(); j < s[i].size(); ++j) cur += s[i][j], ans.pb(s[i][j]);
      |                                 ~~^~~~~~~~~~~~~
printer.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i = 0; i < cur.size(); ++i) ans.pb('-');
      |                    ~~^~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:60:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         for(int j = cur.size(); j < s[i].size(); ++j) cur += s[i][j];
      |                                 ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Incorrect 2 ms 3404 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 3416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3660 KB Output is correct
2 Incorrect 11 ms 3916 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 3920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 4796 KB Output is correct
2 Correct 62 ms 6724 KB Output is correct
3 Incorrect 36 ms 5720 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 4340 KB Output isn't correct
2 Halted 0 ms 0 KB -