Submission #428283

# Submission time Handle Problem Language Result Execution time Memory
428283 2021-06-15T09:35:51 Z arayi Type Printer (IOI08_printer) C++17
100 / 100
100 ms 37836 KB
//Arayi
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>   
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cassert>
#include <chrono>
#include <random>
#include <complex>

#define fr first
#define sc second
#define MP make_pair
#define ad push_back
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define lli long long int
#define y1 arayikhalatyan
#define j1 jigglypuff
#define ld long double
#define itn int
#define pir pair<int, int>
#define all(x) (x).begin(), (x).end()
#define str string
#define enl endl
#define en endl
#define cd complex<long double>
#define vcd vector<cd>
#define vii vector<int>
#define vlli vector<lli>
using namespace std;

lli gcd(lli a, lli b) { return (b == 0LL ? a : gcd(b, a % b)); }
ld dist(ld x, ld y1, ld x2, ld y2)
{
    return sqrt((x - x2) * (x - x2) + (y1 - y2) * (y1 - y2));
}
lli S(lli a)
{
    return (a * (a + 1LL)) / 2;
}
mt19937 rnd(363542);
char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 0, -1, 0, 1, -1, -1, 1, 1, 0 };
int dy[] = { -1, 0, 1, 0, -1, 1, -1, 1, 0 };


const int N = 1e6 + 30;
const lli mod = 1e9 + 7;
const ld pi = acos(-1);
const int T = 200;

lli bp(lli a, lli b = mod - 2LL)
{
    lli ret = 1;
    while (b)
    {
        if (b & 1) ret *= a, ret %= mod;
        a *= a;
        a %= mod;
        b >>= 1;
    }
    return ret;
}
ostream& operator<<(ostream& c, pir a)
{
    c << a.fr << " " << a.sc;
    return c;
}
template<class T>
void maxi(T& a, T b)
{
    a = max(a, b);
}
template <class T>
void mini(T& a, T b)
{
    a = min(a, b);
}



int n;
bool col[N];
vector<char>pat;
string s[N];
int qn(str a, str b)
{
    for (int i = 0; i < min(a.size(), b.size()); i++)
    {
        if(a[i]!=b[i]) return i;
    }
    return a.size();
}
str slv(str nx, vector<str> fp)
{
    sort(fp.begin(), fp.end());
    for(auto p : fp)
    {
        int sm = qn(nx, p);
        for (int j = 0; j < nx.size() - sm; j++) pat.ad('-');
        for (int j = sm; j < p.size(); j++) pat.ad(p[j]);
        pat.ad('P');
        nx = p;
    }
    return nx;
}
int main()
{
    fastio;
    cin >> n;
    int i1 = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
        if(s[i].size() > s[i1].size()) i1 = i;
    }
    str nx = "";
    for (int i = 0; i <= s[i1].size(); i++)
    {
        vector <str> fp;
        for (int j = 0; j < n; j++)
            if(!col[j] && qn(s[j], s[i1]) == i) fp.ad(s[j]), col[j] = 1;
        nx = slv(nx, fp);
    }
    cout << pat.size() << endl;
    for(auto p : pat) cout << p << "\n";
    return 0;
}

/*
    __
  *(><)*
    \/ /
    ||/
  --||
    ||
    /\
   /  \
  /    \

*/

Compilation message

printer.cpp: In function 'int qn(std::string, std::string)':
printer.cpp:103:23: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
  103 |     for (int i = 0; i < min(a.size(), b.size()); i++)
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp: In function 'std::string slv(std::string, std::vector<std::__cxx11::basic_string<char> >)':
printer.cpp:115:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |         for (int j = 0; j < nx.size() - sm; j++) pat.ad('-');
      |                         ~~^~~~~~~~~~~~~~~~
printer.cpp:116:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |         for (int j = sm; j < p.size(); j++) pat.ad(p[j]);
      |                          ~~^~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:133:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  133 |     for (int i = 0; i <= s[i1].size(); i++)
      |                     ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 31564 KB Output is correct
2 Correct 21 ms 31640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31564 KB Output is correct
2 Correct 19 ms 31576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31564 KB Output is correct
2 Correct 18 ms 31560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 31640 KB Output is correct
2 Correct 19 ms 31516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 31536 KB Output is correct
2 Correct 19 ms 31692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 31752 KB Output is correct
2 Correct 21 ms 31820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 32076 KB Output is correct
2 Correct 31 ms 32476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 32568 KB Output is correct
2 Correct 29 ms 32880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 34240 KB Output is correct
2 Correct 90 ms 37048 KB Output is correct
3 Correct 65 ms 36580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 34056 KB Output is correct
2 Correct 100 ms 37732 KB Output is correct
3 Correct 72 ms 37180 KB Output is correct
4 Correct 91 ms 37836 KB Output is correct