Блог пользователя chokudai

Автор chokudai, история, 6 лет назад, По-английски

We will hold AtCoder Beginner Contest 176.

The point values will be 100-200-300-400-500-600.

We are looking forward to your participation!

  • Проголосовать: нравится
  • +93
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +12 Проголосовать: не нравится

Why no editorial for ABC 175 yet?!

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +35 Проголосовать: не нравится

See you all on the scoreboard! (and on Youtube after contest)

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

Please provide Editorials to learn new concepts.After the contests ended_

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

Is it only me or the standing is loading forever. Nice problems by the way.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Is AtCoder predictor broken today? Seems like the performance of everyone is 2400...

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

help me with D after the contest

»
6 лет назад, скрыть # |
 
Проголосовать: нравится -18 Проголосовать: не нравится

Please set problems such that it's possible to come back after going back-foot or at least possible to try.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

how to solve problem D please help??????????????????????????

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Dijkstra

    code
  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Search for 0-1 bfs.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

ok solution of F plz

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For D, first separate all the different regions using DFS.

Then construct a graph between different regions using the trick that the magician can use.

Finally ,find the shortest distance between the region of initial point and the region of final point using

simple bfs (by maintaining a 'level' array).

Here's my submission:

https://atcoder.jp/contests/abc176/submissions/16143722

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +20 Проголосовать: не нравится

Is F a dp problem?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

can problem D solved by DP?????????

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

