CSES - Datatähti 2022 loppu - Results
Submission details
Task:Lista
Sender:andreibe
Submission time:2022-11-06 17:52:33 +0200
Language:C++ (C++11)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED13
#2ACCEPTED26
#3ACCEPTED61
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3details
#2ACCEPTED0.01 s2, 3details
#3ACCEPTED0.01 s3details
#4ACCEPTED0.00 s1, 2, 3details
#5ACCEPTED0.00 s1, 2, 3details
#6ACCEPTED0.00 s1, 2, 3details
#7ACCEPTED0.00 s1, 2, 3details
#8ACCEPTED0.01 s3details
#9ACCEPTED0.01 s3details
#10ACCEPTED0.01 s3details

Compiler report

input/code.cpp: In function 'std::string edit(std::string, std::string, std::string)':
input/code.cpp:52:55: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |                                 for (int j = i + 1; j < s.length(); j++)
      |                                                     ~~^~~~~~~~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:104:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |                 for (int j = 0; j < s.length(); j++)
      |                                 ~~^~~~~~~~~~~~
input/code.cpp:89:22: warning: unused variable 'done' [-Wunused-variable]
   89 |                 bool done = false;
      |                      ^~~~
input/code.cpp:76:13: warning: unused variable 'lastNum' [-Wunused-va...

Code

#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <algorithm>
#include <vector>
#include <fstream>
#include <set>
#include <unordered_map>
#include <queue>
#include <climits>
#include <stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define S second
#define F first
#define A 999999999999999999LL
#define M 1000000007
// https://cses.fi/dt/
int n;
int t;
pair<int, int> d[11][11][5];
int mypow(int a, int b) {
if (b == 0) return 1;
int num = 1;
while (b--) {
num *= a;
}
return num;
}
string edit(string s, string last, string org)
{
int difference = stoi(s) - stoi(last);
// goal s < last
int potentialsavings = 0;
for (int i = s.length() - 1; i >= 0; i--)
{
if (org[i] != '?')
continue;
int limit = s[i] - '0';
for (int k = 1; k <= limit; k++)
{
s[i] = to_string(limit - k)[0];
if (k * pow(10, s.length() - i - 1) + potentialsavings > difference)
{
//cout << "Enough " << i<< " " << k << " " << potentialsavings << " " << difference<< endl;
int extra = k * mypow(10, s.length() - i - 1) + potentialsavings - difference - 1;
//cout << "Extra " << extra << " " << potentialsavings<< " " << s << "\n" ;
for (int j = i + 1; j < s.length(); j++)
{
if (org[j] != '?')
continue;
int amount = extra / pow(10, s.length() - j - 1);
amount = min(amount,9);
extra -= amount * pow(10, s.length() - j - 1);
//cout << "Change " << j << " " << amount << endl;
s[j] = to_string(amount)[0];
}
return s;
}
}
potentialsavings += limit * pow(10, s.length() - i - 1);
}
return s;
}
#define N (1 << 17)
int main()
{
//cout << edit("999999", "999015", "?9????");
//exit(0);
cin >> n;
int lastNum = 0;
vector<string> v;
vector<string> t;
for (int i = 0; i < n; i++)
{
string s; cin >> s;
t.push_back(s);
}
string last = t[t.size() - 1];
replace(last.begin(), last.end(), '?', '9');
v.push_back(last);
for (int i = t.size() - 2; i >= 0; i--)
{
bool done = false;
string s = t[i];
string org = s;
if (s.length() < last.length())
{
replace(s.begin(), s.end(), '?', '9');
v.push_back(s);
last = s;
continue;
}
if (s.length() > last.length())
{
cout << "IMPOSSIBLE";
exit(0);
}
for (int j = 0; j < s.length(); j++)
{
if (s[j] == '?') s[j] = '9';
}
int difference = stoi(s) - stoi(last);
if (difference >= 0) s = edit(s, last,org);
//cout << i << " " << s << " " << org<< endl;
if (stoi(s) < stoi(last) && s[0] != '0')
{
v.push_back(s);
}
else
{
//cout << s << " " << last << " " << org << endl;
cout << "IMPOSSIBLE";
exit(0);
}
last = s;
}
int l = 0;
for (int i = v.size() - 1; i >= 0; i--)
{
//cout << v[i] << " " << t[n-i-1] << " " << i << "\n";
cout << v[i] << "\n";
if (stoi(v[i]) < l)
{
cout << "wtf??? " << i;
exit(0);
}
l = stoi(v[i]);
}
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
100
??
??
??
??
...

correct output
10
11
12
13
20
...

user output
86
87
88
89
90
...
Truncated

Test 2

Group: 2, 3

Verdict: ACCEPTED

input
1000
8??
??8?
????
????
...

correct output
800
1080
1081
1082
1083
...

user output
899
9989
9995
9996
9997
...
Truncated

Test 3

Group: 3

Verdict: ACCEPTED

input
1000
??????
?????9?
??98???
?????5?
...

correct output
100000
1000090
1098000
1098050
4100001
...

user output
999999
4198998
4198999
4199959
4199991
...
Truncated

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
100
?
?
?
?
...

correct output
1
2
3
4
5
...

user output
1
2
3
4
5
...
Truncated

Test 5

Group: 1, 2, 3

Verdict: ACCEPTED

input
2
???
??

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 6

Group: 1, 2, 3

Verdict: ACCEPTED

input
3
123
???
124

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 7

Group: 1, 2, 3

Verdict: ACCEPTED

input
5
1??
???
2??
???
...

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 8

Group: 3

Verdict: ACCEPTED

input
1000
?????????
?????????
?????????
?????????
...

correct output
100000000
100000001
100000002
100000003
100000004
...

user output
100000000
100000001
100000002
100000003
100000004
...
Truncated

Test 9

Group: 3

Verdict: ACCEPTED

input
900
???000000
???000000
???000000
???000000
...

correct output
100000000
101000000
102000000
103000000
104000000
...

user output
100000000
101000000
102000000
103000000
104000000
...
Truncated

Test 10

Group: 3

Verdict: ACCEPTED

input
1000
???1?????
???0?????
???1?????
???0?????
...

correct output
100100000
101000000
101100000
102000000
102100000
...

user output
499199999
500099999
500199999
501099999
501199999
...
Truncated