이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include<iostream>
#include<stdlib.h>
#include<cmath>
#include <algorithm>
#include<numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<ll> vll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define trav(a,x) for (auto& a: x)
#define fr(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>=(b); i+=(s))
#define fr1(e) fr(i, 0, e, 1)
#define fr2(i, e) fr(i, 0, e, 1)
#define fr3(i, b, e) fr(i, b, e, 1)
#define mp make_pair
#define pb push_back
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define in insert
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
int dx[4] = { -1, 0, 1, 0 };
int dy[4] = { 0, 1, 0, -1 };
const int mod = 1e9 + 7;
void xd(string str)
{
ios_base::sync_with_stdio(0); cin.tie(0);
if (str != "")
{
//freopen((str + ".in").c_str(), "r", stdin);
//freopen((str + ".out").c_str(), "w", stdout);
}
}
int add(int a, int b, int mod = 1e9 + 7) { return (((a % mod) + (b % mod)) + mod) % mod; }
int sub(int a, int b, int mod = 1e9 + 7) { return (((a % mod) - (b % mod)) + mod) % mod; }
int mul(int a, int b, int mod = 1e9 + 7) { return (((a % mod) * (b % mod)) + mod) % mod; }
int bin(int a, int b, int mod = 1e9 + 7) { int ans = 1; while (b) { if (b & 1) ans = mul(ans, a, mod); a = mul(a, a, mod); b >>= 1; }return ans; }
int inverse(int a, int mod = 1e9 + 7) { return bin(a, mod - 2, mod); }
int divi(int a, int b, int mod = 1e9 + 7) {
return mul(a, inverse(b, mod), mod);
}
ll add(ll a, ll b, ll mod = 1e9 + 7) { return (((a % mod) + (b % mod)) + mod) % mod; }
ll sub(ll a, ll b, ll mod = 1e9 + 7) { return (((a % mod) - (b % mod)) + mod) % mod; }
ll mul(ll a, ll b, ll mod = 1e9 + 7) { return (((a % mod) * (b % mod)) + mod) % mod; }
ll bin(ll a, ll b, ll mod = 1e9 + 7) { ll ans = 1; while (b) { if (b & 1) ans = mul(ans, a, mod); a = mul(a, a, mod); b >>= 1; }return ans; }
ll inverse(ll a, ll mod = 1e9 + 7) { return bin(a, mod - 2, mod); }
ll divi(ll a, ll b, ll mod = 1e9 + 7) {
return mul(a, inverse(b, mod), mod);
}
ll ex(int base, int power)
{
if (power == 0)
return 1;
ll result = ex(base, power / 2);
if (power % 2 == 1)
return(((result * result) % mod) * base) % mod;
else return (result * result) % mod;
}
int gcd(int a, int b) {
if (b == 0)return a;
else return gcd(b, a % b);
}
int lcm(int a, int b) {
return a * b / gcd(a, b);
}
ll fac(int x) {
ll factorial = 1;
for (ll i = 1; i <= x; ++i) {
factorial = mul(factorial, i);
}
return factorial % mod;
}
ll npr(int x, int c) {
if (x == c) return fac(x);
else return (fac(x) / (fac(x - c) * fac(c))) % mod;
}
void bton(string s) { stoll(s, nullptr, 2); }
inline int read() {
int x = 0, f = 1, c = getchar();
while (!isdigit(c)) { if (c == '-')f = -1; c = getchar(); }
while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
return f == 1 ? x : -x;
}
bool isPrime(int n)
{
if (n == 2 || n == 3)
return true;
if (n <= 1 || n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0)
return false;
}
return true;
}
int ceil_int(int first_number, int divider) {
if (first_number % divider == 0) return first_number / divider;
else return first_number / divider + 1;
}
ll ceil_ll(ll first_number, ll divider) {
if (first_number % divider == 0) return first_number / divider;
else return first_number / divider + 1LL;
}
/*
t=1;
first we can find a[0] and a[n-1] using the range 0,1e18+1 because a[0]>0 && a[n-1]<1e18+1
then using that we can find a[1] by using a[0] because we know that a[1]>=a[0]+1 same for a[n-2]<=a[n-1]-1
so can use MinMax once so that a[0] and a[n-1] is defined, then we can move into the middle so that we can recold {a[1],a[n-2]},{a[2],a[n-3]},....
this solution will be n/2
t=2;
suggestion 1: binary search
suggestion 2: skip the middle part when for example n=3 using math theory
sugegstion 3: mx-mn
*/
#include "dna.h"
string aa, bb;
void init(std::string a, std::string b) {
aa = a;
bb = b;
}
int get_distance(int x, int y) {
x--; y--;
if (y - x == 0) return 0;
else if (y - x == 1) {
if (aa[x] == bb[x] && aa[y] == bb[y]) return 0;
else if (aa[x] == bb[y] && aa[y] == bb[x]) return 1;
return -1;
}
else if (y - x == 2) {
map<char, int> m1;
FOR(i, x, y + 1) m1[aa[i]]++;
map<char, int>m2;
FOR(i, x, y + 1) m2[bb[i]]++;
string p = "ATC";
int ok1 = 0;
FOR(i, 0, sz(p)) {
if (m1[p[i]] != m2[p[i]]) ok1 = 1;
}
if (ok1) return -1;
int ok = 1,cnt=0;
FOR(i, x, y + 1) {
if (aa[i] != bb[i]) ok = 0;
else cnt++;
}
if (ok) return 0;
else {
return cnt - 1;
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:163:1: warning: control reaches end of non-void function [-Wreturn-type]
163 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |