CSES - Aalto Competitive Programming 2024 - wk12 - Wed - Results
Submission details
Task:Text Alignment
Sender:arnxxau
Submission time:2024-11-27 17:32:02 +0200
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#10.00 sdetails
#20.00 sdetails
#30.00 sdetails
#40.00 sdetails
#50.00 sdetails
#60.00 sdetails
#70.00 sdetails
#80.00 sdetails
#90.00 sdetails
#100.00 sdetails
#110.00 sdetails
#120.00 sdetails
#130.00 sdetails

Compiler report

input/code.cpp: In function 'std::vector<std::__cxx11::basic_string<char> > fullJustify(std::vector<std::__cxx11::basic_string<char> >&, int)':
input/code.cpp:13:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for (i = 0; i < a.size(); i = j) {
      |                 ~~^~~~~~~~~~
input/code.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |         for (j = i; j < a.size() && width + a[j].size() + j - i <= b; j++) {
      |                     ~~^~~~~~~~~~
input/code.cpp:15:65: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   15 |         for (j = i; j < a.size() && width +...

Code

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#include <climits>
#include <string>
using ll = long long int;

vector<string> fullJustify(vector<string> &a, int b) {
    vector<string> result;
    int i, j;
    for (i = 0; i < a.size(); i = j) {
        int width = 0;
        for (j = i; j < a.size() && width + a[j].size() + j - i <= b; j++) {
            width += a[j].size();
        }
        int space = 1;
        int extra = 0;
        if (j - i != 1 && j != a.size()) {
            space = (b - width) / (j - i - 1);
            extra = (b - width) % (j - i - 1);
        }
        string line(a[i]);
        for (int k = i + 1; k < j; k++) {
            line += string(space, ' ');
            if (extra-- > 0) {
                line += " ";
            }
            line += a[k];
        }
        int x = line.size();
        line += string(b - x, ' ');
        result.push_back(line);
    }
    return result;
}

int main() {
    string s;
    vector<string> v;
    while (cin >> s) {
        v.push_back(s);
    }

    vector<string> ans = fullJustify(v, v.size());
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i] << endl;
}

Test details

Test 1

Verdict:

input
zsyadhzdg ke irkyowki nflwfanr...

correct output
zsyadhzdg                     ...

user output
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  basic_string...

Test 2

Verdict:

input
eayoylmki efsqdhm qqvnrd npesu...

correct output
eayoylmki                     ...

user output
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  basic_string...

Test 3

Verdict:

input
bsvhdnoxlxad f bclsa llq hjrmp...

correct output
bsvhdnoxlxad                  ...

user output
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  basic_string...

Test 4

Verdict:

input
xoezwspspfdzfasgxlqu f wjzpekp...

correct output
xoezwspspfdzfasgxlqu          ...

user output
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  basic_string...

Test 5

Verdict:

input
bwvfj zmcpktjnmhzevcqtvlg twch...

correct output
bwvfj                         ...

user output
(empty)

Error:
terminate called after throwing an instance of 'std::length_error'
  what():  basic_string...

Test 6

Verdict:

input
yifvbbjczpcnpknimq lttkngpeqsz...

correct output
yifvbbjczpcnpknimq            ...

user output
yifvbbjczpcnpknimq  
lttkngpeqszxvmkrw   
vlbrsdujtqsloodcy   
kffvs     zogurtpssu
wjvghk
...
Truncated

Test 7

Verdict:

input
fu lzslzio ncbkga nrwuijkbrh x...

correct output
fu                            ...

user output
fu   lzslzio  ncbkga
nrwuijkbrh          
xsfilyygatpgyw eouxy
lnk jrfmcfmmpjymjjhv
tyieod
...
Truncated

Test 8

Verdict:

input
azgwjnvgkapltkknwm odostksvqal...

correct output
azgwjnvgkapltkknwm            ...

user output
azgwjnvgkapltkknwm  
odostksvqaljhmzwibf 
bhzrdh       eblfnky
nirzdaijhjotryhidl  
hru   
...
Truncated

Test 9

Verdict:

input
j mmadidafwkd dckim iwjy bzsso...

correct output
j                             ...

user output
j  mmadidafwkd dckim
iwjy bzssodxdryoosyk
sovqmtyjuvzce     nb
mqfwyzzergpwuxbtpjb 
eplmpm
...
Truncated

Test 10

Verdict:

input
barm sykc faxmvycwxs cnxuwpetq...

correct output
barm                          ...

user output
barm  sykc  faxmvycwxs  cnxuwp...
Truncated

Test 11

Verdict:

input
ltwg ns j axhacysdjhrpzymwxae ...

correct output
ltwg                          ...

user output
ltwg  ns  j  axhacysdjhrpzymwx...
Truncated

Test 12

Verdict:

input
pgwvxzeztltppuuq siarhxbs mjmr...

correct output
pgwvxzeztltppuuq              ...

user output
pgwvxzeztltppuuq  siarhxbs  mj...
Truncated

Test 13

Verdict:

input
xurwjadifyf iijoofrunig zadrff...

correct output
xurwjadifyf                   ...

user output
xurwjadifyf  iijoofrunig zadrf...
Truncated