AtCoder Beginner Contest 068 Review of past questions

Past questions that I have never solved, the first time

Time required

スクリーンショット 2019-12-25 14.18.57.png

Impressions

I understood the D problem by looking at the answer, but it didn't seem like a natural solution for me and it took me a long time to chew ...

Problem A

nothing special

answerA.py


print("ABC"+input())

B problem

You just have to find the largest $ 2 ^ k $ that meets the conditions, so log and finish

answerB.py


import math
n=int(input())
print(2**math.floor(math.log(n,2)))

C problem

Since a →? → b, you can find out what the number connected to a and the number connected to b are. TLE occurred frequently because I tried to loop in the loop where the first input was received. (** See the constraints even for simple problems **)

answerC.cc


#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;

int main(){
  int n,m;cin >> n >> m;
  vector<int> x;
  bool f=false;
  for(int i=0;i<m;i++){
    int a,b;cin >> a >>b;
    if(a==1){
      x.push_back(b);
    }
    if(b==n){
      x.push_back(a);
    }
  }
  int l1=x.size();
  set<int> y(x.begin(),x.end());
  if(l1==y.size()){
    cout << "IMPOSSIBLE" << endl;
  }else{
    cout << "POSSIBLE" << endl;
  }
}

answerC.py


n,m=map(int,input().split())
x=[]
for i in range(m):
    a,b=map(int,input().split())
    if a==1:
        x.append(b)
    if b==n:
        x.append(a)
l=len(x)
if len(set(x))==l:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

D problem

answerD1.py、answerD2.py is$2$<=N<=$50$、$0$<=$a_i$<=$50 \times 10^{16}$Because it does not meet each of the above, it has become TLE.


 First, looking at the constraints, we can see that it seems better to do as many n as possible. So let's fix ** n to 50 and ** think about it.
 Here, it is not possible to simulate the entire operation due to the constraint of $ 10 ^ {16} $, so ** Is it possible to narrow down the patterns that can be constraints during operation? ** or ** What is happening in the final state? You need to think about ** first (joseki). If you do an experiment here, you will find out something if you follow it in reverse. Then, in this problem, on the contrary, you can discover the ** cycle ** by following ** accurately **.
 First of all, regarding the final state, it will be easier to understand if you arrange 0 to 49 of length 50 in ascending order. (Experimentally shows that reverse simulation becomes troublesome when there are multiple same numbers.)
 Then, if you add 50 in order from 1st to 50th and add -1 to other elements, you can simulate exactly the opposite. Also, since the total increases by 1 for each inverse simulation from 1st to 50th (from $ 50 + (-1) \ times (50-1) $), think first about k divided by 50. You can see that you should simulate the remaining number of times and then consider how much the whole is added in the remaining cycle.
 When the above is implemented, it becomes ```answerD3.py```.


#### **`answerD1.py`**
```python

k=int(input())
print(2)
if k%2==0:
    print(str(k//2)+" "+str(k//2+1))
else:
    print(str(k//2)+" "+str(k//2+2))

answerD2.py


k=int(input())
n=k+1
if n==1:
    print("2")
    print("0 1")
else:
    print(n-1+k*n,end="")
    for i in range(n-1):
        print(" 0",end="")
    print()

answerD3.py


k=int(input())
x=[0]*50
k1=k//50
k2=k%50
for i in range(k2):
    x[k2-i-1]=50-i
for i in range(k2+1,50):
    x[i]=i-k2
for i in range(50):
    x[i]+=k1
print(50)
print(" ".join(map(str,x)))

Recommended Posts

AtCoder Beginner Contest 102 Review of past questions
AtCoder Beginner Contest 085 Review of past questions
AtCoder Beginner Contest 062 Review of past questions
AtCoder Beginner Contest 113 Review of past questions
AtCoder Beginner Contest 074 Review of past questions
AtCoder Beginner Contest 051 Review of past questions
AtCoder Beginner Contest 119 Review of past questions
AtCoder Beginner Contest 151 Review of past questions
AtCoder Beginner Contest 075 Review of past questions
AtCoder Beginner Contest 054 Review of past questions
AtCoder Beginner Contest 110 Review of past questions
AtCoder Beginner Contest 117 Review of past questions
AtCoder Beginner Contest 070 Review of past questions
AtCoder Beginner Contest 105 Review of past questions
AtCoder Beginner Contest 112 Review of past questions
AtCoder Beginner Contest 076 Review of past questions
AtCoder Beginner Contest 089 Review of past questions
AtCoder Beginner Contest 069 Review of past questions
AtCoder Beginner Contest 079 Review of past questions
AtCoder Beginner Contest 056 Review of past questions
AtCoder Beginner Contest 087 Review of past questions
AtCoder Beginner Contest 093 Review of past questions
AtCoder Beginner Contest 046 Review of past questions
AtCoder Beginner Contest 123 Review of past questions
AtCoder Beginner Contest 049 Review of past questions
AtCoder Beginner Contest 078 Review of past questions
AtCoder Beginner Contest 047 Review of past questions
AtCoder Beginner Contest 104 Review of past questions
AtCoder Beginner Contest 057 Review of past questions
AtCoder Beginner Contest 121 Review of past questions
AtCoder Beginner Contest 090 Review of past questions
AtCoder Beginner Contest 103 Review of past questions
AtCoder Beginner Contest 061 Review of past questions
AtCoder Beginner Contest 083 Review of past questions
AtCoder Beginner Contest 124 Review of past questions
AtCoder Beginner Contest 116 Review of past questions
AtCoder Beginner Contest 097 Review of past questions
AtCoder Beginner Contest 092 Review of past questions
AtCoder Beginner Contest 099 Review of past questions
AtCoder Beginner Contest 065 Review of past questions
AtCoder Beginner Contest 053 Review of past questions
AtCoder Beginner Contest 094 Review of past questions
AtCoder Beginner Contest 063 Review of past questions
AtCoder Beginner Contest 107 Review of past questions
AtCoder Beginner Contest 071 Review of past questions
AtCoder Beginner Contest 064 Review of past questions
AtCoder Beginner Contest 082 Review of past questions
AtCoder Beginner Contest 084 Review of past questions
AtCoder Beginner Contest 068 Review of past questions
AtCoder Beginner Contest 058 Review of past questions
AtCoder Beginner Contest 043 Review of past questions
AtCoder Beginner Contest 098 Review of past questions
AtCoder Beginner Contest 114 Review of past questions
AtCoder Beginner Contest 045 Review of past questions
AtCoder Beginner Contest 120 Review of past questions
AtCoder Beginner Contest 108 Review of past questions
AtCoder Beginner Contest 106 Review of past questions
AtCoder Beginner Contest 122 Review of past questions
AtCoder Beginner Contest 125 Review of past questions
AtCoder Beginner Contest 109 Review of past questions
AtCoder Beginner Contest 118 Review of past questions