how to solve E? I was trying something like O(nsqrtn) which was timing out.

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +15 Проголосовать: не нравится
    hint 1
    hint 2
    hint 3
    code

    And sorry for my poor English.

    • »
      »
      »
      6 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +3 Проголосовать: не нравится

      Same logic , maps TLED my solution!

    • »
      »
      »
      6 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +2 Проголосовать: не нравится

      Thank You for the great explanation. Made things up clear.

    • »
      »
      »
      6 лет назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится -6 Проголосовать: не нравится

      include<stdio.h>

      int main() { long long a,b,c,d,e,f,g,h,i,j,k,l; scanf("%lli",&a,&b,&c); int z[a][b]; for(d=0;d<a;d++) { for(e=0;e<b;e++)z[d][e]=0; } for(;c;c--) { scanf("%lli%lli",&d,&e); z[d-1][e-1]=1; } long long y[a],x[b]; for(d=0;d<a;d++) { for(e=f=0;e<b;e++) { if(z[d][e])f++; } y[d]=f; } for(d=0;d<b;d++) { for(e=f=0;e<a;e++) { if(z[e][d])f++; } x[d]=f; } for(d=f=0;d<a;d++) { for(e=0;e<b;e++) { g=y[d]+x[e]; if(z[d][e])g--; if(g>f)f=g; } } printf("%lli\n",f); return 0; }

      I wrote this for E. But I got error : warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]

      What is the reason for that? Only some test sets return this error, rest give AC. Do you have any suggestion?

      https://atcoder.jp/contests/abc176/submissions/16135523 Submission link. Sorry for the wrong formatting

      • »
        »
        »
        »
        6 лет назад, скрыть # ^ |
        Rev. 2  
        Проголосовать: нравится +10 Проголосовать: не нравится

        This error, which is not actually an error but a warning, has nothing to do with why your solution fails.

        scanf returns the number of variables that were succesfully parsed and set or EOF if none were due to reaching end of file and is declared with attribute((warn_unused_result)) because if you're using it outside competitive programming you should to some extend keep in mind the possibility that the file you're reading is corrupted or something and at least check if the value is what it is supposed to be, but for competitive programming you can pretty much just ignore this warning.

        If you don't want it to pop up to have better chance of spotting a warning referring to something which actually might be wrong, or just because it's annoying you can use -Wno-unused-result flag for compilation

        And the reason your solution gets RE verdict is pretty simple. int z[a][b]; declares an array with $$$a\cdot b$$$ elements which can be up to $$$9\cdot 10^{10}$$$ and by far exceed memory limit

    • »
      »
      »
      6 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +6 Проголосовать: не нравится

      if size of first vector * size of second vector > 300000 then output maximum number of bombs in a row + maximum number of bombs in a column.if size <300000 then how can we be sure that ans is maximum number of bombs in a row + maximum number of bombs?

  • »
    »
    6 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +3 Проголосовать: не нравится

    edit- my solution is wrong tho it was AC

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    My solution is choosing the coordinate x,y that could maximize the target.

    The answer is the number of targets that x hit + the number of targets that y hit — (there is a target at coordinate (x,y)).

  • »
    »
    6 лет назад, скрыть # ^ |
    Rev. 4  
    Проголосовать: нравится +8 Проголосовать: не нравится

    Let $$$r[i]$$$ be the number of targets in row $$$i$$$, and $$$c[j]$$$ be the number of targets in columns $$$j$$$. Then the answer is $$$\max(r) + \max(c)$$$ unless for every pair $$$i, j$$$ such that $$$r[i] == \max(r)$$$ and $$$c[j] == \max(c)$$$, we have a target at $$$(i, j)$$$ (if the intersection of a pair doesn't have a target, we can simply choose that pair). Otherwise, the answer is $$$\max(r)+\max(c)-1$$$ (no matter what, we overcount the target at the intersection).

    This is equivalent to the following: If $$$x$$$ is the number of rows $$$i$$$ with $$$r[i] == \max(r)$$$, $$$y$$$ is the number of columns $$$j$$$ with $$$c[j] == \max(c)$$$, and $$$z$$$ is the number of targets with coordinates $$$(i, j)$$$ satisfying $$$i == \max(r)$$$ and $$$j == \max(c)$$$, then the answer is $$$\max(r)+\max(c)-(x*y == z)$$$.

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    were you using unordered_map?

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    I did this and got AC

    Code
  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    My submission : https://atcoder.jp/contests/abc176/submissions/16163575 Count number of points for in each row and each column. Then find the columns and rows that have maximum points (Sort). In case there are multiple rows(columns) with max value, find if there is atleast one point among them that doesn't have target. If you found such a point answer is max row value + max column value. Else just subtract 1 from it

    • »
      »
      »
      6 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +10 Проголосовать: не нравится
      #include<bits/stdc++.h>
      #define ll long long
      #define fo(i,n) for(int i=0;i<n;i++)
      #define rfo(i,n) for(int i=n-1;i>=0;i--)
      #define Fo(i,q,n) for(int i=q;i<n;i++)
      #define rFo(i,q,n) for(int i=n-1;i>=q;i--)
      #define fO(i,n,k) for(int i=0;i<n;i+=k)
      #define FO(i,q,n,k) for(int i=q;i<n;i+=k)
      #define zero(a,n) memset(a,0,sizeof(a[0])*n)
      #define pb push_back
      #define mp make_pair
      #define F first
      #define S second
      #define endl "\n"
      #define Endl "\n"
      #define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
      using namespace std;
      const int MOD=1000000007;
      void print(){cout <<endl;}
      template <typename T, typename... Types> 
      void print(T var1, Types... var2){cout << var1 << " " ;print(var2...) ;}
      //ceil of a/b
      template <typename T>
      T fceil(T a,T b){return (T)(a+b-1)/b;}
      //const int N=2e5;
      //int arr[N+1];
       
       
      int main(){
      	ios::sync_with_stdio(false);
      	cin.tie(0);
      	int h,w,m;
      	cin>>h>>w>>m;
      	vector<int> rows(h,0);
      	vector<int> cols(w,0);
      	int x,y;
      	map< pair<int,int> ,int>dict;
      	fo(i,m){
      		cin>>x>>y;
      		x--;y--;
      		rows[x]+=1;
      		cols[y]+=1;
      		dict[mp(x,y)]=1;	
      	}
      	vector< pair<int,int> > rc;
      	fo(i,h){
      		rc.pb(mp(rows[i],i));	
      	}
      	vector< pair<int,int> > cc;
      	fo(i,w){
      		cc.pb(mp(cols[i],i));
      	}
      	sort(rc.rbegin(),rc.rend());
      	sort(cc.rbegin(),cc.rend());
      	vector< pair<int,int> > rcp;
      	vector< pair<int,int> > ccp;
      	int rmax = rc[0].F;
      	int cmax = cc[0].F;
      	int k=0;
      	while(k<(int)rc.size() && rc[k].F==rmax){
      		rcp.pb(rc[k]);
      		k++;	
      	}
      	k=0;
      	while(k<(int)cc.size() && cc[k].F==cmax){
      		ccp.pb(cc[k]);
      		k++;	
      	}
      	int flag=1;
      	fo(i,(int)rcp.size()){
      		fo(j,(int)ccp.size()){
      			if(dict[mp(rcp[i].S,ccp[j].S)]==0){
      				flag=0;
      				break;	
      			}
      		}	
      	}
      	cout<<rmax+cmax-flag<<endl;
      	return 0;
      }
      
»
6 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

How to solve E???

  • »
    »
    6 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +2 Проголосовать: не нравится

    The final answer would be either be the maxRowsum + maxColSum or maxRowsum + maxColSum -1(where maxRowSum means maximum number of targets in a row considering all rows and maxColSum means maximum number of targets in a column considering all columns).
    We need to find all rows having number of targets equal to maxRowSum and all columns having number of targets equal to maxColSum and then check for each one of them whether there exists a combination of them where the common element isn't a target.If such combination exists then answer would be maxRowsum + maxColSum otherwise maxRowsum + maxColSum -1.We could use map to check whether a co-ordinate is a target or not.
    My submission:-E — Bomber

    • »
      »
      »
      6 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +1 Проголосовать: не нравится

      Understood.Thanks a lot.

    • »
      »
      »
      6 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      I did the same thing I think, then why tle for 3 cases?

      #include<bits/stdc++.h>
      using namespace std;
      #define ll                          long long
      #define in(a)                       ll a; cin>>a;
      #define in2(a,b)                    ll a,b; cin>>a>>b;
      #define in3(a,b,c)                  ll a,b,c; cin>>a>>b>>c;
      #define in4(a,b,c,d)                ll a,b,c,d; cin>>a>>b>>c>>d;
      #define in5(a,b,c,d,e)              ll a,b,c,d,e; cin>>a>>b>>c>>d>>e;
      #define lelo(b)                     for(auto &i:b)cin>>i;
      #define ff                          first
      #define ss                          second
      #define call(v)                     v.begin(),v.end()
      #define rall(v)                     v.rbegin(),v.rend()
      #define show(x)                     for(auto t:x)cout<<t<<" ";
      #define pb                          push_back
      #define bhar(s,v)                   memset(s,v,sizeof(s))
      #define endl                        "\n"                       
      #define ce(x)                       cout<<x<<"\n";
      #define nl                          cout<<endl;
      #define jaldi                       ios_base::sync_with_stdio(false);cin.tie(NULL);
      #define dekh_lo                     ce("dekh_lo");
      #define sz(x)                       (ll)x.size()
      #define re                          return
      
      typedef pair<ll,ll> pii;
      typedef vector<pii> vii;
      typedef vector<ll> vi;
      
      const ll mod=1e9+7;
      const ll N=4e5+5;
      
      void solve(){
          in3(h,w,m);
      
          ll s=m;
          vii cor;
          while(s--){
              in2(x,y);
              cor.pb({x,y});
          }
      
          vi row(h+1,0),col(w+1,0);
          map<pii,bool> hash;
      
          for(ll i=0;i<sz(cor);i++){
              row[cor[i].ff]++;
              col[cor[i].ss]++;
              hash[{cor[i].ff,cor[i].ss}]=1;
          }
      
          ll maxi1=-1e9;
          vi ind1;
          for(ll i=1;i<=h;i++){
              if(row[i]>maxi1){
                  maxi1=row[i];
              }
          }
      
          for(ll i=1;i<=h;i++){
              if(row[i]==maxi1){
                  ind1.pb(i);
              }
          }
      
          ll maxi2=-1e9;
          vi ind2;
          for(ll i=1;i<=w;i++){
              if(col[i]>maxi2){
                  maxi2=col[i];
              }
          }
      
          for(ll i=1;i<=w;i++){
              if(col[i]==maxi2){
                  ind2.pb(i);
              }
          }
      
          bool f=0;
          for(auto j:ind1){
              for(auto i:ind2){
                  if(!hash[{j,i}]){
                      f=1;
                  }
              }   
          }
         
      
          ll ans=maxi1+maxi2-(f==0);
          ce(ans);
         
      }
      
      int32_t main(){
          // jaldi
          ll t; 
          // cin>>t;
          t=1;     
          while(t--){
              solve();
          }
      } 
      
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

My D TLEd on just 1 test-case.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится -11 Проголосовать: не нравится

Give problems where you need to at least think. Not put D where you need to just write a dijkastra without even thinking

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]

