AtCoder | Learning library
kandi X-RAY | AtCoder Summary
kandi X-RAY | AtCoder Summary
AtCoder
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of AtCoder
AtCoder Key Features
AtCoder Examples and Code Snippets
Community Discussions
Trending Discussions on AtCoder
QUESTION
Link to Problem -> https://atcoder.jp/contests/dp/tasks/dp_i
question Coins-I
Code I wrote gave wrong answer to TEST CASE 3
ANSWER
Answered 2022-Jan-13 at 08:38The number of digits to be printed via output streams is controlled by their precision parameter. The default is 6 digits, if you want more you need to adjust it accordingly by std::setprecision
:
QUESTION
I am getting a runtime error in some test cases when I try to submit my code. Problem Link: https://atcoder.jp/contests/dp/tasks/dp_a
My code:
...ANSWER
Answered 2021-Nov-25 at 07:46I'm not sure this is the only problem, in minCost()
but you're passing dp
by value, not reference. That means the compiler will make a copy of dp
, not the actual dp
.
Change your code to:
QUESTION
I am solving this question: D-Base n (https://atcoder.jp/contests/abc192/tasks/abc192_d)
It states that:
Given are a string X consisting of 0 through 9, and an integer M . Let d be the greatest digit in X . How many different integers not greater than M can be obtained by choosing an integer n not less than d + 1 and seeing X as a base- n number?
I solved this question iteratively (which gave me correct answers for small inputs) but it gave me TLE and overflow issues (see my submission at https://atcoder.jp/contests/abc192/submissions/20651499). The editorial said that I must use Binary Search and I have implemented it as follows. But i still dont get the correct outputs. Any advice is welcomed.
...ANSWER
Answered 2021-Mar-06 at 09:29ll convert(string x, ll base, ll m){
ll ans=0;
ll p=0;
ll cur=1;
for(int i=x.size()-1;i>=0;i--){
if(cur<0 || ans<0)
return m+1;
ans+=(ll)(x[i]-'0')*cur;
cur*=base;
if(ans>m)
return m+1;
}
return ans;
}
void solve(){
ll i, j, m;
string x;
cin>>x>>m;
int n=x.size();
ll mx=0;
for(auto i:x){
mx=max(mx, (ll)(i-'0'));
}
if(n==1){
cout<<(((ll)stoi(x))<=m)<
QUESTION
g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
BackgroundI practice implementing DFS.
I tried to solve this problem.
sorry for dirty code
...ANSWER
Answered 2020-Oct-17 at 02:02The array arr
has only 3 elements, so arr[3]
is out-of-range and no read and write to there are allowed. It seems params
is happened to be placed just after arr
and writing to arr[3]
is breaking data in params
.
To easily fix this, allocate one more element for arr
.
Better fix is to fix range of i
not to cause this out-of-range access.
QUESTION
i was trying to solve a competitive programming problem (on AtCoder) and i wanted to use priority queue, but then i got some problem.
i wrote the code below but when i tried to compile that, i got error messages that said "no matching member function for call to 'push' " (the entire error messages are shown below)
i have no idea why this is happening, and i tried it on AtCoder Code Test online judge.
https://atcoder.jp/contests/abc176/custom_test
it worked completely fine on the online judge.
adding to that, i talked about this problem with my friend and he said the code worked just fine on his environment (he uses Windows).
Here is the code.
...ANSWER
Answered 2020-Sep-21 at 20:58Do you have an ancient version of g++? I tried compiling your code as far back as 4.8.1 (from 2013) and it worked in c++11 mode. In older versions than that, it didn't know some of the headers.
(Current version is 10.2.0)
I suggest you try playing with your code on Compiler Explorer. It gives you access to online versions of g++, clang, msvc++, and others, going back for many years over many versions, without any hassle of setup or installing anything. Here's your code with g++ 4.8:
QUESTION
I came across this quesiton: https://atcoder.jp/contests/agc047/tasks/agc047_b and my code is as follows. My solution is very similar to the editorial.
I'm confused why this has memory issues. I make 10^6 * 26 nodes in the worst case scenario. The memory limit is 1024MB which seems like much more than enough. How is memory measured for a self referential class?
Additionally, how can I salvage my code?
...ANSWER
Answered 2020-Aug-10 at 10:03With 26 million nodes and 1024 megabytes, each node will need to be less than 40 bytes. But sizeof(node)
is going to be at least 112 bytes, just for its members. The "self-referential" part comes from 26 pointers, each of which needs to be 4 bytes to support 1024MB.
You'll need another data structure. One solution is to have just a single firstChild
per node, but also a nextSibling
and a char c
.
QUESTION
I was recently solving a knapsack problem. In this version of knapsack, instead of weight, value is taken into the state.
The problem is the same as general Knapsack: There are n items, Item i has a weight of wi and a value of vi. The capacity of the knapsack is W. Find the maximum possible sum of the values of items that can be filled in the knapsack.
Constraints: 1<= n <=100 1<= W <=10^9 1<= wi <=W 1<= vi <=1000
Input: n W
w1 v1 w2 v2 w3 v3 ..... wn vn
Due to large value of weight, We have to take value in the state and the result will be the minimum weight. Although I have explained the problem but in case you need more details this is the problem link.
The below code is my attempt to solve the problem. I have used 1-based indexing. I'm not able to find out the error. I have tried debugging the code but that didn't help. I'm stuck on this from 2 days. Please help.
...ANSWER
Answered 2020-Aug-01 at 07:12There's a few problems with your code:
- Max value can be 0
- weight needed to reach some value can be >
INT_MAX
dp[1][v[1]]=w[1];
uneeded linefor (int j = 1; j < 100001; ++j)
j
of 0 is valid weight thoughif(j-v[i]>=1){
same as above
Here's a fixed version:
QUESTION
I solved this problem statement (Yeah Yeah, I know, I am putting the problem statement below).
Given are an integer X and an integer sequence of length N: p1, …, pN. Among the integers not contained in the sequence p1, …, pN (not necessarily positive), find the integer nearest to X, i.e. the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer
This is the code I used:
...ANSWER
Answered 2020-Jun-16 at 14:39According to your link, the total number of integers is at most 100. So 100 bits are enough to hold the flags, which numbers appear in the sequence. Those can be held in the processor registers.
The following code shows only the storage, afterwords you would have to chose suitable bit scan operations:
QUESTION
So, I'm trying to solve the following Problem Statement
For an integer N, find the number of times the following operation can be performed:
...ANSWER
Answered 2020-Jun-01 at 13:55The number N
can be factored into (p1 ^ e1)(p2 ^ e2) ...
. For each of these factors p^e
, the most that you can divide N
by is (p)(p ^ 2)(p ^ 3)...
. Of course, all those powers need to sum to less than or equal to e
.
So you only need to compute all the factors once, and then for each e
, find the largest triangular number that is less than or equal to e
. The repeated factor calculations are wasted work, and is unnecessary.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install AtCoder
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page