답안 #581193

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581193 2022-06-22T10:56:30 Z SAAD Type Printer (IOI08_printer) C++17
10 / 100
436 ms 4212 KB
#define F first
#define S second
#define rep(i,a,b) for(int i=a;!(a==b&&i!=b)&&((i<=b&&b>=a)||(i>=b&&a>=b));i+=(a<=b?1:-1))
#define pb push_back
#define Fbitl __builtin_ffs
#define bit1 __builtin_popcount
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int N = 100005;
int n , mx ;
vector <pair<string,int>> z[200] ;
string tab ;
struct s {
    int mx , l , r;
    char ch ;
};
int re ;
string prnt ( string a ){
    string ret = "" ;
    while ( tab.length() > a.length() ) {
        tab.pop_back();
        ret += '-' ;
        re++;
    }
    while ( tab != a.substr(0,tab.length()) ) {
        tab.pop_back();
        ret += '-' ;
        re++;
    }
    while (tab != a) {
        ret += a[tab.length()];
        tab += a[tab.length()];
        re++;
    }
    ret += 'P' ;
    re++;
    return ret ;
}
int main(){
    vector <string> v ;
    int n;
    cin >> n;
    for ( int i = 0 ; i < n ; i++ ) {
        string s;
        cin >> s;
        v.pb(s);
    }
    sort(v.begin(),v.end());
    int l = 0 , r = -1 ;
    s mx ;
    for ( int i = 0 ; i < n ; i++ ) {
        z[v[i][0]].pb({v[i],i});
        r++;
        if ( i > 0 && v[i].length() <= v[i-1].length()) {
                l = i ;
                r = i ;
        }
        if ( v[i].length() > mx.mx ) {
            mx.mx = v[i].length() ;
            mx.l = l ;
            mx.r = r ;
            mx.ch = v[i][0] ;
        }
    }
    vector <string> res ;
    for ( int i = 'a' ; i <= 'z' ; i++ )  {
        if ( mx.ch == i ) continue;
        for ( auto j : z[i] ) {
            res.pb(prnt(j.F));
        }
    }
    for ( auto i : z[mx.ch] ) {
        if ( i.S > mx.r || i.S < mx.l ) {
            res.pb(prnt(i.F));
        }
    }
    for ( auto i : z[mx.ch] ) {
        if ( !(i.S > mx.r || i.S < mx.l) ) {
            res.pb(prnt(i.F));
        }
    }
    cout << re << endl;
    for (auto i : res ) {
        for ( auto j : i ) {
            cout << j << endl;
        }
    }
	return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:70:18: warning: array subscript has type 'char' [-Wchar-subscripts]
   70 |         z[v[i][0]].pb({v[i],i});
      |                  ^
printer.cpp:76:28: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   76 |         if ( v[i].length() > mx.mx ) {
      |              ~~~~~~~~~~~~~~^~~~~~~
printer.cpp:90:25: warning: array subscript has type 'char' [-Wchar-subscripts]
   90 |     for ( auto i : z[mx.ch] ) {
      |                      ~~~^~
printer.cpp:95:25: warning: array subscript has type 'char' [-Wchar-subscripts]
   95 |     for ( auto i : z[mx.ch] ) {
      |                      ~~~^~
printer.cpp:96:9: warning: 'mx.s::r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   96 |         if ( !(i.S > mx.r || i.S < mx.l) ) {
      |         ^~
printer.cpp:68:7: warning: 'mx.s::ch' may be used uninitialized in this function [-Wmaybe-uninitialized]
   68 |     s mx ;
      |       ^~
printer.cpp:96:14: warning: 'mx.s::l' may be used uninitialized in this function [-Wmaybe-uninitialized]
   96 |         if ( !(i.S > mx.r || i.S < mx.l) ) {
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:76:33: warning: 'mx.s::mx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   76 |         if ( v[i].length() > mx.mx ) {
      |                              ~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 72 ms 836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 195 ms 2176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 436 ms 4212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 372 ms 3680 KB Output isn't correct
2 Halted 0 ms 0 KB -