I am getting this error on question E: Bomber. Can anyone help me out?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Why editorials is not posted in atcoder now-a-days?? I am waiting for previous ABC-175 contest for 8 days but still there is no editorial.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Could someone please tell why my ans for D is failing?

https://atcoder.jp/contests/abc176/submissions/16151561

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve D?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

This is my first time participating in atcoder contest , and how can i see my rating change or rating changes later ?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

Problem E is really nice and simple, liked it

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone help me with my submission of Problem E? It shows Runtime Error https://atcoder.jp/contests/abc176/submissions/16150109

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +82 Проголосовать: не нравится

how to solve F

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +14 Проголосовать: не нравится

    At first, I was trying to solve in anyway. After every move we will have two items left. We can do a $$$dp[i][left_1][left_2]$$$ where we do the operation on items $$$left_1$$$, $$$left_2$$$, $$$i$$$, $$$i+1$$$, $$$i+2$$$. This way we can solve in $$$O(n^3)$$$ which is too large. But I started thinking about these pairs $$$(left_1, left_2)$$$ because we can iterate over them.

    So I tried to somehow store all pairs $$$(j, k)$$$ for $$$j, k \lt i$$$ and update the answers using items $$$i$$$, $$$i+1$$$, $$$i+2$$$, as well as insert new pairs.

    To solve all transitions we just need these 5 functions. I will call color as the number written on a card.

    add(i, j, val): insert the pair (i, j) with value val
    get_max(c): returns the maximum value of a pair with both cards equal to the color c
    get_max(id, c): returns the maximum value of a pair where one card has index id and the other has color c
    get_max(id): returns the maximum value of a pair where one card has index id
    lazy_inc(): lazily increments the value of all pairs by one
    

    All of them can be implemented in O(1). Let me know if this is enough.

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +29 Проголосовать: не нравится
    Spoiler
