CSES - Datatähti 2024 alku - Results
Submission details
Task:Laskettelukeskus
Sender:rottis
Submission time:2023-11-01 07:17:52 +0200
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp:40:19: error: extended character ‘ is not valid in an identifier
   40 |   std::cin.ignore(‘\n’)
      |                   ^
input/code.cpp:40:20: error: stray '\' in program
   40 |   std::cin.ignore(‘\n’)
      |                    ^
input/code.cpp:40:21: error: extended character ’ is not valid in an identifier
   40 |   std::cin.ignore(‘\n’)
      |                     ^
input/code.cpp: In function 'int main()':
input/code.cpp:40:19: error: '\U00002018' was not declared in this scope
   40 |   std::cin.ignore(‘\n’)
      |                   ^
input/code.cpp:44:5: error: 'ss' was not declared in this scope
   44 |     ss >> requireds[i];
      |     ^~

Code

#include <string>
#include <array>
#include <iostream>
#include <sstream>
#include <vector>
#include <ios>
std::array<unsigned int, 100000> requireds;
std::array<std::vector<unsigned short int>, 100000> nodes;
int calculate(int cur_node) {
std::vector<unsigned short int> children = nodes[cur_node];
unsigned int t = 0;
for (int c : children) {
t += calculate(c);
}
if (t > requireds[cur_node - 1]) {
return t;
} else {
return requireds[cur_node - 1];
}
}
int main() {
std::ios_base::sync_with_stdio(false);
int count;
std::cin >> count;
int temp1;
int temp2;
for (int i = 0; i < (count - 1); i++) {
std::cin >> temp1 >> temp2;
nodes[temp1].push_back(temp2);
}
std::string input;
std::getline(std::cin, input);
std::cin.ignore(‘\n’)
std::istringstream ss(input);
for (int i = 0; i < count; i++) {
ss >> requireds[i];
}
/*
for (int i = 0; i < count; i++) {
std::cin >> requireds[i];
}
*/
std::cout << calculate(1);
}
/*
$nodes = Hash.new { Array.new }
while rows.length > 0
a, b = rows.shift
$nodes[a] |= [b]
end
def calculate(current)
children = $nodes[current]
#puts "#{current}, #{children}"
if !children.empty?
t = 0
children.each { |c| t += calculate(c) }
if t >= $requireds[current - 1]
return t
end
end
return $requireds[current - 1] # shift
end
count = gets.chomp.to_i
rows = []
(count - 1).times do
rows << gets.chomp.split(" ").map(&:to_i)
end
$requireds = gets.chomp.split(" ").map(&:to_i)
# hash stores parent
# parent through child until child has no child, then take thing and return with alg
puts calculate(1)
*/