답안 #948296

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
948296 2024-03-18T03:53:26 Z ezzzay DNA 돌연변이 (IOI21_dna) C++17
컴파일 오류
0 ms 0 KB
#include "dna.h"
#define ff first
#define ss second
#define pb push_back

void init(std::string a, std::string b) {
}

int get_distance(int x, int y) {
	string s=a.substr(x,y-x+1);
	string t=b.substr(x,y-x+1);
	map<string,int>mp;
	mp[s]=1;
	queue<pair<int,int>>q;
	q.push({s,1});
	while(!q.empty()){
		string a=q.front().ff;
		int w=q.front().ss;
		if(a==t){
			return w-1;
		}
		q.pop();
		for(int i=0;i<a.size();i++){
			for(int j=0;j<a.size();j++){
				string tmp=a;
				swap(tmp[i],tmp[j]);
				if(mp[tmp]==0){
					mp[tmp]=w+1;
					q.push({tmp,w+1});
				}
			}
		}
	}
	return -1;
}

Compilation message

dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:10:2: error: 'string' was not declared in this scope
   10 |  string s=a.substr(x,y-x+1);
      |  ^~~~~~
dna.cpp:10:2: note: suggested alternatives:
In file included from /usr/include/c++/10/string:39,
                 from dna.h:1,
                 from dna.cpp:1:
/usr/include/c++/10/bits/stringfwd.h:79:33: note:   'std::string'
   79 |   typedef basic_string<char>    string;
      |                                 ^~~~~~
In file included from dna.h:1,
                 from dna.cpp:1:
/usr/include/c++/10/string:67:11: note:   'std::pmr::string'
   67 |     using string    = basic_string<char>;
      |           ^~~~~~
dna.cpp:11:8: error: expected ';' before 't'
   11 |  string t=b.substr(x,y-x+1);
      |        ^~
      |        ;
dna.cpp:12:2: error: 'map' was not declared in this scope
   12 |  map<string,int>mp;
      |  ^~~
dna.cpp:12:13: error: expected primary-expression before 'int'
   12 |  map<string,int>mp;
      |             ^~~
dna.cpp:13:2: error: 'mp' was not declared in this scope
   13 |  mp[s]=1;
      |  ^~
dna.cpp:13:5: error: 's' was not declared in this scope
   13 |  mp[s]=1;
      |     ^
dna.cpp:14:2: error: 'queue' was not declared in this scope
   14 |  queue<pair<int,int>>q;
      |  ^~~~~
dna.cpp:14:8: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
   14 |  queue<pair<int,int>>q;
      |        ^~~~
      |        std::pair
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/string:40,
                 from dna.h:1,
                 from dna.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'std::pair' declared here
  211 |     struct pair
      |            ^~~~
dna.cpp:14:13: error: expected primary-expression before 'int'
   14 |  queue<pair<int,int>>q;
      |             ^~~
dna.cpp:15:2: error: 'q' was not declared in this scope
   15 |  q.push({s,1});
      |  ^
dna.cpp:17:9: error: expected ';' before 'a'
   17 |   string a=q.front().ff;
      |         ^~
      |         ;
dna.cpp:19:6: error: 'a' was not declared in this scope
   19 |   if(a==t){
      |      ^
dna.cpp:19:9: error: 't' was not declared in this scope
   19 |   if(a==t){
      |         ^
dna.cpp:23:17: error: 'a' was not declared in this scope
   23 |   for(int i=0;i<a.size();i++){
      |                 ^
dna.cpp:25:11: error: expected ';' before 'tmp'
   25 |     string tmp=a;
      |           ^~~~
      |           ;
dna.cpp:26:10: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   26 |     swap(tmp[i],tmp[j]);
      |          ^~~
      |          tm
dna.cpp:26:5: error: 'swap' was not declared in this scope
   26 |     swap(tmp[i],tmp[j]);
      |     ^~~~
dna.cpp:26:5: note: suggested alternatives:
In file included from /usr/include/c++/10/string:55,
                 from dna.h:1,
                 from dna.cpp:1:
/usr/include/c++/10/bits/basic_string.h:6420:5: note:   'std::swap'
 6420 |     swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~
In file included from /usr/include/c++/10/bits/stl_pair.h:59,
                 from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/string:40,
                 from dna.h:1,
                 from dna.cpp:1:
/usr/include/c++/10/bits/move.h:189:5: note:   'std::swap'
  189 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/10/bits/move.h:189:5: note:   'std::swap'
In file included from /usr/include/c++/10/exception:147,
                 from /usr/include/c++/10/new:41,
                 from /usr/include/c++/10/ext/new_allocator.h:33,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/c++allocator.h:33,
                 from /usr/include/c++/10/bits/allocator.h:46,
                 from /usr/include/c++/10/string:41,
                 from dna.h:1,
                 from dna.cpp:1:
/usr/include/c++/10/bits/exception_ptr.h:169:5: note:   'std::__exception_ptr::swap'
  169 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~