답안 #395275

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
395275 2021-04-28T05:28:25 Z Andyvanh1 Type Printer (IOI08_printer) C++14
30 / 100
553 ms 11752 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>

using namespace std;

#define pb push_back
#define INF INT32_MAX
#define vt vector


typedef vt<int> vi;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef long long ll;


int n;


#define MOD  1000000007
vt<vi> adjlist(1);
vt<char> node(1);
vt<bool> endd(1);
vt<int> par(1);
vt<int> depth(1);
int id;
int cur = 0;

void build(string str){
    int cur = 0;
    int at = 0;

    while(at!=str.length()){

        bool bol = false;
        for(auto& e: adjlist[cur]){
            if(e==par[cur])continue;
            if(node[e]==str[at]){
                at++;
                    cur = e;

                bol = true;
                break;
            }
        }
        if(!bol)break;

    }
    at--;
    while(at!=str.length()-1){
        adjlist.pb(vi(0));
        adjlist[cur].pb(id);
        adjlist[id].pb(cur);
        depth.pb(at+1);
        par.pb(cur);
        node.pb(str[at+1]);
        endd.pb(false);
        cur = id;
        at++;id++;

    }
    endd[id-1] = true;
}
vt<bool> visited;
void dfs(int noder){
    cur++;
    visited[noder] = true;
    if(endd[noder]){
        cout<<"P"<<endl;
    }
for(auto& e: adjlist[noder]){
    if(!visited[e]){
        cout<<string(1,node[e])<<endl;
        dfs(e);
    }

}
if(cur!=adjlist.size()) {
    cout << "-" << endl;
}
}

void solve2(){
    node[0] = 'A';
    endd[0] = false;
    par[0] = -1;
    depth[0] = -1;
    string Maxstr;

    cin>>n;
    id = 1;
    int Max = 0;
    for(int i = 0; i < n; i++){
        string s;
        cin>>s;
        int x = s.length();
        if(x>Max){
            Max = x;
            Maxstr = s;
        }
        build(s);
    }

    for(int i = 0; i < adjlist.size(); i++){
        for(int j = 0; j < adjlist[i].size(); j++){
            if(node[adjlist[i][j]]==Maxstr[depth[adjlist[i][j]]]){
                swap(adjlist[i][j],adjlist[i][adjlist[i].size()-1]);
            }
        }
    }


    visited.resize(adjlist.size());
    for(int i = 0; i < adjlist.size(); i++){
        visited[i] = false;
    }
    cout<<2*adjlist.size()+n-Max-2<<endl;
    dfs(0);





}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int tc = 1;
    //cin>>tc;

    solve2();




    return 0;
}

Compilation message

printer.cpp: In function 'void build(std::string)':
printer.cpp:39:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     while(at!=str.length()){
      |           ~~^~~~~~~~~~~~~~
printer.cpp:56:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     while(at!=str.length()-1){
      |           ~~^~~~~~~~~~~~~~~~
printer.cpp: In function 'void dfs(int)':
printer.cpp:84:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 | if(cur!=adjlist.size()) {
      |    ~~~^~~~~~~~~~~~~~~~
printer.cpp: In function 'void solve2()':
printer.cpp:110:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |     for(int i = 0; i < adjlist.size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~
printer.cpp:111:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |         for(int j = 0; j < adjlist[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~~~~~~~
printer.cpp:120:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |     for(int i = 0; i < adjlist.size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:137:9: warning: unused variable 'tc' [-Wunused-variable]
  137 |     int tc = 1;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 332 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 800 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 87 ms 1968 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 222 ms 4636 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 553 ms 11752 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 473 ms 8940 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -