atcoder_official's blog

By atcoder_official, history, 9 months ago, In English

We will hold AtCoder Beginner Contest 313.

The point values will be 100-300-400-550-600-625-625-650.

Since this contest is used as a qualification round for a local onsite contest, the problems are a bit different from usual ABCs. The style of the problems is a bit closer to ARCs, and the problems are a bit harder. Please refer to previous contests prepared in a similar manner.

We are looking forward to your participation!

  • Vote: I like it
  • +79
  • Vote: I do not like it

»
9 months ago, # |
  Vote: I like it +41 Vote: I do not like it

Never seen point values being so odd.

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Heard that the game is more difficult than usual, hope I can solve ABC.

»
9 months ago, # |
  Vote: I like it +11 Vote: I do not like it

The problems are "a bit" harder.

  • »
    »
    9 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Update: Only solved ABCDE during the contest. It's really difficult!

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

A BIT easier than ARC...

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Let's see if we can solve the first 3 problems.

  • »
    »
    9 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    The first three problems' difficulties today is like the first four problems' difficulties in ordinary ABC's.

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

The point value is different from before and the difficulty has also increased. Looking forward to it.

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I solved problem A. But I can't solve problem B...

  • »
    »
    9 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    The same as you, I thought out the answer of Problem B at last but at that moment the contest has ended... It seems that I am still a newbie.:-(

    • »
      »
      »
      9 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I use depth first search and graphy theory. My Program can't run correctly on testcase 26, 27, 28, 29. When I see the editoral, I find that the correct code is easy!

      • »
        »
        »
        »
        9 months ago, # ^ |
        Rev. 5   Vote: I like it 0 Vote: I do not like it

        Yes. I tried to solve it using the DSU at first, but in fact that proved to be cumbersome and would get WA on nine testcases. I need practise more,lol. Come on, let’s work hard together!

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

No god please no

I only solved AB

My rating will go down rapidly

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

First 3 felt easier than normal ABC's level and then D killed me.

»
9 months ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Why is my code for C wrong?

#include <bits/stdc++.h>
#define int long long
using namespace std;
int n;
int a[2000000];
signed main() {
    cin>>n;
    int sum=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    int temp=(sum+n-1)/n;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(a[i]>temp){
            ans+=a[i]-temp;
        }else if(a[i]<temp){
            ans+=temp-a[i];
        }
    }
    cout<<ans/2<<endl;
    
    return 0;
}
  • »
    »
    9 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    i used this code for first but i get WA on samples so i changed it and solved this problem with binary search.

  • »
    »
    9 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    You intution is wrong . Think different

»
9 months ago, # |
Rev. 2   Vote: I like it +27 Vote: I do not like it
»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Sorry to inform that C == this. btw i got my penalty cuz my sol doesn't have enough array size...

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I only solved ABC My rating will go down rapidly

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

It's wise of me to participate unrated. Problems are very hard.

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

It seems problem C can be solved without sort,in O(n).(the official solution is O(n logn) ) By divide the a[i] into two groups.

My Solution:

if a[i]<sum/n , ans1+=floor(sum/n)-a[i]

else ans2+=a[i]-ceil(sum/n)

so the answer is max(ans1,ans2).

I submit it and AC,but I'm not sure if its really true.Can anyone tell me?

»
9 months ago, # |
  Vote: I like it +10 Vote: I do not like it

Today's difficulty level of the problems I could solve According to me A < B < C < E < D

D was the most thinking I had to do among them, rest were pretty straightforward.

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Why is my code for B wrong?

from collections import defaultdict
n, m = map(int, input().split())
a = [i for i in range(n+1)]
d = defaultdict(list)
for _ in range(m):
    b, c = map(int, input().split())
    a[c] = a[b]
    d[b].append(c)
    for child in d[c]:
        a[child] = a[b]
st = set(a[1:])
print(st.pop() if len(st) == 1 else -1)
  • »
    »
    9 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I see the a list doesn't always have the root in each index, so it's the wrong algorithm for this problem.

»
9 months ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Is there any way to check a specific test case at Atcoder?

My submission for problem D fails at 1 test case out of the 29 test cases, and I'm not able to pinpoint where the error could be.

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Whats Wrong in this code for B ?

using namespace std;
typedef long long int lli;

void dfs(int V, vector adj[], int node, vector &vis)
{
vis[node]=1;
for(auto itr:adj[node])
{
if(vis[itr]==0)
{
vis[itr]=1;
dfs(V,adj,itr,vis);
}
}
}

int main()
{
int n,m;
cin>>n>>m;
vector adj[n+1];
for(int i=0;i<m;i++)
{
lli a,b;
cin>>a>>b;
adj[a].push_back(b);
}
int cnt=0,store=-1;
vector vis(n+1,0);
for(int i=1;i<=n;i++){
if(vis[i]==0){
cnt++;
store=i;
dfs(n,adj,i,vis);
}
}
if(cnt>=2) cout<<"-1"<<endl;
else
cout<<store<<endl;
return 0;
}

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I think problem D is very fantastic. May I ask the atcoder_official team, how do you come up with this problem and idea? Is there any related problem or similar idea that inspires you? I think to create such a problem is even harder than solving it.

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Hey, I am only able to solve atmost 2 problems in the contests and I want to increase this number. Someone of higher rank pls guide me. I really tried to go with brute force, dp, backtracking methods but I am not able to solve those 3, 4 ,... questions of the contest. Pls someone share some keypoints which can help me increase my rank in the contests.

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef unordered_map<string, int> usi;
typedef unordered_map<int, int> uii;
typedef unordered_set<int> ui;
#define FOR(a, b, c) for (int a = b; a < c; ++a)
#define FORN(a, b, c) for (int a = b; a <= c; ++a)
#define FORD(a, b, c) for (int a = b; a >= c; --a)
#define FORSQ(a, b, c) for (int a = b; a * a <= c; ++a)
#define FORC(a, b, c) for (char a = b; a <= c; ++a)
#define FOREACH(a, b) for (auto &(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define debug(x) cout << #x << ' ' << x << '\n'
#define yes cout << "Yes\n"
#define no cout << "No\n"
#define fsp(x) fixed << setprecision(x)
#define nl cout << "\n"

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m;
    cin >> n >> m;
    vi A(m), B(m);
    FOR(i, 0, m)
        cin >> A[i] >> B[i];
    unordered_map<int, int> umap;
    FOR(i, 0, m)
        umap[A[i]] = B[i];
    unordered_set<int> uset;
    FOR(i, 1, n + 1)
    {
        if (umap.find(i) != umap.end())
        {
            bool arr[n + 1] = {0};
            int temp = i;
            arr[temp] = 1;

            while (umap.find(temp) != umap.end())
            {
                arr[umap[temp]] = 1;
                temp = umap[temp];
            }
            bool flag = 1;
            FOR(j, 1, n + 1)
            if (arr[j] == 0)
                flag = 0;
            if (flag)
                uset.insert(i);
        }
    }
    if (uset.size() == 1)
        cout << *(uset.begin()) << "\n";
    else
        cout << "-1"
             << "\n";

    return 0;
}

I tried doing problem B using map,but I am getting wrong answer in some test cases. Can someone explain me what is wrong here? I think logically it should be correct, since it passed most test cases.

Submission link:https://atcoder.jp/contests/abc313/submissions/44280370

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I have passed all the ABCDE questions. Do any talented programmers tell me how to write F questions?

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Hot to see the AfterContest?