»
6 лет назад, скрыть # |
 
Проголосовать: нравится -11 Проголосовать: не нравится

are there any system tests in atcoder?

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится -6 Проголосовать: не нравится

For D, I treated each connected component as a node of a graph and then used bfs to find the shortest path.Lengthy implementation. Is this the intended solution or is there a easier way to do this?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
**See My Luck !!!**
**contest end at 19:40 in my country..and i submit the right solution of E at 19:39 but forgot to remove my debug comment for rush...**

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    It's better to print your debug statements in standard error stream. That may increase the runtime to a certain extent(if you print a lot of lines), however it is highly likely that it gets AC.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

can anybody please help me out to find error in my solution of problem E https://atcoder.jp/contests/abc176/submissions/16135136

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For problem E, I get we have to find the row and column with maximum number of targets, and the answer is at least (sum of targets in the selected row and column)-1.

But the maximum possible answer could be sum of targets in selected row and column, in case there is no target at the intersection of the chosen row and column.

Since AtCoder has apparently stopped releasing English editorials, could anyone explain how to find this maximal answer?

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +18 Проголосовать: не нравится

    Count pairs from given points

    Code
  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +5 Проголосовать: не нравится

    Store the rows with maximum bombs, same for columns. What I did is $$$rowsize * colsize \gt m$$$ then, $$$ans = rowmax + colmax - 1$$$, else, we can iterate over rows and cols and check the possible outcome.

    • »
      »
      »
      6 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      Thanks, this is what I wasn't able to think of, I was thinking there would be some clever way without brute-force.

      PS. I think you made a small typo, the condition should be: $$$rowsize∗colsize \gt m$$$ then, $$$ans=rowmax+colmax$$$.

      • »
        »
        »
        »
        6 лет назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        No, think of $$$(1, 1)$$$, $$$(2, 2)$$$, $$$(3, 3)$$$. Here, $$$m = 3$$$, $$$rowsize = 3$$$, $$$colsize = 3$$$, $$$rowmax = 1$$$, $$$colmax = 1$$$, $$$ans = 1$$$

      • »
        »
        »
        »
        6 лет назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        There is a solution that doesn't require iterating over all possible combinations of best rows and best columns.

        First, store the row coordinates of every row that has the best/maximum value in an $$$unordered\text{_}set$$$. Let the size of this set be $$$size_r$$$. Note that a column is useless to us when every maximal row has a point in that column. So, all we need is a way to calculate the number of points in every column taking into account only maximal rows.

        We can do this by simply maintaining a $$$map$$$, where $$$map[i]$$$ gives us the number of points in the $$$i^{th}$$$ column for every maximal row. You can do this by iterating over every point and if the current point's $$$x$$$-coordinate belongs to a maximal row (which we can check using the unordered set) then we increment $$$map$$$ for this point's $$$y$$$-coordinate. In the end, loop over every maximal column $$$y_i$$$, and if $$$map[y_i] \lt size_r$$$ for any column, then we know that it is possible to avoid the $$$-1$$$.

        In the end though, the complexity turns out to be the same as brute forcing because of the pigeonhole principle.

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Hello sir, I did it using the following steps: 1. Find the maximum number of the target present in any row 2. Find the maximum number of the target present in any column 3. I iterated over the columns and see how much score we can get if we choose the row which we get from step 1 and given column, but if we get any target at the intersection point of these two we need to subtract one from the score and find the maximum score in all the chosen columns with the row from step 1 4. I iterated over the rows and see how much score we can get if we choose the column which we get from step 2 and given row, but if we get any target at the intersection point of these two we need to subtract one from the score and find the maximum score in all the chosen rows with the column from step 2

    Code
  • »
    »
    6 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +5 Проголосовать: не нравится

    Check for every row and column indices for which it gives maximum values, there will not be more than 3 X 10 ^ 5 such pairs.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

If anyone need short explanation & implementation for A-E Here

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

why does simple (bfs || dfs) && dp get TLE on problem D ?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

Screencast of getting a thousand wrong ideas for F, rambling about Dial's algorithm, and somehow beating my last performance with 1/4 the effort (+ (possibly overly elaborate) editorial for A-E)

»
6 лет назад, скрыть # |
 
Проголосовать: нравится -25 Проголосовать: не нравится

WHY mifafaovo is not in top rated list?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

Probably not helpful even with google translate, but the person who got first AC for F wrote an editorial for the round in japanese: https://maspypy.com/atcoder-%e5%8f%82%e5%8a%a0%e6%84%9f%e6%83%b3-2020-08-22abc-176

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

ABC175 A-E, ABC174 E, ABC174 C, ABC174 D,

I’m writing an unofficial editorial for ABC176 too. I’m going to post it tomorrow or the day after tomorrow.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hello, can someone please help me on D?

https://atcoder.jp/contests/abc176/submissions/16163382

I've tried basically all the ideas I had but still get WA on the max case.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What's wrong in this code: https://atcoder.jp/contests/abc176/submissions/16165157 All i did was get the number of targets in each row and each column in two separate maps and if we see the sq with bomb the destroyed are 1 less than the sum of the two maps for the given key else it would be the sum. Thank you for helping!

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone help me with E number problem please? I can't figure out why i'm getting WA for 4 test cases for this solution. Link: https://atcoder.jp/contests/abc176/submissions/16166033

For any kind of help, thanks in advance

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What's wrong with this method for D? I first do a BFS from starting point and mark all the reachable nodes as visited and it would take 0 moves to move to any of them. Then I do a BFS from ending point and find distance to all the reachable nodes. Now, I do a brute force over all reachable nodes from starting point, and the number of moves required to reach that point would be 0 as we go there from starting point without using any move B and then to reach end point from that node, I find distance of ending point from this node which would be same as distance of this node from ending point, and then take minimum over all possible answers.

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +73 Проголосовать: не нравится

Here's my solution for F that I got in contest but couldn't implement in time :P

Problem F solution:

View the problem as you always have a "hand" of two cards, and break the rest of the cards into groups of $$$3$$$ (except the last group, which is group of size $$$1$$$). Index these groups from $$$1$$$ to $$$n$$$. You can treat this as moving left to right from the groups, and each turn, you can exchange some of your cards for cards in the group (or do nothing). Each time you form a set of $$$3$$$ equal cards in a group, you get a point. For the card at index $$$i$$$, let $$$label[i]$$$ denote the index of the group it's in. Now, for any group with $$$3$$$ cards of all the same value, we can ignore that group because it's optimal not to touch it and just take the point. For example, a list of cards $$$1, 1, 2, 3, 3, 2, 2, 2, 1$$$ is broken into $$$(2, 3, 3), (2, 2, 2), (1)$$$ with a starting hand of $$$(1, 1)$$$. We then remove the group $$$(2, 2, 2)$$$, so all we have to do is examine $$$(2, 3, 3), (1)$$$, where these groups are labeled $$$1, 2$$$.

Consider the $$$dp$$$ state $$$dp[i][j]$$$, where $$$i \lt j$$$. This means you've just considered exchanging with the group $$$label[j]$$$, and you currently have the cards at indices $$$i, j$$$ in your hand. $$$dp[i][j]$$$ stores the maximum points you could have at this state. You have two transitions:

Transition 1: You will swap with the next group. This means you will exchange at least one card in group $$$label[j]+1$$$. We can process all transitions of this form by examining all possible exchanges.

Transition 2: You move to the closest next group that shares a card that has a value equal to at least one of the cards in your hand. To see why this is the only other type of transition, note that if we don't exchange with the next group $$$label[j]+1$$$, we can assume we are planning to use the cards in our hand to get a point in the future. We go to the closest possible location where we could possible get a point (the next group that shares a value with at least one card in our hand), and we process exchanges there. Since we've removed all groups with all $$$3$$$ cards equal, if we don't plan on using a card in our hand to try to gain a point in the future, there's no reason we can't just swap it out in the next group, so this is the only other type of transitions. We can similarly process the transitions here as before.

Some care is needed to process the last group with only $$$1$$$ card, but it isn't that difficult.

Thus, the overall time complexity is $$$\mathcal O(N^2)$$$ since there are $$$\mathcal O(N^2)$$$ states and $$$\mathcal O(1)$$$ transition. There is a bit of a constant overhead from processing every possible swapping, but it runs in time still.

Here's my commented code, hopefully any confusion by my bad explanation is cleared up here: Submission

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится

Personal editorial for ABC176

»
6 лет назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

Can anyone please provide me DFS solution for ques D please...

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

can anyone tell me what is wrong with my code for problem D? code Link : https://atcoder.jp/contests/abc176/submissions/16215981

»
6 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится
import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        int h=s.nextInt();
        int w=s.nextInt();
        int m=s.nextInt();
        int a[][]=new int[h+1][w+1];
        for(int i=1;i<=m;i++){
            int x=s.nextInt();
            int y=s.nextInt();
            a[x][y]=1;
        }
        for(int i=1;i<=h;i++){
            int count=0;
            for(int j=1;j<=w;j++){
                count+=a[i][j];
            }
            a[i][0]=count;
        }
        for(int j=1;j<=w;j++){
            int count=0;
            for(int i=1;i<=h;i++){
                count+=a[i][j];
            }
            a[0][j]=count;
        }
        int ans=0;
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                int curr=a[0][j]+a[i][0];
                if(a[i][j]==1){
                    curr--;
                }
                ans=Math.max(ans,curr);
            }
        }
        System.out.println(ans);
    }
}

I am getting RE in problem E. If someone can help it would be great, I am new to atcoder.

Edit: It is resolved. I did not look at the constraints properly :(.